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

fix for ag-grid filtering issue #631

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
41 changes: 34 additions & 7 deletions vuu-ui/packages/vuu-data-ag-grid/src/AgGridFilterUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export const useViewportRowModel = ({
createFilterDataProvider,
viewportDatasource,
defaultColDef: {
resizable: true,
sortable: true,
},
getContextMenuItems,
Expand Down
16 changes: 16 additions & 0 deletions vuu-ui/packages/vuu-data/src/message-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
ClientToServerMenuRPC,
VuuRow,
VuuRpcRequest,
} from "@finos/vuu-protocol-types";
import { VuuUIMessageOut } from "./vuuUIMessageTypes";
Expand All @@ -21,3 +22,18 @@ export const stripRequestId = <T>({
requestId,
...rest
}: WithRequestId<T>): [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];
};
27 changes: 22 additions & 5 deletions vuu-ui/packages/vuu-data/src/server-proxy/viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import * as Message from "./messages";
import {
DataSourceAggregateMessage,
DataSourceColumnsMessage,
DataSourceConfig,
DataSourceDebounceRequest,
DataSourceDisabledMessage,
DataSourceEnabledMessage,
Expand All @@ -54,9 +53,9 @@ import {
DataSourceVisualLinkRemovedMessage,
DataSourceVisualLinksMessage,
DataUpdateMode,
hasGroupBy,
WithFullConfig,
} from "../data-source";
import { getFirstAndLastRows } from "../message-utils";

const EMPTY_GROUPBY: VuuGroupBy = [];

Expand Down Expand Up @@ -169,6 +168,8 @@ export class Viewport {
private batchMode = true;
private useBatchMode = true;

private ignorePostFilterRepeats = false;

private rangeMonitor = new RangeMonitor("ViewPort");

public clientViewportId: string;
Expand Down Expand Up @@ -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 } });
Expand Down Expand Up @@ -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)) {
Expand Down