@gpa-gemstone/common-pages
Version:
Common UI pages for GPA products
52 lines (51 loc) • 2.01 kB
TypeScript
import { AsyncThunk, Slice, ActionReducerMapBuilder, Reducer } from '@reduxjs/toolkit';
import { ReadOnlyControllerFunctions } from '../ControllerFunctions';
import { Application } from '@gpa-gemstone/application-typings';
import { Gemstone } from '../Gemstone';
export interface IError {
Message: string;
Action: 'FETCH' | 'UPDATE' | 'ADD' | 'DELETE';
Time: string;
}
export interface IState<T> {
FetchStatus: Application.Types.Status;
Data: T[];
SortField: keyof T;
Ascending: boolean;
Filter: Gemstone.Types.ISearchFilter<T>[];
PageInfo: Gemstone.Types.IPageInfo;
ParentID: string | number | null;
ActiveID: string[];
Error: (IError | null);
}
export interface IFetchThunkArg<T> {
sortField?: keyof T;
ascending?: boolean;
parentID?: string | number;
filter?: Gemstone.Types.ISearchFilter<T>[];
}
export interface IReadOnlyThunkReturn<T> {
Data: T[];
}
/**
* A generic class providing functionalities related to a slice of data.
*/
export default class ReadOnlyGenericSlice<T> {
protected Name: string;
protected Slice: Slice<any>;
Fetch: AsyncThunk<IReadOnlyThunkReturn<T>, IFetchThunkArg<T>, {}>;
SetStatusToChanged: AsyncThunk<void, void, {}>;
Reducer: Reducer<IState<T>>;
private fetchHandle;
protected controller: ReadOnlyControllerFunctions<T>;
constructor(name: string, defaultSortField: keyof T, ascending: boolean, apiPath: string);
constructor(name: string, defaultSortField: keyof T, ascending: boolean, readonlyController: ReadOnlyControllerFunctions<T>);
protected initializeSlice(defaultSortField: keyof T, ascending?: boolean): void;
protected addExtraReducers(builder: ActionReducerMapBuilder<IState<T>>): void;
Data: (state: any) => T[];
Error: (state: any) => IError | null;
FetchStatus: (state: any) => Application.Types.Status;
SortField: (state: any) => keyof T;
Ascending: (state: any) => boolean;
ParentID: (state: any) => string | number | null;
}