Repository navigation
fix: search localized role names and adjust application type column - #8198
Conversation
| > | ||
| <el-button text type="primary" @click="handleOpenApplication(row)"> | ||
| <MkIcon name="icon_admin_outlined" /> | ||
| </el-button> |
There was a problem hiding this comment.
Here is a review of the code changes with potential issues and optimization suggestions:
1. Performance Optimization (Critical)
Issue: The v-if condition calls four separate functions (perm.application.system...) on every render cycle for every row in the table. If the permission check involves complex logic or API calls, this will significantly degrade performance for large tables.
Recommendation:
Pre-compute the result of this permission check outside the template loop. Create a computed property or a method that returns a boolean, ensuring it only runs once per data update rather than millions of times during rendering.
// In <script setup>
const canManage = computed(() => {
return perm.application.system.overviewRead() ||
perm.application.system.accessRead() ||
perm.application.system.chatLogRead() ||
perm.application.system.chatUserRead();
});Then use it in the template:
<MkTooltip v-if="canManage" :content="t('common.actions.manage')">2. Readability & Maintenance
Positive Change: Breaking the long v-if line into multiple lines improves readability significantly. This adheres well to Vue/HTML best practices.
3. Minor UI Adjustment
Change: Width increased from 100 to 110 for the "type" column.
- Check: Ensure that the new width doesn't cause horizontal overflow on smaller screens. Consider using CSS media queries or dynamic width adjustments if responsive design is a concern.
Summary
- Fix: Move the complex permission check out of the template's
v-ifto avoid repeated function calls. - Keep: The multi-line formatting for readability.
| role_list: group.role_list.filter(({ id, role_name }) => getRoleName(id, role_name).toLowerCase().includes(keyword)), | ||
| })) | ||
| .filter((group) => group.role_list.length > 0) | ||
| }) |
There was a problem hiding this comment.
The change introduces potential issues and performance concerns:
- Performance:
getRoleNameis called inside a.filter()on every item in the loop. If this function performs heavy computation or async operations, it will significantly slow down rendering. It should ideally be pre-computed or cached. - Null Safety: If
role_namecan benullorundefined,.toLowerCase()will throw an error unlessgetRoleNameguarantees a string return. - Side Effects: Ensure
getRoleNameis pure and does not mutate state or have side effects.
Suggestion: Cache the result of getRoleName(id, role_name) if possible, or ensure it's lightweight. Add optional chaining: getRoleName(id, role_name)?.toLowerCase() || ''.
fix: search localized role names and adjust application type column