- refactor for multi-config suport done
- added better errror captures
This commit is contained in:
1 parent
55ea1e23a4
commit
c67d1bd32f
32 files changed
+991
-835
No files matched your search
@@ -53,7 +53,7 @@ const { make, componentMeta } = makeStory({
|
||||
automation: {
|
||||
trigger: [],
|
||||
condition: [],
|
||||
sequence: [],
|
||||
action: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -74,7 +74,7 @@ export const Trigger = make({
|
||||
},
|
||||
],
|
||||
condition: [],
|
||||
sequence: [],
|
||||
action: [],
|
||||
},
|
||||
});
|
||||
|
||||
@@ -110,7 +110,7 @@ export const Conditions = make({
|
||||
below: "15",
|
||||
},
|
||||
],
|
||||
sequence: [],
|
||||
action: [],
|
||||
},
|
||||
});
|
||||
|
||||
@@ -151,7 +151,7 @@ export const FullAuto = make({
|
||||
bad: "node",
|
||||
} as any,
|
||||
],
|
||||
sequence: [
|
||||
action: [
|
||||
{
|
||||
condition: "and",
|
||||
conditions: [
|
||||
@@ -269,7 +269,7 @@ export const ChooseAuto = make({
|
||||
automation: {
|
||||
condition: [],
|
||||
trigger: [],
|
||||
sequence: [
|
||||
action: [
|
||||
{
|
||||
choose: [
|
||||
{
|
||||
@@ -365,7 +365,7 @@ export const EmptyChooseAuto = make({
|
||||
automation: {
|
||||
condition: [],
|
||||
trigger: [],
|
||||
sequence: [
|
||||
action: [
|
||||
{
|
||||
choose: [],
|
||||
default: [],
|
||||
@@ -378,7 +378,7 @@ export const RepeatAuto = make({
|
||||
automation: {
|
||||
condition: [],
|
||||
trigger: [],
|
||||
sequence: [
|
||||
action: [
|
||||
{
|
||||
repeat: {
|
||||
while: 'states(lights.switch) == "on"',
|
||||
@@ -427,7 +427,7 @@ export const ParallelAuto = make({
|
||||
automation: {
|
||||
condition: [],
|
||||
trigger: [],
|
||||
sequence: [
|
||||
action: [
|
||||
{
|
||||
parallel: [
|
||||
{
|
||||
@@ -469,7 +469,7 @@ export const BadNodes = make({
|
||||
{ condition: "and" },
|
||||
"text?",
|
||||
] as any,
|
||||
sequence: [
|
||||
action: [
|
||||
{
|
||||
parallel: {
|
||||
bad: "me",
|
||||
@@ -486,7 +486,7 @@ export const IfElseNode = make({
|
||||
automation: {
|
||||
condition: [],
|
||||
trigger: [],
|
||||
sequence: [
|
||||
action: [
|
||||
{
|
||||
if: [],
|
||||
else: [],
|
||||
@@ -508,7 +508,7 @@ export const TimeNodes = make({
|
||||
platform: "time_pattern",
|
||||
},
|
||||
],
|
||||
sequence: [
|
||||
action: [
|
||||
{
|
||||
condition: "time",
|
||||
},
|
||||
|
||||
@@ -63,7 +63,7 @@ export const useAutomationNodes = (
|
||||
);
|
||||
|
||||
outputState.extend(
|
||||
makeSequenceNodes(automation.sequence, {
|
||||
makeSequenceNodes(automation.action, {
|
||||
...args,
|
||||
state,
|
||||
dims,
|
||||
@@ -74,7 +74,7 @@ export const useAutomationNodes = (
|
||||
dims,
|
||||
true
|
||||
),
|
||||
nodeId: `${dims.flipped}-sequence`,
|
||||
nodeId: `${dims.flipped}-action`,
|
||||
nodeIndex: 2,
|
||||
lastNodeId: outputState.lastNodeId,
|
||||
})
|
||||
@@ -98,7 +98,7 @@ export const makeSequenceNodes: ElementMaker<AutomationSequenceNode> = (
|
||||
enabled: node.enabled ?? true,
|
||||
label: getDescriptionFromAutomationNode(node, namer, true),
|
||||
...state.getIsClosedActions(nodeId, node),
|
||||
...stateUpdater.createNodeActions("sequence", nodeIndex, {
|
||||
...stateUpdater.createNodeActions("action", nodeIndex, {
|
||||
includeAdd: true,
|
||||
flipped: dims.flipped,
|
||||
}),
|
||||
@@ -153,7 +153,7 @@ export const makeSequenceNodes: ElementMaker<AutomationSequenceNode> = (
|
||||
dims,
|
||||
{
|
||||
icon: <AddIcon />,
|
||||
onClick: () => stateUpdater.basic.sequence.addNode(null),
|
||||
onClick: () => stateUpdater.basic.action.addNode(null),
|
||||
}
|
||||
),
|
||||
true
|
||||
@@ -261,7 +261,7 @@ export const makeChooseeNodes = makeSpecialNodeMaker(
|
||||
nodeId: args.nodeId,
|
||||
position: pos,
|
||||
onClick: () =>
|
||||
args.stateUpdater.basic.sequence.updateNode(
|
||||
args.stateUpdater.basic.action.updateNode(
|
||||
{
|
||||
...node,
|
||||
choose: [
|
||||
@@ -464,10 +464,10 @@ export const makeParallelNodes = makeSpecialNodeMaker(
|
||||
onClick: () =>
|
||||
args.openModal({
|
||||
allowedTypes: ["condition", "action"],
|
||||
node: args.stateUpdater.basic.sequence.defaultNode,
|
||||
node: args.stateUpdater.basic.action.defaultNode,
|
||||
saveBtnCreateText: true,
|
||||
update: (n) =>
|
||||
args.stateUpdater.basic.sequence.updateNode(
|
||||
args.stateUpdater.basic.action.updateNode(
|
||||
{
|
||||
...node,
|
||||
parallel: [...node.parallel, n],
|
||||
|
||||
@@ -10,10 +10,10 @@ import { AutomationTrigger } from "types/automations/triggers";
|
||||
import { AutomationCondition } from "types/automations/conditions";
|
||||
|
||||
export const DAGAutomationGraph: FC<{
|
||||
sequence: AutomationSequenceNode[];
|
||||
action: AutomationSequenceNode[];
|
||||
trigger: AutomationTrigger[];
|
||||
condition: AutomationCondition[];
|
||||
onSequenceUpdate: (s: AutomationSequenceNode[]) => void;
|
||||
onActionUpdate: (s: AutomationSequenceNode[]) => void;
|
||||
onTriggerUpdate: (t: AutomationTrigger[]) => void;
|
||||
onConditionUpdate: (c: AutomationCondition[]) => void;
|
||||
isFlipped: boolean;
|
||||
@@ -24,9 +24,9 @@ export const DAGAutomationGraph: FC<{
|
||||
useState<ModalState | undefined>(undefined);
|
||||
const updater = createUpdater({
|
||||
openModal: setModalState,
|
||||
sequence: {
|
||||
data: props.sequence,
|
||||
onUpdate: props.onSequenceUpdate,
|
||||
action: {
|
||||
data: props.action,
|
||||
onUpdate: props.onActionUpdate,
|
||||
},
|
||||
condition: {
|
||||
data: props.condition,
|
||||
@@ -39,7 +39,7 @@ export const DAGAutomationGraph: FC<{
|
||||
});
|
||||
const elementData = useAutomationNodes(
|
||||
{
|
||||
sequence: props.sequence,
|
||||
action: props.action,
|
||||
condition: props.condition,
|
||||
trigger: props.trigger,
|
||||
},
|
||||
|
||||
@@ -10,7 +10,7 @@ export const CollectionNodeMaker = NodeManager.register(
|
||||
...pre,
|
||||
color: (pre.collectionType === "condition"
|
||||
? "blue"
|
||||
: pre.collectionType === "sequence"
|
||||
: pre.collectionType === "action"
|
||||
? "green"
|
||||
: "red") as SequenceNodeColor,
|
||||
sequenceNode: node,
|
||||
|
||||
@@ -93,13 +93,13 @@ export type DAGGraphChooseUpdater = ReturnType<
|
||||
DAGGraphUpdater["createChoosNodeUpdater"]
|
||||
>;
|
||||
export const createUpdater = (
|
||||
args: DAGUpdaterArgs<"sequence" | "condition" | "trigger">
|
||||
args: DAGUpdaterArgs<"action" | "condition" | "trigger">
|
||||
) => {
|
||||
const basic = {
|
||||
sequence: createBasicUpdater("sequence", {
|
||||
action: createBasicUpdater("action", {
|
||||
device_id: "",
|
||||
})({
|
||||
sequence: args.sequence,
|
||||
action: args.action,
|
||||
openModal: args.openModal,
|
||||
}),
|
||||
trigger: createBasicUpdater("trigger", {
|
||||
@@ -179,7 +179,7 @@ export const createUpdater = (
|
||||
},
|
||||
createChoosNodeUpdater(i: number, j: number | "else") {
|
||||
const node = convertChooseActionToOrignal(
|
||||
args.sequence.data[i] as ChooseAction
|
||||
args.action.data[i] as ChooseAction
|
||||
);
|
||||
if (j === "else") {
|
||||
return {
|
||||
@@ -189,10 +189,10 @@ export const createUpdater = (
|
||||
data: [],
|
||||
onUpdate: console.warn,
|
||||
},
|
||||
sequence: {
|
||||
action: {
|
||||
data: node.default ?? [],
|
||||
onUpdate: (upd) =>
|
||||
basic.sequence.updateNode(
|
||||
basic.action.updateNode(
|
||||
{
|
||||
...node,
|
||||
default: upd,
|
||||
@@ -210,7 +210,7 @@ export const createUpdater = (
|
||||
} else {
|
||||
return {
|
||||
onRemove: () =>
|
||||
basic.sequence.updateNode(
|
||||
basic.action.updateNode(
|
||||
{
|
||||
...node,
|
||||
choose: [
|
||||
@@ -225,7 +225,7 @@ export const createUpdater = (
|
||||
condition: {
|
||||
data: node.choose[j].conditions,
|
||||
onUpdate: (upd: any) =>
|
||||
basic.sequence.updateNode(
|
||||
basic.action.updateNode(
|
||||
{
|
||||
...node,
|
||||
choose: [
|
||||
@@ -240,10 +240,10 @@ export const createUpdater = (
|
||||
i
|
||||
),
|
||||
},
|
||||
sequence: {
|
||||
action: {
|
||||
data: node.choose[j].sequence,
|
||||
onUpdate: (upd) =>
|
||||
basic.sequence.updateNode(
|
||||
basic.action.updateNode(
|
||||
{
|
||||
...node,
|
||||
choose: [
|
||||
@@ -267,11 +267,11 @@ export const createUpdater = (
|
||||
}
|
||||
},
|
||||
createRepeatNodeUpdater(i: number) {
|
||||
const { repeat, ...rest } = args.sequence.data[i] as RepeatAction;
|
||||
const sequence = {
|
||||
const { repeat, ...rest } = args.action.data[i] as RepeatAction;
|
||||
const action = {
|
||||
data: repeat.sequence,
|
||||
onUpdate: (upd: AutomationNode[]) =>
|
||||
basic.sequence.updateNode(
|
||||
basic.action.updateNode(
|
||||
{
|
||||
...rest,
|
||||
repeat: {
|
||||
@@ -291,7 +291,7 @@ export const createUpdater = (
|
||||
repeat.while
|
||||
),
|
||||
onUpdate: (upd: any) =>
|
||||
basic.sequence.updateNode(
|
||||
basic.action.updateNode(
|
||||
{
|
||||
...rest,
|
||||
repeat: {
|
||||
@@ -303,7 +303,7 @@ export const createUpdater = (
|
||||
),
|
||||
},
|
||||
trigger: createDummyUpdater(),
|
||||
sequence,
|
||||
action,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -315,7 +315,7 @@ export const createUpdater = (
|
||||
repeat.until
|
||||
),
|
||||
onUpdate: (upd: any) =>
|
||||
basic.sequence.updateNode(
|
||||
basic.action.updateNode(
|
||||
{
|
||||
...rest,
|
||||
repeat: {
|
||||
@@ -327,7 +327,7 @@ export const createUpdater = (
|
||||
),
|
||||
},
|
||||
trigger: createDummyUpdater(),
|
||||
sequence,
|
||||
action,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -335,16 +335,16 @@ export const createUpdater = (
|
||||
openModal: args.openModal,
|
||||
condition: createDummyUpdater(),
|
||||
trigger: createDummyUpdater(),
|
||||
sequence,
|
||||
action,
|
||||
});
|
||||
},
|
||||
createParallelNodeUpdater(i: number, j: number) {
|
||||
const { parallel, ...rest } = args.sequence.data[i] as ParallelAction;
|
||||
const { parallel, ...rest } = args.action.data[i] as ParallelAction;
|
||||
const child = parallel[j];
|
||||
|
||||
return {
|
||||
onRemove: () =>
|
||||
basic.sequence.updateNode(
|
||||
basic.action.updateNode(
|
||||
{
|
||||
...rest,
|
||||
parallel: [...parallel.slice(0, j), ...parallel.slice(j + 1)],
|
||||
@@ -355,10 +355,10 @@ export const createUpdater = (
|
||||
openModal: args.openModal,
|
||||
condition: createDummyUpdater(),
|
||||
trigger: createDummyUpdater(),
|
||||
sequence: {
|
||||
action: {
|
||||
data: "sequence" in child ? child.sequence : [child],
|
||||
onUpdate(d) {
|
||||
basic.sequence.updateNode(
|
||||
basic.action.updateNode(
|
||||
{
|
||||
...rest,
|
||||
parallel: [
|
||||
@@ -383,12 +383,12 @@ export const createUpdaterFromAutomationData = (
|
||||
onUpdate: (a: AutomationActionData) => void
|
||||
): DAGGraphUpdater =>
|
||||
createUpdater({
|
||||
sequence: {
|
||||
data: auto.sequence,
|
||||
action: {
|
||||
data: auto.action,
|
||||
onUpdate: (s: AutomationSequenceNode[]) =>
|
||||
onUpdate({
|
||||
...auto,
|
||||
sequence: s,
|
||||
action: s,
|
||||
}),
|
||||
},
|
||||
condition: {
|
||||
|
||||
Reference in new issue
Block a user