@headless-adminapp/app 1.5.5 → 1.5.7
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/dataform/utils/saveRecord.js +9 -16
- package/datagrid/DataGridProvider/DataResolver.d.ts +1 -2
- package/datagrid/DataGridProvider/DataResolver.js +9 -8
- package/datagrid/context.d.ts +2 -2
- package/datagrid/hooks/useGridSelection.d.ts +2 -1
- package/datagrid/hooks/useMainGridCommands.js +2 -1
- package/datagrid/hooks/useOpenRecord.js +3 -2
- package/package.json +2 -2
- package/quickcreate/hooks/useFormSave.js +3 -2
- package/recordset/hooks/useRecordSetResult.js +2 -1
- package/transport/InMemoryDataService/index.js +2 -1
|
@@ -3,7 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getModifiedValues = getModifiedValues;
|
|
4
4
|
exports.saveRecord = saveRecord;
|
|
5
5
|
exports.saveEditableGridControl = saveEditableGridControl;
|
|
6
|
-
const utils_1 = require("
|
|
6
|
+
const utils_1 = require("@headless-adminapp/core/transport/utils");
|
|
7
|
+
const utils_2 = require("../DataFormProvider/utils");
|
|
7
8
|
function getModifiedValues(
|
|
8
9
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
10
|
initialValues,
|
|
@@ -47,8 +48,8 @@ function generateSubgridUpdateOperation({ recordId, control, schemaStore, values
|
|
|
47
48
|
const newRows = gridRows.filter((x) => !x[gridSchema.idAttribute]);
|
|
48
49
|
const updatedRows = gridRows.filter((x) => x[gridSchema.idAttribute]);
|
|
49
50
|
const deletedIds = initialGridRows
|
|
50
|
-
?.map((x) =>
|
|
51
|
-
.filter((id) => !gridRows.find((x) =>
|
|
51
|
+
?.map((x) => (0, utils_1.getRecordId)(gridSchema, x))
|
|
52
|
+
.filter((id) => !gridRows.find((x) => (0, utils_1.getRecordId)(gridSchema, x) === id));
|
|
52
53
|
for (const row of newRows) {
|
|
53
54
|
operations.push({
|
|
54
55
|
type: 'create',
|
|
@@ -63,7 +64,7 @@ function generateSubgridUpdateOperation({ recordId, control, schemaStore, values
|
|
|
63
64
|
});
|
|
64
65
|
}
|
|
65
66
|
for (const row of updatedRows) {
|
|
66
|
-
const initialRow = initialGridRows.find((x) =>
|
|
67
|
+
const initialRow = initialGridRows.find((x) => (0, utils_1.getRecordId)(gridSchema, x) === (0, utils_1.getRecordId)(gridSchema, row));
|
|
67
68
|
if (!initialRow) {
|
|
68
69
|
throw new Error('Initial row not found');
|
|
69
70
|
}
|
|
@@ -75,7 +76,7 @@ function generateSubgridUpdateOperation({ recordId, control, schemaStore, values
|
|
|
75
76
|
type: 'update',
|
|
76
77
|
logicalName: control.logicalName,
|
|
77
78
|
data: modifiedRow,
|
|
78
|
-
id:
|
|
79
|
+
id: (0, utils_1.getRecordId)(gridSchema, row),
|
|
79
80
|
});
|
|
80
81
|
}
|
|
81
82
|
for (const id of deletedIds) {
|
|
@@ -88,7 +89,7 @@ function generateSubgridUpdateOperation({ recordId, control, schemaStore, values
|
|
|
88
89
|
return operations;
|
|
89
90
|
}
|
|
90
91
|
async function createRecord({ values, form, schema, dataService, }) {
|
|
91
|
-
const controls = (0,
|
|
92
|
+
const controls = (0, utils_2.getControls)(form);
|
|
92
93
|
const editableGridControls = controls.filter((control) => control.type === 'editablegrid' && control.alias);
|
|
93
94
|
const result = await dataService.createRecord(schema.logicalName, values);
|
|
94
95
|
const recordId = result.id;
|
|
@@ -107,7 +108,7 @@ async function createRecord({ values, form, schema, dataService, }) {
|
|
|
107
108
|
return recordId;
|
|
108
109
|
}
|
|
109
110
|
async function updateRecord({ recordId, values, form, schema, dataService, initialValues, schemaStore, }) {
|
|
110
|
-
const controls = (0,
|
|
111
|
+
const controls = (0, utils_2.getControls)(form);
|
|
111
112
|
const editableGridControls = controls.filter((control) => control.type === 'editablegrid' && control.alias);
|
|
112
113
|
const modifiedValues = getModifiedValues(initialValues, values, editableGridControls.map((x) => x.alias));
|
|
113
114
|
const operations = [];
|
|
@@ -148,15 +149,7 @@ async function updateRecord({ recordId, values, form, schema, dataService, initi
|
|
|
148
149
|
async function saveRecord({ values, form, schema, dataService, initialValues, record, schemaStore, }) {
|
|
149
150
|
let recordId;
|
|
150
151
|
if (record) {
|
|
151
|
-
const
|
|
152
|
-
if (typeof idAttributeValue === 'object' &&
|
|
153
|
-
idAttributeValue !== null &&
|
|
154
|
-
'id' in idAttributeValue) {
|
|
155
|
-
recordId = idAttributeValue.id;
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
recordId = idAttributeValue;
|
|
159
|
-
}
|
|
152
|
+
const recordId = (0, utils_1.getRecordId)(schema, record);
|
|
160
153
|
const updateResult = await updateRecord({
|
|
161
154
|
recordId: recordId,
|
|
162
155
|
values,
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare function DataResolver<S extends SchemaAttributes = SchemaAttributes>(): null;
|
|
1
|
+
export declare function DataResolver(): null;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DataResolver = DataResolver;
|
|
4
|
+
const utils_1 = require("@headless-adminapp/core/transport/utils");
|
|
4
5
|
const react_1 = require("react");
|
|
5
6
|
const auth_1 = require("../../auth");
|
|
6
7
|
const hooks_1 = require("../../hooks");
|
|
@@ -12,7 +13,7 @@ const context_2 = require("../context");
|
|
|
12
13
|
const hooks_2 = require("../hooks");
|
|
13
14
|
const useGridDisabled_1 = require("../hooks/useGridDisabled");
|
|
14
15
|
const useQuickFilter_1 = require("../hooks/useQuickFilter");
|
|
15
|
-
const
|
|
16
|
+
const utils_2 = require("./utils");
|
|
16
17
|
function DataResolver() {
|
|
17
18
|
const schema = (0, hooks_2.useDataGridSchema)();
|
|
18
19
|
const view = (0, hooks_2.useSelectedView)();
|
|
@@ -33,14 +34,14 @@ function DataResolver() {
|
|
|
33
34
|
const [search] = (0, useDebouncedValue_1.useDebouncedValue)(searchText, 500);
|
|
34
35
|
const isMobile = (0, hooks_1.useIsMobile)();
|
|
35
36
|
const columns = (0, react_1.useMemo)(() => isMobile
|
|
36
|
-
? (0,
|
|
37
|
-
: (0,
|
|
37
|
+
? (0, utils_2.collectCardColumns)({ cardView: view.experience.card, schema })
|
|
38
|
+
: (0, utils_2.collectGridColumns)({
|
|
38
39
|
gridColumns,
|
|
39
40
|
schema,
|
|
40
41
|
}), [isMobile, view.experience.card, schema, gridColumns]);
|
|
41
42
|
const expand = (0, react_1.useMemo)(() => isMobile
|
|
42
|
-
? (0,
|
|
43
|
-
: (0,
|
|
43
|
+
? (0, utils_2.collectCardExpandedKeys)({ cardView: view.experience.card })
|
|
44
|
+
: (0, utils_2.collectExpandedKeys)(gridColumns), [gridColumns, isMobile, view.experience.card]);
|
|
44
45
|
const quickFilterResults = (0, react_1.useMemo)(() => {
|
|
45
46
|
if (!quickFilter) {
|
|
46
47
|
return null;
|
|
@@ -51,7 +52,7 @@ function DataResolver() {
|
|
|
51
52
|
return quickFilter.resolver(quickFilterValues, authSession);
|
|
52
53
|
}, [authSession, quickFilter, quickFilterValues]);
|
|
53
54
|
const filter = (0, react_1.useMemo)(() => {
|
|
54
|
-
return (0,
|
|
55
|
+
return (0, utils_2.mergeConditions)(schema, view.experience.filter, extraFilter, quickFilterResults, columnFilters, schemaStore);
|
|
55
56
|
}, [
|
|
56
57
|
columnFilters,
|
|
57
58
|
extraFilter,
|
|
@@ -85,12 +86,12 @@ function DataResolver() {
|
|
|
85
86
|
});
|
|
86
87
|
return;
|
|
87
88
|
}
|
|
88
|
-
const selectedIds = selectedIdsRef.current.filter((x) => data.records.some((y) =>
|
|
89
|
+
const selectedIds = selectedIdsRef.current.filter((x) => data.records.some((y) => (0, utils_1.getRecordId)(schema, y) === x));
|
|
89
90
|
setState({
|
|
90
91
|
data,
|
|
91
92
|
selectedIds,
|
|
92
93
|
});
|
|
93
|
-
}, [data, setState, schema
|
|
94
|
+
}, [data, setState, schema]);
|
|
94
95
|
(0, react_1.useEffect)(() => {
|
|
95
96
|
setState({
|
|
96
97
|
dataState: {
|
package/datagrid/context.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LocalizedDataLookup } from '@headless-adminapp/core/attributes';
|
|
1
|
+
import type { Id, LocalizedDataLookup } from '@headless-adminapp/core/attributes';
|
|
2
2
|
import type { CommandItemExperience } from '@headless-adminapp/core/experience/command';
|
|
3
3
|
import type { ColumnCondition, EntityMainGridCommandContext, EntitySubGridCommandContext, SortingState, View } from '@headless-adminapp/core/experience/view';
|
|
4
4
|
import { type TransformedViewColumn } from '@headless-adminapp/core/experience/view/ViewColumn';
|
|
@@ -24,7 +24,7 @@ export interface GridContextState<S extends SchemaAttributes = SchemaAttributes,
|
|
|
24
24
|
columnFilters: Partial<Record<keyof S, ColumnCondition>>;
|
|
25
25
|
sorting: SortingState<Extract<keyof S, string>>;
|
|
26
26
|
quickFilterValues: Record<string, unknown>;
|
|
27
|
-
selectedIds:
|
|
27
|
+
selectedIds: Id[];
|
|
28
28
|
cellSelectionRange?: CellSelectionRange | null;
|
|
29
29
|
data: RetriveRecordsResult<InferredSchemaType<S>> | null;
|
|
30
30
|
dataState: {
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Id } from '@headless-adminapp/core';
|
|
2
|
+
export declare function useGridSelection(): readonly [Id[], (selectedIds: Id[] | ((previousIds: Id[]) => Id[])) => void];
|
|
@@ -7,6 +7,7 @@ exports.useMainGridCommands = useMainGridCommands;
|
|
|
7
7
|
exports.useMainGridContextCommands = useMainGridContextCommands;
|
|
8
8
|
const app_1 = require("@headless-adminapp/app/app");
|
|
9
9
|
const mutable_1 = require("@headless-adminapp/app/mutable");
|
|
10
|
+
const utils_1 = require("@headless-adminapp/core/transport/utils");
|
|
10
11
|
const react_1 = require("react");
|
|
11
12
|
const command_1 = require("../../command");
|
|
12
13
|
const hooks_1 = require("../../dialog/hooks");
|
|
@@ -63,7 +64,7 @@ function useGridControlContext() {
|
|
|
63
64
|
return obj;
|
|
64
65
|
}, [selectedIds]);
|
|
65
66
|
const selectedRecords = (0, react_1.useMemo)(() => {
|
|
66
|
-
return (data?.records ?? []).filter((record) => selectedIdsObj[record
|
|
67
|
+
return (data?.records ?? []).filter((record) => selectedIdsObj[(0, utils_1.getRecordId)(schema, record)]);
|
|
67
68
|
}, [data, schema, selectedIdsObj]);
|
|
68
69
|
return (0, react_1.useMemo)(() => ({
|
|
69
70
|
data,
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useOpenRecord = useOpenRecord;
|
|
4
4
|
const route_1 = require("@headless-adminapp/app/route");
|
|
5
5
|
const app_1 = require("@headless-adminapp/core/experience/app");
|
|
6
|
+
const utils_1 = require("@headless-adminapp/core/transport/utils");
|
|
6
7
|
const react_1 = require("react");
|
|
7
8
|
const useGridData_1 = require("./useGridData");
|
|
8
9
|
const useGridSchema_1 = require("./useGridSchema");
|
|
@@ -23,12 +24,12 @@ function useOpenRecord() {
|
|
|
23
24
|
state: {
|
|
24
25
|
navigator: logicalName === schema.logicalName
|
|
25
26
|
? {
|
|
26
|
-
ids: dataRef.current?.records.map((x) =>
|
|
27
|
+
ids: dataRef.current?.records.map((x) => (0, utils_1.getRecordId)(schema, x)) ?? [],
|
|
27
28
|
visible: false,
|
|
28
29
|
logicalName: schema.logicalName,
|
|
29
30
|
}
|
|
30
31
|
: null,
|
|
31
32
|
},
|
|
32
33
|
});
|
|
33
|
-
}, [routeResolver, router, schema
|
|
34
|
+
}, [routeResolver, router, schema]);
|
|
34
35
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@headless-adminapp/app",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.7",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"uuid": "11.0.3",
|
|
39
39
|
"yup": "^1.4.0"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "85010c33721181b76d6973993ce504e3c5d54aef"
|
|
42
42
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useFormSave = useFormSave;
|
|
4
|
+
const utils_1 = require("@headless-adminapp/core/transport/utils");
|
|
4
5
|
const react_query_1 = require("@tanstack/react-query");
|
|
5
6
|
const react_1 = require("react");
|
|
6
7
|
const react_hook_form_1 = require("react-hook-form");
|
|
@@ -48,8 +49,8 @@ function useFormSave() {
|
|
|
48
49
|
schema.avatarAttribute,
|
|
49
50
|
].filter(Boolean));
|
|
50
51
|
saveResult = {
|
|
51
|
-
id:
|
|
52
|
-
name:
|
|
52
|
+
id: (0, utils_1.getRecordId)(schema, record),
|
|
53
|
+
name: (0, utils_1.getRecordPrimaryName)(schema, record),
|
|
53
54
|
avatar: schema.avatarAttribute
|
|
54
55
|
? record[schema.avatarAttribute]
|
|
55
56
|
: undefined,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useRecordSetResult = useRecordSetResult;
|
|
4
|
+
const utils_1 = require("@headless-adminapp/core/transport/utils");
|
|
4
5
|
const react_query_1 = require("@tanstack/react-query");
|
|
5
6
|
const lodash_1 = require("lodash");
|
|
6
7
|
const react_1 = require("react");
|
|
@@ -55,7 +56,7 @@ function useRecordSetResult() {
|
|
|
55
56
|
sort: [],
|
|
56
57
|
limit: context.ids.length,
|
|
57
58
|
});
|
|
58
|
-
const sortedData = (0, lodash_1.sortBy)(result.records, (x) => context.ids.indexOf(
|
|
59
|
+
const sortedData = (0, lodash_1.sortBy)(result.records, (x) => context.ids.indexOf((0, utils_1.getRecordId)(schema, x)));
|
|
59
60
|
return sortedData;
|
|
60
61
|
},
|
|
61
62
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InMemoryDataService = void 0;
|
|
4
|
+
const utils_1 = require("@headless-adminapp/core/transport/utils");
|
|
4
5
|
class InMemoryDataService {
|
|
5
6
|
options;
|
|
6
7
|
// , IActionService, IReportService
|
|
@@ -24,7 +25,7 @@ class InMemoryDataService {
|
|
|
24
25
|
const schema = this.getSchema(logicalName);
|
|
25
26
|
const records = this.getCollection(logicalName);
|
|
26
27
|
const record = records.find((record) => {
|
|
27
|
-
return
|
|
28
|
+
return (0, utils_1.getRecordId)(schema, record) === id;
|
|
28
29
|
});
|
|
29
30
|
if (!record) {
|
|
30
31
|
throw new Error(`Record with id ${id} not found`);
|