@headless-adminapp/app 0.0.17-alpha.8 → 1.0.0
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/AppProvider.d.ts +0 -3
- package/app/AppProvider.js +10 -33
- package/app/AuthWrapper.d.ts +1 -1
- package/app/AuthWrapper.js +4 -1
- package/app/LayoutProvider.d.ts +8 -7
- package/app/LayoutProvider.js +28 -2
- package/app/context.d.ts +1 -1
- package/auth/AuthProvider.d.ts +1 -1
- package/auth/AuthProvider.js +30 -23
- package/auth/context.d.ts +2 -0
- package/auth/hooks/useIsSkipAuthCheck.d.ts +1 -0
- package/auth/hooks/useIsSkipAuthCheck.js +8 -0
- package/auth/hooks/useLogout.js +1 -1
- package/board/BoardColumnDataResolver.d.ts +1 -0
- package/board/BoardColumnDataResolver.js +64 -0
- package/board/BoardColumnProvider.d.ts +7 -0
- package/board/BoardColumnProvider.js +36 -0
- package/board/context.d.ts +19 -0
- package/board/context.js +6 -0
- package/board/hooks/index.d.ts +6 -0
- package/board/hooks/index.js +15 -0
- package/board/hooks/useBoardColumnConfig.d.ts +2 -0
- package/board/hooks/useBoardColumnConfig.js +8 -0
- package/board/hooks/useBoardColumnData.d.ts +3 -0
- package/board/hooks/useBoardColumnData.js +9 -0
- package/board/hooks/useBoardColumnDataState.d.ts +5 -0
- package/board/hooks/useBoardColumnDataState.js +9 -0
- package/board/hooks/useBoardConfig.d.ts +3 -0
- package/board/hooks/useBoardConfig.js +8 -0
- package/board/hooks/useBoardSchema.d.ts +2 -0
- package/board/hooks/useBoardSchema.js +7 -0
- package/board/hooks/useSearchText.d.ts +1 -0
- package/board/hooks/useSearchText.js +14 -0
- package/board/types.d.ts +47 -0
- package/board/utils.d.ts +3 -0
- package/board/utils.js +6 -0
- package/builders/CommandBuilder/DefaultCommandBuilder.d.ts +15 -6
- package/builders/CommandBuilder/DefaultCommandBuilder.js +42 -20
- package/builders/CommandBuilder/FormCommandBuilder.d.ts +14 -13
- package/builders/CommandBuilder/FormCommandBuilder.js +66 -52
- package/builders/CommandBuilder/SubgridCommandBuilder.d.ts +8 -27
- package/builders/CommandBuilder/SubgridCommandBuilder.js +115 -57
- package/builders/CommandBuilder/ViewCommandBuilder.js +32 -52
- package/builders/CommandBuilder/utils.js +1 -1
- package/builders/DefineFormExperience.d.ts +27 -0
- package/builders/DefineFormExperience.js +99 -0
- package/builders/DefineViewExperience.d.ts +13 -0
- package/builders/DefineViewExperience.js +33 -0
- package/builders/SchemaExperienceBuilder.d.ts +9 -7
- package/builders/SchemaExperienceBuilder.js +62 -40
- package/builders/utils.js +30 -44
- package/calendar/baseEventAttributes.d.ts +35 -0
- package/calendar/baseEventAttributes.js +38 -0
- package/calendar/context.d.ts +6 -0
- package/calendar/context.js +5 -0
- package/calendar/hooks/index.d.ts +1 -0
- package/{appearance → calendar}/hooks/index.js +1 -1
- package/calendar/hooks/useConfig.d.ts +3 -0
- package/calendar/hooks/useConfig.js +8 -0
- package/calendar/types.d.ts +41 -0
- package/calendar/types.js +2 -0
- package/calendar/utils.d.ts +3 -0
- package/calendar/utils.js +6 -0
- package/command/hooks/useBaseCommandHandlerContext.js +15 -6
- package/command/hooks/useCommands.js +1 -1
- package/command/utils/index.js +34 -9
- package/components/ScrollView/index.d.ts +1 -1
- package/components/ScrollView/index.js +2 -2
- package/components/ScrollbarWithMoreDataRequest/index.d.ts +9 -0
- package/components/ScrollbarWithMoreDataRequest/index.js +32 -0
- package/dataform/DataFormProvider/CustomHookExecuter.d.ts +5 -0
- package/dataform/DataFormProvider/CustomHookExecuter.js +14 -0
- package/dataform/DataFormProvider/DataResolver.d.ts +6 -4
- package/dataform/DataFormProvider/DataResolver.js +11 -94
- package/dataform/DataFormProvider/InitialValueResolver.js +3 -2
- package/dataform/DataFormProvider/ReadonlyInfoResolver.js +2 -3
- package/dataform/DataFormProvider/getRecord.d.ts +3 -0
- package/dataform/DataFormProvider/getRecord.js +56 -0
- package/dataform/DataFormProvider/index.d.ts +4 -0
- package/dataform/DataFormProvider/index.js +34 -12
- package/dataform/DataFormProvider/types.d.ts +13 -0
- package/dataform/DataFormProvider/types.js +2 -0
- package/dataform/DataFormProvider/utils.d.ts +23 -0
- package/dataform/DataFormProvider/utils.js +105 -0
- package/dataform/FormManager.d.ts +57 -0
- package/dataform/FormManager.js +247 -0
- package/dataform/constants.d.ts +1 -0
- package/dataform/constants.js +4 -0
- package/dataform/context.d.ts +26 -1
- package/dataform/hooks/index.d.ts +11 -0
- package/dataform/hooks/index.js +11 -0
- package/dataform/hooks/useContextKey.d.ts +1 -0
- package/dataform/hooks/useContextKey.js +8 -0
- package/dataform/hooks/useDisabledControlsManager.d.ts +6 -0
- package/dataform/hooks/useDisabledControlsManager.js +46 -0
- package/dataform/hooks/useEventManager.d.ts +1 -0
- package/dataform/hooks/useEventManager.js +8 -0
- package/dataform/hooks/useFormManager.d.ts +2 -0
- package/dataform/hooks/useFormManager.js +13 -0
- package/dataform/hooks/useFormNotifications.js +2 -2
- package/dataform/hooks/useFormSave.js +28 -31
- package/dataform/hooks/useHiddenControlsManager.d.ts +7 -0
- package/dataform/hooks/useHiddenControlsManager.js +50 -0
- package/dataform/hooks/useIsControlDisabled.d.ts +1 -0
- package/dataform/hooks/useIsControlDisabled.js +27 -0
- package/dataform/hooks/useIsControlHiddenByAttributeName.d.ts +1 -0
- package/dataform/hooks/useIsControlHiddenByAttributeName.js +17 -0
- package/dataform/hooks/useIsControlHiddenByKey.d.ts +1 -0
- package/dataform/hooks/useIsControlHiddenByKey.js +17 -0
- package/dataform/hooks/useIsFieldRequired.d.ts +1 -0
- package/dataform/hooks/useIsFieldRequired.js +25 -0
- package/dataform/hooks/useLoadFormGridPage.js +8 -17
- package/dataform/hooks/useMainFormCommands.d.ts +1 -12
- package/dataform/hooks/useMainFormCommands.js +13 -3
- package/dataform/hooks/useOnFieldValueChangeListener.d.ts +1 -0
- package/dataform/hooks/useOnFieldValueChangeListener.js +30 -0
- package/dataform/hooks/useProcessFlowSteps.d.ts +1 -0
- package/dataform/hooks/useProcessFlowSteps.js +45 -0
- package/dataform/hooks/useRecordTitle.d.ts +3 -1
- package/dataform/hooks/useRecordTitle.js +12 -5
- package/dataform/hooks/useRequiredFieldManager.d.ts +6 -0
- package/dataform/hooks/useRequiredFieldManager.js +49 -0
- package/dataform/test.d.ts +57 -0
- package/dataform/test.js +247 -0
- package/dataform/utils/defaultParameters.d.ts +6 -0
- package/dataform/utils/defaultParameters.js +54 -0
- package/dataform/utils/index.d.ts +6 -24
- package/dataform/utils/index.js +164 -190
- package/dataform/utils/saveRecord.d.ts +27 -0
- package/dataform/utils/saveRecord.js +163 -0
- package/datagrid/DataGridProvider/DataResolver.js +38 -109
- package/datagrid/DataGridProvider/index.d.ts +6 -0
- package/datagrid/DataGridProvider/index.js +18 -8
- package/datagrid/DataGridProvider/transformViewColumns.js +10 -2
- package/datagrid/DataGridProvider/utils.js +8 -8
- package/datagrid/column-filter/constants.js +38 -3
- package/datagrid/column-filter/utils.js +7 -1
- package/datagrid/context.d.ts +6 -0
- package/datagrid/hooks/useChangeView.js +1 -1
- package/datagrid/hooks/useGridColumnFilter.js +4 -1
- package/datagrid/hooks/useGridDisabled.d.ts +1 -0
- package/datagrid/hooks/useGridDisabled.js +8 -0
- package/datagrid/hooks/useLoadMainGridPage.js +1 -1
- package/datagrid/hooks/useMainGridCommands.js +23 -9
- package/datagrid/hooks/useOpenRecord.js +2 -2
- package/datagrid/hooks/useSubGridCommands.js +23 -45
- package/defaults.d.ts +2 -0
- package/defaults.js +5 -0
- package/dialog/hooks/useCloseDialog.js +17 -15
- package/dialog/hooks/useOpenAlertDialog.js +8 -3
- package/dialog/hooks/useOpenConfirmDialog.js +10 -4
- package/dialog/hooks/useOpenDialog.js +7 -5
- package/dialog/hooks/useOpenErrorDialog.js +8 -3
- package/dialog/hooks/useOpenPromptDialog.js +10 -4
- package/form/FormValidationStringContext.d.ts +1 -0
- package/form/FormValidationStringContext.js +1 -0
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +3 -0
- package/hooks/useDebouncedValue.js +0 -1
- package/hooks/useElementLayout.js +1 -1
- package/hooks/useIsMobile.js +0 -1
- package/hooks/useItemsWithKey.d.ts +7 -0
- package/hooks/useItemsWithKey.js +13 -0
- package/hooks/useStorageState.js +1 -2
- package/hooks/useSystemColorScheme.d.ts +1 -1
- package/hooks/useSystemColorScheme.js +0 -1
- package/insights/InsightsProvider.d.ts +8 -0
- package/insights/InsightsProvider.js +27 -0
- package/locale/LocaleProvider.d.ts +2 -1
- package/locale/LocaleProvider.js +3 -3
- package/locale/index.d.ts +1 -0
- package/locale/index.js +1 -0
- package/locale/useCurrencySymbol.d.ts +1 -0
- package/locale/useCurrencySymbol.js +12 -0
- package/locale/utils.js +4 -2
- package/metadata/MetadataProvider.d.ts +8 -4
- package/metadata/MetadataProvider.js +23 -17
- package/metadata/context.d.ts +3 -2
- package/metadata/hooks/index.d.ts +1 -1
- package/metadata/hooks/index.js +1 -1
- package/metadata/hooks/useAppExperience.d.ts +1 -0
- package/metadata/hooks/useAppExperience.js +8 -0
- package/metadata/hooks/useAppStore.d.ts +1 -1
- package/metadata/hooks/useAppStore.js +3 -3
- package/metadata/hooks/useExperienceView.js +2 -11
- package/metadata/hooks/useExperienceViewCommands.d.ts +1 -1
- package/metadata/hooks/useExperienceViewCommands.js +5 -14
- package/metadata/hooks/useExperienceViewLookup.js +2 -11
- package/metadata/hooks/useExperienceViewSubgridCommands.d.ts +1 -1
- package/metadata/hooks/useExperienceViewSubgridCommands.js +5 -14
- package/metadata/hooks/useMetadata.d.ts +11 -10
- package/metadata/hooks/useMetadata.js +4 -16
- package/metadata/hooks/useSchema.d.ts +1 -1
- package/metadata/hooks/useSchema.js +3 -0
- package/mutable/context.d.ts +3 -0
- package/mutable/context.js +8 -0
- package/mutable/utils.js +5 -12
- package/navigation/hooks/useOpenForm.js +4 -0
- package/package.json +6 -10
- package/providers/PageEntityFormProvider/index.d.ts +5 -1
- package/providers/PageEntityFormProvider/index.js +2 -2
- package/recordset/hooks/useRecordSetResult.js +4 -14
- package/route/RouteProvider.d.ts +2 -2
- package/route/RouteProvider.js +4 -1
- package/store/ClientAppStore.js +7 -20
- package/store/ComponentStore.d.ts +1 -1
- package/store/ComponentStore.js +6 -12
- package/store/EventManager.d.ts +2 -2
- package/store/EventManager.js +13 -29
- package/store/SchemaExperienceStore.js +179 -215
- package/store/index.d.ts +0 -1
- package/store/index.js +0 -1
- package/toast-notification/hooks/useCloseToastNotification.js +17 -15
- package/toast-notification/hooks/useOpenToastNotification.js +7 -5
- package/transport/InMemoryDataService/index.js +54 -77
- package/transport/RestDataService/index.d.ts +3 -3
- package/transport/RestDataService/index.js +68 -91
- package/transport/context.d.ts +2 -1
- package/transport/context.js +7 -1
- package/transport/hooks/index.d.ts +1 -0
- package/transport/hooks/index.js +1 -0
- package/transport/hooks/useFileService.d.ts +1 -0
- package/transport/hooks/useFileService.js +9 -0
- package/transport/hooks/useRetriveRecords.d.ts +33 -0
- package/transport/hooks/useRetriveRecords.js +110 -0
- package/utils/calculateColumnWidths.js +1 -1
- package/utils/color.d.ts +1 -0
- package/utils/color.js +14 -0
- package/utils/getAttributeFormattedValue.d.ts +4 -1
- package/utils/getAttributeFormattedValue.js +109 -54
- package/utils/phone.d.ts +13 -0
- package/utils/phone.js +33 -0
- package/appearance/context.d.ts +0 -7
- package/appearance/context.js +0 -5
- package/appearance/hooks/index.d.ts +0 -1
- package/appearance/hooks/useAppearanceContext.d.ts +0 -1
- package/appearance/hooks/useAppearanceContext.js +0 -12
- package/appearance/index.d.ts +0 -2
- package/appearance/index.js +0 -20
- package/builders/CommandBuilder.d.ts +0 -176
- package/builders/CommandBuilder.js +0 -567
- package/locale/types.d.ts +0 -2
- /package/{locale → board}/types.js +0 -0
package/command/utils/index.js
CHANGED
|
@@ -8,8 +8,7 @@ function transformedProperties(command, handlerContext) {
|
|
|
8
8
|
const disabled = (0, utils_1.checkCommandCondition)(handlerContext, command.disabled);
|
|
9
9
|
const onClick = command.onClick
|
|
10
10
|
? () => {
|
|
11
|
-
|
|
12
|
-
(_a = command.onClick(handlerContext)) === null || _a === void 0 ? void 0 : _a.catch(console.error);
|
|
11
|
+
command.onClick(handlerContext)?.catch(console.error);
|
|
13
12
|
}
|
|
14
13
|
: undefined;
|
|
15
14
|
return {
|
|
@@ -23,11 +22,33 @@ function transformCommand(command, handlerContext) {
|
|
|
23
22
|
const commandType = command.type;
|
|
24
23
|
switch (command.type) {
|
|
25
24
|
case 'icon':
|
|
26
|
-
return
|
|
25
|
+
return {
|
|
26
|
+
type: command.type,
|
|
27
|
+
isQuickAction: command.isQuickAction,
|
|
28
|
+
danger: command.danger,
|
|
29
|
+
iconPosition: command.iconPosition,
|
|
30
|
+
...transformedProperties(command, handlerContext),
|
|
31
|
+
};
|
|
27
32
|
case 'button':
|
|
28
|
-
return
|
|
33
|
+
return {
|
|
34
|
+
type: command.type,
|
|
35
|
+
isQuickAction: command.isQuickAction,
|
|
36
|
+
text: command.text,
|
|
37
|
+
danger: command.danger,
|
|
38
|
+
iconPosition: command.iconPosition,
|
|
39
|
+
localizedTexts: command.localizedText,
|
|
40
|
+
...transformedProperties(command, handlerContext),
|
|
41
|
+
};
|
|
29
42
|
case 'menu':
|
|
30
|
-
return
|
|
43
|
+
return {
|
|
44
|
+
type: command.type,
|
|
45
|
+
text: command.text,
|
|
46
|
+
danger: command.danger,
|
|
47
|
+
localizedTexts: command.localizedTexts,
|
|
48
|
+
iconPosition: command.iconPosition,
|
|
49
|
+
...transformedProperties(command, handlerContext),
|
|
50
|
+
items: command.items.map((item) => transformMenuItems(item, handlerContext)),
|
|
51
|
+
};
|
|
31
52
|
default:
|
|
32
53
|
throw new Error(`Unknown command type: ${commandType}`);
|
|
33
54
|
}
|
|
@@ -36,14 +57,18 @@ function transformMenuItems(items, handlerContext) {
|
|
|
36
57
|
return items.map((item) => transformMenuItem(item, handlerContext));
|
|
37
58
|
}
|
|
38
59
|
function transformMenuItem(item, handlerContext) {
|
|
39
|
-
|
|
40
|
-
|
|
60
|
+
return {
|
|
61
|
+
danger: item.danger,
|
|
62
|
+
text: item.text,
|
|
63
|
+
localizedTexts: item.localizedTexts,
|
|
64
|
+
...transformedProperties(item, handlerContext),
|
|
65
|
+
items: item.items?.map((item) => transformMenuItems(item, handlerContext)),
|
|
66
|
+
};
|
|
41
67
|
}
|
|
42
68
|
function transformCommandGroup(group, handlerContext, selector) {
|
|
43
69
|
return group
|
|
44
70
|
.map((command) => {
|
|
45
|
-
|
|
46
|
-
if (!((_a = selector === null || selector === void 0 ? void 0 : selector(command)) !== null && _a !== void 0 ? _a : true)) {
|
|
71
|
+
if (!(selector?.(command) ?? true)) {
|
|
47
72
|
return false; // Skip command
|
|
48
73
|
}
|
|
49
74
|
const transformedCommand = transformCommand(command, handlerContext);
|
|
@@ -6,6 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.ScrollView = void 0;
|
|
7
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
8
|
const clsx_1 = __importDefault(require("clsx"));
|
|
9
|
-
const react_custom_scrollbars_2_1 =
|
|
10
|
-
const ScrollView = ({ children, className, rtl, autoHide, onScroll, }) => ((0, jsx_runtime_1.jsx)(react_custom_scrollbars_2_1.
|
|
9
|
+
const react_custom_scrollbars_2_1 = require("react-custom-scrollbars-2");
|
|
10
|
+
const ScrollView = ({ children, className, rtl, autoHide, onScroll, }) => ((0, jsx_runtime_1.jsx)(react_custom_scrollbars_2_1.Scrollbars, { autoHide: autoHide, className: (0, clsx_1.default)(className, 'hdl-scrollbar', rtl && 'rtl'), onScroll: onScroll, children: children }));
|
|
11
11
|
exports.ScrollView = ScrollView;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FC, PropsWithChildren } from 'react';
|
|
2
|
+
interface ScrollbarWithMoreDataRequest {
|
|
3
|
+
data: any;
|
|
4
|
+
hasMore: boolean;
|
|
5
|
+
onRequestMore: () => void;
|
|
6
|
+
rtl?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const ScrollbarWithMoreDataRequest: FC<PropsWithChildren<ScrollbarWithMoreDataRequest>>;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ScrollbarWithMoreDataRequest = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const ScrollView_1 = require("../ScrollView");
|
|
7
|
+
function getReaminingSpace(div) {
|
|
8
|
+
return div.scrollHeight - div.scrollTop - div.clientHeight;
|
|
9
|
+
}
|
|
10
|
+
const ScrollbarWithMoreDataRequest = ({ data, onRequestMore, hasMore, children, rtl }) => {
|
|
11
|
+
const divRef = (0, react_1.useRef)(null);
|
|
12
|
+
const onRequestMoreRef = (0, react_1.useRef)(onRequestMore);
|
|
13
|
+
onRequestMoreRef.current = onRequestMore;
|
|
14
|
+
(0, react_1.useEffect)(() => {
|
|
15
|
+
const div = divRef.current?.parentElement;
|
|
16
|
+
if (!div) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const remainingSpace = getReaminingSpace(div);
|
|
20
|
+
if (remainingSpace <= 0 && hasMore) {
|
|
21
|
+
onRequestMoreRef.current();
|
|
22
|
+
}
|
|
23
|
+
}, [data, hasMore]);
|
|
24
|
+
return ((0, jsx_runtime_1.jsx)(ScrollView_1.ScrollView, { autoHide: true, rtl: rtl, onScroll: (e) => {
|
|
25
|
+
const div = e.target;
|
|
26
|
+
const remainingSpace = getReaminingSpace(div);
|
|
27
|
+
if (remainingSpace <= 0 && hasMore) {
|
|
28
|
+
onRequestMoreRef.current();
|
|
29
|
+
}
|
|
30
|
+
}, children: (0, jsx_runtime_1.jsx)("div", { ref: divRef, children: children }) }));
|
|
31
|
+
};
|
|
32
|
+
exports.ScrollbarWithMoreDataRequest = ScrollbarWithMoreDataRequest;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomHookExecuter = CustomHookExecuter;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
function CustomHookExecuter({ useHookFn, }) {
|
|
6
|
+
if (!useHookFn) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
return (0, jsx_runtime_1.jsx)(CustomHookExecuterInternal, { useHookFn: useHookFn });
|
|
10
|
+
}
|
|
11
|
+
function CustomHookExecuterInternal({ useHookFn, }) {
|
|
12
|
+
useHookFn();
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import { Form } from '@headless-adminapp/core/experience/form';
|
|
2
1
|
import { SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
import { RetriveRecordFn } from './types';
|
|
3
|
+
interface DataResolverProps<SA extends SchemaAttributes> {
|
|
4
|
+
retriveRecordFn: RetriveRecordFn<SA>;
|
|
5
|
+
}
|
|
6
|
+
export declare function DataResolver<SA extends SchemaAttributes>({ retriveRecordFn, }: DataResolverProps<SA>): null;
|
|
7
|
+
export {};
|
|
@@ -1,113 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getControls = getControls;
|
|
13
|
-
exports.getColumns = getColumns;
|
|
14
3
|
exports.DataResolver = DataResolver;
|
|
15
|
-
const transport_1 = require("@headless-adminapp/core/transport");
|
|
16
4
|
const react_query_1 = require("@tanstack/react-query");
|
|
17
5
|
const react_1 = require("react");
|
|
18
6
|
const hooks_1 = require("../../metadata/hooks");
|
|
19
7
|
const mutable_1 = require("../../mutable");
|
|
20
|
-
const
|
|
8
|
+
const transport_1 = require("../../transport");
|
|
21
9
|
const context_1 = require("../context");
|
|
22
10
|
const hooks_2 = require("../hooks");
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
.flatMap((tab) => tab.tabColumns)
|
|
26
|
-
.flatMap((tabColumn) => tabColumn.sections)
|
|
27
|
-
.flatMap((section) => section.controls);
|
|
28
|
-
return controls;
|
|
29
|
-
}
|
|
30
|
-
function getColumns(form) {
|
|
31
|
-
var _a;
|
|
32
|
-
const columns = Array.from(new Set([
|
|
33
|
-
...((_a = form.experience.includeAttributes) !== null && _a !== void 0 ? _a : []),
|
|
34
|
-
...form.experience.headerControls,
|
|
35
|
-
...getControls(form)
|
|
36
|
-
.filter((control) => control.type === 'standard')
|
|
37
|
-
.map((control) => control.attributeName),
|
|
38
|
-
]));
|
|
39
|
-
return columns;
|
|
40
|
-
}
|
|
41
|
-
function getRecord(_a) {
|
|
42
|
-
return __awaiter(this, arguments, void 0, function* ({ recordId, dataService, form, schema, columns, schemaStore, }) {
|
|
43
|
-
var _b;
|
|
44
|
-
let record = null;
|
|
45
|
-
try {
|
|
46
|
-
record = yield dataService.retriveRecord(schema.logicalName, recordId, columns);
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
if (error instanceof transport_1.HttpError && error.status === 404) {
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
throw error;
|
|
53
|
-
}
|
|
54
|
-
if (!record) {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
const controls = getControls(form);
|
|
58
|
-
const editableGridControls = controls.filter((control) => control.type === 'editablegrid');
|
|
59
|
-
for (const control of editableGridControls) {
|
|
60
|
-
if (control.type !== 'editablegrid') {
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
const controlSchema = schemaStore.getSchema(control.logicalName);
|
|
64
|
-
const records = yield dataService.retriveRecords({
|
|
65
|
-
logicalName: controlSchema.logicalName,
|
|
66
|
-
filter: {
|
|
67
|
-
type: 'and',
|
|
68
|
-
conditions: [
|
|
69
|
-
{
|
|
70
|
-
field: control.referenceAttribute,
|
|
71
|
-
operator: 'eq',
|
|
72
|
-
value: recordId,
|
|
73
|
-
},
|
|
74
|
-
],
|
|
75
|
-
},
|
|
76
|
-
sort: [
|
|
77
|
-
{
|
|
78
|
-
field: (_b = controlSchema.createdAtAttribute) !== null && _b !== void 0 ? _b : controlSchema.idAttribute,
|
|
79
|
-
order: 'asc',
|
|
80
|
-
},
|
|
81
|
-
],
|
|
82
|
-
limit: 5000,
|
|
83
|
-
search: '',
|
|
84
|
-
columns: [
|
|
85
|
-
controlSchema.idAttribute,
|
|
86
|
-
control.referenceAttribute,
|
|
87
|
-
...control.attributes,
|
|
88
|
-
],
|
|
89
|
-
});
|
|
90
|
-
record[control.attributeName] = records.records;
|
|
91
|
-
}
|
|
92
|
-
return record;
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
function DataResolver() {
|
|
11
|
+
const utils_1 = require("./utils");
|
|
12
|
+
function DataResolver({ retriveRecordFn, }) {
|
|
96
13
|
const schema = (0, hooks_2.useDataFormSchema)();
|
|
97
14
|
const form = (0, hooks_2.useSelectedForm)();
|
|
98
|
-
const dataService = (0,
|
|
15
|
+
const dataService = (0, transport_1.useDataService)();
|
|
99
16
|
const recordId = (0, hooks_2.useRecordId)();
|
|
100
17
|
const { schemaStore } = (0, hooks_1.useMetadata)();
|
|
101
18
|
const setState = (0, mutable_1.useContextSetValue)(context_1.DataFormContext);
|
|
102
|
-
const columns = (0, react_1.useMemo)(() => getColumns(form), [form]);
|
|
19
|
+
const columns = (0, react_1.useMemo)(() => (0, utils_1.getColumns)(form, schema), [form, schema]);
|
|
103
20
|
const queryKey = (0, react_1.useMemo)(() => ['data', 'retriveRecord', schema.logicalName, recordId, columns], [columns, recordId, schema.logicalName]);
|
|
104
21
|
const { data, refetch, isPending } = (0, react_query_1.useQuery)({
|
|
105
22
|
queryKey,
|
|
106
|
-
queryFn: () =>
|
|
23
|
+
queryFn: async () => {
|
|
107
24
|
if (!recordId) {
|
|
108
25
|
return null;
|
|
109
26
|
}
|
|
110
|
-
const record =
|
|
27
|
+
const record = retriveRecordFn({
|
|
111
28
|
columns,
|
|
112
29
|
dataService,
|
|
113
30
|
form,
|
|
@@ -116,7 +33,7 @@ function DataResolver() {
|
|
|
116
33
|
schemaStore,
|
|
117
34
|
});
|
|
118
35
|
return record;
|
|
119
|
-
}
|
|
36
|
+
},
|
|
120
37
|
placeholderData: react_query_1.keepPreviousData,
|
|
121
38
|
staleTime: 1000 * 60 * 5, // 5 minutes
|
|
122
39
|
});
|
|
@@ -134,9 +51,9 @@ function DataResolver() {
|
|
|
134
51
|
}, [isPending, setState]);
|
|
135
52
|
(0, react_1.useEffect)(() => {
|
|
136
53
|
setState({
|
|
137
|
-
refresh: () =>
|
|
138
|
-
|
|
139
|
-
}
|
|
54
|
+
refresh: async () => {
|
|
55
|
+
await refetch();
|
|
56
|
+
},
|
|
140
57
|
});
|
|
141
58
|
}, [refetch, setState]);
|
|
142
59
|
return null;
|
|
@@ -6,6 +6,7 @@ const mutable_1 = require("../../mutable");
|
|
|
6
6
|
const context_1 = require("../context");
|
|
7
7
|
const hooks_1 = require("../hooks");
|
|
8
8
|
const utils_1 = require("../utils");
|
|
9
|
+
const defaultParameters_1 = require("../utils/defaultParameters");
|
|
9
10
|
function InitialValueResolver() {
|
|
10
11
|
const formConfig = (0, hooks_1.useSelectedForm)();
|
|
11
12
|
const schema = (0, hooks_1.useDataFormSchema)();
|
|
@@ -13,14 +14,14 @@ function InitialValueResolver() {
|
|
|
13
14
|
const record = (0, mutable_1.useContextSelector)(context_1.DataFormContext, (state) => state.record);
|
|
14
15
|
const formInstance = (0, hooks_1.useFormInstance)();
|
|
15
16
|
const initialValues = (0, react_1.useMemo)(() => {
|
|
17
|
+
const defaultParameters = (0, defaultParameters_1.getFormDefaultParameters)(schema, formConfig.experience) ?? {};
|
|
16
18
|
return (0, utils_1.getInitialValues)({
|
|
17
19
|
cloneRecord: undefined,
|
|
18
20
|
form: formConfig,
|
|
19
21
|
record: record,
|
|
20
22
|
recordId: recordId,
|
|
21
23
|
schema: schema,
|
|
22
|
-
defaultParameters
|
|
23
|
-
// defaultParameters,
|
|
24
|
+
defaultParameters,
|
|
24
25
|
});
|
|
25
26
|
}, [formConfig, record, recordId, schema]);
|
|
26
27
|
const setValue = (0, mutable_1.useContextSetValue)(context_1.DataFormContext);
|
|
@@ -6,14 +6,13 @@ const mutable_1 = require("../../mutable");
|
|
|
6
6
|
const context_1 = require("../context");
|
|
7
7
|
const hooks_1 = require("../hooks");
|
|
8
8
|
function ReadonlyInfoResolver({ setFormReadOnly, }) {
|
|
9
|
-
var _a, _b;
|
|
10
9
|
const schema = (0, hooks_1.useDataFormSchema)();
|
|
11
10
|
const recordId = (0, hooks_1.useRecordId)();
|
|
12
11
|
let readonly = false;
|
|
13
|
-
if (
|
|
12
|
+
if (schema.restrictions?.disableCreate && !recordId) {
|
|
14
13
|
readonly = true;
|
|
15
14
|
}
|
|
16
|
-
if (
|
|
15
|
+
if (schema.restrictions?.disableUpdate && recordId) {
|
|
17
16
|
readonly = true;
|
|
18
17
|
}
|
|
19
18
|
const setValue = (0, mutable_1.useContextSetValue)(context_1.DataFormContext);
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
2
|
+
import { RetriveRecordFnOptions } from './types';
|
|
3
|
+
export declare function getRecord<SA extends SchemaAttributes = SchemaAttributes>({ recordId, dataService, form, schema, columns, schemaStore, }: RetriveRecordFnOptions<SA>): Promise<import("@headless-adminapp/core/transport").Data<SA> | null>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRecord = getRecord;
|
|
4
|
+
const transport_1 = require("@headless-adminapp/core/transport");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
async function getRecord({ recordId, dataService, form, schema, columns, schemaStore, }) {
|
|
7
|
+
let record = null;
|
|
8
|
+
try {
|
|
9
|
+
record = await dataService.retriveRecord(schema.logicalName, recordId, columns);
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
if (error instanceof transport_1.HttpError && error.status === 404) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
throw error;
|
|
16
|
+
}
|
|
17
|
+
if (!record) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const controls = (0, utils_1.getControls)(form);
|
|
21
|
+
const editableGridControls = controls.filter((control) => control.type === 'editablegrid');
|
|
22
|
+
for (const control of editableGridControls) {
|
|
23
|
+
if (control.type !== 'editablegrid') {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
const controlSchema = schemaStore.getSchema(control.logicalName);
|
|
27
|
+
const records = await dataService.retriveRecords({
|
|
28
|
+
logicalName: controlSchema.logicalName,
|
|
29
|
+
filter: {
|
|
30
|
+
type: 'and',
|
|
31
|
+
conditions: [
|
|
32
|
+
{
|
|
33
|
+
field: control.referenceAttribute,
|
|
34
|
+
operator: 'eq',
|
|
35
|
+
value: recordId,
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
sort: [
|
|
40
|
+
{
|
|
41
|
+
field: controlSchema.createdAtAttribute ?? controlSchema.idAttribute,
|
|
42
|
+
order: 'asc',
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
limit: 5000,
|
|
46
|
+
search: '',
|
|
47
|
+
columns: [
|
|
48
|
+
controlSchema.idAttribute,
|
|
49
|
+
control.referenceAttribute,
|
|
50
|
+
...control.attributes,
|
|
51
|
+
],
|
|
52
|
+
});
|
|
53
|
+
record[control.attributeName] = records.records;
|
|
54
|
+
}
|
|
55
|
+
return record;
|
|
56
|
+
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { EntityMainFormCommandItemExperience, Form } from '@headless-adminapp/core/experience/form';
|
|
2
2
|
import { Schema, SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
3
3
|
import { PropsWithChildren } from 'react';
|
|
4
|
+
import { SaveRecordFn } from '../utils/saveRecord';
|
|
5
|
+
import { RetriveRecordFn } from './types';
|
|
4
6
|
export interface DataFormProviderProps<S extends SchemaAttributes = SchemaAttributes> {
|
|
5
7
|
schema: Schema<S>;
|
|
6
8
|
form: Form<S>;
|
|
7
9
|
recordId?: string;
|
|
8
10
|
commands: EntityMainFormCommandItemExperience[][];
|
|
11
|
+
retriveRecordFn?: RetriveRecordFn<S>;
|
|
12
|
+
saveRecordFn?: SaveRecordFn;
|
|
9
13
|
}
|
|
10
14
|
export declare function DataFormProvider<S extends SchemaAttributes = SchemaAttributes>(props: PropsWithChildren<DataFormProviderProps<S>>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.DataFormProvider = DataFormProvider;
|
|
13
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const store_1 = require("@headless-adminapp/app/store");
|
|
14
6
|
const react_1 = require("react");
|
|
15
7
|
const react_hook_form_1 = require("react-hook-form");
|
|
16
8
|
const FormValidationStringContext_1 = require("../../form/FormValidationStringContext");
|
|
@@ -19,13 +11,19 @@ const useMetadata_1 = require("../../metadata/hooks/useMetadata");
|
|
|
19
11
|
const mutable_1 = require("../../mutable");
|
|
20
12
|
const context_1 = require("../context");
|
|
21
13
|
const utils_1 = require("../utils");
|
|
14
|
+
const saveRecord_1 = require("../utils/saveRecord");
|
|
15
|
+
const CustomHookExecuter_1 = require("./CustomHookExecuter");
|
|
22
16
|
const DataResolver_1 = require("./DataResolver");
|
|
17
|
+
const getRecord_1 = require("./getRecord");
|
|
23
18
|
const InitialValueResolver_1 = require("./InitialValueResolver");
|
|
24
19
|
const ReadonlyInfoResolver_1 = require("./ReadonlyInfoResolver");
|
|
20
|
+
const utils_2 = require("./utils");
|
|
25
21
|
function DataFormProvider(props) {
|
|
26
22
|
const { schemaStore } = (0, useMetadata_1.useMetadata)();
|
|
27
|
-
const { language } = (0, useLocale_1.useLocale)();
|
|
23
|
+
const { language, region } = (0, useLocale_1.useLocale)();
|
|
28
24
|
const formValidationStrings = (0, FormValidationStringContext_1.useFormValidationStrings)();
|
|
25
|
+
const eventManager = (0, react_1.useMemo)(() => new store_1.EventManager(), []);
|
|
26
|
+
const contextKey = (0, react_1.useRef)(0);
|
|
29
27
|
const [formReadOnly, setFormReadOnly] = (0, react_1.useState)(false); // A trick to provide readOnly info to formInstance
|
|
30
28
|
const formInstance = (0, react_hook_form_1.useForm)({
|
|
31
29
|
mode: 'all',
|
|
@@ -37,28 +35,52 @@ function DataFormProvider(props) {
|
|
|
37
35
|
schema: props.schema,
|
|
38
36
|
strings: formValidationStrings,
|
|
39
37
|
formReadOnly,
|
|
38
|
+
region,
|
|
40
39
|
}),
|
|
41
40
|
shouldUnregister: false,
|
|
42
41
|
});
|
|
42
|
+
const saveRecordFnRef = (0, react_1.useRef)(props.saveRecordFn);
|
|
43
|
+
saveRecordFnRef.current = props.saveRecordFn;
|
|
44
|
+
const saveRecordFnInternal = (0, react_1.useCallback)(async (options) => {
|
|
45
|
+
return saveRecordFnRef.current
|
|
46
|
+
? saveRecordFnRef.current(options)
|
|
47
|
+
: (0, saveRecord_1.saveRecord)(options);
|
|
48
|
+
}, []);
|
|
43
49
|
const contextValue = (0, mutable_1.useCreateContextStore)({
|
|
50
|
+
contextKey: contextKey.current,
|
|
44
51
|
schema: props.schema,
|
|
45
52
|
form: props.form,
|
|
46
53
|
commands: props.commands,
|
|
47
54
|
dataState: { isFetching: false },
|
|
48
55
|
recordId: props.recordId,
|
|
49
|
-
refresh: () =>
|
|
56
|
+
refresh: async () => { }, // Initial value, will be overridden
|
|
50
57
|
cloneId: undefined,
|
|
51
58
|
// formInstance,
|
|
52
59
|
// formInstanceRenderCount: 0,
|
|
53
60
|
initialValues: {},
|
|
61
|
+
saveRecordFn: saveRecordFnInternal,
|
|
62
|
+
eventManager,
|
|
63
|
+
disabledControls: {},
|
|
64
|
+
requiredFields: {},
|
|
65
|
+
hiddenControls: {},
|
|
66
|
+
hiddenSections: {},
|
|
67
|
+
hiddenTabs: {},
|
|
68
|
+
formInternal: (0, utils_2.transformFormInternal)(props.form),
|
|
54
69
|
});
|
|
55
70
|
(0, react_1.useEffect)(() => {
|
|
56
71
|
contextValue.setValue({
|
|
72
|
+
contextKey: ++contextKey.current,
|
|
57
73
|
form: props.form,
|
|
58
74
|
schema: props.schema,
|
|
59
75
|
recordId: props.recordId,
|
|
60
76
|
cloneId: undefined,
|
|
61
77
|
commands: props.commands,
|
|
78
|
+
disabledControls: {},
|
|
79
|
+
requiredFields: {},
|
|
80
|
+
hiddenControls: {},
|
|
81
|
+
hiddenSections: {},
|
|
82
|
+
hiddenTabs: {},
|
|
83
|
+
formInternal: (0, utils_2.transformFormInternal)(props.form),
|
|
62
84
|
});
|
|
63
85
|
}, [
|
|
64
86
|
props.form,
|
|
@@ -68,5 +90,5 @@ function DataFormProvider(props) {
|
|
|
68
90
|
schemaStore,
|
|
69
91
|
props.commands,
|
|
70
92
|
]);
|
|
71
|
-
return ((0, jsx_runtime_1.jsx)(context_1.DataFormContext.Provider, { value: contextValue, children: (0, jsx_runtime_1.jsxs)(react_hook_form_1.FormProvider,
|
|
93
|
+
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 }), props.children] }) }));
|
|
72
94
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Form } from '@headless-adminapp/core/experience/form';
|
|
2
|
+
import { InferredSchemaType, Schema, SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
3
|
+
import { ISchemaStore } from '@headless-adminapp/core/store';
|
|
4
|
+
import { Data, IDataService } from '@headless-adminapp/core/transport';
|
|
5
|
+
export type RetriveRecordFnOptions<SA extends SchemaAttributes> = {
|
|
6
|
+
recordId: string;
|
|
7
|
+
dataService: IDataService;
|
|
8
|
+
form: Form<SA>;
|
|
9
|
+
schema: Schema<SA>;
|
|
10
|
+
columns: (keyof SA)[];
|
|
11
|
+
schemaStore: ISchemaStore;
|
|
12
|
+
};
|
|
13
|
+
export type RetriveRecordFn<SA extends SchemaAttributes> = (options: RetriveRecordFnOptions<SA>) => Promise<Data<InferredSchemaType<SA>>>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AttributeBase } from '@headless-adminapp/core/attributes/AttributeBase';
|
|
2
|
+
import { Form, Section } from '@headless-adminapp/core/experience/form';
|
|
3
|
+
import { SectionControl, SectionStatndardControl } from '@headless-adminapp/core/experience/form/SectionControl';
|
|
4
|
+
import { Schema, SchemaAttributes } from '@headless-adminapp/core/schema';
|
|
5
|
+
import { DataFormContextState } from '../context';
|
|
6
|
+
export declare function getControls<SA extends SchemaAttributes>(form: Form<SA>): SectionControl<SA>[];
|
|
7
|
+
export declare function getColumns<SA extends SchemaAttributes>(form: Form<SA>, schema: Schema<SA>): (keyof SA)[];
|
|
8
|
+
export declare function transformFormInternal<SA extends SchemaAttributes>(form: Form<SA>): DataFormContextState<SA>['formInternal'];
|
|
9
|
+
export declare function getIsFieldDisabled<S extends SchemaAttributes = SchemaAttributes>({ attribute, isFormReadonly, disabledFields, control, }: {
|
|
10
|
+
attribute: AttributeBase;
|
|
11
|
+
isFormReadonly: boolean | undefined;
|
|
12
|
+
disabledFields: Record<string, boolean>;
|
|
13
|
+
control: Section<S>['controls'][0];
|
|
14
|
+
}): boolean;
|
|
15
|
+
export declare function getIsControlHidden<S extends SchemaAttributes = SchemaAttributes>({ control, hiddenControls, }: {
|
|
16
|
+
hiddenControls: Record<string, boolean>;
|
|
17
|
+
control: Section<S>['controls'][0];
|
|
18
|
+
}): boolean;
|
|
19
|
+
export declare function getIsFieldRequired<S extends SchemaAttributes = SchemaAttributes>({ attribute, control, requiredFields, }: {
|
|
20
|
+
attribute: AttributeBase;
|
|
21
|
+
requiredFields: Record<string, boolean>;
|
|
22
|
+
control: SectionStatndardControl<S>;
|
|
23
|
+
}): boolean;
|