@controleonline/ui-default 1.0.263

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 (56) hide show
  1. package/.github/agents/developer.agent.md +30 -0
  2. package/.github/agents/devops.agent.md +30 -0
  3. package/.github/agents/qa.agent.md +30 -0
  4. package/.github/agents/security.agent.md +30 -0
  5. package/.scrutinizer.yml +20 -0
  6. package/AGENTS.md +47 -0
  7. package/FUNDING.yml +1 -0
  8. package/package.json +21 -0
  9. package/src/react/components/errors/DefaultErrors.js +360 -0
  10. package/src/react/components/files/DefaultFile.js +46 -0
  11. package/src/react/components/filters/CompactFilterSelector.js +262 -0
  12. package/src/react/components/filters/CompactFilterSelector.styles.js +124 -0
  13. package/src/react/components/filters/DateShortcutFilter.js +264 -0
  14. package/src/react/components/filters/DateShortcutFilter.styles.js +82 -0
  15. package/src/react/components/filters/DefaultColumnFilter.js +97 -0
  16. package/src/react/components/filters/DefaultColumnFilter.styles.js +21 -0
  17. package/src/react/components/filters/DefaultExternalFilters.js +441 -0
  18. package/src/react/components/filters/DefaultExternalFilters.styles.js +177 -0
  19. package/src/react/components/filters/DefaultSearch.js +103 -0
  20. package/src/react/components/filters/DefaultSearch.styles.js +70 -0
  21. package/src/react/components/filters/dateFilterSelection.js +29 -0
  22. package/src/react/components/form/DefaultForm.js +198 -0
  23. package/src/react/components/form/DefaultForm.styles.js +70 -0
  24. package/src/react/components/help/DefaultTooltip.js +87 -0
  25. package/src/react/components/help/DefaultTooltip.styles.js +61 -0
  26. package/src/react/components/inputs/DefaultInput.js +160 -0
  27. package/src/react/components/inputs/DefaultInput.styles.js +93 -0
  28. package/src/react/components/inputs/DefaultSelect.js +192 -0
  29. package/src/react/components/inputs/DefaultSelect.styles.js +65 -0
  30. package/src/react/components/inputs/defaultInputUtils.js +230 -0
  31. package/src/react/components/map/DefaultGoogleMap.styles.js +9 -0
  32. package/src/react/components/map/DefaultGoogleMap.web.js +698 -0
  33. package/src/react/components/map/DefaultMap.native.js +71 -0
  34. package/src/react/components/map/DefaultMap.shared.js +762 -0
  35. package/src/react/components/map/DefaultMap.styles.js +16 -0
  36. package/src/react/components/map/DefaultMap.web.js +66 -0
  37. package/src/react/components/map/DefaultNativeMap.native.js +615 -0
  38. package/src/react/components/map/DefaultNativeMap.shared.js +532 -0
  39. package/src/react/components/map/DefaultNativeMap.styles.js +122 -0
  40. package/src/react/components/table/DefaultTable.js +1897 -0
  41. package/src/react/components/table/DefaultTable.styles.js +610 -0
  42. package/src/react/index.js +10 -0
  43. package/src/react/utils/tableVisibleColumnsPreferences.js +264 -0
  44. package/src/store/default/actions.js +444 -0
  45. package/src/store/default/getters.js +28 -0
  46. package/src/store/default/mutation_types.js +26 -0
  47. package/src/store/default/mutations.js +138 -0
  48. package/src/tests/react/components/DateShortcutFilter.test.js +96 -0
  49. package/src/tests/react/components/errors/DefaultErrors.test.js +162 -0
  50. package/src/tests/react/components/files/DefaultFile.test.js +80 -0
  51. package/src/tests/react/components/map/DefaultMap.shared.test.js +162 -0
  52. package/src/tests/react/filters/dateFilterSelection.test.js +46 -0
  53. package/src/tests/react/inputs/defaultInputUtils.test.js +45 -0
  54. package/src/tests/react/store/defaultActions.test.js +112 -0
  55. package/src/tests/react/utils/tableVisibleColumnsPreferences.test.js +223 -0
  56. package/src/utils/filters.js +56 -0
@@ -0,0 +1,264 @@
1
+ export const TABLE_VISIBLE_COLUMNS_PREFERENCES_KEY = 'tableVisibleColumns';
2
+ export const TABLE_VIEW_MODE_PREFERENCES_KEY = 'tableViewModes';
3
+ export const TABLE_SORT_PREFERENCES_KEY = 'tableSorts';
4
+ export const TABLE_SORT_FIELD_PREFERENCES_KEY = 'tableSortFields';
5
+ export const TABLE_SORT_DIRECTION_PREFERENCES_KEY = 'tableSortDirections';
6
+ export const DEFAULT_TABLE_PREFERENCES_STORAGE_KEY = 'DefaultTablePreferences';
7
+
8
+ const isPlainObject = value =>
9
+ !!value && typeof value === 'object' && !Array.isArray(value);
10
+
11
+ const getColumnKey = column => column?.key || column?.name || '';
12
+
13
+ const readStoredPreferences = () => {
14
+ try {
15
+ const rawValue = globalThis?.localStorage?.getItem?.(
16
+ DEFAULT_TABLE_PREFERENCES_STORAGE_KEY,
17
+ );
18
+
19
+ if (!rawValue) {
20
+ return {};
21
+ }
22
+
23
+ const parsedValue = JSON.parse(rawValue);
24
+ return isPlainObject(parsedValue) ? parsedValue : {};
25
+ } catch {
26
+ return {};
27
+ }
28
+ };
29
+
30
+ const writeStoredPreferences = preferences => {
31
+ try {
32
+ globalThis?.localStorage?.setItem?.(
33
+ DEFAULT_TABLE_PREFERENCES_STORAGE_KEY,
34
+ JSON.stringify(preferences),
35
+ );
36
+ } catch {
37
+ // localStorage can be unavailable in some runtimes
38
+ }
39
+ };
40
+
41
+ export const buildDefaultVisibleColumns = columns =>
42
+ (Array.isArray(columns) ? columns : []).reduce((accumulator, column) => {
43
+ const key = getColumnKey(column);
44
+ if (key) {
45
+ accumulator[key] = column?.visible !== false;
46
+ }
47
+ return accumulator;
48
+ }, {});
49
+
50
+ export const sanitizeVisibleColumnsPreference = ({
51
+ columns = [],
52
+ visibleColumns = null,
53
+ }) => {
54
+ const defaultVisibleColumns = buildDefaultVisibleColumns(columns);
55
+
56
+ if (!isPlainObject(visibleColumns)) {
57
+ return defaultVisibleColumns;
58
+ }
59
+
60
+ return Object.keys(defaultVisibleColumns).reduce((accumulator, key) => {
61
+ accumulator[key] =
62
+ typeof visibleColumns[key] === 'boolean'
63
+ ? visibleColumns[key]
64
+ : defaultVisibleColumns[key];
65
+ return accumulator;
66
+ }, {});
67
+ };
68
+
69
+ export const resolveStoredVisibleColumnsPreference = preferenceKey => {
70
+ if (!preferenceKey) {
71
+ return null;
72
+ }
73
+
74
+ const storedPreferences = readStoredPreferences();
75
+ const tableVisibleColumns = storedPreferences[TABLE_VISIBLE_COLUMNS_PREFERENCES_KEY];
76
+
77
+ if (!isPlainObject(tableVisibleColumns)) {
78
+ return null;
79
+ }
80
+
81
+ const pagePreference = tableVisibleColumns[preferenceKey];
82
+ return isPlainObject(pagePreference) ? pagePreference : null;
83
+ };
84
+
85
+ export const persistVisibleColumnsPreference = (
86
+ preferenceKey = '',
87
+ visibleColumns = {},
88
+ ) => {
89
+ if (!preferenceKey || !isPlainObject(visibleColumns)) {
90
+ return;
91
+ }
92
+
93
+ const storedPreferences = readStoredPreferences();
94
+ const tableVisibleColumns = isPlainObject(
95
+ storedPreferences[TABLE_VISIBLE_COLUMNS_PREFERENCES_KEY],
96
+ )
97
+ ? storedPreferences[TABLE_VISIBLE_COLUMNS_PREFERENCES_KEY]
98
+ : {};
99
+
100
+ writeStoredPreferences({
101
+ ...storedPreferences,
102
+ [TABLE_VISIBLE_COLUMNS_PREFERENCES_KEY]: {
103
+ ...tableVisibleColumns,
104
+ [preferenceKey]: visibleColumns,
105
+ },
106
+ });
107
+ };
108
+
109
+ export const resolveStoredTableViewModePreference = (
110
+ preferenceKey = '',
111
+ fallbackViewMode = 'table',
112
+ ) => {
113
+ if (!preferenceKey) {
114
+ return fallbackViewMode;
115
+ }
116
+
117
+ const storedPreferences = readStoredPreferences();
118
+ const tableViewModes = storedPreferences[TABLE_VIEW_MODE_PREFERENCES_KEY];
119
+
120
+ if (!isPlainObject(tableViewModes)) {
121
+ return fallbackViewMode;
122
+ }
123
+
124
+ const resolvedViewMode = tableViewModes[preferenceKey];
125
+ return resolvedViewMode === 'cards' || resolvedViewMode === 'table'
126
+ ? resolvedViewMode
127
+ : fallbackViewMode;
128
+ };
129
+
130
+ export const persistTableViewModePreference = (
131
+ preferenceKey = '',
132
+ viewMode = 'table',
133
+ ) => {
134
+ if (!preferenceKey || (viewMode !== 'cards' && viewMode !== 'table')) {
135
+ return;
136
+ }
137
+
138
+ const storedPreferences = readStoredPreferences();
139
+ const tableViewModes = isPlainObject(
140
+ storedPreferences[TABLE_VIEW_MODE_PREFERENCES_KEY],
141
+ )
142
+ ? storedPreferences[TABLE_VIEW_MODE_PREFERENCES_KEY]
143
+ : {};
144
+
145
+ writeStoredPreferences({
146
+ ...storedPreferences,
147
+ [TABLE_VIEW_MODE_PREFERENCES_KEY]: {
148
+ ...tableViewModes,
149
+ [preferenceKey]: viewMode,
150
+ },
151
+ });
152
+ };
153
+
154
+ export const resolveStoredTableSortPreference = (preferenceKey = '') => {
155
+ if (!preferenceKey) {
156
+ return null;
157
+ }
158
+
159
+ const storedPreferences = readStoredPreferences();
160
+ const tableSortFields =
161
+ storedPreferences[TABLE_SORT_FIELD_PREFERENCES_KEY];
162
+ const tableSortDirections =
163
+ storedPreferences[TABLE_SORT_DIRECTION_PREFERENCES_KEY];
164
+
165
+ const resolvedField = isPlainObject(tableSortFields)
166
+ ? tableSortFields[preferenceKey]
167
+ : '';
168
+ const resolvedDirection = isPlainObject(tableSortDirections)
169
+ ? tableSortDirections[preferenceKey]
170
+ : '';
171
+
172
+ if (
173
+ typeof resolvedField === 'string' &&
174
+ resolvedField.trim() &&
175
+ (resolvedDirection === 'asc' || resolvedDirection === 'desc')
176
+ ) {
177
+ return {
178
+ direction: resolvedDirection,
179
+ field: resolvedField.trim(),
180
+ };
181
+ }
182
+
183
+ const tableSorts = storedPreferences[TABLE_SORT_PREFERENCES_KEY];
184
+
185
+ if (!isPlainObject(tableSorts)) {
186
+ return null;
187
+ }
188
+
189
+ const resolvedSort = tableSorts[preferenceKey];
190
+
191
+ if (!isPlainObject(resolvedSort)) {
192
+ return null;
193
+ }
194
+
195
+ const direction =
196
+ resolvedSort.direction === 'asc' || resolvedSort.direction === 'desc'
197
+ ? resolvedSort.direction
198
+ : null;
199
+ const field =
200
+ typeof resolvedSort.field === 'string' && resolvedSort.field.trim()
201
+ ? resolvedSort.field.trim()
202
+ : '';
203
+
204
+ if (!direction || !field) {
205
+ return null;
206
+ }
207
+
208
+ return {
209
+ direction,
210
+ field,
211
+ };
212
+ };
213
+
214
+ export const persistTableSortPreference = (
215
+ preferenceKey = '',
216
+ sort = null,
217
+ ) => {
218
+ if (
219
+ !preferenceKey ||
220
+ !isPlainObject(sort) ||
221
+ (sort.direction !== 'asc' && sort.direction !== 'desc') ||
222
+ typeof sort.field !== 'string' ||
223
+ !sort.field.trim()
224
+ ) {
225
+ return;
226
+ }
227
+
228
+ const storedPreferences = readStoredPreferences();
229
+ const tableSortFields = isPlainObject(
230
+ storedPreferences[TABLE_SORT_FIELD_PREFERENCES_KEY],
231
+ )
232
+ ? storedPreferences[TABLE_SORT_FIELD_PREFERENCES_KEY]
233
+ : {};
234
+ const tableSortDirections = isPlainObject(
235
+ storedPreferences[TABLE_SORT_DIRECTION_PREFERENCES_KEY],
236
+ )
237
+ ? storedPreferences[TABLE_SORT_DIRECTION_PREFERENCES_KEY]
238
+ : {};
239
+ const legacyTableSorts = isPlainObject(
240
+ storedPreferences[TABLE_SORT_PREFERENCES_KEY],
241
+ )
242
+ ? storedPreferences[TABLE_SORT_PREFERENCES_KEY]
243
+ : {};
244
+
245
+ writeStoredPreferences({
246
+ ...storedPreferences,
247
+ [TABLE_SORT_FIELD_PREFERENCES_KEY]: {
248
+ ...tableSortFields,
249
+ [preferenceKey]: sort.field.trim(),
250
+ },
251
+ [TABLE_SORT_DIRECTION_PREFERENCES_KEY]: {
252
+ ...tableSortDirections,
253
+ [preferenceKey]: sort.direction,
254
+ },
255
+ [TABLE_SORT_PREFERENCES_KEY]: {
256
+ ...legacyTableSorts,
257
+ [preferenceKey]: {
258
+ direction: sort.direction,
259
+ field: sort.field.trim(),
260
+ },
261
+ },
262
+ });
263
+ };
264
+
@@ -0,0 +1,444 @@
1
+ import {api} from '@controleonline/ui-common/src/api';
2
+ import localDB from '@controleonline/ui-common/src/api/localDB';
3
+ import {queue} from '@controleonline/ui-common/src/api/queue';
4
+ import * as types from '@controleonline/ui-default/src/store/default/mutation_types';
5
+
6
+ let db = null;
7
+
8
+ export const STORE_ACTION_META_KEY = '__storeMeta'
9
+
10
+ const isPlainObject = value =>
11
+ Object.prototype.toString.call(value) === '[object Object]'
12
+
13
+ const normalizeText = value => String(value ?? '').trim()
14
+
15
+ const stableSerialize = value => {
16
+ if (value === null || value === undefined) {
17
+ return 'null'
18
+ }
19
+
20
+ if (Array.isArray(value)) {
21
+ return `[${value.map(item => stableSerialize(item)).join(',')}]`
22
+ }
23
+
24
+ if (value instanceof Date) {
25
+ return JSON.stringify(value.toISOString())
26
+ }
27
+
28
+ if (isPlainObject(value)) {
29
+ return `{${Object.keys(value)
30
+ .sort()
31
+ .map(key => `${JSON.stringify(key)}:${stableSerialize(value[key])}`)
32
+ .join(',')}}`
33
+ }
34
+
35
+ return JSON.stringify(value)
36
+ }
37
+
38
+ const normalizeCollectionItems = response => {
39
+ if (Array.isArray(response)) return response
40
+ if (Array.isArray(response?.member)) return response.member
41
+ if (Array.isArray(response?.['hydra:member'])) return response['hydra:member']
42
+
43
+ return []
44
+ }
45
+
46
+ const resolveCollectionTotalItems = (response, items) =>
47
+ Number(
48
+ response?.totalItems ||
49
+ response?.['hydra:totalItems'] ||
50
+ items?.length ||
51
+ 0,
52
+ )
53
+
54
+ const normalizeCollectionItemId = item =>
55
+ normalizeText(item?.['@id'] || item?.id || '').replace(/\D+/g, '')
56
+
57
+ const appendCollectionItems = (currentItems, nextItems) => {
58
+ const mergedItems = Array.isArray(currentItems) ? [...currentItems] : []
59
+ const incomingItems = Array.isArray(nextItems) ? nextItems : []
60
+
61
+ incomingItems.forEach(item => {
62
+ const itemId = normalizeCollectionItemId(item)
63
+ const existingIndex = mergedItems.findIndex(
64
+ currentItem => normalizeCollectionItemId(currentItem) === itemId,
65
+ )
66
+
67
+ if (existingIndex >= 0) {
68
+ mergedItems[existingIndex] = item
69
+ return
70
+ }
71
+
72
+ mergedItems.push(item)
73
+ })
74
+
75
+ return mergedItems
76
+ }
77
+
78
+ export const splitStoreActionPayload = value => {
79
+ if (!isPlainObject(value)) {
80
+ return {
81
+ payload: value,
82
+ storeMeta: {},
83
+ }
84
+ }
85
+
86
+ const payload = {...value}
87
+ const rawStoreMeta = payload[STORE_ACTION_META_KEY]
88
+ delete payload[STORE_ACTION_META_KEY]
89
+
90
+ return {
91
+ payload,
92
+ storeMeta: isPlainObject(rawStoreMeta) ? rawStoreMeta : {},
93
+ }
94
+ }
95
+
96
+ export const buildStoreErrorCommitOptions = storeMeta => {
97
+ if (!isPlainObject(storeMeta)) {
98
+ return {}
99
+ }
100
+
101
+ const options = {}
102
+
103
+ if (storeMeta.skipSystemError === true) {
104
+ options.skipSystemError = true
105
+ }
106
+
107
+ if (typeof storeMeta.dedupeKey === 'string' && storeMeta.dedupeKey.trim()) {
108
+ options.dedupeKey = storeMeta.dedupeKey.trim()
109
+ }
110
+
111
+ if (typeof storeMeta.providerKey === 'string' && storeMeta.providerKey.trim()) {
112
+ options.providerKey = storeMeta.providerKey.trim()
113
+ }
114
+
115
+ if (typeof storeMeta.position === 'string' && storeMeta.position.trim()) {
116
+ options.position = storeMeta.position.trim()
117
+ }
118
+
119
+ return options
120
+ }
121
+
122
+ const commitStoreError = (commit, error, storeMeta) => {
123
+ commit(
124
+ types.SET_ERROR,
125
+ error?.message || error,
126
+ buildStoreErrorCommitOptions(storeMeta),
127
+ )
128
+ }
129
+
130
+ export const executeQueue = ({commit, getters}, func, callback) => {
131
+ queue.executeQueue(func, callback);
132
+ };
133
+
134
+ export const addToQueue = ({commit, getters}, func) => {
135
+ queue.addToQueue(func);
136
+ };
137
+ export const initQueue = ({commit, getters}, func) => {
138
+ queue.initQueue(func);
139
+ return queue;
140
+ };
141
+
142
+ export const saveOffline = ({commit, getters}, data) => {
143
+ return;
144
+ };
145
+
146
+ export const getOfflineItems = ({commit, getters}, params = {}) => {
147
+ const {storeMeta} = splitStoreActionPayload(params)
148
+ commit(types.SET_ISLOADING, true);
149
+ commit(types.SET_ERROR, null);
150
+ commit(types.SET_SUMMARY, {});
151
+
152
+ db = new localDB(getters);
153
+
154
+ return db
155
+ .getItemsByFilters()
156
+ .then(async data => {
157
+ if (!data || (Array.isArray(data) && data.length === 0))
158
+ return getOnlineItems({commit, getters}, params).then(data => {
159
+ commit(types.SET_ITEM, data);
160
+ if (getters.offline) saveOffline({commit, getters}, data);
161
+ return data;
162
+ });
163
+ })
164
+ .catch(e => {
165
+ commitStoreError(commit, e, storeMeta)
166
+ throw e;
167
+ })
168
+ .finally(() => {
169
+ commit(types.SET_ISLOADING, false);
170
+ });
171
+ };
172
+
173
+ export const getOnlineItems = ({commit, getters}, params = {}) => {
174
+ const {payload: requestParams, storeMeta} = splitStoreActionPayload(params)
175
+ const {append: shouldAppend = false, ...queryParams} = isPlainObject(requestParams)
176
+ ? requestParams
177
+ : {}
178
+ const requestKey = stableSerialize({
179
+ append: Boolean(shouldAppend),
180
+ endpoint: getters.resourceEndpoint,
181
+ params: queryParams,
182
+ })
183
+
184
+ commit(types.SET_ACTIVE_REQUEST_KEY, requestKey)
185
+ commit(types.SET_ISLOADING, true);
186
+ commit(types.SET_ISLOADINGLIST, true)
187
+ commit(types.SET_ERROR, null);
188
+ if (!shouldAppend) {
189
+ if (getters.items != null) commit(types.SET_ITEMS, []);
190
+ commit(types.SET_TOTALITEMS, 0);
191
+ commit(types.SET_SUMMARY, {});
192
+ }
193
+ return api
194
+ .fetch(getters.resourceEndpoint, {params: queryParams})
195
+ .then(data => {
196
+ const pageItems = normalizeCollectionItems(data)
197
+
198
+ if (getters.activeRequestKey !== requestKey) {
199
+ return pageItems
200
+ }
201
+
202
+ const nextItems = shouldAppend
203
+ ? appendCollectionItems(getters.items, pageItems)
204
+ : pageItems
205
+
206
+ commit(types.SET_ERROR, null);
207
+ commit(types.SET_ITEMS, nextItems);
208
+ commit(types.SET_TOTALITEMS, resolveCollectionTotalItems(data, nextItems));
209
+ commit(types.SET_SUMMARY, data['summary'] || data?.['hydra:summary'] || {});
210
+ commit(types.SET_LAST_COMPLETED_REQUEST, {
211
+ completedAt: Date.now(),
212
+ requestKey,
213
+ status: 'success',
214
+ });
215
+
216
+ return pageItems;
217
+ })
218
+ .catch(e => {
219
+ if (getters.activeRequestKey === requestKey) {
220
+ commitStoreError(commit, e, storeMeta)
221
+ commit(types.SET_LAST_COMPLETED_REQUEST, {
222
+ completedAt: Date.now(),
223
+ error: e?.message || String(e || ''),
224
+ requestKey,
225
+ status: 'error',
226
+ });
227
+ }
228
+ throw e;
229
+ })
230
+ .finally(() => {
231
+ if (getters.activeRequestKey === requestKey) {
232
+ commit(types.SET_ACTIVE_REQUEST_KEY, '')
233
+ commit(types.SET_ISLOADING, false);
234
+ commit(types.SET_ISLOADINGLIST, false)
235
+ }
236
+ });
237
+ };
238
+
239
+ export const getItems = ({commit, getters}, params = {}) => {
240
+ //if (getters.offline) return getOfflineItems({commit, getters}, params); else
241
+ return getOnlineItems({commit, getters}, params);
242
+ };
243
+
244
+ export const get = ({commit, getters}, id) => {
245
+ const {payload: requestId, storeMeta} = splitStoreActionPayload(id)
246
+ const normalizedId = String(requestId?.id ?? requestId ?? '').replace(/\D/g, '')
247
+ commit(types.SET_ISLOADING, true);
248
+ commit(types.SET_ERROR, null);
249
+ // Refreshes that need the current record to stay mounted can opt out of the
250
+ // destructive intermediate clear by passing `__storeMeta.preserveItem = true`.
251
+ if (storeMeta.preserveItem !== true && getters.item != null) commit(types.SET_ITEM, {});
252
+ return api
253
+ .fetch(
254
+ getters.resourceEndpoint + '/' + normalizedId,
255
+
256
+ {},
257
+ )
258
+ .then(data => {
259
+ commit(types.SET_ERROR, null);
260
+ commit(types.SET_ITEM, data);
261
+ if (normalizedId) {
262
+ commit(types.SET_LOADED_KEY, normalizedId);
263
+ commit(types.SET_LOADED_AT, Date.now());
264
+ }
265
+ if (getters.offline) saveOffline({commit, getters}, data);
266
+ return data;
267
+ })
268
+ .catch(e => {
269
+ commitStoreError(commit, e, storeMeta)
270
+ throw e;
271
+ })
272
+ .finally(() => {
273
+ commit(types.SET_ISLOADING, false);
274
+ });
275
+ };
276
+
277
+ export const save = ({commit, getters}, params) => {
278
+ const {payload: requestParams, storeMeta} = splitStoreActionPayload(params)
279
+ let id = requestParams?.id?.toString().replace(/\D/g, '');
280
+ delete requestParams.id;
281
+
282
+ let options = {
283
+ method: id ? 'PUT' : 'POST',
284
+ body: requestParams,
285
+ };
286
+ commit(types.SET_ISSAVING, true);
287
+ commit(types.SET_ERROR, null);
288
+
289
+ return api
290
+ .fetch(getters.resourceEndpoint + (id ? '/' + id : ''), options)
291
+ .then(data => {
292
+ commit(types.SET_ERROR, null);
293
+ delete data['@context'];
294
+ let items = getters.items ? [...getters.items] : [];
295
+ if (id) {
296
+ const index = items.findIndex(i => {
297
+ return i['@id'].replace(/\D/g, '') === id;
298
+ });
299
+ if (index >= 0) items[index] = data;
300
+ else items.push(data);
301
+ } else items.push(data);
302
+ commit(types.SET_ITEMS, items);
303
+ return data;
304
+ })
305
+ .catch(e => {
306
+ commitStoreError(commit, e, storeMeta)
307
+ throw e;
308
+ })
309
+ .finally(() => {
310
+ commit(types.SET_ISSAVING, false);
311
+ });
312
+ };
313
+
314
+ export const remove = ({commit, getters}, id) => {
315
+ const {payload: requestId, storeMeta} = splitStoreActionPayload(id)
316
+ id = String(requestId?.id ?? requestId ?? '').replace(/\D/g, '');
317
+ let options = {
318
+ method: 'DELETE',
319
+ };
320
+ commit(types.SET_ISSAVING, true);
321
+ commit(types.SET_ERROR, null);
322
+
323
+ return api
324
+ .fetch(getters.resourceEndpoint + '/' + id, options)
325
+ .then(() => {
326
+ commit(types.SET_ERROR, null);
327
+ let items = getters.items ? [...getters.items] : [];
328
+ const index = items.findIndex(i => {
329
+ if (i && i['@id']) return i['@id'].toString().replace(/\D/g, '') === id;
330
+ });
331
+
332
+ if (index >= 0) items.splice(index, 1);
333
+ else items = [];
334
+ commit(types.SET_ITEMS, items);
335
+ return;
336
+ })
337
+ .catch(e => {
338
+ commitStoreError(commit, e, storeMeta)
339
+ throw e;
340
+ })
341
+ .finally(() => {
342
+ commit(types.SET_ISSAVING, false);
343
+ });
344
+ };
345
+
346
+ export const setFilters = ({commit, getters}, params) => {
347
+ commit(types.SET_FILTERS, params);
348
+ };
349
+
350
+ export const setItem = ({commit, getters}, params) => {
351
+ commit(types.SET_ITEM, params);
352
+ };
353
+
354
+ export const setItems = ({commit, getters}, params) => {
355
+ commit(types.SET_ITEMS, params);
356
+ };
357
+
358
+ export const setPrint = ({commit, getters}, params) => {
359
+ commit(types.SET_PRINT, params);
360
+ };
361
+
362
+ export const setReload = ({commit, getters}, reload) => {
363
+ commit(types.SET_RELOAD, reload);
364
+ };
365
+
366
+ export const setError = ({commit, getters}, error) => {
367
+ commit(types.SET_ERROR, error);
368
+ };
369
+
370
+ export const setIsSaving = ({commit, getters}, IsSaving) => {
371
+ commit(types.SET_ISSAVING, IsSaving);
372
+ };
373
+ export const setIsLoading = ({commit, getters}, IsLoading) => {
374
+ commit(types.SET_ISLOADING, IsLoading);
375
+ };
376
+
377
+ export const setTotalItems = ({commit, getters}, totalItems) => {
378
+ commit(types.SET_TOTALITEMS, totalItems);
379
+ };
380
+
381
+ export const setSummary = ({commit, getters}, summary) => {
382
+ commit(types.SET_SUMMARY, summary);
383
+ };
384
+
385
+ export const setColumns = ({commit, getters}, columns) => {
386
+ commit(types.SET_COLUMNS, columns);
387
+ };
388
+
389
+ export const setResourceEndpoint = (
390
+ {commit, getters},
391
+ resourceEndpoint = null,
392
+ ) => {
393
+ commit(types.SET_RESOURCE_ENDPOINT, resourceEndpoint);
394
+ };
395
+
396
+ export const setSelected = ({commit, getters}, selected) => {
397
+ commit(types.SET_SELECTED, selected);
398
+ };
399
+
400
+ export const setMessage = ({commit, getters}, message) => {
401
+ commit(types.SET_MESSAGE, message);
402
+ };
403
+
404
+ export const setMessages = ({commit, getters}, messages) => {
405
+ commit(types.SET_MESSAGES, messages);
406
+ };
407
+
408
+ export const setSelections = ({commit, getters}, selections) => {
409
+ commit(types.SET_SELECTIONS, selections);
410
+ };
411
+
412
+ export const setSelectorModalKey = ({commit, getters}, selectorModalKey) => {
413
+ commit(types.SET_SELECTOR_MODAL_KEY, selectorModalKey);
414
+ };
415
+
416
+ export const setActiveRequestKey = ({commit, getters}, activeRequestKey) => {
417
+ commit(types.SET_ACTIVE_REQUEST_KEY, activeRequestKey);
418
+ };
419
+
420
+ export const setLastCompletedRequest = (
421
+ {commit, getters},
422
+ lastCompletedRequest,
423
+ ) => {
424
+ commit(types.SET_LAST_COMPLETED_REQUEST, lastCompletedRequest);
425
+ };
426
+
427
+ export const setVisibleColumns = ({commit, getters}, visibleColumns) => {
428
+ commit(types.SET_VISIBLECOLUMNS, visibleColumns);
429
+ };
430
+
431
+ export const setIsLoadingList = ({commit, getters}, isLoadingList) => {
432
+ commit(types.SET_ISLOADINGLIST, isLoadingList);
433
+ };
434
+
435
+ export const setStore = ({commit, getters}, store) => {
436
+ commit(types.SET_STORE, store);
437
+ };
438
+
439
+ export const setOffline = ({commit, getters}, offline) => {
440
+ commit(types.SET_OFFLINE, offline);
441
+ };
442
+ export const setPayable = ({commit, getters}, payable) => {
443
+ commit(types.SET_PAYABLE, payable);
444
+ };