-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix: Workflow application node parameter saving cannot be reflected back #3019
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
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. Instructions 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.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
} else { | ||
return item | ||
} | ||
}) | ||
set( | ||
props.nodeModel.properties.node_data, | ||
'user_input_field_list', |
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.
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_list
andmerge_user_input_field_list
. Consider creating a helper function or refactor these sections. -
Undefined Old API Input Field List: If
old_api_input_field_list
can 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