mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
fix(plugin-authentication): CB-478 user editing form synchronisation
This commit is contained in:
+3
-1
@@ -112,9 +112,11 @@ export const UserForm = observer(function UserForm({
|
||||
const tabsStyles = [tabStyles, BORDER_TAB_STYLES];
|
||||
const translate = useTranslate();
|
||||
const service = useService(UserFormService);
|
||||
const controller = useController(UserFormController, user, editing, onCancel);
|
||||
const controller = useController(UserFormController);
|
||||
const [focusedRef] = useFocus<HTMLFormElement>({ focusFirstChild: true });
|
||||
|
||||
controller.update(user, editing, onCancel);
|
||||
|
||||
return styled(useStyles(styles, tabsStyles))(
|
||||
<TabsState container={service.tabsContainer} user={user} controller={controller} editing={editing}>
|
||||
<box as='div'>
|
||||
|
||||
+7
-2
@@ -81,11 +81,16 @@ export class UserFormController implements IInitializableController, IDestructib
|
||||
this.connectionAccessLoaded = false;
|
||||
}
|
||||
|
||||
init(user: AdminUserInfo, editing: boolean, collapse: () => void) {
|
||||
init(): void { }
|
||||
|
||||
update(user: AdminUserInfo, editing: boolean, collapse: () => void): void {
|
||||
const prevUser = this.user;
|
||||
this.user = user;
|
||||
this.editing = editing;
|
||||
this.collapse = collapse;
|
||||
this.loadRoles();
|
||||
if (prevUser !== this.user) {
|
||||
this.loadRoles();
|
||||
}
|
||||
}
|
||||
|
||||
destruct(): void {
|
||||
|
||||
+1
-1
@@ -99,7 +99,7 @@ export const UserInfo: TabContainerPanelComponent<IUserFormProps> = observer(fun
|
||||
value={role.roleId}
|
||||
name='role'
|
||||
checkboxLabel={role.roleName || role.roleId}
|
||||
checked={controller.credentials.roles.get(role.roleId)}
|
||||
checked={!!controller.credentials.roles.get(role.roleId)}
|
||||
disabled={controller.isSaving}
|
||||
mod='surface'
|
||||
onChange={checked => handleRoleChange(role.roleId, checked)}
|
||||
|
||||
+23
-9
@@ -7,13 +7,14 @@
|
||||
*/
|
||||
|
||||
import { observable, computed } from 'mobx';
|
||||
import { Subscription } from 'rxjs';
|
||||
|
||||
import { UsersResource } from '@cloudbeaver/core-authentication';
|
||||
import {
|
||||
injectable, IInitializableController, IDestructibleController
|
||||
} from '@cloudbeaver/core-di';
|
||||
import { NotificationService } from '@cloudbeaver/core-events';
|
||||
import { GQLErrorCatcher, AdminUserInfo } from '@cloudbeaver/core-sdk';
|
||||
import { GQLErrorCatcher, AdminUserInfo, isResourceKeyList } from '@cloudbeaver/core-sdk';
|
||||
|
||||
@injectable()
|
||||
export class UserEditController
|
||||
@@ -22,34 +23,47 @@ implements IInitializableController, IDestructibleController {
|
||||
@observable user: AdminUserInfo | null = null;
|
||||
|
||||
@computed get isDisabled() {
|
||||
return this.isLoading;
|
||||
return this.usersResource.isDataLoading(this.userId);
|
||||
}
|
||||
|
||||
userId!: string;
|
||||
|
||||
readonly error = new GQLErrorCatcher();
|
||||
|
||||
private subscription!: Subscription;
|
||||
|
||||
constructor(
|
||||
private notificationService: NotificationService,
|
||||
private usersResource: UsersResource
|
||||
) { }
|
||||
|
||||
init(id: string) {
|
||||
async init(id: string): Promise<void> {
|
||||
this.userId = id;
|
||||
this.loadUser();
|
||||
|
||||
await this.loadUser();
|
||||
this.subscription = this.usersResource.onItemAdd.subscribe(key => {
|
||||
if ((isResourceKeyList(key) && !key.includes(id)) || (key !== id)) {
|
||||
return;
|
||||
}
|
||||
this.updateUser();
|
||||
});
|
||||
}
|
||||
|
||||
destruct(): void { }
|
||||
destruct(): void {
|
||||
this.subscription.unsubscribe();
|
||||
}
|
||||
|
||||
private async loadUser() {
|
||||
this.isLoading = true;
|
||||
try {
|
||||
// we create a copy to protect the current value from mutation
|
||||
this.user = JSON.parse(JSON.stringify(await this.usersResource.load(this.userId)));
|
||||
await this.usersResource.load(this.userId);
|
||||
this.updateUser();
|
||||
} catch (exception) {
|
||||
this.notificationService.logException(exception, `Can't load user ${this.userId}`);
|
||||
} finally {
|
||||
this.isLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
private async updateUser() {
|
||||
this.user = JSON.parse(JSON.stringify(await this.usersResource.load(this.userId)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user