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

use session table name in typeahead queries #1190

Merged
merged 2 commits into from
Feb 12, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import {
ClientToServerGetUniqueValues,
ClientToServerGetUniqueValuesStartingWith,
TypeaheadParams,
VuuTable,
} from "@finos/vuu-protocol-types";
import { useCallback } from "react";
import { makeRpcCall } from "@finos/vuu-data-remote";
import { TableSchemaTable } from "@finos/vuu-data-types";

export type SuggestionFetcher = (params: TypeaheadParams) => Promise<string[]>;

Expand All @@ -16,7 +16,7 @@ const TYPEAHEAD_MESSAGE_CONSTANTS = {
};

export const getTypeaheadParams = (
table: VuuTable,
table: TableSchemaTable,
column: string,
text = "",
selectedValues: string[] = []
Expand All @@ -27,9 +27,6 @@ export const getTypeaheadParams = (
return [table, column];
};

// const containSpace = (text: string) => text.indexOf(" ") !== -1;
// const replaceSpace = (text: string) => text.replace(/\s/g, SPECIAL_SPACE);

export const useTypeaheadSuggestions = () =>
useCallback<SuggestionFetcher>(async (params: TypeaheadParams) => {
const rpcMessage =
Expand Down
19 changes: 17 additions & 2 deletions vuu-ui/packages/vuu-data-remote/src/server-proxy/viewport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,9 @@ export class Viewport {
range,
sort,
groupBy,
table,
}: ServerToClientCreateViewPortSuccess,
tableSchema: TableSchema
baseTableSchema: TableSchema
) {
this.serverViewportId = viewPortId;
this.status = "subscribed";
Expand All @@ -317,7 +318,21 @@ export class Viewport {
this.groupBy = groupBy;
this.isTree = groupBy && groupBy.length > 0;
this.dataWindow.setRange(range.from, range.to);
// TODO retrieve the filterStruct

// If the table we have subscribed to is a session table, the tablename will
// be a unique name for this instance. It must be used in subsequent operations
// that require table, e.g RPC calls
const tableSchema =
table === baseTableSchema.table.table
? baseTableSchema
: {
...baseTableSchema,
table: {
...baseTableSchema.table,
session: table,
},
};

return {
aggregations,
type: "subscribed",
Expand Down
10 changes: 9 additions & 1 deletion vuu-ui/packages/vuu-data-types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,18 @@ export type SchemaColumn = {
serverDataType: VuuColumnDataType;
};

/**
* session will be present for session tables only, in which case the table
* name represents the 'archetype' table name.
*/
export type TableSchemaTable = VuuTable & {
session?: string;
};

export type TableSchema = {
columns: SchemaColumn[];
key: string;
table: VuuTable;
table: TableSchemaTable;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion vuu-ui/packages/vuu-filters/src/filter-bar/FilterBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface FilterBarProps extends HTMLAttributes<HTMLDivElement> {
onFilterRenamed?: (filter: Filter, name: string) => void;
onFilterStateChanged?: (state: FilterState) => void;
showMenu?: boolean;
tableSchema: TableSchema;
tableSchema?: TableSchema;
}

const classBase = "vuuFilterBar";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface FilterClauseEditorProps
onDropdownClose?: (closeReason: CloseReason) => void;
onDropdownOpen?: () => void;
suggestionProvider?: () => SuggestionFetcher;
tableSchema: TableSchema;
tableSchema?: TableSchema;
}

const classBase = "vuuFilterClause";
Expand Down Expand Up @@ -102,7 +102,7 @@ export const FilterClauseEditor = ({
operator={operator}
selectedColumn={selectedColumn}
suggestionProvider={suggestionProvider}
table={tableSchema.table}
table={tableSchema?.table}
value={value}
/>
{value !== undefined ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
useMemo,
useState,
} from "react";
import { TypeaheadParams } from "@finos/vuu-protocol-types";
import { TypeaheadParams, VuuTable } from "@finos/vuu-protocol-types";
import {
SuggestionFetcher,
useTypeaheadSuggestions,
Expand All @@ -22,9 +22,19 @@ import {
} from "@finos/vuu-ui-controls";
import { ExpandoCombobox } from "./ExpandoCombobox";
import { FilterClauseValueEditor } from "./filterClauseTypes";
import { TableSchemaTable } from "@finos/vuu-data-types";

const selectionKeys = ["Enter", " "];

const getVuuTable = (schemaTable: TableSchemaTable): VuuTable => {
if (schemaTable.session) {
const { module, session } = schemaTable;
return { module, table: session };
} else {
return schemaTable;
}
};

export interface TextInputProps
extends FilterClauseValueEditor,
HTMLAttributes<HTMLDivElement> {
Expand Down Expand Up @@ -79,10 +89,11 @@ export const FilterClauseTextValueEditor = forwardRef(function TextInput(

useEffect(() => {
if (table) {
const vuuTable = getVuuTable(table);
const params: TypeaheadParams =
valueInputValue && !isMultiValue
? [table, column.name, valueInputValue]
: [table, column.name];
? [vuuTable, column.name, valueInputValue]
: [vuuTable, column.name];
getSuggestions(params)
.then((suggestions) => {
if (suggestions.length === 0 && valueInputValue) {
Expand Down Expand Up @@ -200,7 +211,6 @@ export const FilterClauseTextValueEditor = forwardRef(function TextInput(
);
}
}, [
InputPropsProp,
InputProps,
operator,
className,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type InputElementProps = Pick<
| "value"
> &
Pick<FilterClauseEditorProps, "suggestionProvider"> & {
table: TableSchema["table"];
table?: TableSchema["table"];
};

export const FilterClauseValueEditor: React.FC<InputElementProps> = ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { VuuTable } from "@finos/vuu-protocol-types";
import { ColumnDescriptor } from "@finos/vuu-table-types";
import { CloseReason } from "@finos/vuu-ui-controls";
import { InputProps } from "@salt-ds/core";
import { TableSchemaTable } from "@finos/vuu-data-types";

export interface FilterClauseValueEditor<T = string> {
InputProps?: InputProps;
column: ColumnDescriptor;
onDeselect?: () => void;
onInputComplete: (value: T | T[]) => void;
onOpenChange?: (open: boolean, closeReason: CloseReason) => void;
table?: VuuTable;
table?: TableSchemaTable;
}
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export const useFilterTable = ({ tableSchema }: FilterTableFeatureProps) => {
onFilterDeleted: handleFilterDeleted,
onFilterRenamed: handleFilterRenamed,
onFilterStateChanged: handleFilterStateChanged,
tableSchema,
tableSchema: dataSource.tableSchema,
};

const tableProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const useSessionDataSource = ({
return ds;
}, [
dataSourceConfigFromState,
dataSourceSessionKey,
handleDataSourceConfigChange,
id,
loadSession,
Expand Down
Loading