expandable choose node
This commit is contained in:
1 parent
0b381a6e50
commit
befe293f1c
7 files changed
+128
-46
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import { useState } from "react";
|
||||
import { AutomationNode } from "types/automations";
|
||||
|
||||
export type DAGNodeState = Partial<{
|
||||
isClosed: boolean;
|
||||
}>;
|
||||
export type DAGElementsState = ReturnType<typeof useDAGElementsState>;
|
||||
export const useDAGElementsState = () => {
|
||||
const [data, setData] = useState<Record<string, DAGNodeState>>({});
|
||||
console.log(data);
|
||||
return {
|
||||
get(nodeId: string): DAGNodeState {
|
||||
return data[nodeId] ?? {};
|
||||
},
|
||||
|
||||
set<K extends keyof DAGNodeState>(
|
||||
nodeId: string,
|
||||
key: K,
|
||||
value: DAGNodeState[K]
|
||||
) {
|
||||
setData({
|
||||
...data,
|
||||
[nodeId]: {
|
||||
...(data[nodeId] ?? {}),
|
||||
[key]: value,
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
getIsClosedActions(nodeId: string, node: AutomationNode) {
|
||||
if ("choose" in node) {
|
||||
return {
|
||||
isClosed: this.get(nodeId).isClosed ?? false,
|
||||
setIsClosed: (v: boolean) => this.set(nodeId, "isClosed", v),
|
||||
};
|
||||
}
|
||||
return {};
|
||||
},
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user