diff --git a/webapp/src/components/SequenceNodes/index.stories.tsx b/webapp/src/components/SequenceNodes/index.stories.tsx index de59ba9..a543b54 100644 --- a/webapp/src/components/SequenceNodes/index.stories.tsx +++ b/webapp/src/components/SequenceNodes/index.stories.tsx @@ -251,3 +251,50 @@ SubsequentIssue.args = { ...SubsequentIssue.args, sequence: [{ "$smType": "condition", "condition": "and", "condition_data": { "conditions": [{ "$smType": "condition", "condition": "numeric_state", "condition_data": { "entity_id": "sensor.temperature_kitchen", "below": "15" } }, { "$smType": "condition", "condition": "template", "condition_data": { "value_template": "states(switch.kitchen_light) == \"on\"" } }] } }, { "$smType": "action", "action": "service", "action_data": { "alias": "Start Music In Kitchen", "service": "media_player.play_media", "target": { "entity_id": "media_player.kitchen_dot" }, "data": { "media_content_id": "Good Morning", "media_content_type": "SPOTIFY" } } }, { "$smType": "action", "action": "choose", "action_data": { "choose": [], "default": [{ "$smType": "action", "action": "choose", "action_data": { "choose": [], "default": [] } }] } }, { "$smType": "action", "action": "choose", "action_data": { "choose": [], "default": [] } }, { "$smType": "action", "action": "choose", "action_data": { "choose": [], "default": [] } }] } + +export const ChooseNestingIssue = Template.bind({}) +ChooseNestingIssue.args = { + ...ChooseNestingIssue.args, + sequence: [ + { + "$smType": "condition", + "condition": "and", + "condition_data": { + "conditions": [ + { + "$smType": "condition", + "condition": "numeric_state", + "condition_data": { + "entity_id": "sensor.temperature_kitchen", + "below": "15" + } + }, + { + "$smType": "condition", + "condition": "template", + "condition_data": { + "value_template": "states(switch.kitchen_light) == \"on\"" + } + } + ] + } + }, + { + "$smType": "action", + "action": "choose", + "action_data": { + "choose": [], + "default": [ + { + "$smType": "action", + "action": "choose", + "action_data": { + "choose": [], + "default": [] + } + } + ] + } + } + ] +} diff --git a/webapp/src/components/SequenceNodes/index.tsx b/webapp/src/components/SequenceNodes/index.tsx index e2549cf..1e0512c 100644 --- a/webapp/src/components/SequenceNodes/index.tsx +++ b/webapp/src/components/SequenceNodes/index.tsx @@ -31,12 +31,16 @@ export const SequenceNodes: FC = (pro ...modalState.node.slice(i + 1), ]); setModalState(null) }} - onAdd={n => modalState.update([...modalState.node, n as any])} - onRemove={(i) => { + onAdd={(n, slide) => { + modalState.update([...modalState.node, n as any]); + slide(modalState.node.length) + }} + onRemove={(i, slide) => { modalState.update([ ...modalState.node.slice(0, i), ...modalState.node.slice(i + 1), ]); + slide(modalState.node.length - 2); }} allowedTypes={modalState.onlyConditions ? ['condition'] : ['action', 'condition']} /> diff --git a/webapp/src/components/SequenceNodes/positions.test.ts b/webapp/src/components/SequenceNodes/positions.test.ts new file mode 100644 index 0000000..97f3de4 --- /dev/null +++ b/webapp/src/components/SequenceNodes/positions.test.ts @@ -0,0 +1,10 @@ +import { computeNodesEdgesPos } from "./positions" + + +test('empty nodes', () => { + const onChange = () => {} + const openModal = () => { } + const out = Array.from(computeNodesEdgesPos([0, 0], [], onChange, openModal)); + expect(out).toHaveLength(0) +}) + diff --git a/webapp/src/components/SequenceNodes/positions.ts b/webapp/src/components/SequenceNodes/positions.ts index d1b61a9..48cc5a8 100644 --- a/webapp/src/components/SequenceNodes/positions.ts +++ b/webapp/src/components/SequenceNodes/positions.ts @@ -5,7 +5,6 @@ import { makeUpdater, Updater } from './updater'; import { ChooseAction } from 'types/automations/actions'; import { AutomationCondition } from "types/automations/conditions"; import { ModalState } from "./types"; -import { AutomationNode } from '../../types/automations/index'; export type UpdateModalState = ( s: ModalState @@ -131,7 +130,7 @@ function* dealWithChoose( // add new conditions const newCondLoc = offsetPoint( nodeLoc, - [1, node.action_data.choose.length + 1 + offset.y], + [1, node.action_data.choose.length + 3 + offset.y], ); yield { type: 'circle',