Skip to content

fix: honor question permissions in paragraph dialogs - #8288

Merged
wangdan-fit2cloud merged 1 commit into
v3from
pr@v3@fix_question
Dec 3, 2026
Merged

wangdan-fit2cloud merged 1 commit into
v3from
pr@v3@fix_question

Conversation

@shaohuzhang1

Copy link
Copy Markdown
Contributor

fix: honor question permissions in paragraph dialogs

: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.

@wangdan-fit2cloud
wangdan-fit2cloud merged commit 934d2d4 into v3 Dec 3, 2026
3 of 4 checks passed
@wangdan-fit2cloud
wangdan-fit2cloud deleted the pr@v3@fix_question branch December 3, 2026 09:56
<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.

: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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants