UNPKG

@knowmax/genericlist-core

Version:

Knowmax Generic list with basic CRUD support without any user interface implementation.

109 lines (108 loc) 5 kB
import type { FetchOptions, IOrder, IFilter } from "../types"; import { GenericListSettings } from "./GenericListSettings"; export interface IGenericListConfiguration { /** Optional unique id for this list. */ id?: string; /** Endpoint to use for loading list of data. */ endpoint: string; /** Endpoint to use for loading a single item. */ endpointGetSingle?: string; /** Set in case this list required configuration for endpoint postfix. */ requiredEndpointPostfix?: boolean; /** List with order options. */ orderList?: IOrder[]; /** List with filter options. */ filterList?: IFilter[]; /** Page number for pagination. */ page?: number; /** Page size for pagination. */ pageSize?: number; } /** Generic implementation to support lists from different endpoints supporting Knowmax LinqUtility ListRequest. * Can be inherited or used in combination with GenericListHook, @see useList. */ export declare class GenericList<T = unknown> { configuration: IGenericListConfiguration; private _settingsUpdated; private _loadOptions?; constructor(configuration: IGenericListConfiguration); /** Set when this generic list is ready for use. Essentially this means settings configuration is ready. */ get ready(): boolean; /** Unique id representing this list. Will be provided to methods from settings when called to determine active list. Optional due to backward compatibility. */ id: string | undefined; setId(value?: string): void; /** Settings for all generic lists. */ settings: GenericListSettings; /** Usually set from value provided GenericListSettinsProvider. */ setSettings(value: GenericListSettings): void; /** Set while loading a single item */ loadingSingle: boolean; setLoadingSingle(value: boolean): void; /** Set after initially loading data. */ loaded: boolean; setLoaded(value: boolean): void; /** Set while loading data. */ loading: boolean; setLoading(value: boolean): void; error?: Error | string; setError(value?: Error | string): void; /** Available options for order. */ orderList: IOrder[]; setOrderList(value: IOrder[]): void; /** Selected order expression. Set to IOrder from orderList or string order expression. */ order?: IOrder | string; setOrder(value?: IOrder | string): void; /** Server expression based on current order setting. */ get orderExpression(): string; deleted: boolean; setDeleted(value: boolean): void; /** List with all filter definitions available for this list. */ filterList: IFilter[]; setFilterList(value: IFilter[]): void; /** Filter to use while loading data. */ filter?: string; setFilter(value?: string): void; /** Query to be used while loading data. */ search?: string; setSearch(value?: string): void; /** Current selected page. 1-based. */ page: number; setPage(value: number): void; /** Number of items per page. */ pageSize: number; setPageSize(value: number): void; /** List containing actual page of data. */ list: T[]; setList(value: T[]): void; /** Total number of items available. */ totalCount: number; setTotalCount(value: number): void; /** Will be used as post fix for currently configured endpoint. */ endpointPostFix?: string; /** Set to postfix for current endpoint. For example the value "abc" will result in "/abc" postfix after currently configured endpoint. */ setEndpointPostFix(value?: string): void; /** Dynamic hash representing current state of component. Use as dependecy to trigger effects */ get hash(): string; /** Hash at the moment of last update of list with server data. */ currentHash?: string; setCurrentHash(value: string): void; /** Set when hash was updated. Rather use hash as dependecy to trigger effects. */ get hashUpdated(): boolean; /** Set to selected item for specific purpose. */ selectedItem?: T; /** Tag to identify purpose of selected item.. */ selectedItemTag?: string; /** Selects item for specific purpose (not edit or delete). */ setSelectedItem(value?: T, tag?: string): void; /** Load current page of items. * @param reload If true, will reload current page of items using original options used on inital load. * @param options Options to use while loading data. If not provided, will use options used on inital load only in case of reload. */ load(reload?: boolean, options?: FetchOptions): Promise<void>; /** Load single item identified by id. * @param id Id of item to load. * @param options Options to use while loading data. * @param endpoint Endpoint to use while loading data. If not provided, will use endpointGetSingle or endpoint from configuration. */ loadSingle(id: string | number, options?: FetchOptions, endpoint?: string): Promise<T | undefined>; private checkSettings; }