Skip to content

Commit

Permalink
CB-4018 refactor: respect presentation in data viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
Wroud committed Jun 18, 2024
1 parent 0a23993 commit ebd4c02
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 58 deletions.
46 changes: 23 additions & 23 deletions webapp/packages/plugin-data-export/src/DataExportMenuService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import { LocalizationService } from '@cloudbeaver/core-localization';
import { DATA_CONTEXT_NAV_NODE, EObjectFeature } from '@cloudbeaver/core-navigation-tree';
import { EAdminPermission, SessionPermissionsResource } from '@cloudbeaver/core-root';
import { withTimestamp } from '@cloudbeaver/core-utils';
import { ACTION_EXPORT, ActionService, DATA_CONTEXT_MENU, menuExtractItems, MenuService } from '@cloudbeaver/core-view';
import { ACTION_EXPORT, ActionService, menuExtractItems, MenuService } from '@cloudbeaver/core-view';
import {
DATA_CONTEXT_DV_DDM,
DATA_CONTEXT_DV_DDM_RESULT_INDEX,
DATA_CONTEXT_DV_PRESENTATION,
DATA_VIEWER_DATA_MODEL_ACTIONS_MENU,
DataViewerPresentationType,
IDatabaseDataSource,
IDataContainerOptions,
} from '@cloudbeaver/plugin-data-viewer';
Expand All @@ -39,18 +41,26 @@ export class DataExportMenuService {
) {}

register(): void {
this.menuService.addCreator({
menus: [DATA_VIEWER_DATA_MODEL_ACTIONS_MENU],
contexts: [DATA_CONTEXT_DV_DDM, DATA_CONTEXT_DV_DDM_RESULT_INDEX],
isApplicable: context => {
const presentation = context.get(DATA_CONTEXT_DV_PRESENTATION);
return !this.isExportDisabled() && (!presentation || presentation.type === DataViewerPresentationType.Data);
},
getItems(context, items) {
return [...items, ACTION_EXPORT];
},
orderItems(context, items) {
const extracted = menuExtractItems(items, [ACTION_EXPORT]);
return [...items, ...extracted];
},
});
this.actionService.addHandler({
id: 'data-export-base-handler',
menus: [DATA_VIEWER_DATA_MODEL_ACTIONS_MENU],
contexts: [DATA_CONTEXT_DV_DDM, DATA_CONTEXT_DV_DDM_RESULT_INDEX],
isActionApplicable(context, action) {
const menu = context.hasValue(DATA_CONTEXT_MENU, DATA_VIEWER_DATA_MODEL_ACTIONS_MENU);

if (!menu) {
return false;
}

return [ACTION_EXPORT].includes(action);
},
actions: [ACTION_EXPORT],
isDisabled(context) {
const model = context.get(DATA_CONTEXT_DV_DDM)!;
const resultIndex = context.get(DATA_CONTEXT_DV_DDM_RESULT_INDEX)!;
Expand Down Expand Up @@ -97,24 +107,14 @@ export class DataExportMenuService {
}
},
});
this.menuService.addCreator({
menus: [DATA_VIEWER_DATA_MODEL_ACTIONS_MENU],
isApplicable: () => !this.isExportDisabled(),
getItems(context, items) {
return [...items, ACTION_EXPORT];
},
orderItems(context, items) {
const extracted = menuExtractItems(items, [ACTION_EXPORT]);
return [...items, ...extracted];
},
});

this.menuService.addCreator({
root: true,
contexts: [DATA_CONTEXT_NAV_NODE],
isApplicable: context => {
const node = context.get(DATA_CONTEXT_NAV_NODE);
const node = context.get(DATA_CONTEXT_NAV_NODE)!;

if (node && !node.objectFeatures.includes(EObjectFeature.dataContainer)) {
if (!node.objectFeatures.includes(EObjectFeature.dataContainer)) {
return false;
}

Expand Down
36 changes: 18 additions & 18 deletions webapp/packages/plugin-data-import/src/DataImportBootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
*/
import { Bootstrap, injectable } from '@cloudbeaver/core-di';
import { CommonDialogService, DialogueStateResult } from '@cloudbeaver/core-dialogs';
import { ACTION_IMPORT, ActionService, DATA_CONTEXT_MENU, menuExtractItems, MenuService } from '@cloudbeaver/core-view';
import { ACTION_IMPORT, ActionService, menuExtractItems, MenuService } from '@cloudbeaver/core-view';
import {
ContainerDataSource,
DATA_CONTEXT_DV_DDM,
DATA_CONTEXT_DV_DDM_RESULT_INDEX,
DATA_CONTEXT_DV_PRESENTATION,
DATA_VIEWER_DATA_MODEL_ACTIONS_MENU,
DataViewerPresentationType,
} from '@cloudbeaver/plugin-data-viewer';

import { DataImportDialogLazy } from './DataImportDialog/DataImportDialogLazy';
Expand All @@ -33,22 +35,7 @@ export class DataImportBootstrap extends Bootstrap {
this.actionService.addHandler({
id: 'data-import-base-handler',
contexts: [DATA_CONTEXT_DV_DDM, DATA_CONTEXT_DV_DDM_RESULT_INDEX],
isActionApplicable(context, action) {
const menu = context.hasValue(DATA_CONTEXT_MENU, DATA_VIEWER_DATA_MODEL_ACTIONS_MENU);
const model = context.get(DATA_CONTEXT_DV_DDM);
const resultIndex = context.get(DATA_CONTEXT_DV_DDM_RESULT_INDEX);

if (!menu || !model || resultIndex === undefined) {
return false;
}

if (action === ACTION_IMPORT) {
const isContainer = model.source instanceof ContainerDataSource;
return !model.isReadonly(resultIndex) && isContainer;
}

return [ACTION_IMPORT].includes(action);
},
actions: [ACTION_IMPORT],
isDisabled(context) {
const model = context.get(DATA_CONTEXT_DV_DDM)!;
const resultIndex = context.get(DATA_CONTEXT_DV_DDM_RESULT_INDEX)!;
Expand Down Expand Up @@ -103,7 +90,20 @@ export class DataImportBootstrap extends Bootstrap {

this.menuService.addCreator({
menus: [DATA_VIEWER_DATA_MODEL_ACTIONS_MENU],
isApplicable: () => !this.dataImportService.disabled,
contexts: [DATA_CONTEXT_DV_DDM, DATA_CONTEXT_DV_DDM_RESULT_INDEX],
isApplicable: context => {
const model = context.get(DATA_CONTEXT_DV_DDM)!;
const resultIndex = context.get(DATA_CONTEXT_DV_DDM_RESULT_INDEX)!;
const presentation = context.get(DATA_CONTEXT_DV_PRESENTATION);
const isContainer = model.source instanceof ContainerDataSource;
return (
!model.isReadonly(resultIndex) &&
isContainer &&
!this.dataImportService.disabled &&
!presentation?.readonly &&
(!presentation || presentation.type === DataViewerPresentationType.Data)
);
},
getItems(_, items) {
return [...items, ACTION_IMPORT];
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import { ActionService, MenuService } from '@cloudbeaver/core-view';
import {
DATA_CONTEXT_DV_DDM,
DATA_CONTEXT_DV_DDM_RESULT_INDEX,
DATA_CONTEXT_DV_PRESENTATION,
DATA_VIEWER_DATA_MODEL_ACTIONS_MENU,
DataPresentationService,
DataPresentationType,
DataViewerPresentationType,
ResultSetDataAction,
ResultSetSelectAction,
} from '@cloudbeaver/plugin-data-viewer';
Expand Down Expand Up @@ -61,6 +63,10 @@ export class DVResultSetGroupingPluginBootstrap extends Bootstrap {
contexts: [DATA_CONTEXT_DV_DDM_RS_GROUPING],
menus: [DATA_VIEWER_DATA_MODEL_ACTIONS_MENU],
isActionApplicable(context, action) {
const presentation = context.get(DATA_CONTEXT_DV_PRESENTATION);
if (presentation && presentation.type !== DataViewerPresentationType.Data) {
return false;
}
switch (action) {
case ACTION_DATA_VIEWER_GROUPING_REMOVE_COLUMN:
return context.has(DATA_CONTEXT_DV_DDM) && context.has(DATA_CONTEXT_DV_DDM_RESULT_INDEX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
*/
import { createDataContext } from '@cloudbeaver/core-data-context';

export enum DataViewerPresentationType {
Data,
Analytical,
}

export interface IDataViewerPresentation {
type?: DataViewerPresentationType;
readonly?: boolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
ACTION_REVERT,
ACTION_SAVE,
ActionService,
menuExtractItems,
MenuService,
} from '@cloudbeaver/core-view';

Expand All @@ -23,7 +22,7 @@ import { DatabaseSelectAction } from '../../../DatabaseDataModel/Actions/Databas
import { DatabaseEditChangeType } from '../../../DatabaseDataModel/Actions/IDatabaseDataEditAction';
import { DATA_CONTEXT_DV_DDM } from '../../../DatabaseDataModel/DataContext/DATA_CONTEXT_DV_DDM';
import { DATA_CONTEXT_DV_DDM_RESULT_INDEX } from '../../../DatabaseDataModel/DataContext/DATA_CONTEXT_DV_DDM_RESULT_INDEX';
import { DATA_CONTEXT_DV_PRESENTATION } from '../../../DatabaseDataModel/DataContext/DATA_CONTEXT_DV_PRESENTATION';
import { DATA_CONTEXT_DV_PRESENTATION, DataViewerPresentationType } from '../../../DatabaseDataModel/DataContext/DATA_CONTEXT_DV_PRESENTATION';
import type { IDatabaseDataModel } from '../../../DatabaseDataModel/IDatabaseDataModel';
import { DATA_VIEWER_DATA_MODEL_ACTIONS_MENU } from './DATA_VIEWER_DATA_MODEL_ACTIONS_MENU';

Expand All @@ -41,16 +40,13 @@ export class TableFooterMenuService {
isApplicable(context) {
const model = context.get(DATA_CONTEXT_DV_DDM)!;
const resultIndex = context.get(DATA_CONTEXT_DV_DDM_RESULT_INDEX)!;
const presentation = context.get(DATA_CONTEXT_DV_PRESENTATION);

return !model.isReadonly(resultIndex) && !context.get(DATA_CONTEXT_DV_PRESENTATION)?.readonly;
return !model.isReadonly(resultIndex) && !presentation?.readonly && (!presentation || presentation.type === DataViewerPresentationType.Data);
},
getItems(context, items) {
return [ACTION_ADD, ACTION_DUPLICATE, ACTION_DELETE, ACTION_REVERT, ACTION_SAVE, ACTION_CANCEL, ...items];
},
orderItems(context, items) {
const extracted = menuExtractItems(items, [ACTION_ADD, ACTION_DUPLICATE, ACTION_DELETE, ACTION_REVERT, ACTION_SAVE, ACTION_CANCEL]);
return [...extracted, ...items];
},
});
this.actionService.addHandler({
id: 'data-base-handler',
Expand Down
25 changes: 15 additions & 10 deletions webapp/packages/plugin-sql-generator/src/GeneratorMenuBootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
*/
import { Bootstrap, injectable } from '@cloudbeaver/core-di';
import { ResultDataFormat } from '@cloudbeaver/core-sdk';
import { ActionService, menuExtractItems, MenuService } from '@cloudbeaver/core-view';
import { ActionService, MenuService } from '@cloudbeaver/core-view';
import {
DATA_CONTEXT_DV_DDM,
DATA_CONTEXT_DV_DDM_RESULT_INDEX,
DATA_CONTEXT_DV_PRESENTATION,
DATA_VIEWER_DATA_MODEL_ACTIONS_MENU,
DatabaseEditAction,
DataViewerPresentationType,
} from '@cloudbeaver/plugin-data-viewer';

import { ACTION_SQL_GENERATE } from './actions/ACTION_SQL_GENERATE';
Expand All @@ -31,25 +33,28 @@ export class GeneratorMenuBootstrap extends Bootstrap {
register(): void {
this.menuService.addCreator({
menus: [DATA_VIEWER_DATA_MODEL_ACTIONS_MENU],
contexts: [DATA_CONTEXT_DV_DDM, DATA_CONTEXT_DV_DDM_RESULT_INDEX],
isApplicable: context => {
const model = context.get(DATA_CONTEXT_DV_DDM)!;
const resultIndex = context.get(DATA_CONTEXT_DV_DDM_RESULT_INDEX)!;
const presentation = context.get(DATA_CONTEXT_DV_PRESENTATION);
return (
!model.isReadonly(resultIndex) &&
model.source.getResult(resultIndex)?.dataFormat === ResultDataFormat.Resultset &&
!presentation?.readonly &&
(!presentation || presentation.type === DataViewerPresentationType.Data)
);
},
getItems(context, items) {
return [...items, ACTION_SQL_GENERATE];
},
orderItems(context, items) {
const extracted = menuExtractItems(items, [ACTION_SQL_GENERATE]);
return [...items, ...extracted];
},
});

this.actionService.addHandler({
id: 'data-sql-tools-handler',
menus: [DATA_VIEWER_DATA_MODEL_ACTIONS_MENU],
actions: [ACTION_SQL_GENERATE],
contexts: [DATA_CONTEXT_DV_DDM, DATA_CONTEXT_DV_DDM_RESULT_INDEX],
isActionApplicable(context) {
const model = context.get(DATA_CONTEXT_DV_DDM)!;
const resultIndex = context.get(DATA_CONTEXT_DV_DDM_RESULT_INDEX)!;
return !model.isReadonly(resultIndex) && model.source.getResult(resultIndex)?.dataFormat === ResultDataFormat.Resultset;
},
isDisabled(context) {
const model = context.get(DATA_CONTEXT_DV_DDM)!;
const resultIndex = context.get(DATA_CONTEXT_DV_DDM_RESULT_INDEX)!;
Expand Down

0 comments on commit ebd4c02

Please sign in to comment.