Skip to content
Merged
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
2 changes: 1 addition & 1 deletion ui/src/views/knowledge-detail/library/document/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ onBeforeUnmount(() => {
<template v-if="!isWorkspaceSharedResource()">
<!-- 导入 Web、飞书或工作流文档 -->
<ButtonImportDocument
v-if="!showQuickCreate"
v-if="!showQuickCreate && knowledgeDocPermission('docCreate')"
:api="resourceApi.document"
:knowledge-id="knowledgeId"
:knowledge-type="knowledgeType"

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 is an analysis of the code change:

Irregularities/Issues:

  1. Naming Convention: knowledgeDocPermission looks like a function call rather than a standard computed property or reactive boolean used in Vue templates. If it is a method, calling it directly in v-if will re-execute on every render, which is inefficient for permission checks.
  2. Short-circuit Evaluation: While logically sound, v-if="!showQuickCreate && knowledgeDocPermission('docCreate')" creates two separate reactive dependency traces. If showQuickCreate changes frequently but permissions do not, Vue still evaluates the expression (though short-circuits). It is generally cleaner to consolidate complex conditional logic into a single computed property.

Optimization Suggestions:

  1. Use a Computed Property: Move this logic to a computed block for better readability, maintainability, and performance caching.
    const canShowImportButton = computed(() => {
        return !showQuickCreate.value && knowledgeDocPermission('docCreate');
    });
    Then use it in the template: <ButtonImportDocument v-if="canShowImportButton" ...>
  2. Verify Function Side Effects: Ensure knowledgeDocPermission is a pure function (no side effects) if kept in the template. If it's a method, consider converting it to a computed dependency or ensuring it is sufficiently lightweight.

Summary: The change adds a necessary permission check, but should be refactored into a computed property for best practices in Vue.

Expand Down
Loading