-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: Form collection single line tab supports variables #3942
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. 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-sigs/prow 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 |
| formValue.value.default_value_assignment_method = 'custom' | ||
| if (formValue.value.show_default_value === undefined) { | ||
| formValue.value.show_default_value = true | ||
| } |
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 provided code seems clean and well-structured. However, there are a few points of consideration:
-
Dynamic Content: The content within
<el-radio-group>can be more robust when dealing with dynamic data loading asynchronously. -
Validation Rules: Ensure that all validation rules are properly defined in
default_value_ruleto prevent unexpected behavior during updates or deletions of radio values. -
Error Messages: Add clear error messages and feedback through Vue's
$messageAPI for user interaction when form input requirements are not met. -
Testing: Test thoroughly after making changes to ensure no new bugs introduced due to modifications.
-
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 | ||
| } |
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.
There are several potential issues and suggestions in the provided code:
Issues:
-
Undefined
getDefaultVariablesValueRule: The lineconst 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. -
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. -
Incomplete Data Handling: If
getModelreturns null/undefined, the assignment method options won't be correctly populated. Ensure all dependent data structures handle such cases gracefully. -
Exposure Issues: The expose interface does not include
assignment_method_option_listdirectly, so callinggetData(getData())wouldn't work as expected. Consider exposing these computed properties along with others. -
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. -
Validation Logic: While the validation currently checks length, it could be improved to ensure each element in
option_listhas 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. -
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: |
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.
Code Review
Function get_default_option
- 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. - 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
-
Field Reset with Prompt Generation:
- In the
reset_fieldmethod, especially if you want prompt generation only for certain fields (like label), make sure the condition checks these conditions properly. Also, handle cases where_valuemight not be a dictionary before attempting to access keys like'label'.
- In the
-
Handling JSON Input Default Value Assignment Method:
- Ensure that
json_input_default_value_assignment_methodis handled consistently regardless of its casing (upper vs. lower). Adjust the comparison accordingly.
- Ensure that
-
Optimization Recommendations
- If
workflow_manage.get_reference_fieldcan return values that are not lists (perhaps due to incorrect logic or external dependencies), consider adding additional checks within theifstatement to prevent runtime errors.
- If
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.
feat: Form collection single line tab supports variables