Skip to content

Commit

Permalink
CB-5279 fix: return counter button for non result set data format (#2719
Browse files Browse the repository at this point in the history
)

Co-authored-by: Evgenia Bezborodova <[email protected]>
  • Loading branch information
Wroud and EvgeniaBzzz authored Jun 24, 2024
1 parent b155c98 commit c70c932
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { CommonDialogService, ComputedContextMenuModel, DialogueStateResult, ICo
import { ClipboardService } from '@cloudbeaver/core-ui';
import { replaceMiddle } from '@cloudbeaver/core-utils';
import {
DatabaseDataConstraintAction,
IDatabaseDataModel,
IDatabaseDataOptions,
IDatabaseResultSet,
Expand All @@ -18,7 +19,6 @@ import {
IS_NULL_ID,
isFilterConstraint,
nullOperationsFilter,
ResultSetConstraintAction,
ResultSetDataAction,
ResultSetFormatAction,
wrapOperationArgument,
Expand Down Expand Up @@ -54,7 +54,7 @@ export class DataGridContextMenuFilterService {
return;
}

const constraints = model.source.getAction(resultIndex, ResultSetConstraintAction);
const constraints = model.source.getAction(resultIndex, DatabaseDataConstraintAction);
const data = model.source.getAction(resultIndex, ResultSetDataAction);
const resultColumn = data.getColumn(column);

Expand Down Expand Up @@ -126,7 +126,7 @@ export class DataGridContextMenuFilterService {
return true;
}

const constraints = context.data.model.source.getAction(context.data.resultIndex, ResultSetConstraintAction);
const constraints = context.data.model.source.getAction(context.data.resultIndex, DatabaseDataConstraintAction);
return !constraints.supported;
},
});
Expand All @@ -143,12 +143,12 @@ export class DataGridContextMenuFilterService {
return true;
}

const constraints = context.data.model.source.getAction(context.data.resultIndex, ResultSetConstraintAction);
const constraints = context.data.model.source.getAction(context.data.resultIndex, DatabaseDataConstraintAction);
return constraints.orderConstraints.length === 0 && constraints.filterConstraints.length === 0;
},
onClick: async context => {
const { model, resultIndex } = context.data;
const constraints = model.source.getAction(resultIndex, ResultSetConstraintAction);
const constraints = model.source.getAction(resultIndex, DatabaseDataConstraintAction);

await model.requestDataAction(async () => {
constraints.deleteData();
Expand Down Expand Up @@ -340,7 +340,7 @@ export class DataGridContextMenuFilterService {
},
isHidden: context => {
const { model, resultIndex, key } = context.data;
const constraints = model.source.getAction(resultIndex, ResultSetConstraintAction);
const constraints = model.source.getAction(resultIndex, DatabaseDataConstraintAction);
const data = model.source.getAction(resultIndex, ResultSetDataAction);
const resultColumn = data.getColumn(key.column);
const currentConstraint = resultColumn ? constraints.get(resultColumn.position) : undefined;
Expand All @@ -354,7 +354,7 @@ export class DataGridContextMenuFilterService {
},
onClick: async context => {
const { model, resultIndex, key } = context.data;
const constraints = model.source.getAction(resultIndex, ResultSetConstraintAction);
const constraints = model.source.getAction(resultIndex, DatabaseDataConstraintAction);
const data = model.source.getAction(resultIndex, ResultSetDataAction);
const resultColumn = data.getColumn(key.column);

Expand All @@ -378,13 +378,13 @@ export class DataGridContextMenuFilterService {
},
isHidden: context => {
const { model, resultIndex } = context.data;
const constraints = model.source.getAction(resultIndex, ResultSetConstraintAction);
const constraints = model.source.getAction(resultIndex, DatabaseDataConstraintAction);

return constraints.filterConstraints.length === 0 && !model.requestInfo.requestFilter;
},
onClick: async context => {
const { model, resultIndex } = context.data;
const constraints = model.source.getAction(resultIndex, ResultSetConstraintAction);
const constraints = model.source.getAction(resultIndex, DatabaseDataConstraintAction);

await model.requestDataAction(async () => {
constraints.deleteDataFilters();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
*/
import { injectable } from '@cloudbeaver/core-di';
import {
DatabaseDataConstraintAction,
EOrder,
IDatabaseDataModel,
IResultSetColumnKey,
Order,
ResultSetConstraintAction,
ResultSetDataAction,
} from '@cloudbeaver/plugin-data-viewer';

Expand All @@ -29,7 +29,7 @@ export class DataGridContextMenuOrderService {

private async changeOrder(model: IDatabaseDataModel, resultIndex: number, column: IResultSetColumnKey, order: Order) {
const data = model.source.getAction(resultIndex, ResultSetDataAction);
const constraints = model.source.getAction(resultIndex, ResultSetConstraintAction);
const constraints = model.source.getAction(resultIndex, DatabaseDataConstraintAction);
const resultColumn = data.getColumn(column);

if (!resultColumn) {
Expand All @@ -53,7 +53,7 @@ export class DataGridContextMenuOrderService {
return context.contextType === DataGridContextMenuService.cellContext;
},
isHidden(context) {
const constraints = context.data.model.source.getAction(context.data.resultIndex, ResultSetConstraintAction);
const constraints = context.data.model.source.getAction(context.data.resultIndex, DatabaseDataConstraintAction);
return !constraints.supported || context.data.model.isDisabled(context.data.resultIndex);
},
});
Expand All @@ -71,7 +71,7 @@ export class DataGridContextMenuOrderService {
isChecked: context => {
const { model, resultIndex, key } = context.data;
const data = model.source.getAction(resultIndex, ResultSetDataAction);
const constraints = model.source.getAction(resultIndex, ResultSetConstraintAction);
const constraints = model.source.getAction(resultIndex, DatabaseDataConstraintAction);
const resultColumn = data.getColumn(key.column);

return !!resultColumn && constraints.getOrder(resultColumn.position) === EOrder.asc;
Expand All @@ -91,7 +91,7 @@ export class DataGridContextMenuOrderService {
isChecked: context => {
const { model, resultIndex, key } = context.data;
const data = model.source.getAction(resultIndex, ResultSetDataAction);
const constraints = model.source.getAction(resultIndex, ResultSetConstraintAction);
const constraints = model.source.getAction(resultIndex, DatabaseDataConstraintAction);
const resultColumn = data.getColumn(key.column);

return !!resultColumn && constraints.getOrder(resultColumn.position) === EOrder.desc;
Expand All @@ -111,7 +111,7 @@ export class DataGridContextMenuOrderService {
isChecked: context => {
const { model, resultIndex, key } = context.data;
const data = model.source.getAction(resultIndex, ResultSetDataAction);
const constraints = model.source.getAction(resultIndex, ResultSetConstraintAction);
const constraints = model.source.getAction(resultIndex, DatabaseDataConstraintAction);
const resultColumn = data.getColumn(key.column);

return !!resultColumn && constraints.getOrder(resultColumn.position) === null;
Expand All @@ -124,12 +124,12 @@ export class DataGridContextMenuOrderService {
return context.contextType === DataGridContextMenuService.cellContext;
},
isHidden: context => {
const constraints = context.data.model.source.getAction(context.data.resultIndex, ResultSetConstraintAction);
const constraints = context.data.model.source.getAction(context.data.resultIndex, DatabaseDataConstraintAction);
return !constraints.orderConstraints.length;
},
isDisabled: context => context.data.model.isLoading(),
onClick: async context => {
const constraints = context.data.model.source.getAction(context.data.resultIndex, ResultSetConstraintAction);
const constraints = context.data.model.source.getAction(context.data.resultIndex, DatabaseDataConstraintAction);
await context.data.model.requestDataAction(async () => {
constraints.deleteOrders();
await context.data.model.request(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { observer } from 'mobx-react-lite';

import { IconOrImage, s, useS, useTranslate } from '@cloudbeaver/core-blocks';
import { EOrder, getNextOrder, IDatabaseDataModel, ResultSetConstraintAction } from '@cloudbeaver/plugin-data-viewer';
import { DatabaseDataConstraintAction, EOrder, getNextOrder, IDatabaseDataModel } from '@cloudbeaver/plugin-data-viewer';

import style from './OrderButton.module.css';

Expand All @@ -21,7 +21,7 @@ interface Props {

export const OrderButton = observer<Props>(function OrderButton({ model, resultIndex, attributePosition, className }) {
const translate = useTranslate();
const constraints = model.source.getAction(resultIndex, ResultSetConstraintAction);
const constraints = model.source.getAction(resultIndex, DatabaseDataConstraintAction);
const currentOrder = constraints.getOrder(attributePosition);
const disabled = model.isDisabled(resultIndex) || model.isLoading();
const styles = useS(style);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import { createContext } from 'react';

import type { SqlResultColumn } from '@cloudbeaver/core-sdk';
import type {
DatabaseDataConstraintAction,
DatabaseEditChangeType,
IResultSetColumnKey,
IResultSetElementKey,
IResultSetRowKey,
IResultSetValue,
ResultSetConstraintAction,
ResultSetDataAction,
ResultSetDataContentAction,
ResultSetEditAction,
Expand Down Expand Up @@ -43,7 +43,7 @@ export interface ITableData {
data: ResultSetDataAction;
editor: ResultSetEditAction;
view: ResultSetViewAction;
constraints: ResultSetConstraintAction;
constraints: DatabaseDataConstraintAction;
columns: Array<Column<IResultSetRowKey, any>>;
columnKeys: IResultSetColumnKey[];
rows: IResultSetRowKey[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import { computed, observable } from 'mobx';

import { useObservableRef } from '@cloudbeaver/core-blocks';
import {
DatabaseDataConstraintAction,
IDatabaseDataModel,
IDatabaseResultSet,
IResultSetColumnKey,
IResultSetElementKey,
IResultSetRowKey,
ResultSetConstraintAction,
ResultSetDataAction,
ResultSetDataContentAction,
ResultSetDataKeysUtils,
Expand Down Expand Up @@ -53,7 +53,7 @@ export function useTableData(
const editor = model.source.getAction(resultIndex, ResultSetEditAction);
const view = model.source.getAction(resultIndex, ResultSetViewAction);
const dataContent = model.source.getAction(resultIndex, ResultSetDataContentAction);
const constraints = model.source.getAction(resultIndex, ResultSetConstraintAction);
const constraints = model.source.getAction(resultIndex, DatabaseDataConstraintAction);

return useObservableRef<ITableData & { gridDIVElement: React.RefObject<HTMLDivElement | null> }>(
() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import { computed, makeObservable } from 'mobx';

import { DataTypeLogicalOperation, ResultDataFormat, SqlDataFilterConstraint } from '@cloudbeaver/core-sdk';

import { DatabaseDataAction } from '../../DatabaseDataAction';
import type { IDatabaseDataOptions } from '../../IDatabaseDataOptions';
import type { IDatabaseDataSource } from '../../IDatabaseDataSource';
import type { IDatabaseResultSet } from '../../IDatabaseResultSet';
import { EOrder, Order } from '../../Order';
import { databaseDataAction } from '../DatabaseDataActionDecorator';
import type { IDatabaseDataConstraintAction } from '../IDatabaseDataConstraintAction';
import { DatabaseDataAction } from '../DatabaseDataAction';
import type { IDatabaseDataOptions } from '../IDatabaseDataOptions';
import type { IDatabaseDataSource } from '../IDatabaseDataSource';
import type { IDatabaseResultSet } from '../IDatabaseResultSet';
import { EOrder, Order } from '../Order';
import { databaseDataAction } from './DatabaseDataActionDecorator';
import type { IDatabaseDataConstraintAction } from './IDatabaseDataConstraintAction';

export const IS_NULL_ID = 'IS_NULL';
export const IS_NOT_NULL_ID = 'IS_NOT_NULL';

@databaseDataAction()
export class ResultSetConstraintAction
export class DatabaseDataConstraintAction
extends DatabaseDataAction<IDatabaseDataOptions, IDatabaseResultSet>
implements IDatabaseDataConstraintAction<IDatabaseResultSet>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { NotificationService } from '@cloudbeaver/core-events';
import { ResultDataFormat } from '@cloudbeaver/core-sdk';
import { ActionService, menuExtractItems, MenuService } from '@cloudbeaver/core-view';

import { DatabaseDataConstraintAction } from '../DatabaseDataModel/Actions/DatabaseDataConstraintAction';
import { DatabaseMetadataAction } from '../DatabaseDataModel/Actions/DatabaseMetadataAction';
import { ResultSetConstraintAction } from '../DatabaseDataModel/Actions/ResultSet/ResultSetConstraintAction';
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_VIEWER_DATA_MODEL_ACTIONS_MENU } from '../TableViewer/TableFooter/TableFooterMenu/DATA_VIEWER_DATA_MODEL_ACTIONS_MENU';
Expand Down Expand Up @@ -41,7 +41,7 @@ export class ResultSetTableFooterMenuService {
const resultIndex = context.get(DATA_CONTEXT_DV_DDM_RESULT_INDEX)!;
const result = model.getResult(resultIndex);

return !!result && result.dataFormat === ResultDataFormat.Resultset;
return !!result;
},
getItems(context, items) {
return [ACTION_COUNT_TOTAL_ELEMENTS, ...items];
Expand All @@ -61,10 +61,10 @@ export class ResultSetTableFooterMenuService {
const resultIndex = context.get(DATA_CONTEXT_DV_DDM_RESULT_INDEX)!;
const result = model.getResult(resultIndex);

if (!result || result.dataFormat !== ResultDataFormat.Resultset) {
if (!result) {
return false;
}
const constraint = model.source.tryGetAction(resultIndex, ResultSetConstraintAction);
const constraint = model.source.tryGetAction(resultIndex, DatabaseDataConstraintAction);

switch (action) {
case ACTION_COUNT_TOTAL_ELEMENTS: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { PlaceholderContainer } from '@cloudbeaver/core-blocks';
import { Bootstrap, injectable } from '@cloudbeaver/core-di';
import { ActionService, DATA_CONTEXT_MENU, MenuService } from '@cloudbeaver/core-view';

import { DatabaseDataConstraintAction } from '../../DatabaseDataModel/Actions/DatabaseDataConstraintAction';
import { DATA_VIEWER_CONSTRAINTS_DELETE_ACTION } from '../../DatabaseDataModel/Actions/ResultSet/Actions/DATA_VIEWER_CONSTRAINTS_DELETE_ACTION';
import { ResultSetConstraintAction } from '../../DatabaseDataModel/Actions/ResultSet/ResultSetConstraintAction';
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 type { IDatabaseDataModel } from '../../DatabaseDataModel/IDatabaseDataModel';
Expand Down Expand Up @@ -65,7 +65,7 @@ export class TableHeaderService extends Bootstrap {
case DATA_VIEWER_CONSTRAINTS_DELETE_ACTION: {
const model = context.get(DATA_CONTEXT_DV_DDM)!;
const resultIndex = context.get(DATA_CONTEXT_DV_DDM_RESULT_INDEX)!;
const constraints = model.source.tryGetAction(resultIndex, ResultSetConstraintAction);
const constraints = model.source.tryGetAction(resultIndex, DatabaseDataConstraintAction);

if (constraints) {
constraints.deleteData();
Expand All @@ -91,7 +91,7 @@ export class TableHeaderService extends Bootstrap {
}

if (action === DATA_VIEWER_CONSTRAINTS_DELETE_ACTION) {
const constraints = model.source.tryGetAction(resultIndex, ResultSetConstraintAction);
const constraints = model.source.tryGetAction(resultIndex, DatabaseDataConstraintAction);

if (model.source.options?.whereFilter) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import { action, computed, observable } from 'mobx';

import { useObservableRef } from '@cloudbeaver/core-blocks';

import { ResultSetConstraintAction } from '../../DatabaseDataModel/Actions/ResultSet/ResultSetConstraintAction';
import { DatabaseDataConstraintAction } from '../../DatabaseDataModel/Actions/DatabaseDataConstraintAction';
import type { IDatabaseDataModel } from '../../DatabaseDataModel/IDatabaseDataModel';
import type { IDatabaseDataOptions } from '../../DatabaseDataModel/IDatabaseDataOptions';

interface IState {
model: IDatabaseDataModel<IDatabaseDataOptions, any>;
resultIndex: number;
readonly filter: string;
readonly constraints: ResultSetConstraintAction | null;
readonly constraints: DatabaseDataConstraintAction | null;
readonly disabled: boolean;
readonly applicableFilter: boolean;
set: (value: string) => void;
Expand All @@ -39,7 +39,7 @@ export function useWhereFilter(model: IDatabaseDataModel<IDatabaseDataOptions, a
return null;
}

return this.model.source.tryGetAction(this.resultIndex, ResultSetConstraintAction) ?? null;
return this.model.source.tryGetAction(this.resultIndex, DatabaseDataConstraintAction) ?? null;
},
get disabled() {
const supported = this.constraints?.supported ?? false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { useService } from '@cloudbeaver/core-di';
import { ResultDataFormat } from '@cloudbeaver/core-sdk';
import { CaptureView } from '@cloudbeaver/core-view';

import { ResultSetConstraintAction } from '../DatabaseDataModel/Actions/ResultSet/ResultSetConstraintAction';
import { DatabaseDataConstraintAction } from '../DatabaseDataModel/Actions/DatabaseDataConstraintAction';
import { DataPresentationService, DataPresentationType } from '../DataPresentationService';
import { DataPresentation } from './DataPresentation';
import { DataViewerViewService } from './DataViewerViewService';
Expand Down Expand Up @@ -70,7 +70,7 @@ export const TableViewer = observer<TableViewerProps, HTMLDivElement>(

const localActions = useObjectRef({
clearConstraints() {
const constraints = dataModel?.source.tryGetAction(resultIndex, ResultSetConstraintAction);
const constraints = dataModel?.source.tryGetAction(resultIndex, DatabaseDataConstraintAction);

if (constraints) {
constraints.deleteAll();
Expand Down
2 changes: 1 addition & 1 deletion webapp/packages/plugin-data-viewer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export * from './DatabaseDataModel/Actions/ResultSet/isResultSetComplexValue';
export * from './DatabaseDataModel/Actions/ResultSet/isResultSetContentValue';
export * from './DatabaseDataModel/Actions/ResultSet/isResultSetFileValue';
export * from './DatabaseDataModel/Actions/ResultSet/isResultSetGeometryValue';
export * from './DatabaseDataModel/Actions/ResultSet/ResultSetConstraintAction';
export * from './DatabaseDataModel/Actions/DatabaseDataConstraintAction';
export * from './DatabaseDataModel/Actions/ResultSet/ResultSetDataAction';
export * from './DatabaseDataModel/Actions/ResultSet/ResultSetDataKeysUtils';
export * from './DatabaseDataModel/Actions/ResultSet/ResultSetEditAction';
Expand Down

0 comments on commit c70c932

Please sign in to comment.