fix: outdated code conditions and global variable (#2581)

* Fixed Check Code Validity to set outdated as false when type does not exist

* feat: Refactor update_template_values function

Refactor the `update_template_values` function to improve code readability and maintainability. Rename the parameters `frontend_template` to `new_template` and `raw_template` to `previous_template` for clarity. Update the variable names within the function accordingly.

* feat(update_template_field): update load_from_db in case field value is not the default

* refactor: update template values in PromptComponent

Update the `update_template_values` function in the `PromptComponent` class to improve code readability and maintainability. Rename the parameters `frontend_template` to `new_template` and `raw_template` to `previous_template` for clarity. Update the variable names within the function accordingly.

---------

Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org>
This commit is contained in:
Lucas Oliveira 2024-07-08 12:23:03 -03:00 • committed by GitHub
commit 74433bf023
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 25 additions and 23 deletions

View file

@ -13,24 +13,21 @@ const useCheckCodeValidity = (
// This one should run only once
// first check if data.type in NATIVE_CATEGORIES
// if not return
if (
!Object.keys(nodeNames).includes(types[data.type]) ||
!data.node?.template?.code?.value
)
return;
const thisNodeTemplate = templates[data.type].template;
// if the template does not have a code key
// return
if (!thisNodeTemplate.code) return;
const currentCode = thisNodeTemplate.code?.value;
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 && !componentsToIgnore.includes(data.type),
currentCode &&
thisNodesCode &&
currentCode !== thisNodesCode &&
!componentsToIgnore.includes(data.type) &&
Object.keys(nodeNames).includes(types[data.type]),
);
setIsUserEdited(data.node?.edited ?? false);
// template.code can be undefined
}, [
data.node,
data.node?.template?.code?.value,
templates,
setIsOutdated,