From 14b3132c64bc035c253ab3198b3dcb32b1f3ba8e Mon Sep 17 00:00:00 2001 From: Ari Date: Fri, 27 May 2022 13:00:52 -0400 Subject: [PATCH] ensured unique tag types --- webapp/src/components/AutomationList/TagDB.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/webapp/src/components/AutomationList/TagDB.ts b/webapp/src/components/AutomationList/TagDB.ts index 8bb361a..759baf4 100644 --- a/webapp/src/components/AutomationList/TagDB.ts +++ b/webapp/src/components/AutomationList/TagDB.ts @@ -2,11 +2,14 @@ import { AutomationData } from "types/automations"; export type TagDB = ReturnType; export const makeTagDB = (automations: AutomationData[]) => { - const allTags: Record = {}; + const allTags: Record> = {}; automations.forEach(({ tags }) => Object.keys(tags).forEach(tagName => { const tagValue = tags[tagName]; - allTags[tagName] = (allTags[tagName] ?? []).concat([tagValue]); + if (!allTags[tagName]) { + allTags[tagName] = new Set() + } + allTags[tagName].add(tagValue); }) ); const allTagNames = Object.keys(allTags); @@ -15,7 +18,7 @@ export const makeTagDB = (automations: AutomationData[]) => { return allTagNames.filter(n => !myTags.includes(n)) }, getTagValues(tagName: string): string[] { - return allTags[tagName] ?? []; + return allTags[tagName] ? Array.from(allTags[tagName].values()) : []; } } } \ No newline at end of file