@headless-adminapp/app 0.0.17-alpha.22 → 0.0.17-alpha.24
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/builders/CommandBuilder/FormCommandBuilder.js +1 -1
- package/builders/CommandBuilder/SubgridCommandBuilder.js +3 -3
- package/dataform/hooks/useFormSave.js +7 -0
- package/dataform/hooks/useMainFormCommands.d.ts +1 -12
- package/dataform/hooks/useMainFormCommands.js +9 -1
- package/datagrid/DataGridProvider/DataResolver.js +6 -1
- package/datagrid/DataGridProvider/DataSelectionResolve.d.ts +1 -0
- package/datagrid/DataGridProvider/DataSelectionResolve.js +13 -0
- package/package.json +2 -2
- package/transport/RestDataService/index.d.ts +1 -1
- package/transport/RestDataService/index.js +17 -16
|
@@ -132,7 +132,7 @@ var FormCommandBuilder;
|
|
|
132
132
|
if (!(confirmResult === null || confirmResult === void 0 ? void 0 : confirmResult.confirmed)) {
|
|
133
133
|
return;
|
|
134
134
|
}
|
|
135
|
-
context.utility.showProgressIndicator(
|
|
135
|
+
context.utility.showProgressIndicator((0, utils_1.plurialize)(1, localizeSelector((s) => s.status.deleting)) + '...');
|
|
136
136
|
yield context.dataService.deleteRecord(context.primaryControl.logicalName, recordId);
|
|
137
137
|
context.utility.showNotification({
|
|
138
138
|
title: (0, utils_1.plurialize)(1, localizeSelector((s) => s.successNotification.title)),
|
|
@@ -50,7 +50,7 @@ var SubgridCommandBuilder;
|
|
|
50
50
|
onClick: (context) => {
|
|
51
51
|
if (context.secondaryControl.associated) {
|
|
52
52
|
context.navigation.openForm({
|
|
53
|
-
logicalName: context.
|
|
53
|
+
logicalName: context.secondaryControl.schema.logicalName,
|
|
54
54
|
parameters: {
|
|
55
55
|
[context.secondaryControl.associated.refAttributeName]: {
|
|
56
56
|
id: context.secondaryControl.associated.id,
|
|
@@ -62,7 +62,7 @@ var SubgridCommandBuilder;
|
|
|
62
62
|
}
|
|
63
63
|
else {
|
|
64
64
|
context.navigation.openForm({
|
|
65
|
-
logicalName: context.
|
|
65
|
+
logicalName: context.secondaryControl.schema.logicalName,
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
68
|
},
|
|
@@ -119,7 +119,7 @@ var SubgridCommandBuilder;
|
|
|
119
119
|
}
|
|
120
120
|
context.utility.showProgressIndicator(plurialize(recordIds.length, localizeSelector((s) => s.status.deleting)) + '...');
|
|
121
121
|
for (const recordId of recordIds) {
|
|
122
|
-
yield context.dataService.deleteRecord(context.
|
|
122
|
+
yield context.dataService.deleteRecord(context.secondaryControl.logicalName, recordId);
|
|
123
123
|
}
|
|
124
124
|
context.utility.showNotification({
|
|
125
125
|
title: plurialize(recordIds.length, localizeSelector((s) => s.successNotification.title)),
|
|
@@ -17,6 +17,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
17
17
|
};
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.useFormSave = useFormSave;
|
|
20
|
+
// Wrapper - Loader, response message
|
|
21
|
+
// Core - Extract modified fields, prepare operations, perform operations
|
|
22
|
+
const route_1 = require("@headless-adminapp/app/route");
|
|
20
23
|
const react_query_1 = require("@tanstack/react-query");
|
|
21
24
|
const react_1 = require("react");
|
|
22
25
|
const react_hook_form_1 = require("react-hook-form");
|
|
@@ -42,6 +45,7 @@ function useFormSave() {
|
|
|
42
45
|
const { showProgressIndicator, hideProgressIndicator } = (0, useProgressIndicator_1.useProgressIndicator)();
|
|
43
46
|
const openToastNotification = (0, useOpenToastNotification_1.useOpenToastNotification)();
|
|
44
47
|
const client = (0, react_query_1.useQueryClient)();
|
|
48
|
+
const router = (0, route_1.useRouter)();
|
|
45
49
|
function showMessageAfterSave({ isCreatedMode }) {
|
|
46
50
|
// Show notification
|
|
47
51
|
if (!isCreatedMode) {
|
|
@@ -97,6 +101,9 @@ function useFormSave() {
|
|
|
97
101
|
yield client.invalidateQueries({
|
|
98
102
|
queryKey: ['data', 'retriveRecord'],
|
|
99
103
|
});
|
|
104
|
+
if (mode === 'saveandclose') {
|
|
105
|
+
router.back();
|
|
106
|
+
}
|
|
100
107
|
}
|
|
101
108
|
yield client.invalidateQueries({
|
|
102
109
|
queryKey: ['data', 'retriveRecords'],
|
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
import { EntityFormCommandContext } from '@headless-adminapp/core/experience/form';
|
|
2
2
|
import { CommandItemState } from '../../command';
|
|
3
|
-
export declare function useFormControlContext():
|
|
4
|
-
data: any;
|
|
5
|
-
logicalName: string;
|
|
6
|
-
schema: import("@headless-adminapp/core/schema").Schema<import("@headless-adminapp/core/schema").SchemaAttributes>;
|
|
7
|
-
form: import("@headless-adminapp/core/experience/form").Form<import("@headless-adminapp/core/schema").SchemaAttributes>;
|
|
8
|
-
formId: string;
|
|
9
|
-
originalData: import("@headless-adminapp/core/transport").Data<import("@headless-adminapp/core/schema").InferredSchemaType<import("@headless-adminapp/core/schema").SchemaAttributes>> | null;
|
|
10
|
-
recordId: string | number;
|
|
11
|
-
refresh: () => Promise<void>;
|
|
12
|
-
save: (mode?: import("@headless-adminapp/core/experience/form").SaveMode) => Promise<void>;
|
|
13
|
-
readonly: boolean | undefined;
|
|
14
|
-
};
|
|
3
|
+
export declare function useFormControlContext(): EntityFormCommandContext['primaryControl'];
|
|
15
4
|
export declare function useMainFormCommandHandlerContext(): EntityFormCommandContext;
|
|
16
5
|
export declare function useMainFormCommands(): CommandItemState[][];
|
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.useFormControlContext = useFormControlContext;
|
|
4
4
|
exports.useMainFormCommandHandlerContext = useMainFormCommandHandlerContext;
|
|
5
5
|
exports.useMainFormCommands = useMainFormCommands;
|
|
6
|
+
const route_1 = require("@headless-adminapp/app/route");
|
|
7
|
+
const react_1 = require("react");
|
|
6
8
|
const command_1 = require("../../command");
|
|
7
9
|
const context_1 = require("../../mutable/context");
|
|
8
10
|
const context_2 = require("../context");
|
|
@@ -13,6 +15,7 @@ const useFormSave_1 = require("./useFormSave");
|
|
|
13
15
|
const useFormSchema_1 = require("./useFormSchema");
|
|
14
16
|
const useRecordId_1 = require("./useRecordId");
|
|
15
17
|
function useFormControlContext() {
|
|
18
|
+
var _a;
|
|
16
19
|
const schema = (0, useFormSchema_1.useDataFormSchema)();
|
|
17
20
|
const form = (0, context_1.useContextSelector)(context_2.DataFormContext, (state) => state.form);
|
|
18
21
|
const originalData = (0, useFormRecord_1.useFormRecord)();
|
|
@@ -20,8 +23,12 @@ function useFormControlContext() {
|
|
|
20
23
|
const save = (0, useFormSave_1.useFormSave)();
|
|
21
24
|
const refresh = (0, context_1.useContextSelector)(context_2.DataFormContext, (state) => state.refresh);
|
|
22
25
|
const formInstance = (0, useFormInstance_1.useFormInstance)();
|
|
23
|
-
const readonly = (0, useFormIsReadonly_1.useFormIsReadonly)();
|
|
26
|
+
const readonly = (_a = (0, useFormIsReadonly_1.useFormIsReadonly)()) !== null && _a !== void 0 ? _a : false;
|
|
24
27
|
const data = formInstance.watch();
|
|
28
|
+
const router = (0, route_1.useRouter)();
|
|
29
|
+
const close = (0, react_1.useCallback)(() => {
|
|
30
|
+
router.back();
|
|
31
|
+
}, [router]);
|
|
25
32
|
return {
|
|
26
33
|
data,
|
|
27
34
|
logicalName: schema.logicalName,
|
|
@@ -33,6 +40,7 @@ function useFormControlContext() {
|
|
|
33
40
|
refresh,
|
|
34
41
|
save,
|
|
35
42
|
readonly,
|
|
43
|
+
close,
|
|
36
44
|
};
|
|
37
45
|
}
|
|
38
46
|
function useMainFormCommandHandlerContext() {
|
|
@@ -32,7 +32,10 @@ function DataResolver() {
|
|
|
32
32
|
const [columnFilters] = (0, hooks_1.useGridColumnFilter)();
|
|
33
33
|
const gridColumns = (0, hooks_1.useGridColumns)();
|
|
34
34
|
const maxRecords = (_a = (0, hooks_1.useMaxRecords)()) !== null && _a !== void 0 ? _a : MAX_RECORDS;
|
|
35
|
+
const [selectedIds] = (0, hooks_1.useGridSelection)();
|
|
35
36
|
const { schemaStore } = (0, useMetadata_1.useMetadata)();
|
|
37
|
+
const selectedIdsRef = (0, react_1.useRef)(selectedIds);
|
|
38
|
+
selectedIdsRef.current = selectedIds;
|
|
36
39
|
const setState = (0, context_1.useContextSetValue)(context_2.GridContext);
|
|
37
40
|
const [search] = (0, useDebouncedValue_1.useDebouncedValue)(searchText, 500);
|
|
38
41
|
const columns = (0, react_1.useMemo)(() => Array.from(new Set([
|
|
@@ -146,10 +149,12 @@ function DataResolver() {
|
|
|
146
149
|
count: (_c = (_b = data === null || data === void 0 ? void 0 : data.pages) === null || _b === void 0 ? void 0 : _b[0].data.count) !== null && _c !== void 0 ? _c : 0,
|
|
147
150
|
records: (_d = data === null || data === void 0 ? void 0 : data.pages.map((x) => x.data.records).flat()) !== null && _d !== void 0 ? _d : [],
|
|
148
151
|
};
|
|
152
|
+
const selectedIds = selectedIdsRef.current.filter((x) => finalData.records.some((y) => y[schema.idAttribute] === x));
|
|
149
153
|
setState({
|
|
150
154
|
data: finalData,
|
|
155
|
+
selectedIds,
|
|
151
156
|
});
|
|
152
|
-
}, [data, setState]);
|
|
157
|
+
}, [data, setState, schema.idAttribute]);
|
|
153
158
|
(0, react_1.useEffect)(() => {
|
|
154
159
|
setState({
|
|
155
160
|
dataState: {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function DataSelectionResolver(): null;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataSelectionResolver = DataSelectionResolver;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const hooks_1 = require("../hooks");
|
|
6
|
+
function DataSelectionResolver() {
|
|
7
|
+
const data = (0, hooks_1.useGridData)();
|
|
8
|
+
const [selectedIds] = (0, hooks_1.useGridSelection)();
|
|
9
|
+
const selectedIdsRef = (0, react_1.useRef)(selectedIds);
|
|
10
|
+
selectedIdsRef.current = selectedIds;
|
|
11
|
+
(0, react_1.useEffect)(() => { }, [data]);
|
|
12
|
+
return null;
|
|
13
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@headless-adminapp/app",
|
|
3
|
-
"version": "0.0.17-alpha.
|
|
3
|
+
"version": "0.0.17-alpha.24",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"react-hook-form": "7.52.2",
|
|
40
40
|
"yup": "^1.4.0"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "3280eb0e29b7a026f0251771f564b33c123c9bec"
|
|
43
43
|
}
|
|
@@ -3,11 +3,11 @@ import { RetriveRecordsFnOptions, RetriveRecordsResult } from '@headless-adminap
|
|
|
3
3
|
interface RestDataServiceOptions {
|
|
4
4
|
endpoint: string;
|
|
5
5
|
}
|
|
6
|
+
export declare function handleResponseError(response: Response): Promise<void>;
|
|
6
7
|
export declare class RestDataService implements IDataService {
|
|
7
8
|
protected readonly options: RestDataServiceOptions;
|
|
8
9
|
constructor(options: RestDataServiceOptions);
|
|
9
10
|
protected readonly headers: Record<string, string>;
|
|
10
|
-
protected handleResponseError(response: Response): Promise<void>;
|
|
11
11
|
private getHeaders;
|
|
12
12
|
setHeader(name: string, value: string): void;
|
|
13
13
|
removeHeader(name: string): void;
|
|
@@ -10,27 +10,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.RestDataService = void 0;
|
|
13
|
+
exports.handleResponseError = handleResponseError;
|
|
13
14
|
const transport_1 = require("@headless-adminapp/core/transport");
|
|
15
|
+
function handleResponseError(response) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
var _a;
|
|
18
|
+
if (response.ok) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if ((_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.includes('application/json')) {
|
|
22
|
+
const data = yield response.json();
|
|
23
|
+
if (data.error) {
|
|
24
|
+
throw new transport_1.HttpError(response.status, data.error);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
throw new transport_1.HttpError(response.status, response.statusText);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
14
30
|
class RestDataService {
|
|
15
31
|
constructor(options) {
|
|
16
32
|
this.options = options;
|
|
17
33
|
this.headers = {};
|
|
18
34
|
}
|
|
19
|
-
handleResponseError(response) {
|
|
20
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
var _a;
|
|
22
|
-
if (response.ok) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
if ((_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.includes('application/json')) {
|
|
26
|
-
const data = yield response.json();
|
|
27
|
-
if (data.error) {
|
|
28
|
-
throw new transport_1.HttpError(response.status, data.error);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
throw new transport_1.HttpError(response.status, response.statusText);
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
35
|
getHeaders() {
|
|
35
36
|
return Object.assign({ 'content-type': 'application/json' }, this.headers);
|
|
36
37
|
}
|
|
@@ -47,7 +48,7 @@ class RestDataService {
|
|
|
47
48
|
method: 'POST',
|
|
48
49
|
body: JSON.stringify(data),
|
|
49
50
|
});
|
|
50
|
-
yield
|
|
51
|
+
yield handleResponseError(response);
|
|
51
52
|
return response.json();
|
|
52
53
|
});
|
|
53
54
|
}
|