choerodon-ui
Version:
An enterprise-class UI design language and React-based implementation
193 lines (192 loc) • 7.62 kB
TypeScript
import { AxiosError, AxiosInstance, AxiosPromise, AxiosRequestConfig, Method } from 'axios';
import { Moment, MomentInput } from 'moment';
import noop from 'lodash/noop';
import { LovConfig } from '../interface';
import { ExportMode, RecordStatus, FieldType } from '../data-set/enum';
import { ValidationMessages } from '../validator/Validator';
import { TransportHookProps, TransportProps } from '../data-set/Transport';
import DataSet from '../data-set/DataSet';
import { FeedBack } from '../data-set/FeedBack';
import { defaultValidationMessageFormatter, defaultValidationMessageReportFormatter, ValidationMessageFormatter, ValidationMessageReportFormatter } from '../validator/ValidationMessageReportFormatter';
import Field from '../data-set/Field';
import Record from '../data-set/Record';
import { CacheOptions } from '../cache';
import AttachmentFile, { FileLike } from '../data-set/AttachmentFile';
import AttachmentFileChunk from '../data-set/AttachmentFileChunk';
export declare type TimeZone = string | ((moment: Moment) => string);
export declare type BigNumberTarget = 'currency' | 'number-field';
export declare type Status = {
[RecordStatus.add]: string;
[RecordStatus.update]: string;
[RecordStatus.delete]: string;
};
export declare type Formatter = {
jsonDate: string | null;
date: string;
dateTime: string;
time: string;
year: string;
month: string;
week: string;
timeZone?: TimeZone;
};
export interface AttachmentConfig {
defaultFileKey: string;
defaultFileSize: number;
defaultChunkSize: number;
defaultChunkThreads: number;
action?: AxiosRequestConfig | ((props: {
attachment: AttachmentFile;
chunk?: AttachmentFileChunk | undefined;
bucketName?: string | undefined;
bucketDirectory?: string | undefined;
storageCode?: string | undefined;
attachmentUUID: string;
isPublic?: boolean | undefined;
}) => AxiosRequestConfig);
batchFetchCount?: <T extends string | number | symbol>(attachmentUUIDs: T[], props: {
isPublic?: boolean;
}) => Promise<{
[key in T]: number;
}>;
fetchList?: (props: {
bucketName?: string;
bucketDirectory?: string;
storageCode?: string;
attachmentUUID: string;
isPublic?: boolean;
}) => Promise<FileLike[]>;
getPreviewUrl?: (props: {
attachment: AttachmentFile;
bucketName?: string;
bucketDirectory?: string;
storageCode?: string;
attachmentUUID?: string;
isPublic?: boolean;
}) => string | undefined;
getDownloadUrl?: (props: {
attachment: AttachmentFile;
bucketName?: string;
bucketDirectory?: string;
storageCode?: string;
attachmentUUID?: string;
isPublic?: boolean;
}) => string | Function | undefined;
getDownloadAllUrl?: (props: {
bucketName?: string;
bucketDirectory?: string;
storageCode?: string;
attachmentUUID: string;
isPublic?: boolean;
}) => string | Function | undefined;
getAttachmentUUID?: (props: {
isPublic?: boolean;
}) => Promise<string> | string;
onBeforeUpload?: (attachment: AttachmentFile, attachments: AttachmentFile[], props: {
useChunk?: boolean;
bucketName?: string;
bucketDirectory?: string;
storageCode?: string;
isPublic?: boolean;
}) => boolean | undefined | PromiseLike<boolean | undefined>;
onBeforeUploadChunk?: (props: {
chunk: AttachmentFileChunk;
attachment: AttachmentFile;
bucketName?: string;
bucketDirectory?: string;
storageCode?: string;
isPublic?: boolean;
}) => boolean | undefined | PromiseLike<boolean | undefined>;
onUploadSuccess?: (response: any, attachment: AttachmentFile, props: {
useChunk?: boolean;
bucketName?: string;
bucketDirectory?: string;
storageCode?: string;
isPublic?: boolean;
}) => void;
onUploadError?: (error: AxiosError, attachment: AttachmentFile) => void;
onOrderChange?: (props: {
attachmentUUID: string;
attachments: AttachmentFile[];
bucketName?: string;
bucketDirectory?: string;
storageCode?: string;
isPublic?: boolean;
}) => Promise<void>;
onRemove?: (props: {
attachment: AttachmentFile;
attachmentUUID: string;
bucketName?: string;
bucketDirectory?: string;
storageCode?: string;
isPublic?: boolean;
}) => Promise<boolean>;
}
export interface Config {
lookupCache?: CacheOptions<string, AxiosPromise>;
lookupUrl?: string | ((code: string) => string);
lookupAxiosMethod?: Method;
lookupAxiosConfig?: AxiosRequestConfig | ((props: {
params?: any;
dataSet?: DataSet;
record?: Record;
lookupCode?: string;
}) => AxiosRequestConfig);
lookupBatchAxiosConfig?: (codes: string[]) => AxiosRequestConfig;
lovDefineUrl?: string | ((code: string) => string);
lovDefineAxiosConfig?: AxiosRequestConfig | ((code: string, field?: Field) => AxiosRequestConfig);
lovQueryUrl?: string | ((code: string, lovConfig: LovConfig | undefined, props: TransportHookProps) => string);
lovQueryAxiosConfig?: AxiosRequestConfig | ((code: string, lovConfig: LovConfig | undefined, props: TransportHookProps) => AxiosRequestConfig);
axios?: AxiosInstance;
feedback?: FeedBack;
dataKey?: string;
totalKey?: string;
statusKey?: string;
tlsKey?: string;
status?: Status;
exportMode?: ExportMode;
defaultValidationMessages?: ValidationMessages;
validationMessageFormatter?: ValidationMessageFormatter;
validationMessageReportFormatter?: ValidationMessageReportFormatter;
transport?: TransportProps;
generatePageQuery?: (pageParams: {
page?: number;
pageSize?: number;
sortName?: string;
sortOrder?: string;
sort?: string[];
}) => object;
formatter?: Formatter;
attachment?: AttachmentConfig;
numberFieldNonStrictStep?: boolean;
confirm?: (message: any) => Promise<boolean>;
min?: (type: FieldType) => number | MomentInput | string | null;
max?: (type: FieldType) => number | MomentInput | string | null;
xlsx?: () => Promise<any>;
}
export declare type ConfigKeys = keyof Config;
declare const defaultConfig: {
lookupCache: CacheOptions<string, AxiosPromise<any>>;
lookupUrl: (code: any) => string;
lookupAxiosMethod: Method;
lovDefineUrl: (code: any) => string;
lovQueryUrl: (code: any) => string;
dataKey: string;
totalKey: string;
statusKey: string;
tlsKey: string;
status: Status;
feedback: Required<FeedBack>;
formatter: Formatter;
attachment: AttachmentConfig;
confirm: (_: any) => Promise<boolean>;
validationMessageFormatter: typeof defaultValidationMessageFormatter;
validationMessageReportFormatter: typeof defaultValidationMessageReportFormatter;
xlsx: typeof noop;
};
export declare type DefaultConfig = typeof defaultConfig;
export declare function getConfig<C extends Config, T extends keyof C, D extends DefaultConfig>(key: T): T extends keyof D ? D[T] : C[T];
export declare function overwriteDefaultConfig<T extends Config>(config: T, mergeProps?: (keyof T)[] | null): void;
export declare function overwriteConfigMergeProps<T extends Config>(customMergeProps: (keyof T)[]): void;
export default function configure<T extends Config>(config: T, mergeProps?: (keyof T)[] | null): void;
export {};