Skip to content
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

CB-5391 remove controller from the plugin-connections-administration #2876

Merged
merged 7 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 21 additions & 27 deletions webapp/packages/core-blocks/src/Table/TableState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,28 @@ import { action, computed, makeObservable, observable } from 'mobx';

import { Executor, IExecutor } from '@cloudbeaver/core-executor';

type Key = string | string[];

interface IData {
key: string;
interface IData<Key> {
key: Key;
value: boolean;
}

export class TableState {
readonly onExpand: IExecutor<IData>;
export class TableState<K = string> {
readonly onExpand: IExecutor<IData<K>>;

selected: Map<string, boolean>;
expanded: Map<string, boolean>;
selected: Map<K, boolean>;
expanded: Map<K, boolean>;

get itemsSelected(): boolean {
return Array.from(this.selected.values()).some(v => v);
}

get selectedList(): string[] {
get selectedList(): K[] {
return Array.from(this.selected)
.filter(([_, value]) => value)
.map(([key]) => key);
}

get expandedList(): string[] {
get expandedList(): K[] {
return Array.from(this.expanded)
.filter(([_, value]) => value)
.map(([key]) => key);
Expand All @@ -41,8 +39,8 @@ export class TableState {
constructor() {
this.onExpand = new Executor();

this.selected = new Map();
this.expanded = new Map();
this.selected = new Map<K, boolean>();
this.expanded = new Map<K, boolean>();

makeObservable(this, {
selected: observable,
Expand All @@ -55,37 +53,33 @@ export class TableState {
});
}

unselect(key?: Key): Map<string, boolean> {
unselect(key?: K | K[]): Map<K, boolean> {
if (key === undefined) {
this.selected.clear();
} else {
if (typeof key === 'string') {
this.selected.delete(key);
} else {
for (const id of key) {
this.selected.delete(id);
}
const keys = Array.isArray(key) ? key : [key];

for (const id of keys) {
this.selected.delete(id);
}
}

return this.selected;
}

expand(key: string, value: boolean) {
expand(key: K, value: boolean) {
this.expanded.set(key, value);
this.onExpand.execute({ key, value });
}

collapse(key?: Key): Map<string, boolean> {
collapse(key?: K | K[]): Map<K, boolean> {
if (key === undefined) {
this.expanded.clear();
} else {
if (typeof key === 'string') {
this.expanded.delete(key);
} else {
for (const id of key) {
this.expanded.delete(id);
}
const keys = Array.isArray(key) ? key : [key];

for (const id of keys) {
this.expanded.delete(id);
}
}

Expand Down
4 changes: 2 additions & 2 deletions webapp/packages/core-blocks/src/Table/useTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useState } from 'react';

import { TableState } from './TableState';

export function useTable(): TableState {
const [table] = useState(() => new TableState());
export function useTable<K = string>(): TableState<K> {
const [table] = useState(() => new TableState<K>());
return table;
}
6 changes: 1 addition & 5 deletions webapp/packages/core-di/src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Executor, IExecutor } from '@cloudbeaver/core-executor';
import { Bootstrap } from './Bootstrap';
import { Dependency } from './Dependency';
import type { DIContainer } from './DIContainer';
import type { IServiceCollection, IServiceConstructor, IServiceInjector } from './IApp';
import type { IServiceCollection, IServiceConstructor } from './IApp';
import { IDiWrapper, inversifyWrapper } from './inversifyWrapper';
import { IServiceProvider } from './IServiceProvider';
import type { PluginManifest } from './PluginManifest';
Expand Down Expand Up @@ -92,10 +92,6 @@ export class App {
return this.diWrapper.collection;
}

getServiceInjector(): IServiceInjector {
return this.diWrapper.injector;
}

// first phase register all dependencies
private async registerServices(preload?: boolean): Promise<void> {
if (!this.isAppServiceBound) {
Expand Down
1 change: 0 additions & 1 deletion webapp/packages/core-di/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export * from './DIService';
export * from './injectable';
export * from './PluginManifest';
export * from './useService';
export * from './useController';
export * from './ITypedConstructor';
export * from './isConstructor';
export * from './IServiceProvider';
Expand Down
62 changes: 0 additions & 62 deletions webapp/packages/core-di/src/useController.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@ import {
StyleRegistry,
ToolsAction,
ToolsPanel,
useResource,
useS,
useTranslate,
} from '@cloudbeaver/core-blocks';
import { ConnectionInfoActiveProjectKey, ConnectionInfoResource, DBDriverResource } from '@cloudbeaver/core-connections';
import { useController, useService } from '@cloudbeaver/core-di';
import { CachedMapAllKey } from '@cloudbeaver/core-resource';
import { useService } from '@cloudbeaver/core-di';

import ConnectionsAdministrationStyle from './ConnectionsAdministration.module.css';
import { ConnectionsAdministrationController } from './ConnectionsAdministrationController';
import { ConnectionsTable } from './ConnectionsTable/ConnectionsTable';
import { useConnectionsTable } from './ConnectionsTable/useConnectionsTable';
import { CreateConnection } from './CreateConnection/CreateConnection';
import { CreateConnectionService } from './CreateConnectionService';

Expand All @@ -51,16 +48,11 @@ export const ConnectionsAdministration = observer<AdministrationItemContentProps
param,
configurationWizard,
}) {
const service = useService(CreateConnectionService);
const controller = useController(ConnectionsAdministrationController);
const translate = useTranslate();
const style = useS(ConnectionsAdministrationStyle);
const translate = useTranslate();
const service = useService(CreateConnectionService);

useResource(ConnectionsAdministration, ConnectionInfoResource, {
key: ConnectionInfoActiveProjectKey,
includes: ['customIncludeOptions'],
});
useResource(ConnectionsAdministration, DBDriverResource, CachedMapAllKey);
const state = useConnectionsTable();

return (
<ColoredContainer vertical wrap parent gap>
Expand All @@ -73,7 +65,7 @@ export const ConnectionsAdministration = observer<AdministrationItemContentProps
title={translate('connections_administration_tools_add_tooltip')}
icon="add"
viewBox="0 0 24 24"
disabled={!!sub || controller.isProcessing}
disabled={!!sub || state.loading}
onClick={service.create}
>
{translate('ui_add')}
Expand All @@ -82,17 +74,17 @@ export const ConnectionsAdministration = observer<AdministrationItemContentProps
title={translate('connections_administration_tools_refresh_tooltip')}
icon="refresh"
viewBox="0 0 24 24"
disabled={controller.isProcessing}
onClick={controller.update}
disabled={state.loading}
onClick={state.update}
>
{translate('ui_refresh')}
</ToolsAction>
<ToolsAction
title={translate('connections_administration_tools_delete_tooltip')}
icon="trash"
viewBox="0 0 24 24"
disabled={!controller.itemsSelected || controller.isProcessing}
onClick={controller.delete}
disabled={!state.table.itemsSelected || state.loading}
onClick={state.delete}
>
{translate('ui_delete')}
</ToolsAction>
Expand All @@ -108,13 +100,8 @@ export const ConnectionsAdministration = observer<AdministrationItemContentProps
{sub && <CreateConnection method={param} configurationWizard={configurationWizard} />}
<Group boxNoOverflow>
<SContext registry={registry}>
<Loader loading={controller.isProcessing} overlay>
<ConnectionsTable
keys={controller.keys}
connections={controller.connections}
selectedItems={controller.selectedItems}
expandedItems={controller.expandedItems}
/>
<Loader loading={state.loading} overlay>
<ConnectionsTable state={state} />
</Loader>
</SContext>
</Group>
Expand Down
Loading
Loading