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
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ defineExpose({ open, close })
<ParagraphForm ref="paragraphFormRef" v-model="paragraphForm" :knowledge-id="targetKnowledgeId" />
<!-- 关联问题 -->
<ParagraphQuestions
v-if="knowledgeQuestionPermission()"
v-model="relatedQuestions"
:show="knowledgeQuestionPermission()"
:knowledge-id="targetKnowledgeId"
:document-id="targetDocumentId"
/>

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.

Review of the Diff

What changed

  • Before: ParagraphQuestions was always rendered; visibility was delegated to the child via a :show prop driven by knowledgeQuestionPermission().
  • After: the component is conditionally rendered with v-if="knowledgeQuestionPermission()", and the show prop is removed.

Potential issues

  1. Permission function called during render — knowledgeQuestionPermission() is invoked on every re-render. If it performs non-trivial work (API calls, store lookups, deep checks), this hurts performance. Prefer a computed:

    const canShowQuestions = computed(() => knowledgeQuestionPermission())

    then v-if="canShowQuestions". A computed also avoids redundant recomputation across renders.

  2. Loss of child-side control — Removing :show shifts behavior from "child decides how to hide" (e.g., keeps state/mounted instance) to "parent unmounts." Confirm the child doesn't rely on being mounted while hidden (e.g., internal watchers, form init, telemetry). If it does, v-show may be more appropriate than v-if.

  3. v-if + v-model interaction — When permission flips false→true, the component remounts. Any local edits in relatedQuestions held inside the child could be reset. Ensure v-model binding survives remount correctly.

  4. Reactivity assumption — v-if requires knowledgeQuestionPermission() to be reactive (depends on refs/reactive state). If permission comes from a non-reactive source (plain function reading a module variable), the block won't update. Verify reactivity.

  5. Stale prop type / unused prop in child — Since :show was removed, check that ParagraphQuestions no longer declares/expects a required show prop and that its internal logic doesn't still gate on it (dead code / warnings).

  6. Naming consistency — knowledgeQuestionPermission() reads like a boolean getter; consider naming it hasKnowledgeQuestionPermission for clarity, or exposing it as a computed boolean directly in the template.

  7. Nested single-condition v-if — Fine here, but if more conditions are added later, consider computing a single predicate to keep the template clean.

Optimization suggestion

<script setup>
const canShowQuestions = computed(() => knowledgeQuestionPermission())
</script>

<template>
  <ParagraphQuestions
    v-if="canShowQuestions"
    v-model="relatedQuestions"
    :knowledge-id="targetKnowledgeId"
    :document-id="targetDocumentId"
  />
</template>

Verdict

The change itself is reasonable and arguably cleaner (permission gating at the parent avoids rendering an unauthorized component at all). Main risks are: calling a possibly non-reactive/expensive function in the template, and behavioral differences from remount vs hide. Address those two and the diff is sound.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ const loading = ref(false)
const detailFailed = ref(false)
const relatedQuestions = ref<ParagraphQuestionDraft[]>([])
const isImageDocument = computed(() => props.resourceType === DOCUMENT_RESOURCE_TYPE.IMAGE)
const showQuestions = computed(() => hasProblemReadPermission())

function loadParagraphDetail() {
if (loading.value) return
Expand Down Expand Up @@ -174,8 +173,8 @@ defineExpose({ open, close })
</div>
<!-- 关联问题 -->
<ParagraphQuestions
v-if="hasProblemReadPermission()"
v-model="relatedQuestions"
:show="showQuestions"
:knowledge-id="targetKnowledgeId"
:document-id="targetDocumentId"
:paragraph-id="targetParagraphId"

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.

The diff is small, but there are a few things to verify and potential improvements:

  1. Confirm ParagraphQuestions no longer requires show

    • You removed both :show="showQuestions" and the show prop usage. If the child component still declares show as a required prop, or uses it internally for conditional rendering/data loading, this will cause a warning or behavior change.
    • Either remove show from the child API or keep passing it.
  2. v-if changes behavior compared with a show prop

    • v-if unmounts ParagraphQuestions when permission is false. The old :show approach likely kept it mounted but hidden.
    • This can be an optimization because the child is not created when not needed.
    • However, it also means:
      • Child internal state is lost when permission becomes false.
      • Lifecycle hooks, watchers, and data fetching inside the child will not run until permission is true.
      • If permission toggles frequently, the component will be destroyed/recreated.
    • If preserving child state is important, use v-show or continue using a show prop.
  3. Avoid calling hasProblemReadPermission() directly in the template

    • It works, but it is called on every render.
    • A computed value is clearer and cached:
      const canReadProblems = computed(() => hasProblemReadPermission())
      
      <ParagraphQuestions v-if="canReadProblems" ... />
      
    • This is especially useful if the permission check is non-trivial or reused elsewhere.
  4. Ensure reactivity of the permission check

    • v-if="hasProblemReadPermission()" will update only if hasProblemReadPermission() depends on reactive state.
    • If it reads from a non-reactive global or cached value, the template will not re-render when permissions change.
  5. Check for remaining references to showQuestions

    • You removed the showQuestions computed. Make sure it is not referenced anywhere else in the file or exposed to the template.
  6. Check v-model behavior on remount

    • With v-model="relatedQuestions" and v-if, the child will remount when permission becomes true.
    • Verify that ParagraphQuestions does not emit an unintended update:modelValue on mount that could overwrite relatedQuestions.
  7. Consider the permission dependency on IDs

    • If hasProblemReadPermission() depends on targetKnowledgeId, targetDocumentId, or targetParagraphId, make sure those values are valid before rendering. Otherwise, the child may be shown/hidden incorrectly during initial load.

Overall, the change is reasonable if the goal is to avoid mounting ParagraphQuestions when the user lacks read permission. The main risks are the child component’s show prop contract and the behavioral difference between hiding and unmounting. Using a computed canReadProblems instead of a template method call would be a small readability and performance improvement.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const props = defineProps<{
knowledgeId: string
documentId: string
paragraphId?: string
show: boolean
}>()
const { resourceApi } = useDocumentDetailContext()
const relatedProblems = defineModel<ParagraphQuestionDraft[]>({ required: true })
Expand Down Expand Up @@ -142,7 +141,7 @@ function handleRemoveProblem(index: number) {
</script>

<template>
<aside v-if="show" v-loading="loading" class="mk-gray-card-lg flex-column w-60 shrink-0">
<aside v-loading="loading" class="mk-gray-card-lg flex-column w-60 shrink-0">
<div class="mb-4 flex-between shrink-0 gap-3">
<h4>{{ t('knowledge.paragraph.relatedQuestions.label') }}</h4>
<!-- 添加关联问题 -->

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.

The diff removes the show prop and its v-if guard, so the <aside> is now always rendered. Here are the issues and suggestions:

Potential Issues

  1. Loss of conditional rendering: Previously the parent could hide the panel via :show="false". Now visibility must be controlled by the parent using v-if/v-show on the component itself, or the panel will always mount. Confirm all call sites still want this behavior.

  2. Unused import / dead code: If show was used elsewhere (e.g., in a watcher, computed, or another branch), any leftover references will break the build or cause runtime errors. Double-check nothing else references show.

  3. v-loading now runs unconditionally: v-loading="loading" will activate even when the section is conceptually hidden. If loading is only meaningful while visible, gate the loading state or keep a lightweight v-show for layout stability.

  4. Layout shift: With w-60 shrink-0, the aside occupies width at all times. If it's meant to be collapsible, use v-show (keeps layout/DOM) vs v-if (removes DOM) deliberately — right now you've effectively forced it permanently visible.

  5. Breaking change to the public prop API: Removing show from defineProps is a breaking change for any consumer passing it. Vue will emit an "extraneous non-props attribute" warning and attach show as an HTML attribute on the root element instead of ignoring it. Consider deprecating it first or updating all usages atomically.

Suggestions

  • If the intent is "parent controls visibility," prefer not adding a prop and letting the parent wrap with v-if="show". This is cleaner and avoids a redundant prop.
  • If you keep removing show, ensure every call site is updated in the same changeset and remove now-dead imports/variables.
  • Consider whether the always-mounted resourceApi / relatedProblems model subscriptions cause unnecessary work when the panel is hidden; lazy-mount if expensive.
  • Verify tests/stories that referenced the show prop are updated.

Summary: The change is safe only if (a) all consumers no longer pass show, (b) no other code references show, and (c) the panel genuinely should always render. Otherwise, expect Vue attribute warnings and unintended always-visible UI.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ defineExpose({ open, close })
<div v-loading="loading" class="flex w-full gap-4">
<ParagraphForm ref="paragraphFormRef" v-model="paragraphForm" :knowledge-id="knowledgeId" />
<!-- 关联问题仅保存到导入草稿,未创建文档不传入分段 ID -->
<ParagraphQuestions v-model="relatedQuestions" :show="knowledgeQuestionPermission()" :knowledge-id="knowledgeId" document-id="" />
<ParagraphQuestions v-if="knowledgeQuestionPermission()" v-model="relatedQuestions" :knowledge-id="knowledgeId" document-id="" />
</div>
<template #footer>
<!-- 取消分段编辑 -->
Expand Down
51 changes: 0 additions & 51 deletions ui/tests/dingtalk-auth-code.test.mjs

This file was deleted.

96 changes: 0 additions & 96 deletions ui/tests/document-strategy-workspace.html

This file was deleted.

158 changes: 0 additions & 158 deletions ui/tests/login-manual-mode.test.mjs

This file was deleted.

34 changes: 0 additions & 34 deletions ui/tests/tool-export.test.mjs

This file was deleted.

Loading
Loading