@gisce/react-ooui 2.0.0-alpha.61 → 2.0.0-alpha.63

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.
Files changed (246) hide show
  1. package/dist/react-ooui.es.js +5 -2
  2. package/dist/react-ooui.es.js.map +1 -1
  3. package/dist/widgets/views/Tree/treeComponents.d.ts.map +1 -1
  4. package/package.json +6 -8
  5. package/src/ConnectionProvider.ts +0 -16
  6. package/src/__tests__/iconMapper.test.ts +0 -30
  7. package/src/__tests__/searchFilterHelper.spec.ts +0 -386
  8. package/src/actionbar/ActionButton.tsx +0 -40
  9. package/src/actionbar/AttachmentsButton.tsx +0 -132
  10. package/src/actionbar/AttachmentsButtonWrapper.tsx +0 -157
  11. package/src/actionbar/ButtonWithBadge.tsx +0 -44
  12. package/src/actionbar/ChangeViewButton.tsx +0 -137
  13. package/src/actionbar/DashboardActionBar.tsx +0 -63
  14. package/src/actionbar/DropdownButton.tsx +0 -124
  15. package/src/actionbar/FormActionBar.tsx +0 -491
  16. package/src/actionbar/GraphActionBar.tsx +0 -67
  17. package/src/actionbar/NewButton.tsx +0 -46
  18. package/src/actionbar/SearchBar.tsx +0 -73
  19. package/src/actionbar/TreeActionBar.tsx +0 -383
  20. package/src/common/ButtonWithTooltip.tsx +0 -18
  21. package/src/common/DatePicker.tsx +0 -98
  22. package/src/common/Field.tsx +0 -93
  23. package/src/common/SelectAllRecordsRow.tsx +0 -94
  24. package/src/common/TimePicker.tsx +0 -38
  25. package/src/context/ActionViewContext.tsx +0 -213
  26. package/src/context/ConfigContext.tsx +0 -28
  27. package/src/context/ContentRootContext.tsx +0 -461
  28. package/src/context/DashboardActionContext.tsx +0 -44
  29. package/src/context/FormContext.tsx +0 -79
  30. package/src/context/FormModalContext.tsx +0 -28
  31. package/src/context/LocaleContext.tsx +0 -50
  32. package/src/context/One2manyContext.tsx +0 -45
  33. package/src/context/TabManagerContext.tsx +0 -117
  34. package/src/helpers/containerHelper.ts +0 -145
  35. package/src/helpers/dayjs.ts +0 -21
  36. package/src/helpers/dynamicColumnsHelper.ts +0 -73
  37. package/src/helpers/errorHelper.ts +0 -27
  38. package/src/helpers/filesHelper.ts +0 -41
  39. package/src/helpers/formHelper.ts +0 -301
  40. package/src/helpers/iconMapper.ts +0 -164
  41. package/src/helpers/logInfoHelper.tsx +0 -30
  42. package/src/helpers/one2manyHelper.ts +0 -194
  43. package/src/helpers/searchHelper.ts +0 -196
  44. package/src/helpers/timeHelper.ts +0 -58
  45. package/src/helpers/treeHelper.tsx +0 -226
  46. package/src/helpers/viewHelper.ts +0 -23
  47. package/src/hooks/useEffectDebugger.ts +0 -43
  48. package/src/hooks/useExport.ts +0 -439
  49. package/src/hooks/useFetchViews.ts +0 -0
  50. package/src/hooks/useSearch.ts +0 -434
  51. package/src/hooks/useWindowDimensions.ts +0 -33
  52. package/src/index.ts +0 -168
  53. package/src/locales/ca_ES.tsx +0 -99
  54. package/src/locales/en_US.tsx +0 -96
  55. package/src/locales/es_ES.tsx +0 -101
  56. package/src/stories/Binary.stories.tsx +0 -23
  57. package/src/stories/Boolean.stories.tsx +0 -22
  58. package/src/stories/Button.stories.tsx +0 -130
  59. package/src/stories/Char.stories.tsx +0 -76
  60. package/src/stories/FiberGrid.stories.tsx +0 -109
  61. package/src/stories/Float.stories.tsx +0 -22
  62. package/src/stories/FloatTime.stories.tsx +0 -32
  63. package/src/stories/Image.stories.tsx +0 -25
  64. package/src/stories/Integer.stories.tsx +0 -22
  65. package/src/stories/Label.stories.tsx +0 -100
  66. package/src/stories/Many2one.stories.tsx +0 -31
  67. package/src/stories/One2many.stories.tsx +0 -288
  68. package/src/stories/ProgressBar.stories.tsx +0 -22
  69. package/src/stories/Reference.stories.tsx +0 -43
  70. package/src/stories/Selection.stories.tsx +0 -34
  71. package/src/stories/Separator.stories.tsx +0 -53
  72. package/src/stories/Text.stories.tsx +0 -35
  73. package/src/stories/Time.stories.tsx +0 -31
  74. package/src/stories/Utils.stories.tsx +0 -14
  75. package/src/stories/containers/Group.stories.tsx +0 -84
  76. package/src/stories/containers/NewLine.stories.tsx +0 -52
  77. package/src/stories/containers/Notebook.stories.tsx +0 -188
  78. package/src/stories/custom/Avatar.stories.tsx +0 -22
  79. package/src/stories/custom/ButtonGroup.stories.tsx +0 -74
  80. package/src/stories/custom/CodeEditor.stories.tsx +0 -25
  81. package/src/stories/custom/Comments.stories.tsx +0 -197
  82. package/src/stories/custom/Indicator.stories.tsx +0 -36
  83. package/src/stories/custom/Markdown.stories.tsx +0 -38
  84. package/src/stories/custom/MultiCheckbox.stories.tsx +0 -60
  85. package/src/stories/custom/Radio.stories.tsx +0 -68
  86. package/src/stories/custom/Steps.stories.tsx +0 -43
  87. package/src/stories/custom/Switch.stories.tsx +0 -23
  88. package/src/stories/custom/Tag.stories.tsx +0 -66
  89. package/src/stories/custom/Tags.stories.tsx +0 -74
  90. package/src/stories/dashboard/Dashboard.stories.tsx +0 -23
  91. package/src/stories/dashboard/DashboardGrid.stories.tsx +0 -43
  92. package/src/stories/forms/ActivacioContracteForm.stories.tsx +0 -25
  93. package/src/stories/forms/Attachment.stories.tsx +0 -24
  94. package/src/stories/forms/CUPSForm.stories.tsx +0 -25
  95. package/src/stories/forms/Company.stories.tsx +0 -25
  96. package/src/stories/forms/CrmCaseForm.stories.tsx +0 -25
  97. package/src/stories/forms/Documents.stories.tsx +0 -25
  98. package/src/stories/forms/FormWithGridFiber.stories.tsx +0 -25
  99. package/src/stories/forms/FormWithLinks.stories.tsx +0 -30
  100. package/src/stories/forms/Lead.stories.tsx +0 -25
  101. package/src/stories/forms/ModContractForm.stories.tsx +0 -26
  102. package/src/stories/forms/PartnersForm.stories.tsx +0 -25
  103. package/src/stories/forms/PolissaForm.stories.tsx +0 -25
  104. package/src/stories/forms/PreferencesForm.stories.tsx +0 -691
  105. package/src/stories/forms/Signatures.stories.tsx +0 -25
  106. package/src/stories/forms/Switching.stories.tsx +0 -25
  107. package/src/stories/graphs/GraphIndicator.stories.tsx +0 -20
  108. package/src/stories/graphs/PieGraph.stories.tsx +0 -78
  109. package/src/stories/mocks/index.ts +0 -46
  110. package/src/stories/mocks/mockProvider.ts +0 -189
  111. package/src/stories/mocks/models/activacioContracte.ts +0 -112
  112. package/src/stories/mocks/models/attachment.ts +0 -1326
  113. package/src/stories/mocks/models/butlleti.ts +0 -296
  114. package/src/stories/mocks/models/company.ts +0 -135
  115. package/src/stories/mocks/models/crm_case.ts +0 -595
  116. package/src/stories/mocks/models/cups.ts +0 -937
  117. package/src/stories/mocks/models/document.ts +0 -223
  118. package/src/stories/mocks/models/factura.ts +0 -2713
  119. package/src/stories/mocks/models/form_with_gridfiber.ts +0 -141
  120. package/src/stories/mocks/models/hist_autoconsum.ts +0 -146
  121. package/src/stories/mocks/models/lead.ts +0 -2101
  122. package/src/stories/mocks/models/modcontractual.ts +0 -952
  123. package/src/stories/mocks/models/partner.ts +0 -1340
  124. package/src/stories/mocks/models/polissa.ts +0 -3127
  125. package/src/stories/mocks/models/res_partner_category.ts +0 -15
  126. package/src/stories/mocks/models/signatura.ts +0 -558
  127. package/src/stories/mocks/models/switching.ts +0 -767
  128. package/src/stories/modals/FormModal.stories.tsx +0 -36
  129. package/src/stories/modals/SearchModal.stories.tsx +0 -37
  130. package/src/stories/trees/FacturesTree.stories.tsx +0 -16
  131. package/src/stories/ui/ActionBar.stories.tsx +0 -21
  132. package/src/stories/ui/FavouriteButton.stories.tsx +0 -16
  133. package/src/stories/ui/GoToResourceModal.stories.tsx +0 -25
  134. package/src/stories/views/ActionView.stories.tsx +0 -28
  135. package/src/stories/views/SearchTree.stories.tsx +0 -1064
  136. package/src/stories/views/Tab.stories.tsx +0 -93
  137. package/src/stories/views/TabsAndContent.stories.tsx +0 -88
  138. package/src/stories/views/Tree.stories.jsx +0 -178
  139. package/src/stories/views/searchFilter/DateRangePicker.stories.tsx +0 -22
  140. package/src/stories/views/searchFilter/DateTimeRangePicker.stories.tsx +0 -23
  141. package/src/stories/views/searchFilter/PairFields.stories.tsx +0 -23
  142. package/src/stories/views/searchFilter/SearchFilter.stories.tsx +0 -165
  143. package/src/stories/views/searchFilter/examples/PartnersSearchFilter.stories.tsx +0 -409
  144. package/src/types/index.ts +0 -392
  145. package/src/ui/ActionErrorDialog.tsx +0 -24
  146. package/src/ui/ConfirmDialog.tsx +0 -28
  147. package/src/ui/ErrorAlert.tsx +0 -37
  148. package/src/ui/FavouriteButton.tsx +0 -271
  149. package/src/ui/FormErrorsDialog.tsx +0 -17
  150. package/src/ui/GenericErrorDialog.tsx +0 -16
  151. package/src/ui/GoToResourceModal.tsx +0 -76
  152. package/src/ui/InfoDialog.tsx +0 -13
  153. package/src/ui/RefreshItemDialog.tsx +0 -29
  154. package/src/ui/RemoveItemDialog.tsx +0 -20
  155. package/src/ui/TitleHeader.tsx +0 -117
  156. package/src/ui/UnlinkItemDialog.tsx +0 -20
  157. package/src/ui/UnsavedChangesDialog.tsx +0 -29
  158. package/src/ui/WarningDialog.tsx +0 -17
  159. package/src/views/ActionView.tsx +0 -526
  160. package/src/views/CurrentTabContent.tsx +0 -21
  161. package/src/views/RootView.tsx +0 -509
  162. package/src/views/TabContent.tsx +0 -31
  163. package/src/views/TabSelector.tsx +0 -31
  164. package/src/views/Welcome.tsx +0 -18
  165. package/src/views/actionViews/DashboardActionView.tsx +0 -52
  166. package/src/views/actionViews/FormActionView.tsx +0 -70
  167. package/src/views/actionViews/GraphActionView.tsx +0 -152
  168. package/src/views/actionViews/TreeActionView.tsx +0 -87
  169. package/src/views/tabs/Tab.tsx +0 -82
  170. package/src/widgets/WidgetFactory.tsx +0 -142
  171. package/src/widgets/base/Binary.tsx +0 -145
  172. package/src/widgets/base/Boolean.tsx +0 -44
  173. package/src/widgets/base/Button.tsx +0 -77
  174. package/src/widgets/base/Char.tsx +0 -157
  175. package/src/widgets/base/Date.tsx +0 -12
  176. package/src/widgets/base/DateTime.tsx +0 -12
  177. package/src/widgets/base/Email.tsx +0 -27
  178. package/src/widgets/base/Float.tsx +0 -38
  179. package/src/widgets/base/FloatTime.tsx +0 -73
  180. package/src/widgets/base/Image.tsx +0 -120
  181. package/src/widgets/base/Integer.tsx +0 -55
  182. package/src/widgets/base/Label.tsx +0 -56
  183. package/src/widgets/base/LinkInput.tsx +0 -106
  184. package/src/widgets/base/MultiSelection.tsx +0 -90
  185. package/src/widgets/base/ProgressBar.tsx +0 -38
  186. package/src/widgets/base/Reference.tsx +0 -115
  187. package/src/widgets/base/ReferenceTree.tsx +0 -62
  188. package/src/widgets/base/Selection.tsx +0 -71
  189. package/src/widgets/base/Separator.tsx +0 -25
  190. package/src/widgets/base/Text.tsx +0 -162
  191. package/src/widgets/base/Time.tsx +0 -40
  192. package/src/widgets/base/Url.tsx +0 -26
  193. package/src/widgets/base/many2one/Many2one.tsx +0 -322
  194. package/src/widgets/base/many2one/Many2oneSuffix.tsx +0 -232
  195. package/src/widgets/base/many2one/Many2oneSuffixModal.tsx +0 -42
  196. package/src/widgets/base/many2one/Many2oneTree.tsx +0 -18
  197. package/src/widgets/base/one2many/One2many.tsx +0 -100
  198. package/src/widgets/base/one2many/One2manyInput.tsx +0 -724
  199. package/src/widgets/base/one2many/One2manyTopBar.tsx +0 -158
  200. package/src/widgets/containers/Container.tsx +0 -99
  201. package/src/widgets/containers/Group.tsx +0 -37
  202. package/src/widgets/containers/Notebook.tsx +0 -52
  203. package/src/widgets/custom/Avatar.tsx +0 -40
  204. package/src/widgets/custom/ButtonGroup.tsx +0 -169
  205. package/src/widgets/custom/CodeEditor.tsx +0 -32
  206. package/src/widgets/custom/Comments.tsx +0 -147
  207. package/src/widgets/custom/FiberGrid.tsx +0 -48
  208. package/src/widgets/custom/Indicator.tsx +0 -66
  209. package/src/widgets/custom/Markdown.tsx +0 -32
  210. package/src/widgets/custom/MultiCheckbox.tsx +0 -165
  211. package/src/widgets/custom/Radio.tsx +0 -47
  212. package/src/widgets/custom/Steps.tsx +0 -56
  213. package/src/widgets/custom/Switch.tsx +0 -26
  214. package/src/widgets/custom/Tag.tsx +0 -53
  215. package/src/widgets/custom/Tags.tsx +0 -164
  216. package/src/widgets/custom/Timeline.tsx +0 -196
  217. package/src/widgets/modals/ExportModal.tsx +0 -75
  218. package/src/widgets/modals/FormModal.tsx +0 -125
  219. package/src/widgets/modals/SearchModal.tsx +0 -130
  220. package/src/widgets/modals/TranslationModal.tsx +0 -202
  221. package/src/widgets/views/Dashboard/Dashboard.tsx +0 -381
  222. package/src/widgets/views/Dashboard/DashboardForm.tsx +0 -30
  223. package/src/widgets/views/Dashboard/DashboardTree.tsx +0 -238
  224. package/src/widgets/views/Dashboard/dashboardHelper.ts +0 -79
  225. package/src/widgets/views/DashboardGrid/DashboardGrid.tsx +0 -53
  226. package/src/widgets/views/DashboardGrid/DashboardGrid.types.ts +0 -4
  227. package/src/widgets/views/DashboardGrid/DashboardGridItem.tsx +0 -62
  228. package/src/widgets/views/DashboardGrid/DashboardGridItem.types.ts +0 -10
  229. package/src/widgets/views/DashboardGrid/index.ts +0 -4
  230. package/src/widgets/views/Form.tsx +0 -1152
  231. package/src/widgets/views/Graph/Graph.tsx +0 -145
  232. package/src/widgets/views/Graph/GraphChart.tsx +0 -113
  233. package/src/widgets/views/Graph/GraphDefaults.ts +0 -170
  234. package/src/widgets/views/Graph/GraphIndicator.tsx +0 -421
  235. package/src/widgets/views/Graph/useGraphData.tsx +0 -176
  236. package/src/widgets/views/SearchTree.tsx +0 -367
  237. package/src/widgets/views/Tree/Tree.tsx +0 -295
  238. package/src/widgets/views/Tree/index.ts +0 -1
  239. package/src/widgets/views/Tree/treeComponents.tsx +0 -276
  240. package/src/widgets/views/searchFilter/DateRangePicker.tsx +0 -16
  241. package/src/widgets/views/searchFilter/DateTimeRangePicker.tsx +0 -87
  242. package/src/widgets/views/searchFilter/PairFields.tsx +0 -56
  243. package/src/widgets/views/searchFilter/SearchBottomBar.tsx +0 -54
  244. package/src/widgets/views/searchFilter/SearchField.tsx +0 -63
  245. package/src/widgets/views/searchFilter/SearchFilter.tsx +0 -160
  246. package/src/widgets/views/searchFilter/SearchParams.tsx +0 -35
@@ -1,1152 +0,0 @@
1
- import React, {
2
- useState,
3
- forwardRef,
4
- useImperativeHandle,
5
- useEffect,
6
- useRef,
7
- useContext,
8
- } from "react";
9
- import { Form as FormOoui, parseContext } from "@gisce/ooui";
10
- import {
11
- Form as AntForm,
12
- Button,
13
- Divider,
14
- Space,
15
- Row,
16
- Alert,
17
- Spin,
18
- message,
19
- } from "antd";
20
- import Measure from "react-measure";
21
- import { CheckOutlined, CloseOutlined } from "@ant-design/icons";
22
- import debounce from "lodash/debounce";
23
-
24
- import Container from "@/widgets/containers/Container";
25
- import {
26
- processValues,
27
- getTouchedValues,
28
- checkFieldsType,
29
- mergeFieldsDomain,
30
- getValuesForDomain,
31
- getOnChangePayload,
32
- } from "@/helpers/formHelper";
33
- import ConnectionProvider from "@/ConnectionProvider";
34
- import showUnsavedChangesDialog from "@/ui/UnsavedChangesDialog";
35
- import formErrorsDialog from "@/ui/FormErrorsDialog";
36
- import showErrorDialog from "@/ui/ActionErrorDialog";
37
- import showWarningDialog from "@/ui/WarningDialog";
38
- import FormProvider, {
39
- FormContext,
40
- FormContextType,
41
- } from "@/context/FormContext";
42
- import { FormView, One2manyItem } from "@/index";
43
- import {
44
- FormModalContext,
45
- FormModalContextType,
46
- } from "@/context/FormModalContext";
47
-
48
- import {
49
- ActionViewContext,
50
- ActionViewContextType,
51
- } from "@/context/ActionViewContext";
52
-
53
- import {
54
- ContentRootContext,
55
- ContentRootContextType,
56
- } from "@/context/ContentRootContext";
57
- import { LocaleContext, LocaleContextType } from "@/context/LocaleContext";
58
- import { convertToPlain2ManyValues } from "@/helpers/one2manyHelper";
59
- import { ErrorAlert } from "@/ui/ErrorAlert";
60
-
61
- export type FormProps = {
62
- model: string;
63
- readOnly?: boolean;
64
- id?: number;
65
- formView?: FormView;
66
- values?: any;
67
- showFooter?: boolean;
68
- getDataFromAction?: boolean;
69
- mustClearAfterSave?: boolean;
70
- submitMode?: "api" | "values" | "2many";
71
- onSubmitSucceed?: (
72
- id?: number,
73
- values?: any,
74
- formValues?: any,
75
- x2manyPendingLink?: boolean,
76
- ) => void;
77
- onSubmitError?: (error: any) => void;
78
- onCancel?: () => void;
79
- onFieldsChange?: (values: any) => void;
80
- postSaveAction?: (event: any) => Promise<void>;
81
- insideButtonModal?: boolean;
82
- parentContext?: any;
83
- actionDomain?: any;
84
- visible?: boolean;
85
- rootForm?: boolean;
86
- defaultValues?: any;
87
- forcedValues?: any;
88
- parentWidth?: number;
89
- };
90
-
91
- const WIDTH_BREAKPOINT = 800;
92
-
93
- function Form(props: FormProps, ref: any) {
94
- const {
95
- model,
96
- id,
97
- onCancel: propsOnCancel,
98
- onSubmitSucceed: propsOnSubmitSucceed,
99
- showFooter = false,
100
- getDataFromAction = false,
101
- onFieldsChange,
102
- onSubmitError: propsOnSubmitError,
103
- readOnly = false,
104
- mustClearAfterSave = false,
105
- submitMode = "api",
106
- values: valuesProps,
107
- formView: formViewProps,
108
- postSaveAction,
109
- insideButtonModal = false,
110
- parentContext = {},
111
- actionDomain,
112
- visible = true,
113
- rootForm = false,
114
- defaultValues,
115
- forcedValues = {},
116
- parentWidth,
117
- } = props;
118
- const { t, lang } = useContext(LocaleContext) as LocaleContextType;
119
-
120
- const [isSubmitting, setIsSubmitting] = useState<boolean>(false);
121
- const [error, setError] = useState<string>();
122
- const [formOoui, setFormOoui] = useState<FormOoui>();
123
- const [antForm] = AntForm.useForm();
124
- const [arch, setArch] = useState<string>();
125
- const [fields, setFields] = useState<any>();
126
- const formModalContext = useContext(FormModalContext) as FormModalContextType;
127
- const [containerWidth, setContainerWidth] = useState<any>();
128
- const [defaultGetCalled, setDefaultGetCalled] = useState<boolean>(false);
129
-
130
- const createdId = useRef<number>();
131
- const originalFormValues = useRef<any>({});
132
- const lastAssignedValues = useRef<any>({});
133
- const warningIsShown = useRef<boolean>(false);
134
- const formSubmitting = useRef<boolean>(false);
135
- const x2manyPendingLink = useRef<boolean>(false);
136
-
137
- const widthToEvaluate =
138
- parentWidth !== undefined ? parentWidth : containerWidth;
139
- const responsiveBehaviour = widthToEvaluate < WIDTH_BREAKPOINT;
140
-
141
- const formContext = useContext(FormContext) as FormContextType;
142
- const { activeId: parentId, getPlainValues: getParentPlainValues } =
143
- formContext || {};
144
-
145
- const actionViewContext = useContext(
146
- ActionViewContext,
147
- ) as ActionViewContextType;
148
- const {
149
- setFormIsSaving = undefined,
150
- setFormHasChanges = undefined,
151
- setCurrentId = undefined,
152
- setFormIsLoading = undefined,
153
- setAttachments = undefined,
154
- title = undefined,
155
- setTitle = undefined,
156
- } = (rootForm ? actionViewContext : {}) || {};
157
-
158
- const contentRootContext = useContext(
159
- ContentRootContext,
160
- ) as ContentRootContextType;
161
- const { processAction, globalValues } = contentRootContext || {};
162
-
163
- useImperativeHandle(ref, () => ({
164
- submitForm,
165
- getFields,
166
- getValues,
167
- getPlainValues,
168
- getContext,
169
- fetchValues,
170
- cancelUnsavedChanges,
171
- clearAndReload: () => {
172
- createdId.current = undefined;
173
- setFormOoui(undefined);
174
- fetchData();
175
- },
176
- }));
177
-
178
- useEffect(() => {
179
- setError(undefined);
180
-
181
- if (!model && !formViewProps) {
182
- return;
183
- }
184
-
185
- if (!visible) {
186
- createdId.current = undefined;
187
- setFormOoui(undefined);
188
- return;
189
- }
190
-
191
- // In the case we set the id to undefined for creating a new item
192
- if (
193
- (id === undefined && fields) ||
194
- (id !== undefined && fields && id < 0)
195
- ) {
196
- createdId.current = undefined;
197
- setFormOoui(undefined);
198
- }
199
-
200
- fetchData();
201
- }, [id, model, valuesProps, formViewProps, visible]);
202
-
203
- useEffect(() => {
204
- if (defaultGetCalled) {
205
- checkFieldsChanges({
206
- elementHasLostFocus: true,
207
- });
208
- setDefaultGetCalled(false);
209
- }
210
- }, [defaultGetCalled]);
211
-
212
- const onSubmitSucceed = (
213
- id?: number,
214
- values?: any,
215
- formValues?: any,
216
- x2manyPendingLink?: boolean,
217
- ) => {
218
- setFormHasChanges?.(false);
219
- setFormIsSaving?.(false);
220
- propsOnSubmitSucceed?.(id, values, formValues, x2manyPendingLink);
221
- setCurrentId?.(id);
222
- };
223
-
224
- const onCancel = () => {
225
- setFormIsSaving?.(false);
226
- propsOnCancel?.();
227
- };
228
-
229
- const onSubmitError = (error: any) => {
230
- setFormIsSaving?.(false);
231
- propsOnSubmitError?.(error);
232
- };
233
-
234
- function getCurrentId() {
235
- return id || createdId.current;
236
- }
237
-
238
- function getFields() {
239
- return fields;
240
- }
241
-
242
- function getValues() {
243
- const values = {
244
- ...getCurrentValues(fields),
245
- ...getAdditionalValues(),
246
- };
247
-
248
- for (const key in values) {
249
- if (values[key] === undefined) {
250
- delete values[key];
251
- }
252
- }
253
-
254
- return values;
255
- }
256
-
257
- function getPlainValues() {
258
- const values: any = getValues();
259
- const fields: any = getFields();
260
- const reformattedValues: { [key: string]: any } = {};
261
-
262
- Object.keys(values).forEach((key) => {
263
- const value = values[key];
264
-
265
- if (
266
- fields[key] &&
267
- fields[key].type === "many2one" &&
268
- value &&
269
- Array.isArray(value) &&
270
- value.length === 2
271
- ) {
272
- reformattedValues[key] = value[0];
273
- } else if (
274
- fields[key] &&
275
- (fields[key].type === "one2many" || fields[key].type === "many2many") &&
276
- value &&
277
- value.items
278
- ) {
279
- reformattedValues[key] = value.items
280
- .filter((item: One2manyItem) => item.operation !== "pendingRemove")
281
- .map((val: any) => val.id);
282
- } else {
283
- reformattedValues[key] = value;
284
- }
285
- });
286
-
287
- return reformattedValues;
288
- }
289
-
290
- function getFormValues() {
291
- const values = {
292
- ...getCurrentValues(fields),
293
- };
294
-
295
- for (const key in values) {
296
- if (values[key] === undefined) {
297
- delete values[key];
298
- }
299
- }
300
-
301
- return values;
302
- }
303
-
304
- function getContext() {
305
- return { ...parentContext, ...formOoui?.context };
306
- }
307
-
308
- function getActiveIdsContext() {
309
- const currentId = getCurrentId()!;
310
-
311
- if (!currentId) {
312
- return {};
313
- }
314
- return { active_id: getCurrentId()!, active_ids: [getCurrentId()!] };
315
- }
316
-
317
- function getAdditionalValues() {
318
- return {
319
- id: getCurrentId()!,
320
- active_id: getCurrentId()!,
321
- active_ids: [getCurrentId()!],
322
- parent_id: parentId,
323
- ...globalValues,
324
- };
325
- }
326
-
327
- const getDefaultValues = async (fields: any) => {
328
- const formContext = getCurrentId() ? formOoui?.context : {};
329
- return await ConnectionProvider.getHandler().defaultGet({
330
- model,
331
- fields,
332
- context: { ...parentContext, ...formContext },
333
- extraValues: defaultValues,
334
- });
335
- };
336
-
337
- const formHasChanges = () => {
338
- return (
339
- Object.keys(
340
- getTouchedValues({
341
- source: originalFormValues.current,
342
- target: getCurrentValues(fields),
343
- fields,
344
- }),
345
- ).length !== 0
346
- );
347
- };
348
-
349
- const getCurrentValues = (fields: any) => {
350
- const currentValues = antForm.getFieldsValue(true);
351
- return processValues(currentValues, fields);
352
- };
353
-
354
- const setFieldValue = (field: string, value?: string) => {
355
- assignNewValuesToForm({
356
- values: {
357
- ...processValues(antForm.getFieldsValue(true), fields),
358
- [field]: value,
359
- },
360
- fields,
361
- reset: false,
362
- });
363
- };
364
-
365
- const getFieldValue = (field: string) => {
366
- const values = antForm.getFieldsValue(true);
367
- return values[field];
368
- };
369
-
370
- async function checkIfFormHasErrors() {
371
- try {
372
- await antForm.validateFields();
373
- return false;
374
- } catch (verror) {
375
- message.error(t("fillRequiredFields"));
376
- return true;
377
- }
378
- }
379
- const fetchData = async () => {
380
- setError(undefined);
381
- setFormIsLoading?.(true);
382
-
383
- let view;
384
-
385
- try {
386
- if (formViewProps) {
387
- view = { arch: formViewProps.arch, fields: formViewProps.fields };
388
- } else {
389
- view = await getFormView();
390
- }
391
-
392
- const { fields, arch } = view;
393
- setFields(fields);
394
- setArch(arch);
395
-
396
- await fetchValues({
397
- fields,
398
- arch,
399
- });
400
- } catch (err) {
401
- setError(err?.message ? err.message + err.stack : err);
402
- setFormIsLoading?.(false);
403
- // setLoading(false);
404
- }
405
- };
406
-
407
- type FetchValuesOptions = {
408
- fields?: any;
409
- arch?: string;
410
- forceRefresh?: boolean;
411
- };
412
-
413
- const fetchValues = async (options?: FetchValuesOptions) => {
414
- let values;
415
- let _fields;
416
- let _arch;
417
- let hasDefaultGetCalled;
418
-
419
- setFormIsLoading?.(true);
420
- setError(undefined);
421
-
422
- if (options?.fields) {
423
- _fields = options.fields;
424
- _arch = options.arch;
425
- } else {
426
- _fields = fields;
427
- _arch = arch;
428
- }
429
-
430
- if (valuesProps && options?.forceRefresh !== true) {
431
- values = valuesProps;
432
- } else {
433
- ({ values, defaultGetCalled: hasDefaultGetCalled } =
434
- await fetchValuesFromApi({
435
- fields: _fields,
436
- arch: _arch!,
437
- }));
438
- }
439
-
440
- if (actionDomain) {
441
- values = { ...getValuesForDomain(actionDomain), ...values };
442
- }
443
-
444
- originalFormValues.current = processValues(values, _fields);
445
-
446
- assignNewValuesToForm({
447
- values,
448
- fields: _fields,
449
- reset: true,
450
- isDefaultGet: hasDefaultGetCalled,
451
- });
452
- parseForm({ fields: _fields, arch: _arch!, values });
453
- setFormIsLoading?.(false);
454
- setFormHasChanges?.(false);
455
-
456
- if (hasDefaultGetCalled) {
457
- setDefaultGetCalled(true);
458
- }
459
- };
460
-
461
- const cancelUnsavedChanges = async () => {
462
- return new Promise(async (resolve) => {
463
- if (formHasChanges()) {
464
- showUnsavedChangesDialog({
465
- lang,
466
- onOk: () => {
467
- onCancel?.();
468
- resolve(true);
469
- },
470
- onCancel: () => {
471
- resolve(false);
472
- },
473
- });
474
- } else {
475
- onCancel?.();
476
- resolve(true);
477
- }
478
- });
479
- };
480
-
481
- const getFormView = async (): Promise<FormView> => {
482
- if (getDataFromAction) {
483
- const action =
484
- await ConnectionProvider.getHandler().getActionStringForModel(model);
485
- const viewsForAction =
486
- await ConnectionProvider.getHandler().getViewsForAction({
487
- action,
488
- context: parentContext,
489
- });
490
- return viewsForAction.views.get("form");
491
- }
492
-
493
- return (await ConnectionProvider.getHandler().getView({
494
- model,
495
- type: "form",
496
- context: parentContext,
497
- })) as FormView;
498
- };
499
-
500
- const assignNewValuesToForm = ({
501
- values: newValues,
502
- fields,
503
- reset,
504
- isDefaultGet = false,
505
- }: {
506
- values: any;
507
- fields: any;
508
- reset: boolean;
509
- isDefaultGet?: boolean;
510
- }) => {
511
- const currentValues = reset ? {} : antForm.getFieldsValue(true);
512
- const mergedValues = { ...currentValues, ...newValues };
513
- const valuesProcessed = processValues(mergedValues, fields);
514
- const fieldsToUpdate = Object.keys(fields).map((fieldName) => {
515
- const fieldValue =
516
- valuesProcessed[fieldName] !== undefined
517
- ? valuesProcessed[fieldName]
518
- : undefined;
519
- return {
520
- name: fieldName,
521
- touched: false,
522
- value: fieldValue,
523
- };
524
- });
525
-
526
- if (!isDefaultGet) {
527
- lastAssignedValues.current = valuesProcessed;
528
- }
529
-
530
- antForm.setFields(fieldsToUpdate);
531
- };
532
-
533
- const fetchValuesFromApi = async ({
534
- fields,
535
- arch,
536
- }: {
537
- fields: any;
538
- arch: string;
539
- }) => {
540
- let values = {};
541
- let defaultGetCalled = false;
542
-
543
- if (getCurrentId()!) {
544
- values = (
545
- await ConnectionProvider.getHandler().readObjects({
546
- model,
547
- ids: [getCurrentId()!],
548
- fields,
549
- context: parentContext,
550
- })
551
- )[0];
552
-
553
- const results = await ConnectionProvider.getHandler().search({
554
- params: [
555
- ["res_model", "=", model],
556
- ["res_id", "=", getCurrentId()!],
557
- ],
558
- fieldsToRetrieve: ["id", "name"],
559
- context: getContext(),
560
- model: "ir.attachment",
561
- });
562
- setAttachments?.(results);
563
- } else {
564
- setAttachments?.([]);
565
- values = await getDefaultValues(fields);
566
- defaultGetCalled = true;
567
- }
568
- return { values, defaultGetCalled };
569
- };
570
-
571
- const submitApi = async (options?: { callOnSubmitSucceed?: boolean }) => {
572
- const { callOnSubmitSucceed = true } = options || {};
573
-
574
- if (getCurrentId()) {
575
- const touchedValues = getTouchedValues({
576
- source: originalFormValues.current,
577
- target: getCurrentValues(fields),
578
- fields,
579
- });
580
-
581
- await ConnectionProvider.getHandler().update({
582
- model,
583
- id: getCurrentId()!,
584
- values: { ...touchedValues, ...forcedValues },
585
- fields,
586
- context: {
587
- ...parentContext,
588
- ...formOoui?.context,
589
- },
590
- });
591
- originalFormValues.current = getCurrentValues(fields);
592
- } else {
593
- const currentValues = getCurrentValues(fields);
594
-
595
- const newId = await ConnectionProvider.getHandler().create({
596
- model,
597
- values: { ...currentValues, ...forcedValues },
598
- fields,
599
- context: {
600
- ...parentContext,
601
- ...formOoui?.context,
602
- },
603
- });
604
- createdId.current = newId;
605
- originalFormValues.current = currentValues;
606
- }
607
-
608
- if (postSaveAction) {
609
- await postSaveAction([getCurrentId()]);
610
- }
611
-
612
- if (!insideButtonModal && callOnSubmitSucceed) {
613
- onSubmitSucceed?.(getCurrentId(), getValues(), getFormValues());
614
- }
615
- };
616
-
617
- const submitValues = async (options?: { callOnSubmitSucceed?: boolean }) => {
618
- const { callOnSubmitSucceed = true } = options || {};
619
-
620
- if (!insideButtonModal && callOnSubmitSucceed) {
621
- onSubmitSucceed?.(getCurrentId(), getValues(), getFormValues());
622
- }
623
- };
624
-
625
- const submitForm = async (options?: { callOnSubmitSucceed?: boolean }) => {
626
- let submitSucceed = false;
627
- const { callOnSubmitSucceed = true } = options || {};
628
- formSubmitting.current = true;
629
-
630
- setError(undefined);
631
-
632
- if (
633
- x2manyPendingLink.current &&
634
- !formHasChanges() &&
635
- getCurrentId()! &&
636
- callOnSubmitSucceed
637
- ) {
638
- formSubmitting.current = false;
639
- setFormHasChanges?.(false);
640
- onSubmitSucceed?.(
641
- getCurrentId(),
642
- getValues(),
643
- getFormValues(),
644
- x2manyPendingLink.current,
645
- );
646
- x2manyPendingLink.current = false;
647
- const currentId = getCurrentId()!;
648
-
649
- if (mustClearAfterSave) {
650
- createdId.current = undefined;
651
- assignNewValuesToForm({ values: {}, fields, reset: true });
652
- }
653
-
654
- return { succeed: true, id: currentId };
655
- }
656
-
657
- if (!formHasChanges() && getCurrentId()! && callOnSubmitSucceed) {
658
- formSubmitting.current = false;
659
- setFormHasChanges?.(false);
660
- onCancel?.();
661
- return { succeed: true, id: getCurrentId()! };
662
- }
663
-
664
- if (await checkIfFormHasErrors()) {
665
- formSubmitting.current = false;
666
- formErrorsDialog(lang);
667
- return { succeed: false, id: getCurrentId()! };
668
- }
669
-
670
- setIsSubmitting(true);
671
- setFormIsSaving?.(true);
672
-
673
- try {
674
- if (submitMode === "api") {
675
- await submitApi(options);
676
- } else {
677
- await submitValues(options);
678
- }
679
-
680
- if (mustClearAfterSave) {
681
- createdId.current = undefined;
682
- assignNewValuesToForm({ values: {}, fields, reset: true });
683
- }
684
-
685
- await fetchValues({ forceRefresh: true });
686
- submitSucceed = true;
687
- message.success(t("savedRegisters"));
688
- } catch (err) {
689
- formSubmitting.current = false;
690
- setIsSubmitting(false);
691
- setFormIsSaving?.(false);
692
- onSubmitError?.(err);
693
- message.error(t("errorWhileSavingForm"));
694
- setError(err?.message ? err.message : err);
695
- } finally {
696
- formSubmitting.current = false;
697
- setFormIsSaving?.(false);
698
- setIsSubmitting(false);
699
- }
700
-
701
- return { succeed: submitSucceed, id: getCurrentId()! };
702
- };
703
-
704
- const parseForm = ({
705
- fields,
706
- arch,
707
- values,
708
- operationInProgress = false,
709
- }: {
710
- arch: string;
711
- fields: any;
712
- values: any;
713
- operationInProgress?: boolean;
714
- }) => {
715
- const ooui = new FormOoui(fields);
716
- // TODO: Here we must inject `values` to the ooui parser in order to evaluate arch+values and get the new form container
717
- ooui.parse(arch, {
718
- readOnly: readOnly || operationInProgress,
719
- values: convertToPlain2ManyValues(
720
- {
721
- ...values,
722
- ...getAdditionalValues(),
723
- },
724
- fields,
725
- ),
726
- });
727
- setFormOoui(ooui);
728
-
729
- if (ooui.string && ooui.string !== title) {
730
- setTitle?.(ooui.string);
731
- }
732
-
733
- if (formModalContext && ooui.string)
734
- formModalContext.setTitle?.(ooui.string);
735
- };
736
-
737
- const checkFieldsChanges = async ({
738
- elementHasLostFocus = false,
739
- }: {
740
- elementHasLostFocus?: boolean;
741
- }) => {
742
- if (formSubmitting.current) return;
743
-
744
- const touchedValues = getTouchedValues({
745
- source: lastAssignedValues.current,
746
- target: getCurrentValues(fields),
747
- fields,
748
- });
749
-
750
- const changedFields = Object.keys(touchedValues);
751
-
752
- if (changedFields.length !== 0) {
753
- // We check if there are any field of type text, email, url or char inside the changed values
754
- // in order to ignore the call, because it will fire when element lost focus
755
- if (
756
- checkFieldsType({
757
- changedFields,
758
- formOoui: formOoui!,
759
- types: [
760
- "text",
761
- "codeeditor",
762
- "email",
763
- "url",
764
- "char",
765
- "float",
766
- "float_time",
767
- "integer",
768
- "many2one",
769
- ],
770
- }) &&
771
- elementHasLostFocus !== true
772
- ) {
773
- } else {
774
- const values = processValues(antForm.getFieldsValue(true), fields);
775
- lastAssignedValues.current = values;
776
-
777
- onFieldsChange?.(values);
778
- setFormHasChanges?.(true);
779
-
780
- evaluateChanges(changedFields);
781
- }
782
- }
783
- };
784
-
785
- const debouncedCheckFieldsChanges = debounce(checkFieldsChanges, 100);
786
-
787
- const evaluateChanges = async (changedFields: any) => {
788
- try {
789
- for (let i = 0; i < changedFields.length; i += 1) {
790
- const changedField = changedFields[i];
791
- await processFieldOnChange(changedField);
792
- }
793
- } catch (err) {
794
- showErrorDialog(err);
795
- }
796
- };
797
-
798
- const processFieldOnChange = async (fieldName: string) => {
799
- const onChangeFieldAction = formOoui?.onChangeFields[fieldName];
800
-
801
- if (!onChangeFieldAction) {
802
- parseForm({
803
- fields,
804
- arch: arch!,
805
- values: getCurrentValues(fields),
806
- });
807
- return;
808
- }
809
-
810
- const payload = getOnChangePayload({
811
- values: {
812
- ...getCurrentValues(fields),
813
- context: {
814
- ...parentContext,
815
- ...formOoui?.context,
816
- },
817
- },
818
- parentValues: getParentPlainValues?.(),
819
- onChangeFieldActionArgs: onChangeFieldAction.args,
820
- });
821
-
822
- const response = await ConnectionProvider.getHandler().executeOnChange({
823
- model,
824
- action: onChangeFieldAction.method,
825
- ids: getCurrentId()! ? [getCurrentId()!] : [],
826
- payload,
827
- fields,
828
- });
829
-
830
- if (response.value) {
831
- const processedValues = {
832
- ...getCurrentValues(fields),
833
- ...response.value,
834
- };
835
- parseForm({ fields, arch: arch!, values: processedValues });
836
- assignNewValuesToForm({
837
- values: processedValues,
838
- fields,
839
- reset: false,
840
- });
841
- }
842
-
843
- if (
844
- response.warning &&
845
- response.warning.title &&
846
- response.warning.message &&
847
- !warningIsShown.current
848
- ) {
849
- const { title, message } = response.warning;
850
- warningIsShown.current = true;
851
- showWarningDialog(title, message, () => {
852
- warningIsShown.current = false;
853
- });
854
- }
855
-
856
- if (response.domain && Object.keys(response.domain).length > 0) {
857
- const proccessedFields = mergeFieldsDomain({
858
- fieldsDomain: response.domain,
859
- fields,
860
- });
861
-
862
- parseForm({
863
- fields: proccessedFields,
864
- arch: arch!,
865
- values: getCurrentValues(proccessedFields),
866
- });
867
- setFields(proccessedFields);
868
- }
869
- };
870
-
871
- async function runObjectButton({
872
- action,
873
- context,
874
- }: {
875
- action: string;
876
- context: any;
877
- }) {
878
- const response = await ConnectionProvider.getHandler().execute({
879
- model,
880
- action,
881
- payload: [getCurrentId()!],
882
- context: {
883
- ...formOoui?.context,
884
- ...parentContext,
885
- ...context,
886
- },
887
- });
888
-
889
- if (
890
- typeof response === "object" &&
891
- response !== null &&
892
- Object.keys(response).length === 0 &&
893
- insideButtonModal
894
- ) {
895
- onSubmitSucceed?.(getCurrentId(), getValues(), getFormValues());
896
- } else if (
897
- response.type &&
898
- response.type === "ir.actions.act_window_close"
899
- ) {
900
- onSubmitSucceed?.(getCurrentId(), getValues(), getFormValues());
901
- } else if (response.type) {
902
- let responseContext = {};
903
-
904
- if (response.context) {
905
- responseContext = parseContext({
906
- context: response.context,
907
- fields,
908
- values: getValues(),
909
- });
910
- }
911
-
912
- await runAction({
913
- actionData: response,
914
- context: { ...context, ...responseContext },
915
- });
916
- } else {
917
- await fetchValues({ forceRefresh: true });
918
- }
919
- }
920
-
921
- async function runWorkflowButton({ action }: { action: string }) {
922
- const response = await ConnectionProvider.getHandler().executeWorkflow({
923
- model,
924
- action,
925
- payload: getCurrentId()!,
926
- });
927
-
928
- if (response.type && response.type === "ir.actions.act_window_close") {
929
- onSubmitSucceed?.(getCurrentId(), getValues(), getFormValues());
930
- } else {
931
- await fetchValues({ forceRefresh: true });
932
- }
933
- }
934
-
935
- async function runActionButton({
936
- action,
937
- context,
938
- }: {
939
- action: string;
940
- context: any;
941
- }) {
942
- const actionData = (
943
- await ConnectionProvider.getHandler().readObjects({
944
- model: "ir.actions.actions",
945
- ids: [parseInt(action)],
946
- context: parentContext,
947
- })
948
- )[0];
949
-
950
- await runAction({ actionData, context });
951
- }
952
-
953
- async function runAction({
954
- actionData,
955
- context,
956
- }: {
957
- actionData: any;
958
- context: any;
959
- }) {
960
- const { closeParent } =
961
- (await processAction?.({
962
- actionData,
963
- fields,
964
- values: getValues(),
965
- context: {
966
- ...parentContext,
967
- ...formOoui?.context,
968
- ...context,
969
- },
970
- onRefreshParentValues: () => {
971
- fetchValues({ forceRefresh: true });
972
- },
973
- })) || {};
974
-
975
- if (!rootForm && closeParent) {
976
- onSubmitSucceed?.(getCurrentId(), getValues(), getFormValues());
977
- }
978
- }
979
-
980
- function elementHasLostFocus() {
981
- checkFieldsChanges({ elementHasLostFocus: true });
982
- }
983
-
984
- function updateOperationInProgress(value: boolean) {
985
- parseForm({
986
- fields,
987
- arch: arch!,
988
- values: getCurrentValues(fields),
989
- operationInProgress: value,
990
- });
991
- }
992
-
993
- async function executeButtonAction({
994
- type,
995
- action,
996
- context,
997
- }: {
998
- type: string;
999
- action: string;
1000
- context?: any;
1001
- }) {
1002
- // If the type of the button it's a cancel, we just close our form
1003
- if (type === "cancel") {
1004
- onCancel?.();
1005
- return;
1006
- }
1007
-
1008
- // We check for required fields
1009
- if (await checkIfFormHasErrors()) {
1010
- formErrorsDialog(lang);
1011
- return;
1012
- }
1013
-
1014
- let mustBlockButtons = false;
1015
-
1016
- try {
1017
- if (!readOnly && (formHasChanges() || getCurrentId() === undefined)) {
1018
- mustBlockButtons = true;
1019
- updateOperationInProgress(true);
1020
- if (submitMode === "2many") {
1021
- await submitApi({ callOnSubmitSucceed: false });
1022
- x2manyPendingLink.current = true;
1023
- } else {
1024
- await submitForm({ callOnSubmitSucceed: false });
1025
- }
1026
- }
1027
-
1028
- const additionalContext = x2manyPendingLink.current
1029
- ? getActiveIdsContext()
1030
- : {};
1031
-
1032
- const updatedContext = { ...context, ...additionalContext };
1033
-
1034
- if (type === "object") {
1035
- await runObjectButton({ action, context: updatedContext });
1036
- } else if (type === "workflow") {
1037
- await runWorkflowButton({ action });
1038
- } else if (type === "action") {
1039
- await runActionButton({ action, context: updatedContext });
1040
- }
1041
- mustBlockButtons && updateOperationInProgress(false);
1042
- } catch (err) {
1043
- mustBlockButtons && updateOperationInProgress(false);
1044
- showErrorDialog(err);
1045
- }
1046
- }
1047
-
1048
- const content = () => {
1049
- if (!formOoui && !error) {
1050
- return <Spin />;
1051
- }
1052
-
1053
- if (!model && !formViewProps) {
1054
- return null;
1055
- }
1056
-
1057
- if (!visible) {
1058
- return null;
1059
- }
1060
-
1061
- return (
1062
- <>
1063
- <FormProvider
1064
- getValues={getValues}
1065
- getPlainValues={getPlainValues}
1066
- getFields={getFields}
1067
- domain={actionDomain}
1068
- activeId={id}
1069
- activeModel={model}
1070
- setFieldValue={setFieldValue}
1071
- getFieldValue={getFieldValue}
1072
- executeButtonAction={executeButtonAction}
1073
- getContext={getContext}
1074
- submitForm={submitForm}
1075
- fetchValues={fetchValues}
1076
- formHasChanges={formHasChanges}
1077
- elementHasLostFocus={elementHasLostFocus}
1078
- >
1079
- <AntForm
1080
- form={antForm}
1081
- onFieldsChange={() => {
1082
- debouncedCheckFieldsChanges({ elementHasLostFocus: false });
1083
- }}
1084
- component={false}
1085
- >
1086
- {formOoui && (
1087
- <Container
1088
- container={formOoui.container}
1089
- responsiveBehaviour={responsiveBehaviour}
1090
- />
1091
- )}
1092
- </AntForm>
1093
- </FormProvider>
1094
- </>
1095
- );
1096
- };
1097
-
1098
- const footer = () => {
1099
- return (
1100
- <>
1101
- <Divider />
1102
- <Row justify="end">
1103
- <Space>
1104
- <Button
1105
- icon={<CloseOutlined />}
1106
- disabled={isSubmitting}
1107
- onClick={async () => {
1108
- await cancelUnsavedChanges();
1109
- }}
1110
- >
1111
- Cancel
1112
- </Button>
1113
- <Button
1114
- disabled={isSubmitting || readOnly}
1115
- loading={isSubmitting}
1116
- icon={<CheckOutlined />}
1117
- onClick={async () => {
1118
- await submitForm();
1119
- }}
1120
- type="primary"
1121
- >
1122
- OK
1123
- </Button>
1124
- </Space>
1125
- </Row>
1126
- </>
1127
- );
1128
- };
1129
-
1130
- if (!visible) {
1131
- return null;
1132
- }
1133
-
1134
- return (
1135
- <Measure
1136
- bounds
1137
- onResize={(contentRect) => {
1138
- setContainerWidth(contentRect.bounds?.width!);
1139
- }}
1140
- >
1141
- {({ measureRef }) => (
1142
- <div className="pb-2" ref={measureRef}>
1143
- {error && <ErrorAlert className="mt-5 mb-10" error={error} />}
1144
- {content()}
1145
- {showFooter && footer()}
1146
- </div>
1147
- )}
1148
- </Measure>
1149
- );
1150
- }
1151
-
1152
- export default forwardRef(Form);