infinity-forge
Version:
137 lines (136 loc) • 3.98 kB
TypeScript
import React from 'react';
import { IconsNames, DynamicFormHandlerProps, QueryOptions, PaginationModel, useQueryProps, ModalProps } from '../../../../ui/index.js';
import { Filter } from './components/table/filters/index.js';
import { ExportTable } from './components/table/interfaces.js';
interface Column<T = any> {
id: keyof T;
label: string;
width?: number;
hasAsc?: boolean;
enabled?: boolean;
ComponentTHead?: {
Element: (props: {
index: number;
tableItems: IConfigurationsTable<T>['tableData'];
}) => React.ReactNode;
props?: {
[key: string]: any;
};
};
Component?: {
Element: (props: {
[key in keyof T]?: any;
} & {
index: number;
tableItems: IConfigurationsTable<T>['tableData'];
}) => React.ReactNode;
props?: {
[key: string]: any;
};
};
}
interface IParamsTable {
page?: number;
}
interface IConfigurationsTable<T> {
tableData?: T[];
tableKeyItem?: keyof T;
search?: {
enabled?: boolean;
searchRouteKey?: string;
};
isLoading?: boolean;
errorMessage: string;
customFilters?: Filter<T>[];
disableRoutingUpdateFilters?: boolean;
disableGetFilter?: boolean;
disablePagination?: boolean;
enableSearchInSelf?: boolean;
pagination?: PaginationModel;
disableOrdenationTable?: boolean;
exports?: ExportTable[];
mobile?: {
mediaQuery?: 1024 | 768 | 420;
Component: (props?: T) => React.ReactNode;
};
}
type QueryTable<M = any> = {
user?: any;
container?: any;
Types?: any;
queryKey: {
remoteName?: M;
customKey?: string;
};
requireUser?: boolean;
queryKeyParams?: string;
dynamicFiltersFromApi?: boolean;
debugMode?: boolean;
options?: QueryOptions;
customRemote?: (params: any) => any;
};
type TableActionCreate<T = any> = {
link?: {
href: string;
};
modal?: Partial<ModalProps>;
text?: string;
icon?: IconsNames;
Custom?: (props: any) => React.ReactNode;
} & DynamicFormHandlerProps<T>;
type TableActionEdit<T = any> = {
link?: {
href: (table: {
[key in keyof T]: string;
}) => string;
text: string;
icon?: IconsNames;
};
modal?: Partial<ModalProps>;
} & DynamicFormHandlerProps<T>;
type TableActionDelete<T> = (table: {
[key in keyof T]: T[key];
}) => void;
type FNComponent = (props: any) => React.ReactNode;
type ActionsTable<T = any> = {
edit?: TableActionEdit<T>;
create?: TableActionCreate<T>;
custom?: FNComponent[];
modalStyles?: React.CSSProperties;
delete?: {
modal?: Partial<ModalProps>;
confirmDelete?: boolean;
onDelete?: TableActionDelete<T>;
};
detail?: (table: {
[key in keyof T]: string;
}) => string;
};
type ChildrenTable<T = any> = {
childrenKey: keyof T;
columns: Column<any>[];
omitEmptyList?: boolean;
getChildrenData?: ({ tableData, tableIsLoading, }: {
tableData: IConfigurationsTable<T>['tableData'];
tableIsLoading?: boolean;
}) => {
querykey?: ({ tableItem }: {
tableItem: T;
}) => string;
queryFn?: ({ tableItem }: {
tableItem: T;
}) => Promise<any>;
} & Omit<useQueryProps<T>, 'queryKey' | 'queryFn'>;
childrens?: ChildrenTable<T>;
};
type ColumnsConfiguration<T = any> = {
columns: Column<T>[];
childrens?: ChildrenTable<T>;
actions?: ActionsTable<T>;
};
interface IUseTableProps<T = any, M = any> {
query?: QueryTable<M>;
configs: IConfigurationsTable<T>;
columnsConfiguration: ColumnsConfiguration<T>;
}
export type { Column, QueryTable, FNComponent, ActionsTable, IParamsTable, ChildrenTable, IUseTableProps, TableActionEdit, TableActionCreate, TableActionDelete, IConfigurationsTable, ColumnsConfiguration, };