From 6179b4c96ec03cd93aec3688560239f1bb0c54e1 Mon Sep 17 00:00:00 2001 From: heswell Date: Tue, 11 Apr 2023 22:08:25 +0100 Subject: [PATCH] fix for ag-grid filtering issue (#631) --- .../vuu-data-ag-grid/src/AgGridFilterUtils.ts | 41 +++++++++++++++---- .../src/useViewportRowModel.ts | 1 + vuu-ui/packages/vuu-data/src/message-utils.ts | 16 ++++++++ .../vuu-data/src/server-proxy/viewport.ts | 27 +++++++++--- 4 files changed, 73 insertions(+), 12 deletions(-) diff --git a/vuu-ui/packages/vuu-data-ag-grid/src/AgGridFilterUtils.ts b/vuu-ui/packages/vuu-data-ag-grid/src/AgGridFilterUtils.ts index 5739f804f5..d69ee72abe 100644 --- a/vuu-ui/packages/vuu-data-ag-grid/src/AgGridFilterUtils.ts +++ b/vuu-ui/packages/vuu-data-ag-grid/src/AgGridFilterUtils.ts @@ -44,6 +44,12 @@ export type AgGridNotEqualFilter = { filterType: "number" | "text"; type: "notEqual"; }; +export type AgGridRangeFilter = { + filter: number; + filterTo: number; + filterType: "number"; + type: "inRange"; +}; export type AgGridStartsWithFilter = { filter: string; filterType: "text"; @@ -57,7 +63,11 @@ export type AgGridFilter = | AgGridLessThanFilter | AgGridSetFilter | AgGridGreaterThanOrEqualFilter - | AgGridLessThanOrEqualFilter; + | AgGridLessThanOrEqualFilter + | AgGridRangeFilter; + +const isRangeFilter = (filter: AgGridFilter): filter is AgGridRangeFilter => + (filter as AgGridRangeFilter)?.type === "inRange"; const agToSingleValueVuuFilterType = ( type: string @@ -127,12 +137,29 @@ export const agGridFilterModelToVuuFilter = ( filterClauses.push(filterClause); } else if (filterType === "text" || filterType === "number") { const { type } = agGridFilter; - const filterClause: FilterClause = { - op: agToSingleValueVuuFilterType(type), - column, - value, - }; - filterClauses.push(filterClause); + if (isRangeFilter(agGridFilter)) { + const filterClause: Filter = { + op: "and", + filters: [ + { + op: "or", + filters: [ + { column, op: ">", value: agGridFilter.filter }, + { column, op: "=", value: agGridFilter.filter }, + ], + }, + { column, op: "<", value: agGridFilter.filterTo }, + ], + }; + filterClauses.push(filterClause); + } else { + const filterClause: FilterClause = { + op: agToSingleValueVuuFilterType(type), + column, + value, + }; + filterClauses.push(filterClause); + } } }); diff --git a/vuu-ui/packages/vuu-data-ag-grid/src/useViewportRowModel.ts b/vuu-ui/packages/vuu-data-ag-grid/src/useViewportRowModel.ts index 3f45af29fb..cdd9809206 100644 --- a/vuu-ui/packages/vuu-data-ag-grid/src/useViewportRowModel.ts +++ b/vuu-ui/packages/vuu-data-ag-grid/src/useViewportRowModel.ts @@ -226,6 +226,7 @@ export const useViewportRowModel = ({ createFilterDataProvider, viewportDatasource, defaultColDef: { + resizable: true, sortable: true, }, getContextMenuItems, diff --git a/vuu-ui/packages/vuu-data/src/message-utils.ts b/vuu-ui/packages/vuu-data/src/message-utils.ts index 45315d17fb..86750ccfc5 100644 --- a/vuu-ui/packages/vuu-data/src/message-utils.ts +++ b/vuu-ui/packages/vuu-data/src/message-utils.ts @@ -1,5 +1,6 @@ import { ClientToServerMenuRPC, + VuuRow, VuuRpcRequest, } from "@finos/vuu-protocol-types"; import { VuuUIMessageOut } from "./vuuUIMessageTypes"; @@ -21,3 +22,18 @@ export const stripRequestId = ({ requestId, ...rest }: WithRequestId): [string, T] => [requestId, rest as T]; + +export const getFirstAndLastRows = ( + rows: VuuRow[] +): [VuuRow, VuuRow] | [VuuRow] => { + let firstRow = rows.at(0) as VuuRow; + if (firstRow.updateType === "SIZE") { + if (rows.length === 1) { + return rows as [VuuRow]; + } else { + firstRow = rows.at(1) as VuuRow; + } + } + const lastRow = rows.at(-1) as VuuRow; + return [firstRow, lastRow]; +}; diff --git a/vuu-ui/packages/vuu-data/src/server-proxy/viewport.ts b/vuu-ui/packages/vuu-data/src/server-proxy/viewport.ts index 857a9279c6..b012bec399 100644 --- a/vuu-ui/packages/vuu-data/src/server-proxy/viewport.ts +++ b/vuu-ui/packages/vuu-data/src/server-proxy/viewport.ts @@ -39,7 +39,6 @@ import * as Message from "./messages"; import { DataSourceAggregateMessage, DataSourceColumnsMessage, - DataSourceConfig, DataSourceDebounceRequest, DataSourceDisabledMessage, DataSourceEnabledMessage, @@ -54,9 +53,9 @@ import { DataSourceVisualLinkRemovedMessage, DataSourceVisualLinksMessage, DataUpdateMode, - hasGroupBy, WithFullConfig, } from "../data-source"; +import { getFirstAndLastRows } from "../message-utils"; const EMPTY_GROUPBY: VuuGroupBy = []; @@ -169,6 +168,8 @@ export class Viewport { private batchMode = true; private useBatchMode = true; + private ignorePostFilterRepeats = false; + private rangeMonitor = new RangeMonitor("ViewPort"); public clientViewportId: string; @@ -629,6 +630,12 @@ export class Viewport { type: "filter", data: dataSourceFilter, }); + + this.ignorePostFilterRepeats = true; + + if (this.useBatchMode) { + this.batchMode = true; + } const { filter } = dataSourceFilter; info?.(`filterRequest: ${filter}`); return this.createRequest({ filterSpec: { filter } }); @@ -732,10 +739,20 @@ export class Viewport { }; updateRows(rows: VuuRow[]) { - const [{ rowIndex: firstRowIndex }] = rows; - const { rowIndex: lastRowIndex } = rows.at(-1) as VuuRow; + const [firstRow, lastRow] = getFirstAndLastRows(rows); + if (firstRow && lastRow) { + this.removePendingRangeRequest(firstRow.rowIndex, lastRow.rowIndex); + } - this.removePendingRangeRequest(firstRowIndex, lastRowIndex); + if (this.ignorePostFilterRepeats) { + if (firstRow.vpSize === this.dataWindow?.rowCount) { + debug?.(`ignore data, rows are post filter repeats`); + this.ignorePostFilterRepeats = false; + return; + } else { + this.ignorePostFilterRepeats = false; + } + } for (const row of rows) { if (this.isTree && isLeafUpdate(row)) {