@headless-adminapp/app 0.0.17-alpha.53 → 0.0.17-alpha.55
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/app/AppProvider.js +24 -32
- package/app/AuthWrapper.js +13 -9
- package/app/LayoutProvider.js +34 -39
- package/app/context.js +5 -2
- package/app/hooks/index.js +17 -1
- package/app/hooks/useAppContext.js +7 -4
- package/app/index.js +11 -4
- package/auth/AuthProvider.js +27 -36
- package/auth/context.d.ts +1 -1
- package/auth/context.js +5 -2
- package/auth/hooks/index.js +18 -2
- package/auth/hooks/useAuthSession.js +7 -4
- package/auth/hooks/useIsSkipAuthCheck.js +7 -4
- package/auth/hooks/useLogout.js +11 -8
- package/auth/index.js +23 -4
- package/auth/types.js +2 -1
- package/board/BoardColumnDataResolver.js +23 -20
- package/board/BoardColumnProvider.js +14 -10
- package/board/context.d.ts +2 -2
- package/board/context.js +6 -3
- package/board/hooks/index.js +15 -6
- package/board/hooks/useBoardColumnConfig.js +7 -4
- package/board/hooks/useBoardColumnData.d.ts +3 -1
- package/board/hooks/useBoardColumnData.js +7 -4
- package/board/hooks/useBoardColumnDataState.js +7 -4
- package/board/hooks/useBoardConfig.js +7 -4
- package/board/hooks/useBoardSchema.js +6 -3
- package/board/hooks/useSearchText.js +10 -7
- package/board/types.js +2 -1
- package/board/utils.js +4 -1
- package/builders/CommandBuilder/CommandBuilder.js +13 -10
- package/builders/CommandBuilder/DefaultCommandBuilder.js +30 -23
- package/builders/CommandBuilder/FormCommandBuilder.js +29 -38
- package/builders/CommandBuilder/SubgridCommandBuilder.js +27 -36
- package/builders/CommandBuilder/ViewCommandBuilder.js +29 -38
- package/builders/CommandBuilder/index.js +5 -1
- package/builders/CommandBuilder/utils.js +7 -3
- package/builders/SchemaExperienceBuilder.js +55 -31
- package/builders/index.js +7 -2
- package/builders/utils.js +59 -44
- package/command/hooks/index.js +18 -2
- package/command/hooks/useBaseCommandHandlerContext.js +29 -25
- package/command/hooks/useCommands.js +9 -6
- package/command/index.js +18 -2
- package/command/types.js +2 -1
- package/command/utils/index.js +41 -13
- package/components/ScrollView/index.d.ts +1 -1
- package/components/ScrollView/index.js +11 -4
- package/components/ScrollbarWithMoreDataRequest/index.js +14 -11
- package/dataform/DataFormProvider/DataResolver.js +81 -89
- package/dataform/DataFormProvider/InitialValueResolver.js +22 -20
- package/dataform/DataFormProvider/ReadonlyInfoResolver.js +14 -12
- package/dataform/DataFormProvider/index.js +26 -32
- package/dataform/context.js +5 -2
- package/dataform/hooks/index.js +29 -13
- package/dataform/hooks/useFormInstance.js +6 -3
- package/dataform/hooks/useFormIsDirty.js +6 -3
- package/dataform/hooks/useFormIsReadonly.js +7 -4
- package/dataform/hooks/useFormNotifications.js +12 -9
- package/dataform/hooks/useFormRecord.js +7 -4
- package/dataform/hooks/useFormSave.js +40 -46
- package/dataform/hooks/useFormSchema.js +7 -4
- package/dataform/hooks/useLoadFormGridPage.js +19 -25
- package/dataform/hooks/useMainFormCommands.js +37 -30
- package/dataform/hooks/useProcessFlowSteps.js +27 -23
- package/dataform/hooks/useRecordId.js +7 -4
- package/dataform/hooks/useRecordTitle.js +12 -9
- package/dataform/hooks/useSelectedForm.js +7 -4
- package/dataform/index.js +23 -4
- package/dataform/utils/defaultParameters.js +16 -6
- package/dataform/utils/index.js +90 -56
- package/dataform/utils/saveRecord.js +99 -104
- package/datagrid/DataGridProvider/DataResolver.js +36 -34
- package/datagrid/DataGridProvider/index.js +31 -32
- package/datagrid/DataGridProvider/transformViewColumns.js +17 -6
- package/datagrid/DataGridProvider/utils.js +13 -5
- package/datagrid/column-filter/constants.js +5 -2
- package/datagrid/column-filter/index.js +7 -2
- package/datagrid/column-filter/types.js +2 -1
- package/datagrid/column-filter/utils.js +13 -3
- package/datagrid/context.d.ts +1 -1
- package/datagrid/context.js +5 -2
- package/datagrid/hooks/index.js +36 -20
- package/datagrid/hooks/useChangeView.js +10 -7
- package/datagrid/hooks/useGridColumnFilter.js +14 -8
- package/datagrid/hooks/useGridColumns.js +7 -4
- package/datagrid/hooks/useGridCommands.js +7 -4
- package/datagrid/hooks/useGridData.js +7 -4
- package/datagrid/hooks/useGridDataState.js +7 -4
- package/datagrid/hooks/useGridExtraFilter.js +7 -4
- package/datagrid/hooks/useGridOptions.js +4 -1
- package/datagrid/hooks/useGridPagination.js +4 -1
- package/datagrid/hooks/useGridRefresh.js +10 -7
- package/datagrid/hooks/useGridSchema.js +7 -4
- package/datagrid/hooks/useGridSelection.js +10 -7
- package/datagrid/hooks/useGridSorting.js +10 -7
- package/datagrid/hooks/useGridViewLookupData.js +7 -4
- package/datagrid/hooks/useLoadMainGridPage.js +12 -9
- package/datagrid/hooks/useMainGridCommands.js +62 -54
- package/datagrid/hooks/useMaxRecords.js +7 -4
- package/datagrid/hooks/useOpenRecord.js +20 -17
- package/datagrid/hooks/useSearchText.js +10 -7
- package/datagrid/hooks/useSelectedView.js +7 -4
- package/datagrid/hooks/useSubGridCommands.js +34 -23
- package/datagrid/index.js +27 -5
- package/defaults.js +5 -2
- package/dialog/DialogProvider.js +10 -6
- package/dialog/context.d.ts +1 -1
- package/dialog/context.js +5 -2
- package/dialog/hooks/index.js +24 -8
- package/dialog/hooks/useCloseDialog.js +10 -7
- package/dialog/hooks/useDialogItem.d.ts +1 -1
- package/dialog/hooks/useDialogItem.js +7 -4
- package/dialog/hooks/useDialogItems.d.ts +1 -1
- package/dialog/hooks/useDialogItems.js +7 -4
- package/dialog/hooks/useOpenAlertDialog.js +16 -8
- package/dialog/hooks/useOpenConfirmDialog.js +18 -9
- package/dialog/hooks/useOpenDialog.js +18 -11
- package/dialog/hooks/useOpenErrorDialog.js +16 -8
- package/dialog/hooks/useOpenPromptDialog.js +18 -9
- package/dialog/index.js +22 -3
- package/form/FormValidationStringContext.js +9 -5
- package/form/index.js +7 -1
- package/hooks/index.js +24 -6
- package/hooks/useDebouncedValue.js +11 -8
- package/hooks/useElementLayout.js +7 -4
- package/hooks/useIsMobile.js +12 -6
- package/hooks/useItemsWithKey.js +8 -5
- package/hooks/useStorageState.js +7 -5
- package/hooks/useSystemColorScheme.js +7 -4
- package/insights/InsightsProvider.js +13 -10
- package/insights/context.d.ts +1 -1
- package/insights/context.js +5 -2
- package/insights/hooks/index.js +7 -4
- package/insights/index.js +20 -2
- package/locale/LocaleProvider.js +12 -8
- package/locale/context.js +5 -2
- package/locale/index.js +23 -4
- package/locale/useCurrencySymbol.js +10 -8
- package/locale/useLocale.js +7 -4
- package/locale/utils.js +8 -3
- package/metadata/MetadataProvider.js +21 -17
- package/metadata/context.d.ts +1 -1
- package/metadata/context.js +5 -2
- package/metadata/hooks/index.js +24 -8
- package/metadata/hooks/useAppStore.js +7 -4
- package/metadata/hooks/useExperienceStore.js +7 -4
- package/metadata/hooks/useExperienceView.js +11 -17
- package/metadata/hooks/useExperienceViewCommands.js +14 -20
- package/metadata/hooks/useExperienceViewLookup.js +10 -16
- package/metadata/hooks/useExperienceViewSubgridCommands.js +14 -20
- package/metadata/hooks/useMetadata.js +11 -8
- package/metadata/hooks/useSchema.js +6 -3
- package/metadata/index.js +22 -3
- package/mutable/context.js +25 -17
- package/mutable/index.js +27 -3
- package/mutable/state.js +10 -6
- package/mutable/type.js +2 -1
- package/mutable/utils.js +12 -8
- package/navigation/hooks/index.js +17 -1
- package/navigation/hooks/useOpenForm.js +14 -11
- package/navigation/index.js +17 -1
- package/package.json +4 -12
- package/progress-indicator/ProgressIndicatorProvider.js +16 -12
- package/progress-indicator/context.js +5 -2
- package/progress-indicator/hooks/index.js +17 -1
- package/progress-indicator/hooks/useProgressIndicator.d.ts +1 -1
- package/progress-indicator/hooks/useProgressIndicator.js +7 -4
- package/progress-indicator/index.js +22 -3
- package/providers/PageEntityFormProvider/index.js +7 -4
- package/providers/PageEntityViewProvider/index.js +7 -4
- package/recordset/RecordSetProvider.js +16 -12
- package/recordset/context.d.ts +1 -1
- package/recordset/context.js +5 -2
- package/recordset/hooks/index.js +19 -3
- package/recordset/hooks/useRecordSetResult.js +22 -29
- package/recordset/hooks/useRecordSetSetter.js +9 -6
- package/recordset/hooks/useRecordSetVisibility.js +10 -7
- package/recordset/index.js +22 -3
- package/route/RouteProvider.js +18 -14
- package/route/context.js +9 -6
- package/route/hooks/index.js +22 -6
- package/route/hooks/useBasePath.js +7 -4
- package/route/hooks/useIsRouteActive.js +7 -4
- package/route/hooks/usePathname.js +7 -4
- package/route/hooks/useRouteResolver.js +7 -4
- package/route/hooks/useRouter.js +7 -4
- package/route/hooks/useSearchParams.js +7 -4
- package/route/index.js +20 -2
- package/route/types.js +2 -1
- package/store/ClientAppStore.js +12 -21
- package/store/ComponentStore.js +6 -4
- package/store/EventManager.js +20 -32
- package/store/SchemaExperienceStore.js +186 -217
- package/store/index.js +20 -4
- package/toast-notification/ToastNotificationProvider.js +10 -6
- package/toast-notification/context.d.ts +1 -1
- package/toast-notification/context.js +5 -2
- package/toast-notification/hooks/index.js +19 -3
- package/toast-notification/hooks/useCloseToastNotification.js +10 -7
- package/toast-notification/hooks/useOpenToastNotification.js +18 -11
- package/toast-notification/hooks/useToastNotificationItems.d.ts +1 -1
- package/toast-notification/hooks/useToastNotificationItems.js +7 -4
- package/toast-notification/index.js +22 -3
- package/transport/InMemoryDataService/index.js +59 -78
- package/transport/RestDataService/index.d.ts +2 -2
- package/transport/RestDataService/index.js +72 -91
- package/transport/context.js +9 -15
- package/transport/hooks/index.js +18 -2
- package/transport/hooks/useDataService.js +7 -4
- package/transport/hooks/useFileService.js +7 -4
- package/transport/hooks/useRetriveRecords.d.ts +1 -1
- package/transport/hooks/useRetriveRecords.js +25 -31
- package/transport/index.js +20 -2
- package/utils/calculateColumnWidths.js +5 -2
- package/utils/color.js +4 -1
- package/utils/getAttributeFormattedValue.js +38 -40
- package/utils/index.js +18 -2
- package/widget/context.js +5 -2
- package/widget/hooks/index.js +7 -4
- package/widget/index.js +5 -1
package/dataform/utils/index.js
CHANGED
|
@@ -1,21 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
9
24
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.generateAttributeValidationSchema = exports.generateValidationSchema = exports.formValidator = exports.saveRecord = void 0;
|
|
27
|
+
exports.getInitialValues = getInitialValues;
|
|
28
|
+
const yup_1 = require("@hookform/resolvers/yup");
|
|
29
|
+
const lodash_1 = require("lodash");
|
|
30
|
+
const yup = __importStar(require("yup"));
|
|
31
|
+
const DataResolver_1 = require("../../dataform/DataFormProvider/DataResolver");
|
|
32
|
+
const utils_1 = require("../../locale/utils");
|
|
33
|
+
var saveRecord_1 = require("./saveRecord");
|
|
34
|
+
Object.defineProperty(exports, "saveRecord", { enumerable: true, get: function () { return saveRecord_1.saveRecord; } });
|
|
35
|
+
function getInitialValues({ cloneRecord, form, record, recordId, schema, defaultParameters, }) {
|
|
36
|
+
const formColumns = (0, DataResolver_1.getColumns)(form, schema);
|
|
37
|
+
const editableGridControls = (0, DataResolver_1.getControls)(form).filter((control) => control.type === 'editablegrid');
|
|
19
38
|
const allColumns = [
|
|
20
39
|
...formColumns,
|
|
21
40
|
...editableGridControls.map((x) => x.attributeName),
|
|
@@ -32,7 +51,6 @@ export function getInitialValues({ cloneRecord, form, record, recordId, schema,
|
|
|
32
51
|
return acc;
|
|
33
52
|
}, {});
|
|
34
53
|
return allColumns.reduce((acc, column) => {
|
|
35
|
-
var _a;
|
|
36
54
|
const cloneAttributeInfo = cloneAttributesObj[column];
|
|
37
55
|
// | EditableGridCloneAttribute; // TODO:
|
|
38
56
|
let value = null;
|
|
@@ -62,19 +80,24 @@ export function getInitialValues({ cloneRecord, form, record, recordId, schema,
|
|
|
62
80
|
// }
|
|
63
81
|
}
|
|
64
82
|
else {
|
|
65
|
-
value =
|
|
83
|
+
value = defaultParameters[column] ?? null;
|
|
66
84
|
}
|
|
67
|
-
return
|
|
85
|
+
return {
|
|
86
|
+
...acc,
|
|
87
|
+
[column]: value,
|
|
88
|
+
};
|
|
68
89
|
}, {});
|
|
69
90
|
}
|
|
70
91
|
return allColumns.reduce((acc, column) => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
92
|
+
const value = record ? record[column] : defaultParameters[column] ?? null;
|
|
93
|
+
return {
|
|
94
|
+
...acc,
|
|
95
|
+
[column]: value,
|
|
96
|
+
};
|
|
74
97
|
}, {});
|
|
75
98
|
}
|
|
76
|
-
|
|
77
|
-
return (values, context, options) =>
|
|
99
|
+
exports.formValidator = (0, lodash_1.memoize)(function formValidator({ form, schema, readonlyAttributes, formReadOnly, schemaStore, language, strings, }) {
|
|
100
|
+
return async (values, context, options) => {
|
|
78
101
|
let validator = yup.object().shape({});
|
|
79
102
|
if (!formReadOnly) {
|
|
80
103
|
const activeControls = form.experience.tabs
|
|
@@ -99,7 +122,7 @@ export const formValidator = memoize(function formValidator({ form, schema, read
|
|
|
99
122
|
.filter((control) => control.type === 'standard')
|
|
100
123
|
.map((control) => control.attributeName),
|
|
101
124
|
]));
|
|
102
|
-
validator = generateValidationSchema({
|
|
125
|
+
validator = (0, exports.generateValidationSchema)({
|
|
103
126
|
editableGrids: editableGridControls.map((control) => {
|
|
104
127
|
if (control.type !== 'editablegrid') {
|
|
105
128
|
throw new Error('Invalid control type');
|
|
@@ -119,10 +142,10 @@ export const formValidator = memoize(function formValidator({ form, schema, read
|
|
|
119
142
|
readonlyAttributes,
|
|
120
143
|
});
|
|
121
144
|
}
|
|
122
|
-
const resolver = yupResolver(validator);
|
|
123
|
-
const result =
|
|
145
|
+
const resolver = (0, yup_1.yupResolver)(validator);
|
|
146
|
+
const result = await resolver(values, context, options);
|
|
124
147
|
return result;
|
|
125
|
-
}
|
|
148
|
+
};
|
|
126
149
|
}, ({ form, language, schema, strings, readonlyAttributes, formReadOnly }) => JSON.stringify({
|
|
127
150
|
schema,
|
|
128
151
|
form,
|
|
@@ -131,31 +154,42 @@ export const formValidator = memoize(function formValidator({ form, schema, read
|
|
|
131
154
|
readonlyAttributes,
|
|
132
155
|
formReadOnly,
|
|
133
156
|
}));
|
|
134
|
-
|
|
135
|
-
return yup.object().shape(
|
|
136
|
-
|
|
157
|
+
exports.generateValidationSchema = (0, lodash_1.memoize)(function generateValidationSchema({ columns, editableGrids, language, schema, strings, readonlyAttributes, }) {
|
|
158
|
+
return yup.object().shape({
|
|
159
|
+
...columns.reduce((acc, column) => {
|
|
160
|
+
if (readonlyAttributes?.includes(column)) {
|
|
161
|
+
return acc;
|
|
162
|
+
}
|
|
163
|
+
const attribute = schema.attributes[column];
|
|
164
|
+
const validationSchema = (0, exports.generateAttributeValidationSchema)(attribute, language, strings);
|
|
165
|
+
return {
|
|
166
|
+
...acc,
|
|
167
|
+
[column]: validationSchema,
|
|
168
|
+
};
|
|
169
|
+
}, {}),
|
|
170
|
+
...editableGrids?.reduce((acc, grid) => {
|
|
171
|
+
let validationSchema = yup
|
|
172
|
+
.array()
|
|
173
|
+
.of(yup.object().shape({
|
|
174
|
+
...grid.columns.reduce((acc, column) => {
|
|
175
|
+
const attribute = grid.schema.attributes[column];
|
|
176
|
+
const validationSchema = (0, exports.generateAttributeValidationSchema)(attribute, language, strings);
|
|
177
|
+
return {
|
|
178
|
+
...acc,
|
|
179
|
+
[column]: validationSchema,
|
|
180
|
+
};
|
|
181
|
+
}, {}),
|
|
182
|
+
}))
|
|
183
|
+
.nullable();
|
|
184
|
+
if (grid.required) {
|
|
185
|
+
validationSchema = validationSchema
|
|
186
|
+
.required(strings.atLeastOneRowRequired)
|
|
187
|
+
.min(1, strings.atLeastOneRowRequired);
|
|
188
|
+
}
|
|
189
|
+
acc[grid.attributeName] = validationSchema;
|
|
137
190
|
return acc;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const validationSchema = generateAttributeValidationSchema(attribute, language, strings);
|
|
141
|
-
return Object.assign(Object.assign({}, acc), { [column]: validationSchema });
|
|
142
|
-
}, {})), editableGrids === null || editableGrids === void 0 ? void 0 : editableGrids.reduce((acc, grid) => {
|
|
143
|
-
let validationSchema = yup
|
|
144
|
-
.array()
|
|
145
|
-
.of(yup.object().shape(Object.assign({}, grid.columns.reduce((acc, column) => {
|
|
146
|
-
const attribute = grid.schema.attributes[column];
|
|
147
|
-
const validationSchema = generateAttributeValidationSchema(attribute, language, strings);
|
|
148
|
-
return Object.assign(Object.assign({}, acc), { [column]: validationSchema });
|
|
149
|
-
}, {}))))
|
|
150
|
-
.nullable();
|
|
151
|
-
if (grid.required) {
|
|
152
|
-
validationSchema = validationSchema
|
|
153
|
-
.required(strings.atLeastOneRowRequired)
|
|
154
|
-
.min(1, strings.atLeastOneRowRequired);
|
|
155
|
-
}
|
|
156
|
-
acc[grid.attributeName] = validationSchema;
|
|
157
|
-
return acc;
|
|
158
|
-
}, {})));
|
|
191
|
+
}, {}),
|
|
192
|
+
});
|
|
159
193
|
}, ({ columns, editableGrids, language, schema, strings, readonlyAttributes }) => JSON.stringify({
|
|
160
194
|
schema,
|
|
161
195
|
columns,
|
|
@@ -247,14 +281,14 @@ function extendAttributeAttachmentsValidationSchema({ attribute, validationSchem
|
|
|
247
281
|
if (!value) {
|
|
248
282
|
return true;
|
|
249
283
|
}
|
|
250
|
-
return value.every((file) =>
|
|
284
|
+
return value.every((file) => file?.size && file.size <= attribute.maxSize);
|
|
251
285
|
});
|
|
252
286
|
}
|
|
253
287
|
return validationSchema;
|
|
254
288
|
}
|
|
255
|
-
|
|
289
|
+
exports.generateAttributeValidationSchema = (0, lodash_1.memoize)(function generateAttributeValidationSchema(attribute, language, strings) {
|
|
256
290
|
let validationSchema = createAttributeValidationSchema(attribute);
|
|
257
|
-
const label = localizedLabel(language, attribute);
|
|
291
|
+
const label = (0, utils_1.localizedLabel)(language, attribute);
|
|
258
292
|
validationSchema = extendAttributeRequiredValidationSchema({
|
|
259
293
|
attribute,
|
|
260
294
|
validationSchema,
|
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { getControls } from '../../dataform/DataFormProvider/DataResolver';
|
|
11
|
-
export function getModifiedValues(initialValues, values, exclude) {
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getModifiedValues = getModifiedValues;
|
|
4
|
+
exports.saveRecord = saveRecord;
|
|
5
|
+
const DataResolver_1 = require("../../dataform/DataFormProvider/DataResolver");
|
|
6
|
+
function getModifiedValues(initialValues, values, exclude) {
|
|
12
7
|
const keys = Object.keys(values);
|
|
13
8
|
return keys.reduce((p, c) => {
|
|
14
9
|
if (c === '_id') {
|
|
15
10
|
return p;
|
|
16
11
|
}
|
|
17
|
-
if (exclude
|
|
12
|
+
if (exclude?.includes(c)) {
|
|
18
13
|
return p;
|
|
19
14
|
}
|
|
20
15
|
if (JSON.stringify(values[c]) !== JSON.stringify(initialValues[c])) {
|
|
@@ -23,19 +18,17 @@ export function getModifiedValues(initialValues, values, exclude) {
|
|
|
23
18
|
return p;
|
|
24
19
|
}, {});
|
|
25
20
|
}
|
|
26
|
-
function executeOperation(operation, dataService) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
});
|
|
21
|
+
async function executeOperation(operation, dataService) {
|
|
22
|
+
switch (operation.type) {
|
|
23
|
+
case 'create':
|
|
24
|
+
await dataService.createRecord(operation.logicalName, operation.data);
|
|
25
|
+
break;
|
|
26
|
+
case 'update':
|
|
27
|
+
await dataService.updateRecord(operation.logicalName, operation.id, operation.data);
|
|
28
|
+
break;
|
|
29
|
+
case 'delete':
|
|
30
|
+
await dataService.deleteRecord(operation.logicalName, operation.id);
|
|
31
|
+
}
|
|
39
32
|
}
|
|
40
33
|
function generateSubgridUpdateOperation({ recordId, control, schemaStore, values, initialValues, }) {
|
|
41
34
|
const operations = [];
|
|
@@ -44,14 +37,19 @@ function generateSubgridUpdateOperation({ recordId, control, schemaStore, values
|
|
|
44
37
|
const initialGridRows = initialValues[control.attributeName];
|
|
45
38
|
const newRows = gridRows.filter((x) => !x[gridSchema.idAttribute]);
|
|
46
39
|
const updatedRows = gridRows.filter((x) => x[gridSchema.idAttribute]);
|
|
47
|
-
const deletedIds = initialGridRows
|
|
40
|
+
const deletedIds = initialGridRows
|
|
41
|
+
?.map((x) => x[gridSchema.idAttribute])
|
|
42
|
+
.filter((id) => !gridRows.find((x) => x[gridSchema.idAttribute] === id));
|
|
48
43
|
for (const row of newRows) {
|
|
49
44
|
operations.push({
|
|
50
45
|
type: 'create',
|
|
51
46
|
logicalName: control.logicalName,
|
|
52
|
-
data:
|
|
47
|
+
data: {
|
|
48
|
+
...row,
|
|
49
|
+
[control.referenceAttribute]: {
|
|
53
50
|
id: recordId,
|
|
54
|
-
}
|
|
51
|
+
},
|
|
52
|
+
},
|
|
55
53
|
});
|
|
56
54
|
}
|
|
57
55
|
for (const row of updatedRows) {
|
|
@@ -79,85 +77,82 @@ function generateSubgridUpdateOperation({ recordId, control, schemaStore, values
|
|
|
79
77
|
}
|
|
80
78
|
return operations;
|
|
81
79
|
}
|
|
82
|
-
function createRecord(
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
return recordId;
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
function updateRecord(_a) {
|
|
100
|
-
return __awaiter(this, arguments, void 0, function* ({ recordId, values, form, schema, dataService, initialValues, schemaStore, }) {
|
|
101
|
-
const controls = getControls(form);
|
|
102
|
-
const editableGridControls = controls.filter((control) => control.type === 'editablegrid');
|
|
103
|
-
const modifiedValues = getModifiedValues(initialValues, values, editableGridControls.map((x) => x.attributeName));
|
|
104
|
-
const operations = [];
|
|
105
|
-
if (Object.keys(modifiedValues).length) {
|
|
106
|
-
operations.push({
|
|
107
|
-
type: 'update',
|
|
108
|
-
logicalName: schema.logicalName,
|
|
109
|
-
data: modifiedValues,
|
|
110
|
-
id: recordId,
|
|
80
|
+
async function createRecord({ values, form, schema, dataService, }) {
|
|
81
|
+
const controls = (0, DataResolver_1.getControls)(form);
|
|
82
|
+
const editableGridControls = controls.filter((control) => control.type === 'editablegrid');
|
|
83
|
+
const result = await dataService.createRecord(schema.logicalName, values);
|
|
84
|
+
const recordId = result[schema.idAttribute];
|
|
85
|
+
for (const control of editableGridControls) {
|
|
86
|
+
const gridRows = values[control.attributeName];
|
|
87
|
+
for (const row of gridRows) {
|
|
88
|
+
await dataService.createRecord(control.logicalName, {
|
|
89
|
+
...row,
|
|
90
|
+
[control.referenceAttribute]: {
|
|
91
|
+
id: recordId,
|
|
92
|
+
},
|
|
111
93
|
});
|
|
112
94
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
recordId,
|
|
116
|
-
control,
|
|
117
|
-
schemaStore,
|
|
118
|
-
initialValues,
|
|
119
|
-
values,
|
|
120
|
-
}));
|
|
121
|
-
}
|
|
122
|
-
if (!operations.length) {
|
|
123
|
-
return {
|
|
124
|
-
success: false,
|
|
125
|
-
title: 'No changes',
|
|
126
|
-
message: 'No changes made to the record',
|
|
127
|
-
isError: false,
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
for (const operation of operations) {
|
|
131
|
-
yield executeOperation(operation, dataService);
|
|
132
|
-
}
|
|
133
|
-
});
|
|
95
|
+
}
|
|
96
|
+
return recordId;
|
|
134
97
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
else {
|
|
151
|
-
recordId = yield createRecord({
|
|
152
|
-
dataService,
|
|
153
|
-
form,
|
|
154
|
-
schema,
|
|
155
|
-
values,
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
return {
|
|
159
|
-
success: true,
|
|
98
|
+
async function updateRecord({ recordId, values, form, schema, dataService, initialValues, schemaStore, }) {
|
|
99
|
+
const controls = (0, DataResolver_1.getControls)(form);
|
|
100
|
+
const editableGridControls = controls.filter((control) => control.type === 'editablegrid');
|
|
101
|
+
const modifiedValues = getModifiedValues(initialValues, values, editableGridControls.map((x) => x.attributeName));
|
|
102
|
+
const operations = [];
|
|
103
|
+
if (Object.keys(modifiedValues).length) {
|
|
104
|
+
operations.push({
|
|
105
|
+
type: 'update',
|
|
106
|
+
logicalName: schema.logicalName,
|
|
107
|
+
data: modifiedValues,
|
|
108
|
+
id: recordId,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
for (const control of editableGridControls) {
|
|
112
|
+
operations.push(...generateSubgridUpdateOperation({
|
|
160
113
|
recordId,
|
|
114
|
+
control,
|
|
115
|
+
schemaStore,
|
|
116
|
+
initialValues,
|
|
117
|
+
values,
|
|
118
|
+
}));
|
|
119
|
+
}
|
|
120
|
+
if (!operations.length) {
|
|
121
|
+
return {
|
|
122
|
+
success: false,
|
|
123
|
+
title: 'No changes',
|
|
124
|
+
message: 'No changes made to the record',
|
|
125
|
+
isError: false,
|
|
161
126
|
};
|
|
162
|
-
}
|
|
127
|
+
}
|
|
128
|
+
for (const operation of operations) {
|
|
129
|
+
await executeOperation(operation, dataService);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async function saveRecord({ values, form, schema, dataService, initialValues, record, schemaStore, }) {
|
|
133
|
+
let recordId;
|
|
134
|
+
if (record) {
|
|
135
|
+
recordId = record[schema.idAttribute];
|
|
136
|
+
await updateRecord({
|
|
137
|
+
recordId,
|
|
138
|
+
values,
|
|
139
|
+
form,
|
|
140
|
+
schema,
|
|
141
|
+
dataService,
|
|
142
|
+
initialValues,
|
|
143
|
+
schemaStore,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
recordId = await createRecord({
|
|
148
|
+
dataService,
|
|
149
|
+
form,
|
|
150
|
+
schema,
|
|
151
|
+
values,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
success: true,
|
|
156
|
+
recordId,
|
|
157
|
+
};
|
|
163
158
|
}
|
|
@@ -1,29 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataResolver = DataResolver;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const useDebouncedValue_1 = require("../../hooks/useDebouncedValue");
|
|
6
|
+
const useMetadata_1 = require("../../metadata/hooks/useMetadata");
|
|
7
|
+
const context_1 = require("../../mutable/context");
|
|
8
|
+
const useRetriveRecords_1 = require("../../transport/hooks/useRetriveRecords");
|
|
9
|
+
const context_2 = require("../context");
|
|
10
|
+
const hooks_1 = require("../hooks");
|
|
11
|
+
const utils_1 = require("./utils");
|
|
9
12
|
const MAX_RECORDS = 10000;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const [
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const selectedIdsRef = useRef(selectedIds);
|
|
13
|
+
function DataResolver() {
|
|
14
|
+
const schema = (0, hooks_1.useDataGridSchema)();
|
|
15
|
+
const view = (0, hooks_1.useSelectedView)();
|
|
16
|
+
const [sorting] = (0, hooks_1.useGridSorting)();
|
|
17
|
+
const [searchText] = (0, hooks_1.useSearchText)();
|
|
18
|
+
const extraFilter = (0, hooks_1.useGridExtraFilter)();
|
|
19
|
+
const [columnFilters] = (0, hooks_1.useGridColumnFilter)();
|
|
20
|
+
const gridColumns = (0, hooks_1.useGridColumns)();
|
|
21
|
+
const maxRecords = (0, hooks_1.useMaxRecords)() ?? MAX_RECORDS;
|
|
22
|
+
const [selectedIds] = (0, hooks_1.useGridSelection)();
|
|
23
|
+
const { schemaStore } = (0, useMetadata_1.useMetadata)();
|
|
24
|
+
const selectedIdsRef = (0, react_1.useRef)(selectedIds);
|
|
23
25
|
selectedIdsRef.current = selectedIds;
|
|
24
|
-
const setState = useContextSetValue(GridContext);
|
|
25
|
-
const [search] = useDebouncedValue(searchText, 500);
|
|
26
|
-
const columns = useMemo(() => {
|
|
26
|
+
const setState = (0, context_1.useContextSetValue)(context_2.GridContext);
|
|
27
|
+
const [search] = (0, useDebouncedValue_1.useDebouncedValue)(searchText, 500);
|
|
28
|
+
const columns = (0, react_1.useMemo)(() => {
|
|
27
29
|
const set = new Set([
|
|
28
30
|
...gridColumns.filter((x) => !x.expandedKey).map((x) => x.name),
|
|
29
31
|
schema.primaryAttribute,
|
|
@@ -32,12 +34,12 @@ export function DataResolver() {
|
|
|
32
34
|
set.add(schema.avatarAttribute);
|
|
33
35
|
}
|
|
34
36
|
return Array.from(set);
|
|
35
|
-
}, [gridColumns, schema.primaryAttribute]);
|
|
36
|
-
const expand = useMemo(() => collectExpandedKeys(gridColumns), [gridColumns]);
|
|
37
|
-
const filter = useMemo(() => {
|
|
38
|
-
return mergeConditions(schema, view.experience.filter, extraFilter, columnFilters, schemaStore);
|
|
37
|
+
}, [gridColumns, schema.avatarAttribute, schema.primaryAttribute]);
|
|
38
|
+
const expand = (0, react_1.useMemo)(() => (0, utils_1.collectExpandedKeys)(gridColumns), [gridColumns]);
|
|
39
|
+
const filter = (0, react_1.useMemo)(() => {
|
|
40
|
+
return (0, utils_1.mergeConditions)(schema, view.experience.filter, extraFilter, columnFilters, schemaStore);
|
|
39
41
|
}, [columnFilters, extraFilter, schema, schemaStore, view.experience.filter]);
|
|
40
|
-
const queryKey = useRetrieveRecordsKey({
|
|
42
|
+
const queryKey = (0, useRetriveRecords_1.useRetrieveRecordsKey)({
|
|
41
43
|
columns,
|
|
42
44
|
expand,
|
|
43
45
|
filter,
|
|
@@ -46,8 +48,8 @@ export function DataResolver() {
|
|
|
46
48
|
search,
|
|
47
49
|
sorting,
|
|
48
50
|
});
|
|
49
|
-
useClearDataExceptFirstPage(queryKey);
|
|
50
|
-
const { fetchNextPage, data, hasNextPage, isFetching, isFetchingNextPage } = useRetriveRecords(queryKey, {
|
|
51
|
+
(0, useRetriveRecords_1.useClearDataExceptFirstPage)(queryKey);
|
|
52
|
+
const { fetchNextPage, data, hasNextPage, isFetching, isFetchingNextPage } = (0, useRetriveRecords_1.useRetriveRecords)(queryKey, {
|
|
51
53
|
columns,
|
|
52
54
|
expand,
|
|
53
55
|
filter,
|
|
@@ -56,12 +58,12 @@ export function DataResolver() {
|
|
|
56
58
|
search,
|
|
57
59
|
sorting,
|
|
58
60
|
});
|
|
59
|
-
useEffect(() => {
|
|
61
|
+
(0, react_1.useEffect)(() => {
|
|
60
62
|
setState({
|
|
61
63
|
fetchNextPage: () => fetchNextPage,
|
|
62
64
|
});
|
|
63
65
|
}, [fetchNextPage, setState]);
|
|
64
|
-
useEffect(() => {
|
|
66
|
+
(0, react_1.useEffect)(() => {
|
|
65
67
|
if (!data) {
|
|
66
68
|
setState({
|
|
67
69
|
data: null,
|
|
@@ -74,7 +76,7 @@ export function DataResolver() {
|
|
|
74
76
|
selectedIds,
|
|
75
77
|
});
|
|
76
78
|
}, [data, setState, schema.idAttribute]);
|
|
77
|
-
useEffect(() => {
|
|
79
|
+
(0, react_1.useEffect)(() => {
|
|
78
80
|
setState({
|
|
79
81
|
dataState: {
|
|
80
82
|
isFetching,
|