Adding a level in tag definitions to support routes (in addition to POIs)

This commit is contained in:
Eric van der Vlist 2023-06-12 18:26:53 +02:00
parent db85c8ff69
commit 0ae8b68255
2 changed files with 39 additions and 17 deletions

View File

@ -11,11 +11,12 @@ describe('The getTagStatus function', () => {
expect( expect(
getTagStatus( getTagStatus(
'whatever', 'whatever',
{ hiking: { eating: { whatever: {} } } }, { hiking: { route: { eating: { whatever: {} } } } },
'hiking', 'hiking',
'eating' 'eating'
) )
).toEqual({ ).toEqual({
type: 'route',
definition: {}, definition: {},
highlighted: true, highlighted: true,
}); });
@ -24,11 +25,12 @@ describe('The getTagStatus function', () => {
expect( expect(
getTagStatus( getTagStatus(
'whatever', 'whatever',
{ hiking: { sleeping: { whatever: {} } } }, { hiking: { route: { eating: { whatever: {} } } } },
'hiking', 'hiking',
'eating' 'sleeping'
) )
).toEqual({ ).toEqual({
type: 'route',
definition: {}, definition: {},
highlighted: false, highlighted: false,
}); });

View File

@ -4,8 +4,14 @@ interface TagCategoryDefinitions {
[key: string]: TagFormatDefinition; [key: string]: TagFormatDefinition;
} }
enum TagType {
POI = 'poi',
ROUTE = 'route',
}
interface TagActivityDefinitions { interface TagActivityDefinitions {
[key: string]: TagCategoryDefinitions; poi?: { [key: string]: TagCategoryDefinitions };
route?: { [key: string]: TagCategoryDefinitions };
} }
interface TagDefinitions { interface TagDefinitions {
@ -13,6 +19,7 @@ interface TagDefinitions {
} }
interface TagStatus { interface TagStatus {
type?: TagType;
definition?: TagFormatDefinition; definition?: TagFormatDefinition;
highlighted: boolean; highlighted: boolean;
} }
@ -31,21 +38,34 @@ export const getTagStatus = <TagStatus>(
return defaultStatus; return defaultStatus;
} }
const highlightedDefinitions = activityDefinitions[highlightedKey]; for (const type of Object.values(TagType)) {
const typeDefinitions = activityDefinitions[type as TagType];
if (!!highlightedDefinitions) { if (!!typeDefinitions) {
const definition = highlightedDefinitions[tag]; const highlightedDefinitions = typeDefinitions[highlightedKey];
if (!!definition) {
return { definition, highlighted: true };
}
}
for (const category of Object.keys(activityDefinitions)) { if (!!highlightedDefinitions) {
if (category !== highlightedKey) { const definition = highlightedDefinitions[tag];
const categoryDefinitions = activityDefinitions[category]; if (!!definition) {
const definition = categoryDefinitions[tag]; return { type, definition, highlighted: true };
if (!!definition) { }
return { definition, highlighted: false }; }
for (const category of Object.keys(typeDefinitions)) {
if (category !== highlightedKey) {
const categoryDefinitions = typeDefinitions[category];
console.log({
caller: 'getTagStatus / looping over categories',
type,
typeDefinitions,
category,
categoryDefinitions,
});
const definition = categoryDefinitions[tag];
if (!!definition) {
return { type, definition, highlighted: false };
}
}
} }
} }
} }