-
Notifications
You must be signed in to change notification settings - Fork 2k
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
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. 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. |
[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 |
sync_form_field_list() | ||
} | ||
}) | ||
} | ||
onMounted(() => { | ||
set(props.nodeModel, 'validate', validate) | ||
sync_form_field_list() |
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 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
-
Null Checking: Ensure null checking when accessing elements to avoid runtime errors.
-
Dynamic Table Classes: Consider using dynamic classes or styles based on additional conditions if needed.
-
Code Comments and Formatting: Add comments where necessary to explain complex logic or sections of code.
-
Event Listeners: If any event listeners need cleanup during beforeUnmount lifecycle hooks.
-
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 | |||
|
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 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.
What this PR does / why we need it?
Summary of your change
Please indicate you've done the following: