Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

feat: Form collection single line tab supports variables

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Aug 26, 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.

Details

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-sigs/prow repository.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Aug 26, 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.

Details 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

formValue.value.default_value_assignment_method = 'custom'
if (formValue.value.show_default_value === undefined) {
formValue.value.show_default_value = true
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code seems clean and well-structured. However, there are a few points of consideration:

  1. Dynamic Content: The content within <el-radio-group> can be more robust when dealing with dynamic data loading asynchronously.

  2. Validation Rules: Ensure that all validation rules are properly defined in default_value_rule to prevent unexpected behavior during updates or deletions of radio values.

  3. Error Messages: Add clear error messages and feedback through Vue's $message API for user interaction when form input requirements are not met.

  4. Testing: Test thoroughly after making changes to ensure no new bugs introduced due to modifications.

  5. Comments: Consider adding comments explaining complex logic or decisions to improve readability.

Overall, the current implementation is good but could be improved by considering these guidelines for better future development adaptability and maintainability.

formValue.value.assignment_method = 'custom'
if (formValue.value.show_default_value === undefined) {
formValue.value.show_default_value = true
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are several potential issues and suggestions in the provided code:

Issues:

  1. Undefined getDefaultVariablesValueRule: The line const default_ref_variables_value_rule = {...} is incomplete. It's likely that there should be more logic here to generate the correct rule based on other conditions, but without it complete, this will cause runtime errors when trying to validate.

  2. Missing Import Declarations: There isn't an explicit import statement for InfoFilled, which is used inside of the <el-popover>. This might result in type checking errors or incorrect tooltips being displayed.

  3. Incomplete Data Handling: If getModel returns null/undefined, the assignment method options won't be correctly populated. Ensure all dependent data structures handle such cases gracefully.

  4. Exposure Issues: The expose interface does not include assignment_method_option_list directly, so calling getData(getData()) wouldn't work as expected. Consider exposing these computed properties along with others.

  5. Dynamic Property Binding on Labels: In Vue 3 Compositions API, accessing dynamic property values using ${$t(...) within JSX expressions can lead to some confusion; typically you'd use string interpolation with plain JavaScript functions ($t(...)) rather than attempting to bind to them directly.

  6. Validation Logic: While the validation currently checks length, it could be improved to ensure each element in option_list has valid properties according to your requirements (e.g., non-empty labels and/or values). You might also want to validate against a predefined schema or list of allowed combinations.

  7. Code Duplication: There’s a good opportunity to refactor parts of the conditional rendering logic into utility functions to avoid redundancy.

Suggestions:

  • Ensure all imports at the top of your file if needed.

  • Add missing details like actual validation rules for dynamic variables reference and custom inputs.

  • Provide clear documentation or comments about what each part of the code does to enhance maintainability.

  • Simplify or optimize complex expressions where possible, especially around template literals and conditional statements.

By addressing these points, the code will be more robust and easier to understand.


return field

def execute(self, form_field_list, form_content_format, form_data, **kwargs) -> NodeResult:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

Function get_default_option

  1. Type Checking: The function should use an explicit type check (isinstance) instead of relying on method existence to ensure robustness when handling different input types.
  2. Exception Handling: Although there's a try-except block, it currently uses a generic exception handler, which could catch unrelated errors. It might be beneficial to catch specific exceptions relevant to the operation (e.g., IndexError, ValueError).

Function write_context

  • No issues or optimizations.

Function generate_prompt

  • This function is designed correctly to handle missing prompt generation gracefully by returning the original value.

Class BaseFormNode

  1. Field Reset with Prompt Generation:

    • In the reset_field method, especially if you want prompt generation only for certain fields (like label), make sure the condition checks these conditions properly. Also, handle cases where _value might not be a dictionary before attempting to access keys like 'label'.
  2. Handling JSON Input Default Value Assignment Method:

    • Ensure that json_input_default_value_assignment_method is handled consistently regardless of its casing (upper vs. lower). Adjust the comparison accordingly.
  3. Optimization Recommendations

    • If workflow_manage.get_reference_field can return values that are not lists (perhaps due to incorrect logic or external dependencies), consider adding additional checks within the if statement to prevent runtime errors.

Here’s how you might improve those points:

class BaseFormNode(IFormNode):
    def save_context(self, details, workflow_manage):
        form_data = details.get('form_data', None)
        
        # Handle non-dict data appropriately if needed
        if form_data is not None and isinstance(form_data, dict):
            for key in form_data.keys():
                current_val = form_data.get(key)
                
                if current_val is not None:
                    if isinstance(current_val, str):
                        form_data[key] = generate_prompt(workflow_manage, current_val)
                    
                    if f == 'label':
                        label_dict = current_val
                        label_value = label_dict.get('label')
                        
                        if label_value is not None:
                            label_dict['label'] = generate_prompt(workflow_manage, label_value)
                            
                            tooltips = label_dict.get('attrs').get('tooltip')
                            if tooltips is not None:
                                labels_attr = label_dict.get('attrs')
                                labels_attr.update({'tooltip': generate_prompt(workflow_manage, tooltips)})
                                
                            form_data[key] = label_dict
        
            option_list_fields = ['SingleSelect', 'MultiSelect', 'RadioCard', 'RadioRow']
            
            for field in form_field_list:
                if field["input_type"] in option_list_fields:
                    assignment_method = field.get("assignment_method", "none")
                    
                    if assignment_method.lower() != 'ref_variables':
                        continue
                    
                    ref_values = field.get("option_list", [])
                    
                    if isinstance(ref_values[0], str):
                        opt_list = []
                        for ref in ref_values:
                            opt_list.append(generate_prompt(workspace.manage, ref))
                    else:
                        opt_list = [o.get("description") for o in ref_values]
                    
                    field["option_list"] = opt_list if isinstance(opt_list, list) else []
                    field.setdefault("default_value", get_default_option(opt_list, field["input_type"], field["value_field"]))
                    
                if field["input_type"] == 'JsonInput':
                    json_default_value_assign = field.get("default_value_assignment_method", "").lower()
                    
                    if json_default_value_assign != 'ref_variables':
                        continue
                
                    ref_vals_json = [v.strip('{ }') for v in field.pop("default_value")]
                    
                    if all([v.startswith('"') and v.endswith('"') for v in ref_vals_json]):
                        val_lst = []
                        for ref_v in ref_vals_json:
                            val_lst.append(generate_prompt(workspace.manage, ref_v))
                    else:
                        try:
                            lst_of_objs = eval('[%s]' % ', '.join(ref_vals_json))  # Assuming this works based on JSON-like syntax
                        
                        except (SyntaxError, ValueError):
                            print((f"Eval error! Invalid default value format for JsonInput: {ref_vals_json}"))
                            val_lst = []

These improvements address many of the identified potential issues, making your code more robust and maintainable. Always test thoroughly after changes to ensure no unintended behaviors arise.

@shaohuzhang1 shaohuzhang1 merged commit a05573b into v2 Aug 26, 2025
3 of 6 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@v2@feat_form_node branch August 26, 2025 12:01
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.

2 participants