import { AsyncThunk, Slice } from '@reduxjs/toolkit'; import { Application } from '@gpa-gemstone/application-typings'; import { Search } from './SearchBar/SearchBar'; import { WritableDraft } from 'immer/dist/types/types-external'; interface IOptions { /** * Optional function triggered on specific action dependencies. * @param state - The current state of type IState. * @param action - The action triggering the dependency. * @param arg - Additional argument for the dependency. */ ActionDependencies?: (state: IState, action: string, arg: any) => void; /** * Optional function triggered on pending action dependencies. * @param state - The current state of type IState. * @param action - The action triggering the dependency. * @param arg - Additional argument for the dependency. * @param requestID - The ID associated with the request. * */ ActionPendingDependencies?: (state: IState, action: string, arg: any, requestID: string) => void; /** * Optional function triggered on action error dependencies. * @param state - The current state of type IState. * @param action - The action triggering the dependency. * @param arg - Additional argument for the dependency. * @param requestID - The ID associated with the request. */ ActionErrorDependencies?: (state: IState, action: string, arg: any, requestID: string) => void; /** * Optional function triggered on action fulfilled dependencies. * @param state - The current state of type IState. * @param action - The action triggering the dependency. * @param arg - Additional argument for the dependency. * @param requestID - The ID associated with the request. */ ActionFullfilledDependencies?: (state: IState, action: string, arg: any, requestID: string) => void; /** * Array of additional thunks of type IAdditionalThunk. */ AddionalThunks?: IAdditionalThunk[]; } interface IAdditionalThunk { Name: string; Fetch: (state: IState, args: any | void) => null | JQuery.jqXHR; OnSuccess?: (state: WritableDraft>, requestId: string, data: any, args: any | void) => void; OnFailure?: (state: WritableDraft>, requestId: string, args: any | void, error: any) => void; OnPending?: (state: WritableDraft>, requestId: string, args: any | void) => void; } /** * Common properties of an object type U with an ID of type number or string, including error message, verb, and time in string format. */ interface U { ID: number | string; } interface IError { Message: string; Verb: 'POST' | 'DELETE' | 'PATCH' | 'FETCH' | 'SEARCH' | 'PAGE'; Time: string; } /** * Represents the state of the application with generic type T extending U. */ export interface IState { Status: Application.Types.Status; ActiveFetchID: string[]; SearchStatus: Application.Types.Status; ActiveSearchID: string[]; Error: (IError | null); Data: T[]; SortField: keyof T; Ascending: boolean; ParentID: (number | null | string); SearchResults: T[]; Filter: Search.IFilter[]; } /** * Interface representing a state with paging capabilities, extending IState. */ interface IPagedState extends IState { PagedStatus: Application.Types.Status; ActivePagedID: string[]; CurrentPage: number; TotalPages: number; TotalRecords: number; PagedData: T[]; PagedSortField: keyof T; PagedAscending: boolean; PagedFilter: Search.IFilter[]; } /** * A generic class providing functionalities related to a slice of data. */ export default class GenericSlice { Name: string; APIPath: string; Slice: (Slice>); Fetch: (AsyncThunk); SetChanged: (AsyncThunk); DBAction: (AsyncThunk); DBSearch: (AsyncThunk[]; sortField?: keyof T; ascending?: boolean; }, {}>); PagedSearch: (AsyncThunk[]; sortField?: keyof T; ascending?: boolean; page?: number; }, {}>); Sort: (AsyncThunk); AdditionalThunk: { [key: string]: AsyncThunk; }; Reducer: any; private fetchHandle; private searchHandle; private pageHandle; private controller; private actionDependency; private actionFullfilledDependency; private actionPendingDependency; private actionErrorDependency; /** * Creates a new GenericSlice of type T, which can be used to perform basic CRUD operations against * a specified web api. * @typeParam T - Model of Generic Slice * @param {string} name - string defining the name of the slice in the store * @param {string} apiPath - string containing relative path to web api * @param {keyof T} defaultSort - string showing default sort field * @param {boolean} ascending - (optional) default sort direction - defaults to true * @returns a new GenericSlice */ constructor(name: string, apiPath: string, defaultSort: keyof T, ascending?: boolean, options?: IOptions | null); Data: (state: any) => T[]; Error: (state: any) => IError; Datum: (state: any, id: number | string) => T; Status: (state: any) => Application.Types.Status; SortField: (state: any) => keyof T; Ascending: (state: any) => boolean; ParentID: (state: any) => number | string; SearchResults: (state: any) => T[]; SearchStatus: (state: any) => Application.Types.Status; SearchFilters: (state: any) => Search.IFilter[]; PagedResults: (state: any) => T[]; PagedStatus: (state: any) => Application.Types.Status; PagedFilters: (state: any) => Search.IFilter[]; PagedSortField: (state: any) => keyof T; PagedAscending: (state: any) => boolean; CurrentPage: (state: any) => number; TotalPages: (state: any) => number; TotalRecords: (state: any) => number; } export {};