Skip to content

fix: update role names reactively when switching languages - #8196

Merged
wangdan-fit2cloud merged 1 commit into
v3from
pr@v3@fix_role_traslation
Nov 27, 2026
Merged

wangdan-fit2cloud merged 1 commit into
v3from
pr@v3@fix_role_traslation

Conversation

@shaohuzhang1

Copy link
Copy Markdown
Contributor

fix: update role names reactively when switching languages

postSyncSystemUsers,
putUser,
putUserPassword,
}

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 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, and localizeRoleSource have been removed. Consequently, getUserManagePage no 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: getUserManagePage returns the raw promise from get. 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 in getUserManagePage slightly 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 like SystemUser include fields that were previously transformed, verify consumers aren't expecting localized text.

4. Recommendations

  1. ✅ Good Change: Simplifying the service layer by moving presentation concerns (localization) out of the API client is generally a best practice.
  2. ⚠️ Validation Needed: Confirm that all places using getUserManagePage render 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.
  3. 📝 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.

@wangdan-fit2cloud
wangdan-fit2cloud merged commit 776e497 into v3 Nov 27, 2026
3 of 4 checks passed
@wangdan-fit2cloud
wangdan-fit2cloud deleted the pr@v3@fix_role_traslation branch November 27, 2026 04:15
postRemoveSystemUserGroupMembers,
postSystemUserGroup,
postSystemUserGroupMembers,
}

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 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.roles or the localized structure of member.role_info, it will break or display incorrect data.
  • Recommendation: Ensure all consumers of getSystemUserGroupMembers have been updated to handle raw member.role_info instead of the previously derived member.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 postRemoveSystemUserGroupMembers arguments) 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 localizeRoleInfo import avoids linter warnings and dead code.
  • API Consistency: Ensure query parameter 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).

⚠️ Caution:

  • Verify downstream consumers. The removal of derived fields (roles, localized role_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>

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.

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.
  • formatLabel is called inside a computed, which re-runs whenever props.tags or formatLabel changes. If formatLabel identity 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.

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