Skip to content

feat: Optimize the menu Role Permission page#43

Merged
kagol merged 6 commits into
devfrom
wyp/roles-0507
May 29, 2025
Merged

feat: Optimize the menu Role Permission page#43
kagol merged 6 commits into
devfrom
wyp/roles-0507

Conversation

@wuyiping0628

@wuyiping0628 wuyiping0628 commented May 21, 2025

Copy link
Copy Markdown
Collaborator

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Added localization keys for success messages and confirmation prompts related to permissions, roles, and menus in English and Chinese.
    • Introduced a menu search input placeholder in both English and Chinese locales.
  • Refactor

    • Replaced menu tree component with a grid-based tree layout featuring enhanced columns and operation controls.
    • Enabled inline editing for permissions and roles, removing modal-based update forms.
    • Simplified role update handling by removing update modal and streamlining table interactions.
    • Improved role menu assignment with a modal containing a filterable tree and custom icons.
  • Style

    • Updated modal and button styles with rounded corners and reordered footer buttons for consistency.
    • Added icons and adjusted column order in role and permission tables for better clarity.
  • Chores

    • Removed the update role component and all associated code for a cleaner and more maintainable codebase.

@wuyiping0628 wuyiping0628 added the enhancement New feature or request label May 21, 2025
@coderabbitai

coderabbitai Bot commented May 21, 2025

Copy link
Copy Markdown

Walkthrough

This update refactors several Vue components related to menu, permission, and role management. It introduces new localization keys, restructures menu and permission editing to use grids with inline editing, removes modal-based update flows for roles and permissions, and updates UI elements for consistency. The update also removes the dedicated role update component, consolidating editing logic into grid-based interfaces. Additionally, menu tree handling changes from a tree component to a grid with tree configuration, and role permission selection UI is enhanced with filtering and icon support.

Changes

File(s) Change Summary
template/nestJs/locales.json Added multiple localization keys for success messages and confirmation prompts related to permissions, roles, and menus; updated menu add modal title; added menu search placeholder.
template/tinyvue/src/views/menu/info/components/info-tab.vue Updated onUpdate, onCheck, and onDelete function signatures to accept direct Node parameter; updated success message keys; added localeData prop to menu-tree; modified modal attributes and footer buttons styling.
template/tinyvue/src/views/menu/info/components/menu-tree.vue Replaced <tiny-tree> with <tiny-grid> configured as a tree; added multiple columns; added localeData prop; updated event emits to use row objects; added delete confirmation pop-up; imported new components and icons; added styling for icons.
template/tinyvue/src/views/permission/info/components/info-tab.vue Removed update permission modal and related state; enabled inline editing on grid cells; updated update handling to use grid's edit-closed event; simplified add permission modal layout and buttons; added delete confirmation UI with icons; removed redundant state and functions.
template/tinyvue/src/views/role/info/components/add-role.vue Removed mask-closable attribute; set modal width to 700; reordered footer buttons with cancel before confirm; added round styling to buttons; removed duplicate cancel button.
template/tinyvue/src/views/role/info/components/info-tab.vue Removed update role modal component and related state and logic; simplified update handling to only reload table; added permissions prop to role table; reordered pager layout; mapped permission IDs explicitly in role data; styled "Add Role" button as round.
template/tinyvue/src/views/role/info/components/menu-drawer.vue Replaced drawer and tree with modal and tiny-tree; added filter input for tree nodes; implemented filtering logic; added custom expand/shrink icons; updated footer buttons to cancel and confirm with event emissions; used local reactive visible state.
template/tinyvue/src/views/role/info/components/permission-table.vue Reordered grid columns so name column precedes desc.
template/tinyvue/src/views/role/info/components/role-table.vue Added permissions prop; removed roleUpdate event emit; added updateRoleClose event emit; added reactive roleTable; refactored update method to handle inline cell editing with API call and modal feedback; replaced type column with editable permissionIds multi-select; added icons and delete confirmation pop-up; updated grid column widths and edit configs; added styling for icons.
template/tinyvue/src/views/role/info/components/update-role.vue Deleted entire component, including props, events, types, and template.
template/tinyvue/src/views/menu/info/components/add-menu.vue Removed validation rule for icon field; other validation rules unchanged.
template/tinyvue/src/views/menu/info/components/update-form.vue Added icon selection form item with filterable select using imported icons JSON; replaced customIcon with icon in reactive data; added Vue h function import; no changes to validation or exposed methods.

Sequence Diagram(s)

Inline Role Update Flow (New)

sequenceDiagram
    participant User
    participant RoleTable (Grid)
    participant API
    participant Modal

    User->>RoleTable: Edit role cell (name or permissions)
    RoleTable->>API: updateRole(editedRow)
    API-->>RoleTable: Success/Error response
    RoleTable->>Modal: Show success/error message
    RoleTable->>Parent: emit updateRoleClose
Loading

Inline Permission Update Flow (New)

sequenceDiagram
    participant User
    participant PermissionGrid
    participant API
    participant Modal

    User->>PermissionGrid: Edit permission cell (name or desc)
    PermissionGrid->>API: updatePermission(editedRow)
    API-->>PermissionGrid: Success/Error response
    PermissionGrid->>Modal: Show success/error message
Loading

Poem

🐇
A hop, a skip, some grids anew,
Menus and roles now easy to view.
Modals retire, in-lines take the stage,
Permissions and names, all edited on-page.
With icons and rounds, the UI delights—
Rabbits rejoice in these streamlined nights!
🥕✨


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 7

🧹 Nitpick comments (7)
template/tinyvue/src/views/menu/info/components/menu-tree.vue (1)

66-72: Remove dead code (localeData prop & treeOp computed)

localeData and treeOp are never referenced in the template or script. Keeping unused reactives increases bundle size and cognitive load.

-  const props = defineProps<{
-    data: ITreeNodeData[];
-    localeData: { value: string; label: string }[];
-  }>();
+  const props = defineProps<{
+    data: ITreeNodeData[];
+  }>();
 
-  const treeOp = computed(() => ({ data: props.data }));
template/tinyvue/src/views/role/info/components/role-table.vue (6)

2-2: Remove unused import

The nextTick is imported but never used in this component. Remove it to keep imports clean.

-import { nextTick, reactive, ref, watch } from 'vue';
+import { reactive, ref, watch } from 'vue';

37-37: Remove unused reactive variable

The roleTable reactive variable is initialized but never used throughout the component.

-const roleTable = reactive([]);

74-82: Optimize permission name concatenation

The current string concatenation approach can be simplified using array methods for better readability and performance.

const getPermission = (row:any) => {
-  let permissionDate = ''
-  if (row?.permission.length) {
-    row?.permission.forEach((item, index) => {
-      permissionDate = `${permissionDate} ${row?.permission[index].name}`
-    });
-  }
-  return permissionDate
+  if (!row?.permission?.length) return '';
+  return row.permission.map(item => item.name).join(' ');
};

160-168: Add accessibility improvements for icon usage

The icon components are used without any accessibility attributes. Consider adding aria labels or tooltips.

-<iconCueL class="del-icon"></iconCueL>
+<iconCueL class="del-icon" aria-label="Bind role" title="Bind role"></iconCueL>
...
-<iconDel class="del-icon"></iconDel>
+<iconDel class="del-icon" aria-label="Delete role" title="Delete role"></iconDel>

171-171: Fix inconsistent CSS class naming

The delete operation uses the class operation-update which is misleading. It should use operation-delete to maintain clarity and consistency with its function.

-class="operation-update"
+class="operation-delete"

197-203: Fix CSS formatting issues

There are formatting issues in the CSS including a double semicolon and inconsistent spacing.

.del-icon{
  fill: #1890ff;
  margin-right: 8px;
-  margin-left: 16px;;
+  margin-left: 16px;
  font-size: 16px;
  margin-top: -3px;
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between da0be4c and 41100d9.

📒 Files selected for processing (10)
  • template/nestJs/locales.json (2 hunks)
  • template/tinyvue/src/views/menu/info/components/info-tab.vue (2 hunks)
  • template/tinyvue/src/views/menu/info/components/menu-tree.vue (1 hunks)
  • template/tinyvue/src/views/permission/info/components/info-tab.vue (1 hunks)
  • template/tinyvue/src/views/role/info/components/add-role.vue (1 hunks)
  • template/tinyvue/src/views/role/info/components/info-tab.vue (5 hunks)
  • template/tinyvue/src/views/role/info/components/menu-drawer.vue (1 hunks)
  • template/tinyvue/src/views/role/info/components/permission-table.vue (1 hunks)
  • template/tinyvue/src/views/role/info/components/role-table.vue (5 hunks)
  • template/tinyvue/src/views/role/info/components/update-role.vue (0 hunks)
💤 Files with no reviewable changes (1)
  • template/tinyvue/src/views/role/info/components/update-role.vue
🔇 Additional comments (11)
template/tinyvue/src/views/role/info/components/permission-table.vue (1)

8-11: Column order changed to improve UI layout.

The name column is now positioned before the description column, which provides a more logical viewing order when users scan the permission table.

template/tinyvue/src/views/role/info/components/add-role.vue (2)

100-100: UI enhancement: Added rounded styling to primary button.

The rounded styling improves visual consistency with other buttons in the role and permission management interfaces.


103-103: UI enhancement: Added rounded styling to cancel button.

The rounded styling on the cancel button matches the confirm button and maintains consistent UI design throughout the application.

template/nestJs/locales.json (2)

593-593: Added English localization key for search placeholder.

New localization key menu.add.placeholder with English translation supports search input functionality in the menu management UI.


1201-1201: Added Chinese localization key for search placeholder.

Corresponding Chinese translation for the menu.add.placeholder key ensures consistent internationalization support.

template/tinyvue/src/views/menu/info/components/info-tab.vue (2)

98-98: Updated parameter handling in onUpdate function.

Changed from destructured { data } to direct data: Node parameter to align with updated event payload structure from the child component.


260-260: Added localeData prop binding to menu-tree component.

This provides locale information to the menu-tree component, enabling proper localization support for menu items in the tree display.

template/tinyvue/src/views/menu/info/components/menu-tree.vue (1)

25-30: Possible duplicate icon rendering

The customIcon column already displays the icon (<component :is="row.customIcon">).
Rendering the same icon again in the Operations column (line 35) may be unintentional noise.

Confirm if the second icon is required; otherwise remove it to declutter the grid.

template/tinyvue/src/views/permission/info/components/info-tab.vue (1)

130-139: Form validation rules reference non-existent props

Rules reference name and desc, but the form items use prop="desc" and prop="name" in reverse order (desc first).
Although both fields are required, clarify to avoid accidental mismatches when extending rules.

No code change needed; just verify.

template/tinyvue/src/views/role/info/components/role-table.vue (2)

119-122: Good implementation of inline editing

The use of cell-based editing with trigger on click is a good approach for inline editing. This aligns with the refactoring goal of removing the modal workflow.


139-157: Well-structured permission selection field

The implementation of the permission selection using TinySelect with multiple selection support is a good approach. The configuration is comprehensive with proper value and text field mappings.

Comment thread template/tinyvue/src/views/menu/info/components/menu-tree.vue Outdated
Comment thread template/tinyvue/src/views/role/info/components/menu-drawer.vue
Comment thread template/tinyvue/src/views/role/info/components/menu-drawer.vue
Comment thread template/tinyvue/src/views/role/info/components/menu-drawer.vue
Comment thread template/tinyvue/src/views/role/info/components/info-tab.vue
Comment thread template/tinyvue/src/views/permission/info/components/info-tab.vue
Comment thread template/tinyvue/src/views/role/info/components/role-table.vue
@kagol

kagol commented May 27, 2025

Copy link
Copy Markdown
Member

@wuyiping0628 主要有以下问题:

  1. 新建的无父节点的菜单,点击删除,控制台报错
    image
  2. 表格列最后的删除操作需要加上 PopConfirm 确认框的交互
  3. 这个页面的表格第一列有勾选框,但实际上勾选之后没有任何作用,建议:要么去掉这个勾选框,要么增加批量删除的操作
  4. 点击弹窗空白处不应该关闭弹窗,容易误操作,导致用户填写的表单数据丢失
    image

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
template/tinyvue/src/views/menu/info/components/update-form.vue (2)

70-70: Consider adding error handling for missing icons data.

The icons import assumes the JSON file exists and has the expected structure. Consider adding error handling or type checking to prevent runtime errors.

-import { icons } from '@opentiny/icons/json/icons.json';
+import { icons } from '@opentiny/icons/json/icons.json';
+
+// Add type safety and error handling
+const safeIcons = icons || {};

130-136: Optimize icon data generation for better performance.

The current implementation creates a new iconDatas array with rendered elements on every component instantiation, which could impact performance with a large number of icons.

Consider memoizing the icon data or moving it outside the component:

-const iconDatas = Object.keys(icons).map((key) => {
-  return {
-    label: key,
-    value: key,
-    icon: h('i', { class: `ci-${key}`, style: { fontSize: '18px',  marginRight: '6px' } }),
-  };
-});
+const iconDatas = computed(() => 
+  Object.keys(icons).map((key) => ({
+    label: key,
+    value: key,
+    icon: h('i', { 
+      class: `ci-${key}`, 
+      style: { fontSize: '18px', marginRight: '6px' },
+      'aria-label': key // Add accessibility
+    }),
+  }))
+);

This change:

  • Uses computed() for better reactivity management
  • Adds aria-label for accessibility
  • Fixes spacing in the style object
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fbd86a4 and ec4ffc8.

📒 Files selected for processing (9)
  • template/nestJs/locales.json (6 hunks)
  • template/tinyvue/src/views/menu/info/components/add-menu.vue (0 hunks)
  • template/tinyvue/src/views/menu/info/components/info-tab.vue (6 hunks)
  • template/tinyvue/src/views/menu/info/components/menu-tree.vue (2 hunks)
  • template/tinyvue/src/views/menu/info/components/update-form.vue (3 hunks)
  • template/tinyvue/src/views/permission/info/components/info-tab.vue (1 hunks)
  • template/tinyvue/src/views/role/info/components/add-role.vue (2 hunks)
  • template/tinyvue/src/views/role/info/components/info-tab.vue (6 hunks)
  • template/tinyvue/src/views/role/info/components/role-table.vue (5 hunks)
💤 Files with no reviewable changes (1)
  • template/tinyvue/src/views/menu/info/components/add-menu.vue
🚧 Files skipped from review as they are similar to previous changes (7)
  • template/tinyvue/src/views/role/info/components/add-role.vue
  • template/tinyvue/src/views/permission/info/components/info-tab.vue
  • template/tinyvue/src/views/menu/info/components/menu-tree.vue
  • template/nestJs/locales.json
  • template/tinyvue/src/views/role/info/components/info-tab.vue
  • template/tinyvue/src/views/menu/info/components/info-tab.vue
  • template/tinyvue/src/views/role/info/components/role-table.vue
🔇 Additional comments (2)
template/tinyvue/src/views/menu/info/components/update-form.vue (2)

41-50: LGTM! Icon selection form item is well implemented.

The new icon selection form item correctly uses a filterable select with proper placeholder and validation setup. The implementation follows the established pattern used by other form items in this component.


68-68:

Details

✅ Verification successful

Verify the h function import is necessary.

The h function is imported but should be confirmed as necessary for the icon rendering in the iconDatas array.


🏁 Script executed:

#!/bin/bash
# Description: Verify if the h function is actually used in the component
# Expected: Should find usage of h() function in the iconDatas array

rg -A 5 -B 5 "h\(" template/tinyvue/src/views/menu/info/components/update-form.vue

Length of output: 618


No changes needed for h import

The h function is used in the iconDatas array to render the <i> elements for icons, so the import should be kept.

Comment thread template/tinyvue/src/views/menu/info/components/update-form.vue
@kagol kagol merged commit a49f90b into dev May 29, 2025
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request nestjs web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants