Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ui/src/components/dynamics-form/items/MultiRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const selected = (activeValue: string | number) => {
elFormItem.validate('change')
}
}
const reset = (activeValue: string) => {
const reset = (activeValue: string | number) => {
const _result = props.modelValue ? [...props.modelValue, activeValue] : [activeValue]
return _result.filter((r) => option_value_list.value.includes(r))
}
Copy link
Copy Markdown
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 is clean and does not have any serious errors or issues based on the given context. However, there are minor optimizations you can make:

  1. Type Safety: In TypeScript, it's better to explicitly specify the type of arrays when pushing items using push(). You can avoid the need for a temporary array _result by pushing directly into props.modelValue.

  2. Filtering Optimization: If option_value_list.value.includes(r) always returns true (or false), the filtering step might be unnecessary unless the list contains multiple values.

Here's the optimized version of the code:

const selected = (activeValue: string | number) => {
  elFormItem.validate('change');
}

const reset = (activeValue: string | number) => {
  if (!props.modelValue || !Array.isArray(props.modelValue)) {
    props.modelValue = [];
  }
  
  // Push activeValue onto the existing array or create a new one with activeValue only
  const _selectedValues = props.modelValue.push(activeValue) > -1 
    ? props.modelValue.slice(0)
    : [activeValue];

  
  // This line was potentially inefficient due to slicing. It could be replaced by the above logic.
  /* const _filteredSelectedValues = _selectedValues.filter((r) =>
    option_value_list.value.includes(r)); */

  return _selectedValues;
}

These changes ensure that the code remains efficient while adhering to TypeScript best practices.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const deleteFile = (file: any) => {

const model_value = computed({
get: () => {
if (!model_value.value) {
if (!props.modelValue) {
emit('update:modelValue', [])
}
return props.modelValue
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The given code snippet contains the following issues and potential improvements:

  1. Logical Error: The model_value function is incorrectly trying to access its own property within itself (model_value.value). This will cause an error because a computed property cannot directly access other properties.

  2. Typo: In the line emit("update:modelValue", []), there seems to be an unnecessary colon after "update:modelValue".

Corrections

Here’s the corrected version of the code with improved logic:

const model_value = computed(() => {
  return props.modelValue;
});

By removing model_value.value, you prevent direct interaction that leads to errors, improving maintainability and security. Additionally, the typo has been fixed.

This change ensures that the computed getter does not inadvertently interact with its own state.

Expand Down
Loading