@gisce/react-ooui 2.0.0-alpha.62 → 2.0.0-alpha.64

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 (245) hide show
  1. package/dist/react-ooui.es.js +1 -1
  2. package/dist/react-ooui.es.js.map +1 -1
  3. package/package.json +7 -9
  4. package/src/ConnectionProvider.ts +0 -16
  5. package/src/__tests__/iconMapper.test.ts +0 -30
  6. package/src/__tests__/searchFilterHelper.spec.ts +0 -386
  7. package/src/actionbar/ActionButton.tsx +0 -40
  8. package/src/actionbar/AttachmentsButton.tsx +0 -132
  9. package/src/actionbar/AttachmentsButtonWrapper.tsx +0 -157
  10. package/src/actionbar/ButtonWithBadge.tsx +0 -44
  11. package/src/actionbar/ChangeViewButton.tsx +0 -137
  12. package/src/actionbar/DashboardActionBar.tsx +0 -63
  13. package/src/actionbar/DropdownButton.tsx +0 -124
  14. package/src/actionbar/FormActionBar.tsx +0 -491
  15. package/src/actionbar/GraphActionBar.tsx +0 -67
  16. package/src/actionbar/NewButton.tsx +0 -46
  17. package/src/actionbar/SearchBar.tsx +0 -73
  18. package/src/actionbar/TreeActionBar.tsx +0 -383
  19. package/src/common/ButtonWithTooltip.tsx +0 -18
  20. package/src/common/DatePicker.tsx +0 -98
  21. package/src/common/Field.tsx +0 -93
  22. package/src/common/SelectAllRecordsRow.tsx +0 -94
  23. package/src/common/TimePicker.tsx +0 -38
  24. package/src/context/ActionViewContext.tsx +0 -213
  25. package/src/context/ConfigContext.tsx +0 -28
  26. package/src/context/ContentRootContext.tsx +0 -461
  27. package/src/context/DashboardActionContext.tsx +0 -44
  28. package/src/context/FormContext.tsx +0 -79
  29. package/src/context/FormModalContext.tsx +0 -28
  30. package/src/context/LocaleContext.tsx +0 -50
  31. package/src/context/One2manyContext.tsx +0 -45
  32. package/src/context/TabManagerContext.tsx +0 -117
  33. package/src/helpers/containerHelper.ts +0 -145
  34. package/src/helpers/dayjs.ts +0 -21
  35. package/src/helpers/dynamicColumnsHelper.ts +0 -73
  36. package/src/helpers/errorHelper.ts +0 -27
  37. package/src/helpers/filesHelper.ts +0 -41
  38. package/src/helpers/formHelper.ts +0 -301
  39. package/src/helpers/iconMapper.ts +0 -164
  40. package/src/helpers/logInfoHelper.tsx +0 -30
  41. package/src/helpers/one2manyHelper.ts +0 -194
  42. package/src/helpers/searchHelper.ts +0 -196
  43. package/src/helpers/timeHelper.ts +0 -58
  44. package/src/helpers/treeHelper.tsx +0 -226
  45. package/src/helpers/viewHelper.ts +0 -23
  46. package/src/hooks/useEffectDebugger.ts +0 -43
  47. package/src/hooks/useExport.ts +0 -439
  48. package/src/hooks/useFetchViews.ts +0 -0
  49. package/src/hooks/useSearch.ts +0 -434
  50. package/src/hooks/useWindowDimensions.ts +0 -33
  51. package/src/index.ts +0 -168
  52. package/src/locales/ca_ES.tsx +0 -99
  53. package/src/locales/en_US.tsx +0 -96
  54. package/src/locales/es_ES.tsx +0 -101
  55. package/src/stories/Binary.stories.tsx +0 -23
  56. package/src/stories/Boolean.stories.tsx +0 -22
  57. package/src/stories/Button.stories.tsx +0 -130
  58. package/src/stories/Char.stories.tsx +0 -76
  59. package/src/stories/FiberGrid.stories.tsx +0 -109
  60. package/src/stories/Float.stories.tsx +0 -22
  61. package/src/stories/FloatTime.stories.tsx +0 -32
  62. package/src/stories/Image.stories.tsx +0 -25
  63. package/src/stories/Integer.stories.tsx +0 -22
  64. package/src/stories/Label.stories.tsx +0 -100
  65. package/src/stories/Many2one.stories.tsx +0 -31
  66. package/src/stories/One2many.stories.tsx +0 -288
  67. package/src/stories/ProgressBar.stories.tsx +0 -22
  68. package/src/stories/Reference.stories.tsx +0 -43
  69. package/src/stories/Selection.stories.tsx +0 -34
  70. package/src/stories/Separator.stories.tsx +0 -53
  71. package/src/stories/Text.stories.tsx +0 -35
  72. package/src/stories/Time.stories.tsx +0 -31
  73. package/src/stories/Utils.stories.tsx +0 -14
  74. package/src/stories/containers/Group.stories.tsx +0 -84
  75. package/src/stories/containers/NewLine.stories.tsx +0 -52
  76. package/src/stories/containers/Notebook.stories.tsx +0 -188
  77. package/src/stories/custom/Avatar.stories.tsx +0 -22
  78. package/src/stories/custom/ButtonGroup.stories.tsx +0 -74
  79. package/src/stories/custom/CodeEditor.stories.tsx +0 -25
  80. package/src/stories/custom/Comments.stories.tsx +0 -197
  81. package/src/stories/custom/Indicator.stories.tsx +0 -36
  82. package/src/stories/custom/Markdown.stories.tsx +0 -38
  83. package/src/stories/custom/MultiCheckbox.stories.tsx +0 -60
  84. package/src/stories/custom/Radio.stories.tsx +0 -68
  85. package/src/stories/custom/Steps.stories.tsx +0 -43
  86. package/src/stories/custom/Switch.stories.tsx +0 -23
  87. package/src/stories/custom/Tag.stories.tsx +0 -66
  88. package/src/stories/custom/Tags.stories.tsx +0 -74
  89. package/src/stories/dashboard/Dashboard.stories.tsx +0 -23
  90. package/src/stories/dashboard/DashboardGrid.stories.tsx +0 -43
  91. package/src/stories/forms/ActivacioContracteForm.stories.tsx +0 -25
  92. package/src/stories/forms/Attachment.stories.tsx +0 -24
  93. package/src/stories/forms/CUPSForm.stories.tsx +0 -25
  94. package/src/stories/forms/Company.stories.tsx +0 -25
  95. package/src/stories/forms/CrmCaseForm.stories.tsx +0 -25
  96. package/src/stories/forms/Documents.stories.tsx +0 -25
  97. package/src/stories/forms/FormWithGridFiber.stories.tsx +0 -25
  98. package/src/stories/forms/FormWithLinks.stories.tsx +0 -30
  99. package/src/stories/forms/Lead.stories.tsx +0 -25
  100. package/src/stories/forms/ModContractForm.stories.tsx +0 -26
  101. package/src/stories/forms/PartnersForm.stories.tsx +0 -25
  102. package/src/stories/forms/PolissaForm.stories.tsx +0 -25
  103. package/src/stories/forms/PreferencesForm.stories.tsx +0 -691
  104. package/src/stories/forms/Signatures.stories.tsx +0 -25
  105. package/src/stories/forms/Switching.stories.tsx +0 -25
  106. package/src/stories/graphs/GraphIndicator.stories.tsx +0 -20
  107. package/src/stories/graphs/PieGraph.stories.tsx +0 -78
  108. package/src/stories/mocks/index.ts +0 -46
  109. package/src/stories/mocks/mockProvider.ts +0 -189
  110. package/src/stories/mocks/models/activacioContracte.ts +0 -112
  111. package/src/stories/mocks/models/attachment.ts +0 -1326
  112. package/src/stories/mocks/models/butlleti.ts +0 -296
  113. package/src/stories/mocks/models/company.ts +0 -135
  114. package/src/stories/mocks/models/crm_case.ts +0 -595
  115. package/src/stories/mocks/models/cups.ts +0 -937
  116. package/src/stories/mocks/models/document.ts +0 -223
  117. package/src/stories/mocks/models/factura.ts +0 -2713
  118. package/src/stories/mocks/models/form_with_gridfiber.ts +0 -141
  119. package/src/stories/mocks/models/hist_autoconsum.ts +0 -146
  120. package/src/stories/mocks/models/lead.ts +0 -2101
  121. package/src/stories/mocks/models/modcontractual.ts +0 -952
  122. package/src/stories/mocks/models/partner.ts +0 -1340
  123. package/src/stories/mocks/models/polissa.ts +0 -3127
  124. package/src/stories/mocks/models/res_partner_category.ts +0 -15
  125. package/src/stories/mocks/models/signatura.ts +0 -558
  126. package/src/stories/mocks/models/switching.ts +0 -767
  127. package/src/stories/modals/FormModal.stories.tsx +0 -36
  128. package/src/stories/modals/SearchModal.stories.tsx +0 -37
  129. package/src/stories/trees/FacturesTree.stories.tsx +0 -16
  130. package/src/stories/ui/ActionBar.stories.tsx +0 -21
  131. package/src/stories/ui/FavouriteButton.stories.tsx +0 -16
  132. package/src/stories/ui/GoToResourceModal.stories.tsx +0 -25
  133. package/src/stories/views/ActionView.stories.tsx +0 -28
  134. package/src/stories/views/SearchTree.stories.tsx +0 -1064
  135. package/src/stories/views/Tab.stories.tsx +0 -93
  136. package/src/stories/views/TabsAndContent.stories.tsx +0 -88
  137. package/src/stories/views/Tree.stories.jsx +0 -178
  138. package/src/stories/views/searchFilter/DateRangePicker.stories.tsx +0 -22
  139. package/src/stories/views/searchFilter/DateTimeRangePicker.stories.tsx +0 -23
  140. package/src/stories/views/searchFilter/PairFields.stories.tsx +0 -23
  141. package/src/stories/views/searchFilter/SearchFilter.stories.tsx +0 -165
  142. package/src/stories/views/searchFilter/examples/PartnersSearchFilter.stories.tsx +0 -409
  143. package/src/types/index.ts +0 -392
  144. package/src/ui/ActionErrorDialog.tsx +0 -24
  145. package/src/ui/ConfirmDialog.tsx +0 -28
  146. package/src/ui/ErrorAlert.tsx +0 -37
  147. package/src/ui/FavouriteButton.tsx +0 -271
  148. package/src/ui/FormErrorsDialog.tsx +0 -17
  149. package/src/ui/GenericErrorDialog.tsx +0 -16
  150. package/src/ui/GoToResourceModal.tsx +0 -76
  151. package/src/ui/InfoDialog.tsx +0 -13
  152. package/src/ui/RefreshItemDialog.tsx +0 -29
  153. package/src/ui/RemoveItemDialog.tsx +0 -20
  154. package/src/ui/TitleHeader.tsx +0 -117
  155. package/src/ui/UnlinkItemDialog.tsx +0 -20
  156. package/src/ui/UnsavedChangesDialog.tsx +0 -29
  157. package/src/ui/WarningDialog.tsx +0 -17
  158. package/src/views/ActionView.tsx +0 -526
  159. package/src/views/CurrentTabContent.tsx +0 -21
  160. package/src/views/RootView.tsx +0 -509
  161. package/src/views/TabContent.tsx +0 -31
  162. package/src/views/TabSelector.tsx +0 -31
  163. package/src/views/Welcome.tsx +0 -18
  164. package/src/views/actionViews/DashboardActionView.tsx +0 -52
  165. package/src/views/actionViews/FormActionView.tsx +0 -70
  166. package/src/views/actionViews/GraphActionView.tsx +0 -152
  167. package/src/views/actionViews/TreeActionView.tsx +0 -87
  168. package/src/views/tabs/Tab.tsx +0 -82
  169. package/src/widgets/WidgetFactory.tsx +0 -142
  170. package/src/widgets/base/Binary.tsx +0 -145
  171. package/src/widgets/base/Boolean.tsx +0 -44
  172. package/src/widgets/base/Button.tsx +0 -77
  173. package/src/widgets/base/Char.tsx +0 -157
  174. package/src/widgets/base/Date.tsx +0 -12
  175. package/src/widgets/base/DateTime.tsx +0 -12
  176. package/src/widgets/base/Email.tsx +0 -27
  177. package/src/widgets/base/Float.tsx +0 -38
  178. package/src/widgets/base/FloatTime.tsx +0 -73
  179. package/src/widgets/base/Image.tsx +0 -120
  180. package/src/widgets/base/Integer.tsx +0 -55
  181. package/src/widgets/base/Label.tsx +0 -56
  182. package/src/widgets/base/LinkInput.tsx +0 -106
  183. package/src/widgets/base/MultiSelection.tsx +0 -90
  184. package/src/widgets/base/ProgressBar.tsx +0 -38
  185. package/src/widgets/base/Reference.tsx +0 -115
  186. package/src/widgets/base/ReferenceTree.tsx +0 -62
  187. package/src/widgets/base/Selection.tsx +0 -71
  188. package/src/widgets/base/Separator.tsx +0 -25
  189. package/src/widgets/base/Text.tsx +0 -162
  190. package/src/widgets/base/Time.tsx +0 -40
  191. package/src/widgets/base/Url.tsx +0 -26
  192. package/src/widgets/base/many2one/Many2one.tsx +0 -322
  193. package/src/widgets/base/many2one/Many2oneSuffix.tsx +0 -232
  194. package/src/widgets/base/many2one/Many2oneSuffixModal.tsx +0 -42
  195. package/src/widgets/base/many2one/Many2oneTree.tsx +0 -18
  196. package/src/widgets/base/one2many/One2many.tsx +0 -100
  197. package/src/widgets/base/one2many/One2manyInput.tsx +0 -724
  198. package/src/widgets/base/one2many/One2manyTopBar.tsx +0 -158
  199. package/src/widgets/containers/Container.tsx +0 -99
  200. package/src/widgets/containers/Group.tsx +0 -37
  201. package/src/widgets/containers/Notebook.tsx +0 -52
  202. package/src/widgets/custom/Avatar.tsx +0 -40
  203. package/src/widgets/custom/ButtonGroup.tsx +0 -169
  204. package/src/widgets/custom/CodeEditor.tsx +0 -32
  205. package/src/widgets/custom/Comments.tsx +0 -147
  206. package/src/widgets/custom/FiberGrid.tsx +0 -48
  207. package/src/widgets/custom/Indicator.tsx +0 -66
  208. package/src/widgets/custom/Markdown.tsx +0 -32
  209. package/src/widgets/custom/MultiCheckbox.tsx +0 -165
  210. package/src/widgets/custom/Radio.tsx +0 -47
  211. package/src/widgets/custom/Steps.tsx +0 -56
  212. package/src/widgets/custom/Switch.tsx +0 -26
  213. package/src/widgets/custom/Tag.tsx +0 -53
  214. package/src/widgets/custom/Tags.tsx +0 -164
  215. package/src/widgets/custom/Timeline.tsx +0 -196
  216. package/src/widgets/modals/ExportModal.tsx +0 -75
  217. package/src/widgets/modals/FormModal.tsx +0 -125
  218. package/src/widgets/modals/SearchModal.tsx +0 -130
  219. package/src/widgets/modals/TranslationModal.tsx +0 -202
  220. package/src/widgets/views/Dashboard/Dashboard.tsx +0 -381
  221. package/src/widgets/views/Dashboard/DashboardForm.tsx +0 -30
  222. package/src/widgets/views/Dashboard/DashboardTree.tsx +0 -238
  223. package/src/widgets/views/Dashboard/dashboardHelper.ts +0 -79
  224. package/src/widgets/views/DashboardGrid/DashboardGrid.tsx +0 -53
  225. package/src/widgets/views/DashboardGrid/DashboardGrid.types.ts +0 -4
  226. package/src/widgets/views/DashboardGrid/DashboardGridItem.tsx +0 -62
  227. package/src/widgets/views/DashboardGrid/DashboardGridItem.types.ts +0 -10
  228. package/src/widgets/views/DashboardGrid/index.ts +0 -4
  229. package/src/widgets/views/Form.tsx +0 -1152
  230. package/src/widgets/views/Graph/Graph.tsx +0 -145
  231. package/src/widgets/views/Graph/GraphChart.tsx +0 -113
  232. package/src/widgets/views/Graph/GraphDefaults.ts +0 -170
  233. package/src/widgets/views/Graph/GraphIndicator.tsx +0 -421
  234. package/src/widgets/views/Graph/useGraphData.tsx +0 -176
  235. package/src/widgets/views/SearchTree.tsx +0 -367
  236. package/src/widgets/views/Tree/Tree.tsx +0 -295
  237. package/src/widgets/views/Tree/index.ts +0 -1
  238. package/src/widgets/views/Tree/treeComponents.tsx +0 -283
  239. package/src/widgets/views/searchFilter/DateRangePicker.tsx +0 -16
  240. package/src/widgets/views/searchFilter/DateTimeRangePicker.tsx +0 -87
  241. package/src/widgets/views/searchFilter/PairFields.tsx +0 -56
  242. package/src/widgets/views/searchFilter/SearchBottomBar.tsx +0 -54
  243. package/src/widgets/views/searchFilter/SearchField.tsx +0 -63
  244. package/src/widgets/views/searchFilter/SearchFilter.tsx +0 -160
  245. package/src/widgets/views/searchFilter/SearchParams.tsx +0 -35
@@ -1,439 +0,0 @@
1
- import {
2
- ExportField,
3
- ExportOptions,
4
- PredefinedExport,
5
- PredefinedExportField,
6
- } from "@gisce/react-formiga-components";
7
- import { useCallback, useRef } from "react";
8
- import { ConnectionProvider } from "..";
9
- import showInfo from "@/ui/InfoDialog";
10
- import { tForLang } from "@/context/LocaleContext";
11
- import { getMimeType, openBase64InNewTab } from "@/helpers/filesHelper";
12
-
13
- export const useExport = ({
14
- model,
15
- context,
16
- locale,
17
- selectedRegistersToExport,
18
- domain,
19
- limit,
20
- onClose,
21
- }: {
22
- model: string;
23
- context: any;
24
- locale: string;
25
- selectedRegistersToExport?: any[];
26
- domain: any[];
27
- limit?: number;
28
- onClose: () => void;
29
- }) => {
30
- const fields = useRef<any>({});
31
- const exportModelFields = useRef<Map<string, any>>(new Map<string, any>());
32
-
33
- const onExport = useCallback(
34
- async (options: ExportOptions) => {
35
- if (
36
- options.selectedKeys === undefined ||
37
- options.selectedKeys.length === 0
38
- ) {
39
- showInfo(tForLang("selectAtLeastOneField", locale));
40
- return;
41
- }
42
-
43
- let exportDomain = domain;
44
-
45
- if (
46
- options.registersAmount === "selected" &&
47
- selectedRegistersToExport?.length !== 0
48
- ) {
49
- exportDomain = [
50
- ["id", "in", selectedRegistersToExport?.map((r) => r.id)],
51
- ];
52
- }
53
-
54
- const { datas } = await ConnectionProvider.getHandler().exportData({
55
- model,
56
- fields: addIdToRelationFields({
57
- keys: options.selectedKeys,
58
- fields: fields.current,
59
- }),
60
- domain: exportDomain,
61
- limit: options.registersAmount === "all" ? 0 : limit,
62
- context,
63
- format: options.exportType,
64
- });
65
-
66
- onClose();
67
-
68
- await new Promise((resolve) => setTimeout(resolve, 200));
69
-
70
- const fileType: any = await getMimeType(datas);
71
- openBase64InNewTab(datas, fileType.mime);
72
- },
73
- [locale, model, domain, limit, context, onClose],
74
- );
75
-
76
- const onGetFields = useCallback(async () => {
77
- const viewData = await ConnectionProvider.getHandler().getFields({
78
- model,
79
- context,
80
- fields: [],
81
- });
82
- fields.current["/"] = viewData;
83
- return convertToExportFields({ fields: viewData });
84
- }, [model, context, fields]);
85
-
86
- const onGetFieldChilds = useCallback(
87
- async (key: string) => {
88
- const fieldDefinition = getFieldDefinition(key, fields.current);
89
- const optsForField = fieldDefinition[getChildKey(key)];
90
- const relation = optsForField.relation;
91
- const viewData = await ConnectionProvider.getHandler().getFields({
92
- model: relation,
93
- context,
94
- fields: [],
95
- });
96
-
97
- // We must iterate over each key of viewData in order to replace the string value
98
- for (const [key, value] of Object.entries(viewData)) {
99
- viewData[key].string = getTitle({
100
- parentTitle: optsForField.string,
101
- title: (value as any).string,
102
- });
103
- }
104
-
105
- fields.current[key] = viewData;
106
-
107
- return convertToExportFields({
108
- fields: viewData,
109
- parentKey: key,
110
- });
111
- },
112
- [fields.current, model, context],
113
- );
114
-
115
- const onGetPredefinedExports = useCallback(async () => {
116
- const predefinedExports = await listPredefinedExports({ model, context });
117
-
118
- const keysWithChilds = await retrieveKeyFieldsForPredefinedExports({
119
- predefinedExports,
120
- fields: fields.current,
121
- onGetFieldChilds,
122
- });
123
-
124
- // Then we reformat predefined exports to get the title
125
- const predefinedExportsAdjusted = predefinedExports.map((pExport) => {
126
- return {
127
- ...pExport,
128
- fields: pExport.fields.map((field: PredefinedExportField) => {
129
- const childKey = getChildKey(field.key);
130
- const fieldDefinition = getFieldDefinition(field.key, fields.current);
131
- const optsForField = fieldDefinition[childKey];
132
- return {
133
- key: field.key,
134
- title: optsForField.string,
135
- };
136
- }),
137
- };
138
- });
139
-
140
- return {
141
- predefinedExports: predefinedExportsAdjusted,
142
- keysWithChilds,
143
- };
144
- }, [fields.current]);
145
-
146
- const onSavePredefinedExport = useCallback(
147
- async (pExport: PredefinedExport) => {
148
- const fieldsForExport = await getModelFields("ir.exports");
149
- const fieldsForExportLine = await getModelFields("ir.exports.line");
150
-
151
- // First we must create the parent object
152
- const exportId = await ConnectionProvider.getHandler().create({
153
- model: "ir.exports",
154
- values: {
155
- name: pExport.name,
156
- resource: model,
157
- },
158
- fields: fieldsForExport,
159
- context,
160
- });
161
-
162
- // We create the lines
163
- await Promise.all(
164
- pExport.fields.map(async (field: any) => {
165
- return await ConnectionProvider.getHandler().create({
166
- model: "ir.exports.line",
167
- values: {
168
- name: field.key,
169
- export_id: exportId,
170
- },
171
- fields: fieldsForExportLine,
172
- context,
173
- });
174
- }),
175
- );
176
-
177
- return { ...pExport, id: exportId };
178
- },
179
- [],
180
- );
181
-
182
- const onRemovePredefinedExport = useCallback(
183
- async (pExport: PredefinedExport) => {
184
- await ConnectionProvider.getHandler().deleteObjects({
185
- model: "ir.exports",
186
- ids: [pExport.id!],
187
- context,
188
- });
189
- },
190
- [],
191
- );
192
-
193
- const getModelFields = useCallback(
194
- async (model: string) => {
195
- if (exportModelFields.current.has(model)) {
196
- return exportModelFields.current.get(model);
197
- }
198
-
199
- const fieldsForModel = ConnectionProvider.getHandler().getFields({
200
- model,
201
- context,
202
- fields: [],
203
- });
204
-
205
- exportModelFields.current.set(model, fieldsForModel);
206
- },
207
- [exportModelFields, context],
208
- );
209
-
210
- return {
211
- onGetFields,
212
- onGetFieldChilds,
213
- onExport,
214
- onGetPredefinedExports,
215
- onSavePredefinedExport,
216
- onRemovePredefinedExport,
217
- };
218
- };
219
-
220
- const convertToExportFields = ({
221
- fields,
222
- parentKey,
223
- }: {
224
- fields: any;
225
- parentKey?: string;
226
- }) => {
227
- const exportFields = [];
228
-
229
- for (const key of Object.keys(fields)) {
230
- const valuesForField = fields[key];
231
-
232
- if (valuesForField.relation && valuesForField.is_function === true) {
233
- continue;
234
- }
235
-
236
- const relationField = isRelationField(valuesForField);
237
-
238
- exportFields.push({
239
- key: compoundId({ key, parentKey }),
240
- title: valuesForField.string,
241
- tooltip: valuesForField.help,
242
- required: valuesForField.required,
243
- isLeaf: !relationField,
244
- });
245
- }
246
- return exportFields;
247
- };
248
-
249
- const isRelationField = (fieldDefinition: any) => {
250
- return (
251
- fieldDefinition.type === "many2one" ||
252
- fieldDefinition.type === "one2many" ||
253
- fieldDefinition.type === "many2many"
254
- );
255
- };
256
-
257
- const compoundId = ({
258
- parentKey,
259
- key,
260
- }: {
261
- parentKey?: string;
262
- key: string;
263
- }) => {
264
- return `${parentKey ? parentKey + "/" : ""}${key}`;
265
- };
266
-
267
- const getParentKey = (key: string) => {
268
- if (key.indexOf("/") === -1) {
269
- return key;
270
- }
271
- const items = key.split("/");
272
- return items.slice(0, -1).join("/");
273
- };
274
-
275
- const getChildKey = (key: string) => {
276
- if (key.indexOf("/") === -1) {
277
- return key;
278
- }
279
- const items = key.split("/");
280
- return items[items.length - 1];
281
- };
282
-
283
- const getFieldDefinition = (key: string, fields: any) => {
284
- if (key.indexOf("/") === -1) {
285
- return fields["/"];
286
- } else {
287
- return fields[getParentKey(key)];
288
- }
289
- };
290
-
291
- const getTitle = ({
292
- title,
293
- parentTitle,
294
- }: {
295
- title: string;
296
- parentTitle?: string;
297
- }) => {
298
- return `${parentTitle ? parentTitle + " → " : ""}${title}`;
299
- };
300
-
301
- const listPredefinedExports = async ({
302
- model,
303
- context,
304
- }: {
305
- model: string;
306
- context: any;
307
- }) => {
308
- const pExports = await ConnectionProvider.getHandler().search({
309
- model: "ir.exports",
310
- params: [["resource", "=", model]],
311
- context,
312
- });
313
-
314
- const exportLinesIds = pExports.flatMap((exp: any) => exp.export_fields);
315
-
316
- // Now we must read each id of the export lines
317
- const exportLinesObjects = await ConnectionProvider.getHandler().readObjects({
318
- model: "ir.exports.line",
319
- ids: exportLinesIds,
320
- context,
321
- });
322
-
323
- return pExports.map((pExport) => ({
324
- id: pExport.id,
325
- name: pExport.name,
326
- fields: pExport.export_fields.map((id: number) => {
327
- const exportLine = exportLinesObjects.find((e: any) => e.id === id);
328
- return {
329
- key: exportLine.name,
330
- };
331
- }),
332
- }));
333
- };
334
-
335
- const getKeysWithoutChildsInFields = ({
336
- fields,
337
- keys,
338
- }: {
339
- fields: any;
340
- keys: string[];
341
- }) => {
342
- return splitAndSortKeys([
343
- ...new Set(
344
- keys
345
- .filter((key) => {
346
- if (key.indexOf("/") === -1) {
347
- return !fields["/"]?.[key];
348
- } else {
349
- const parentKey = getParentKey(key);
350
- console.log({ key, parentKey, fields });
351
- const exists = fields?.[getParentKey(key)]?.[key];
352
- console.log({ exists });
353
- return !fields?.[getParentKey(key)]?.[key];
354
- }
355
- })
356
- .map((key) => getParentKey(key)),
357
- ),
358
- ]);
359
- };
360
-
361
- const retrieveKeyFieldsForPredefinedExports = async ({
362
- predefinedExports,
363
- fields,
364
- onGetFieldChilds,
365
- }: {
366
- predefinedExports: PredefinedExport[];
367
- fields: any;
368
- onGetFieldChilds: (key: string) => Promise<ExportField[]>;
369
- }) => {
370
- const allPredefinedExportKeys = predefinedExports.flatMap(
371
- (exp: PredefinedExport) => exp.fields.map((field: any) => field.key),
372
- );
373
-
374
- const keysWithoutChildsInFields = getKeysWithoutChildsInFields({
375
- fields,
376
- keys: allPredefinedExportKeys,
377
- });
378
-
379
- const keysWithChilds = [];
380
-
381
- // We must load the fields info for each key if not loaded yet in fields and store them in an array to pass them to the formiga component
382
- for (const key of keysWithoutChildsInFields) {
383
- keysWithChilds.push({ key, childs: await onGetFieldChilds(key) });
384
- }
385
-
386
- return keysWithChilds;
387
- };
388
-
389
- const addIdToRelationFields = ({
390
- keys,
391
- fields,
392
- }: {
393
- keys: string[];
394
- fields: any;
395
- }) =>
396
- keys.map((key) => {
397
- const childKey = getChildKey(key);
398
- const fieldDefinition = getFieldDefinition(key, fields);
399
- const optsForField = fieldDefinition[childKey];
400
- const relationField = isRelationField(optsForField);
401
- return relationField ? `${key}/id` : key;
402
- });
403
-
404
- const splitAndSortKeys = (keys: string[]): string[] => {
405
- // We must split the keys that have more than one level (character / ocurrences in the string > 1)
406
- // Into an array of keys with only one level
407
- // For example: "partner_id/country_id/name" => ["partner_id", "partner_id/country_id", "partner_id/country_id/name"]
408
- // We must do this because we must load the fields info for each key if not loaded yet in fields
409
- // And we must load the fields info for the parent key first
410
- //
411
- // We must also sort the keys by the number of levels they have
412
- // For example: ["partner_id", "partner_id/country_id", "partner_id/country_id/name"]
413
-
414
- const keysMap: Map<string, boolean> = new Map();
415
- const result: string[] = [];
416
-
417
- // Split keys with more than one level
418
- for (const key of keys) {
419
- const subKeys = key.split("/");
420
- let parentKey = "";
421
- for (const subKey of subKeys) {
422
- const currentKey = parentKey ? `${parentKey}/${subKey}` : subKey;
423
- if (!keysMap.has(currentKey)) {
424
- result.push(currentKey);
425
- keysMap.set(currentKey, true);
426
- }
427
- parentKey = currentKey;
428
- }
429
- }
430
-
431
- // Sort keys by number of levels
432
- result.sort((a, b) => {
433
- const aLevels = a.split("/").length;
434
- const bLevels = b.split("/").length;
435
- return aLevels - bLevels;
436
- });
437
-
438
- return result;
439
- };
File without changes