mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-10-28 03:24:29 +08:00
Cb 5562 Fix bad this.setState for the new form API (#2903)
* CB-5478 adds useAdministrationUserFormState with flexible id field * CB-5478 simplifies logic fork form state hooks * CB-5562 refactors form state and form parts * CB-5562 fixes disabled param for formState * CB-5562 comments cleanup * CB-5562 fixes getting of exceptions * CB-5562 baseform bad set state fix * CB-5562 removes load and configure method for forms * CB-5562 reverts some state.exception changes * CB-5562 removes bad set state from user form * CB-5562 cleanup * CB-5562 cleanup * CB-5562 removes bad set state from user form * CB-5562 fixes bad set state for user profile * CB-5562 pr fixes * CB-5562 pr fixes --------- Co-authored-by: Daria Marutkina <125263541+dariamarutkina@users.noreply.github.com>
This commit is contained in:
co-authored by
Daria Marutkina
parent
4f0db5b854
commit
2d1bde22a2
+2
-2
@@ -59,7 +59,7 @@ export const AdministrationUserForm = observer<Props>(function AdministrationUse
|
||||
},
|
||||
});
|
||||
|
||||
useAutoLoad(AdministrationUserForm, state);
|
||||
useAutoLoad(AdministrationUserForm, [userFormInfoPart]);
|
||||
|
||||
return (
|
||||
<Form context={form} disabled={state.isDisabled} contents focusFirstChild>
|
||||
@@ -69,7 +69,7 @@ export const AdministrationUserForm = observer<Props>(function AdministrationUse
|
||||
<Container fill>
|
||||
<StatusMessage
|
||||
className={s(styles, { statusMessage: true })}
|
||||
exception={getFirstException(state.exception)}
|
||||
exception={getFirstException(userFormInfoPart.exception)}
|
||||
type={state.statusType}
|
||||
message={state.statusMessage}
|
||||
/>
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ export class UserFormConnectionAccessPart extends FormPart<AdminConnectionGrantI
|
||||
super(formState, []);
|
||||
}
|
||||
|
||||
isChanged(): boolean {
|
||||
get isChanged(): boolean {
|
||||
if (!this.loaded) {
|
||||
return false;
|
||||
}
|
||||
|
||||
+4
-13
@@ -9,12 +9,11 @@ import { observable, toJS } from 'mobx';
|
||||
|
||||
import type { AdminUser, AuthRolesResource, UserResourceIncludes, UsersResource } from '@cloudbeaver/core-authentication';
|
||||
import type { IExecutionContextProvider } from '@cloudbeaver/core-executor';
|
||||
import { CachedResourceIncludeArgs, getCachedDataResourceLoaderState } from '@cloudbeaver/core-resource';
|
||||
import { CachedResourceIncludeArgs } from '@cloudbeaver/core-resource';
|
||||
import type { ServerConfigResource } from '@cloudbeaver/core-root';
|
||||
import type { AdminUserInfoFragment } from '@cloudbeaver/core-sdk';
|
||||
import { FormMode, FormPart, formValidationContext, IFormState } from '@cloudbeaver/core-ui';
|
||||
import { isArraysEqual, isDefined, isObjectsEqual, isValuesEqual } from '@cloudbeaver/core-utils';
|
||||
import { DATA_CONTEXT_LOADABLE_STATE } from '@cloudbeaver/core-view';
|
||||
|
||||
import type { IUserFormState } from '../AdministrationUserFormService';
|
||||
import type { IUserFormInfoState } from './IUserFormInfoState';
|
||||
@@ -62,7 +61,7 @@ export class UserFormInfoPart extends FormPart<IUserFormInfoState, IUserFormStat
|
||||
return this.usersResource.isOutdated(this.initialState.userId, this.baseIncludes);
|
||||
}
|
||||
|
||||
return false;
|
||||
return this.serverConfigResource.isOutdated() || this.authRolesResource.isOutdated();
|
||||
}
|
||||
|
||||
isLoaded(): boolean {
|
||||
@@ -77,7 +76,7 @@ export class UserFormInfoPart extends FormPart<IUserFormInfoState, IUserFormStat
|
||||
return this.loaded;
|
||||
}
|
||||
|
||||
isChanged(): boolean {
|
||||
get isChanged(): boolean {
|
||||
if (!this.loaded) {
|
||||
return false;
|
||||
}
|
||||
@@ -138,14 +137,6 @@ export class UserFormInfoPart extends FormPart<IUserFormInfoState, IUserFormStat
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override configure() {
|
||||
const loadableStateContext = this.formState.dataContext.get(DATA_CONTEXT_LOADABLE_STATE)!;
|
||||
|
||||
loadableStateContext.getState('user-info', () => [
|
||||
getCachedDataResourceLoaderState(this.serverConfigResource, () => undefined),
|
||||
getCachedDataResourceLoaderState(this.authRolesResource, () => undefined),
|
||||
]);
|
||||
}
|
||||
|
||||
private async updateCredentials() {
|
||||
const password = this.state.password;
|
||||
@@ -220,7 +211,7 @@ export class UserFormInfoPart extends FormPart<IUserFormInfoState, IUserFormStat
|
||||
|
||||
protected override async loader() {
|
||||
let user: AdminUser | null = null;
|
||||
const serverConfig = await this.serverConfigResource.load();
|
||||
const [serverConfig] = await Promise.all([this.serverConfigResource.load(), this.authRolesResource.load()]);
|
||||
|
||||
if (this.formState.mode === FormMode.Edit && this.initialState.userId) {
|
||||
user = await this.usersResource.load(this.initialState.userId, this.baseIncludes);
|
||||
|
||||
Reference in New Issue
Block a user