@headless-adminapp/app 0.0.17-alpha.54 → 0.0.17-alpha.55
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.js +24 -32
- package/app/AuthWrapper.js +13 -9
- package/app/LayoutProvider.js +34 -39
- package/app/context.js +5 -2
- package/app/hooks/index.js +17 -1
- package/app/hooks/useAppContext.js +7 -4
- package/app/index.js +11 -4
- package/auth/AuthProvider.js +27 -36
- package/auth/context.d.ts +1 -1
- package/auth/context.js +5 -2
- package/auth/hooks/index.js +18 -2
- package/auth/hooks/useAuthSession.js +7 -4
- package/auth/hooks/useIsSkipAuthCheck.js +7 -4
- package/auth/hooks/useLogout.js +11 -8
- package/auth/index.js +23 -4
- package/auth/types.js +2 -1
- package/board/BoardColumnDataResolver.js +23 -20
- package/board/BoardColumnProvider.js +14 -10
- package/board/context.d.ts +2 -2
- package/board/context.js +6 -3
- package/board/hooks/index.js +15 -6
- package/board/hooks/useBoardColumnConfig.js +7 -4
- package/board/hooks/useBoardColumnData.d.ts +3 -1
- package/board/hooks/useBoardColumnData.js +7 -4
- package/board/hooks/useBoardColumnDataState.js +7 -4
- package/board/hooks/useBoardConfig.js +7 -4
- package/board/hooks/useBoardSchema.js +6 -3
- package/board/hooks/useSearchText.js +10 -7
- package/board/types.js +2 -1
- package/board/utils.js +4 -1
- package/builders/CommandBuilder/CommandBuilder.js +13 -10
- package/builders/CommandBuilder/DefaultCommandBuilder.js +30 -23
- package/builders/CommandBuilder/FormCommandBuilder.js +29 -38
- package/builders/CommandBuilder/SubgridCommandBuilder.js +27 -36
- package/builders/CommandBuilder/ViewCommandBuilder.js +29 -38
- package/builders/CommandBuilder/index.js +5 -1
- package/builders/CommandBuilder/utils.js +7 -3
- package/builders/SchemaExperienceBuilder.js +55 -31
- package/builders/index.js +7 -2
- package/builders/utils.js +59 -44
- package/command/hooks/index.js +18 -2
- package/command/hooks/useBaseCommandHandlerContext.js +29 -25
- package/command/hooks/useCommands.js +9 -6
- package/command/index.js +18 -2
- package/command/types.js +2 -1
- package/command/utils/index.js +41 -13
- package/components/ScrollView/index.js +11 -4
- package/components/ScrollbarWithMoreDataRequest/index.js +14 -11
- package/dataform/DataFormProvider/DataResolver.js +81 -89
- package/dataform/DataFormProvider/InitialValueResolver.js +22 -20
- package/dataform/DataFormProvider/ReadonlyInfoResolver.js +14 -12
- package/dataform/DataFormProvider/index.js +26 -32
- package/dataform/context.js +5 -2
- package/dataform/hooks/index.js +29 -13
- package/dataform/hooks/useFormInstance.js +6 -3
- package/dataform/hooks/useFormIsDirty.js +6 -3
- package/dataform/hooks/useFormIsReadonly.js +7 -4
- package/dataform/hooks/useFormNotifications.js +12 -9
- package/dataform/hooks/useFormRecord.js +7 -4
- package/dataform/hooks/useFormSave.js +40 -46
- package/dataform/hooks/useFormSchema.js +7 -4
- package/dataform/hooks/useLoadFormGridPage.js +19 -25
- package/dataform/hooks/useMainFormCommands.js +37 -30
- package/dataform/hooks/useProcessFlowSteps.js +27 -23
- package/dataform/hooks/useRecordId.js +7 -4
- package/dataform/hooks/useRecordTitle.js +12 -9
- package/dataform/hooks/useSelectedForm.js +7 -4
- package/dataform/index.js +23 -4
- package/dataform/utils/defaultParameters.js +16 -6
- package/dataform/utils/index.js +90 -56
- package/dataform/utils/saveRecord.js +99 -104
- package/datagrid/DataGridProvider/DataResolver.js +36 -34
- package/datagrid/DataGridProvider/index.js +31 -32
- package/datagrid/DataGridProvider/transformViewColumns.js +17 -6
- package/datagrid/DataGridProvider/utils.js +13 -5
- package/datagrid/column-filter/constants.js +5 -2
- package/datagrid/column-filter/index.js +7 -2
- package/datagrid/column-filter/types.js +2 -1
- package/datagrid/column-filter/utils.js +13 -3
- package/datagrid/context.d.ts +1 -1
- package/datagrid/context.js +5 -2
- package/datagrid/hooks/index.js +36 -20
- package/datagrid/hooks/useChangeView.js +10 -7
- package/datagrid/hooks/useGridColumnFilter.js +14 -8
- package/datagrid/hooks/useGridColumns.js +7 -4
- package/datagrid/hooks/useGridCommands.js +7 -4
- package/datagrid/hooks/useGridData.js +7 -4
- package/datagrid/hooks/useGridDataState.js +7 -4
- package/datagrid/hooks/useGridExtraFilter.js +7 -4
- package/datagrid/hooks/useGridOptions.js +4 -1
- package/datagrid/hooks/useGridPagination.js +4 -1
- package/datagrid/hooks/useGridRefresh.js +10 -7
- package/datagrid/hooks/useGridSchema.js +7 -4
- package/datagrid/hooks/useGridSelection.js +10 -7
- package/datagrid/hooks/useGridSorting.js +10 -7
- package/datagrid/hooks/useGridViewLookupData.js +7 -4
- package/datagrid/hooks/useLoadMainGridPage.js +12 -9
- package/datagrid/hooks/useMainGridCommands.js +62 -54
- package/datagrid/hooks/useMaxRecords.js +7 -4
- package/datagrid/hooks/useOpenRecord.js +20 -17
- package/datagrid/hooks/useSearchText.js +10 -7
- package/datagrid/hooks/useSelectedView.js +7 -4
- package/datagrid/hooks/useSubGridCommands.js +34 -23
- package/datagrid/index.js +27 -5
- package/defaults.js +5 -2
- package/dialog/DialogProvider.js +10 -6
- package/dialog/context.d.ts +1 -1
- package/dialog/context.js +5 -2
- package/dialog/hooks/index.js +24 -8
- package/dialog/hooks/useCloseDialog.js +10 -7
- package/dialog/hooks/useDialogItem.d.ts +1 -1
- package/dialog/hooks/useDialogItem.js +7 -4
- package/dialog/hooks/useDialogItems.d.ts +1 -1
- package/dialog/hooks/useDialogItems.js +7 -4
- package/dialog/hooks/useOpenAlertDialog.js +16 -8
- package/dialog/hooks/useOpenConfirmDialog.js +18 -9
- package/dialog/hooks/useOpenDialog.js +18 -11
- package/dialog/hooks/useOpenErrorDialog.js +16 -8
- package/dialog/hooks/useOpenPromptDialog.js +18 -9
- package/dialog/index.js +22 -3
- package/form/FormValidationStringContext.js +9 -5
- package/form/index.js +7 -1
- package/hooks/index.js +24 -6
- package/hooks/useDebouncedValue.js +11 -8
- package/hooks/useElementLayout.js +7 -4
- package/hooks/useIsMobile.js +12 -6
- package/hooks/useItemsWithKey.js +8 -5
- package/hooks/useStorageState.js +7 -5
- package/hooks/useSystemColorScheme.js +7 -4
- package/insights/InsightsProvider.js +13 -10
- package/insights/context.d.ts +1 -1
- package/insights/context.js +5 -2
- package/insights/hooks/index.js +7 -4
- package/insights/index.js +20 -2
- package/locale/LocaleProvider.js +12 -8
- package/locale/context.js +5 -2
- package/locale/index.js +23 -4
- package/locale/useCurrencySymbol.js +10 -8
- package/locale/useLocale.js +7 -4
- package/locale/utils.js +8 -3
- package/metadata/MetadataProvider.js +21 -17
- package/metadata/context.d.ts +1 -1
- package/metadata/context.js +5 -2
- package/metadata/hooks/index.js +24 -8
- package/metadata/hooks/useAppStore.js +7 -4
- package/metadata/hooks/useExperienceStore.js +7 -4
- package/metadata/hooks/useExperienceView.js +11 -17
- package/metadata/hooks/useExperienceViewCommands.js +14 -20
- package/metadata/hooks/useExperienceViewLookup.js +10 -16
- package/metadata/hooks/useExperienceViewSubgridCommands.js +14 -20
- package/metadata/hooks/useMetadata.js +11 -8
- package/metadata/hooks/useSchema.js +6 -3
- package/metadata/index.js +22 -3
- package/mutable/context.js +25 -17
- package/mutable/index.js +27 -3
- package/mutable/state.js +10 -6
- package/mutable/type.js +2 -1
- package/mutable/utils.js +12 -8
- package/navigation/hooks/index.js +17 -1
- package/navigation/hooks/useOpenForm.js +14 -11
- package/navigation/index.js +17 -1
- package/package.json +4 -12
- package/progress-indicator/ProgressIndicatorProvider.js +16 -12
- package/progress-indicator/context.js +5 -2
- package/progress-indicator/hooks/index.js +17 -1
- package/progress-indicator/hooks/useProgressIndicator.d.ts +1 -1
- package/progress-indicator/hooks/useProgressIndicator.js +7 -4
- package/progress-indicator/index.js +22 -3
- package/providers/PageEntityFormProvider/index.js +7 -4
- package/providers/PageEntityViewProvider/index.js +7 -4
- package/recordset/RecordSetProvider.js +16 -12
- package/recordset/context.d.ts +1 -1
- package/recordset/context.js +5 -2
- package/recordset/hooks/index.js +19 -3
- package/recordset/hooks/useRecordSetResult.js +22 -29
- package/recordset/hooks/useRecordSetSetter.js +9 -6
- package/recordset/hooks/useRecordSetVisibility.js +10 -7
- package/recordset/index.js +22 -3
- package/route/RouteProvider.js +18 -14
- package/route/context.js +9 -6
- package/route/hooks/index.js +22 -6
- package/route/hooks/useBasePath.js +7 -4
- package/route/hooks/useIsRouteActive.js +7 -4
- package/route/hooks/usePathname.js +7 -4
- package/route/hooks/useRouteResolver.js +7 -4
- package/route/hooks/useRouter.js +7 -4
- package/route/hooks/useSearchParams.js +7 -4
- package/route/index.js +20 -2
- package/route/types.js +2 -1
- package/store/ClientAppStore.js +12 -21
- package/store/ComponentStore.js +6 -4
- package/store/EventManager.js +20 -32
- package/store/SchemaExperienceStore.js +186 -217
- package/store/index.js +20 -4
- package/toast-notification/ToastNotificationProvider.js +10 -6
- package/toast-notification/context.d.ts +1 -1
- package/toast-notification/context.js +5 -2
- package/toast-notification/hooks/index.js +19 -3
- package/toast-notification/hooks/useCloseToastNotification.js +10 -7
- package/toast-notification/hooks/useOpenToastNotification.js +18 -11
- package/toast-notification/hooks/useToastNotificationItems.d.ts +1 -1
- package/toast-notification/hooks/useToastNotificationItems.js +7 -4
- package/toast-notification/index.js +22 -3
- package/transport/InMemoryDataService/index.js +59 -78
- package/transport/RestDataService/index.d.ts +2 -2
- package/transport/RestDataService/index.js +72 -91
- package/transport/context.js +9 -15
- package/transport/hooks/index.js +18 -2
- package/transport/hooks/useDataService.js +7 -4
- package/transport/hooks/useFileService.js +7 -4
- package/transport/hooks/useRetriveRecords.d.ts +1 -1
- package/transport/hooks/useRetriveRecords.js +25 -31
- package/transport/index.js +20 -2
- package/utils/calculateColumnWidths.js +5 -2
- package/utils/color.js +4 -1
- package/utils/getAttributeFormattedValue.js +38 -40
- package/utils/index.js +18 -2
- package/widget/context.js +5 -2
- package/widget/hooks/index.js +7 -4
- package/widget/index.js +5 -1
|
@@ -1,32 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
import { useDataService } from '../../transport';
|
|
16
|
-
import { DataFormContext } from '../context';
|
|
17
|
-
import { useDataFormSchema, useRecordId, useSelectedForm } from '../hooks';
|
|
18
|
-
export function getControls(form) {
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getControls = getControls;
|
|
4
|
+
exports.getColumns = getColumns;
|
|
5
|
+
exports.DataResolver = DataResolver;
|
|
6
|
+
const transport_1 = require("@headless-adminapp/core/transport");
|
|
7
|
+
const react_query_1 = require("@tanstack/react-query");
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const hooks_1 = require("../../metadata/hooks");
|
|
10
|
+
const mutable_1 = require("../../mutable");
|
|
11
|
+
const transport_2 = require("../../transport");
|
|
12
|
+
const context_1 = require("../context");
|
|
13
|
+
const hooks_2 = require("../hooks");
|
|
14
|
+
function getControls(form) {
|
|
19
15
|
const controls = form.experience.tabs
|
|
20
16
|
.flatMap((tab) => tab.tabColumns)
|
|
21
17
|
.flatMap((tabColumn) => tabColumn.sections)
|
|
22
18
|
.flatMap((section) => section.controls);
|
|
23
19
|
return controls;
|
|
24
20
|
}
|
|
25
|
-
|
|
26
|
-
var _a, _b;
|
|
21
|
+
function getColumns(form, schema) {
|
|
27
22
|
const set = new Set([
|
|
28
|
-
...(
|
|
29
|
-
...(
|
|
23
|
+
...(form.experience.includeAttributes ?? []),
|
|
24
|
+
...(form.experience.headerControls ?? []),
|
|
30
25
|
...getControls(form)
|
|
31
26
|
.filter((control) => control.type === 'standard')
|
|
32
27
|
.map((control) => control.attributeName),
|
|
@@ -37,72 +32,69 @@ export function getColumns(form, schema) {
|
|
|
37
32
|
const columns = Array.from(set);
|
|
38
33
|
return columns;
|
|
39
34
|
}
|
|
40
|
-
function getRecord(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
catch (error) {
|
|
48
|
-
if (error instanceof HttpError && error.status === 404) {
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
throw error;
|
|
52
|
-
}
|
|
53
|
-
if (!record) {
|
|
35
|
+
async function getRecord({ recordId, dataService, form, schema, columns, schemaStore, }) {
|
|
36
|
+
let record = null;
|
|
37
|
+
try {
|
|
38
|
+
record = await dataService.retriveRecord(schema.logicalName, recordId, columns);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (error instanceof transport_1.HttpError && error.status === 404) {
|
|
54
42
|
return null;
|
|
55
43
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
],
|
|
74
|
-
},
|
|
75
|
-
sort: [
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
if (!record) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
const controls = getControls(form);
|
|
50
|
+
const editableGridControls = controls.filter((control) => control.type === 'editablegrid');
|
|
51
|
+
for (const control of editableGridControls) {
|
|
52
|
+
if (control.type !== 'editablegrid') {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const controlSchema = schemaStore.getSchema(control.logicalName);
|
|
56
|
+
const records = await dataService.retriveRecords({
|
|
57
|
+
logicalName: controlSchema.logicalName,
|
|
58
|
+
filter: {
|
|
59
|
+
type: 'and',
|
|
60
|
+
conditions: [
|
|
76
61
|
{
|
|
77
|
-
field:
|
|
78
|
-
|
|
62
|
+
field: control.referenceAttribute,
|
|
63
|
+
operator: 'eq',
|
|
64
|
+
value: recordId,
|
|
79
65
|
},
|
|
80
66
|
],
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
controlSchema.idAttribute,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
67
|
+
},
|
|
68
|
+
sort: [
|
|
69
|
+
{
|
|
70
|
+
field: controlSchema.createdAtAttribute ?? controlSchema.idAttribute,
|
|
71
|
+
order: 'asc',
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
limit: 5000,
|
|
75
|
+
search: '',
|
|
76
|
+
columns: [
|
|
77
|
+
controlSchema.idAttribute,
|
|
78
|
+
control.referenceAttribute,
|
|
79
|
+
...control.attributes,
|
|
80
|
+
],
|
|
81
|
+
});
|
|
82
|
+
record[control.attributeName] = records.records;
|
|
83
|
+
}
|
|
84
|
+
return record;
|
|
93
85
|
}
|
|
94
|
-
|
|
95
|
-
const schema = useDataFormSchema();
|
|
96
|
-
const form = useSelectedForm();
|
|
97
|
-
const dataService = useDataService();
|
|
98
|
-
const recordId = useRecordId();
|
|
99
|
-
const { schemaStore } = useMetadata();
|
|
100
|
-
const setState = useContextSetValue(DataFormContext);
|
|
101
|
-
const columns = useMemo(() => getColumns(form, schema), [form, schema]);
|
|
102
|
-
const queryKey = useMemo(() => ['data', 'retriveRecord', schema.logicalName, recordId, columns], [columns, recordId, schema.logicalName]);
|
|
103
|
-
const { data, refetch, isPending } = useQuery({
|
|
86
|
+
function DataResolver() {
|
|
87
|
+
const schema = (0, hooks_2.useDataFormSchema)();
|
|
88
|
+
const form = (0, hooks_2.useSelectedForm)();
|
|
89
|
+
const dataService = (0, transport_2.useDataService)();
|
|
90
|
+
const recordId = (0, hooks_2.useRecordId)();
|
|
91
|
+
const { schemaStore } = (0, hooks_1.useMetadata)();
|
|
92
|
+
const setState = (0, mutable_1.useContextSetValue)(context_1.DataFormContext);
|
|
93
|
+
const columns = (0, react_1.useMemo)(() => getColumns(form, schema), [form, schema]);
|
|
94
|
+
const queryKey = (0, react_1.useMemo)(() => ['data', 'retriveRecord', schema.logicalName, recordId, columns], [columns, recordId, schema.logicalName]);
|
|
95
|
+
const { data, refetch, isPending } = (0, react_query_1.useQuery)({
|
|
104
96
|
queryKey,
|
|
105
|
-
queryFn: () =>
|
|
97
|
+
queryFn: async () => {
|
|
106
98
|
if (!recordId) {
|
|
107
99
|
return null;
|
|
108
100
|
}
|
|
@@ -115,27 +107,27 @@ export function DataResolver() {
|
|
|
115
107
|
schemaStore,
|
|
116
108
|
});
|
|
117
109
|
return record;
|
|
118
|
-
}
|
|
119
|
-
placeholderData: keepPreviousData,
|
|
110
|
+
},
|
|
111
|
+
placeholderData: react_query_1.keepPreviousData,
|
|
120
112
|
staleTime: 1000 * 60 * 5, // 5 minutes
|
|
121
113
|
});
|
|
122
|
-
useEffect(() => {
|
|
114
|
+
(0, react_1.useEffect)(() => {
|
|
123
115
|
setState({
|
|
124
116
|
record: data,
|
|
125
117
|
});
|
|
126
118
|
}, [data, setState]);
|
|
127
|
-
useEffect(() => {
|
|
119
|
+
(0, react_1.useEffect)(() => {
|
|
128
120
|
setState({
|
|
129
121
|
dataState: {
|
|
130
122
|
isFetching: isPending,
|
|
131
123
|
},
|
|
132
124
|
});
|
|
133
125
|
}, [isPending, setState]);
|
|
134
|
-
useEffect(() => {
|
|
126
|
+
(0, react_1.useEffect)(() => {
|
|
135
127
|
setState({
|
|
136
|
-
refresh: () =>
|
|
137
|
-
|
|
138
|
-
}
|
|
128
|
+
refresh: async () => {
|
|
129
|
+
await refetch();
|
|
130
|
+
},
|
|
139
131
|
});
|
|
140
132
|
}, [refetch, setState]);
|
|
141
133
|
return null;
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InitialValueResolver = InitialValueResolver;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const mutable_1 = require("../../mutable");
|
|
6
|
+
const context_1 = require("../context");
|
|
7
|
+
const hooks_1 = require("../hooks");
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
const defaultParameters_1 = require("../utils/defaultParameters");
|
|
10
|
+
function InitialValueResolver() {
|
|
11
|
+
const formConfig = (0, hooks_1.useSelectedForm)();
|
|
12
|
+
const schema = (0, hooks_1.useDataFormSchema)();
|
|
13
|
+
const recordId = (0, hooks_1.useRecordId)();
|
|
14
|
+
const record = (0, mutable_1.useContextSelector)(context_1.DataFormContext, (state) => state.record);
|
|
15
|
+
const formInstance = (0, hooks_1.useFormInstance)();
|
|
16
|
+
const initialValues = (0, react_1.useMemo)(() => {
|
|
17
|
+
const defaultParameters = (0, defaultParameters_1.getFormDefaultParameters)(schema) ?? {};
|
|
18
|
+
return (0, utils_1.getInitialValues)({
|
|
17
19
|
cloneRecord: undefined,
|
|
18
20
|
form: formConfig,
|
|
19
21
|
record: record,
|
|
@@ -22,15 +24,15 @@ export function InitialValueResolver() {
|
|
|
22
24
|
defaultParameters,
|
|
23
25
|
});
|
|
24
26
|
}, [formConfig, record, recordId, schema]);
|
|
25
|
-
const setValue = useContextSetValue(DataFormContext);
|
|
26
|
-
useEffect(() => {
|
|
27
|
+
const setValue = (0, mutable_1.useContextSetValue)(context_1.DataFormContext);
|
|
28
|
+
(0, react_1.useEffect)(() => {
|
|
27
29
|
setValue({
|
|
28
30
|
initialValues,
|
|
29
31
|
});
|
|
30
32
|
}, [setValue, initialValues]);
|
|
31
|
-
const formInstanceRef = useRef(formInstance);
|
|
33
|
+
const formInstanceRef = (0, react_1.useRef)(formInstance);
|
|
32
34
|
formInstanceRef.current = formInstance;
|
|
33
|
-
useEffect(() => {
|
|
35
|
+
(0, react_1.useEffect)(() => {
|
|
34
36
|
const timer = setTimeout(() => {
|
|
35
37
|
formInstanceRef.current.reset(initialValues);
|
|
36
38
|
});
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReadonlyInfoResolver = ReadonlyInfoResolver;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const mutable_1 = require("../../mutable");
|
|
6
|
+
const context_1 = require("../context");
|
|
7
|
+
const hooks_1 = require("../hooks");
|
|
8
|
+
function ReadonlyInfoResolver({ setFormReadOnly, }) {
|
|
9
|
+
const schema = (0, hooks_1.useDataFormSchema)();
|
|
10
|
+
const recordId = (0, hooks_1.useRecordId)();
|
|
9
11
|
let readonly = false;
|
|
10
|
-
if (
|
|
12
|
+
if (schema.restrictions?.disableCreate && !recordId) {
|
|
11
13
|
readonly = true;
|
|
12
14
|
}
|
|
13
|
-
if (
|
|
15
|
+
if (schema.restrictions?.disableUpdate && recordId) {
|
|
14
16
|
readonly = true;
|
|
15
17
|
}
|
|
16
|
-
const setValue = useContextSetValue(DataFormContext);
|
|
17
|
-
useEffect(() => {
|
|
18
|
+
const setValue = (0, mutable_1.useContextSetValue)(context_1.DataFormContext);
|
|
19
|
+
(0, react_1.useEffect)(() => {
|
|
18
20
|
setValue({
|
|
19
21
|
isReadonly: readonly,
|
|
20
22
|
});
|
|
@@ -1,33 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export function DataFormProvider(props) {
|
|
23
|
-
const { schemaStore } = useMetadata();
|
|
24
|
-
const { language } = useLocale();
|
|
25
|
-
const formValidationStrings = useFormValidationStrings();
|
|
26
|
-
const [formReadOnly, setFormReadOnly] = useState(false); // A trick to provide readOnly info to formInstance
|
|
27
|
-
const formInstance = useForm({
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataFormProvider = DataFormProvider;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
7
|
+
const FormValidationStringContext_1 = require("../../form/FormValidationStringContext");
|
|
8
|
+
const useLocale_1 = require("../../locale/useLocale");
|
|
9
|
+
const useMetadata_1 = require("../../metadata/hooks/useMetadata");
|
|
10
|
+
const mutable_1 = require("../../mutable");
|
|
11
|
+
const context_1 = require("../context");
|
|
12
|
+
const utils_1 = require("../utils");
|
|
13
|
+
const DataResolver_1 = require("./DataResolver");
|
|
14
|
+
const InitialValueResolver_1 = require("./InitialValueResolver");
|
|
15
|
+
const ReadonlyInfoResolver_1 = require("./ReadonlyInfoResolver");
|
|
16
|
+
function DataFormProvider(props) {
|
|
17
|
+
const { schemaStore } = (0, useMetadata_1.useMetadata)();
|
|
18
|
+
const { language } = (0, useLocale_1.useLocale)();
|
|
19
|
+
const formValidationStrings = (0, FormValidationStringContext_1.useFormValidationStrings)();
|
|
20
|
+
const [formReadOnly, setFormReadOnly] = (0, react_1.useState)(false); // A trick to provide readOnly info to formInstance
|
|
21
|
+
const formInstance = (0, react_hook_form_1.useForm)({
|
|
28
22
|
mode: 'all',
|
|
29
23
|
defaultValues: {},
|
|
30
|
-
resolver: formValidator({
|
|
24
|
+
resolver: (0, utils_1.formValidator)({
|
|
31
25
|
form: props.form,
|
|
32
26
|
schemaStore,
|
|
33
27
|
language,
|
|
@@ -37,19 +31,19 @@ export function DataFormProvider(props) {
|
|
|
37
31
|
}),
|
|
38
32
|
shouldUnregister: false,
|
|
39
33
|
});
|
|
40
|
-
const contextValue = useCreateContextStore({
|
|
34
|
+
const contextValue = (0, mutable_1.useCreateContextStore)({
|
|
41
35
|
schema: props.schema,
|
|
42
36
|
form: props.form,
|
|
43
37
|
commands: props.commands,
|
|
44
38
|
dataState: { isFetching: false },
|
|
45
39
|
recordId: props.recordId,
|
|
46
|
-
refresh: () =>
|
|
40
|
+
refresh: async () => { }, // Initial value, will be overridden
|
|
47
41
|
cloneId: undefined,
|
|
48
42
|
// formInstance,
|
|
49
43
|
// formInstanceRenderCount: 0,
|
|
50
44
|
initialValues: {},
|
|
51
45
|
});
|
|
52
|
-
useEffect(() => {
|
|
46
|
+
(0, react_1.useEffect)(() => {
|
|
53
47
|
contextValue.setValue({
|
|
54
48
|
form: props.form,
|
|
55
49
|
schema: props.schema,
|
|
@@ -65,5 +59,5 @@ export function DataFormProvider(props) {
|
|
|
65
59
|
schemaStore,
|
|
66
60
|
props.commands,
|
|
67
61
|
]);
|
|
68
|
-
return (
|
|
62
|
+
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, {}), (0, jsx_runtime_1.jsx)(InitialValueResolver_1.InitialValueResolver, {}), (0, jsx_runtime_1.jsx)(ReadonlyInfoResolver_1.ReadonlyInfoResolver, { setFormReadOnly: setFormReadOnly }), props.children] }) }));
|
|
69
63
|
}
|
package/dataform/context.js
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DataFormContext = void 0;
|
|
4
|
+
const mutable_1 = require("../mutable");
|
|
5
|
+
exports.DataFormContext = (0, mutable_1.createContext)();
|
package/dataform/hooks/index.js
CHANGED
|
@@ -1,13 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./useFormInstance"), exports);
|
|
18
|
+
__exportStar(require("./useFormIsDirty"), exports);
|
|
19
|
+
__exportStar(require("./useFormIsReadonly"), exports);
|
|
20
|
+
__exportStar(require("./useFormNotifications"), exports);
|
|
21
|
+
__exportStar(require("./useFormRecord"), exports);
|
|
22
|
+
__exportStar(require("./useFormSave"), exports);
|
|
23
|
+
__exportStar(require("./useFormSchema"), exports);
|
|
24
|
+
__exportStar(require("./useMainFormCommands"), exports);
|
|
25
|
+
__exportStar(require("./useRecordId"), exports);
|
|
26
|
+
__exportStar(require("./useRecordTitle"), exports);
|
|
27
|
+
__exportStar(require("./useSelectedForm"), exports);
|
|
28
|
+
__exportStar(require("./useLoadFormGridPage"), exports);
|
|
29
|
+
__exportStar(require("./useProcessFlowSteps"), exports);
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useFormInstance = useFormInstance;
|
|
4
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
5
|
+
function useFormInstance() {
|
|
6
|
+
const formInstance = (0, react_hook_form_1.useFormContext)();
|
|
4
7
|
return formInstance;
|
|
5
8
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useFormIsDirty = useFormIsDirty;
|
|
4
|
+
const useFormInstance_1 = require("./useFormInstance");
|
|
5
|
+
function useFormIsDirty() {
|
|
6
|
+
const formInstance = (0, useFormInstance_1.useFormInstance)();
|
|
4
7
|
return Object.keys(formInstance.formState.dirtyFields).length > 0;
|
|
5
8
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useFormIsReadonly = useFormIsReadonly;
|
|
4
|
+
const mutable_1 = require("../../mutable");
|
|
5
|
+
const context_1 = require("../context");
|
|
6
|
+
function useFormIsReadonly() {
|
|
7
|
+
const readonly = (0, mutable_1.useContextSelector)(context_1.DataFormContext, (state) => state.isReadonly);
|
|
5
8
|
return readonly;
|
|
6
9
|
}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useFormNotifications = useFormNotifications;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const useFormInstance_1 = require("./useFormInstance");
|
|
6
|
+
const useFormIsReadonly_1 = require("./useFormIsReadonly");
|
|
7
|
+
function useFormNotifications() {
|
|
8
|
+
const readonly = (0, useFormIsReadonly_1.useFormIsReadonly)();
|
|
9
|
+
const formInstance = (0, useFormInstance_1.useFormInstance)();
|
|
7
10
|
const formInstanceAvailable = !!formInstance;
|
|
8
|
-
return useMemo(() => {
|
|
11
|
+
return (0, react_1.useMemo)(() => {
|
|
9
12
|
const notifications = [];
|
|
10
13
|
if (readonly) {
|
|
11
14
|
notifications.push({
|
|
@@ -24,8 +27,8 @@ export function useFormNotifications() {
|
|
|
24
27
|
return notifications;
|
|
25
28
|
}, [
|
|
26
29
|
formInstanceAvailable,
|
|
27
|
-
formInstance
|
|
28
|
-
formInstance
|
|
30
|
+
formInstance?.formState.errors,
|
|
31
|
+
formInstance?.formState.isSubmitted,
|
|
29
32
|
readonly,
|
|
30
33
|
]);
|
|
31
34
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useFormRecord = useFormRecord;
|
|
4
|
+
const mutable_1 = require("../../mutable");
|
|
5
|
+
const context_1 = require("../context");
|
|
6
|
+
function useFormRecord() {
|
|
7
|
+
const record = (0, mutable_1.useContextSelector)(context_1.DataFormContext, (state) => state.record);
|
|
5
8
|
return record;
|
|
6
9
|
}
|