Repository navigation
fix: user workspace select error #7715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ import UserAuthorizationList from './components/UserAuthorizationList.vue' | |
| import UserGroupAuthorizationList from './components/user-group/UserGroupAuthorizationList.vue' | ||
| import { RESOURCE_AUTHORIZATION_LABELS } from './constants' | ||
|
|
||
| const { auth } = useStore() | ||
| const { auth, user } = useStore() | ||
| const route = useRoute() | ||
|
|
||
| const resourceType = ref<ResourceAuthorizationType>((route.meta.resource as ResourceAuthorizationType) ?? RESOURCE_TYPE.APPLICATION) | ||
|
|
@@ -40,7 +40,7 @@ const resourceTypeOptions: OptionItem<ResourceAuthorizationType>[] = [ | |
|
|
||
| /* 选择工作空间列表 */ | ||
| const loadingView = ref(false) | ||
| const selectedWorkspaceId = ref('default') | ||
| const selectedWorkspaceId = ref(user.userInfo?.workspace_list?.[0]?.id ?? 'default') | ||
| const workspaceOptions = ref<WorkspaceItem[]>([]) | ||
|
|
||
| function handleWorkspaceSelect(workspace: WorkspaceItem) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The diff is syntactically fine, but there are a few potential issues to review:
Overall, the main risk is async user/workspace data loading. If |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming this is Vue 3 + Pinia, the change is reasonable but has a few potential issues.
Potential issues
Pinia destructuring may break reactivity
Destructuring state/getters from a Pinia store can lose reactivity if the property is later replaced. If
useris a state/getter and may update asynchronously, prefer:If
useris an action or a stable nested object and you only read it once, this is less critical.Initialization timing / async user data
This reads
userInfoonly once during setup. IfuserInfoorworkspace_listis loaded asynchronously after component creation,selectedWorkspaceIdwill stay'default'and will not update when data arrives.Use a
watchwithimmediate: true, and avoid overwriting a valid user selection.Fallback only handles
null/undefined?? 'default'does not handle an empty string or an invalid workspace ID. If empty IDs are possible, validate explicitly:Be careful if
0is a valid ID — in that case use an explicit check instead of||.Type inference may be wrong
If
WorkspaceItem['id']isnumber, then:may infer
number | "default", which can conflict with code expecting astring. Consider:or a proper
WorkspaceIdtype.usermay be undefinedIf there is any chance
useris not always defined, use:Otherwise the current optional chaining only protects
userInfo, notuser.Selected workspace may not exist in
workspaceOptionsDefaulting to the first workspace from
userInfocan produce an invalid selection ifworkspaceOptionsis loaded later or filtered. Make sureselectedWorkspaceIdis always present inworkspaceOptions, or initialize it after options are loaded.Product behavior change
Previously the default was
'default'; now it is the first workspace. Confirm this is intentional. If'default'is a special backend value, switching to a real workspace ID may change API behavior.Suggested safer pattern
Summary
The main risks are:
selectedWorkspaceIdbefore async user/workspace data is available,The change is safe only if
user.userInfois guaranteed to be available synchronously and ifworkspace_list[0]is always a valid selectable workspace.