Fix and updateNodeOnScreen

This commit is contained in:
anovazzi1 2024-03-11 17:59:18 -03:00
commit 52df90c110
5 changed files with 8 additions and 33 deletions

View file

@ -47,11 +47,7 @@ export default function GenericNode({
const flowPool = useFlowStore((state) => state.flowPool); const flowPool = useFlowStore((state) => state.flowPool);
const buildFlow = useFlowStore((state) => state.buildFlow); const buildFlow = useFlowStore((state) => state.buildFlow);
const setNode = useFlowStore((state) => state.setNode); const setNode = useFlowStore((state) => state.setNode);
const addToOutdatedNodes = useFlowStore((state) => state.addToOutdatedNodes);
const updateNodeInternals = useUpdateNodeInternals(); const updateNodeInternals = useUpdateNodeInternals();
const removeFromOutdatedNodes = useFlowStore(
(state) => state.removeFromOutdatedNodes
);
const setErrorData = useAlertStore((state) => state.setErrorData); const setErrorData = useAlertStore((state) => state.setErrorData);
const name = nodeIconsLucide[data.type] ? data.type : types[data.type]; const name = nodeIconsLucide[data.type] ? data.type : types[data.type];
const [inputName, setInputName] = useState(false); const [inputName, setInputName] = useState(false);
@ -79,20 +75,16 @@ export default function GenericNode({
// This one should run only once // This one should run only once
// first check if data.type in NATIVE_CATEGORIES // first check if data.type in NATIVE_CATEGORIES
// if not return // if not return
if (!NATIVE_CATEGORIES.includes(types[data.type])) return; if (!NATIVE_CATEGORIES.includes(types[data.type]) || !data.node?.template?.code?.value) return;
const thisNodeTemplate = templates[data.type].template; const thisNodeTemplate = templates[data.type].template;
// if the template does not have a code key // if the template does not have a code key
// return // return
if (!thisNodeTemplate.code) return; if (!thisNodeTemplate.code) return;
const currentCode = thisNodeTemplate.code?.value; const currentCode = thisNodeTemplate.code?.value;
const thisNodesCode = data.node!.template?.code?.value; const thisNodesCode = data.node!.template?.code?.value;
if (currentCode !== thisNodesCode) { if (currentCode !== thisNodesCode) {
addToOutdatedNodes(data.id);
setIsOutdated(true); setIsOutdated(true);
} else { } else {
// remove the node from the outdatedNodes
removeFromOutdatedNodes(data.id);
setIsOutdated(false); setIsOutdated(false);
} }
// template.code can be undefined // template.code can be undefined
@ -111,13 +103,14 @@ export default function GenericNode({
}; };
newNode.data.node.template[name].value = code; newNode.data.node.template[name].value = code;
setIsOutdated(false);
return newNode; return newNode;
}); });
updateNodeInternals(data.id); updateNodeInternals(data.id);
}, },
[data.id, data.node, setNode] [data.id, data.node, setNode,setIsOutdated]
); );
if (!data.node!.template) { if (!data.node!.template) {
@ -361,6 +354,7 @@ export default function GenericNode({
openAdvancedModal={false} openAdvancedModal={false}
onCloseAdvancedModal={() => {}} onCloseAdvancedModal={() => {}}
updateNodeCode={updateNodeCode} updateNodeCode={updateNodeCode}
isOutdated={isOutdated}
selected={selected} selected={selected}
></NodeToolbarComponent> ></NodeToolbarComponent>
</NodeToolbar> </NodeToolbar>

View file

@ -43,6 +43,7 @@ export default function NodeToolbarComponent({
updateNodeCode, updateNodeCode,
setShowState, setShowState,
onCloseAdvancedModal, onCloseAdvancedModal,
isOutdated,
}: nodeToolbarPropsType): JSX.Element { }: nodeToolbarPropsType): JSX.Element {
const nodeLength = Object.keys(data.node!.template).filter( const nodeLength = Object.keys(data.node!.template).filter(
(templateField) => (templateField) =>
@ -83,9 +84,6 @@ export default function NodeToolbarComponent({
const [showModalAdvanced, setShowModalAdvanced] = useState(false); const [showModalAdvanced, setShowModalAdvanced] = useState(false);
const [showconfirmShare, setShowconfirmShare] = useState(false); const [showconfirmShare, setShowconfirmShare] = useState(false);
const [showOverrideModal, setShowOverrideModal] = useState(false); const [showOverrideModal, setShowOverrideModal] = useState(false);
const isOutdated = useFlowStore((state) => state.outDatedNodes).includes(
data.id
);
const [flowComponent, setFlowComponent] = useState<FlowType>(); const [flowComponent, setFlowComponent] = useState<FlowType>();
const openInNewTab = (url) => { const openInNewTab = (url) => {

View file

@ -581,21 +581,6 @@ const useFlowStore = create<FlowStoreType>((set, get) => ({
} }
}); });
}, },
outDatedNodes: [],
addToOutdatedNodes: (nodeId) => {
// add the nodes to the list of outdated nodes
// without removing the previous ones
let oldOutDatedNodes = get().outDatedNodes;
// filter out the nodes that are already in the list
if (!oldOutDatedNodes.includes(nodeId)) {
set({ outDatedNodes: [...oldOutDatedNodes, nodeId] });
}
},
removeFromOutdatedNodes: (nodeId) => {
// remove the nodes from the list of outdated nodes
let oldOutDatedNodes = get().outDatedNodes;
set({ outDatedNodes: oldOutDatedNodes.filter((id) => id !== nodeId) });
},
})); }));
export default useFlowStore; export default useFlowStore;

View file

@ -493,10 +493,11 @@ export type nodeToolbarPropsType = {
selected: boolean; selected: boolean;
updateNodeCode?: ( updateNodeCode?: (
newNodeClass: APIClassType, newNodeClass: APIClassType,
code?: string, code: string,
name?: string name: string
) => void; ) => void;
setShowState: (show: boolean | SetStateAction<boolean>) => void; setShowState: (show: boolean | SetStateAction<boolean>) => void;
isOutdated?: boolean;
}; };
export type parsedDataType = { export type parsedDataType = {

View file

@ -124,7 +124,4 @@ export type FlowStoreType = {
data: FlowPoolObjectType | ChatOutputType | chatInputType, data: FlowPoolObjectType | ChatOutputType | chatInputType,
buildId?: string buildId?: string
) => void; ) => void;
outDatedNodes: string[];
addToOutdatedNodes: (nodeId: string) => void;
removeFromOutdatedNodes: (nodeId: string) => void;
}; };