mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
feat: fix issue with request duplication CB-23
This commit is contained in:
@@ -25,7 +25,7 @@ import { injectable, IInitializableController, IDestructibleController } from '@
|
||||
|
||||
import { AgGridContext } from './AgGridContext';
|
||||
import {
|
||||
AgGridRow, IAgGridActions, IAgGridCol, IAgGridModel, IColumnSorting, SortMode,
|
||||
AgGridRow, IAgGridActions, IAgGridCol, IAgGridModel, SortMode, SortModel,
|
||||
} from './IAgGridModel';
|
||||
import { RowSelection } from './TableSelection/RowSelection';
|
||||
import { TableSelection } from './TableSelection/TableSelection';
|
||||
@@ -40,7 +40,6 @@ export class AgGridTableController implements IInitializableController, IDestruc
|
||||
};
|
||||
|
||||
private readonly selection = new TableSelection();
|
||||
private sortingOrder: IColumnSorting[] = []; // sort mode of all columns except index column
|
||||
|
||||
/**
|
||||
* contains properties to pass to ag-grid
|
||||
@@ -132,6 +131,7 @@ export class AgGridTableController implements IInitializableController, IDestruc
|
||||
startRow,
|
||||
endRow,
|
||||
successCallback,
|
||||
sortModel,
|
||||
failCallback,
|
||||
} = params;
|
||||
|
||||
@@ -141,7 +141,7 @@ export class AgGridTableController implements IInitializableController, IDestruc
|
||||
startRow,
|
||||
length,
|
||||
{
|
||||
sorting: this.sortingOrder,
|
||||
sorting: sortModel as SortModel,
|
||||
}
|
||||
);
|
||||
// update columns only once after first data fetching
|
||||
@@ -201,17 +201,9 @@ export class AgGridTableController implements IInitializableController, IDestruc
|
||||
}
|
||||
|
||||
private handleSortChanged(event: SortChangedEvent) {
|
||||
console.log(event);
|
||||
this.sortingOrder = event.columnApi.getAllGridColumns().map((col) => {
|
||||
const columnSorting: IColumnSorting = {
|
||||
colId: col.getColId(),
|
||||
sortMode: col.getSort() as SortMode || null,
|
||||
sortOrder: col.getSortedAt(),
|
||||
};
|
||||
return columnSorting;
|
||||
});
|
||||
if (this.gridModel.onSortChanged) {
|
||||
this.gridModel.onSortChanged(this.sortingOrder);
|
||||
const sortModel = event.api.getSortModel() as SortModel;
|
||||
this.gridModel.onSortChanged(sortModel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,11 +212,10 @@ export class AgGridTableController implements IInitializableController, IDestruc
|
||||
private resetData(columns?: IAgGridCol[], rows?: AgGridRow[]): void {
|
||||
this.selection.clear();
|
||||
if (this.api) {
|
||||
// only purgeInfiniteCache() doesn't work when cache is empty.
|
||||
// probably it thinks that nothing to delete - nothing to refresh
|
||||
this.api.refreshInfiniteCache(); // it will mark internal state for reload
|
||||
this.api.purgeInfiniteCache(); // it will reset internal state
|
||||
this.columns = columns ? mapDataToColumns(columns) : this.columns;
|
||||
if (columns) {
|
||||
this.columns = mapDataToColumns(columns);
|
||||
}
|
||||
this.setInitialRow(rows);
|
||||
}
|
||||
}
|
||||
@@ -237,7 +228,7 @@ export class AgGridTableController implements IInitializableController, IDestruc
|
||||
addIndex: 0,
|
||||
add: initialRows || [],
|
||||
};
|
||||
this.api!.updateRowData(transaction);
|
||||
this.api!.applyTransaction(transaction);
|
||||
}
|
||||
|
||||
private updateCellValue(rowNumber: number, colNumber: number, value: any): void {
|
||||
|
||||
@@ -12,14 +12,14 @@ export type AgGridRow = any[];
|
||||
|
||||
export type SortMode = 'asc' | 'desc' | null;
|
||||
|
||||
export interface IColumnSorting {
|
||||
export type SortModel = {
|
||||
colId: string;
|
||||
sortMode: SortMode;
|
||||
sortOrder: number;
|
||||
}
|
||||
sort: SortMode;
|
||||
}[];
|
||||
|
||||
|
||||
export interface IRequestDataOptions {
|
||||
sorting?: IColumnSorting[];
|
||||
sorting?: SortModel;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ export interface IAgGridModel {
|
||||
// hooks
|
||||
onRequestData(rowOffset: number, count: number, options?: IRequestDataOptions): Promise<IRequestedData>;
|
||||
onCellEditingStopped?(rowNumber: number, colNumber: number, value: any): void;
|
||||
onSortChanged?(sorting: IColumnSorting[]): void;
|
||||
onSortChanged?(sorting: SortModel): void;
|
||||
onEditSave(): void;
|
||||
onEditCancel(): void;
|
||||
}
|
||||
|
||||
@@ -118,7 +118,6 @@ export function TableColumnHeader(props: HeaderProps) {
|
||||
[]
|
||||
);
|
||||
|
||||
console.log(props.displayName, props.column.getSort(), props);
|
||||
return styled(headerStyles)(
|
||||
<table-header as="div" onClick={handleClick}>
|
||||
<icon as="div">
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { IColumnSorting } from '@dbeaver/ag-grid-plugin';
|
||||
import { SqlDataFilterConstraint } from '@dbeaver/core/sdk';
|
||||
|
||||
import { IRequestDataResultOptions } from './TableViewer/TableViewerModel';
|
||||
@@ -7,19 +6,14 @@ export function RequestDataOptionsToConstrains(
|
||||
options?: IRequestDataResultOptions
|
||||
): SqlDataFilterConstraint[] | undefined {
|
||||
const constraints: SqlDataFilterConstraint[] = (options?.sorting || [])
|
||||
.reduce((accumulator: SqlDataFilterConstraint[], columnSorting: IColumnSorting) => {
|
||||
if (columnSorting.sortMode) {
|
||||
const constrain: SqlDataFilterConstraint = {
|
||||
attribute: columnSorting.colId,
|
||||
orderPosition: columnSorting.sortOrder || 0,
|
||||
orderAsc: columnSorting.sortMode === 'asc',
|
||||
};
|
||||
accumulator.push(constrain);
|
||||
}
|
||||
return accumulator;
|
||||
}, []);
|
||||
constraints.sort((a, b) => a.orderPosition! - b.orderPosition!);
|
||||
constraints.forEach((c, ind) => c.orderPosition = ind);
|
||||
.map((columnSorting, index) => {
|
||||
const constrain: SqlDataFilterConstraint = {
|
||||
attribute: columnSorting.colId,
|
||||
orderPosition: index,
|
||||
orderAsc: columnSorting.sort === 'asc',
|
||||
};
|
||||
return constrain;
|
||||
});
|
||||
|
||||
return constraints.length ? constraints : undefined;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import { action, observable } from 'mobx';
|
||||
|
||||
import {
|
||||
IAgGridModel, IRequestedData, IRequestDataOptions, IColumnSorting
|
||||
IAgGridModel, IRequestedData, IRequestDataOptions, SortModel
|
||||
} from '@dbeaver/ag-grid-plugin';
|
||||
import { ErrorDetailsDialog } from '@dbeaver/core/app';
|
||||
import { CommonDialogService } from '@dbeaver/core/dialogs';
|
||||
@@ -32,7 +32,7 @@ export const fetchingSettings = {
|
||||
|
||||
export interface IRequestDataResultOptions extends IRequestDataOptions {
|
||||
// to be extended, now just reexport to avoid ag-grid-plugin dependency
|
||||
sorting?: IColumnSorting[];
|
||||
sorting?: SortModel;
|
||||
}
|
||||
|
||||
export interface ITableViewerModelOptions {
|
||||
@@ -280,7 +280,8 @@ export class TableViewerModel implements ITableViewerModelOptions {
|
||||
}
|
||||
|
||||
private onSortChanged() {
|
||||
this.resetData();
|
||||
this.tableDataModel.resetData();
|
||||
this._hasMoreRows = true;
|
||||
}
|
||||
|
||||
private async trySaveChanges(diffs: RowDiff[]) {
|
||||
|
||||
Reference in New Issue
Block a user