Repository navigation
fix: update role names reactively when switching languages - #8196
Conversation
| postSyncSystemUsers, | ||
| putUser, | ||
| putUserPassword, | ||
| } |
There was a problem hiding this comment.
Here is a review of the code diff provided. The primary change removes localization logic for system users, simplifies the API response handling, and improves code formatting.
1. Functional Changes & Potential Issues
- Removal of Localization Logic: The functions
localizeSystemUser,localizeRoleName, andlocalizeRoleSourcehave been removed. Consequently,getUserManagePageno longer transforms the data before returning it.- Risk: If any downstream components rely on localized role names or sources (e.g., Chinese vs. English), they will now receive raw backend data. Ensure UI components handle raw data correctly or perform localization themselves.
- Simplified Data Flow:
getUserManagePagereturns the raw promise fromget. This is good if the UI can handle raw data or if localization moved elsewhere. It reduces coupling in the service layer. - Unused Import Removal: The import
import { localizeRoleName, localizeRoleSource }was correctly removed since these functions are no longer used in this file. This prevents linting errors.
2. Code Style & Formatting
- Export Object Formatting: The default export object changed from a single line to a multi-line format. This is improvement for readability, especially as the list of exported functions grows. Each function is on its own line, making it easier to add/remove items and see diffs clearly.
- Whitespace Cleanup: An extra blank line before
/** 下载系统用户导入模板。 */was removed, improving vertical space consistency.
3. Optimization Suggestions
- No Performance Impact: The changes do not introduce significant performance benefits or drawbacks. Removing the
.map()call ingetUserManagePageslightly reduces overhead on large lists, which is beneficial. - Type Safety: Ensure that
ResponsePage<SystemUser>and the actual data returned by the backend align with what the UI expects after removing localization. If types likeSystemUserinclude fields that were previously transformed, verify consumers aren't expecting localized text.
4. Recommendations
- ✅ Good Change: Simplifying the service layer by moving presentation concerns (localization) out of the API client is generally a best practice.
⚠️ Validation Needed: Confirm that all places usinggetUserManagePagerender role names correctly without client-side transformation. If localization is required, consider implementing it at the component level or via a shared utility hook/component instead of mutating API responses globally.- 📝 Documentation Update: Since behavior changed (data is no longer pre-localized), update any internal docs or comments explaining how user/role data flows through the app.
Overall, this is a clean refactor that decouples presentation logic from data fetching. No bugs introduced if downstream consumers don't depend on localized strings in the API response.
| postRemoveSystemUserGroupMembers, | ||
| postSystemUserGroup, | ||
| postSystemUserGroupMembers, | ||
| } |
There was a problem hiding this comment.
Here is a review of the code changes, focusing on functionality, potential issues, and style.
1. Functional Impact & Potential Issue (Critical)
Change: Removal of localizeRoleInfo logic in getSystemUserGroupMembers.
Issue: The original code transformed API data (role_info) into additional fields (roles array of strings, localized role_info). This change removes that transformation.
- Consequence: If any component consuming this API relies on
member.rolesor the localized structure ofmember.role_info, it will break or display incorrect data. - Recommendation: Ensure all consumers of
getSystemUserGroupMembershave been updated to handle rawmember.role_infoinstead of the previously derivedmember.roles. If localization/display logic moved to the UI layer, verify it's correctly implemented there.
2. Code Style & Formatting
Change: Multi-line formatting in exports and function arguments.
Observation: Positive change.
- Splitting long lines (like the default export and
postRemoveSystemUserGroupMembersarguments) improves readability and adheres to common Prettier/ESLint guidelines.
3. Optimization
Change: Simplified getSystemUserGroupMembers.
Observation: Positive performance improvement.
- Removing the
.then()block and.map()iteration eliminates unnecessary client-side processing of every list item. This reduces CPU usage, especially for large pages/records.
4. Consistency Check
- Import Cleanup: Correct removal of unused
localizeRoleInfoimport avoids linter warnings and dead code. - API Consistency: Ensure
queryparameter usage remains consistent with other paginated functions in the file (it currently does).
Summary
✅ Good Changes:
- Removed unused import.
- Improved readability via formatting.
- Eliminated unnecessary client-side mapping (performance gain).
- Verify downstream consumers. The removal of derived fields (
roles, localizedrole_info) is a behavioral breaking change if not synchronized across the application.
| <el-tag v-for="tag in tagLabels.slice(1)" :key="tag" type="info" :size="size" :title="tag" :disable-transitions="true"> | ||
| {{ tag }} | ||
| </el-tag> | ||
| </div> |
There was a problem hiding this comment.
Review
1. Silent data loss (most important)
In tagLabels, object tags are dropped when formatLabel is not provided:
return formatLabel ? [formatLabel(tag)] : []This silently hides items, so +N counts and the popover list will be wrong without any warning. Consider falling back (e.g. String(tag)) or, at minimum, dev-mode warning.
2. Duplicate-key risk in v-for
<el-tag v-for="tag in tagLabels.slice(1)" :key="tag" ...>Keys are the label strings — duplicate labels cause Vue key collisions. Use index (:key="index") or a composite key.
3. title binding on the first tag
tagLabels[0] may be undefined when tags is empty; previously tags?.[0] guarded this. Functionally OK (attribute omitted), but the first el-tag is still rendered with empty content when there are no tags. Was the original intent to render nothing at all? If so, add v-if="tagLabels.length".
4. Generic type narrowing
defineProps<{ tags?: (string | T)[] }> with generic="T extends object" works, but flatMap inference can be loose. typeof tag === 'string' narrowing is fine here; just be aware consumers using only strings must still supply T, or rely on the default. Consider documenting that T is only needed for object tags.
5. Unnecessary non-null assertion / redundant nullish check
(tags ?? []) is redundant since the prop default is () => []. Harmless, but optional chaining elsewhere (tags?.length) was removed — fine given the default.
6. Minor typo suggestion
Comment says "字符串或待格式化的标签数据" — accurate, but clarify behavior when formatLabel is missing (see point 1).
7. Optimization suggestions
- Wrap
slice(1)results in a computed (restLabels) to avoid re-slicing on each render. formatLabelis called inside acomputed, which re-runs wheneverprops.tagsorformatLabelchanges. IfformatLabelidentity changes per parent render (inline arrow functions), the computed recomputes unnecessarily — acceptable, but worth noting for perf-sensitive lists.- Consider
Object.freeze/stable keys if tags can be reordered.
Verdict
Logic is mostly sound; the silent drop of object tags without formatLabel and duplicate :key usage are the two issues I'd fix before merging.
fix: update role names reactively when switching languages