infinity-forge
Version:
160 lines (159 loc) • 4.64 kB
TypeScript
import React from 'react';
import { IconsNames, DynamicFormHandlerProps, 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 | (string & {});
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;
enabledShallowPagination?: boolean;
enableEnterKeySubmitForm?: boolean;
autoSubmitFields?: string[];
exports?: ExportTable[];
customFilterActive?: ({ filter, filterInUrl }: {
filter: any;
filterInUrl: any;
}) => any;
modifyInitialDataCustomFilters?: (data: any) => any;
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?: any;
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;
};
enabled?: (tableitem: T) => boolean;
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?: {
enabled?: (tableitem: T) => boolean;
modal?: Partial<ModalProps>;
confirmDelete?: boolean;
onDelete?: TableActionDelete<T>;
};
detail?: (table: {
[key in keyof T]: string;
}) => string;
tablePermissions?: {
create?: {
roles?: string[];
claims?: string[];
};
edit?: {
roles?: string[];
claims?: string[];
};
delete?: {
roles?: string[];
claims?: string[];
};
};
};
type ChildrenTable<T = any> = {
childrenKey: keyof T | (string & {});
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> {
configs: IConfigurationsTable<T>;
columnsConfiguration: ColumnsConfiguration<T>;
}
export type { Column, QueryTable, FNComponent, ActionsTable, IParamsTable, ChildrenTable, IUseTableProps, TableActionEdit, TableActionCreate, TableActionDelete, IConfigurationsTable, ColumnsConfiguration, };