resizeable collection nodes
This commit is contained in:
1 parent
7483f2b65d
commit
1d7b6e96c1
4 files changed
+234
-39
No files matched your search
@@ -121,3 +121,156 @@ Conditions.args = {
|
||||
sequence: [],
|
||||
},
|
||||
};
|
||||
|
||||
export const FullAuto = Template.bind({});
|
||||
FullAuto.args = {
|
||||
...FullAuto.args,
|
||||
automation: {
|
||||
condition: [
|
||||
{
|
||||
condition: "and",
|
||||
conditions: [
|
||||
{
|
||||
condition: "numeric_state",
|
||||
entity_id: "sensor.temperature_kitchen",
|
||||
below: "15",
|
||||
},
|
||||
{
|
||||
condition: "template",
|
||||
value_template: 'states(switch.kitchen_light) == "on"',
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
{
|
||||
condition: "numeric_state",
|
||||
entity_id: "sensor.temperature_kitchen",
|
||||
below: "15",
|
||||
},
|
||||
],
|
||||
trigger: [
|
||||
{
|
||||
platform: "numeric_state",
|
||||
entity_id: "test",
|
||||
},
|
||||
{
|
||||
platform: "homeassistant",
|
||||
event: "start",
|
||||
},
|
||||
{
|
||||
bad: "node",
|
||||
} as any,
|
||||
],
|
||||
sequence: [
|
||||
{
|
||||
condition: "and",
|
||||
conditions: [
|
||||
{
|
||||
condition: "numeric_state",
|
||||
entity_id: "sensor.temperature_kitchen",
|
||||
below: "15",
|
||||
},
|
||||
{
|
||||
condition: "template",
|
||||
value_template: 'states(switch.kitchen_light) == "on"',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
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",
|
||||
},
|
||||
},
|
||||
{
|
||||
alias: "Bad Node",
|
||||
},
|
||||
{
|
||||
choose: [
|
||||
{
|
||||
conditions: [
|
||||
{
|
||||
condition: "state",
|
||||
entity_id: "lights.bathroom",
|
||||
state: "off",
|
||||
},
|
||||
],
|
||||
sequence: [
|
||||
{
|
||||
service: "light.turn_on",
|
||||
target: {
|
||||
entity_id: "lights.bathroom",
|
||||
},
|
||||
data: {},
|
||||
},
|
||||
{
|
||||
alias: "Turn off bedroom",
|
||||
service: "light.turn_off",
|
||||
target: {
|
||||
entity_id: "lights.bedroom",
|
||||
},
|
||||
data: {},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
conditions: [
|
||||
{
|
||||
condition: "state",
|
||||
entity_id: "lights.bedroom",
|
||||
state: "off",
|
||||
},
|
||||
],
|
||||
sequence: [
|
||||
{
|
||||
alias: "Turn on bedroom",
|
||||
service: "light.turn_on",
|
||||
target: {
|
||||
entity_id: "lights.bedroom",
|
||||
},
|
||||
data: {},
|
||||
},
|
||||
{
|
||||
choose: [
|
||||
{
|
||||
conditions: [],
|
||||
sequence: [
|
||||
{
|
||||
choose: [],
|
||||
default: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
default: [
|
||||
{
|
||||
choose: [],
|
||||
default: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
default: [
|
||||
{
|
||||
service: "light.turn_off",
|
||||
target: {
|
||||
entity_id: "lights.bathroom",
|
||||
},
|
||||
data: {},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
condition: "and",
|
||||
conditions: [],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -7,7 +7,10 @@ import {
|
||||
import { AutomationTrigger } from "types/automations/triggers";
|
||||
import * as distance from "./distance";
|
||||
import { getDescriptionFromAutomationNode } from "utils/formatting";
|
||||
import { AutomationActionData } from "types/automations";
|
||||
import {
|
||||
AutomationActionData,
|
||||
AutomationSequenceNode,
|
||||
} from "types/automations";
|
||||
import { AutomationCondition } from "types/automations/conditions";
|
||||
import { CollectionNodeMaker } from "../nodes/CollectionNode";
|
||||
|
||||
@@ -26,7 +29,7 @@ export const makeAutomationNodes = (
|
||||
nodeIndex: 0,
|
||||
});
|
||||
|
||||
const condOut = makeConditionNodes(automation.condition, {
|
||||
state = makeConditionNodes(automation.condition, {
|
||||
...args,
|
||||
elementData: state.elementData,
|
||||
position: distance.moveFromTo(
|
||||
@@ -40,7 +43,21 @@ export const makeAutomationNodes = (
|
||||
lastNodeId: state.lastNode.nodeId,
|
||||
});
|
||||
|
||||
return condOut.elementData;
|
||||
state = makeSequenceNodes(automation.sequence, {
|
||||
...args,
|
||||
elementData: state.elementData,
|
||||
position: distance.moveFromTo(
|
||||
"condition",
|
||||
"node",
|
||||
state.lastNode.pos,
|
||||
args.dims
|
||||
),
|
||||
nodeId: `${args.dims.flipped}-sequence`,
|
||||
nodeIndex: 2,
|
||||
lastNodeId: state.lastNode.nodeId,
|
||||
});
|
||||
|
||||
return state.elementData;
|
||||
};
|
||||
|
||||
export const makeTriggerNodes: ElementMaker<AutomationTrigger> = (
|
||||
@@ -73,16 +90,7 @@ export const makeTriggerNodes: ElementMaker<AutomationTrigger> = (
|
||||
|
||||
export const makeConditionNodes: ElementMaker<AutomationCondition> = (
|
||||
nodes,
|
||||
{
|
||||
elementData,
|
||||
nodeId,
|
||||
stateUpdater,
|
||||
position,
|
||||
dims,
|
||||
namer,
|
||||
openModal,
|
||||
lastNodeId,
|
||||
}
|
||||
{ elementData, nodeId, stateUpdater, position, dims, namer, lastNodeId }
|
||||
) => {
|
||||
elementData.nodes.push(
|
||||
CollectionNodeMaker.makeElement({ id: nodeId, position }, dims, {
|
||||
@@ -103,6 +111,7 @@ export const makeConditionNodes: ElementMaker<AutomationCondition> = (
|
||||
elementData.edges.push({
|
||||
source: lastNodeId,
|
||||
target: elementData.nodes[elementData.nodes.length - 1].id,
|
||||
animated: true,
|
||||
id: `${lastNodeId}->${
|
||||
elementData.nodes[elementData.nodes.length - 1].id
|
||||
}`,
|
||||
@@ -113,7 +122,21 @@ export const makeConditionNodes: ElementMaker<AutomationCondition> = (
|
||||
lastNode: {
|
||||
nodeId,
|
||||
pos: elementData.nodes[elementData.nodes.length - 1].position,
|
||||
size: dims.trigger,
|
||||
size: dims.condition,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const makeSequenceNodes: ElementMaker<AutomationSequenceNode> = (
|
||||
nodes,
|
||||
{ nodeId, elementData, dims }
|
||||
) => {
|
||||
return {
|
||||
elementData,
|
||||
lastNode: {
|
||||
nodeId,
|
||||
pos: elementData.nodes[elementData.nodes.length - 1].position,
|
||||
size: dims.node,
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -1,11 +1,26 @@
|
||||
.collection-nodes {
|
||||
.collection-nodes--wrap {
|
||||
--padding: 1.5em;
|
||||
/* outline: 1px dotted white; */
|
||||
|
||||
min-width: var(--node-width);
|
||||
min-height: var(--node-height);
|
||||
max-width: var(--node-width);
|
||||
max-height: var(--node-height);
|
||||
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.collection-nodes {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
gap: 1.5em;
|
||||
max-width: var(--node-width);
|
||||
max-height: var(--node-height);
|
||||
|
||||
border-color: var(--node-color);
|
||||
border-style: solid;
|
||||
@@ -13,4 +28,8 @@
|
||||
border-radius: 10px;
|
||||
overflow: auto;
|
||||
padding: var(--padding);
|
||||
}
|
||||
|
||||
.collection-nodes .react-flow__handle {
|
||||
opacity: 0;
|
||||
}
|
||||
@@ -22,37 +22,37 @@ export const CollectionNode: FC<CollectionNodeProps> = ({
|
||||
|
||||
return (
|
||||
<div
|
||||
className="collection-nodes"
|
||||
className="collection-nodes--wrap"
|
||||
style={
|
||||
{
|
||||
"--node-color": nodeColor,
|
||||
minHeight: `calc(${height}px - 2*var(--padding))`,
|
||||
minWidth: `calc(${width}px - 2*var(--padding))`,
|
||||
maxHeight: `calc(${height}px - 2*var(--padding))`,
|
||||
maxWidth: `calc(${width}px - 2*var(--padding))`,
|
||||
"--node-height": `calc(${height}px - 2*var(--padding))`,
|
||||
"--node-width": `calc(${width}px - 2*var(--padding))`,
|
||||
} as any
|
||||
}
|
||||
>
|
||||
{nodes.map((n, i) => (
|
||||
<SequenceNodeElement
|
||||
{...n}
|
||||
{...sequenceNode}
|
||||
key={i}
|
||||
color={color}
|
||||
flipped={flipped}
|
||||
/>
|
||||
))}
|
||||
<ButtonIcon icon={<Add />} onClick={onAddNode} />
|
||||
<Handle
|
||||
type="source"
|
||||
position={flipped ? Position.Bottom : Position.Right}
|
||||
/>
|
||||
{hasInput && (
|
||||
<div className="collection-nodes">
|
||||
{nodes.map((n, i) => (
|
||||
<SequenceNodeElement
|
||||
{...n}
|
||||
{...sequenceNode}
|
||||
key={i}
|
||||
color={color}
|
||||
flipped={flipped}
|
||||
/>
|
||||
))}
|
||||
<ButtonIcon icon={<Add />} onClick={onAddNode} />
|
||||
<Handle
|
||||
type="target"
|
||||
position={flipped ? Position.Top : Position.Left}
|
||||
type="source"
|
||||
position={flipped ? Position.Bottom : Position.Right}
|
||||
/>
|
||||
)}
|
||||
{hasInput && (
|
||||
<Handle
|
||||
type="target"
|
||||
position={flipped ? Position.Top : Position.Left}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
Reference in new issue
Block a user