From 029a2dac9f9e7b3ea76f77fbb4c1c3358cf7f8ad Mon Sep 17 00:00:00 2001 From: Ari Date: Wed, 18 May 2022 22:57:51 -0400 Subject: [PATCH] better formatting --- .../AutomationList/AutomationList.stories.tsx | 32 +++++++++++++++++++ webapp/src/components/DAGFlow/index.tsx | 1 - .../components/DAGFlow/sequenceConvertor.ts | 2 -- webapp/src/components/DAGFlow/styles.ts | 1 + .../components/DAGFlow/triggerConvertor.ts | 3 +- webapp/src/utils/formatting.ts | 29 +++++++++++++++++ 6 files changed, 64 insertions(+), 4 deletions(-) diff --git a/webapp/src/components/AutomationList/AutomationList.stories.tsx b/webapp/src/components/AutomationList/AutomationList.stories.tsx index a0e3b63..9f990ea 100644 --- a/webapp/src/components/AutomationList/AutomationList.stories.tsx +++ b/webapp/src/components/AutomationList/AutomationList.stories.tsx @@ -510,6 +510,38 @@ export const BadAutmations = Template.bind({}) BadAutmations.args = { ...BadAutmations.args, automations: [ + { + "metadata": { + "alias": "Set Thermostat to 76 at 8am", + "description": "", + "mode": "single", + } as any, + "trigger": [ + { + "at": "08:00:00", + "platform": "time" + } + ], + "condition": [ + { + "condition": "state", + "entity_id": "climate.thermostat", + "state": "cool" + } + ], + "sequence": [ + { + "data": { + "temperature": 76 + }, + "service": "climate.set_temperature", + "target": { + "entity_id": "climate.thermostat" + } + } + ], + "tags": {}, + }, { condition: [], tags: {}, diff --git a/webapp/src/components/DAGFlow/index.tsx b/webapp/src/components/DAGFlow/index.tsx index 89701fc..8bc551a 100644 --- a/webapp/src/components/DAGFlow/index.tsx +++ b/webapp/src/components/DAGFlow/index.tsx @@ -127,7 +127,6 @@ export const DAGAutomationFlow: FC = ({ }, makeSequenceUpdater(sequence, onSequenceUpdate, setModalState), ); - console.log(flowData) // render return <> diff --git a/webapp/src/components/DAGFlow/sequenceConvertor.ts b/webapp/src/components/DAGFlow/sequenceConvertor.ts index b241165..9e9da1b 100644 --- a/webapp/src/components/DAGFlow/sequenceConvertor.ts +++ b/webapp/src/components/DAGFlow/sequenceConvertor.ts @@ -41,9 +41,7 @@ export const sequenceToFlow = ( try { const out = addChooseNode(node, position, nodeId, dims, updater, i); position = out.lastPos - console.log(out); flowData = mergeFlowDatas(flowData, out.flowData); - console.log(flowData); } catch (err) { console.error(err) addErrorNode(flowData, nodeId, position, dims, err, updater.makeOnEditForBadNode(i)); diff --git a/webapp/src/components/DAGFlow/styles.ts b/webapp/src/components/DAGFlow/styles.ts index 3331983..4b4c1b4 100644 --- a/webapp/src/components/DAGFlow/styles.ts +++ b/webapp/src/components/DAGFlow/styles.ts @@ -78,6 +78,7 @@ export const useNodeStyles = createAppUseStyles<{ textOverflow: 'ellipsis', overflow: "hidden", whiteSpace: "break-spaces", + lineBreak: "anywhere", cursor: 'default', }, buttonDelete: { diff --git a/webapp/src/components/DAGFlow/triggerConvertor.ts b/webapp/src/components/DAGFlow/triggerConvertor.ts index b98a9af..625cb94 100644 --- a/webapp/src/components/DAGFlow/triggerConvertor.ts +++ b/webapp/src/components/DAGFlow/triggerConvertor.ts @@ -1,6 +1,7 @@ import { AutomationTrigger } from 'types/automations/triggers'; import { DAGAutomationFlowDims, FlowData, TriggerMakerOptions } from './types'; import { makeAddButton } from './flowDataMods'; +import { getDescriptionFromAutomationNode } from 'utils/formatting'; export const triggerToFlow = ( flowData: FlowData, @@ -23,7 +24,7 @@ export const triggerToFlow = ( id: flowId, type: 'dagnode', data: { - label: t.alias ?? t.platform, + label: getDescriptionFromAutomationNode(t), height: nodeHeight, width: nodeWidth, color: 'red', diff --git a/webapp/src/utils/formatting.ts b/webapp/src/utils/formatting.ts index f4dd051..2f43851 100644 --- a/webapp/src/utils/formatting.ts +++ b/webapp/src/utils/formatting.ts @@ -16,10 +16,39 @@ export const convertTimeToString = (t: AutomationTime) => { } } export const getDescriptionFromAutomationNode = (node: AutomationNode): string => { + console.log(node) if (node.alias) { return node.alias; } if ('platform' in node) { + if (node.platform === 'time') { + return node.at + } + if (node.platform === 'homeassistant') { + if (node.event === 'start') { + return 'HA is starting' + } else { + return 'HA is shutting down' + } + } + if (node.platform === 'tag') { + return `Tag = ${node.tag_id}` + } + if (node.platform === 'state') { + let out = ""; + if (typeof node.entity_id === 'string') { + out = node.entity_id + } else { + out = node.entity_id[0] + " and more" + } + if (node.from) { + out += ` from ${node.from}` + } + if (node.to) { + out += ` to ${node.to}` + } + return out + } return node.platform } if ('condition' in node) {