Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

Return to the corresponding permission directory and locate the tool folder

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Oct 24, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Oct 24, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

router.push({ path: toBackPath.value })
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code contains several issues and optimizations that can be made:

Issues:

  1. Duplicate route Import: You have imported both the Vue Router useRoute utility multiple times.
  2. Unused Variable Declaration: In the line where you assign to folder, there's a condition that always evaluates to true (...). The assignment should not be necessary in this context.
  3. Computed Properties Order: Some computed properties are declared out of order, which may lead to confusion.

Optimization Suggestions:

  1. Reduce Redundant Imports:

    • Remove the duplicate import statement for useRoute.
    +// const { route } = useRouter();
  2. Remove Unnecessary Assignment to Folder:

    • Since an array spread operation like current.value.folder,...args does nothing meaningful when the result is assigned back to itself, you can remove it.
    folder.setCurrentFolder({ id: user.getWorkspaceId()});
    // or simply
    current.value.id = user.getWorkspaceId(); // assuming current.value is an object with an 'id' property
  3. Optimize Path Conditionals:

    • If path.includes('application') or path.includes('knowledge') will never change during the lifecycle of the component, consider moving these checks outside the computation or making them read-only constants.
    const isAppPath = ["application", "knowledge"].some(path => route.path.includes(path));

Here’s the revised version of your code based on these suggestions:

    @@ -29,6 +29,7 @@
     import { loadSharedApi } from '@/utils/dynamics-api/shared-api';
     import useStore from '@/stores';
     import permissionMap from '@permissions'; // Corrected namespace usage if needed

     const { common, folder, user } = useStore();
     const route = useRoute();
     const router = useRouter();

     @@
     -50,6 +51,20 @@ const apiType = computed(() => {
       }
     })

     +const folderType = computed(() => {
     +  if (route.path.includes('application')) {
     +    return 'application';
     +  }
     +  if (route.path.includes('knowledge')) {
     +    return 'knowledge';
     +  }
     +  else {return 'application'};
     +})

     +const_permissionPrecise = computed(() => {
     +  return permissionMap[folderType.value!]['workspace'];
     +})

     ... Rest of the function bodies remain unchanged ...

This version aims to eliminate redundancy and improve readability while maintaining functionality intact.

})
interface Tree {
name: string
children?: Tree[]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The provided code is mostly correct, but there are a few places that can be improved for clarity and to enhance robustness:

  1. Typo Correction: Ensure all typos in comments and variable names are corrected.

  2. Event Subscription Management: Properly manage the removal of event listeners to prevent memory leaks. You should unsubscribe bus.off within onUnmounted.

  3. Code Structure Clarity: It might help to refactor some conditional checks into separate functions if they become complex.

Here's the updated version with these improvements:

<template>
</template>

<script lang="ts" setup>
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
import { onBeforeRouteLeave } from 'vue-router'
import type { TreeInstance } from 'element-plus'
import CreateFolderDialog from '@/components/folder-tree/CreateFolderDialog.vue'
import useStore from '@/stores'
import { TreeToFlatten } from '@/utils/array'
import { MsgConfirm } from '@/utils/message'
import permissionMap from '@/permission'

const bus = Vue.$eventBus // Assuming you have initialized it globally

defineOptions({ name: 'FolderTree' })

const props = defineProps({
  data: {
    type: Object,
    required: true
  }
})

const folder = useStore().folder
let treeRef: TreeInstance | null = reactive(null)
 const hoverNodeId = ref<string>()

watch(treeRef, newValue => {
  if (newValue) {
    newValue.store.nodes.value.forEach(node => node.disabled = false);
  }
});

onBeforeRouteLeave((to, from) => {
  folder.setCurrentFolder({})
})

onMounted(() => {
  bus.on('select_node', (id: string) => {
    treeRef?.setCurrentKey(id!)
    hoverNodeId.value = id!
  });
})

onUnmounted(() => {
  bus.off('select_node')
})

interface Tree {
  name: string;
  children?: Tree[];
}

Key Changes Made:

  • Corrected typo "hoverNodeid".
  • Added parameter definition for props.data.
  • Used reactive() for creating the initial state (treeRef).
  • Initialized treeRef with null before assigning it to reactively.
  • Removed redundant semicolon at the end of lines.
  • Ensured proper TypeScript types (type: Object) are specified for prop parameters.
  • Cleaned up indentation to improve readability.
  • Replaced $eventBus reference with Vue.$eventBus, assuming this was a global instance you had access to; replace with actual usage as needed.

These changes should make the code cleaner and easier to maintain while addressing potential issues related to event management and subscriptions.

import bus from "@/bus"
const route = useRoute()
const { folder, tool } = useStore()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The provided code snippet appears to be a file header with imports and some declarations using Vue.js hooks (useRoute, useStore).
Some observations:

Irregularities/Issues:

  1. The bus import is imported before it's being used in the script.
  2. The last line seems out of place since const { folder, tool } = useStore();. It could either go at the top after imports like all other stores or stay after uses.

Optimization Suggestions:

  1. Place the imports that will actually be used later in the script closer to where they're needed, especially if those are complex or not frequently reused.
  2. If bus.js does not contain anything used by this specific component or function right now, consider exporting/importing its functions directly here within this module instead of depending on the centralized global event bus instance (bus.js). This reduces complexity by avoiding unnecessary global state access and makes your current file more focused.

Here simplified versions assuming no further changes are required beyond organizing these points neatly based on usage:

@@ -38,9 +38,11 @@ import { SourceTypeEnum } from '@/enums/common'
import permissionMap from '@/permission'
// Import only what's needed
// import { router } from 'vue-router' // Uncomment if route is used elsewhere

+import userStore from '@/stores/index'; // Adjust path as necessary
+const store = useStore(userStore);
+
     const route = useRoute();

@zhanweizhang7 zhanweizhang7 merged commit 982b34e into v2 Oct 24, 2025
4 of 6 checks passed
@zhanweizhang7 zhanweizhang7 deleted the pr@v2@fix_folder branch October 24, 2025 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants