Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Implement useFlowUpdate hook and refactor node code management #4783

Merged
merged 5 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/frontend/src/modals/codeAreaModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import "ace-builds/src-noconflict/theme-twilight";
// import "ace-builds/webpack-resolver";
import { usePostValidateCode } from "@/controllers/API/queries/nodes/use-post-validate-code";
import { usePostValidateComponentCode } from "@/controllers/API/queries/nodes/use-post-validate-component-code";
import useFlowStore from "@/stores/flowStore";
import { cloneDeep } from "lodash";
import { useEffect, useRef, useState } from "react";
import AceEditor from "react-ace";
import ReactAce from "react-ace/lib/ace";
Expand Down Expand Up @@ -40,6 +42,7 @@ export default function CodeAreaModal({
readonly = false,
open: myOpen,
setOpen: mySetOpen,
componentId,
}: codeAreaModalPropsType): JSX.Element {
const [code, setCode] = useState(value);
const [open, setOpen] =
Expand All @@ -58,6 +61,9 @@ export default function CodeAreaModal({
} | null>(null);

const { mutate: validateComponentCode } = usePostValidateComponentCode();
const currentFlow = useFlowStore((state) => state.currentFlow);
const nodes = useFlowStore((state) => state.nodes);
const setNodes = useFlowStore((state) => state.setNodes);

useEffect(() => {
// if nodeClass.template has more fields other than code and dynamic is true
Expand Down Expand Up @@ -120,6 +126,17 @@ export default function CodeAreaModal({
if (data && type) {
setValue(code);
setNodeClass(data, type);
const currentNode = nodes.find((node) => node.id === componentId);
const currentNodeIndex = nodes.findIndex(
(node) => node.id === componentId,
);
const currentNodes = cloneDeep(nodes);

if (currentNode) {
currentNodes[currentNodeIndex].data.node = data;
}
setNodes(currentNodes);

setError({ detail: { error: undefined, traceback: undefined } });
setOpen(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ export default function NodeToolbarComponent({
}}
nodeClass={data.node}
value={data.node?.template[name].value ?? ""}
componentId={data.id}
>
<></>
</CodeAreaModal>
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/types/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ export type codeAreaModalPropsType = {
readonly?: boolean;
open?: boolean;
setOpen?: (open: boolean) => void;
componentId?: string;
};

export type chatMessagePropsType = {
Expand Down
Loading