@nocobase/client-v2 2.2.0-beta.3 → 2.2.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.d.ts +2 -0
- package/es/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableColumnModel.d.ts +1 -0
- package/es/flow/utils/dateTimeDisplayProps.d.ts +49 -0
- package/es/index.mjs +110 -90
- package/lib/index.js +89 -69
- package/package.json +7 -7
- package/src/flow/actions/dateTimeFormat.tsx +42 -28
- package/src/flow/admin-shell/admin-layout/HelpLite.tsx +1 -3
- package/src/flow/components/DynamicFlowsIcon.tsx +447 -126
- package/src/flow/components/__tests__/DynamicFlowsIcon.test.tsx +148 -2
- package/src/flow/flows/editMarkdownFlow.tsx +1 -1
- package/src/flow/index.ts +1 -1
- package/src/flow/internal/utils/operatorSchemaHelper.ts +15 -1
- package/src/flow/models/blocks/filter-manager/flow-actions/__tests__/customizeFilterRender.test.tsx +56 -1
- package/src/flow/models/blocks/table/TableColumnModel.tsx +36 -3
- package/src/flow/models/blocks/table/__tests__/TableColumnModel.test.tsx +159 -1
- package/src/flow/models/fields/AssociationFieldModel/RecordSelectFieldModel.tsx +16 -4
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/SubTableColumnModel.tsx +24 -1
- package/src/flow/models/fields/AssociationFieldModel/SubTableFieldModel/__tests__/SubTableColumnModel.rowRecord.test.ts +12 -0
- package/src/flow/models/fields/AssociationFieldModel/__tests__/RecordPickerFieldModel.itemContext.test.ts +23 -0
- package/src/flow/models/fields/ClickableFieldModel.tsx +5 -0
- package/src/flow/models/fields/DisplayDateTimeFieldModel.tsx +29 -1
- package/src/flow/models/fields/SelectFieldModel.tsx +6 -4
- package/src/flow/models/fields/__tests__/DisplayDateTimeFieldModel.test.tsx +96 -0
- package/src/flow/models/fields/__tests__/SelectFieldModel.test.tsx +43 -0
- package/src/flow/utils/__tests__/dateTimeFormat.test.ts +258 -0
- package/src/flow/utils/dateTimeDisplayProps.ts +135 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { FlowModelContext } from '@nocobase/flow-engine';
|
|
11
|
+
|
|
12
|
+
type DateTimeDisplayProps = {
|
|
13
|
+
dateOnly?: boolean;
|
|
14
|
+
dateFormat?: string;
|
|
15
|
+
format?: string;
|
|
16
|
+
picker?: string;
|
|
17
|
+
showTime?: boolean;
|
|
18
|
+
timeFormat?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type DateTimeCollectionField = {
|
|
22
|
+
type?: string;
|
|
23
|
+
interface?: string;
|
|
24
|
+
getComponentProps?: () => DateTimeDisplayProps;
|
|
25
|
+
targetCollection?: {
|
|
26
|
+
getField?: (name?: string) => DateTimeCollectionField | undefined;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
type DateTimeModelContext = FlowModelContext & {
|
|
31
|
+
collectionField?: DateTimeCollectionField;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
type DateTimeModel = {
|
|
35
|
+
props?: DateTimeDisplayProps & {
|
|
36
|
+
titleField?: string;
|
|
37
|
+
};
|
|
38
|
+
context?: DateTimeModelContext;
|
|
39
|
+
getStepParams?: (flowKey: string, stepKey: string) => DateTimeDisplayProps | undefined;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
type ResolveDateTimeDisplayPropsOptions = {
|
|
43
|
+
model?: DateTimeModel;
|
|
44
|
+
collectionField?: DateTimeCollectionField;
|
|
45
|
+
titleField?: string;
|
|
46
|
+
currentProps?: DateTimeDisplayProps;
|
|
47
|
+
params?: DateTimeDisplayProps;
|
|
48
|
+
withDefaults?: boolean;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const dateTimeDisplayPropKeys: Array<keyof DateTimeDisplayProps> = [
|
|
52
|
+
'dateOnly',
|
|
53
|
+
'dateFormat',
|
|
54
|
+
'format',
|
|
55
|
+
'picker',
|
|
56
|
+
'showTime',
|
|
57
|
+
'timeFormat',
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
const pickDateTimeDisplayProps = (source?: DateTimeDisplayProps) => {
|
|
61
|
+
if (!source) {
|
|
62
|
+
return {};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const result: DateTimeDisplayProps = {};
|
|
66
|
+
for (const key of dateTimeDisplayPropKeys) {
|
|
67
|
+
if (key === 'dateOnly' || key === 'showTime') {
|
|
68
|
+
if (typeof source[key] !== 'undefined') {
|
|
69
|
+
result[key] = source[key];
|
|
70
|
+
}
|
|
71
|
+
} else if (typeof source[key] !== 'undefined') {
|
|
72
|
+
result[key] = source[key];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const stripUndefined = (props: DateTimeDisplayProps) =>
|
|
79
|
+
Object.fromEntries(Object.entries(props).filter(([, value]) => typeof value !== 'undefined')) as DateTimeDisplayProps;
|
|
80
|
+
|
|
81
|
+
const getModelCollectionField = (model?: DateTimeModel) => model?.context?.collectionField;
|
|
82
|
+
|
|
83
|
+
export const getDateTimeFormatCollectionField = (options: ResolveDateTimeDisplayPropsOptions) => {
|
|
84
|
+
const collectionField = options.collectionField || getModelCollectionField(options.model);
|
|
85
|
+
const titleField = options.titleField || options.model?.props?.titleField;
|
|
86
|
+
return collectionField?.targetCollection?.getField?.(titleField) || collectionField;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export const isTimeCollectionField = (collectionField?: DateTimeCollectionField) =>
|
|
90
|
+
collectionField?.type === 'time' || collectionField?.interface === 'time';
|
|
91
|
+
|
|
92
|
+
export const isDateOnlyCollectionField = (collectionField?: DateTimeCollectionField) =>
|
|
93
|
+
collectionField?.type === 'dateOnly' || collectionField?.interface === 'dateOnly';
|
|
94
|
+
|
|
95
|
+
export const getSavedDateTimeFormatParams = (model?: DateTimeModel) =>
|
|
96
|
+
model?.getStepParams?.('datetimeSettings', 'dateFormat') || model?.getStepParams?.('timeSettings', 'dateFormat');
|
|
97
|
+
|
|
98
|
+
export const resolveDateTimeDisplayProps = (options: ResolveDateTimeDisplayPropsOptions) => {
|
|
99
|
+
const collectionField = options.collectionField || getModelCollectionField(options.model);
|
|
100
|
+
const targetCollectionField = getDateTimeFormatCollectionField(options);
|
|
101
|
+
const mergedProps = {
|
|
102
|
+
...pickDateTimeDisplayProps(collectionField?.getComponentProps?.()),
|
|
103
|
+
...pickDateTimeDisplayProps(
|
|
104
|
+
targetCollectionField !== collectionField ? targetCollectionField?.getComponentProps?.() : undefined,
|
|
105
|
+
),
|
|
106
|
+
...pickDateTimeDisplayProps(options.currentProps || options.model?.props),
|
|
107
|
+
...pickDateTimeDisplayProps(getSavedDateTimeFormatParams(options.model)),
|
|
108
|
+
...pickDateTimeDisplayProps(options.params),
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
if (isTimeCollectionField(targetCollectionField)) {
|
|
112
|
+
const timeFormat = mergedProps.timeFormat || mergedProps.format || 'HH:mm:ss';
|
|
113
|
+
return stripUndefined({
|
|
114
|
+
...mergedProps,
|
|
115
|
+
timeFormat,
|
|
116
|
+
format: timeFormat,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const picker = mergedProps.picker || (options.withDefaults ? 'date' : undefined);
|
|
121
|
+
const dateFormat = mergedProps.dateFormat || (options.withDefaults ? 'YYYY-MM-DD' : undefined);
|
|
122
|
+
const timeFormat = mergedProps.timeFormat || (options.withDefaults ? 'HH:mm:ss' : undefined);
|
|
123
|
+
const showTime = isDateOnlyCollectionField(targetCollectionField) ? false : mergedProps.showTime;
|
|
124
|
+
const finalDateFormat = dateFormat || 'YYYY-MM-DD';
|
|
125
|
+
const finalTimeFormat = timeFormat || 'HH:mm:ss';
|
|
126
|
+
|
|
127
|
+
return stripUndefined({
|
|
128
|
+
...mergedProps,
|
|
129
|
+
picker,
|
|
130
|
+
dateFormat,
|
|
131
|
+
timeFormat,
|
|
132
|
+
showTime,
|
|
133
|
+
format: showTime ? `${finalDateFormat} ${finalTimeFormat}` : finalDateFormat,
|
|
134
|
+
});
|
|
135
|
+
};
|