Skip to content

fix: the community edition does not display the 'shared tools' and 'shared knowledge bases' menus - #8195

Merged
peslyn merged 1 commit into
v3from
pr@v3@fix_the_community_edition_dose_not_display_the_shared_tools_and_shared_knowledge_bases_menus
Nov 27, 2026
Merged

peslyn merged 1 commit into
v3from
pr@v3@fix_the_community_edition_dose_not_display_the_shared_tools_and_shared_knowledge_bases_menus

Conversation

@shaohuzhang1

Copy link
Copy Markdown
Contributor

fix: the community edition does not display the 'shared tools' and 'shared knowledge bases' menus

<FolderTree v-model="currentFolderId" :can-edit="false" :show-shared="(auth.isEE || auth.isPE) && isToolMenu" :source="source" @select="loadResources" />
</aside>

<section v-loading="loading" class="flex-column min-w-0 flex-1">

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 provided code diff, focusing on irregularities, potential issues, and optimization suggestions.

1. Potential Issue: Reactivity Loss with Destructured Store

Code: const { auth } = useStore()

  • Problem: In Vue's Pinia or similar stores, destructuring properties like this (const { auth } = useStore()) breaks reactivity. The auth variable will hold a static snapshot of the state at the time of component setup. It will not update automatically when the store state changes (e.g., if the user logs in, upgrades their plan, or permissions change dynamically).
  • Impact: The condition (auth.isEE || auth.isPE) && isToolMenu may fail to update the UI when auth.isEE or auth.isPE changes from false to true (or vice versa) after the component has mounted.
  • Recommendation: Use storeToRefs to maintain reactivity.
import { storeToRefs } from 'pinia'; // Or equivalent for your store library
const { auth } = storeToRefs(useStore());
// Note: With storeToRefs, auth becomes a Ref<AuthState>, so you access properties via auth.value?.isEE

Alternatively, if useStore returns reactive refs directly (Vue 3 Composition API style), ensure you are accessing them correctly. If it's a standard Pinia store instance, do not destructure actions/getters that depend on state without storeToRefs.

Corrected Approach (Pinia Example):

import { storeToRefs } from 'pinia'
import { useStore as useMainStore } from '@/stores' // Renamed to avoid conflict if needed

const mainStore = useMainStore()
const { auth } = storeToRefs(mainStore) 
// Now use auth.value.isEE in template or computed property

2. Optimization: Computed Property for Complex Condition

Code: :show-shared="(auth.isEE || auth.isPE) && isToolMenu"

  • Issue: Complex conditional logic directly in the template can hurt readability and performance (re-evaluated on every render). It also combines business logic (permissions) with UI presentation.
  • Suggestion: Move this logic into a computed property in the <script setup> block. This improves testability, readability, and ensures the value is cached until dependencies change.
const canShowShared = computed(() => {
  // Assuming auth is now reactive via storeToRefs
  return (auth.value?.isEE || auth.value?.isPE) && isToolMenu
})

Then in template:

<FolderTree ... :show-shared="canShowShared" ... />

3. Naming Convention & Context Clarity

  • Variable Name Confusion: The function useStore() imported from @/stores is very generic. Since there is already a useWorkflowStore from @/workflow-canvas/store, using a generic name like useStore might lead to confusion about which store is being accessed.
    • Suggestion: Rename the import to be more specific, e.g., import { useAuthStore } from '@/stores' or import { useGlobalStore } from '@/stores', depending on what auth represents.

4. Optional Chaining Safety

  • Issue: If auth can be undefined or null during initial load (before hydration or async initialization), accessing auth.isEE directly might throw an error.
  • Suggestion: Use optional chaining auth?.isEE regardless of the store implementation, especially if auth is derived asynchronously.

5. Summary of Recommended Changes

<script setup>
// ... existing imports
import { storeToRefs } from 'pinia' // Add import
import { useAuthStore } from '@/stores' // More descriptive name recommended

// ... other imports

const workflowStore = useWorkflowStore()
const authStore = useAuthStore()
const { auth } = storeToRefs(authStore) // Maintain reactivity

// ... existing code

// Add computed property
const showSharedFolder = computed({
  get: () => {
    // Handle potential null/undefined and use .value for ref
    return (auth.value?.isEE || auth.value?.isPE) ? isToolMenu : false
  }
})

defineOptions({ name: 'ResourceNodeMenu' })

// ... rest of script
</script>

<template>
  <!-- Use the computed property -->
  <aside v-if="!isSystemScope" class="flex w-sidebar-expanded shrink-0 border-r pt-3">
    <FolderTree 
      v-model="currentFolderId" 
      :can-edit="false" 
      :show-shared="showSharedFolder" 
      :source="source" 
      @select="loadResources" 
    />
  </aside>
  <!-- ... -->
</template>

Key Takeaway

The most critical issue is the loss of reactivity by destructuring auth without storeToRefs. This must be fixed to ensure the UI updates correctly when user entitlements (isEE/isPE) change.

@peslyn
peslyn merged commit 0a0e795 into v3 Nov 27, 2026
3 of 4 checks passed
@peslyn
peslyn deleted the pr@v3@fix_the_community_edition_dose_not_display_the_shared_tools_and_shared_knowledge_bases_menus branch November 27, 2026 03:44
:show-shared="auth.isEE || auth.isPE"
@loaded="selectFolder"
@select="selectFolder"
/>

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 are the findings, potential issues, and optimization suggestions for the code changes:

1. Naming Collision: useStore vs useAuth

  • Issue: You are importing useStore from @/stores and immediately destructuring auth from it: const { auth } = useStore().
  • Critique: If useStore is a global singleton store (like Pinia or Vuex), this works. However, if auth is its own separate store, calling useStore() might imply a dependency on a monolithic store rather than a modular one.
  • Suggestion: If auth is a distinct module, prefer using its specific composable (e.g., useAuth()) directly to reduce coupling and improve clarity. If it must be part of a larger store, consider naming it authStore or authState to distinguish from component-local refs.

2. Missing Validation/Type Checks for Auth Flags

  • Issue: The line :show-shared="auth.isEE || auth.isPE" assumes auth.isEE and auth.isPE are always boolean-like.
  • Risk: If auth is undefined during initial loading or if isEE/isPE are not initialized correctly, this could throw runtime errors or behave unexpectedly.
  • Suggestion: Ensure auth is safely initialized in the store. Alternatively, add optional chaining if supported by your template compiler (though often discouraged for performance): :show-shared="!!(auth?.isEE || auth?.isPE)". A safer approach is ensuring the store initializes these flags as booleans by default.

3. Hardcoded Business Logic in Template

  • Issue: The condition auth.isEE || auth.isPE represents business logic (Enterprise Edition or Professional Edition users can see shared resources).
  • Optimization: It is cleaner to compute this permission check in the script setup block rather than embedding it directly in the template.
  • Suggestion:
    const showShared = computed(() => auth.isEE || auth.isPE);
    Then use :show-shared="showShared". This improves readability, testability, and allows for easier modification of logic later.

4. Potential Race Condition / Initial Render

  • Issue: If useStore() returns an empty object initially while fetching auth state asynchronously, auth.isEE might be undefined during the first render.
  • Recommendation: Verify that the store provides default values (false) for isEE and isPE to prevent temporary UI glitches or errors before data loads.

5. Code Style & Consistency

  • Observation: The added lines follow existing indentation and style well. No formatting issues detected.

✅ Recommended Improved Code Snippet

<script setup>
import { computed } from 'vue';
import FolderTree from '@/components/business/folder-tree/index.vue'
import { TOOLTIP_SHOW_DELAY } from '@/components/global/mk-tooltip/constants'
import KnowledgeCard from '@/views/knowledge/knowledge-card/KnowledgeCard.vue'
import { FOLDER_ENTRY_ID } from '@/constants/folder'
import { useStore } from '@/stores' // Consider renaming if dedicated auth hook exists
import { isSystemResource, isSystemSharedResource, isWorkspaceResource } from '@/utils/resource-context'

const { t } = useI18n({ useScope: 'global' })
const { auth } = useStore()

// Extract logic into a computed property for clarity and reusability
const showSharedFeature = computed(() => !!(auth.isEE || auth.isPE));

defineOptions({ name: 'SelectKnowledgeDialog' })
// ...
</script>

<template>
  <!-- ... -->
  <FolderTree
    class="pt-4"
    :can-edit="false"
    :source="RESOURCE_TYPE.KNOWLEDGE"
    :show-shared="showSharedFeature"
    @loaded="selectFolder"
    @select="selectFolder"
  />
  <!-- ... -->
</template>

This version decouples logic from the template, enhances maintainability, and ensures safer evaluation of the feature flag.

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