mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-10-25 09:34:18 +08:00
CB-4067 cleanup
This commit is contained in:
@@ -151,7 +151,7 @@ export class FormState<TState> implements IFormState<TState> {
|
||||
|
||||
async reload() {
|
||||
for (const part of this.parts.values()) {
|
||||
await part.load();
|
||||
await part.reload();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,5 +16,6 @@ export interface IFormPart<TState> extends ILoadableState {
|
||||
readonly isChanged: boolean;
|
||||
|
||||
load(): Promise<void>;
|
||||
reload(): Promise<void>;
|
||||
reset(): void;
|
||||
}
|
||||
|
||||
@@ -154,17 +154,12 @@ export class ConnectionSearchService {
|
||||
port: String(database.port),
|
||||
driverId: database.defaultDriver,
|
||||
},
|
||||
// TODO remove it?
|
||||
submitType: null,
|
||||
projectId: projects[0]!.id,
|
||||
availableDrivers: database.possibleDrivers,
|
||||
type: 'public',
|
||||
});
|
||||
|
||||
// this.formState.closeTask.addHandler(this.goBack.bind(this));
|
||||
}
|
||||
|
||||
// this.formState.load();
|
||||
}
|
||||
|
||||
private clearFormState() {
|
||||
|
||||
+2
@@ -22,6 +22,7 @@ interface Props {
|
||||
export const ConnectionEdit = observer<Props>(function ConnectionEditNew({ item }) {
|
||||
const data = useConnectionFormState(item, state => {
|
||||
state.setMode(FormMode.Edit);
|
||||
// TODO refactor it?
|
||||
state.setState({
|
||||
...state.state,
|
||||
config: {
|
||||
@@ -37,6 +38,7 @@ export const ConnectionEdit = observer<Props>(function ConnectionEditNew({ item
|
||||
const projectId = item.projectId;
|
||||
const connectionId = item.connectionId;
|
||||
|
||||
// TODO remove it?
|
||||
useMemo(() => {
|
||||
data.state.config.connectionId = connectionId;
|
||||
data.state.projectId = projectId;
|
||||
|
||||
-2
@@ -112,8 +112,6 @@ export class CreateConnectionService {
|
||||
submitType: null,
|
||||
type: 'admin',
|
||||
});
|
||||
|
||||
// this.data.closeTask.addHandler(this.cancelCreate.bind(this));
|
||||
}
|
||||
|
||||
clearConnectionTemplate(): void {
|
||||
|
||||
+6
-2
@@ -72,13 +72,17 @@ export class ConnectionFormAccessPart extends FormPart<IConnectionFormAccessStat
|
||||
return;
|
||||
}
|
||||
|
||||
const promises = [];
|
||||
|
||||
if (subjectsToRevoke.length > 0) {
|
||||
await this.connectionInfoResource.deleteConnectionsAccess(key, subjectsToRevoke);
|
||||
promises.push(this.connectionInfoResource.deleteConnectionsAccess(key, subjectsToRevoke));
|
||||
}
|
||||
|
||||
if (subjectsToGrant.length > 0) {
|
||||
await this.connectionInfoResource.addConnectionsAccess(key, subjectsToGrant);
|
||||
promises.push(this.connectionInfoResource.addConnectionsAccess(key, subjectsToGrant));
|
||||
}
|
||||
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
edit() {
|
||||
|
||||
+5
-3
@@ -11,18 +11,20 @@ import { ConnectionInfoResource, createConnectionParam, type DBDriverResource }
|
||||
import type { IConnectionFormState } from '../IConnectionFormState.js';
|
||||
import type { IConnectionProperties } from '../Options/IConnectionConfig.js';
|
||||
|
||||
const getDefaultState = (): IConnectionProperties => ({});
|
||||
|
||||
export class ConnectionFormDriverPropertiesPart extends FormPart<IConnectionProperties, IConnectionFormState> {
|
||||
constructor(
|
||||
formState: IFormState<IConnectionFormState>,
|
||||
private readonly dbDriverResource: DBDriverResource,
|
||||
private readonly connectionInfoResource: ConnectionInfoResource,
|
||||
) {
|
||||
super(formState, {});
|
||||
super(formState, getDefaultState());
|
||||
}
|
||||
|
||||
protected override async loader(): Promise<void> {
|
||||
if (!this.formState.state.config.connectionId || !this.formState.state.projectId) {
|
||||
this.setInitialState({});
|
||||
this.setInitialState(getDefaultState());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -30,7 +32,7 @@ export class ConnectionFormDriverPropertiesPart extends FormPart<IConnectionProp
|
||||
createConnectionParam(this.formState.state.projectId, this.formState.state.config.connectionId),
|
||||
);
|
||||
|
||||
this.setInitialState(connection?.properties ?? {});
|
||||
this.setInitialState(connection?.properties ?? getDefaultState());
|
||||
}
|
||||
|
||||
protected override async saveChanges(
|
||||
|
||||
+2
-2
@@ -52,12 +52,12 @@ export const DriverProperties: TabContainerPanelComponent<IConnectionFormProps>
|
||||
|
||||
runInAction(() => {
|
||||
if (driver.data) {
|
||||
for (const key of Object.keys(driverPropertiesPart.state ?? {})) {
|
||||
for (const key of Object.keys(driverPropertiesPart.state)) {
|
||||
if (driver.data.driverProperties.some(property => property.id === key) || state.propertiesList.some(property => property.key === key)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
state.add(key, driverPropertiesPart.state![key]);
|
||||
state.add(key, driverPropertiesPart.state[key]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -9,7 +9,7 @@ import { DriverConfigurationType } from '@cloudbeaver/core-sdk';
|
||||
import { schema } from '@cloudbeaver/core-utils';
|
||||
import { CONNECTION_NETWORK_HANDLER_SCHEMA } from './IConnectionNetworkHanler.js';
|
||||
|
||||
export const CONNECTION_PROPERTIES_SCHEMA = schema.record(schema.any()).optional();
|
||||
export const CONNECTION_PROPERTIES_SCHEMA = schema.record(schema.any());
|
||||
|
||||
export const CONNECTION_CONFIG_SCHEMA = schema.object({
|
||||
authModelId: schema.string().optional(),
|
||||
@@ -28,7 +28,7 @@ export const CONNECTION_CONFIG_SCHEMA = schema.object({
|
||||
name: schema.string().optional(),
|
||||
networkHandlersConfig: schema.array(CONNECTION_NETWORK_HANDLER_SCHEMA).optional(),
|
||||
port: schema.string().optional(),
|
||||
properties: CONNECTION_PROPERTIES_SCHEMA,
|
||||
properties: CONNECTION_PROPERTIES_SCHEMA.optional(),
|
||||
providerProperties: schema.record(schema.any()).optional(),
|
||||
readOnly: schema.boolean().optional(),
|
||||
saveCredentials: schema.boolean().optional(),
|
||||
|
||||
@@ -140,7 +140,7 @@ export const Options: TabContainerPanelComponent<IConnectionFormProps> = observe
|
||||
DatabaseAuthModelsResource,
|
||||
getComputed(() => config.authModelId || info?.authModel || driver?.defaultAuthModel || null),
|
||||
{
|
||||
onData: data => optionsHook.setAuthModel(data),
|
||||
onData: optionsHook.setAuthModel,
|
||||
},
|
||||
);
|
||||
|
||||
@@ -157,7 +157,7 @@ export const Options: TabContainerPanelComponent<IConnectionFormProps> = observe
|
||||
return;
|
||||
}
|
||||
|
||||
optionsHook.setAuthModel(model);
|
||||
await optionsHook.setAuthModel(model);
|
||||
}
|
||||
|
||||
const authentication = useAuthenticationAction({
|
||||
@@ -176,10 +176,7 @@ export const Options: TabContainerPanelComponent<IConnectionFormProps> = observe
|
||||
});
|
||||
|
||||
function setProject(projectId: string) {
|
||||
formState.setState({
|
||||
...formState.state,
|
||||
projectId,
|
||||
});
|
||||
formState.state.projectId = projectId;
|
||||
}
|
||||
|
||||
let properties = authModel?.properties;
|
||||
|
||||
@@ -104,7 +104,7 @@ export function useOptions(formState: IFormState<IConnectionFormState>, config:
|
||||
}
|
||||
});
|
||||
},
|
||||
setAuthModel(model: DatabaseAuthModel) {
|
||||
async setAuthModel(model: DatabaseAuthModel) {
|
||||
const { config, info, formState } = refObject;
|
||||
|
||||
config.credentials = {};
|
||||
@@ -119,7 +119,7 @@ export function useOptions(formState: IFormState<IConnectionFormState>, config:
|
||||
}
|
||||
}
|
||||
|
||||
formState.reload();
|
||||
await formState.reload();
|
||||
},
|
||||
|
||||
isNameAutoFill() {
|
||||
|
||||
+4
-6
@@ -41,7 +41,7 @@ export class ConnectionFormOriginInfoFormPart extends FormPart<IConnectionFormOr
|
||||
}
|
||||
|
||||
get providerId(): string | null {
|
||||
if (!this.formState.state.config.connectionId || !this.formState.state.projectId || !this.formState.state.config.driverId) {
|
||||
if (!this.formState.state.projectId || !this.formState.state.config.driverId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ export class ConnectionFormOriginInfoFormPart extends FormPart<IConnectionFormOr
|
||||
return null;
|
||||
}
|
||||
|
||||
const info = this.connectionInfoResource.get(createConnectionParam(this.formState.state.projectId, this.formState.state.config.connectionId));
|
||||
const info = this.connectionInfoResource.get(createConnectionParam(this.formState.state.projectId, this.formState.state.config.connectionId!));
|
||||
const authModel = this.databaseAuthModelsResource.get(
|
||||
this.formState.state.config.authModelId ?? info?.authModel ?? driver?.defaultAuthModel ?? null,
|
||||
);
|
||||
@@ -61,7 +61,7 @@ export class ConnectionFormOriginInfoFormPart extends FormPart<IConnectionFormOr
|
||||
}
|
||||
|
||||
get isAuthenticated(): boolean {
|
||||
if (!this.formState.state.config.connectionId || !this.formState.state.projectId || !this.formState.state.config.driverId || !this.providerId) {
|
||||
if (!this.providerId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -100,7 +100,5 @@ export class ConnectionFormOriginInfoFormPart extends FormPart<IConnectionFormOr
|
||||
this.setInitialState(state);
|
||||
}
|
||||
|
||||
protected override async saveChanges(data: IFormState<IConnectionFormState>): Promise<void> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
protected override async saveChanges(data: IFormState<IConnectionFormState>): Promise<void> {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user