feat: remove items with invalid quadrant or ring and optionally filter by tags

This commit is contained in:
Mathias Schopmans
2024-03-08 13:41:42 +01:00
committed by Mathias Schopmans
parent 9d18d97a94
commit cfaa40a225
4 changed files with 36 additions and 7 deletions

View File

@@ -70,6 +70,7 @@ Copy the [`config.json`](./data/config.json) next to the `package.json` and adap
| social | Social links in the footer. See config below | | social | Social links in the footer. See config below |
| imprint | URL to the legal information | | imprint | URL to the legal information |
| labels | Configure the labels to change the texts and labels of the radar | | labels | Configure the labels to change the texts and labels of the radar |
| tags | (optional) Use to render only items, which contain at least one of the specified tags. e.g `["frontend", "backend"]` |
| editUrl | (optional) If set, an edit button will be shown next to the revision.<br/> You can use placeholders for `{id}` and `{release}` | | editUrl | (optional) If set, an edit button will be shown next to the revision.<br/> You can use placeholders for `{id}` and `{release}` |
#### `config.quadrants` #### `config.quadrants`

View File

@@ -2,7 +2,7 @@
title: "Demo 3" title: "Demo 3"
ring: hold ring: hold
quadrant: tools quadrant: tools
tags: [coding] tags: [coding, frontend]
--- ---
This is a demo entry. It is used to show how a radar item is written in Markdown format. The meta header is used to define the attributes of the item. The content of the file is used as the description of the item. This is a demo entry. It is used to show how a radar item is written in Markdown format. The meta header is used to define the attributes of the item. The content of the file is used as the description of the item.

View File

@@ -2,7 +2,7 @@
title: "Demo 2" title: "Demo 2"
ring: adopt ring: adopt
quadrant: platforms-and-operations quadrant: platforms-and-operations
tags: [coding] tags: [coding, backend]
--- ---
This is a revision of the 2nd demo item. It moved from trail to adopt. This is a revision of the 2nd demo item. It moved from trail to adopt.

View File

@@ -16,7 +16,10 @@ const {
chart: { size }, chart: { size },
} = config; } = config;
const ringIds = rings.map((r) => r.id);
const quadrants = config.quadrants.map((q, i) => ({ ...q, position: i + 1 })); const quadrants = config.quadrants.map((q, i) => ({ ...q, position: i + 1 }));
const quadrantIds = quadrants.map((q) => q.id);
const tags = (config as { tags?: string[] }).tags || [];
const positioner = new Positioner(size, quadrants, rings); const positioner = new Positioner(size, quadrants, rings);
const marked = new Marked( const marked = new Marked(
@@ -151,11 +154,36 @@ function postProcessItems(items: Item[]): {
tags: string[]; tags: string[];
items: Item[]; items: Item[];
} { } {
const releases = getUniqueReleases(items); const filteredItems = items.filter((item) => {
const tags = getUniqueTags(items); // check if the items' quadrant and ring are valid
const latestRelease = releases[releases.length - 1]; if (!item.quadrant || !item.ring) {
console.warn(`Item ${item.id} has no quadrant or ring`);
return false;
}
const processedItems = items.map((item) => ({ if (!quadrantIds.includes(item.quadrant)) {
console.warn(`Item ${item.id} has invalid quadrant ${item.quadrant}`);
return false;
}
if (!ringIds.includes(item.ring)) {
console.warn(`Item ${item.id} has invalid ring ${item.ring}`);
return false;
}
// check if config has a key `tags` and if it is an array
if (Array.isArray(tags) && tags.length) {
// if tags are specified, only keep items that have at least one of the tags
return item.tags.some((tag) => tags.includes(tag));
}
return true;
});
const releases = getUniqueReleases(filteredItems);
const uniqueTags = getUniqueTags(filteredItems);
const latestRelease = releases[releases.length - 1];
const processedItems = filteredItems.map((item) => ({
...item, ...item,
position: positioner.getNextPosition(item.quadrant, item.ring), position: positioner.getNextPosition(item.quadrant, item.ring),
flag: getFlag(item, latestRelease), flag: getFlag(item, latestRelease),
@@ -173,7 +201,7 @@ function postProcessItems(items: Item[]): {
.reverse(), .reverse(),
})); }));
return { releases, tags, items: processedItems }; return { releases, tags: uniqueTags, items: processedItems };
} }
// Parse the data and write radar data to JSON file // Parse the data and write radar data to JSON file