-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prompt template not being saved on advanced modal (#2488)
* Fixed dbvalue on table node cell renderer * Added Change Advanced hook * Added Handle New Value hook * Added Handle Node Class hook * Added Node Class handler to TableNodeCellRender * Removed internal state of EditNode, added internal state for NodeClass and made the rows and columns be updated when NodeClass changes * Added NodeClass as dependencies on useMemo to update columns when NodeClass changes * Fixed advanced not changing the node * feat: updating tests without save btn * Added Close button on editNode --------- Co-authored-by: cristhianzl <[email protected]> Co-authored-by: anovazzi1 <[email protected]>
- Loading branch information
1 parent
74845ff
commit fe21f90
Showing
20 changed files
with
259 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/frontend/src/modals/editNodeModal/hooks/use-handle-change-advanced.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { cloneDeep } from "lodash"; | ||
import { NodeDataType } from "../../../types/flow"; | ||
|
||
const useHandleChangeAdvanced = ( | ||
data: NodeDataType, | ||
takeSnapshot: () => void, | ||
setNode: (id: string, callback: (oldNode: any) => any) => void, | ||
updateNodeInternals: (id: string) => void, | ||
) => { | ||
const handleChangeAdvanced = (name) => { | ||
if (!data.node) return; | ||
takeSnapshot(); | ||
|
||
setNode(data.id, (oldNode) => { | ||
let newNode = cloneDeep(oldNode); | ||
|
||
newNode.data.node.template[name].advanced = | ||
!newNode.data.node.template[name].advanced; | ||
|
||
return newNode; | ||
}); | ||
|
||
updateNodeInternals(data.id); | ||
}; | ||
|
||
return { handleChangeAdvanced }; | ||
}; | ||
|
||
export default useHandleChangeAdvanced; |
84 changes: 84 additions & 0 deletions
84
src/frontend/src/modals/editNodeModal/hooks/use-handle-new-value.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { cloneDeep } from "lodash"; | ||
import { | ||
ERROR_UPDATING_COMPONENT, | ||
TITLE_ERROR_UPDATING_COMPONENT, | ||
} from "../../../constants/constants"; | ||
import useAlertStore from "../../../stores/alertStore"; | ||
import { ResponseErrorTypeAPI } from "../../../types/api"; | ||
import { NodeDataType } from "../../../types/flow"; | ||
|
||
const useHandleOnNewValue = ( | ||
data: NodeDataType, | ||
takeSnapshot: () => void, | ||
handleUpdateValues: (name: string, data: NodeDataType) => Promise<any>, | ||
debouncedHandleUpdateValues: any, | ||
setNode: (id: string, callback: (oldNode: any) => any) => void, | ||
) => { | ||
const setErrorData = useAlertStore((state) => state.setErrorData); | ||
|
||
const handleOnNewValue = async ( | ||
newValue, | ||
name, | ||
dbValue, | ||
skipSnapshot = false, | ||
) => { | ||
const nodeTemplate = data.node!.template[name]; | ||
const currentValue = nodeTemplate.value; | ||
|
||
if (currentValue !== newValue && !skipSnapshot) { | ||
takeSnapshot(); | ||
} | ||
|
||
const shouldUpdate = | ||
data.node?.template[name].real_time_refresh && | ||
!data.node?.template[name].refresh_button && | ||
currentValue !== newValue; | ||
|
||
const typeToDebounce = nodeTemplate.type; | ||
|
||
nodeTemplate.value = newValue; | ||
|
||
let newTemplate; | ||
if (shouldUpdate) { | ||
try { | ||
if (["int"].includes(typeToDebounce)) { | ||
newTemplate = await handleUpdateValues(name, data); | ||
} else { | ||
newTemplate = await debouncedHandleUpdateValues(name, data); | ||
} | ||
} catch (error) { | ||
let responseError = error as ResponseErrorTypeAPI; | ||
setErrorData({ | ||
title: TITLE_ERROR_UPDATING_COMPONENT, | ||
list: [ | ||
responseError?.response?.data?.detail.error ?? | ||
ERROR_UPDATING_COMPONENT, | ||
], | ||
}); | ||
} | ||
} | ||
|
||
setNode(data.id, (oldNode) => { | ||
const newNode = cloneDeep(oldNode); | ||
newNode.data = { | ||
...newNode.data, | ||
}; | ||
|
||
if (dbValue !== undefined) { | ||
newNode.data.node.template[name].load_from_db = dbValue; | ||
} | ||
|
||
if (data.node?.template[name].real_time_refresh && newTemplate) { | ||
newNode.data.node.template = newTemplate; | ||
} else { | ||
newNode.data.node.template[name].value = newValue; | ||
} | ||
|
||
return newNode; | ||
}); | ||
}; | ||
|
||
return { handleOnNewValue }; | ||
}; | ||
|
||
export default useHandleOnNewValue; |
39 changes: 39 additions & 0 deletions
39
src/frontend/src/modals/editNodeModal/hooks/use-handle-node-class.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { cloneDeep } from "lodash"; | ||
import { NodeDataType } from "../../../types/flow"; | ||
|
||
const useHandleNodeClass = ( | ||
data: NodeDataType, | ||
takeSnapshot: () => void, | ||
setNode: (id: string, callback: (oldNode: any) => any) => void, | ||
updateNodeInternals: (id: string) => void, | ||
) => { | ||
const handleNodeClass = (newNodeClass, name, code, type?: string) => { | ||
if (!data.node) return; | ||
if (data.node!.template[name].value !== code) { | ||
takeSnapshot(); | ||
} | ||
|
||
setNode(data.id, (oldNode) => { | ||
let newNode = cloneDeep(oldNode); | ||
|
||
newNode.data = { | ||
...newNode.data, | ||
node: newNodeClass, | ||
description: newNodeClass.description ?? data.node!.description, | ||
display_name: newNodeClass.display_name ?? data.node!.display_name, | ||
}; | ||
if (type) { | ||
newNode.data.node.template[name].type = type; | ||
} | ||
newNode.data.node.template[name].value = code; | ||
|
||
return newNode; | ||
}); | ||
|
||
updateNodeInternals(data.id); | ||
}; | ||
|
||
return { handleNodeClass }; | ||
}; | ||
|
||
export default useHandleNodeClass; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.