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 5368 create api for kill session sm #3028

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { injectable } from '@cloudbeaver/core-di';
import {
DatabaseEditChangeType,
DataViewerContextMenuService,
isBooleanValuePresentationAvailable,
isResultSetDataSource,
ResultSetDataContentAction,
Expand All @@ -18,39 +19,37 @@ import {
ResultSetViewAction,
} from '@cloudbeaver/plugin-data-viewer';

import { DataGridContextMenuService } from './DataGridContextMenuService.js';

@injectable()
export class DataGridContextMenuCellEditingService {
private static readonly menuEditingToken = 'menuEditing';

constructor(private readonly dataGridContextMenuService: DataGridContextMenuService) {}
constructor(private readonly dataViewerContextMenuService: DataViewerContextMenuService) {}

getMenuEditingToken(): string {
return DataGridContextMenuCellEditingService.menuEditingToken;
}

register(): void {
this.dataGridContextMenuService.add(this.dataGridContextMenuService.getMenuToken(), {
this.dataViewerContextMenuService.add(this.dataViewerContextMenuService.getMenuToken(), {
id: this.getMenuEditingToken(),
order: 4,
title: 'data_grid_table_editing',
icon: 'edit',
isPanel: true,
isPresent(context) {
return context.contextType === DataGridContextMenuService.cellContext;
return context.contextType === DataViewerContextMenuService.cellContext;
},
isHidden(context) {
return context.data.model.isDisabled(context.data.resultIndex) || context.data.model.isReadonly(context.data.resultIndex);
},
});
this.dataGridContextMenuService.add(this.getMenuEditingToken(), {
this.dataViewerContextMenuService.add(this.getMenuEditingToken(), {
id: 'open_inline_editor',
order: 0,
title: 'data_grid_table_editing_open_inline_editor',
icon: 'edit',
isPresent(context) {
return context.contextType === DataGridContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
return context.contextType === DataViewerContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
},
isHidden(context) {
const source = context.data.model.source as unknown as ResultSetDataSource;
Expand All @@ -72,12 +71,12 @@ export class DataGridContextMenuCellEditingService {
context.data.spreadsheetActions.edit(context.data.key);
},
});
this.dataGridContextMenuService.add(this.getMenuEditingToken(), {
this.dataViewerContextMenuService.add(this.getMenuEditingToken(), {
id: 'set_to_null',
order: 1,
title: 'data_grid_table_editing_set_to_null',
isPresent(context) {
return context.contextType === DataGridContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
return context.contextType === DataViewerContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
},
isHidden(context) {
const { key, model, resultIndex } = context.data;
Expand All @@ -93,13 +92,13 @@ export class DataGridContextMenuCellEditingService {
source.getAction(context.data.resultIndex, ResultSetEditAction).set(context.data.key, null);
},
});
this.dataGridContextMenuService.add(this.getMenuEditingToken(), {
this.dataViewerContextMenuService.add(this.getMenuEditingToken(), {
id: 'row_add',
order: 5,
icon: '/icons/data_add_sm.svg',
title: 'data_grid_table_editing_row_add',
isPresent(context) {
return context.contextType === DataGridContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
return context.contextType === DataViewerContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
},
isHidden(context) {
const source = context.data.model.source as unknown as ResultSetDataSource;
Expand All @@ -112,13 +111,13 @@ export class DataGridContextMenuCellEditingService {
editor.addRow(context.data.key.row);
},
});
this.dataGridContextMenuService.add(this.getMenuEditingToken(), {
this.dataViewerContextMenuService.add(this.getMenuEditingToken(), {
id: 'row_add_copy',
order: 5.5,
icon: '/icons/data_add_copy_sm.svg',
title: 'data_grid_table_editing_row_add_copy',
isPresent(context) {
return context.contextType === DataGridContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
return context.contextType === DataViewerContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
},
isHidden(context) {
const source = context.data.model.source as unknown as ResultSetDataSource;
Expand All @@ -131,13 +130,13 @@ export class DataGridContextMenuCellEditingService {
editor.duplicateRow(context.data.key.row);
},
});
this.dataGridContextMenuService.add(this.getMenuEditingToken(), {
this.dataViewerContextMenuService.add(this.getMenuEditingToken(), {
id: 'row_delete',
order: 6,
icon: '/icons/data_delete_sm.svg',
title: 'data_grid_table_editing_row_delete',
isPresent(context) {
return context.contextType === DataGridContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
return context.contextType === DataViewerContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
},
isHidden(context) {
const source = context.data.model.source as unknown as ResultSetDataSource;
Expand All @@ -156,13 +155,13 @@ export class DataGridContextMenuCellEditingService {
editor.deleteRow(context.data.key.row);
},
});
this.dataGridContextMenuService.add(this.getMenuEditingToken(), {
this.dataViewerContextMenuService.add(this.getMenuEditingToken(), {
id: 'row_delete_selected',
order: 6.1,
icon: '/icons/data_delete_sm.svg',
title: 'data_viewer_action_edit_delete',
isPresent(context) {
return context.contextType === DataGridContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
return context.contextType === DataViewerContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
},
isHidden(context) {
const source = context.data.model.source as unknown as ResultSetDataSource;
Expand All @@ -188,13 +187,13 @@ export class DataGridContextMenuCellEditingService {
editor.delete(...selectedElements);
},
});
this.dataGridContextMenuService.add(this.getMenuEditingToken(), {
this.dataViewerContextMenuService.add(this.getMenuEditingToken(), {
id: 'row_revert',
order: 7,
icon: '/icons/data_revert_sm.svg',
title: 'data_grid_table_editing_row_revert',
isPresent(context) {
return context.contextType === DataGridContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
return context.contextType === DataViewerContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
},
isHidden(context) {
const source = context.data.model.source as unknown as ResultSetDataSource;
Expand All @@ -207,13 +206,13 @@ export class DataGridContextMenuCellEditingService {
editor.revert(context.data.key);
},
});
this.dataGridContextMenuService.add(this.getMenuEditingToken(), {
this.dataViewerContextMenuService.add(this.getMenuEditingToken(), {
id: 'row_revert_selected',
order: 7.1,
icon: '/icons/data_revert_sm.svg',
title: 'data_viewer_action_edit_revert',
isPresent(context) {
return context.contextType === DataGridContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
return context.contextType === DataViewerContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
},
isHidden(context) {
const source = context.data.model.source as unknown as ResultSetDataSource;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import { ClipboardService } from '@cloudbeaver/core-ui';
import { replaceMiddle } from '@cloudbeaver/core-utils';
import {
DatabaseDataConstraintAction,
DataViewerContextMenuService,
type IDatabaseDataModel,
type IDataViewerContextMenu,
type IResultSetColumnKey,
IS_NOT_NULL_ID,
IS_NULL_ID,
Expand All @@ -31,20 +33,18 @@ import {
wrapOperationArgument,
} from '@cloudbeaver/plugin-data-viewer';

import { DataGridContextMenuService, type IDataGridCellMenuContext } from '../DataGridContextMenuService.js';

const FilterCustomValueDialog = importLazyComponent(() => import('./FilterCustomValueDialog.js').then(m => m.FilterCustomValueDialog));

@injectable()
export class DataGridContextMenuFilterService {
private static readonly menuFilterToken = 'menuFilter';

constructor(
private readonly dataGridContextMenuService: DataGridContextMenuService,
private readonly dataViewerContextMenuService: DataViewerContextMenuService,
private readonly commonDialogService: CommonDialogService,
private readonly clipboardService: ClipboardService,
) {
this.dataGridContextMenuService.onRootMenuOpen.addHandler(this.getClipboardValue.bind(this));
this.dataViewerContextMenuService.onRootMenuOpen.addHandler(this.getClipboardValue.bind(this));
}

getMenuFilterToken(): string {
Expand Down Expand Up @@ -82,11 +82,11 @@ export class DataGridContextMenuFilterService {
}

private getGeneralizedMenuItems(
context: IMenuContext<IDataGridCellMenuContext>,
context: IMenuContext<IDataViewerContextMenu>,
value: any | (() => any),
icon: string,
isHidden?: (context: IMenuContext<IDataGridCellMenuContext>) => boolean,
): Array<IContextMenuItem<IDataGridCellMenuContext>> {
isHidden?: (context: IMenuContext<IDataViewerContextMenu>) => boolean,
): Array<IContextMenuItem<IDataViewerContextMenu>> {
const { model, resultIndex, key } = context.data;
const source = model.source as unknown as ResultSetDataSource;
const data = source.getAction(resultIndex, ResultSetDataAction);
Expand Down Expand Up @@ -120,14 +120,14 @@ export class DataGridContextMenuFilterService {
}

register(): void {
this.dataGridContextMenuService.add(this.dataGridContextMenuService.getMenuToken(), {
this.dataViewerContextMenuService.add(this.dataViewerContextMenuService.getMenuToken(), {
id: this.getMenuFilterToken(),
order: 2,
title: 'data_grid_table_filter',
icon: 'filter',
isPanel: true,
isPresent(context) {
return context.contextType === DataGridContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
return context.contextType === DataViewerContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
},
isHidden(context) {
if (context.data.model.isDisabled(context.data.resultIndex)) {
Expand All @@ -139,13 +139,13 @@ export class DataGridContextMenuFilterService {
return !constraints.supported;
},
});
this.dataGridContextMenuService.add(this.dataGridContextMenuService.getMenuToken(), {
this.dataViewerContextMenuService.add(this.dataViewerContextMenuService.getMenuToken(), {
id: 'deleteFiltersAndOrders',
order: 3,
title: 'data_grid_table_delete_filters_and_orders',
icon: 'erase',
isPresent(context) {
return context.contextType === DataGridContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
return context.contextType === DataViewerContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
},
isHidden(context) {
if (context.data.model.isDisabled(context.data.resultIndex)) {
Expand All @@ -166,13 +166,13 @@ export class DataGridContextMenuFilterService {
});
},
});
this.dataGridContextMenuService.add(this.getMenuFilterToken(), {
this.dataViewerContextMenuService.add(this.getMenuFilterToken(), {
id: 'clipboardValue',
order: 0,
title: 'ui_clipboard',
icon: 'filter-clipboard',
isPresent(context) {
return context.contextType === DataGridContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
return context.contextType === DataViewerContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
},
isHidden: context => {
if (!this.clipboardService.clipboardAvailable || this.clipboardService.state === 'denied') {
Expand All @@ -185,10 +185,10 @@ export class DataGridContextMenuFilterService {

return supportedOperations.length === 0;
},
panel: new ComputedContextMenuModel<IDataGridCellMenuContext>({
panel: new ComputedContextMenuModel<IDataViewerContextMenu>({
id: 'clipboardValuePanel',
menuItemsGetter: context => {
if (context.contextType !== DataGridContextMenuService.cellContext) {
if (context.contextType !== DataViewerContextMenuService.cellContext) {
return [];
}

Expand All @@ -214,13 +214,13 @@ export class DataGridContextMenuFilterService {
},
}),
});
this.dataGridContextMenuService.add(this.getMenuFilterToken(), {
this.dataViewerContextMenuService.add(this.getMenuFilterToken(), {
id: 'cellValue',
order: 1,
title: 'data_grid_table_filter_cell_value',
icon: 'filter',
isPresent(context) {
return context.contextType === DataGridContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
return context.contextType === DataViewerContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
},
isHidden: context => {
const { model, resultIndex, key } = context.data;
Expand All @@ -232,7 +232,7 @@ export class DataGridContextMenuFilterService {

return value === undefined || supportedOperations.length === 0 || format.isNull(key);
},
panel: new ComputedContextMenuModel<IDataGridCellMenuContext>({
panel: new ComputedContextMenuModel<IDataViewerContextMenu>({
id: 'cellValuePanel',
menuItemsGetter: context => {
const { model, resultIndex, key } = context.data;
Expand All @@ -244,13 +244,13 @@ export class DataGridContextMenuFilterService {
},
}),
});
this.dataGridContextMenuService.add(this.getMenuFilterToken(), {
this.dataViewerContextMenuService.add(this.getMenuFilterToken(), {
id: 'customValue',
order: 2,
title: 'data_grid_table_filter_custom_value',
icon: 'filter-custom',
isPresent(context) {
return context.contextType === DataGridContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
return context.contextType === DataViewerContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
},
isHidden: context => {
const { model, resultIndex, key } = context.data;
Expand All @@ -261,7 +261,7 @@ export class DataGridContextMenuFilterService {

return cellValue === undefined || supportedOperations.length === 0;
},
panel: new ComputedContextMenuModel<IDataGridCellMenuContext>({
panel: new ComputedContextMenuModel<IDataViewerContextMenu>({
id: 'customValuePanel',
menuItemsGetter: context => {
const { model, resultIndex, key } = context.data;
Expand Down Expand Up @@ -309,12 +309,12 @@ export class DataGridContextMenuFilterService {
},
}),
});
this.dataGridContextMenuService.add(this.getMenuFilterToken(), {
this.dataViewerContextMenuService.add(this.getMenuFilterToken(), {
id: 'isNullValue',
order: 3,
icon: 'filter',
isPresent(context) {
return context.contextType === DataGridContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
return context.contextType === DataViewerContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
},
isHidden: context => {
const source = context.data.model.source as unknown as ResultSetDataSource;
Expand All @@ -338,12 +338,12 @@ export class DataGridContextMenuFilterService {
);
},
});
this.dataGridContextMenuService.add(this.getMenuFilterToken(), {
this.dataViewerContextMenuService.add(this.getMenuFilterToken(), {
id: 'isNotNullValue',
order: 4,
icon: 'filter',
isPresent(context) {
return context.contextType === DataGridContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
return context.contextType === DataViewerContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
},
isHidden: context => {
const source = context.data.model.source as unknown as ResultSetDataSource;
Expand All @@ -367,12 +367,12 @@ export class DataGridContextMenuFilterService {
);
},
});
this.dataGridContextMenuService.add(this.getMenuFilterToken(), {
this.dataViewerContextMenuService.add(this.getMenuFilterToken(), {
id: 'deleteFilter',
order: 5,
icon: 'filter-reset',
isPresent(context) {
return context.contextType === DataGridContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
return context.contextType === DataViewerContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
},
isHidden: context => {
const { model, resultIndex, key } = context.data;
Expand Down Expand Up @@ -406,13 +406,13 @@ export class DataGridContextMenuFilterService {
});
},
});
this.dataGridContextMenuService.add(this.getMenuFilterToken(), {
this.dataViewerContextMenuService.add(this.getMenuFilterToken(), {
id: 'deleteAllFilters',
order: 6,
icon: 'filter-reset-all',
title: 'data_grid_table_filter_reset_all_filters',
isPresent(context) {
return context.contextType === DataGridContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
return context.contextType === DataViewerContextMenuService.cellContext && isResultSetDataSource(context.data.model.source);
},
isHidden: context => {
const { model, resultIndex } = context.data;
Expand Down
Loading
Loading