import { type TypeValue as FilterTypeValue, type OperatorValue as FilterOperatorValue } from '@deephaven/filters'; import type { dh as DhType } from '@deephaven/jsapi-types'; import { type CancelablePromise } from '@deephaven/utils'; import { type ColumnName } from './Formatter'; import { type FilterConditionFactory } from './FilterUtils'; type Values = T[keyof T]; export type DataType = Values; export type SortDirection = Values; export type ReverseType = Values; export type AdvancedFilterItemType = { selectedType: FilterTypeValue; value: string; }; export interface FilterItem { selectedType: FilterTypeValue; value: string; } export interface SortDescriptor { column: { name: ColumnName; type: string; }; isAbs: boolean; direction: string; } export type AdvancedFilterOptions = { filterItems: FilterItem[]; filterOperators: FilterOperatorValue[]; invertSelection: boolean; selectedValues: unknown[]; }; export type RowDataMapValue = { type: string; text: string; value: unknown; isExpandable: boolean; isGrouped: boolean; visibleIndex: number; }; export type RowDataMap = Record; export declare function isSortDirection(value: string | null): value is SortDirection; /** Utility class to provide some functions for working with tables */ export declare class TableUtils { static dataType: { readonly BOOLEAN: "boolean"; readonly CHAR: "char"; readonly DATETIME: "datetime"; readonly DECIMAL: "decimal"; readonly INT: "int"; readonly STRING: "string"; readonly UNKNOWN: "unknown"; }; static sortDirection: { readonly ascending: "ASC"; readonly descending: "DESC"; readonly reverse: "REVERSE"; readonly none: null; }; static APPLY_TABLE_CHANGE_TIMEOUT_MS: number; static REVERSE_TYPE: Readonly<{ readonly NONE: "none"; readonly PRE_SORT: "pre-sort"; readonly POST_SORT: "post-sort"; }>; static NUMBER_REGEX: RegExp; /** * Copy a given table and apply filters. * @param maybeTable Table to copy and apply filters to * @param filterFactories Filter condition factories to apply * @returns A derived, filtered table */ static copyTableAndApplyFilters(maybeTable: T, ...filterFactories: FilterConditionFactory[]): Promise; /** * Executes a callback on a given table and returns a Promise that will resolve * the next time a particular event type fires on the table. * @param exec Callback function to execute. * @param table Table that gets passed to the `exec` function and that is * subscribed to for a given `eventType`. * @param eventType The event type to listen for. * @param timeout If the event doesn't fire within the timeout, the returned * Promise will be rejected. * @returns a Promise to the original table that resolves on next `eventType` * event */ static executeAndWaitForEvent: (exec: (maybeTable: T | null | undefined) => void, table: T | null | undefined, eventType: string, timeout?: number) => Promise; static getSortIndex(sort: readonly SortDescriptor[], columnName: ColumnName): number | null; /** * @param tableSort The sorts from the table to get the sort from * @param columnName The name of the column to get the sort for * @returns The sort for the column, or null if it's not sorted */ static getSortForColumn(tableSort: readonly SortDescriptor[], columnName: ColumnName): SortDescriptor | null; static getFilterText(filter?: DhType.FilterCondition | null): string | null; /** Return the valid filter types for the column */ static getFilterTypes(columnType: string): FilterTypeValue[]; static getNextSort(columns: readonly DhType.Column[], sorts: readonly SortDescriptor[], columnIndex: number): SortDescriptor | null; static makeColumnSort(columns: readonly DhType.Column[], columnIndex: number, direction: SortDirection, isAbs: boolean): SortDescriptor | null; /** * Toggles the sort for the specified column * @param sorts The current sorts from IrisGrid.state * @param columns The columns to apply the sort to * @param columnIndex The column index to apply the sort to * @param addToExisting Add this sort to the existing sort */ static toggleSortForColumn(sorts: readonly SortDescriptor[], columns: readonly DhType.Column[], columnIndex: number, addToExisting?: boolean): readonly SortDescriptor[]; static sortColumn(sorts: readonly SortDescriptor[], columns: readonly DhType.Column[], modelColumn: number, direction: SortDirection, isAbs: boolean, addToExisting: boolean): readonly SortDescriptor[]; /** * Sets the sort for the given column *and* removes any reverses * @param tableSort The current sorts from IrisGrid.state * @param columnName The column name to apply the sort to * @param sort The sort object to add * @param addToExisting Add this sort to the existing sort * @returns Returns the modified array of sorts - removing reverses */ static setSortForColumn(tableSort: readonly SortDescriptor[], columnName: ColumnName, sort: SortDescriptor | null, addToExisting?: boolean): readonly SortDescriptor[]; static getNormalizedType(columnType?: string | null): DataType; static isLongType(columnType: string): boolean; static isDateType(columnType: string): boolean; static isNumberType(columnType: string): boolean; static isIntegerType(columnType: string): boolean; static isDecimalType(columnType: string): boolean; static isBigDecimalType(columnType: string): boolean; static isBigIntegerType(columnType: string): boolean; static isBooleanType(columnType: string): boolean; static isCharType(columnType: string): boolean; static isStringType(columnType: string): boolean; static isTextType(columnType: string): boolean; /** * Get base column type * @param columnType Column type * @returns Element type for array columns, original type for non-array columns */ static getBaseType(columnType: string): string; /** * Check if the column types are compatible * @param type1 Column type to check * @param type2 Column type to check * @returns True, if types are compatible */ static isCompatibleType(type1?: string | null, type2?: string | null): boolean; /** * Adds quotes to a value if they're not already added * @param value Value to add quotes around */ static quoteValue(value: string): string; static isRangeOperation(operation: string): boolean; /** * @param filter The column filter to apply the range operation to * @param operation The range operation to run * @param value The value to use for the operation * @returns The condition with the specified operation */ static makeRangeFilterWithOperation(filter: DhType.FilterValue, operation: string, value: DhType.FilterValue): DhType.FilterCondition | null; /** * Wraps a table promise in a cancelable promise that will close the table if the promise is cancelled. * Use in a component that loads a table, and call cancel when unmounting. * @param table The table promise to wrap */ static makeCancelableTablePromise(table: Promise | DhType.Table): CancelablePromise; /** * Make a cancelable promise for a one-shot table event with a timeout. * @param table Table to listen for events on * @param eventName Event to listen for * @param timeout Event timeout in milliseconds, defaults to 0 * @param matcher Optional function to determine if the promise can be resolved or stays pending * @deprecated Use `makeCancelableEventPromise` instead. * @returns Resolves with the event data */ static makeCancelableTableEventPromise(table: DhType.Table | DhType.TreeTable, eventName: string, timeout?: number, matcher?: ((event: DhType.Event) => boolean) | null): CancelablePromise>; /** * Make a cancelable promise for a one-shot event with a timeout. * @param emitter The object emitting the event * @param eventName Event to listen for * @param options Optional options for listening * @param options.timeout Event timeout in milliseconds, defaults to 0 * @param options.matcher Optional function to determine if the promise can be resolved or stays pending * @returns Resolves with the event data */ static makeCancelableEventPromise(emitter: DhType.HasEventHandling, eventName: string, options?: { timeout?: number; matcher?: (event: DhType.Event) => boolean; }): CancelablePromise>; static removeCommas(value: string): string; static makeBooleanValue(text: string, allowEmpty?: boolean): boolean | null; static makeNumberValue(text: string): number | null; static getFilterOperatorString(operation: FilterTypeValue): string; static isPartitionedTable(table: unknown): table is DhType.PartitionedTable; static isTreeTable(table: unknown): table is DhType.TreeTable; /** * Copies the provided array, sorts by column name case insensitive, and returns the sorted array. * @param columns The columns to sort * @param isAscending Whether to sort ascending */ static sortColumns(columns: readonly DhType.Column[], isAscending?: boolean): DhType.Column[]; dh: typeof DhType; constructor(dh: typeof DhType); /** * Create a table containing a distinct list of values for given column name and * applies the given sort direction. * @param table Source table to derive table from * @param columnName Column to dermine distinct values * @param sortDirection Direction to sort * @param filterConditionFactories Optional filters to apply. Note that these * will be applied before the `selectCall` in case we need to base the filtering * on columns other than the distinct value column */ createDistinctSortedColumnTable(table: DhType.Table | null | undefined, columnName: string, sortDirection: 'asc' | 'desc', ...filterConditionFactories: FilterConditionFactory[]): Promise; /** * Check if any columns contain a given value. * @param table Table to search for values * @param columnNames Column names to search * @param value Value to search for * @param isCaseSensitive Whether the value check is case sensitive */ doesColumnValueExist(table: DhType.Table | null | undefined, columnNames: string | string[], value: string, isCaseSensitive: boolean): Promise; /** * Get the `dh.ValueType` corresponding to the given `dh.Column.type` value. * @param columnType The column type to get the value type for * @returns The `dh.ValueType` corresponding to the column type */ getValueType(columnType?: string): string; /** * Create filter with the provided column and text. Handles multiple filters joined with && or || * @param column The column to set the filter on * @param text The text string to create the filter from * @param timeZone The time zone to make this value in if it is a date type. E.g. America/New_York * @returns Returns the created filter, null if text could not be parsed */ makeQuickFilter(column: DhType.Column, text: string, timeZone?: string): DhType.FilterCondition | null; /** * Create filter with the provided column and text of one component (no multiple conditions) * @param column The column to set the filter on * @param text The text string to create the filter from * @param timeZone The time zone to make this filter in if it is a date type. E.g. America/New_York * @returns Returns the created filter, null if text could not be parsed */ makeQuickFilterFromComponent(column: DhType.Column, text: string, timeZone?: string): DhType.FilterCondition | null; makeQuickNumberFilter(column: DhType.Column, text: string): DhType.FilterCondition | null; /** * Given a text string from a table, escape quick filter operators in string with \ * ex. =test returns \=test, null returns \null * @param string quickfilter string to escape * @returns escaped string */ static escapeQuickTextFilter(quickFilterText: string | null): string | null; /** * Given an escaped quick filter, unescape the operators for giving it to the js api * ex. \=test returns =test, \null returns null * @param string quickfilter string to escape * @returns escaped string */ static unescapeQuickTextFilter(quickFilterText: string): string; makeQuickTextFilter(column: DhType.Column, text: string): DhType.FilterCondition | null; makeQuickBooleanFilter(column: DhType.Column, text: string | number): DhType.FilterCondition | null; /** * Builds a date filter parsed from the text string which may or may not include an operator. * @param column The column to build the filter from, with or without a leading operator. * @param text The date string text to parse. * @param timeZone The time zone to make this filter in if it is a date type. E.g. America/New_York */ makeQuickDateFilter(column: DhType.Column, text: string, timeZone: string): DhType.FilterCondition; /** * Builds a date filter parsed from the text string with the provided filter. * @param column The column to build the filter from. * @param text The date string text to parse, without an operator. * @param operation The filter operation to use. * @param timeZone The time zone to make this filter with. E.g. America/New_York */ makeQuickDateFilterWithOperation(column: DhType.Column, text: string, operation: FilterTypeValue, timeZone: string): DhType.FilterCondition; makeQuickCharFilter(column: DhType.Column, text: string): DhType.FilterCondition | null; makeAdvancedFilter(column: DhType.Column, options: AdvancedFilterOptions, timeZone: string): DhType.FilterCondition | null; makeAdvancedValueFilter(column: DhType.Column, operation: FilterTypeValue, value: string, timeZone: string): DhType.FilterCondition | null; /** * Create a filter condition that can search a column by a given `searchText` * value. * @param column The column to search * @param searchText The text to search for * @param timeZone The time zone to make this filter in if it is a date type. E.g. America/New_York * @returns The filter condition that can be applied to the column */ makeSearchTextFilter(column: DhType.Column, searchText: string, timeZone: string): DhType.FilterCondition; /** * Apply a filter to a table that won't match anything. * @table The table to apply the filter to * @columnName The name of the column to apploy the filter to * @param timeout Timeout before cancelling the promise that waits for the next * dh.Table.EVENT_FILTERCHANGED event * @returns a Promise to the Table that resolves after the next * dh.Table.EVENT_FILTERCHANGED event */ applyNeverFilter(table: T | null | undefined, columnName: string, timeout?: number): Promise; /** * Apply custom columns to a given table. Return a Promise that resolves with * the table once the dh.Table.EVENT_CUSTOMCOLUMNSCHANGED event has fired. * @param table The table to apply custom columns to. * @param columns The list of column expressions or definitions to apply. * @returns A Promise that will be resolved with the given table after the * columns are applied. */ applyCustomColumns(table: DhType.Table | null | undefined, columns: (string | DhType.CustomColumn)[], timeout?: number): Promise; /** * Apply filters to a given table. * @param table Table to apply filters to * @param filters Filters to apply * @param timeout Timeout before cancelling the promise that waits for the next * dh.Table.EVENT_FILTERCHANGED event * @returns a Promise to the Table that resolves after the next * dh.Table.EVENT_FILTERCHANGED event */ applyFilter(table: T | null | undefined, filters: readonly DhType.FilterCondition[], timeout?: number): Promise; /** * Apply sorts to a given Table. * @param table The table to apply sorts to * @param sorts The sorts to apply * @param timeout Timeout before cancelling the promise that waits for the next * dh.Table.EVENT_SORTCHANGED event * @returns a Promise to the Table that resolves after the next * dh.Table.EVENT_SORTCHANGED event */ applySort(table: T | null | undefined, sorts: readonly DhType.Sort[], timeout?: number): Promise; /** * Create a filter condition that results in zero results for a given column * @param column */ makeNeverFilter(column: DhType.Column): DhType.FilterCondition; /** * @param columnType The column type to make the filter value from. * @param value The value to make the filter value from. * @returns The FilterValue item for this column/value combination */ makeFilterValue(columnType: string, value: string): DhType.FilterValue; /** * Takes a value and converts it to an `dh.FilterValue` * * @param columnType The column type to make the filter value from. * @param value The value to actually set * @returns The FilterValue item for this column/value combination */ makeFilterRawValue(columnType: string, rawValue: unknown): DhType.FilterValue; /** * Creates an Eq filter for the given column and raw value * @param column The column to set the filter on * @param rawValue The nullable value to filter on * @returns The filter for this column/value combination */ makeNullableEqFilter(column: DhType.Column, rawValue: unknown): DhType.FilterCondition; /** * Converts a string value to a value appropriate for the column * @param columnType The column type to make the value for * @param text The string value to make a type for * @param timeZone The time zone to make this value in if it is a date type. E.g. America/New_York */ makeValue(columnType: string, text: string, timeZone: string): string | number | boolean | DhType.LongWrapper | null; /** * Create a filter using the selected items * Has a flag for invertSelection as we start from a "Select All" state and a user just deselects items. * Since there may be millions of distinct items, it's easier to build an inverse filter. * @param column The column to set the filter on * @param selectedValues The values that are selected * @param invertSelection Invert the selection (eg. All items are selected, then you deselect items) * @returns Returns a `in` or `notIn` FilterCondition as necessary, or null if no filtering should be applied (everything selected) */ makeSelectValueFilter(column: DhType.Column, selectedValues: unknown[], invertSelection: TInvert): TInvert extends true ? DhType.FilterCondition | null : DhType.FilterCondition; } export default TableUtils; //# sourceMappingURL=TableUtils.d.ts.map