-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix: fix github#1988 #1995
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: fix github#1988 #1995
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -202,7 +202,6 @@ const update_field = () => { | |
.then((ok) => { | ||
const old_api_input_field_list = props.nodeModel.properties.node_data.api_input_field_list | ||
const old_user_input_field_list = props.nodeModel.properties.node_data.user_input_field_list | ||
|
||
if (isWorkFlow(ok.data.type)) { | ||
const nodeData = ok.data.work_flow.nodes[0].properties.node_data | ||
const new_api_input_field_list = ok.data.work_flow.nodes[0].properties.api_input_field_list | ||
|
@@ -213,7 +212,13 @@ const update_field = () => { | |
(old_item: any) => old_item.variable == item.variable | ||
) | ||
if (find_field) { | ||
return { ...item, default_value: JSON.parse(JSON.stringify(find_field.default_value)) } | ||
return { | ||
...item, | ||
default_value: JSON.parse(JSON.stringify(find_field.default_value)), | ||
value: JSON.parse(JSON.stringify(find_field.value)), | ||
label: | ||
typeof item.label === 'object' && item.label != null ? item.label.label : item.label | ||
} | ||
} else { | ||
return item | ||
} | ||
|
@@ -228,12 +233,17 @@ const update_field = () => { | |
(old_item: any) => old_item.field == item.field | ||
) | ||
if (find_field) { | ||
return { ...item, default_value: JSON.parse(JSON.stringify(find_field.default_value)) } | ||
return { | ||
...item, | ||
default_value: JSON.parse(JSON.stringify(find_field.default_value)), | ||
value: JSON.parse(JSON.stringify(find_field.value)), | ||
label: | ||
typeof item.label === 'object' && item.label != null ? item.label.label : item.label | ||
} | ||
} else { | ||
return item | ||
} | ||
}) | ||
console.log(merge_user_input_field_list) | ||
set( | ||
props.nodeModel.properties.node_data, | ||
'user_input_field_list', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code snippet seems to be part of a React component handling updates for node data fields, specifically focusing on input variables. Here are some observations and suggestions:
Here's an updated version of the code incorporating these considerations: const update_field = () => {
return Ok.ok({
properties: [
{
// Update your payload according to your application requirements here
node_data: {
api_input_field_list: [...],
user_input_field_list: [...]
}
}
]
});
};
// Example call:
Ok.then(update_field).then((response) => {
const { node_model } = response.payload;
if (node_model) {
let merged_user_input = [...node_model.properties[node_model.name_of_node]];
// Assuming you want to merge based on certain conditions
merged_user_input.forEach(item => {
const findFieldApiList = old_api_input_field_list.find(oldItem =>
newItem.variable === item.variable
);
if (findFieldApiList) {
item.default_value = JSON.parse(JSON.stringify(findFieldApiList.default_value));
if ('value' in findFieldApiList && typeof findFieldApiList.value !== 'string') {
try {
item.value = JSON.parse(JSON.stringify(findFieldApiList.value)); // Add error handling
} catch (error) {
console.error('Error parsing value:', error);
}
}
if (
(typeof item.label === 'object' || typeof item.label === 'array') &&
item.label?.label !== undefined
) {
item.label = item.label.label; // Extract label from object or array
}
} else {
item.default_value = '';
item.value = ''; // Initialize or set appropriate defaults
}
// Merge similarly for other lists...
});
node_model.properties[node_model.name_of_node] = merged_user_input;
console.log(node_model); // Log the updated model
} else {
console.error("Node model was not found.");
}
}).catch(error => {
console.error('There was a problem updating fields!', error.message);
}); Key Changes:
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code provided appears to have several potential issues:
Imports and Class Definitions: The imports at the top appear correct, but there might be unused import statements which could cause confusion.
get_application
Method:with_valid
is set toTrue
, it checks if the current user (self
) is valid. However, there is no method namedis_valid()
defined within theProfileAPI
class.with_valid
is false), the code retrieves an application using its ID and then returns an updated version of it using a serializer. This is done correctly.Custom Theme Handling: There is unnecessary complexity with default font colors handled directly rather than using a function or template context.
Work Flow Version Selection: The selection of the latest Work Flow version in embedded applications seems redundant since the method would only return the most recent version regardless of whether embedded or standalone.
Database Queries: While the logic looks efficient, some queries can be optimized, particularly ensuring that related data like datasets is fetched concurrently where possible and avoiding nested calls like
list_dataset
.Here is a brief refactored snippet with improvements mentioned above:
This should improve readability and reduce redundancy while maintaining core functionality.