Repository navigation
feat: termbase edit #7764
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
feat: termbase edit #7764
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 |
|---|---|---|
|
|
@@ -14,6 +14,10 @@ const getTermbasePage = (knowledgeId: string, page: ParamsPage, query?: { conten | |
| /** 删除单个知识库自定义分词条目。 */ | ||
| const deleteTermbase = (knowledgeId: string, termbaseId: string) => del<undefined, boolean>(`${getPrefix(knowledgeId)}/${termbaseId}`) | ||
|
|
||
| /** 修改单个知识库自定义分词条目。 */ | ||
| const putTermbase = (knowledgeId: string, termbaseId: string, payload: TermbaseUpdatePayload) => | ||
| put<TermbaseUpdatePayload, void>(`${getPrefix(knowledgeId)}/${termbaseId}`, payload) | ||
|
|
||
| /** 批量删除知识库自定义分词条目。 */ | ||
| const putBatchDeleteTermbases = (knowledgeId: string, termbaseIds: string[]) => | ||
| put<string[], boolean>(`${getPrefix(knowledgeId)}/batch_delete`, termbaseIds) | ||
|
|
@@ -26,6 +30,7 @@ export default { | |
| postTermbases, | ||
| getTermbasePage, | ||
| deleteTermbase, | ||
| putTermbase, | ||
| putBatchDeleteTermbases, | ||
| postExportTermbases, | ||
| } | ||
|
Contributor
Author
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. Here is a review of your code snippet: 1. Inconsistency in Function Naming (Irregularity)Issue: 2. Redundant Payload Typing in
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,20 +2,20 @@ | |
| import { computed, onMounted, ref } from 'vue' | ||
| import { useRoute } from 'vue-router' | ||
| import type MkQuickCreate from '@/components/global/mk-table/MkQuickCreate.vue' | ||
| import MkEditName from '@/components/mk-edit-name/index.vue' | ||
| import type { ResourceDetailPageProps } from '@/layout/ResourceDetailLayout.vue' | ||
| import type { TermbaseItem } from '@/api/types' | ||
| import { datetimeFormat } from '@/utils/time' | ||
| import { MsgSuccess } from '@/utils/message' | ||
| import { useKnowledgeDetailContext } from '@/views/knowledge-detail/context' | ||
| import ButtonCreateTermbase from './components/ButtonCreateTermbase.vue' | ||
| import { isWorkspaceSharedResource,isSystemResource, isSystemSharedResource } from '@/utils/resource-context' | ||
| import { isWorkspaceSharedResource, isSystemResource, isSystemSharedResource } from '@/utils/resource-context' | ||
| import { perm } from '@/permission' | ||
|
|
||
| /** | ||
| * 知识库「词库」权限判断 | ||
| */ | ||
| type KnowledgeTermbasePermissionMethod = | ||
| 'termbaseCreate' | 'termbaseEdit' | 'termbaseDelete' | 'termbaseExport' | ||
| type KnowledgeTermbasePermissionMethod = 'termbaseCreate' | 'termbaseEdit' | 'termbaseDelete' | 'termbaseExport' | ||
|
|
||
| function knowledgeTermbasePermission(method: KnowledgeTermbasePermissionMethod): boolean { | ||
| if (isSystemResource()) return Boolean(perm.knowledge.system[method]()) | ||
|
|
@@ -81,6 +81,16 @@ function handleTermbasesCreated() { | |
| return loadTermbases() | ||
| } | ||
|
|
||
| /* 词语原位编辑:保存接口不返回词条,刷新当前页同步更新时间。 */ | ||
| function saveTermbaseContent(termbaseId: string, content: string): Promise<string> { | ||
| return ( | ||
| resourceApi.termbase | ||
| .putTermbase?.(knowledgeId.value, termbaseId, { content }) | ||
| .then(() => loadTermbases()) | ||
| .then(() => content) ?? Promise.resolve(termbases.value.find(({ id }) => id === termbaseId)?.content ?? '') | ||
| ) | ||
| } | ||
|
|
||
| /* 快捷创建与弹窗创建复用同一批量创建接口。 */ | ||
| function handleQuickCreate(content: string) { | ||
| if (operationLoading.value) return | ||
|
|
@@ -200,7 +210,18 @@ onMounted(() => { | |
| /> | ||
| </template> | ||
| <el-table-column type="selection" width="40" /> | ||
| <el-table-column prop="content" label="词语" show-overflow-tooltip /> | ||
| <el-table-column prop="content" label="词语" show-overflow-tooltip> | ||
| <template #default="{ row }: { row: TermbaseItem }"> | ||
| <!-- 编辑分词 --> | ||
| <MkEditName | ||
| :key="row.id" | ||
| v-model="row.content" | ||
| :maxlength="256" | ||
| :save="(content) => saveTermbaseContent(row.id, content)" | ||
| :disabled="isWorkspaceSharedResource() || !knowledgeTermbasePermission('termbaseEdit')" | ||
| /> | ||
| </template> | ||
| </el-table-column> | ||
| <el-table-column prop="create_time" label="创建时间" width="180"> | ||
| <template #default="{ row }: { row: TermbaseItem }"> | ||
| {{ datetimeFormat(row.create_time) }} | ||
|
|
@@ -223,9 +244,23 @@ onMounted(() => { | |
| </el-table-column> | ||
| <template #footer-batch-actions> | ||
| <!-- 批量导出词语 --> | ||
| <el-button v-if="knowledgeTermbasePermission('termbaseExport')" type="primary" plain :disabled="operationLoading" @click="handleExportTermbases">导出</el-button> | ||
| <el-button | ||
| v-if="knowledgeTermbasePermission('termbaseExport')" | ||
| type="primary" | ||
| plain | ||
| :disabled="operationLoading" | ||
| @click="handleExportTermbases" | ||
| > | ||
| 导出 | ||
| </el-button> | ||
| <!-- 批量删除词语 --> | ||
| <el-button v-if="!isWorkspaceSharedResource() && knowledgeTermbasePermission('termbaseDelete')" type="danger" plain :loading="operationLoading" @click="handleBatchDeleteTermbases"> | ||
| <el-button | ||
| v-if="!isWorkspaceSharedResource() && knowledgeTermbasePermission('termbaseDelete')" | ||
| type="danger" | ||
| plain | ||
| :loading="operationLoading" | ||
| @click="handleBatchDeleteTermbases" | ||
| > | ||
| 删除 | ||
| </el-button> | ||
| </template> | ||
|
Contributor
Author
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. Review1.
|
||
|
|
||
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.
Here is a review of the code snippet:
1. Naming Inconsistency (Critical for Readability)
putTermbase, but its neighboring functions use inconsistent verbs for HTTP methods:getTerbbasePage(GET)deleteTermbase(DELETE)postTermbases/postExportTermbases(POST)putBatchDeleteTermbases(PUT)putTermbaseis technically correct for a PUT request, consider if this endpoint is actually for updating (which might be a PATCH or PUT) vs. replacing. More importantly, ensure the verb in the name matches the action. IfputBatchDeleteTermbasesexists,putTermbaseimplies a full replacement update. Ensure your team agrees on whether "update" maps topatchXorputX. Consistency is key.2. Return Type Mismatch / API Contract Check
putTermbasereturnsvoid(put<TermbaseUpdatePayload, void>). However,deleteTermbasereturnsboolean, andputBatchDeleteTermbasesalso returnsboolean.boolean. If it returns 204,voidis correct, but note thatputfrom many HTTP clients resolves toundefinedor the response object depending on configuration. Ensure yourputhelper handles204 No Contentgracefully when typed asvoid.3. Lack of Input Validation
payload: TermbaseUpdatePayloadis passed directly. There is no check ifTermbaseUpdatePayloadis partially defined or empty.TermbaseUpdatePayload, ensure it’s marked asPartial<Termbase>or explicitly defines optional fields to allow for PATCH-like behavior if intended. If it’s a full replacement (PUT), ensure all required fields are present in the type definition.4. Export Consistency
putTermbaseto the default export object maintains consistency with other CRUD operations. This looks good.5. Potential Optimization / Typo Check
Termbaseusually implies a whole database of terms. If this updates a single term, the naming might be misleading. Confirm ifknowledgeId + termbaseIdtargets a single term or a sub-document.Summary of Recommendations
✅ Code Structure: Good, follows existing patterns.
⚠️ Return Type: Confirm if the API returns
⚠️ Naming: Ensure
voidorboolean. Be consistent withdeleteTermbasewhich returnsboolean.putaccurately reflects the HTTP method (PUT vs PATCH). If you intend partial updates, considerpatchTermbase.💡 Type Safety: Ensure
TermbaseUpdatePayloadis well-typed to prevent partial sends if the server expects a full object for PUT.