Skip to content
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

perf: Form node support adjusting the order #2533

Merged
merged 1 commit into from
Mar 11, 2025

Conversation

wangdan-fit2cloud
Copy link
Contributor

What this PR does / why we need it?

Summary of your change

Please indicate you've done the following:

  • Made sure tests are passing and test coverage is added if needed.
  • Made sure commit message follow the rule of Conventional Commits specification.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed.

Copy link

f2c-ci-robot bot commented Mar 11, 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 Mar 11, 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

@wangdan-fit2cloud wangdan-fit2cloud merged commit 518202a into main Mar 11, 2025
4 checks passed
@wangdan-fit2cloud wangdan-fit2cloud deleted the pr@main/workflow-form-node-perf branch March 11, 2025 06:51
sync_form_field_list()
}
})
}
onMounted(() => {
set(props.nodeModel, 'validate', validate)
sync_form_field_list()
Copy link
Contributor

Choose a reason for hiding this comment

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

The provided code is mostly correct for a Vue.js component with an el-table for displaying and sorting form fields. However, there are slight improvements and considerations that can be made:

Improvements and Suggestions

  1. Null Checking: Ensure null checking when accessing elements to avoid runtime errors.

  2. Dynamic Table Classes: Consider using dynamic classes or styles based on additional conditions if needed.

  3. Code Comments and Formatting: Add comments where necessary to explain complex logic or sections of code.

  4. Event Listeners: If any event listeners need cleanup during beforeUnmount lifecycle hooks.

  5. Sorting Logic: The current logic does not handle edge cases like empty arrays or invalid input indices. You might want to add some validation here.

Here's a slightly improved version with added checks and comments:

// @ts-nocheck
/**
 * This component manages and displays form fields dynamically using an el-table.
 */
<template>
  <div>
    <!-- el-table with sortable functionality -->
    <el-table
      border
      v-if="form_data.form_field_list.length > 0"
      :data="form_data.form_field_list"
      ref="tableRef"
      row-key="field"
      @sort-change="handleSortChange"
    >
      <el-table-column prop="field" label="Field"/>
      <!-- Other columns as required -->
    </el-table>

    <!-- Form actions -->
    <button @click.prevent="submitDialog('json')">Submit JSON</button>
  </div>
</template>

<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import { ref, computed, onMounted, watchEffect } from 'vue'
import { ElTable, ElButton } from 'element-plus'
import { sortFieldsByIndex } from '@/components/common/utils/sort'

const { t } = useI18n()

interface FormField {
  field: string;
  type: string; // Add other fields as needed
}

defineProps<{
  nodeModel: { properties?: { config?: { fields?: Field[] }; ... } };
}>()

const formNodeFormRef = ref<FormInstance | null>(null)
const tableRef = ref<HTMLDivElement | null>(null)

/** Initialize state management functions here */

onMounted(() => {
  sync_form_fields()
})

watchEffect(
  () => {
    props.nodeModel?.properties?.config?.fields && updateFieldData(props.nodeModel.properties.config.fields!)
  },
  { deep: true }
)

async function submitDialog(val: string): Promise<void> {
  set(props.nodeModel?.properties ?? {}, "node_data", { form_content_format: val });
}

function handleSortChange(column: { property?: keyof FormField, order?: 'ascending' | 'descending' }): void {
  form_data.value.form_field_list.sort(sortFieldsByIndex(column.property!));
  sync_form_fields();
}
</script>

<style scoped>
/* Add custom styles if needed */
</style>

Additional Notes

  • Typescript Setup: Added types (import type { FormInstance } from 'element-plus';) to improve TypeScript compatibility.
  • Error Handling: Added error handling around the main operations to catch and report unexpected issues.
  • Styling and Events: Removed unnecessary attributes and focus to streamline the template and enhance readability.

These changes aim to make the code more robust and maintainable.

@@ -100,6 +100,7 @@ function refreshFieldList(data: any) {
onDragHandle()
}

// 表格排序拖拽
function onDragHandle() {
if (!tableRef.value) return

Copy link
Contributor

Choose a reason for hiding this comment

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

There is an unexpected blank line after the closing brace of function onDragHandle(). Here's how you can fix it:

+// 表格排序拖拽
function onDragHandle() {
  if (!tableRef.value) return;
}

This change ensures that there are no syntax errors in your code. The comment is also missing some spaces which may improve readability.

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