fix: Workflow application node parameter saving cannot be reflected back#3019
fix: Workflow application node parameter saving cannot be reflected back#3019shaohuzhang1 merged 1 commit intomainfrom
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| }) | ||
| set( | ||
| props.nodeModel.properties.node_data, | ||
| 'user_input_field_list', |
There was a problem hiding this comment.
In this code snippet, there are several potential issues that need to be addressed:
-
Redundant Code: The same logic is repeated for
merge_api_input_field_listandmerge_user_input_field_list. Consider creating a helper function or refactor these sections. -
Undefined Old API Input Field List: If
old_api_input_field_listcan be undefined, it's good practice to handle that case properly. -
Type Annotations: Ensure type annotations are correct for variables used throughout the function.
-
String Literals: Replace hardcoded string literals with constants where applicable to improve readability.
-
Cloning Process: The use of
cloneDeep()from lodash might not always be necessary. You could consider using simple deep cloning if you don't rely on specific features provided by lodash.
Here's an optimized version of the code addressing some of these concerns:
import { cloneDeep } from 'lodash';
const MERGE_FIELDS = [
'variable', // For API input field list
'field' // For user input field list
];
// Helper function to create merged fields list
function mergeFields(newFieldList, oldFieldList, variableName) {
return (
newFieldList || []
).map(item => {
const findField = oldFieldList.find(oldItem => {
return oldItem[variableName] === item[variableName];
});
if (!findField) {
return item;
}
return {
...item,
value: findField.value,
label:
typeof findField.label === 'object'
? findField.label[label]
: findField.label
};
});
}
const update_field = () => {
const new_user_input_field_list = cloneDeep(
ok.data.work_flow.nodes[0].properties.user_input_field_list
);
const new_api_input_field_list = cloneDeep(
ok.data.work_flow.nodes[0].properties.api_input_field_list
);
const merge_api_input_field_list = mergeFields(
new_api_input_field_list,
old_api_input_field_list,
'variable'
);
const merge_user_input_field_list = mergeFields(
new_user_input_field_list,
old_user_input_field_list,
'field'
);
set(props.nodeModel.properties.node_data, 'api_input_field_list', merge_api_input_field_list);
set(props.nodeModel.properties.node_data, 'user_input_field_list', merge_user_input_field_list);
};By refactoring the code into reusable methods like mergeFields, we have reduced redundancy and improved maintainability. This approach also makes the code easier to test and understand.
fix: Workflow application node parameter saving cannot be reflected back