-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat: Internal function can modify names #2725
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<template> | ||
<el-dialog | ||
:title="$t('views.functionLib.functionForm.form.functionName.placeholder')" | ||
:title="$t('views.functionLib.functionForm.form.functionName.name')" | ||
v-model="dialogVisible" | ||
:close-on-click-modal="false" | ||
:close-on-press-escape="false" | ||
|
@@ -23,7 +23,7 @@ | |
<span class="dialog-footer"> | ||
<el-button @click.prevent="dialogVisible = false"> {{ $t('common.cancel') }} </el-button> | ||
<el-button type="primary" @click="submit(fieldFormRef)" :loading="loading"> | ||
{{ $t('common.add') }} | ||
{{ isEdit ? $t('common.save') : $t('common.add') }} | ||
</el-button> | ||
</span> | ||
</template> | ||
|
@@ -39,6 +39,7 @@ const emit = defineEmits(['refresh']) | |
|
||
const fieldFormRef = ref() | ||
const loading = ref<boolean>(false) | ||
const isEdit = ref<boolean>(false) | ||
|
||
const form = ref<any>({ | ||
name: '' | ||
|
@@ -64,19 +65,19 @@ watch(dialogVisible, (bool) => { | |
} | ||
}) | ||
|
||
const open = (row: any) => { | ||
const open = (row: any, edit: boolean) => { | ||
if (row) { | ||
form.value = cloneDeep(row) | ||
} | ||
|
||
isEdit.value = edit || false | ||
dialogVisible.value = true | ||
} | ||
|
||
const submit = async (formEl: FormInstance | undefined) => { | ||
if (!formEl) return | ||
await formEl.validate((valid) => { | ||
if (valid) { | ||
emit('refresh', form.value) | ||
emit('refresh', form.value, isEdit.value) | ||
dialogVisible.value = false | ||
} | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code appears to be mostly correct, but here are a few optimizations and improvements: Improvements
Optimizations
Cleaned-up CodeHere’s the optimized version of the provided code: <template>
<el-dialog
:title="$t('views.functionLib.functionForm.form.functionName.name')"
v-model="dialogVisible"
:close-on-click-modal="false"
:close-on-press-escape="false"
>
...
<!-- rest of template content -->
</el-dialog>
</template>
<script setup lang="ts">
import { cloneDeep } from 'lodash'; // Importing lodash for deep cloning
import { ref, defineProps, defineEmits } from 'vue';
import type { FormInstance } from 'element-plus';
defineProps({
row: Object,
});
defineEmits(['refresh']);
const dialogVisible = ref(false);
const fieldFormRef = ref<FormInstance>();
const loading = ref(false);
const isEdit = ref(true);
const form = ref<any>({
name: '',
});
watch(dialogVisible, () => {
form.value = {};
});
const open = (row?: any) => {
if (row) {
form.value = cloneDeep(row);
isEdit.value = !!row; // Check if row exists before setting edit state
}
dialogVisible.value = true;
};
const submit = async (formEl: FormInstance | undefined) => {
if (!formEl) return;
await formEl.validate((valid) => {
if (valid) {
emit('refresh', form.value, isEdit.value);
dialogVisible.value = false;
}
});
};
</script> Additional Considerations
By addressing these points, your code becomes more efficient, readable, and maintainable. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,6 @@ | ||
<template> | ||
<div class="function-lib-list-container p-24" style="padding-top: 16px"> | ||
<el-tabs | ||
v-model="functionType" | ||
@tab-change=" | ||
tabChangeHandle | ||
|
||
" | ||
> | ||
<el-tabs v-model="functionType" @tab-change="tabChangeHandle"> | ||
<el-tab-pane :label="$t('views.functionLib.title')" name="PUBLIC"></el-tab-pane> | ||
<el-tab-pane :label="$t('views.functionLib.internalTitle')" name="INTERNAL"></el-tab-pane> | ||
</el-tabs> | ||
|
@@ -165,6 +159,14 @@ | |
</el-button> | ||
<template #dropdown> | ||
<el-dropdown-menu> | ||
<el-dropdown-item | ||
v-if="item.template_id" | ||
:disabled="item.permission_type === 'PUBLIC' && !canEdit(item)" | ||
@click.stop="addInternalFunction(item, true)" | ||
> | ||
<el-icon><EditPen /></el-icon> | ||
{{ $t('common.edit') }} | ||
</el-dropdown-item> | ||
<el-dropdown-item | ||
v-if="!item.template_id" | ||
:disabled="item.permission_type === 'PUBLIC' && !canEdit(item)" | ||
|
@@ -366,17 +368,24 @@ async function openDescDrawer(row: any) { | |
InternalDescDrawerRef.value.open(content, row) | ||
} | ||
|
||
function addInternalFunction(data?: any) { | ||
AddInternalFunctionDialogRef.value.open(data) | ||
function addInternalFunction(data?: any, isEdit?: boolean) { | ||
AddInternalFunctionDialogRef.value.open(data, isEdit) | ||
} | ||
|
||
function confirmAddInternalFunction(data?: any) { | ||
functionLibApi | ||
.addInternalFunction(data.id, { name: data.name }, changeStateloading) | ||
.then((res) => { | ||
MsgSuccess(t('common.submitSuccess')) | ||
function confirmAddInternalFunction(data?: any, isEdit?: boolean) { | ||
if (isEdit) { | ||
functionLibApi.putFunctionLib(data?.id as string, data, loading).then((res) => { | ||
MsgSuccess(t('common.saveSuccess')) | ||
searchHandle() | ||
}) | ||
} else { | ||
functionLibApi | ||
.addInternalFunction(data.id, { name: data.name }, changeStateloading) | ||
.then((res) => { | ||
MsgSuccess(t('common.addSuccess')) | ||
searchHandle() | ||
}) | ||
} | ||
} | ||
|
||
function searchHandle() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code seems to be an Angular template for displaying a list of functions with tabs ( Main Issues
Optimization Suggestions
Incorporating these changes will help make the code more maintainable, scalable, and adhere to best practices. |
||
|
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 has a minor issue with duplicate keys in the JSON object structure under
form
. The property 'name' is duplicated within thefunctionName
schema. This duplication might be unnecessary unless you intended to have two separate fields for different purposes.Here's the corrected and optimized version:
This ensures that each field maintains a unique identifier while providing clear and concise labels. If there was indeed a need for both 'name' and another property with similar functionality, please clarify your use case further for more specific recommendations.