This commit is contained in:
ari committed 2022-06-06 11:27:25 -04:00
1 parent c934a4afcb
commit ac1ee86cc7
8 files changed
+98 -50

No files matched your search

+4 -2
View File
@@ -16,6 +16,7 @@ import { AutomationCondition } from "types/automations/conditions";
import { makeConditionPoint } from "./flowDataMods";
import { convertToFlowNode } from "./helpers";
import { DAGErrorNode } from "./DAGErrorNode";
import { useHA } from "haService";
const nodeTypes = {
'dagnode': convertToFlowNode(DAGNode),
@@ -57,10 +58,9 @@ export const DAGAutomationFlow: FC<DAGAutomationFlowProps> = ({
}) => {
// state
const [modalState, setModalState] = useState<ModalState | null>(null);
const { namer, } = useHA();
// modal
let modalBody = <></>
console.log(modalState)
if (modalState) {
if (modalState.single) {
modalBody = <NodeEditor
@@ -102,6 +102,7 @@ export const DAGAutomationFlow: FC<DAGAutomationFlowProps> = ({
edges: [],
}
triggerToFlow(flowData, trigger, condPoint.id, dims, {
namer,
onAdd: () => onTriggerUpdate([
...trigger, {
platform: 'event',
@@ -136,6 +137,7 @@ export const DAGAutomationFlow: FC<DAGAutomationFlowProps> = ({
y: dims.padding.y,
}
},
namer,
makeSequenceUpdater(sequence, onSequenceUpdate, setModalState),
);
// render
@@ -1,6 +1,6 @@
import { AutomationSequenceNode } from 'types/automations';
import { DAGAutomationFlowDims, FlowData } from './types';
import { getDescriptionFromAutomationNode } from 'utils/formatting';
import { getDescriptionFromAutomationNode, Namer } from 'utils/formatting';
import { XYPosition } from 'react-flow-renderer';
import { ChooseAction } from 'types/automations/actions';
import { makeFlowCircle } from './DAGCircle';
@@ -14,6 +14,7 @@ export const sequenceToFlow = (
sequence: AutomationSequenceNode[],
fromPoint: string,
dims: DAGAutomationFlowDims,
namer: Namer,
updater: SequenceUpdater,
prefix: string = "",
) => {
@@ -45,7 +46,7 @@ export const sequenceToFlow = (
if (getNodeType(node) === 'action') {
if ('choose' in node) {
try {
const out = addChooseNode(node, position, nodeId, dims, updater, i);
const out = addChooseNode(node, position, nodeId, dims, namer, updater, i);
position = out.lastPos
flowData = mergeFlowDatas(flowData, out.flowData);
} catch (err) {
@@ -55,13 +56,15 @@ export const sequenceToFlow = (
} else {
addSingleNode(flowData, node, position, nodeId, dims, {
onEditClick: updater.makeOnModalOpenForNode(i, node),
onXClick: () => updater.removeNode(i)
onXClick: () => updater.removeNode(i),
namer,
});
}
} else {
addSingleNode(flowData, node, position, nodeId, dims, {
onEditClick: updater.makeOnModalOpenForNode(i, node),
onXClick: () => updater.removeNode(i)
onXClick: () => updater.removeNode(i),
namer,
});
}
@@ -124,12 +127,13 @@ const addSingleNode = (
opts: {
onEditClick: () => void;
onXClick: () => void;
namer: Namer;
}
) => flowData.nodes.push({
id: nodeId,
type: 'dagnode',
data: {
label: getDescriptionFromAutomationNode(node),
label: getDescriptionFromAutomationNode(node, opts.namer),
height: nodeHeight,
width: nodeWidth,
color: getNodeType(node) === 'action' ? 'green' : 'blue',
@@ -171,6 +175,7 @@ const addChooseNode = (
position: XYPosition,
nodeId: string,
dims: DAGAutomationFlowDims,
namer: Namer,
updater: SequenceUpdater,
i: number,
) => {
@@ -181,6 +186,7 @@ const addChooseNode = (
addSingleNode(flowData, node, position, nodeId, dims, {
onEditClick: updater.makeOnModalOpenForNode(i, node),
onXClick: () => updater.removeNode(i),
namer,
});
let lastPos: XYPosition = position;
// conditions
@@ -230,7 +236,7 @@ const addChooseNode = (
x: condNode.position.x - (dims.nodeWidth + dims.conditionWidth),
y: condNode.position.y - dims.conditionHeight / 2,
},
}, updater.makeChildUpdaterForChooseAction(i, j), `${sequenceId}.`);
}, namer, updater.makeChildUpdaterForChooseAction(i, j), `${sequenceId}.`);
if (lastPoint.position) {
lastPos = xyApply(lastPos, lastPoint.position, Math.max)
} else {
@@ -290,7 +296,7 @@ const addChooseNode = (
x: position.x - dims.nodeWidth,
y: elseCircle.position.y - dims.circleSize / 4,
},
}, updater.makeChildUpdaterForChooseAction(i, null), `${nodeId}.${totalChildren}.`)
}, namer, updater.makeChildUpdaterForChooseAction(i, null), `${nodeId}.${totalChildren}.`)
if (lastPoint.position) {
lastPos = xyApply(lastPos, lastPoint.position, Math.max)
} else {
@@ -16,7 +16,6 @@ export const triggerToFlow = (
nodeWidth,
padding,
conditionHeight,
conditionWidth,
circleSize,
flipped,
} = dims;
@@ -27,7 +26,7 @@ export const triggerToFlow = (
id: flowId,
type: 'dagnode',
data: {
label: getDescriptionFromAutomationNode(t),
label: getDescriptionFromAutomationNode(t, opts.namer),
height: nodeHeight,
width: nodeWidth,
flipped,
+2
View File
@@ -5,6 +5,7 @@ import { DAGNodeProps } from './DAGNode';
import { AutomationTrigger } from 'types/automations/triggers';
import { MultiNodeEditorProps } from 'components/MultiNodeEditors/types';
import { DAGErrorNodeProps } from './DAGErrorNode';
import { Namer } from 'utils/formatting';
export type DAGAutomationFlowDims = {
@@ -28,6 +29,7 @@ export type TriggerMakerOptions = {
onAdd: () => void,
onEdit: (i: number) => void,
onDelete: (i: number) => void,
namer: Namer,
}
export type UpdateModalState<T extends AutomationSequenceNode | AutomationTrigger = any> = (
@@ -6,7 +6,7 @@ import { getNodeSubType, getSubTypeList, validateNode } from 'utils/automations'
import InputYaml from 'components/Inputs/InputYaml';
import InputText from 'components/Inputs/InputText';
import { getDescriptionFromAutomationNode } from 'utils/formatting';
import { useHAEntities } from 'haService';
import { useHA } from 'haService';
import { Generic } from './Generic';
import { getNodeTypeAndValidate } from '../../../utils/automations';
@@ -19,7 +19,7 @@ export const useEditorNodeState = (originalNode: AutomationNode, isErrored: bool
isModified: false,
...computeInvalidYaml(originalNode, allowedTypes)
});
const entities = useHAEntities();
const { entities, namer } = useHA();
// aliases
const { node: currentNode, isModified, yamlMode, invalidManualYaml } = allState;
// effects
@@ -88,7 +88,7 @@ export const useEditorNodeState = (originalNode: AutomationNode, isErrored: bool
aliasEditor = <InputText
key="alias"
label="Alias"
value={getDescriptionFromAutomationNode(allState.node)}
value={getDescriptionFromAutomationNode(allState.node, namer)}
onChange={alias => setState({
...allState.node,
alias