import { convertId } from 'fastapi-rtk/utils'; import { EntryRow } from 'fastapi-rtk/contexts'; import { InfiniteData, QueryKey, UseInfiniteQueryOptions, UseInfiniteQueryResult, UseQueryOptions, UseQueryResult } from '../../../../.external/lib/@tanstack/react-query'; import { RefObject } from 'react'; import { Adapters } from '../../adapters/types'; import { createItem } from '../../fetchers/createItem'; import { deleteItem } from '../../fetchers/deleteItem'; import { downloadItems } from '../../fetchers/downloadItems'; import { formCreateItem } from '../../fetchers/formCreateItem'; import { formUpdateItem } from '../../fetchers/formUpdateItem'; import { getInfo } from '../../fetchers/getInfo'; import { getItem } from '../../fetchers/getItem'; import { getItems } from '../../fetchers/getItems'; import { updateItem } from '../../fetchers/updateItem'; import { uploadItems } from '../../fetchers/uploadItems'; import { postBulk } from '../../fetchers/postBulkAction'; import { BulkActionResponse } from '../../fetchers/bulkActions.types'; import { DataPage, PrimaryKey, StreamingPage, ValidationError } from 'fastapi-rtk/api-types'; import { CoreConvertedInfo, QueryParams } from '../utils/types'; export type { DataPage, StreamingPage }; /** An entry identifier as accepted by the action functions before conversion. */ export type EntryId = Parameters[0]; /** The converted `/_info` data as held by the info query, tagged with the resource path. */ export type InfoQueryData = CoreConvertedInfo & { path: string; }; /** The set of API functions the provider hooks dispatch through. */ export interface ApiFunctions { getItem: typeof getItem; getItems: typeof getItems; createItem: typeof createItem; updateItem: typeof updateItem; deleteItem: typeof deleteItem; downloadItems: typeof downloadItems; uploadItems: typeof uploadItems; getInfo: typeof getInfo; formCreateItem: typeof formCreateItem; formUpdateItem: typeof formUpdateItem; } /** The set of bulk-action functions the bulk provider dispatches through. */ export interface BulkFunctions { postBulk: typeof postBulk; } /** A relation reference seeded into the query filters by the provider. */ export interface RelationParam { foreign_key?: string; type?: string; id?: PrimaryKey | null; id_?: PrimaryKey | null; } /** The arguments accepted by `useApiActions`. */ export interface UseApiActionsParams { api: ApiFunctions; adapters: Adapters; path: string; pathRef: RefObject; infoRef: RefObject; queryParamsRef: RefObject; currentLanguage: string; } /** The options accepted by the provider's download action. */ export interface DownloadActionOptions { export_mode?: string; delimiter?: string; quotechar?: string; } /** The options accepted by the provider's upload action. */ export interface UploadActionOptions { delimiter?: string; quotechar?: string; } /** The arguments accepted by `useStreamingData`. */ export interface UseStreamingDataParams { streamingMode: boolean; dataQuery: UseQueryResult; streamingQuery: UseInfiniteQueryResult>; streamingQueryKey: QueryKey; } /** The configuration object accepted by `useProvideApi`. */ export interface UseProvideApiParams { path: string; initialQueryParams?: QueryParams; relation?: RelationParam; fetchInfo?: boolean; clearInfoOnRefetch?: boolean; clearDataOnRefetch?: boolean; refetchInfoBasedOnLang?: boolean; refetchDataBasedOnLang?: boolean; resetQueryParamsOnPathChange?: boolean; infoQueryProps?: Partial>; dataQueryProps?: Partial>; streamingQueryProps?: Partial, QueryKey, number>>; streaming?: boolean; } export interface BulkActions { /** An array of currently selected IDs for bulk actions. */ selectedIds: Array; /** A function to set the selected IDs. */ setSelectedIds: (ids: Array) => void; } export interface BulkActionsContextValue { /** An object containing the selected IDs and a function to set them. */ bulkActions: BulkActions; /** * Dispatches a bulk action; falls back to the currently selected IDs when `data` is omitted. * Resolves to `undefined` when the action throws (the error is surfaced via `error`). */ dispatchBulkActions: (handler: string, data?: Array) => Promise; /** An error object if the bulk action failed. */ error?: { message: string; originalError: Error; }; /** A function to reset the error state. */ resetError: () => void; } export type FormType = 'view' | 'add' | 'edit' | 'delete'; export type FormViewMode = 'normal' | 'fullScreen' | 'overlay'; export interface FormState { errors: ValidationError[]; data: EntryRow | undefined; } export interface FormsContextValue { /** Indicates whether the form is currently opened. */ opened: boolean; /** A function to get the current opened state of the form. */ getOpened: () => boolean; /** A function to set the opened state of the form. */ setOpened: (newOpened: boolean) => void; /** The current view mode of the form. See `VIEW_MODE` from `@fastapi-rtk/constants` for more details. */ view: FormViewMode; /** A function to get the current view mode of the form. */ getView: () => FormViewMode; /** A function to set the view mode of the form. */ setView: (newView: FormViewMode) => void; /** The current state of the form, including errors and data. */ state: FormState; /** A function to get the current state of the form. */ getState: () => FormState; /** A function to set the state of the form. */ setState: (newState: FormState) => void; /** A function to reset the form state to its initial state. */ reset: () => void; /** The current item being edited in the form, if applicable. */ item: TItem | undefined; /** A function to get the current item in the form. */ getItem: () => TItem | undefined; /** A function to set the current item in the form. */ setItem: (newItem: TItem | undefined) => void; }