teko-file-history
Version:
File history component for Teko system
313 lines (307 loc) • 8.21 kB
TypeScript
import React, { ReactNode } from 'react';
import { TableProps } from 'antd/es/table';
import { UploadProps, UploadFile } from 'antd/es/upload/interface';
type UploadFilePayload = {
url: string;
clientId: number;
fileName?: string;
};
type ClientConfigParams = {
clientId: number;
};
type Pagination = {
totalItems: number;
currentPage: number;
pageSize: number;
};
type GetListProcessingFileParams = {
page: number;
pageSize: number;
clientId?: number;
clientIds?: number[];
createdByEmails?: string[];
isUploadedByMe?: boolean;
processingFileIds?: number[];
searchFilename?: string;
};
type GetProcessingFileResponse = {
processingFiles: ProcessingFile[];
pagination: Pagination;
};
type ProcessingFile = {
clientId: number;
processingFileId?: number;
fileDisplayName: string;
errorDisplay?: string;
fileUrl: string;
resultFileUrl?: string;
/**
* Possible values: INIT, PROCESSING, SUCCESS, FAILED
*/
status: string;
statsTotalRow: number;
statsTotalSuccess: number;
statsTotalProcessed: number;
createdAt: number;
createdBy: string;
finishedAt?: number;
};
type ProcessingFileStatus = {
[key: string]: {
code: string;
name: string;
color: string;
colorCode: string;
};
};
type FileRow = {
fileID: number;
rowIndex: number;
rowDataRaw: string;
executedTime: number;
tasks: TaskInRow[];
};
type TaskInRow = {
taskIndex: number;
taskRequestCurl: string;
taskResponseRaw: string;
taskName: string;
groupByValue: string;
status: number;
errorDisplay: string;
executedTime: number;
createdAt: number;
updatedAt: number;
};
type GetListFileRowsParams = {
fileId: number;
page?: number;
pageSize?: number;
};
type GetListFileRowsResponse = {
rows: FileRow[];
pagination: {
page: number;
pageSize: number;
total: number;
};
};
type BaseProps = {
/**
* Accepted values: [vi, en, fr, id, km, ms, zh]
*/
language: string;
/**
* FPS client ID
*/
clientId?: number;
/**
* List of FPS client IDs
* Get import history of multiple clients
* This field does not replace clientId and you need to render the download template button by yourself
*/
clientIds?: number[];
/**
* Filter current user's uploaded files
*/
isUploadedByMe?: boolean;
/**
* Filter files by createdByEmails
*/
createdByEmails?: string[];
/**
* Filter files by processingFileIds
*/
processingFileIds?: number[];
/**
* Filter files by file name
*/
searchFileName?: string;
/**
* Environment, used for handling internal API requests and download files from file service.
* Possible values: [DEV, STAG, PROD]
*/
env?: string;
/**
* Custom class names for the components
*/
classNames?: ClassName;
/**
* Config whether component props should overwrite responses from get-client-config API.
* This field is used for development purposes only and should be set to false or unset in production.
* Default value is false
*/
isOverwriteDBConfig?: boolean;
/**
* Extra content under the uploader component
*/
extra?: ReactNode;
/**
* Custom function to handle file download
*/
downloadFile?: (url: string) => Promise<void>;
/**
* Function to get parent app's access token, used for handling internal API requests.
* Require prefix 'Bearer ' in the result
*/
getAccessToken?: () => string;
/**
* X-Request-ID header for the [GET] processing-files API
*/
filterRequestID?: string;
};
type BaseUIConfig = {
/**
* Show debug button, default value is true, require prop env
*/
isShowDebug?: boolean;
/**
* Show created by column, default value is true
*/
isShowCreatedBy?: boolean;
/**
* Show reload button, default value is true
*/
isShowReload?: boolean;
};
/**
* Could be configured in the client config, or passed in directly to the Uploader component
*/
type BaseUploaderProps = {
/**
* Template file URL, used for download template file.
* If not configured, the download button will not be displayed
*/
importFileTemplateUrl?: string;
/**
* Max file size in MB, default value is 5
*/
maxFileSize?: number;
/**
* Accepted file types, accept lowercase letters, default value is ['xlsx'].
* Currently support xlsx, xls, csv
*/
inputFileTypes?: string[];
/**
* Show uploader, default value is true
*/
isShowUploader?: boolean;
/**
* Uploader position, default is right
*/
uploaderPosition?: 'left' | 'right';
};
type HistoryTableProps = TableProps<ProcessingFile> & BaseUIConfig & {
tableTitle?: string | ReactNode;
/**
* Default value is 'DD/MM/YYYY HH:mm:ss'
*/
dateFormat?: string;
/**
* Column ordering, view/ hide columns
* Default ordering and possible values is ['id', 'name', 'createdAt', 'status', 'progressStatus']
*/
orderColumn?: string[];
/**
* Reload table function
*/
onReload?: () => void;
/**
* Whether to concat result file name with dateTime
* Require dateFormat prop
*/
shouldAppendDateToFileName?: boolean;
};
type UploaderProps = UploadProps & BaseUploaderProps & {
onUploadFile?: (file: UploadFile, setFile?: (file?: UploadFile) => void) => Promise<void>;
/**
* Custom download template button
*/
downloadTemplateButton?: ReactNode;
/**
* Additional parameters for the upload file API
*/
parameters?: Object;
/**
* Extra content above the drag and drop section
*/
extra?: ReactNode;
};
/**
* !!! IMPORTANT !!! Read the README please 🤞
*/
type FileHistoryProps = BaseProps & {
tableProps?: HistoryTableProps;
uploaderProps?: UploaderProps;
};
type ClientConfig = Omit<BaseUploaderProps, 'isShowUploader' | 'uploaderPosition'> & {
clientId?: number;
uiConfig?: {
importHistoryTable?: BaseUIConfig;
};
};
type ImportRules = {
maxSize: number;
types: Array<{
extension: string;
mimeType: string;
}>;
maxLine: number;
};
type IMap<T> = {
[key: string]: T;
};
/**
* The library add classNames to the components.
* Styles then added based on the CSS values of the className in the parent's application.
* You can override the default className to match your application's one or add a new className with different styles.
*/
type ClassName = {
/**
* 'd-flex'
*/
displayFlex?: string;
/**
* 'flex-column'
*/
flexColumn?: string;
/**
* 'gap-base'
*/
gapBase?: string;
/**
* 'gap-half'
*/
gapHalf?: string;
/**
* 'mb-0'
*/
marginBottomZero?: string;
/**
* 'mt-half'
*/
marginTopHalf?: string;
/**
* 'mx-base'
*/
marginHorizontalBase?: string;
/**
* 'px-base'
*/
paddingHorizontalBase?: string;
/**
* 'py-half'
*/
paddingVerticalHalf?: string;
/**
* 'text-error'
*/
textErrorColor?: string;
/**
* 'text-primary'
*/
textPrimaryColor?: string;
};
type AnyObject = IMap<any>;
declare const FileImportHistory: React.FC<FileHistoryProps>;
export { AnyObject, BaseProps, BaseUIConfig, BaseUploaderProps, ClassName, ClientConfig, ClientConfigParams, FileHistoryProps, FileImportHistory, FileRow, GetListFileRowsParams, GetListFileRowsResponse, GetListProcessingFileParams, GetProcessingFileResponse, HistoryTableProps, ImportRules, Pagination, ProcessingFile, ProcessingFileStatus, TaskInRow, UploadFilePayload, UploaderProps };