Skip to content

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

Merged
merged 1 commit into from
Apr 29, 2025

Conversation

shaohuzhang1
Copy link
Contributor

fix: Workflow application node parameter saving cannot be reflected back

Copy link

f2c-ci-robot bot commented Apr 29, 2025

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.

Copy link

f2c-ci-robot bot commented Apr 29, 2025

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

} else {
return item
}
})
set(
props.nodeModel.properties.node_data,
'user_input_field_list',
Copy link
Contributor Author

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:

  1. Redundant Code: The same logic is repeated for merge_api_input_field_list and merge_user_input_field_list. Consider creating a helper function or refactor these sections.

  2. Undefined Old API Input Field List: If old_api_input_field_list can be undefined, it's good practice to handle that case properly.

  3. Type Annotations: Ensure type annotations are correct for variables used throughout the function.

  4. String Literals: Replace hardcoded string literals with constants where applicable to improve readability.

  5. 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.

@shaohuzhang1 shaohuzhang1 merged commit 704077d into main Apr 29, 2025
4 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@main@fix_workflow branch April 29, 2025 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant