react-select-table
Version:
React table component with selectable items
121 lines (120 loc) • 5.35 kB
TypeScript
/**
* @namespace StoreTypes
*/
/**
* The key of the row as returned from {@link https://lodash.com/docs/4.17.15#keyBy|_.keyBy}
* with iteratee {@link Options.keyBy}
*
* @typedef {string|number} StoreTypes.RowKey
*/
/**
* @typedef {object} StoreTypes.RowMetadata
* @property {boolean} visible The visibility of the item, based on the filter
*/
/**
* @typedef {object} StoreTypes.State
* @property {import('../utils/setUtils').SetTypes.Set<StoreTypes.RowKey>} selected A set containing all selected row keys
* @property {*} filter The item filter
* @property {Object<string, boolean>} sortAscending An object with property paths as keys, and true for ascending order or false for descending, as values
* @property {boolean} isLoading When true, a loading indicator is displayed
* @property {number} pageSize The maximum number of items in a page, 0 if pagination is disabled
* @property {*} error When truthy, it is passed as a child to {@link TableProps.errorComponent} which in turn is rendered instead of the table rows
* @property {import('../utils/trieUtils').TrieTypes.Node<StoreTypes.RowKey>} searchIndex The root node of a trie made from the {@link Options.searchProperty} value of each row after being parsed by {@link Options.searchPhraseParser}
* @property {string} searchPhrase The search phrase after being parsed by {@link Options.searchPhraseParser}
* @property {StoreTypes.RowKey[]} matches The keys of the rows that matched the search phrase, sorted in the order they appear
* @property {number} matchIndex The currently highlighted match index
* @property {import('../utils/dlMapUtils').DlMapTypes.Map<StoreTypes.RowKey, object, StoreTypes.RowMetadata>} items A list of all items, sorted based on {@link sortAscending}
* @property {StoreTypes.RowKey[]} rowKeys The keys of the visible items, sorted and paginated
* @property {number} visibleItemCount The total number of visible items on all pages
* @property {number} activeIndex The index of the active row inside {@link rowKeys}
* @property {number} pivotIndex The index of the pivot row inside {@link rowKeys}
*/
/**
* @typedef {import('../models/Actions').ActionsTypes.ActionsClass} ActionsClass
*/
/**
* Returns a table reducer
*
* @param {string} namespace A unique identifier for the table reducer
* @param {Partial<import('../utils/optionsUtils').Options>} options The reducer options
* @returns {import('redux').Reducer<StoreTypes.State, ActionsClass>} The table reducer
*/
export default function createTable(namespace: string, options?: Partial<import('../utils/optionsUtils').Options>): import("redux").Reducer<StoreTypes.State, import("../models/Actions").default>;
export namespace StoreTypes {
/**
* The key of the row as returned from {@link https://lodash.com/docs/4.17.15#keyBy|_.keyBy}
* with iteratee {@link Options.keyBy }
*/
type RowKey = string | number;
type RowMetadata = {
/**
* The visibility of the item, based on the filter
*/
visible: boolean;
};
type State = {
/**
* A set containing all selected row keys
*/
selected: import('../utils/setUtils').SetTypes.Set<StoreTypes.RowKey>;
/**
* The item filter
*/
filter: any;
/**
* An object with property paths as keys, and true for ascending order or false for descending, as values
*/
sortAscending: {
[x: string]: boolean;
};
/**
* When true, a loading indicator is displayed
*/
isLoading: boolean;
/**
* The maximum number of items in a page, 0 if pagination is disabled
*/
pageSize: number;
/**
* When truthy, it is passed as a child to {@link TableProps.errorComponent } which in turn is rendered instead of the table rows
*/
error: any;
/**
* The root node of a trie made from the {@link Options.searchProperty } value of each row after being parsed by {@link Options.searchPhraseParser }
*/
searchIndex: import('../utils/trieUtils').TrieTypes.Node<StoreTypes.RowKey>;
/**
* The search phrase after being parsed by {@link Options.searchPhraseParser }
*/
searchPhrase: string;
/**
* The keys of the rows that matched the search phrase, sorted in the order they appear
*/
matches: StoreTypes.RowKey[];
/**
* The currently highlighted match index
*/
matchIndex: number;
/**
* A list of all items, sorted based on {@link sortAscending }
*/
items: import('../utils/dlMapUtils').DlMapTypes.Map<StoreTypes.RowKey, object, StoreTypes.RowMetadata>;
/**
* The keys of the visible items, sorted and paginated
*/
rowKeys: StoreTypes.RowKey[];
/**
* The total number of visible items on all pages
*/
visibleItemCount: number;
/**
* The index of the active row inside {@link rowKeys }
*/
activeIndex: number;
/**
* The index of the pivot row inside {@link rowKeys }
*/
pivotIndex: number;
};
}
export type ActionsClass = import('../models/Actions').ActionsTypes.ActionsClass;