Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ui/src/views/document-detail/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ async function handleOpenCreateParagraph(position?: number) {
}

async function handleOpenParagraphDetail(paragraph: ParagraphItem, initialMode: 'detail' | 'edit' = 'detail') {
if (loading.value) return
if (loading.value || isWorkspaceSharedResource()) return
editDialogMounted.value = true
await nextTick()
editDialogRef.value?.open(paragraph, initialMode)
Expand Down Expand Up @@ -362,9 +362,9 @@ onMounted(() => {
<el-card
:id="`paragraph-${paragraph.id}`"
shadow="never"
class="mk-paragraph-card relative cursor-pointer overflow-visible!"
class="mk-paragraph-card relative overflow-visible!"
body-class="overflow-visible!"
:class="{ selectable: batchMode, active: batchMode && selectedParagraphIds.includes(paragraph.id), disabled: !paragraph.is_active }"
:class="{ 'cursor-pointer': !isWorkspaceSharedResource(), selectable: batchMode, active: batchMode && selectedParagraphIds.includes(paragraph.id), disabled: !paragraph.is_active }"
@click="handleClickParagraphCard(paragraph)"
>
<div

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Here's my review of the changes:

Summary

The diff adds a "shared workspace resource" guard that disables paragraph interaction (opening detail, pointer cursor) when the workspace is a shared read-only resource. This is generally reasonable but has a few issues.

Issues & Suggestions

  1. Inconsistent gating — click handler not guarded

    • You remove cursor-pointer and block handleOpenParagraphDetail, but @click="handleClickParagraphCard(paragraph)" still fires. If handleClickParagraphCard internally calls handleOpenParagraphDetail, that's fine; but if it triggers other side effects (selection, navigation), those will still run in shared mode.
    • Suggestion: Verify handleClickParagraphCard respects isWorkspaceSharedResource(), or guard at that level for a single source of truth.
  2. Batch mode / selection may still be allowed

    • The selectable and active classes are untouched. In shared mode with batchMode, users can still select paragraphs (checkbox, highlight). Confirm whether batch operations should be disabled in shared mode too — if so, add a guard where batchMode is entered/enabled.
  3. Repeated isWorkspaceSharedResource() calls

    • It's called inline in template (:class) on every render, potentially per card. If it's a cheap computed getter this is fine; if it does any meaningful work (e.g., reading route/store traversal), consider exposing a computed like isReadOnly or canEditParagraphs once and reuse it in both template and methods.
    • Suggestion:
      const isReadOnly = computed(() => isWorkspaceSharedResource())
      then use isReadOnly.value / isReadOnly consistently.
  4. Naming / semantics

    • isWorkspaceSharedResource() returning "should not edit" is an indirect signal. A dedicated predicate like isReadOnlyView() or canInteractWithParagraph() would make intent clearer at call sites.
  5. UX feedback

    • Silently ignoring the click may confuse users. Consider showing a tooltip ("Shared workspace – read only") on hover when shared, rather than just removing the pointer cursor.
  6. Template class binding readability

    • The ternary-in-object-key form works but is less readable. Also mixing cursor-pointer into an object key while other entries are static is fine but slightly inconsistent with prior style. Optional:
      :class="[
        { 'cursor-pointer': !isReadOnly },
        { selectable: batchMode, active: batchMode && selectedParagraphIds.includes(paragraph.id), disabled: !paragraph.is_active }
      ]"
  7. disabled class vs shared-mode visual state

    • When !paragraph.is_active, a .disabled style is applied. In shared mode, cards are also effectively non-interactive but get no visual cue besides missing pointer cursor. Consider adding a subtle shared/read-only visual state for consistency.
  8. Guard placement in handleOpenParagraphDetail

    • Early-return happens before editDialogMounted.value = true and nextTick() — good, avoids mounting the dialog unnecessarily. ✅ No issue here.

Minor Nit

  • The if (loading.value || isWorkspaceSharedResource()) return line now silently blocks opening the detail dialog even in detail mode (not just edit). If viewing details was intended to remain available in shared mode (read-only viewing), this is a behavior change worth confirming. If detail viewing should still be allowed, separate the guard:
    if (loading.value) return
    if (initialMode === 'edit' && isWorkspaceSharedResource()) return

Overall: Functionally OK, but the main risk is partially gated interactions (click handler, batch selection) and a possible unintended block on read-only viewing. Clarify the intended UX and centralize the read-only check.

Expand Down
5 changes: 3 additions & 2 deletions ui/src/views/knowledge-detail/library/image/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,10 @@ const { knowledge, resourceApi } = useKnowledgeDetailContext()
/* 图片分段详情:取首个分段,弹窗关闭后卸载。 */
const paragraphDialogRef = ref<InstanceType<typeof ParagraphDialog>>()
const selectedParagraph = ref<ParagraphItem & { source_file_id?: string }>()
const imageRowClassName = computed(() => (isWorkspaceSharedResource() ? '' : 'cursor-pointer'))

function handleOpenParagraph(document: DocumentItem, column?: TableColumnCtx<DocumentItem> | null) {
if (loading.value || operationLoading.value || selectedParagraph.value || column?.type === 'selection') return
if (isWorkspaceSharedResource() || loading.value || operationLoading.value || selectedParagraph.value || column?.type === 'selection') return
operationLoading.value = true
return resourceApi.paragraph
.getParagraphPage(knowledgeId.value, document.id, { currentPage: 1, pageSize: 1 })
Expand Down Expand Up @@ -333,7 +334,7 @@ onBeforeUnmount(() => {
@size-change="loadDocuments()"
@selection-change="handleSelectionChange"
@row-click="handleOpenParagraph"
row-class-name="cursor-pointer"
:row-class-name="imageRowClassName"
resizable
>
<el-table-column type="selection" width="40" reserve-selection v-if="!isWorkspaceSharedResource()" />

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Code Review

1. Bug: isWorkspaceSharedResource guard is inverted in handleOpenParagraph

if (isWorkspaceSharedResource() || loading.value || ...) return

This means when the resource is a workspace-shared resource, clicking a row does nothing. Combined with the template change (imageRowClassName returns 'cursor-pointer' only when not shared), this appears to be the intention — but verify it against the original behavior.

Issue: In the original code, row-class-name="cursor-pointer" was applied unconditionally, and handleOpenParagraph did not check isWorkspaceSharedResource(). So previously, clicking a row on a shared resource apparently did open the paragraph dialog. This patch silently disables that feature for shared resources.

  • If disabling is intended → fine, but confirm the product requirement.
  • If not → remove the isWorkspaceSharedResource() check from handleOpenParagraph.

2. Column config inconsistency (likely bug)

The el-table-column type="selection" is conditionally rendered with v-if="!isWorkspaceSharedResource()", but the row-click guard also checks column?.type === 'selection'. Since selection columns are hidden for shared resources, the column?.type === 'selection' branch is dead code in that path. Not harmful, but redundant given the new early return.

3. Naming

imageRowClassName is misleading — there's no logic about images here, just pointer-cursor styling. Prefer:

const rowClassName = computed(() =>
  isWorkspaceSharedResource() ? '' : 'cursor-pointer',
)

or clickableRowClassName.

4. Reactive dependency concern

isWorkspaceSharedResource() is called inside a computed. If it reads reactive refs/state, this works; if it reads non-reactive values (e.g., a module-level flag or route params cached once), the computed will never invalidate and the class may become stale. Verify isWorkspaceSharedResource actually touches reactive sources, otherwise consider using a plain function in the binding instead of computed.

5. Minor: empty string vs null

Returning '' for the class name is fine in Element Plus. Returning null would also work, but '' is safer across render paths.

6. Guard order / performance

In handleOpenParagraph, the cheap synchronous checks are first — good. However, operationLoading.value = true is set after early returns but before the async call; ensure the .finally() (or .catch) resets it. If the promise rejects without resetting, subsequent clicks lock the UI. Confirm the reset exists (not shown in the diff).

Summary

Severity Item
⚠️ High Behavior change for shared resources — confirm intent (item 1)
🟡 Low Rename imageRowClassName (item 3)
🟡 Low Verify isWorkspaceSharedResource reactivity inside computed (item 4)
ℹ️ Info Dead column?.type === 'selection' branch for shared resources (item 2)
ℹ️ Info Verify operationLoading reset on error (item 6)

Expand Down
Loading