Skip to content

Commit de1304d

Browse files
CopilotSoulter
andauthored
feat: add edit button to persona selector dialog (#4826)
* Initial plan * feat: add edit persona functionality in chatui selector dialog Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com> * fix: address code review feedback - improve null checks and i18n consistency Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com>
1 parent f835f63 commit de1304d

3 files changed

Lines changed: 51 additions & 13 deletions

File tree

dashboard/src/components/folder/BaseFolderItemSelector.vue

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,17 @@
119119
</v-list-item-subtitle>
120120

121121
<template v-slot:append>
122-
<v-icon v-if="selectedItemId === getItemId(item)"
123-
color="primary" size="22">mdi-check-circle</v-icon>
122+
<div class="d-flex align-center ga-1">
123+
<v-btn v-if="showEditButton && !isDefaultItem(item)"
124+
icon="mdi-pencil"
125+
size="small"
126+
variant="text"
127+
@click.stop="handleEditItem(item)"
128+
:title="labels.editButton || 'Edit'"
129+
/>
130+
<v-icon v-if="selectedItemId === getItemId(item)"
131+
color="primary" size="22">mdi-check-circle</v-icon>
132+
</div>
124133
</template>
125134
</v-list-item>
126135
</template>
@@ -197,6 +206,11 @@ export default defineComponent({
197206
type: Boolean,
198207
default: false
199208
},
209+
// 是否显示编辑按钮
210+
showEditButton: {
211+
type: Boolean,
212+
default: false
213+
},
200214
// 默认项(如 "默认人格")
201215
defaultItem: {
202216
type: Object as PropType<SelectableItem | null>,
@@ -221,7 +235,7 @@ export default defineComponent({
221235
default: null
222236
}
223237
},
224-
emits: ['update:modelValue', 'navigate', 'create'],
238+
emits: ['update:modelValue', 'navigate', 'create', 'edit'],
225239
data() {
226240
return {
227241
dialog: false,
@@ -370,6 +384,17 @@ export default defineComponent({
370384
cancelSelection() {
371385
this.selectedItemId = this.modelValue || '';
372386
this.dialog = false;
387+
},
388+
389+
isDefaultItem(item: SelectableItem): boolean {
390+
if (this.defaultItem === null) {
391+
return false;
392+
}
393+
return this.getItemId(item) === this.getItemId(this.defaultItem);
394+
},
395+
396+
handleEditItem(item: SelectableItem) {
397+
this.$emit('edit', item);
373398
}
374399
}
375400
});

dashboard/src/components/folder/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ export interface FolderItemSelectorLabels {
241241

242242
// 按钮
243243
createButton?: string;
244+
editButton?: string;
244245
confirmButton?: string;
245246
cancelButton?: string;
246247

dashboard/src/components/shared/PersonaSelector.vue

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,24 @@
88
:items-loading="itemsLoading"
99
:labels="labels"
1010
:show-create-button="true"
11+
:show-edit-button="true"
1112
:default-item="defaultPersona"
1213
item-id-field="persona_id"
1314
item-name-field="persona_id"
1415
item-description-field="system_prompt"
1516
:display-value-formatter="formatDisplayValue"
1617
@navigate="handleNavigate"
1718
@create="openCreatePersona"
19+
@edit="openEditPersona"
1820
/>
1921
20-
<!-- 创建人格对话框 -->
22+
<!-- 创建/编辑人格对话框 -->
2123
<PersonaForm
22-
v-model="showCreateDialog"
23-
:editing-persona="undefined"
24+
v-model="showPersonaDialog"
25+
:editing-persona="editingPersona ?? undefined"
2426
:current-folder-id="currentFolderId ?? undefined"
2527
:current-folder-name="currentFolderName ?? undefined"
26-
@saved="handlePersonaCreated"
28+
@saved="handlePersonaSaved"
2729
@error="handleError" />
2830
</template>
2931

@@ -62,7 +64,8 @@ const folderTree = ref<FolderTreeNode[]>([])
6264
const currentPersonas = ref<Persona[]>([])
6365
const treeLoading = ref(false)
6466
const itemsLoading = ref(false)
65-
const showCreateDialog = ref(false)
67+
const showPersonaDialog = ref(false)
68+
const editingPersona = ref<Persona | null>(null)
6669
const currentFolderId = ref<string | null>(null)
6770
6871
// 默认人格
@@ -104,6 +107,7 @@ const labels = computed(() => ({
104107
defaultItem: tm('personaSelector.defaultPersona'),
105108
noDescription: tm('personaSelector.noDescription'),
106109
createButton: tm('personaSelector.createPersona'),
110+
editButton: tm('personaSelector.editPersona') || 'Edit',
107111
confirmButton: t('core.common.confirm'),
108112
cancelButton: t('core.common.cancel'),
109113
rootFolder: tm('personaSelector.rootFolder') || '全部人格',
@@ -171,13 +175,21 @@ async function handleNavigate(folderId: string | null) {
171175
172176
// 打开创建人格对话框
173177
function openCreatePersona() {
174-
showCreateDialog.value = true
178+
editingPersona.value = null
179+
showPersonaDialog.value = true
175180
}
176181
177-
// 人格创建成功
178-
async function handlePersonaCreated(message: string) {
179-
console.log('人格创建成功:', message)
180-
showCreateDialog.value = false
182+
// 打开编辑人格对话框
183+
function openEditPersona(persona: Persona) {
184+
editingPersona.value = persona
185+
showPersonaDialog.value = true
186+
}
187+
188+
// 人格保存成功(创建或编辑)
189+
async function handlePersonaSaved(message: string) {
190+
console.log('人格保存成功:', message)
191+
showPersonaDialog.value = false
192+
editingPersona.value = null
181193
// 刷新当前文件夹的人格列表
182194
await loadPersonasInFolder(currentFolderId.value)
183195
}

0 commit comments

Comments
 (0)