@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.
Files changed (221) hide show
  1. package/app/AppProvider.js +24 -32
  2. package/app/AuthWrapper.js +13 -9
  3. package/app/LayoutProvider.js +34 -39
  4. package/app/context.js +5 -2
  5. package/app/hooks/index.js +17 -1
  6. package/app/hooks/useAppContext.js +7 -4
  7. package/app/index.js +11 -4
  8. package/auth/AuthProvider.js +27 -36
  9. package/auth/context.d.ts +1 -1
  10. package/auth/context.js +5 -2
  11. package/auth/hooks/index.js +18 -2
  12. package/auth/hooks/useAuthSession.js +7 -4
  13. package/auth/hooks/useIsSkipAuthCheck.js +7 -4
  14. package/auth/hooks/useLogout.js +11 -8
  15. package/auth/index.js +23 -4
  16. package/auth/types.js +2 -1
  17. package/board/BoardColumnDataResolver.js +23 -20
  18. package/board/BoardColumnProvider.js +14 -10
  19. package/board/context.d.ts +2 -2
  20. package/board/context.js +6 -3
  21. package/board/hooks/index.js +15 -6
  22. package/board/hooks/useBoardColumnConfig.js +7 -4
  23. package/board/hooks/useBoardColumnData.d.ts +3 -1
  24. package/board/hooks/useBoardColumnData.js +7 -4
  25. package/board/hooks/useBoardColumnDataState.js +7 -4
  26. package/board/hooks/useBoardConfig.js +7 -4
  27. package/board/hooks/useBoardSchema.js +6 -3
  28. package/board/hooks/useSearchText.js +10 -7
  29. package/board/types.js +2 -1
  30. package/board/utils.js +4 -1
  31. package/builders/CommandBuilder/CommandBuilder.js +13 -10
  32. package/builders/CommandBuilder/DefaultCommandBuilder.js +30 -23
  33. package/builders/CommandBuilder/FormCommandBuilder.js +29 -38
  34. package/builders/CommandBuilder/SubgridCommandBuilder.js +27 -36
  35. package/builders/CommandBuilder/ViewCommandBuilder.js +29 -38
  36. package/builders/CommandBuilder/index.js +5 -1
  37. package/builders/CommandBuilder/utils.js +7 -3
  38. package/builders/SchemaExperienceBuilder.js +55 -31
  39. package/builders/index.js +7 -2
  40. package/builders/utils.js +59 -44
  41. package/command/hooks/index.js +18 -2
  42. package/command/hooks/useBaseCommandHandlerContext.js +29 -25
  43. package/command/hooks/useCommands.js +9 -6
  44. package/command/index.js +18 -2
  45. package/command/types.js +2 -1
  46. package/command/utils/index.js +41 -13
  47. package/components/ScrollView/index.d.ts +1 -1
  48. package/components/ScrollView/index.js +11 -4
  49. package/components/ScrollbarWithMoreDataRequest/index.js +14 -11
  50. package/dataform/DataFormProvider/DataResolver.js +81 -89
  51. package/dataform/DataFormProvider/InitialValueResolver.js +22 -20
  52. package/dataform/DataFormProvider/ReadonlyInfoResolver.js +14 -12
  53. package/dataform/DataFormProvider/index.js +26 -32
  54. package/dataform/context.js +5 -2
  55. package/dataform/hooks/index.js +29 -13
  56. package/dataform/hooks/useFormInstance.js +6 -3
  57. package/dataform/hooks/useFormIsDirty.js +6 -3
  58. package/dataform/hooks/useFormIsReadonly.js +7 -4
  59. package/dataform/hooks/useFormNotifications.js +12 -9
  60. package/dataform/hooks/useFormRecord.js +7 -4
  61. package/dataform/hooks/useFormSave.js +40 -46
  62. package/dataform/hooks/useFormSchema.js +7 -4
  63. package/dataform/hooks/useLoadFormGridPage.js +19 -25
  64. package/dataform/hooks/useMainFormCommands.js +37 -30
  65. package/dataform/hooks/useProcessFlowSteps.js +27 -23
  66. package/dataform/hooks/useRecordId.js +7 -4
  67. package/dataform/hooks/useRecordTitle.js +12 -9
  68. package/dataform/hooks/useSelectedForm.js +7 -4
  69. package/dataform/index.js +23 -4
  70. package/dataform/utils/defaultParameters.js +16 -6
  71. package/dataform/utils/index.js +90 -56
  72. package/dataform/utils/saveRecord.js +99 -104
  73. package/datagrid/DataGridProvider/DataResolver.js +36 -34
  74. package/datagrid/DataGridProvider/index.js +31 -32
  75. package/datagrid/DataGridProvider/transformViewColumns.js +17 -6
  76. package/datagrid/DataGridProvider/utils.js +13 -5
  77. package/datagrid/column-filter/constants.js +5 -2
  78. package/datagrid/column-filter/index.js +7 -2
  79. package/datagrid/column-filter/types.js +2 -1
  80. package/datagrid/column-filter/utils.js +13 -3
  81. package/datagrid/context.d.ts +1 -1
  82. package/datagrid/context.js +5 -2
  83. package/datagrid/hooks/index.js +36 -20
  84. package/datagrid/hooks/useChangeView.js +10 -7
  85. package/datagrid/hooks/useGridColumnFilter.js +14 -8
  86. package/datagrid/hooks/useGridColumns.js +7 -4
  87. package/datagrid/hooks/useGridCommands.js +7 -4
  88. package/datagrid/hooks/useGridData.js +7 -4
  89. package/datagrid/hooks/useGridDataState.js +7 -4
  90. package/datagrid/hooks/useGridExtraFilter.js +7 -4
  91. package/datagrid/hooks/useGridOptions.js +4 -1
  92. package/datagrid/hooks/useGridPagination.js +4 -1
  93. package/datagrid/hooks/useGridRefresh.js +10 -7
  94. package/datagrid/hooks/useGridSchema.js +7 -4
  95. package/datagrid/hooks/useGridSelection.js +10 -7
  96. package/datagrid/hooks/useGridSorting.js +10 -7
  97. package/datagrid/hooks/useGridViewLookupData.js +7 -4
  98. package/datagrid/hooks/useLoadMainGridPage.js +12 -9
  99. package/datagrid/hooks/useMainGridCommands.js +62 -54
  100. package/datagrid/hooks/useMaxRecords.js +7 -4
  101. package/datagrid/hooks/useOpenRecord.js +20 -17
  102. package/datagrid/hooks/useSearchText.js +10 -7
  103. package/datagrid/hooks/useSelectedView.js +7 -4
  104. package/datagrid/hooks/useSubGridCommands.js +34 -23
  105. package/datagrid/index.js +27 -5
  106. package/defaults.js +5 -2
  107. package/dialog/DialogProvider.js +10 -6
  108. package/dialog/context.d.ts +1 -1
  109. package/dialog/context.js +5 -2
  110. package/dialog/hooks/index.js +24 -8
  111. package/dialog/hooks/useCloseDialog.js +10 -7
  112. package/dialog/hooks/useDialogItem.d.ts +1 -1
  113. package/dialog/hooks/useDialogItem.js +7 -4
  114. package/dialog/hooks/useDialogItems.d.ts +1 -1
  115. package/dialog/hooks/useDialogItems.js +7 -4
  116. package/dialog/hooks/useOpenAlertDialog.js +16 -8
  117. package/dialog/hooks/useOpenConfirmDialog.js +18 -9
  118. package/dialog/hooks/useOpenDialog.js +18 -11
  119. package/dialog/hooks/useOpenErrorDialog.js +16 -8
  120. package/dialog/hooks/useOpenPromptDialog.js +18 -9
  121. package/dialog/index.js +22 -3
  122. package/form/FormValidationStringContext.js +9 -5
  123. package/form/index.js +7 -1
  124. package/hooks/index.js +24 -6
  125. package/hooks/useDebouncedValue.js +11 -8
  126. package/hooks/useElementLayout.js +7 -4
  127. package/hooks/useIsMobile.js +12 -6
  128. package/hooks/useItemsWithKey.js +8 -5
  129. package/hooks/useStorageState.js +7 -5
  130. package/hooks/useSystemColorScheme.js +7 -4
  131. package/insights/InsightsProvider.js +13 -10
  132. package/insights/context.d.ts +1 -1
  133. package/insights/context.js +5 -2
  134. package/insights/hooks/index.js +7 -4
  135. package/insights/index.js +20 -2
  136. package/locale/LocaleProvider.js +12 -8
  137. package/locale/context.js +5 -2
  138. package/locale/index.js +23 -4
  139. package/locale/useCurrencySymbol.js +10 -8
  140. package/locale/useLocale.js +7 -4
  141. package/locale/utils.js +8 -3
  142. package/metadata/MetadataProvider.js +21 -17
  143. package/metadata/context.d.ts +1 -1
  144. package/metadata/context.js +5 -2
  145. package/metadata/hooks/index.js +24 -8
  146. package/metadata/hooks/useAppStore.js +7 -4
  147. package/metadata/hooks/useExperienceStore.js +7 -4
  148. package/metadata/hooks/useExperienceView.js +11 -17
  149. package/metadata/hooks/useExperienceViewCommands.js +14 -20
  150. package/metadata/hooks/useExperienceViewLookup.js +10 -16
  151. package/metadata/hooks/useExperienceViewSubgridCommands.js +14 -20
  152. package/metadata/hooks/useMetadata.js +11 -8
  153. package/metadata/hooks/useSchema.js +6 -3
  154. package/metadata/index.js +22 -3
  155. package/mutable/context.js +25 -17
  156. package/mutable/index.js +27 -3
  157. package/mutable/state.js +10 -6
  158. package/mutable/type.js +2 -1
  159. package/mutable/utils.js +12 -8
  160. package/navigation/hooks/index.js +17 -1
  161. package/navigation/hooks/useOpenForm.js +14 -11
  162. package/navigation/index.js +17 -1
  163. package/package.json +4 -12
  164. package/progress-indicator/ProgressIndicatorProvider.js +16 -12
  165. package/progress-indicator/context.js +5 -2
  166. package/progress-indicator/hooks/index.js +17 -1
  167. package/progress-indicator/hooks/useProgressIndicator.d.ts +1 -1
  168. package/progress-indicator/hooks/useProgressIndicator.js +7 -4
  169. package/progress-indicator/index.js +22 -3
  170. package/providers/PageEntityFormProvider/index.js +7 -4
  171. package/providers/PageEntityViewProvider/index.js +7 -4
  172. package/recordset/RecordSetProvider.js +16 -12
  173. package/recordset/context.d.ts +1 -1
  174. package/recordset/context.js +5 -2
  175. package/recordset/hooks/index.js +19 -3
  176. package/recordset/hooks/useRecordSetResult.js +22 -29
  177. package/recordset/hooks/useRecordSetSetter.js +9 -6
  178. package/recordset/hooks/useRecordSetVisibility.js +10 -7
  179. package/recordset/index.js +22 -3
  180. package/route/RouteProvider.js +18 -14
  181. package/route/context.js +9 -6
  182. package/route/hooks/index.js +22 -6
  183. package/route/hooks/useBasePath.js +7 -4
  184. package/route/hooks/useIsRouteActive.js +7 -4
  185. package/route/hooks/usePathname.js +7 -4
  186. package/route/hooks/useRouteResolver.js +7 -4
  187. package/route/hooks/useRouter.js +7 -4
  188. package/route/hooks/useSearchParams.js +7 -4
  189. package/route/index.js +20 -2
  190. package/route/types.js +2 -1
  191. package/store/ClientAppStore.js +12 -21
  192. package/store/ComponentStore.js +6 -4
  193. package/store/EventManager.js +20 -32
  194. package/store/SchemaExperienceStore.js +186 -217
  195. package/store/index.js +20 -4
  196. package/toast-notification/ToastNotificationProvider.js +10 -6
  197. package/toast-notification/context.d.ts +1 -1
  198. package/toast-notification/context.js +5 -2
  199. package/toast-notification/hooks/index.js +19 -3
  200. package/toast-notification/hooks/useCloseToastNotification.js +10 -7
  201. package/toast-notification/hooks/useOpenToastNotification.js +18 -11
  202. package/toast-notification/hooks/useToastNotificationItems.d.ts +1 -1
  203. package/toast-notification/hooks/useToastNotificationItems.js +7 -4
  204. package/toast-notification/index.js +22 -3
  205. package/transport/InMemoryDataService/index.js +59 -78
  206. package/transport/RestDataService/index.d.ts +2 -2
  207. package/transport/RestDataService/index.js +72 -91
  208. package/transport/context.js +9 -15
  209. package/transport/hooks/index.js +18 -2
  210. package/transport/hooks/useDataService.js +7 -4
  211. package/transport/hooks/useFileService.js +7 -4
  212. package/transport/hooks/useRetriveRecords.d.ts +1 -1
  213. package/transport/hooks/useRetriveRecords.js +25 -31
  214. package/transport/index.js +20 -2
  215. package/utils/calculateColumnWidths.js +5 -2
  216. package/utils/color.js +4 -1
  217. package/utils/getAttributeFormattedValue.js +38 -40
  218. package/utils/index.js +18 -2
  219. package/widget/context.js +5 -2
  220. package/widget/hooks/index.js +7 -4
  221. package/widget/index.js +5 -1
@@ -1,21 +1,40 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
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
- import { yupResolver } from '@hookform/resolvers/yup';
11
- import { memoize } from 'lodash';
12
- import * as yup from 'yup';
13
- import { getColumns, getControls, } from '../../dataform/DataFormProvider/DataResolver';
14
- import { localizedLabel } from '../../locale/utils';
15
- export { saveRecord } from './saveRecord';
16
- export function getInitialValues({ cloneRecord, form, record, recordId, schema, defaultParameters, }) {
17
- const formColumns = getColumns(form, schema);
18
- const editableGridControls = getControls(form).filter((control) => control.type === 'editablegrid');
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 = (_a = defaultParameters[column]) !== null && _a !== void 0 ? _a : null;
83
+ value = defaultParameters[column] ?? null;
66
84
  }
67
- return Object.assign(Object.assign({}, acc), { [column]: value });
85
+ return {
86
+ ...acc,
87
+ [column]: value,
88
+ };
68
89
  }, {});
69
90
  }
70
91
  return allColumns.reduce((acc, column) => {
71
- var _a;
72
- const value = record ? record[column] : (_a = defaultParameters[column]) !== null && _a !== void 0 ? _a : null;
73
- return Object.assign(Object.assign({}, acc), { [column]: value });
92
+ const value = record ? record[column] : defaultParameters[column] ?? null;
93
+ return {
94
+ ...acc,
95
+ [column]: value,
96
+ };
74
97
  }, {});
75
98
  }
76
- export const formValidator = memoize(function formValidator({ form, schema, readonlyAttributes, formReadOnly, schemaStore, language, strings, }) {
77
- return (values, context, options) => __awaiter(this, void 0, void 0, function* () {
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 = yield resolver(values, context, options);
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
- export const generateValidationSchema = memoize(function generateValidationSchema({ columns, editableGrids, language, schema, strings, readonlyAttributes, }) {
135
- return yup.object().shape(Object.assign(Object.assign({}, columns.reduce((acc, column) => {
136
- if (readonlyAttributes === null || readonlyAttributes === void 0 ? void 0 : readonlyAttributes.includes(column)) {
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
- const attribute = schema.attributes[column];
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) => (file === null || file === void 0 ? void 0 : file.size) && file.size <= attribute.maxSize);
284
+ return value.every((file) => file?.size && file.size <= attribute.maxSize);
251
285
  });
252
286
  }
253
287
  return validationSchema;
254
288
  }
255
- export const generateAttributeValidationSchema = memoize(function generateAttributeValidationSchema(attribute, language, strings) {
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
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
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 === null || exclude === void 0 ? void 0 : exclude.includes(c)) {
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
- return __awaiter(this, void 0, void 0, function* () {
28
- switch (operation.type) {
29
- case 'create':
30
- yield dataService.createRecord(operation.logicalName, operation.data);
31
- break;
32
- case 'update':
33
- yield dataService.updateRecord(operation.logicalName, operation.id, operation.data);
34
- break;
35
- case 'delete':
36
- yield dataService.deleteRecord(operation.logicalName, operation.id);
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 === null || initialGridRows === void 0 ? void 0 : initialGridRows.map((x) => x[gridSchema.idAttribute]).filter((id) => !gridRows.find((x) => x[gridSchema.idAttribute] === id));
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: Object.assign(Object.assign({}, row), { [control.referenceAttribute]: {
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(_a) {
83
- return __awaiter(this, arguments, void 0, function* ({ values, form, schema, dataService, }) {
84
- const controls = getControls(form);
85
- const editableGridControls = controls.filter((control) => control.type === 'editablegrid');
86
- const result = yield dataService.createRecord(schema.logicalName, values);
87
- const recordId = result[schema.idAttribute];
88
- for (const control of editableGridControls) {
89
- const gridRows = values[control.attributeName];
90
- for (const row of gridRows) {
91
- yield dataService.createRecord(control.logicalName, Object.assign(Object.assign({}, row), { [control.referenceAttribute]: {
92
- id: recordId,
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
- for (const control of editableGridControls) {
114
- operations.push(...generateSubgridUpdateOperation({
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
- export function saveRecord(_a) {
136
- return __awaiter(this, arguments, void 0, function* ({ values, form, schema, dataService, initialValues, record, schemaStore, }) {
137
- let recordId;
138
- if (record) {
139
- recordId = record[schema.idAttribute];
140
- yield updateRecord({
141
- recordId,
142
- values,
143
- form,
144
- schema,
145
- dataService,
146
- initialValues,
147
- schemaStore,
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
- import { useClearDataExceptFirstPage, useRetrieveRecordsKey, useRetriveRecords, } from '@headless-adminapp/app/transport/hooks/useRetriveRecords';
2
- import { useEffect, useMemo, useRef } from 'react';
3
- import { useDebouncedValue } from '../../hooks/useDebouncedValue';
4
- import { useMetadata } from '../../metadata/hooks/useMetadata';
5
- import { useContextSetValue } from '../../mutable/context';
6
- import { GridContext } from '../context';
7
- import { useDataGridSchema, useGridColumnFilter, useGridColumns, useGridExtraFilter, useGridSelection, useGridSorting, useMaxRecords, useSearchText, useSelectedView, } from '../hooks';
8
- import { collectExpandedKeys, mergeConditions } from './utils';
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
- export function DataResolver() {
11
- var _a;
12
- const schema = useDataGridSchema();
13
- const view = useSelectedView();
14
- const [sorting] = useGridSorting();
15
- const [searchText] = useSearchText();
16
- const extraFilter = useGridExtraFilter();
17
- const [columnFilters] = useGridColumnFilter();
18
- const gridColumns = useGridColumns();
19
- const maxRecords = (_a = useMaxRecords()) !== null && _a !== void 0 ? _a : MAX_RECORDS;
20
- const [selectedIds] = useGridSelection();
21
- const { schemaStore } = useMetadata();
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,