Talking about indirection, I started going down the path of data-driven grouping — which worked but was a little confusing:
groupLookup[itemFilters.groupBy]?.[item[itemFilters.groupBy]] ?? "Items with no Epic";
I changed it to a switch to make it clearer and to be able to do arbitrary logic:
const groupTitle = (item: TransfomedItem) => {
switch (itemFilters.groupBy) {
case "statusId":
return statuses[item.statusId as keyof typeof ItemStatuses];
case "parentId":
return (item.parentId && epics ? epics[item.parentId] : "Items with no Epic");
}
return "All Items";
};
The data driven approach also had to deal with different types (uuid, string, undefined) so had to be unioned. The groupTitle() function simply returns a string.