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: update node alert to detect outdated components #3051

Merged
merged 6 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { componentsToIgnoreUpdate } from "@/constants/constants";
import { useEffect } from "react";
import { NodeDataType } from "../../types/flow";
import { nodeNames } from "../../utils/styleUtils";
Expand All @@ -16,13 +17,11 @@ const useCheckCodeValidity = (
if (!data?.node || !templates) return;
const currentCode = templates[data.type]?.template?.code?.value;
const thisNodesCode = data.node!.template?.code?.value;
const componentsToIgnore = ["CustomComponent"];
setIsOutdated(
currentCode &&
thisNodesCode &&
currentCode !== thisNodesCode &&
!componentsToIgnore.includes(data.type) &&
Object.keys(nodeNames).includes(types[data.type]),
!componentsToIgnoreUpdate.includes(data.type),
);
setIsUserEdited(data.node?.edited ?? false);
// template.code can be undefined
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,8 @@ export const MODAL_CLASSES =

export const ALLOWED_IMAGE_INPUT_EXTENSIONS = ["png", "jpg", "jpeg"];

export const componentsToIgnoreUpdate = ["CustomComponent"];

export const FS_ERROR_TEXT =
"Please ensure your file has one of the following extensions:";
export const SN_ERROR_TEXT = ALLOWED_IMAGE_INPUT_EXTENSIONS.join(", ");
Expand Down
31 changes: 29 additions & 2 deletions src/frontend/src/stores/flowStore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { BROKEN_EDGES_WARNING } from "@/constants/constants";
import {
BROKEN_EDGES_WARNING,
componentsToIgnoreUpdate,
} from "@/constants/constants";
import { brokenEdgeMessage } from "@/utils/utils";
import { cloneDeep, zip } from "lodash";
import {
Expand Down Expand Up @@ -44,9 +47,27 @@ import useAlertStore from "./alertStore";
import { useDarkStore } from "./darkStore";
import useFlowsManagerStore from "./flowsManagerStore";
import { useGlobalVariablesStore } from "./globalVariablesStore/globalVariables";
import { useTypesStore } from "./typesStore";

// this is our useStore hook that we can use in our components to get parts of the store and call actions
const useFlowStore = create<FlowStoreType>((set, get) => ({
componentsToUpdate: false,
updateComponentsToUpdate: (nodes) => {
let outdatedNodes = false;
const templates = useTypesStore.getState().templates;
for (let i = 0; i < nodes.length; i++) {
const currentCode = templates[nodes[i].data?.type]?.template?.code?.value;
const thisNodesCode = nodes[i].data?.node!.template?.code?.value;
outdatedNodes =
currentCode &&
thisNodesCode &&
currentCode !== thisNodesCode &&
!nodes[i].data?.node?.edited &&
!componentsToIgnoreUpdate.includes(nodes[i].data?.type);
if (outdatedNodes) break;
}
set({ componentsToUpdate: outdatedNodes });
},
onFlowPage: false,
lockChat: false,
setLockChat: (lockChat) => {
Expand Down Expand Up @@ -143,6 +164,7 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
}
let newEdges = cleanEdges(nodes, edges);
const { inputs, outputs } = getInputsAndOutputs(nodes);
get().updateComponentsToUpdate(nodes);
set({
nodes,
edges: newEdges,
Expand Down Expand Up @@ -188,7 +210,7 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
let newChange = typeof change === "function" ? change(get().nodes) : change;
let newEdges = cleanEdges(newChange, get().edges);
const { inputs, outputs } = getInputsAndOutputs(newChange);

get().updateComponentsToUpdate(newChange);
set({
edges: newEdges,
nodes: newChange,
Expand Down Expand Up @@ -633,6 +655,11 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
.map((element) => element.id)
.filter(Boolean) as string[];
useFlowStore.getState().updateBuildStatus(idList, BuildStatus.BUILT);
if (get().componentsToUpdate)
setErrorData({
title:
"There are outdated components in the flow. The error may be related.",
});
anovazzi1 marked this conversation as resolved.
Show resolved Hide resolved
setErrorData({ list, title });
get().setIsBuilding(false);
get().setLockChat(false);
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/src/types/zustand/flow/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export type FlowPoolType = {
};

export type FlowStoreType = {
componentsToUpdate: boolean;
updateComponentsToUpdate: (nodes: Node[]) => void;
onFlowPage: boolean;
setOnFlowPage: (onFlowPage: boolean) => void;
flowPool: FlowPoolType;
Expand Down
Loading