Skip to content

Commit

Permalink
Quick filters (finos#1523)
Browse files Browse the repository at this point in the history
* fix filters generated by QuickFilters

all filters defaulted to contains
remove suggestionProvider as prop

* inline filters

* enhance VuuTypeaheadInput

allow input that does not match suggestions
allow full function in absence of suggestions
remove prop drilling of suggestionPtovider

* remove last referenced to suggestionProvider

* improve inline filter behaviour and appearence
  • Loading branch information
heswell authored Oct 23, 2024
1 parent 21af093 commit 61f108e
Show file tree
Hide file tree
Showing 37 changed files with 812 additions and 401 deletions.
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
import {
import type {
DataValueDescriptor,
SuggestionProvider,
TableSchemaTable,
} from "@finos/vuu-data-types";
import {
VuuDatePicker,
VuuInput,
VuuTypeaheadInput,
VuuTypeaheadInputProps,
} from "@finos/vuu-ui-controls";
import { CommitHandler, isDateTimeDataValue } from "@finos/vuu-utils";
import { InputProps } from "@salt-ds/core";

export interface DataItemEditControlProps {
InputProps?: Partial<InputProps>;
TypeaheadProps?: Pick<VuuTypeaheadInputProps, "highlightFirstSuggestion">;
/**
* A table column or form field Descriptor.
*/
dataDescriptor: DataValueDescriptor;
errorMessage?: string;
onCommit: CommitHandler<HTMLElement, string | undefined>;
suggestionProvider?: SuggestionProvider;
table?: TableSchemaTable;
}

export type ValidationStatus = "initial" | true | string;

export const getDataItemEditControl = ({
InputProps,
TypeaheadProps,
dataDescriptor,
errorMessage,
onCommit,
suggestionProvider,
table,
}: DataItemEditControlProps) => {
const handleCommitNumber: CommitHandler<HTMLElement, number> = (
Expand All @@ -52,16 +52,13 @@ export const getDataItemEditControl = ({
);
} else if (isDateTimeDataValue(dataDescriptor)) {
return <VuuDatePicker onCommit={handleCommitNumber} />;
} else if (
dataDescriptor.serverDataType === "string" &&
suggestionProvider &&
table
) {
} else if (dataDescriptor.serverDataType === "string" && table) {
return (
<VuuTypeaheadInput
{...InputProps}
{...TypeaheadProps}
column={dataDescriptor.name}
onCommit={onCommit}
suggestionProvider={suggestionProvider}
table={table}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export interface CustomFilterProps
| "onFilterDeleted"
| "onFilterRenamed"
| "onFilterStateChanged"
| "suggestionProvider"
| "tableSchema"
> {
columnDescriptors: ColumnDescriptor[];
Expand All @@ -34,7 +33,6 @@ export const CustomFilters = ({
onFilterDeleted,
onFilterRenamed,
onFilterStateChanged,
suggestionProvider,
tableSchema,
}: CustomFilterProps) => {
const rootRef = useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -81,7 +79,7 @@ export const CustomFilters = ({
filter={filter}
key={`filter-${i}`}
selected={activeFilterIndex.includes(i)}
/>
/>,
);
});
return items;
Expand Down Expand Up @@ -119,7 +117,6 @@ export const CustomFilters = ({
onCancel={onCancelEdit}
onSave={onSave}
filter={interactedFilterState?.filter}
suggestionProvider={suggestionProvider}
tableSchema={tableSchema}
/>
)}
Expand Down
2 changes: 0 additions & 2 deletions vuu-ui/packages/vuu-filters/src/filter-bar/FilterBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,13 @@ export const FilterBar = ({
onFilterDeleted={onFilterDeleted}
onFilterRenamed={onFilterRenamed}
onFilterStateChanged={onFilterStateChanged}
suggestionProvider={suggestionProvider}
tableSchema={tableSchema}
/>
) : (
<QuickFilters
{...QuickFilterProps}
availableColumns={columnDescriptors}
onApplyFilter={onApplyFilter}
suggestionProvider={suggestionProvider}
tableSchema={tableSchema}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SuggestionProvider, TableSchema } from "@finos/vuu-data-types";
import type { TableSchema } from "@finos/vuu-data-types";
import {
ColumnDescriptorsByName,
MultiValueFilterClause,
Expand Down Expand Up @@ -31,7 +31,6 @@ export interface FilterClauseProps
onDropdownClose?: (closeReason: CloseReason) => void;
onDropdownOpen?: () => void;
onFocusSave?: () => void;
suggestionProvider?: SuggestionProvider;
tableSchema: TableSchema;
}

Expand All @@ -45,7 +44,6 @@ export const FilterClause = ({
onDropdownOpen,
onFocusSave,
filterClauseModel,
suggestionProvider,
tableSchema,
...htmlAttributes
}: FilterClauseProps) => {
Expand Down Expand Up @@ -109,7 +107,6 @@ export const FilterClause = ({
operator={filterClauseModel.op}
ref={valueRef}
selectedColumn={selectedColumn}
suggestionProvider={suggestionProvider}
table={tableSchema.table}
value={
(filterClause as MultiValueFilterClause)?.values ??
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,19 @@ import {
} from "@finos/vuu-filter-types";
import { isDateTimeDataValue } from "@finos/vuu-utils";
import { ForwardedRef, forwardRef } from "react";
import { FilterClauseProps } from "../FilterClause";
import { FilterClauseValueEditorDate } from "./FilterClauseValueEditorDate";

const classBase = "vuuFilterClause";

type FilterClauseValueEditorProps = Pick<
ReturnType<typeof useFilterClause>,
"selectedColumn" | "inputProps" | "onChangeValue" | "onDeselectValue"
> &
Pick<FilterClauseProps, "suggestionProvider"> & {
table?: TableSchemaTable;
} & {
operator?: SingleValueFilterClauseOp | "in";
value?: string | string[] | number | number[] | boolean | boolean[];
};
> & {
table?: TableSchemaTable;
} & {
operator?: SingleValueFilterClauseOp | "in";
value?: string | string[] | number | number[] | boolean | boolean[];
};

export const FilterClauseValueEditor = forwardRef(
function FilterClauseValueEditor(
Expand All @@ -34,7 +32,6 @@ export const FilterClauseValueEditor = forwardRef(
inputProps,
onChangeValue,
onDeselectValue,
suggestionProvider,
table,
value,
}: FilterClauseValueEditorProps,
Expand Down Expand Up @@ -69,7 +66,6 @@ export const FilterClauseValueEditor = forwardRef(
onChangeValue={onChangeValue}
operator={operator}
ref={forwardedRef}
suggestionProvider={suggestionProvider}
table={table}
value={
value === undefined
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { useTypeaheadSuggestions } from "@finos/vuu-data-react";
import type { SuggestionFetcher } from "@finos/vuu-data-types";
import type { TypeaheadParams } from "@finos/vuu-protocol-types";
import { ExpandoInput, MultiSelectionHandler } from "@finos/vuu-ui-controls";
import { CommitHandler, getVuuTable } from "@finos/vuu-utils";
import { CommitHandler, getVuuTable, NO_DATA_MATCH } from "@finos/vuu-utils";
import { Option } from "@salt-ds/core";
import {
FormEvent,
Expand All @@ -25,12 +24,9 @@ export interface FilterClauseTextValueEditorProps
"data-field"?: string;
ref: RefObject<HTMLDivElement>;
operator: string;
suggestionProvider?: () => SuggestionFetcher;
value: string | string[];
}

const NO_DATA_MATCH = ["No matching data"];

export const FilterClauseValueEditorText = forwardRef(
function FilterClauseTextValueEditor(
{
Expand All @@ -39,7 +35,6 @@ export const FilterClauseValueEditorText = forwardRef(
column,
onChangeValue,
operator,
suggestionProvider = useTypeaheadSuggestions,
table,
value,
}: FilterClauseTextValueEditorProps,
Expand All @@ -60,7 +55,7 @@ export const FilterClauseValueEditorText = forwardRef(
[],
);

const getSuggestions = suggestionProvider();
const getSuggestions = useTypeaheadSuggestions();

const handleSingleValueSelectionChange = useCallback(
(_, [value]: string[]) => onChangeValue(value),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SuggestionProvider, TableSchema } from "@finos/vuu-data-types";
import { TableSchema } from "@finos/vuu-data-types";
import type { Filter } from "@finos/vuu-filter-types";
import { ColumnDescriptor } from "@finos/vuu-table-types";
import { SplitButton } from "@finos/vuu-ui-controls";
Expand All @@ -23,7 +23,6 @@ export interface FilterEditorProps extends HTMLAttributes<HTMLDivElement> {
filter?: Filter;
onCancel: FilterEditCancelHandler;
onSave: FilterEditSaveHandler;
suggestionProvider?: SuggestionProvider;
tableSchema: TableSchema;
}

Expand All @@ -32,7 +31,6 @@ export const FilterEditor = ({
filter,
onCancel,
onSave,
suggestionProvider,
tableSchema,
...htmlAttributes
}: FilterEditorProps) => {
Expand Down Expand Up @@ -73,7 +71,7 @@ export const FilterEditor = ({
onChange={onChangeFilterCombinator}
onKeyDown={onKeyDownCombinator}
operator={op}
/>
/>,
);
}
content.push(
Expand All @@ -84,9 +82,8 @@ export const FilterEditor = ({
key={`editor-${i}`}
onCancel={onCancelFilterClause}
onFocusSave={focusSaveButton}
suggestionProvider={suggestionProvider}
tableSchema={tableSchema}
/>
/>,
);
});
return content;
Expand Down
23 changes: 19 additions & 4 deletions vuu-ui/packages/vuu-filters/src/inline-filter/InlineFilter.css
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
.vuuInlineFilter {
height: 24px;
height: var(--salt-size-base);

.vuuInlineFilter-filter {
--saltInput-minHeight: 22px;
display: inline-block;
padding: 1px;
height: 100%;
padding: 1px 1px 1px 0;

.vuuTypeaheadInput {
border: solid 1px var(--salt-separable-secondary-borderColor);
border-radius: 0;
}

.vuuTypeaheadInput {
height: 22px;
input::placeholder {
color: var(--salt-content-primary-foreground-disabled);
}
}

.saltInput-primary.vuuInput {
border-color: var(--salt-separable-secondary-borderColor);
border: solid 1px var(--salt-separable-secondary-borderColor);
border-radius: 0;
height: 22px;
min-height: 22px;
input::placeholder {
color: var(--tar-color-gray-25);
color: var(--salt-content-primary-foreground-disabled);
}
}
}
Expand Down
30 changes: 24 additions & 6 deletions vuu-ui/packages/vuu-filters/src/inline-filter/InlineFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { getDataItemEditControl } from "@finos/vuu-data-react";
import { VirtualColSpan, useHeaderProps } from "@finos/vuu-table";
import { CommitHandler, getFieldName } from "@finos/vuu-utils";
import {
CommitHandler,
FilterAggregator,
getFieldName,
} from "@finos/vuu-utils";
import { useComponentCssInjection } from "@salt-ds/styles";
import { useWindow } from "@salt-ds/window";
import { HTMLAttributes, useCallback } from "react";
import { HTMLAttributes, useCallback, useMemo } from "react";
import { ColumnDescriptor } from "@finos/vuu-table-types";

import inlineFilteCss from "./InlineFilter.css";
import { InputProps } from "@salt-ds/core";
import { TableSchemaTable } from "@finos/vuu-data-types";

const classBase = "vuuInlineFilter";

Expand All @@ -18,15 +23,23 @@ export type FilterValueChangeHandler = (
export interface InlineFilterProps
extends Omit<HTMLAttributes<HTMLDivElement>, "onChange"> {
onChange: FilterValueChangeHandler;
table: TableSchemaTable;
}

const InputProps: Partial<InputProps> = {
placeholder: "Enter value",
inputProps: {
placeholder: "Filter value",
},
variant: "primary",
};

const TypeaheadProps = {
highlightFirstSuggestion: false,
};

export const InlineFilter = ({
onChange,
table,
...htmlAttributes
}: InlineFilterProps) => {
const targetWindow = useWindow();
Expand All @@ -36,6 +49,7 @@ export const InlineFilter = ({
window: targetWindow,
});

const filterAggregator = useMemo(() => new FilterAggregator(), []);
const { columns, virtualColSpan = 0 } = useHeaderProps();

const onCommit = useCallback<
Expand All @@ -45,25 +59,29 @@ export const InlineFilter = ({
const fieldName = getFieldName(evt.target);
const column = columns.find((c) => c.name === fieldName);
if (column) {
onChange(column, value.toString());
filterAggregator.addFilter(fieldName, value.toString());
// onChange(column, value.toString());
}
},
[columns, onChange],
[columns, filterAggregator],
);

return (
<div {...htmlAttributes} className={classBase}>
<div {...htmlAttributes} className={classBase} role="row">
<VirtualColSpan width={virtualColSpan} />
{columns.map((column) => (
<div
className={`${classBase}-filter`}
data-field={column.name}
key={column.name}
style={{ width: column.width }}
>
{getDataItemEditControl({
InputProps,
TypeaheadProps,
dataDescriptor: column,
onCommit,
table,
})}
</div>
))}
Expand Down
Loading

0 comments on commit 61f108e

Please sign in to comment.