From 46209564f064386f23c9a3e04253824265c35496 Mon Sep 17 00:00:00 2001 From: Ari Date: Sat, 23 Apr 2022 22:07:11 -0400 Subject: [PATCH] matching tag definitions --- .../AutomationEditor/AutoInfoBox.stories.tsx | 1 - .../AutomationEditor/index.stories.tsx | 4 ++-- .../AutomationList/AutomationListBox.test.ts | 24 +++++++++---------- .../AutomationList/AutomationListBox.tsx | 14 +++++------ webapp/src/types/automations/index.ts | 2 +- webapp/src/utils/defaults.ts | 2 +- webapp/src/utils/mocks.ts | 2 +- 7 files changed, 24 insertions(+), 25 deletions(-) diff --git a/webapp/src/components/AutomationEditor/AutoInfoBox.stories.tsx b/webapp/src/components/AutomationEditor/AutoInfoBox.stories.tsx index 909c478..55a9da7 100644 --- a/webapp/src/components/AutomationEditor/AutoInfoBox.stories.tsx +++ b/webapp/src/components/AutomationEditor/AutoInfoBox.stories.tsx @@ -34,6 +34,5 @@ Basic.args = { 'wowo': '!' }, mode: 'single', - tags: {}, }, } diff --git a/webapp/src/components/AutomationEditor/index.stories.tsx b/webapp/src/components/AutomationEditor/index.stories.tsx index 663632c..e39eb1a 100644 --- a/webapp/src/components/AutomationEditor/index.stories.tsx +++ b/webapp/src/components/AutomationEditor/index.stories.tsx @@ -38,6 +38,7 @@ export const Simple = Template.bind({}) Simple.args = { ...Simple.args, automation: { + tags: {}, metadata: { id: "random", alias: "Random", @@ -46,7 +47,6 @@ Simple.args = { 'wowo': '!' }, mode: 'single', - tags: {}, }, trigger: [ { @@ -108,6 +108,7 @@ export const EmptyStart = Template.bind({}) EmptyStart.args = { ...EmptyStart.args, automation: { + tags: {}, metadata: { id: "random", alias: "Random", @@ -116,7 +117,6 @@ EmptyStart.args = { 'wowo': '!' }, mode: 'single', - tags: {}, }, trigger: [ ], diff --git a/webapp/src/components/AutomationList/AutomationListBox.test.ts b/webapp/src/components/AutomationList/AutomationListBox.test.ts index 826fcfc..81c6fda 100644 --- a/webapp/src/components/AutomationList/AutomationListBox.test.ts +++ b/webapp/src/components/AutomationList/AutomationListBox.test.ts @@ -10,10 +10,10 @@ test('group automations', () => { alias: '', description: '', mode: 'single', - tags: { - "Room": 'Living Room', - "Type": 'Lights' - } + }, + tags: { + "Room": 'Living Room', + "Type": 'Lights' }, sequence: [], trigger: [], @@ -24,10 +24,10 @@ test('group automations', () => { alias: '', description: '', mode: 'single', - tags: { - "Room": 'Living Room', - "Type": 'Climate' - } + }, + tags: { + "Room": 'Living Room', + "Type": 'Climate' }, sequence: [], trigger: [], @@ -38,10 +38,10 @@ test('group automations', () => { alias: '', description: '', mode: 'single', - tags: { - "Room": 'Kitchen', - "Type": 'Climate' - } + }, + tags: { + "Room": 'Kitchen', + "Type": 'Climate' }, sequence: [], trigger: [], diff --git a/webapp/src/components/AutomationList/AutomationListBox.tsx b/webapp/src/components/AutomationList/AutomationListBox.tsx index 07ddbf4..6bd63ee 100644 --- a/webapp/src/components/AutomationList/AutomationListBox.tsx +++ b/webapp/src/components/AutomationList/AutomationListBox.tsx @@ -54,7 +54,7 @@ export const AutomationListBox: FC = ({ export const getTagList = (autos: AutomationData[]): string[] => Object.keys(autos - .map(a => Object.keys(a.metadata.tags)) + .map(a => Object.keys(a.tags)) .reduce((all: any, keys) => { for (const k of keys) { all[k] = 1 @@ -75,7 +75,7 @@ const filterAutomations = (autos: AutomationData[], searchText: string, selected } if (selected.length > 0) { for (const i of selected) { - if (!a.metadata.tags[tags[i]]) { + if (!a.tags[tags[i]]) { return false } } @@ -103,10 +103,10 @@ export const groupAutomations = ( if (lastKey !== null) { where = where[lastKey] } - if (!where[a.metadata.tags[tag]]) { - where[a.metadata.tags[tag]] = {} + if (!where[a.tags[tag]]) { + where[a.tags[tag]] = {} } - lastKey = a.metadata.tags[tag] + lastKey = a.tags[tag] } if (lastKey !== null) { if (!where[lastKey] || !Array.isArray(where[lastKey])) { @@ -141,8 +141,8 @@ const convertGroupsToItems = (
- {Object.keys(auto.metadata.tags).map(tagName => - {tagName}: {auto.metadata.tags[tagName]} + {Object.keys(auto.tags).map(tagName => + {tagName}: {auto.tags[tagName]} )}
diff --git a/webapp/src/types/automations/index.ts b/webapp/src/types/automations/index.ts index 5aaea9b..62e5254 100644 --- a/webapp/src/types/automations/index.ts +++ b/webapp/src/types/automations/index.ts @@ -9,12 +9,12 @@ export interface AutomationMetadata { description: string; trigger_variables?: Record; mode: "single" | "restart" | "queued" | "parallel"; - tags: Record; } export interface AutomationData { metadata: AutomationMetadata; trigger: AutomationTrigger[]; sequence: AutomationSequenceNode[]; + tags: Record; } export type AutomationSequenceNode = AutomationAction | AutomationCondition; export type AutomationNodeMapping = { diff --git a/webapp/src/utils/defaults.ts b/webapp/src/utils/defaults.ts index 8c70a55..0e07df5 100644 --- a/webapp/src/utils/defaults.ts +++ b/webapp/src/utils/defaults.ts @@ -47,8 +47,8 @@ export const defaultAutomation = (id: string): AutomationData => ({ alias: "New Automation", description: "", mode: "single", - tags: {}, }, + tags: {}, trigger: [], sequence: [], }) diff --git a/webapp/src/utils/mocks.ts b/webapp/src/utils/mocks.ts index 97761b7..bcff5f2 100644 --- a/webapp/src/utils/mocks.ts +++ b/webapp/src/utils/mocks.ts @@ -10,8 +10,8 @@ export const createMockAuto = (tags: Record = {}): AutomationDat 'wowo': '!' }, mode: 'single', - tags }, + tags, trigger: [ { "$smType": undefined,