Skip to content

Commit

Permalink
fix: improve node internal updates in setNodeClass function (langflow…
Browse files Browse the repository at this point in the history
…-ai#4836)

* ✨ (use-handle-new-value.tsx): change the callback function to be asynchronous to introduce a delay of 500ms before updating node internals

* 🐛 (use-handle-new-value.tsx): fix setNode function call to include additional parameters for immediate update and callback function to update node internals after setting the node class.

* 🔧 (use-handle-new-value.tsx): Remove unnecessary line break to improve code readability and consistency

* 🔧 (.github/workflows/typescript_test.yml): update matrix output to ensure proper JSON formatting using jq command
  • Loading branch information
Cristhianzl authored Nov 25, 2024
1 parent e2b947b commit 043cf14
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/typescript_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
description: "Test suites to run (JSON array)"
required: false
type: string
default: '[]'
default: "[]"
release:
description: "Whether this is a release build"
required: false
Expand Down Expand Up @@ -153,7 +153,8 @@ jobs:
echo "Final test suites to run: $SUITES"
echo "Test grep pattern: $TEST_GREP"
echo "matrix=$SUITES" >> $GITHUB_OUTPUT
# Ensure proper JSON formatting for matrix output
echo "matrix=$(echo $SUITES | jq -c .)" >> $GITHUB_OUTPUT
echo "test_grep=$TEST_GREP" >> $GITHUB_OUTPUT
setup-and-test:
Expand Down
24 changes: 15 additions & 9 deletions src/frontend/src/CustomNodes/hooks/use-handle-new-value.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const useHandleOnNewValue = ({
const updateNodeInternals = useUpdateNodeInternals();

const setErrorData = useAlertStore((state) => state.setErrorData);

const postTemplateValue = usePostTemplateValue({
parameterId: name,
nodeId: nodeId,
Expand Down Expand Up @@ -72,14 +71,21 @@ const useHandleOnNewValue = ({

const setNodeClass = (newNodeClass: APIClassType) => {
options?.setNodeClass && options.setNodeClass(newNodeClass);
setNode(nodeId, (oldNode) => {
const newData = cloneDeep(oldNode.data);
newData.node = newNodeClass;
return {
...oldNode,
data: newData,
};
});
setNode(
nodeId,
(oldNode) => {
const newData = cloneDeep(oldNode.data);
newData.node = newNodeClass;
return {
...oldNode,
data: newData,
};
},
true,
() => {
updateNodeInternals(nodeId);
},
);
};

if (shouldUpdate && changes.value !== undefined) {
Expand Down

0 comments on commit 043cf14

Please sign in to comment.