Adding a level in tag definitions to support routes (in addition to POIs)
This commit is contained in:
parent
db85c8ff69
commit
0ae8b68255
|
@ -11,11 +11,12 @@ describe('The getTagStatus function', () => {
|
|||
expect(
|
||||
getTagStatus(
|
||||
'whatever',
|
||||
{ hiking: { eating: { whatever: {} } } },
|
||||
{ hiking: { route: { eating: { whatever: {} } } } },
|
||||
'hiking',
|
||||
'eating'
|
||||
)
|
||||
).toEqual({
|
||||
type: 'route',
|
||||
definition: {},
|
||||
highlighted: true,
|
||||
});
|
||||
|
@ -24,11 +25,12 @@ describe('The getTagStatus function', () => {
|
|||
expect(
|
||||
getTagStatus(
|
||||
'whatever',
|
||||
{ hiking: { sleeping: { whatever: {} } } },
|
||||
{ hiking: { route: { eating: { whatever: {} } } } },
|
||||
'hiking',
|
||||
'eating'
|
||||
'sleeping'
|
||||
)
|
||||
).toEqual({
|
||||
type: 'route',
|
||||
definition: {},
|
||||
highlighted: false,
|
||||
});
|
||||
|
|
|
@ -4,8 +4,14 @@ interface TagCategoryDefinitions {
|
|||
[key: string]: TagFormatDefinition;
|
||||
}
|
||||
|
||||
enum TagType {
|
||||
POI = 'poi',
|
||||
ROUTE = 'route',
|
||||
}
|
||||
|
||||
interface TagActivityDefinitions {
|
||||
[key: string]: TagCategoryDefinitions;
|
||||
poi?: { [key: string]: TagCategoryDefinitions };
|
||||
route?: { [key: string]: TagCategoryDefinitions };
|
||||
}
|
||||
|
||||
interface TagDefinitions {
|
||||
|
@ -13,6 +19,7 @@ interface TagDefinitions {
|
|||
}
|
||||
|
||||
interface TagStatus {
|
||||
type?: TagType;
|
||||
definition?: TagFormatDefinition;
|
||||
highlighted: boolean;
|
||||
}
|
||||
|
@ -31,21 +38,34 @@ export const getTagStatus = <TagStatus>(
|
|||
return defaultStatus;
|
||||
}
|
||||
|
||||
const highlightedDefinitions = activityDefinitions[highlightedKey];
|
||||
for (const type of Object.values(TagType)) {
|
||||
const typeDefinitions = activityDefinitions[type as TagType];
|
||||
|
||||
if (!!highlightedDefinitions) {
|
||||
const definition = highlightedDefinitions[tag];
|
||||
if (!!definition) {
|
||||
return { definition, highlighted: true };
|
||||
}
|
||||
}
|
||||
if (!!typeDefinitions) {
|
||||
const highlightedDefinitions = typeDefinitions[highlightedKey];
|
||||
|
||||
for (const category of Object.keys(activityDefinitions)) {
|
||||
if (category !== highlightedKey) {
|
||||
const categoryDefinitions = activityDefinitions[category];
|
||||
const definition = categoryDefinitions[tag];
|
||||
if (!!definition) {
|
||||
return { definition, highlighted: false };
|
||||
if (!!highlightedDefinitions) {
|
||||
const definition = highlightedDefinitions[tag];
|
||||
if (!!definition) {
|
||||
return { type, definition, highlighted: true };
|
||||
}
|
||||
}
|
||||
|
||||
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 };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue