Skip to content

Commit

Permalink
connect filterbar to persistence
Browse files Browse the repository at this point in the history
  • Loading branch information
heswell committed Oct 27, 2023
1 parent 84a4770 commit 474d5ca
Show file tree
Hide file tree
Showing 22 changed files with 454 additions and 327 deletions.
46 changes: 17 additions & 29 deletions vuu-ui/packages/vuu-data-react/src/hooks/useTypeaheadSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,20 @@ export const getTypeaheadParams = (
// const containSpace = (text: string) => text.indexOf(" ") !== -1;
// const replaceSpace = (text: string) => text.replace(/\s/g, SPECIAL_SPACE);

export const useTypeaheadSuggestions = () => {
const getTypeaheadSuggestions: SuggestionFetcher = useCallback(
async (params: TypeaheadParams) => {
const rpcMessage =
params.length === 2
? ({
method: "getUniqueFieldValues",
params,
...TYPEAHEAD_MESSAGE_CONSTANTS,
} as ClientToServerGetUniqueValues)
: ({
method: "getUniqueFieldValuesStartingWith",
params,
...TYPEAHEAD_MESSAGE_CONSTANTS,
} as ClientToServerGetUniqueValuesStartingWith);

const suggestions = await makeRpcCall<string[]>(rpcMessage);

// TODO replacing space with underscores like this is not being correctly handled elsewhere
return suggestions;
// return suggestions.some(containSpace)
// ? suggestions.map(replaceSpace)
// : suggestions;
},
[]
);

return getTypeaheadSuggestions;
};
export const useTypeaheadSuggestions = () =>
useCallback<SuggestionFetcher>(async (params: TypeaheadParams) => {
const rpcMessage =
params.length === 2
? ({
method: "getUniqueFieldValues",
params,
...TYPEAHEAD_MESSAGE_CONSTANTS,
} as ClientToServerGetUniqueValues)
: ({
method: "getUniqueFieldValuesStartingWith",
params,
...TYPEAHEAD_MESSAGE_CONSTANTS,
} as ClientToServerGetUniqueValuesStartingWith);

return makeRpcCall<string[]>(rpcMessage);
}, []);
16 changes: 16 additions & 0 deletions vuu-ui/packages/vuu-data/src/remote-data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ export class RemoteDataSource
visualLink: visualLink || this.#config.visualLink,
};

console.log(`1)`, {
config: this.#config,
});

this.#title = title;
this.rangeRequest = this.throttleRangeRequest;
}
Expand Down Expand Up @@ -158,6 +162,14 @@ export class RemoteDataSource

const { bufferSize } = this;

console.log(`subscribe`, {
config: this.#config,
});

console.log(`3)`, {
config: this.#config,
});

this.server?.subscribe(
{
...this.#config,
Expand Down Expand Up @@ -388,6 +400,9 @@ export class RemoteDataSource
}

set config(config: DataSourceConfig) {
console.log(`2)`, {
config,
});
if (configChanged(this.#config, config)) {
if (config) {
const newConfig: DataSourceConfig =
Expand Down Expand Up @@ -437,6 +452,7 @@ export class RemoteDataSource
this.server.send(message);
}
}
console.log("set columns");
this.emit("config", this.#config);
}

Expand Down
5 changes: 4 additions & 1 deletion vuu-ui/packages/vuu-filters/src/filter-bar/FilterBar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TableSchema } from "@finos/vuu-data";
import { DataSourceFilter } from "@finos/vuu-data-types";
import { Filter } from "@finos/vuu-filter-types";
import { Toolbar } from "@finos/vuu-layout";
import { ActiveItemChangeHandler, Toolbar } from "@finos/vuu-layout";
import { Prompt } from "@finos/vuu-popups";
import { Button } from "@salt-ds/core";
import cx from "classnames";
Expand All @@ -19,6 +19,7 @@ export interface FilterBarProps extends HTMLAttributes<HTMLDivElement> {
activeFilterIndex?: number[];
filters: Filter[];
onApplyFilter: (filter: DataSourceFilter) => void;
onChangeActiveFilterIndex: ActiveItemChangeHandler;
onFiltersChanged?: (filters: Filter[]) => void;
showMenu?: boolean;
tableSchema: TableSchema;
Expand All @@ -32,6 +33,7 @@ export const FilterBar = ({
className: classNameProp,
filters: filtersProp,
onApplyFilter,
onChangeActiveFilterIndex: onChangeActiveFilterIndexProp,
onFiltersChanged,
showMenu: showMenuProp = false,
tableSchema,
Expand All @@ -58,6 +60,7 @@ export const FilterBar = ({
containerRef: rootRef,
filters: filtersProp,
onApplyFilter,
onChangeActiveFilterIndex: onChangeActiveFilterIndexProp,
onFiltersChanged,
showMenu: showMenuProp,
});
Expand Down
6 changes: 4 additions & 2 deletions vuu-ui/packages/vuu-filters/src/filter-bar/useFilterBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface FilterBarHookProps
| "activeFilterIndex"
| "filters"
| "onApplyFilter"
| "onChangeActiveFilterIndex"
| "onFiltersChanged"
| "showMenu"
> {
Expand All @@ -46,6 +47,7 @@ export const useFilterBar = ({
containerRef,
filters: filtersProp,
onApplyFilter,
onChangeActiveFilterIndex: onChangeActiveFilterIndexProp,
onFiltersChanged,
showMenu: showMenuProp,
}: FilterBarHookProps) => {
Expand Down Expand Up @@ -308,8 +310,9 @@ export const useFilterBar = ({
const handleChangeActiveFilterIndex = useCallback<ActiveItemChangeHandler>(
(itemIndex) => {
setActiveFilterIndex(itemIndex);
onChangeActiveFilterIndexProp?.(itemIndex);
},
[]
[onChangeActiveFilterIndexProp]
);

const handleClickAddFilter = useCallback(() => {
Expand All @@ -327,7 +330,6 @@ export const useFilterBar = ({
};

const handleChangeFilterClause = (filterClause: Partial<FilterClause>) => {
console.log({ filterClause });
if (filterClause !== undefined) {
setEditFilter((filter) => replaceClause(filter, filterClause));
setShowMenu(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export const ExpandoCombobox = forwardRef(function ExpandoCombobox<
);

const handleSetSelectedText = useCallback((text: string) => {
console.log(`handleSetSelectedText ${text}`);
setText(text);
}, []);

Expand Down Expand Up @@ -132,7 +131,7 @@ export const ExpandoCombobox = forwardRef(function ExpandoCombobox<
minWidth: 102,
};

return (
return props.source?.length === 0 ? null : (
<div
className={cx(classBase, classNameProp)}
data-text={text}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const TextInput = forwardRef(function TextInput(
setTypeaheadValues(suggestions);
})
.catch((err) => {
console.error("Error getting suggsetions", err);
console.error("Error getting suggestions", err);
});
}
}, [table, column, valueInputValue, getSuggestions]);
Expand Down
4 changes: 2 additions & 2 deletions vuu-ui/packages/vuu-filters/src/filter-pill/FilterPill.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
align-items: center;
background: var(--salt-taggable-background);
border: solid 1px var(--salt-taggable-foreground);
border-radius: 26px;
border-radius: 24px;
color: var(--vuu-color-gray-50);
display: inline-flex;
max-width: var(--vuuFilterPill-maxWidth, 200px);
Expand All @@ -13,7 +13,7 @@
}

.vuuFilterPill.vuuToolbarItem {
height: 26px;
height: 24px;
}

.vuuFilterPill[aria-selected="true"]{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FocusEventHandler, HTMLAttributes, memo, useCallback } from "react";
import { HTMLAttributes, memo } from "react";
import { ColumnDefinitionExpression } from "./column-language-parser";
import {
ExpressionSuggestionConsumer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const columnFunctionDescriptors: ColumnFunctionDescriptor[] = [
{
accepts: ["boolean"],
description:
"Applies boolean and operator across supplied parameters to retuner a single boolean result",
"Applies boolean and operator across supplied parameters to returns a single boolean result",
example: {
expression: 'and(ccy="EUR",quantity=0)',
result: "true | false",
Expand Down Expand Up @@ -124,6 +124,24 @@ export const columnFunctionDescriptors: ColumnFunctionDescriptor[] = [
},
type: "string",
},
/**
* or
*/
{
accepts: ["boolean"],
description:
"Applies boolean or operator across supplied parameters to returns a single boolean result",
example: {
expression: 'or(status="cancelled",quantity=0)',
result: "true | false",
},
name: "or",
params: {
description: "( boolean, [ boolean* ] )",
},
type: "boolean",
},

/**
* upper()
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,9 @@ class ColumnExpression {
: new RelationalExpressionImpl();
this.addExpression(condition);
}
} else {
} /*else if (isCallExpression(this.#expression)) {
this.addExpression(new RelationalExpressionImpl());
} */ else {
console.error("setCondition called unexpectedly");
}
}
Expand Down Expand Up @@ -586,6 +588,7 @@ export const walkTree = (tree: Tree, source: string) => {
const cursor = tree.cursor();
do {
const { name, from, to } = cursor;
console.log(`walkTree ${name}`);
switch (name) {
case "AndCondition":
columnExpression.setCondition("and");
Expand All @@ -596,6 +599,7 @@ export const walkTree = (tree: Tree, source: string) => {
break;

case "RelationalExpression":
// TODO this breaks when the relationalexpression is an argument to a CallExpression
columnExpression.setCondition();
break;

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

@precedence {
call,
or @left,
and @left
times @left,
plus @left
op @left
}

@top ColumnDefinitionExpression { expression }
Expand All @@ -18,7 +18,8 @@ expression {
ParenthesizedExpression |
ArithmeticExpression |
ConditionalExpression |
CallExpression
RelationalExpression |
CallExpression
}

ParenthesizedExpression { OpenBrace expression CloseBrace }
Expand All @@ -44,7 +45,7 @@ AndCondition { booleanCondition !and "and" booleanCondition }
OrCondition { booleanCondition !or "or" booleanCondition }

RelationalExpression {
expression RelationalOperator expression
expression !op RelationalOperator expression
}

RelationalOperator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,20 @@ describe("Column Expression treeWalker", () => {
});
});
});

it.only("parses and expressions with boolean conditions", () => {
const str = 'and(bid > 100, currency="EUR")';
const result = parser.parse(str);
const expression = walkTree(result, str);
expect(expression).toEqual({
type: "callExpression",
functionName: "and",
arguments: [
{ type: "relationalExpression" },
{ type: "relationalExpression" },
],
});
});
});

// expect(evaluateExpression('if(side="Sell","N","Y")')).toEqual(Ok);
Expand Down
8 changes: 8 additions & 0 deletions vuu-ui/packages/vuu-table-extras/test/column-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ describe("ColumnExpressionParser", () => {
).toEqual(Ok);
});

it("parses and function", () => {
expect(evaluateExpression('and(price > 100, ccy="EUR")')).toEqual(Ok);
});

it("parses or function", () => {
expect(evaluateExpression('or(price > 100, ccy="EUR")')).toEqual(Ok);
});

it("parses conditional expressions", () => {
expect(evaluateExpression("if(price > 100, true, false)")).toEqual(Ok);
expect(evaluateExpression('if(side="Sell","N","Y")')).toEqual(Ok);
Expand Down
2 changes: 1 addition & 1 deletion vuu-ui/packages/vuu-table/src/table-next/useTableNext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export const useTable = ({
// tableSchema,
// });
} else {
console.log("usbscription message with no schema");
console.log("subscription message with no schema");
}
},
[]
Expand Down
5 changes: 4 additions & 1 deletion vuu-ui/packages/vuu-utils/src/filter-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,14 @@ export function isMultiClauseFilter(
const filterValue = (value: string | number | boolean) =>
typeof value === "string" ? `"${value}"` : value;

const quotedStrings = (value: string | number | boolean) =>
typeof value === "string" ? `"${value}"` : value;

export const filterAsQuery = (f: Filter): string => {
if (isMultiClauseFilter(f)) {
return f.filters.map((filter) => filterAsQuery(filter)).join(` ${f.op} `);
} else if (isMultiValueFilter(f)) {
return `${f.column} ${f.op} [${f.values.join(",")}]`;
return `${f.column} ${f.op} [${f.values.map(quotedStrings).join(",")}]`;
} else {
return `${f.column} ${f.op} ${filterValue(f.value)}`;
}
Expand Down
Loading

0 comments on commit 474d5ca

Please sign in to comment.