oak-frontend-base/lib/types/AbstractComponent.d.ts

156 lines
5.0 KiB
TypeScript

/// <reference types="react" />
import { EntityDict } from 'oak-domain/lib/types/Entity';
import { EntityDict as BaseEntityDict } from 'oak-domain/lib/base-app-domain';
import { DataType, DataTypeParams } from 'oak-domain/lib/types/schema/DataTypes';
import { ButtonProps } from 'antd';
import { ActionDef } from './Page';
export type ED = BaseEntityDict & EntityDict;
export type RenderWidth = 1 | 2 | 3 | 4;
export type RenderAlign = 'left' | 'right' | 'center';
export type RenderFixed = 'left' | 'right';
export type OakActionBtnProps = {
label: string;
action: string;
type?: 'a' | 'button';
ctxType?: string;
};
export type OakExtraActionProps = {
action: string;
label: string;
show: boolean;
};
export type OakActionsProps = {
action: string;
label?: string;
};
export type OakAbsNativeAttrDef = {
path: string;
width?: RenderWidth;
};
export type OakAbsDerivedAttrDef = {
path: string;
label: string;
width?: number;
span?: number;
type?: 'image' | 'link' | 'ref' | DataType;
linkUrl?: string;
render?: (row: any) => React.ReactNode;
fixed?: RenderFixed;
align?: RenderAlign;
};
export type OakAbsAttrDef = string | OakAbsDerivedAttrDef;
export type OakAbsAttrJudgeDef = {
path: string;
entity: keyof ED;
attr: string;
attribute: OakAbsAttrDef;
attrType: DataType | 'ref' | undefined;
};
export type CardDef = {
title: string | React.ReactNode;
state?: string | React.ReactNode;
rows: OakAbsAttrDef[];
};
export interface OakAbsRefAttrPickerDef<ED2 extends ED, T extends keyof ED2> {
type: 'ref';
mode: 'select' | 'list' | 'radio';
attr: string;
entity: T;
projection: ED2[T]['Selection']['data'];
title: (row: Partial<ED2[T]['Schema']>) => string;
titleLabel?: string;
filter?: ED2[T]['Selection']['filter'];
sorter?: ED2[T]['Selection']['sorter'];
getDynamicSelectors?: () => Promise<{
filter?: ED2[T]['Selection']['filter'];
sorter?: ED2[T]['Selection']['sorter'];
projection?: ED2[T]['Selection']['data'];
}>;
count?: number;
label?: string;
placeholder?: string;
allowNull?: boolean;
}
export interface OakAbsRefAttrPickerRender<ED extends EntityDict & BaseEntityDict, T extends keyof ED> extends OakAbsRefAttrPickerDef<ED, T> {
required?: boolean;
}
export interface OakAbsGeoAttrUpsertDef {
type: 'geo';
category: 'point';
attributes?: {
areaId?: string;
poiName?: string;
coordinate?: string;
};
allowNull?: boolean;
}
export interface OakAbsNativeAttrUpsertDef<ED extends EntityDict & BaseEntityDict, T extends keyof ED, A extends keyof ED[T]['OpSchema']> {
attr: A;
type: Omit<DataType, 'ref' | 'geo'>;
label?: string;
placeholder?: string;
max?: number;
min?: number;
maxLength?: number;
defaultValue?: any;
required?: boolean;
allowNull?: boolean;
}
export type OakAbsAttrUpsertDef<ED extends EntityDict & BaseEntityDict, T extends keyof ED, T2 extends keyof ED = keyof ED> = OakAbsGeoAttrUpsertDef | OakAbsRefAttrPickerDef<ED, T2> | keyof ED[T]['OpSchema'] | OakAbsNativeAttrUpsertDef<ED, T, keyof ED[T]['OpSchema']>;
export type AttrRender = {
label: string;
value: any;
type: DataType | ('image' | 'link' | 'ref');
color?: string;
span?: RenderWidth;
attr: string;
};
export interface OakAbsNativeAttrUpsertRender<ED extends EntityDict & BaseEntityDict, T extends keyof ED, A extends keyof ED[T]['OpSchema']> extends Omit<OakAbsNativeAttrUpsertDef<ED, T, A>, 'type'> {
value: any;
type: Omit<DataType, 'ref'> | 'coordinate' | 'poiName';
enumeration?: Array<{
label: string;
value: string;
}>;
extra?: any;
params: DataTypeParams;
}
export type AttrUpsertRender<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = OakAbsNativeAttrUpsertRender<ED, T, keyof ED[T]['OpSchema']> | OakAbsRefAttrPickerRender<ED, T>;
export type ColumnDefProps = {
width: number;
title: string;
entity: string;
attr: string;
path: string;
type: DataType & ('img' | 'file' | 'avatar');
fixed?: 'right' | 'left';
};
export type DataTransformer = (data: object) => AttrRender[];
export type DataUpsertTransformer<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = (data: object) => AttrUpsertRender<ED, T>[];
export type DataConverter = (data: any[]) => Record<string, any>;
export type CascadeActionProps = {
path: string;
action: string;
};
export type onActionFnDef = (row: any, action: string, cascadeAction?: CascadeActionProps) => void;
export type CascadeActionDef = {
[K in keyof ED[keyof EntityDict]['Schema']]?: ActionDef<ED, keyof ED>[];
};
export type ListButtonProps = {
label: string;
show?: boolean;
type?: ButtonProps['type'];
icon?: React.ReactNode;
onClick: () => void;
};
type ColSpanType = 1 | 2 | 3 | 4;
export type ColumnMapType = {
xxl: ColSpanType;
xl: ColSpanType;
lg: ColSpanType;
md: ColSpanType;
sm: ColSpanType;
xs: ColSpanType;
};
export {};