Skip to content

Commit

Permalink
feat: allow to change order of sections on main page
Browse files Browse the repository at this point in the history
  • Loading branch information
d-koppenhagen authored and mathiasschopmans committed Mar 25, 2024
1 parent 88a7eb5 commit 7c08e52
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 14 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Open the `config.json` file and configure the radar to your needs.
| --------- | ------------------------------------------------------------------------------------------------------------------------------ |
| basePath | Set if hosting under a sub-path, otherwise set it to `/`. Default is `/techradar` |
| toggles | (optional) Modify the behaviour and contents of the radar. See config below. |
| sections | (optional) Modify the order of sections (`radar`, `tags`, `list`) |
| colors | A map of colors for the radar. Can be any valid CSS color value |
| quadrants | Config of the 4 quadrants of the radar. See config below. |
| rings | Config of the rings of the radar. See config below. |
Expand All @@ -91,6 +92,10 @@ Open the `config.json` file and configure the radar to your needs.
| showQuadrantList | Render the items below the radar? |
| showEmptyRings | If set to `true` it will render empty rings in the list |

#### `config.sections`

An array with of `radar`, `tags`, `list` in order you want them to appear on the page.

#### `config.quadrants`

| Attribute | Description |
Expand Down
1 change: 1 addition & 0 deletions data/config.default.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"showQuadrantList": true,
"showEmptyRings": false
},
"sections": ["radar", "tags", "list"],
"colors": {
"foreground": "#fcf2e6",
"background": "#113521",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ if (userConfig.labels)
if (userConfig.toggles)
config.toggles = { ...defaultConfig.toggles, ...userConfig.toggles };

if (userConfig.sections)
config.sections = { ...defaultConfig.sections, ...userConfig.sections };

export default config;
4 changes: 4 additions & 0 deletions src/lib/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export function getToggle(key: keyof typeof config.toggles) {
return config.toggles[key] || false;
}

export function getSections() {
return config.sections;
}

export function getAppName() {
return getLabel("title");
}
Expand Down
40 changes: 28 additions & 12 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getQuadrants,
getReleases,
getRings,
getSections,
getTags,
getToggle,
} from "@/lib/data";
Expand All @@ -20,6 +21,7 @@ const Home: CustomPage = () => {
const tag = router.query.tag as string | undefined;
const appName = getAppName();
const chartConfig = getChartConfig();
const sections = getSections();
const version = getReleases().length;
const rings = getRings();
const quadrants = getQuadrants();
Expand All @@ -36,18 +38,32 @@ const Home: CustomPage = () => {
Version #{version}
</span>
</h1>
{getToggle("showChart") && (
<Radar
size={chartConfig.size}
quadrants={quadrants}
rings={rings}
items={items}
/>
)}
{getToggle("showTagFilter") && tags.length > 0 && (
<Tags tags={tags} activeTag={tag} />
)}
{getToggle("showQuadrantList") && <QuadrantList items={items} />}
{sections.map((section) => {
switch (section) {
case "radar":
return (
getToggle("showChart") && (
<Radar
size={chartConfig.size}
quadrants={quadrants}
rings={rings}
items={items}
/>
)
);
case "tags":
return (
getToggle("showTagFilter") &&
tags.length > 0 && <Tags tags={tags} activeTag={tag} />
);
case "list":
return (
getToggle("showQuadrantList") && <QuadrantList items={items} />
);
default:
return null;
}
})}
</>
);
};
Expand Down

0 comments on commit 7c08e52

Please sign in to comment.