@headless-adminapp/app 1.4.21 → 1.4.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/app/LayoutProvider.js +3 -1
- package/calendar/types.d.ts +2 -1
- package/command/hooks/useBaseCommandHandlerContext.js +4 -1
- package/dataform/DataFormProvider/CalculatedField.js +0 -8
- package/dataform/DataFormProvider/index.js +1 -2
- package/dataform/hooks/useFormSave.js +4 -2
- package/dataform/utils/defaultParameters.d.ts +1 -1
- package/dataform/utils/defaultParameters.js +10 -1
- package/dataform/utils/index.d.ts +20 -0
- package/dataform/utils/index.js +28 -2
- package/package.json +2 -2
- package/providers/PageEntityFormProvider/index.js +2 -1
- package/quickcreate/QuickCreateProvider.d.ts +5 -0
- package/quickcreate/QuickCreateProvider.js +13 -0
- package/quickcreate/context.d.ts +16 -0
- package/quickcreate/context.js +5 -0
- package/quickcreate/hooks/index.d.ts +5 -0
- package/quickcreate/hooks/index.js +13 -0
- package/quickcreate/hooks/useFormSave.d.ts +2 -0
- package/quickcreate/hooks/useFormSave.js +64 -0
- package/quickcreate/hooks/useIsQuickCreateSupported.d.ts +1 -0
- package/quickcreate/hooks/useIsQuickCreateSupported.js +16 -0
- package/quickcreate/hooks/useOpenQuickCreate.d.ts +3 -0
- package/quickcreate/hooks/useOpenQuickCreate.js +58 -0
- package/quickcreate/hooks/useQuickCreateItem.d.ts +1 -0
- package/quickcreate/hooks/useQuickCreateItem.js +8 -0
- package/quickcreate/hooks/useQuickCreateItems.d.ts +1 -0
- package/quickcreate/hooks/useQuickCreateItems.js +8 -0
- package/quickcreate/index.d.ts +1 -0
- package/quickcreate/index.js +5 -0
- package/route/RouteProvider.d.ts +1 -1
- package/route/context.d.ts +1 -18
- package/route/hooks/useRouter.d.ts +1 -1
- package/store/SchemaExperienceStore.d.ts +5 -2
- package/store/SchemaExperienceStore.js +19 -0
package/app/LayoutProvider.js
CHANGED
|
@@ -11,10 +11,12 @@ const locale_1 = require("../locale");
|
|
|
11
11
|
const metadata_1 = require("../metadata");
|
|
12
12
|
const unsaved_changes_1 = require("../navigation/unsaved-changes");
|
|
13
13
|
const progress_indicator_1 = require("../progress-indicator");
|
|
14
|
+
const quickcreate_1 = require("../quickcreate");
|
|
14
15
|
const route_1 = require("../route");
|
|
15
16
|
const toast_notification_1 = require("../toast-notification");
|
|
16
17
|
const transport_1 = require("../transport");
|
|
17
18
|
const context_1 = require("../transport/context");
|
|
19
|
+
const AppProvider_1 = require("./AppProvider");
|
|
18
20
|
const AuthWrapper_1 = require("./AuthWrapper");
|
|
19
21
|
const dataServiceNotProvidedError = new Error('No data service provided');
|
|
20
22
|
const defaultDataService = {
|
|
@@ -41,6 +43,6 @@ const defaultDataService = {
|
|
|
41
43
|
},
|
|
42
44
|
};
|
|
43
45
|
const LayoutProvider = ({ authPlaceholder, authProps, dataService = defaultDataService, fileService, localeProps, metadataProps, queryClient = defaults_1.queryClient, routeProps, children, containers: { DialogContainer, ProgressIndicatorContainer, ToastNotificationContainer, }, }) => {
|
|
44
|
-
return ((0, jsx_runtime_1.jsx)(route_1.RouteProvider, { ...routeProps, children: (0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: queryClient, children: (0, jsx_runtime_1.jsx)(locale_1.LocaleProvider, { ...localeProps, children: (0, jsx_runtime_1.jsx)(metadata_1.MetadataProvider, { ...metadataProps, children: (0, jsx_runtime_1.jsx)(transport_1.DataServiceContext.Provider, { value: dataService, children: (0, jsx_runtime_1.jsx)(context_1.FileServiceContext.Provider, { value: fileService ?? null, children: (0, jsx_runtime_1.jsx)(dialog_1.DialogProvider, { children: (0, jsx_runtime_1.jsx)(progress_indicator_1.ProgressIndicatorProvider, { children: (0, jsx_runtime_1.jsxs)(toast_notification_1.ToastNotificationProvider, { children: [(0, jsx_runtime_1.jsx)(DialogContainer, {}), (0, jsx_runtime_1.jsx)(ProgressIndicatorContainer, {}), (0, jsx_runtime_1.jsx)(ToastNotificationContainer, {}), (0, jsx_runtime_1.jsx)(auth_1.AuthProvider, { ...authProps, children: (0, jsx_runtime_1.jsx)(header_1.HeaderProvider, { children: (0, jsx_runtime_1.jsxs)(AuthWrapper_1.AuthWrapper, { Placeholder: authPlaceholder, children: [(0, jsx_runtime_1.jsx)(unsaved_changes_1.UnsavedChangesRouteGuard, {}), children] }) }) })] }) }) }) }) }) }) }) }) }));
|
|
46
|
+
return ((0, jsx_runtime_1.jsx)(route_1.RouteProvider, { ...routeProps, children: (0, jsx_runtime_1.jsx)(react_query_1.QueryClientProvider, { client: queryClient, children: (0, jsx_runtime_1.jsx)(locale_1.LocaleProvider, { ...localeProps, children: (0, jsx_runtime_1.jsx)(metadata_1.MetadataProvider, { ...metadataProps, children: (0, jsx_runtime_1.jsx)(transport_1.DataServiceContext.Provider, { value: dataService, children: (0, jsx_runtime_1.jsx)(context_1.FileServiceContext.Provider, { value: fileService ?? null, children: (0, jsx_runtime_1.jsx)(dialog_1.DialogProvider, { children: (0, jsx_runtime_1.jsx)(progress_indicator_1.ProgressIndicatorProvider, { children: (0, jsx_runtime_1.jsxs)(toast_notification_1.ToastNotificationProvider, { children: [(0, jsx_runtime_1.jsx)(DialogContainer, {}), (0, jsx_runtime_1.jsx)(ProgressIndicatorContainer, {}), (0, jsx_runtime_1.jsx)(ToastNotificationContainer, {}), (0, jsx_runtime_1.jsx)(auth_1.AuthProvider, { ...authProps, children: (0, jsx_runtime_1.jsx)(header_1.HeaderProvider, { children: (0, jsx_runtime_1.jsxs)(AuthWrapper_1.AuthWrapper, { Placeholder: authPlaceholder, children: [(0, jsx_runtime_1.jsx)(unsaved_changes_1.UnsavedChangesRouteGuard, {}), (0, jsx_runtime_1.jsx)(AppProvider_1.AppProvider, { children: (0, jsx_runtime_1.jsx)(quickcreate_1.QuickCreateProvider, { children: children }) })] }) }) })] }) }) }) }) }) }) }) }) }));
|
|
45
47
|
};
|
|
46
48
|
exports.LayoutProvider = LayoutProvider;
|
package/calendar/types.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { EventContentArg } from '@fullcalendar/core';
|
|
2
2
|
import { AuthSession } from '@headless-adminapp/core/experience/auth';
|
|
3
3
|
import { OpenFormOptions } from '@headless-adminapp/core/experience/command';
|
|
4
|
+
import { RouterInstance } from '@headless-adminapp/core/navigation';
|
|
4
5
|
import { InferredSchemaType, SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
5
|
-
import { InternalRouteResolver
|
|
6
|
+
import { InternalRouteResolver } from '../route/context';
|
|
6
7
|
export interface CalendarEvent {
|
|
7
8
|
id: string;
|
|
8
9
|
title: string;
|
|
@@ -12,6 +12,7 @@ const hooks_2 = require("../../metadata/hooks");
|
|
|
12
12
|
const hooks_3 = require("../../progress-indicator/hooks");
|
|
13
13
|
const useOpenToastNotification_1 = require("../../toast-notification/hooks/useOpenToastNotification");
|
|
14
14
|
const transport_1 = require("../../transport");
|
|
15
|
+
const route_1 = require("@headless-adminapp/app/route");
|
|
15
16
|
function useUtility() {
|
|
16
17
|
const { hideProgressIndicator, showProgressIndicator } = (0, hooks_3.useProgressIndicator)();
|
|
17
18
|
const openAlertDialog = (0, hooks_1.useOpenAlertDialog)();
|
|
@@ -39,9 +40,11 @@ function useUtility() {
|
|
|
39
40
|
}
|
|
40
41
|
function useNavigation() {
|
|
41
42
|
const openForm = (0, navigation_1.useOpenForm)();
|
|
43
|
+
const router = (0, route_1.useRouter)();
|
|
42
44
|
return (0, react_1.useMemo)(() => ({
|
|
43
45
|
openForm,
|
|
44
|
-
|
|
46
|
+
router,
|
|
47
|
+
}), [openForm, router]);
|
|
45
48
|
}
|
|
46
49
|
function useBaseCommandHandlerContext() {
|
|
47
50
|
const dataService = (0, transport_1.useDataService)();
|
|
@@ -54,10 +54,6 @@ const CalculatedField = () => {
|
|
|
54
54
|
}
|
|
55
55
|
const currentValue = formInstanceRef.current.getValues(item.attributeName);
|
|
56
56
|
const newValue = item.handler(record, relatedRecords);
|
|
57
|
-
console.log('Recalculated main record field:', item.attributeName, item, record, relatedRecords, {
|
|
58
|
-
currentValue,
|
|
59
|
-
newValue,
|
|
60
|
-
});
|
|
61
57
|
if (currentValue !== newValue) {
|
|
62
58
|
formInstanceRef.current.setValue(item.attributeName, newValue);
|
|
63
59
|
eventManager.emit(constants_1.EVENT_KEY_ON_FIELD_CHANGE, item.attributeName, newValue, currentValue);
|
|
@@ -70,10 +66,6 @@ const CalculatedField = () => {
|
|
|
70
66
|
}
|
|
71
67
|
const currentValue = formInstanceRef.current.getValues(`${alias}.${indexStr}.${item.attributeName}`);
|
|
72
68
|
const newValue = item.handler(record, {});
|
|
73
|
-
console.log('Subgrid row level calculation:', item.attributeName, item, record, {
|
|
74
|
-
currentValue,
|
|
75
|
-
newValue,
|
|
76
|
-
});
|
|
77
69
|
if (currentValue !== newValue) {
|
|
78
70
|
formInstanceRef.current.setValue(`${alias}.${indexStr}.${item.attributeName}`, newValue);
|
|
79
71
|
eventManager.emit(constants_1.EVENT_KEY_ON_FIELD_CHANGE, `${alias}.${indexStr}.${item.attributeName}`, newValue, currentValue);
|
|
@@ -20,7 +20,6 @@ const DataResolver_1 = require("./DataResolver");
|
|
|
20
20
|
const getRecord_1 = require("./getRecord");
|
|
21
21
|
const InitialValueResolver_1 = require("./InitialValueResolver");
|
|
22
22
|
const ReadonlyInfoResolver_1 = require("./ReadonlyInfoResolver");
|
|
23
|
-
const UnsavedChangesInfoSetter_1 = require("./UnsavedChangesInfoSetter");
|
|
24
23
|
const utils_2 = require("./utils");
|
|
25
24
|
function mergeInitialWithHistory(initialValue, historyState) {
|
|
26
25
|
return {
|
|
@@ -118,5 +117,5 @@ function DataFormProvider(props) {
|
|
|
118
117
|
schemaStore,
|
|
119
118
|
props.commands,
|
|
120
119
|
]);
|
|
121
|
-
return ((0, jsx_runtime_1.jsx)(context_1.DataFormContext.Provider, { value: contextValue, children: (0, jsx_runtime_1.jsxs)(react_hook_form_1.FormProvider, { ...formInstance, children: [(0, jsx_runtime_1.jsx)(DataResolver_1.DataResolver, { retriveRecordFn: props.retriveRecordFn ?? getRecord_1.getRecord }), (0, jsx_runtime_1.jsx)(InitialValueResolver_1.InitialValueResolver, {}), (0, jsx_runtime_1.jsx)(ReadonlyInfoResolver_1.ReadonlyInfoResolver, { setFormReadOnly: setFormReadOnly }), (0, jsx_runtime_1.jsx)(CustomHookExecuter_1.CustomHookExecuter, { useHookFn: props.form.experience.useHookFn }), (0, jsx_runtime_1.jsx)(CalculatedField_1.CalculatedField, {}),
|
|
120
|
+
return ((0, jsx_runtime_1.jsx)(context_1.DataFormContext.Provider, { value: contextValue, children: (0, jsx_runtime_1.jsxs)(react_hook_form_1.FormProvider, { ...formInstance, children: [(0, jsx_runtime_1.jsx)(DataResolver_1.DataResolver, { retriveRecordFn: props.retriveRecordFn ?? getRecord_1.getRecord }), (0, jsx_runtime_1.jsx)(InitialValueResolver_1.InitialValueResolver, {}), (0, jsx_runtime_1.jsx)(ReadonlyInfoResolver_1.ReadonlyInfoResolver, { setFormReadOnly: setFormReadOnly }), (0, jsx_runtime_1.jsx)(CustomHookExecuter_1.CustomHookExecuter, { useHookFn: props.form.experience.useHookFn }), (0, jsx_runtime_1.jsx)(CalculatedField_1.CalculatedField, {}), props.children] }) }));
|
|
122
121
|
}
|
|
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
10
10
|
exports.useFormSave = useFormSave;
|
|
11
11
|
// Wrapper - Loader, response message
|
|
12
12
|
// Core - Extract modified fields, prepare operations, perform operations
|
|
13
|
+
const unsaved_changes_1 = require("@headless-adminapp/app/navigation/unsaved-changes");
|
|
13
14
|
const route_1 = require("@headless-adminapp/app/route");
|
|
14
15
|
const app_1 = require("@headless-adminapp/core/experience/app");
|
|
15
16
|
const react_query_1 = require("@tanstack/react-query");
|
|
@@ -85,12 +86,13 @@ function useFormSave() {
|
|
|
85
86
|
});
|
|
86
87
|
return;
|
|
87
88
|
}
|
|
89
|
+
(0, unsaved_changes_1.setUnsavedChangesInfo)(null);
|
|
88
90
|
if (mode === 'save') {
|
|
89
91
|
if (record) {
|
|
90
92
|
await refresh();
|
|
91
93
|
}
|
|
92
94
|
else {
|
|
93
|
-
router.replace(routeResolver({
|
|
95
|
+
await router.replace(routeResolver({
|
|
94
96
|
type: app_1.PageType.EntityForm,
|
|
95
97
|
logicalName: schema.logicalName,
|
|
96
98
|
id: result.recordId,
|
|
@@ -102,7 +104,7 @@ function useFormSave() {
|
|
|
102
104
|
queryKey: ['data', 'retriveRecord'],
|
|
103
105
|
});
|
|
104
106
|
if (mode === 'saveandclose') {
|
|
105
|
-
router.back();
|
|
107
|
+
await router.back();
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
110
|
await client.invalidateQueries({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RouterInstance } from '@headless-adminapp/app/route/context';
|
|
2
1
|
import { FormExperience } from '@headless-adminapp/core/experience/form';
|
|
2
|
+
import { RouterInstance } from '@headless-adminapp/core/navigation';
|
|
3
3
|
import { Schema } from '@headless-adminapp/core/schema';
|
|
4
4
|
export declare function getFormDefaultParameters(schema: Schema, formExperience: FormExperience, router: RouterInstance): {
|
|
5
5
|
[x: string]: any;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.getFormDefaultParameters = getFormDefaultParameters;
|
|
7
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
4
8
|
function getFormDefaultParameters(schema, formExperience, router) {
|
|
5
9
|
const _values = router.getState('defaultParameters')?.values;
|
|
6
10
|
const _logicalName = router.getState('defaultParameters')?.logicalName;
|
|
@@ -14,7 +18,12 @@ function getFormDefaultParameters(schema, formExperience, router) {
|
|
|
14
18
|
defaultValue = defaultValue.toISOString();
|
|
15
19
|
}
|
|
16
20
|
else if (attribute.type === 'date' && defaultValue === '@now') {
|
|
17
|
-
|
|
21
|
+
if (attribute.format === 'date') {
|
|
22
|
+
defaultValue = (0, dayjs_1.default)().format('YYYY-MM-DD');
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
defaultValue = new Date().toISOString();
|
|
26
|
+
}
|
|
18
27
|
}
|
|
19
28
|
return {
|
|
20
29
|
...acc,
|
|
@@ -60,3 +60,23 @@ export declare const generateValidationSchema: (<A extends SchemaAttributes = Sc
|
|
|
60
60
|
[x: string]: any;
|
|
61
61
|
}, "">) & MemoizedFunction;
|
|
62
62
|
export declare const generateAttributeValidationSchema: ((attribute: Attribute, language: string, strings: FormValidationStringSet, region: string) => yup.Schema<any, any, any, "">) & MemoizedFunction;
|
|
63
|
+
export declare const generateAttributesValidationSchema: (<A extends SchemaAttributes = SchemaAttributes>({ attributes, language, strings, region, }: {
|
|
64
|
+
attributes: A;
|
|
65
|
+
language: string;
|
|
66
|
+
strings: FormValidationStringSet;
|
|
67
|
+
region: string;
|
|
68
|
+
}) => yup.ObjectSchema<{
|
|
69
|
+
[x: string]: any;
|
|
70
|
+
}, yup.AnyObject, {
|
|
71
|
+
[x: string]: any;
|
|
72
|
+
}, "">) & MemoizedFunction;
|
|
73
|
+
export declare const attributesFormValidator: (<A extends SchemaAttributes = SchemaAttributes>({ attributes, language, strings, region, }: {
|
|
74
|
+
attributes: A;
|
|
75
|
+
language: string;
|
|
76
|
+
strings: FormValidationStringSet;
|
|
77
|
+
region: string;
|
|
78
|
+
}) => (values: Record<string, any>, context: any, options: any) => Promise<ResolverResult<{
|
|
79
|
+
[x: string]: any;
|
|
80
|
+
[x: number]: any;
|
|
81
|
+
[x: symbol]: any;
|
|
82
|
+
}>>) & MemoizedFunction;
|
package/dataform/utils/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.generateAttributeValidationSchema = exports.generateValidationSchema = exports.editableSubgridFormValidator = exports.formValidator = exports.saveRecord = void 0;
|
|
26
|
+
exports.attributesFormValidator = exports.generateAttributesValidationSchema = exports.generateAttributeValidationSchema = exports.generateValidationSchema = exports.editableSubgridFormValidator = exports.formValidator = exports.saveRecord = void 0;
|
|
27
27
|
exports.getInitialValues = getInitialValues;
|
|
28
28
|
const phone_1 = require("@headless-adminapp/app/utils/phone");
|
|
29
29
|
const yup_1 = require("@hookform/resolvers/yup");
|
|
@@ -316,7 +316,7 @@ function extendAttributeStringValidationSchema({ attribute, validationSchema, la
|
|
|
316
316
|
// extend the validation schema with the min length
|
|
317
317
|
validationSchema = validationSchema.min(attribute.minLength, `${label}: ${strings.minLength}`);
|
|
318
318
|
}
|
|
319
|
-
if (attribute.pattern) {
|
|
319
|
+
if ('pattern' in attribute && attribute.pattern) {
|
|
320
320
|
// extend the validation schema with the pattern
|
|
321
321
|
validationSchema = validationSchema.matches(new RegExp(attribute.pattern), `${label}: ${strings.invalidFormat}`);
|
|
322
322
|
}
|
|
@@ -388,3 +388,29 @@ exports.generateAttributeValidationSchema = (0, lodash_1.memoize)(function gener
|
|
|
388
388
|
});
|
|
389
389
|
return validationSchema;
|
|
390
390
|
});
|
|
391
|
+
exports.generateAttributesValidationSchema = (0, lodash_1.memoize)(function generateAttributesValidationSchema({ attributes, language, strings, region, }) {
|
|
392
|
+
const columns = Object.keys(attributes);
|
|
393
|
+
return yup.object().shape({
|
|
394
|
+
...columns.reduce((acc, column) => {
|
|
395
|
+
const attribute = attributes[column];
|
|
396
|
+
const validationSchema = (0, exports.generateAttributeValidationSchema)(attribute, language, strings, region);
|
|
397
|
+
return {
|
|
398
|
+
...acc,
|
|
399
|
+
[column]: validationSchema,
|
|
400
|
+
};
|
|
401
|
+
}, {}),
|
|
402
|
+
});
|
|
403
|
+
}, (options) => JSON.stringify(options));
|
|
404
|
+
exports.attributesFormValidator = (0, lodash_1.memoize)(function formValidator({ attributes, language, strings, region, }) {
|
|
405
|
+
return async (values, context, options) => {
|
|
406
|
+
const validator = (0, exports.generateAttributesValidationSchema)({
|
|
407
|
+
attributes,
|
|
408
|
+
language,
|
|
409
|
+
strings,
|
|
410
|
+
region,
|
|
411
|
+
});
|
|
412
|
+
const resolver = (0, yup_1.yupResolver)(validator);
|
|
413
|
+
const result = await resolver(values, context, options);
|
|
414
|
+
return result;
|
|
415
|
+
};
|
|
416
|
+
}, (options) => JSON.stringify(options));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@headless-adminapp/app",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.24",
|
|
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": "3a4c06f1e18f8ac7861647b82d4a4f8cd8f0141c"
|
|
42
42
|
}
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PageEntityFormProvider = PageEntityFormProvider;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const DataFormProvider_1 = require("../../dataform/DataFormProvider");
|
|
6
|
+
const UnsavedChangesInfoSetter_1 = require("../../dataform/DataFormProvider/UnsavedChangesInfoSetter");
|
|
6
7
|
function PageEntityFormProvider({ schema, form, recordId, children, commands, retriveRecordFn, saveRecordFn, }) {
|
|
7
|
-
return ((0, jsx_runtime_1.
|
|
8
|
+
return ((0, jsx_runtime_1.jsxs)(DataFormProvider_1.DataFormProvider, { schema: schema, form: form, recordId: recordId, commands: commands, retriveRecordFn: retriveRecordFn, saveRecordFn: saveRecordFn, children: [(0, jsx_runtime_1.jsx)(UnsavedChangesInfoSetter_1.UnsavedChangesInfoSetter, {}), children] }));
|
|
8
9
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QuickCreateProvider = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const context_1 = require("../mutable/context");
|
|
6
|
+
const context_2 = require("./context");
|
|
7
|
+
const QuickCreateProvider = ({ children }) => {
|
|
8
|
+
const contextState = (0, context_1.useCreateContextStore)({
|
|
9
|
+
items: [],
|
|
10
|
+
});
|
|
11
|
+
return ((0, jsx_runtime_1.jsx)(context_2.QuickCreateContext.Provider, { value: contextState, children: children }));
|
|
12
|
+
};
|
|
13
|
+
exports.QuickCreateProvider = QuickCreateProvider;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Id } from '@headless-adminapp/core';
|
|
2
|
+
import { DataLookup } from '@headless-adminapp/core/attributes';
|
|
3
|
+
export interface QuickCreateOptions {
|
|
4
|
+
logicalName: string;
|
|
5
|
+
formId?: string;
|
|
6
|
+
onCreate?: (value: DataLookup<Id>) => void;
|
|
7
|
+
onCancel?: () => void;
|
|
8
|
+
}
|
|
9
|
+
export type QuickCreateItemState = QuickCreateOptions & {
|
|
10
|
+
id: string;
|
|
11
|
+
isOpen: boolean;
|
|
12
|
+
};
|
|
13
|
+
export interface QuickCreateContextState {
|
|
14
|
+
items: QuickCreateItemState[];
|
|
15
|
+
}
|
|
16
|
+
export declare const QuickCreateContext: import("react").Context<import("../mutable").ContextValue<QuickCreateContextState>>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { useOpenQuickCreate } from './useOpenQuickCreate';
|
|
2
|
+
export { useQuickCreateItem } from './useQuickCreateItem';
|
|
3
|
+
export { useQuickCreateItems } from './useQuickCreateItems';
|
|
4
|
+
export { useFormSave } from './useFormSave';
|
|
5
|
+
export { useIsQuickCreateSupported } from './useIsQuickCreateSupported';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useIsQuickCreateSupported = exports.useFormSave = exports.useQuickCreateItems = exports.useQuickCreateItem = exports.useOpenQuickCreate = void 0;
|
|
4
|
+
var useOpenQuickCreate_1 = require("./useOpenQuickCreate");
|
|
5
|
+
Object.defineProperty(exports, "useOpenQuickCreate", { enumerable: true, get: function () { return useOpenQuickCreate_1.useOpenQuickCreate; } });
|
|
6
|
+
var useQuickCreateItem_1 = require("./useQuickCreateItem");
|
|
7
|
+
Object.defineProperty(exports, "useQuickCreateItem", { enumerable: true, get: function () { return useQuickCreateItem_1.useQuickCreateItem; } });
|
|
8
|
+
var useQuickCreateItems_1 = require("./useQuickCreateItems");
|
|
9
|
+
Object.defineProperty(exports, "useQuickCreateItems", { enumerable: true, get: function () { return useQuickCreateItems_1.useQuickCreateItems; } });
|
|
10
|
+
var useFormSave_1 = require("./useFormSave");
|
|
11
|
+
Object.defineProperty(exports, "useFormSave", { enumerable: true, get: function () { return useFormSave_1.useFormSave; } });
|
|
12
|
+
var useIsQuickCreateSupported_1 = require("./useIsQuickCreateSupported");
|
|
13
|
+
Object.defineProperty(exports, "useIsQuickCreateSupported", { enumerable: true, get: function () { return useIsQuickCreateSupported_1.useIsQuickCreateSupported; } });
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useFormSave = useFormSave;
|
|
4
|
+
const react_query_1 = require("@tanstack/react-query");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
7
|
+
const dataform_1 = require("../../dataform");
|
|
8
|
+
const useMetadata_1 = require("../../metadata/hooks/useMetadata");
|
|
9
|
+
const context_1 = require("../../mutable/context");
|
|
10
|
+
const useOpenToastNotification_1 = require("../../toast-notification/hooks/useOpenToastNotification");
|
|
11
|
+
const transport_1 = require("../../transport");
|
|
12
|
+
function useFormSave() {
|
|
13
|
+
const form = (0, dataform_1.useSelectedForm)();
|
|
14
|
+
const formInstance = (0, react_hook_form_1.useFormContext)();
|
|
15
|
+
const { schemaStore } = (0, useMetadata_1.useMetadata)();
|
|
16
|
+
const schema = (0, dataform_1.useDataFormSchema)();
|
|
17
|
+
const initialValues = (0, context_1.useContextSelector)(dataform_1.DataFormContext, (state) => state.initialValues);
|
|
18
|
+
const dataService = (0, transport_1.useDataService)();
|
|
19
|
+
const openToastNotification = (0, useOpenToastNotification_1.useOpenToastNotification)();
|
|
20
|
+
const saveRecord = (0, context_1.useContextSelector)(dataform_1.DataFormContext, (state) => state.saveRecordFn);
|
|
21
|
+
const client = (0, react_query_1.useQueryClient)();
|
|
22
|
+
const _save = async () => {
|
|
23
|
+
let saveResult = null;
|
|
24
|
+
await formInstance.handleSubmit(async (values) => {
|
|
25
|
+
const result = await saveRecord({
|
|
26
|
+
values,
|
|
27
|
+
form: form,
|
|
28
|
+
record: undefined,
|
|
29
|
+
initialValues: initialValues,
|
|
30
|
+
dataService,
|
|
31
|
+
schema: schema,
|
|
32
|
+
schemaStore,
|
|
33
|
+
});
|
|
34
|
+
if (!result.success) {
|
|
35
|
+
openToastNotification({
|
|
36
|
+
type: result.isError ? 'error' : 'info',
|
|
37
|
+
title: 'Error',
|
|
38
|
+
text: result.message,
|
|
39
|
+
});
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
await client.invalidateQueries({
|
|
43
|
+
queryKey: ['data', 'retriveRecords', schema.logicalName],
|
|
44
|
+
});
|
|
45
|
+
const record = await dataService.retriveRecord(schema.logicalName, result.recordId, [
|
|
46
|
+
schema.idAttribute,
|
|
47
|
+
schema.primaryAttribute,
|
|
48
|
+
schema.avatarAttribute,
|
|
49
|
+
].filter(Boolean));
|
|
50
|
+
saveResult = {
|
|
51
|
+
id: record[schema.idAttribute],
|
|
52
|
+
name: record[schema.primaryAttribute],
|
|
53
|
+
avatar: schema.avatarAttribute
|
|
54
|
+
? record[schema.avatarAttribute]
|
|
55
|
+
: undefined,
|
|
56
|
+
};
|
|
57
|
+
})();
|
|
58
|
+
return saveResult;
|
|
59
|
+
};
|
|
60
|
+
const _saveRef = (0, react_1.useRef)(_save);
|
|
61
|
+
_saveRef.current = _save;
|
|
62
|
+
const save = (0, react_1.useCallback)(() => _saveRef.current(), [_saveRef]);
|
|
63
|
+
return save;
|
|
64
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useIsQuickCreateSupported(logicalName: string): boolean | undefined;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useIsQuickCreateSupported = useIsQuickCreateSupported;
|
|
4
|
+
const metadata_1 = require("@headless-adminapp/app/metadata");
|
|
5
|
+
const react_query_1 = require("@tanstack/react-query");
|
|
6
|
+
function useIsQuickCreateSupported(logicalName) {
|
|
7
|
+
const experienceStore = (0, metadata_1.useExperienceStore)();
|
|
8
|
+
const { data: isSupported } = (0, react_query_1.useQuery)({
|
|
9
|
+
queryKey: ['experience-schema-quick-create-form-supported', logicalName],
|
|
10
|
+
queryFn: async () => {
|
|
11
|
+
return experienceStore.getIsQuickCreateSupported(logicalName);
|
|
12
|
+
},
|
|
13
|
+
staleTime: 1000 * 60 * 5, // 5 minutes
|
|
14
|
+
});
|
|
15
|
+
return isSupported;
|
|
16
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useOpenQuickCreate = useOpenQuickCreate;
|
|
4
|
+
const mutable_1 = require("@headless-adminapp/app/mutable");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const uuid_1 = require("uuid");
|
|
7
|
+
const context_1 = require("../context");
|
|
8
|
+
function markAsClosed(items, id) {
|
|
9
|
+
return items.map((item) => {
|
|
10
|
+
if (item.id === id) {
|
|
11
|
+
return { ...item, isOpen: false };
|
|
12
|
+
}
|
|
13
|
+
return item;
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function excludeItemById(items, id) {
|
|
17
|
+
return items.filter((item) => item.id !== id);
|
|
18
|
+
}
|
|
19
|
+
function useOpenQuickCreate() {
|
|
20
|
+
const setValue = (0, mutable_1.useContextSetValue)(context_1.QuickCreateContext);
|
|
21
|
+
const openQuickCreate = (0, react_1.useCallback)((options) => {
|
|
22
|
+
const id = (0, uuid_1.v4)();
|
|
23
|
+
const close = (id) => {
|
|
24
|
+
setValue((state) => ({
|
|
25
|
+
items: markAsClosed(state.items, id),
|
|
26
|
+
}));
|
|
27
|
+
// Simulate a delay to show the dialog closing animation
|
|
28
|
+
setTimeout(() => {
|
|
29
|
+
setValue((state) => ({
|
|
30
|
+
items: excludeItemById(state.items, id),
|
|
31
|
+
}));
|
|
32
|
+
}, 1000);
|
|
33
|
+
};
|
|
34
|
+
return new Promise((resolve) => {
|
|
35
|
+
setValue((state) => {
|
|
36
|
+
return {
|
|
37
|
+
items: [
|
|
38
|
+
...state.items,
|
|
39
|
+
{
|
|
40
|
+
...options,
|
|
41
|
+
id,
|
|
42
|
+
isOpen: true,
|
|
43
|
+
onCancel: () => {
|
|
44
|
+
close(id);
|
|
45
|
+
resolve(null);
|
|
46
|
+
},
|
|
47
|
+
onCreate: (value) => {
|
|
48
|
+
close(id);
|
|
49
|
+
resolve(value);
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}, [setValue]);
|
|
57
|
+
return openQuickCreate;
|
|
58
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useQuickCreateItem(id: string): import("../context").QuickCreateItemState | undefined;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useQuickCreateItem = useQuickCreateItem;
|
|
4
|
+
const context_1 = require("../../mutable/context");
|
|
5
|
+
const context_2 = require("../context");
|
|
6
|
+
function useQuickCreateItem(id) {
|
|
7
|
+
return (0, context_1.useContextSelector)(context_2.QuickCreateContext, (state) => state.items.find((item) => item.id === id));
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useQuickCreateItems(): import("../context").QuickCreateItemState[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useQuickCreateItems = useQuickCreateItems;
|
|
4
|
+
const context_1 = require("../../mutable/context");
|
|
5
|
+
const context_2 = require("../context");
|
|
6
|
+
function useQuickCreateItems() {
|
|
7
|
+
return (0, context_1.useContextSelector)(context_2.QuickCreateContext, (state) => state.items);
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { QuickCreateProvider } from './QuickCreateProvider';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QuickCreateProvider = void 0;
|
|
4
|
+
var QuickCreateProvider_1 = require("./QuickCreateProvider");
|
|
5
|
+
Object.defineProperty(exports, "QuickCreateProvider", { enumerable: true, get: function () { return QuickCreateProvider_1.QuickCreateProvider; } });
|
package/route/RouteProvider.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IsRouteActive, RouteResolver } from '@headless-adminapp/core/experience/route';
|
|
2
|
+
import { RouterInstance } from '@headless-adminapp/core/navigation';
|
|
2
3
|
import { FC, PropsWithChildren } from 'react';
|
|
3
|
-
import { RouterInstance } from './context';
|
|
4
4
|
import { ReadonlyURLSearchParams } from './types';
|
|
5
5
|
export interface RouteProviderProps {
|
|
6
6
|
router: RouterInstance;
|
package/route/context.d.ts
CHANGED
|
@@ -1,24 +1,8 @@
|
|
|
1
1
|
import { NavPageItem } from '@headless-adminapp/core/experience/app';
|
|
2
|
+
import { RouterInstance } from '@headless-adminapp/core/navigation';
|
|
2
3
|
import { ReadonlyURLSearchParams } from './types';
|
|
3
4
|
export type InternalRouteResolver = (item: NavPageItem) => string;
|
|
4
5
|
export type InternalIsRouteActive = (path: string, item: NavPageItem) => boolean;
|
|
5
|
-
interface NavigateOptions {
|
|
6
|
-
state?: any;
|
|
7
|
-
}
|
|
8
|
-
export type GuardFn = () => boolean | Promise<boolean>;
|
|
9
|
-
export interface RouterInstance {
|
|
10
|
-
back: () => Promise<void>;
|
|
11
|
-
forward: () => Promise<void>;
|
|
12
|
-
push(href: string, options?: NavigateOptions): Promise<void>;
|
|
13
|
-
replace(href: string, options?: NavigateOptions): Promise<void>;
|
|
14
|
-
prefetch(href: string): void;
|
|
15
|
-
setState(state: any): void;
|
|
16
|
-
setState(key: string, state: any): void;
|
|
17
|
-
getState<T = any>(): T;
|
|
18
|
-
getState<T = any>(key: string): T | undefined;
|
|
19
|
-
registerGuard(fn: GuardFn): void;
|
|
20
|
-
unregisterGuard(fn: GuardFn): void;
|
|
21
|
-
}
|
|
22
6
|
export declare const RouterContext: import("react").Context<RouterInstance>;
|
|
23
7
|
export declare const RouterPathnameContext: import("react").Context<string>;
|
|
24
8
|
export declare const RouterSearchParamsContext: import("react").Context<ReadonlyURLSearchParams>;
|
|
@@ -28,4 +12,3 @@ export interface RouteHelperContext {
|
|
|
28
12
|
isRouteActive: InternalIsRouteActive;
|
|
29
13
|
}
|
|
30
14
|
export declare const RouteHelperContext: import("react").Context<RouteHelperContext>;
|
|
31
|
-
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function useRouter(): import("
|
|
1
|
+
export declare function useRouter(): import("@headless-adminapp/core/navigation").RouterInstance;
|
|
@@ -21,8 +21,11 @@ export declare class SchemaExperienceStore implements ISchemaExperienceStore {
|
|
|
21
21
|
getViewLookupV2<S extends SchemaAttributes = SchemaAttributes>(logicalName: string, viewId?: string): Promise<View<S>>;
|
|
22
22
|
getDefaultViewId(logicalName: string): Promise<string>;
|
|
23
23
|
getDefaultViewLookupId(logicalName: string): Promise<string>;
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
getDefaultFormId(logicalName: string): Promise<string>;
|
|
25
|
+
getDefaultQuickCreateFormId(logicalName: string): Promise<string | null>;
|
|
26
|
+
getIsQuickCreateSupported(logicalName: string): Promise<boolean>;
|
|
27
|
+
getForm<S extends SchemaAttributes = SchemaAttributes>(logicalName: string, formId?: string): Promise<Form<S>>;
|
|
28
|
+
getQuickCreateForm<S extends SchemaAttributes = SchemaAttributes>(logicalName: string, formId?: string): Promise<QuickCreateForm<S>>;
|
|
26
29
|
getViewCommands(logicalName: string): Promise<EntityMainGridCommandItemExperience[][] | undefined>;
|
|
27
30
|
getFormCommands(logicalName: string): Promise<EntityMainFormCommandItemExperience[][] | undefined>;
|
|
28
31
|
getSubgridCommands(logicalName: string): Promise<SubGridCommandItemExperience[][] | undefined>;
|
|
@@ -151,6 +151,19 @@ class SchemaExperienceStore {
|
|
|
151
151
|
const experience = await this.getExperience(logicalName);
|
|
152
152
|
return experience.defaultLookupId;
|
|
153
153
|
}
|
|
154
|
+
async getDefaultFormId(logicalName) {
|
|
155
|
+
const experience = await this.getExperience(logicalName);
|
|
156
|
+
return experience.defaultFormId;
|
|
157
|
+
}
|
|
158
|
+
async getDefaultQuickCreateFormId(logicalName) {
|
|
159
|
+
const experience = await this.getExperience(logicalName);
|
|
160
|
+
return experience.defaultQuickCreateFormId ?? null;
|
|
161
|
+
}
|
|
162
|
+
async getIsQuickCreateSupported(logicalName) {
|
|
163
|
+
const experience = await this.getExperience(logicalName);
|
|
164
|
+
return (!!experience.defaultQuickCreateFormId &&
|
|
165
|
+
experience.quickCreateForms.length > 0);
|
|
166
|
+
}
|
|
154
167
|
async getForm(logicalName, formId) {
|
|
155
168
|
const experience = await this.getExperience(logicalName);
|
|
156
169
|
if (!formId) {
|
|
@@ -173,6 +186,12 @@ class SchemaExperienceStore {
|
|
|
173
186
|
}
|
|
174
187
|
async getQuickCreateForm(logicalName, formId) {
|
|
175
188
|
const experience = await this.getExperience(logicalName);
|
|
189
|
+
if (!formId) {
|
|
190
|
+
if (!experience.defaultQuickCreateFormId) {
|
|
191
|
+
throw new Error(`No quick create form ID provided and no default quick create form ID found for ${logicalName}`);
|
|
192
|
+
}
|
|
193
|
+
formId = experience.defaultQuickCreateFormId;
|
|
194
|
+
}
|
|
176
195
|
const form = experience.quickCreateForms.find((f) => f.id === formId);
|
|
177
196
|
if (!form) {
|
|
178
197
|
throw new Error(`Quick create form ${formId} not found`);
|