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

Filter ux fixes #1078

Merged
merged 9 commits into from
Dec 18, 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
5 changes: 5 additions & 0 deletions vuu-ui/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const viteConfig: UserConfig = {
build: {
sourcemap: true,
},
define: {
"process.env.NODE_DEBUG": false,
"process.env.LOCAL": true,
"process.env.LAYOUT_BASE_URL": `"http://127.0.0.1:8081/api"`,
},
resolve: {
alias: {
"cypress/react18": reactVersion.startsWith("18")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,5 @@ export const useTypeaheadSuggestions = () =>
params,
...TYPEAHEAD_MESSAGE_CONSTANTS,
} as ClientToServerGetUniqueValuesStartingWith);

return makeRpcCall<string[]>(rpcMessage);
}, []);
12 changes: 11 additions & 1 deletion vuu-ui/packages/vuu-data-test/src/TickingArrayDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from "@finos/vuu-protocol-types";
import { SelectionItem } from "@finos/vuu-table-types";
import { metadataKeys } from "@finos/vuu-utils";
import { makeSuggestions } from "./makeSuggestions";
import { Table } from "./Table";

export type RpcService = {
Expand Down Expand Up @@ -109,7 +110,6 @@ export class TickingArrayDataSource extends ArrayDataSource {
columnName: string,
value: VuuRowDataItemType
): Promise<true> {
console.log(`applyEdit ${columnName} ${value}`);
const key = row[metadataKeys.KEY];
this.#table?.update(key, columnName, value);
return Promise.resolve(true);
Expand Down Expand Up @@ -160,4 +160,14 @@ export class TickingArrayDataSource extends ArrayDataSource {
}
return super.menuRpcCall(rpcRequest);
}

getTypeaheadSuggestions(column: string, pattern?: string): Promise<string[]> {
if (this.#table) {
return makeSuggestions(this.#table, column, pattern);
} else {
throw Error(
"cannot call getTypeaheadSuggestions on TickingDataSOurce if table has not been provided"
);
}
}
}
30 changes: 22 additions & 8 deletions vuu-ui/packages/vuu-data-test/src/makeSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const getUniqueValues = (table: Table, column: string, pattern = "") => {
uniqueValues.push(value);
}
}
uniqueValues.sort();
if (cachedEntry) {
cachedEntry.set(column, uniqueValues);
} else {
Expand All @@ -31,15 +32,28 @@ const getUniqueValues = (table: Table, column: string, pattern = "") => {
: uniqueValues;
};

// export const makeSuggestions = (
// table: Table,
// column: string,
// pattern?: string
// ) => {
// const uniqueValues = getUniqueValues(table, column, pattern);
// if (uniqueValues.length > 20) {
// return uniqueValues?.slice(0, 20).map((v) => v.toString());
// } else {
// return uniqueValues.map((v) => v.toString());
// }
// };
export const makeSuggestions = (
table: Table,
column: string,
pattern?: string
) => {
const uniqueValues = getUniqueValues(table, column, pattern);
if (uniqueValues.length > 20) {
return uniqueValues?.slice(0, 20).map((v) => v.toString());
} else {
return uniqueValues.map((v) => v.toString());
}
};
): Promise<string[]> =>
new Promise((resolve) => {
const uniqueValues = getUniqueValues(table, column, pattern);
const result =
uniqueValues.length > 20
? uniqueValues?.slice(0, 20).map((v) => v.toString())
: uniqueValues.map((v) => v.toString());
setTimeout(() => resolve(result), 100);
});
2 changes: 1 addition & 1 deletion vuu-ui/packages/vuu-data-test/src/simul/simul-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const createDataSource = (tableName: SimulTableName) => {
});
};

const suggestionFetcher: SuggestionFetcher = async ([
const suggestionFetcher: SuggestionFetcher = ([
vuuTable,
column,
pattern,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export class ArrayDataSource
}

set config(config: DataSourceConfig) {
if (configChanged(this.#config, config)) {
if (this.applyConfig(config)) {
if (config) {
const originalConfig = this.#config;
const newConfig: DataSourceConfig =
Expand Down Expand Up @@ -406,6 +406,25 @@ export class ArrayDataSource
}
}

applyConfig(config: DataSourceConfig) {
if (configChanged(this.#config, config)) {
if (config) {
const newConfig: DataSourceConfig =
config?.filter?.filter && config?.filter.filterStruct === undefined
? {
...config,
filter: {
filter: config.filter.filter,
filterStruct: parseFilter(config.filter.filter),
},
}
: config;
this.#config = withConfigDefaults(newConfig);
return true;
}
}
}

get selectedRowsCount() {
return this.#selectedRowsCount;
}
Expand Down
26 changes: 25 additions & 1 deletion vuu-ui/packages/vuu-data/src/data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,33 @@ export type DataSourceStatus =
| "suspended"
| "unsubscribed";

export interface DataSource extends EventEmitter<DataSourceEvents> {
export interface TypeaheadSuggestionProvider {
getTypeaheadSuggestions: (
columnName: string,
pattern?: string
) => Promise<string[]>;
}

export const isTypeaheadSuggestionProvider = (
source: unknown
): source is TypeaheadSuggestionProvider =>
typeof (source as TypeaheadSuggestionProvider)["getTypeaheadSuggestions"] ===
"function";

export interface DataSource
extends EventEmitter<DataSourceEvents>,
Partial<TypeaheadSuggestionProvider> {
aggregations: VuuAggregation[];
applyEdit: DataSourceEditHandler;
/**
* set config without triggering config event. Use this method when initialising
* a dataSource that has been restored from session state. The dataSource will
* not yet be subscribed. Triggering the config event is unnecessary and might
* cause a React exception if the event were to cause a render.
* @param config DataSourceConfig
* @returns true if config has been applied (will not be if existig config is same)
*/
applyConfig: (config: DataSourceConfig) => true | undefined;
closeTreeNode: (key: string, cascade?: boolean) => void;
columns: string[];
config: DataSourceConfig;
Expand Down
6 changes: 3 additions & 3 deletions vuu-ui/packages/vuu-data/src/inlined-worker.js

Large diffs are not rendered by default.

28 changes: 16 additions & 12 deletions vuu-ui/packages/vuu-data/src/remote-data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,21 @@ export class RemoteDataSource
}

set config(config: DataSourceConfig) {
if (this.applyConfig(config)) {
if (this.#config && this.viewport && this.server) {
if (config) {
this.server?.send({
viewport: this.viewport,
type: "config",
config: this.#config,
});
}
}
this.emit("config", this.#config);
}
}

applyConfig(config: DataSourceConfig) {
if (configChanged(this.#config, config)) {
if (config) {
const newConfig: DataSourceConfig =
Expand All @@ -449,19 +464,8 @@ export class RemoteDataSource
},
}
: config;

this.#config = withConfigDefaults(newConfig);

if (this.#config && this.viewport && this.server) {
if (config) {
this.server?.send({
viewport: this.viewport,
type: "config",
config: this.#config,
});
}
}
this.emit("config", this.#config);
return true;
}
}
}
Expand Down
Loading
Loading