@gisce/react-ooui 1.2.0-rc.7 → 1.2.0-rc.71
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/dist/actionbar/FormActionBar.d.ts.map +1 -1
- package/dist/actionbar/TreeActionBar.d.ts.map +1 -1
- package/dist/common/DatePicker.d.ts +12 -0
- package/dist/common/DatePicker.d.ts.map +1 -1
- package/dist/context/ActionViewContext.d.ts +5 -1
- package/dist/context/ActionViewContext.d.ts.map +1 -1
- package/dist/context/ContentRootContext.d.ts.map +1 -1
- package/dist/context/FormContext.d.ts +4 -2
- package/dist/context/FormContext.d.ts.map +1 -1
- package/dist/helpers/formHelper.d.ts +5 -3
- package/dist/helpers/formHelper.d.ts.map +1 -1
- package/dist/helpers/iconMapper.d.ts +5 -1
- package/dist/helpers/iconMapper.d.ts.map +1 -1
- package/dist/helpers/one2manyHelper.d.ts +12 -4
- package/dist/helpers/one2manyHelper.d.ts.map +1 -1
- package/dist/helpers/searchHelper.d.ts +1 -1
- package/dist/helpers/searchHelper.d.ts.map +1 -1
- package/dist/helpers/treeHelper.d.ts +1 -1
- package/dist/helpers/treeHelper.d.ts.map +1 -1
- package/dist/hooks/useExport.d.ts +44 -0
- package/dist/hooks/useExport.d.ts.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/locales/ca_ES.d.ts +2 -0
- package/dist/locales/ca_ES.d.ts.map +1 -1
- package/dist/locales/en_US.d.ts +2 -0
- package/dist/locales/en_US.d.ts.map +1 -1
- package/dist/locales/es_ES.d.ts +2 -0
- package/dist/locales/es_ES.d.ts.map +1 -1
- package/dist/react-ooui.es.js +25403 -27411
- package/dist/react-ooui.es.js.map +1 -1
- package/dist/react-ooui.umd.js +46 -184
- package/dist/react-ooui.umd.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/views/RootView.d.ts.map +1 -1
- package/dist/views/actionViews/GraphActionView.d.ts.map +1 -1
- package/dist/views/actionViews/TreeActionView.d.ts.map +1 -1
- package/dist/widgets/WidgetFactory.d.ts.map +1 -1
- package/dist/widgets/base/Integer.d.ts.map +1 -1
- package/dist/widgets/base/Label.d.ts.map +1 -1
- package/dist/widgets/base/Reference.d.ts.map +1 -1
- package/dist/widgets/base/ReferenceTree.d.ts +8 -0
- package/dist/widgets/base/ReferenceTree.d.ts.map +1 -0
- package/dist/widgets/base/Separator.d.ts.map +1 -1
- package/dist/widgets/base/many2one/Many2one.d.ts.map +1 -1
- package/dist/widgets/base/many2one/Many2oneTree.d.ts +6 -0
- package/dist/widgets/base/many2one/Many2oneTree.d.ts.map +1 -0
- package/dist/widgets/base/one2many/One2manyInput.d.ts.map +1 -1
- package/dist/widgets/containers/Group.d.ts.map +1 -1
- package/dist/widgets/custom/MultiCheckbox.d.ts.map +1 -1
- package/dist/widgets/custom/Tag.d.ts +5 -0
- package/dist/widgets/custom/Tag.d.ts.map +1 -0
- package/dist/widgets/custom/Tags.d.ts.map +1 -1
- package/dist/widgets/custom/Timeline.d.ts.map +1 -1
- package/dist/widgets/modals/ExportModal.d.ts +2 -1
- package/dist/widgets/modals/ExportModal.d.ts.map +1 -1
- package/dist/widgets/views/Dashboard/Dashboard.d.ts.map +1 -1
- package/dist/widgets/views/Dashboard/DashboardTree.d.ts.map +1 -1
- package/dist/widgets/views/Form.d.ts.map +1 -1
- package/dist/widgets/views/Graph/GraphChart.d.ts.map +1 -1
- package/dist/widgets/views/Graph/GraphDefaults.d.ts +36 -0
- package/dist/widgets/views/Graph/GraphDefaults.d.ts.map +1 -1
- package/dist/widgets/views/SearchTree.d.ts.map +1 -1
- package/dist/widgets/views/Tree.d.ts +2 -0
- package/dist/widgets/views/Tree.d.ts.map +1 -1
- package/dist/widgets/views/searchFilter/SearchFilter.d.ts +1 -0
- package/dist/widgets/views/searchFilter/SearchFilter.d.ts.map +1 -1
- package/package.json +8 -7
- package/src/__tests__/iconMapper.test.ts +20 -5
- package/src/actionbar/ChangeViewButton.tsx +2 -2
- package/src/actionbar/FormActionBar.tsx +82 -11
- package/src/actionbar/TreeActionBar.tsx +23 -28
- package/src/common/DatePicker.tsx +4 -3
- package/src/context/ActionViewContext.tsx +7 -4
- package/src/context/ContentRootContext.tsx +15 -7
- package/src/context/FormContext.tsx +1 -4
- package/src/helpers/formHelper.ts +26 -5
- package/src/helpers/iconMapper.ts +134 -107
- package/src/helpers/one2manyHelper.ts +94 -39
- package/src/helpers/searchHelper.ts +8 -7
- package/src/helpers/treeHelper.ts +17 -5
- package/src/hooks/useExport.ts +439 -0
- package/src/index.ts +2 -0
- package/src/locales/ca_ES.tsx +2 -0
- package/src/locales/en_US.tsx +2 -0
- package/src/locales/es_ES.tsx +2 -0
- package/src/stories/Label.stories.tsx +7 -8
- package/src/stories/Separator.stories.tsx +33 -0
- package/src/stories/containers/Group.stories.tsx +24 -0
- package/src/stories/containers/Notebook.stories.tsx +27 -0
- package/src/stories/custom/Tag.stories.tsx +57 -0
- package/src/stories/mocks/models/crm_case.ts +7 -10
- package/src/stories/views/Tree.stories.jsx +5 -5
- package/src/types/index.ts +1 -0
- package/src/ui/FavouriteButton.tsx +4 -4
- package/src/views/RootView.tsx +7 -1
- package/src/views/actionViews/GraphActionView.tsx +1 -0
- package/src/views/actionViews/TreeActionView.tsx +10 -1
- package/src/widgets/WidgetFactory.tsx +3 -0
- package/src/widgets/base/Integer.tsx +1 -0
- package/src/widgets/base/Label.tsx +5 -9
- package/src/widgets/base/Reference.tsx +13 -3
- package/src/widgets/base/ReferenceTree.tsx +62 -0
- package/src/widgets/base/Separator.tsx +11 -3
- package/src/widgets/base/many2one/Many2one.tsx +10 -19
- package/src/widgets/base/many2one/Many2oneTree.tsx +18 -0
- package/src/widgets/base/one2many/One2manyInput.tsx +79 -23
- package/src/widgets/containers/Group.tsx +7 -4
- package/src/widgets/custom/ButtonGroup.tsx +1 -1
- package/src/widgets/custom/MultiCheckbox.tsx +1 -0
- package/src/widgets/custom/Tag.tsx +24 -0
- package/src/widgets/custom/Tags.tsx +27 -28
- package/src/widgets/custom/Timeline.tsx +9 -3
- package/src/widgets/modals/ExportModal.tsx +33 -134
- package/src/widgets/views/Dashboard/Dashboard.tsx +15 -4
- package/src/widgets/views/Dashboard/DashboardTree.tsx +1 -0
- package/src/widgets/views/Form.tsx +38 -31
- package/src/widgets/views/Graph/GraphChart.tsx +6 -1
- package/src/widgets/views/Graph/GraphDefaults.ts +113 -0
- package/src/widgets/views/Graph/GraphIndicator.tsx +17 -3
- package/src/widgets/views/SearchTree.tsx +3 -0
- package/src/widgets/views/Tree.tsx +111 -25
- package/src/widgets/views/searchFilter/SearchFilter.tsx +12 -6
- package/dist/helpers/icons/antd_icons.d.ts +0 -4
- package/dist/helpers/icons/antd_icons.d.ts.map +0 -1
- package/dist/helpers/icons/tabler_icons.d.ts +0 -4
- package/dist/helpers/icons/tabler_icons.d.ts.map +0 -1
- package/dist/ui/Fieldset.d.ts +0 -8
- package/dist/ui/Fieldset.d.ts.map +0 -1
- package/src/helpers/icons/antd_icons.ts +0 -1583
- package/src/helpers/icons/tabler_icons.ts +0 -5367
- package/src/ui/Fieldset.tsx +0 -31
|
@@ -1,18 +1,33 @@
|
|
|
1
1
|
import { One2manyItem } from "@/widgets/base/one2many/One2manyInput";
|
|
2
2
|
import ConnectionProvider from "@/ConnectionProvider";
|
|
3
|
+
import { TreeView, View, ViewType } from "@/types";
|
|
4
|
+
import { getColorMap, getTree } from "./treeHelper";
|
|
3
5
|
|
|
4
6
|
type ReadObjectValuesOptions = {
|
|
5
7
|
items: One2manyItem[];
|
|
6
8
|
model: string;
|
|
7
|
-
treeFields: any;
|
|
8
|
-
formFields: any;
|
|
9
9
|
context?: any;
|
|
10
|
+
currentView: ViewType;
|
|
11
|
+
formView: {
|
|
12
|
+
fields: any;
|
|
13
|
+
};
|
|
14
|
+
treeView: {
|
|
15
|
+
arch?: string;
|
|
16
|
+
fields: any;
|
|
17
|
+
};
|
|
10
18
|
};
|
|
11
19
|
|
|
12
20
|
const readObjectValues = async (
|
|
13
21
|
options: ReadObjectValuesOptions
|
|
14
|
-
): Promise<One2manyItem[]> => {
|
|
15
|
-
const {
|
|
22
|
+
): Promise<[One2manyItem[], any]> => {
|
|
23
|
+
const {
|
|
24
|
+
items,
|
|
25
|
+
model,
|
|
26
|
+
formView,
|
|
27
|
+
treeView,
|
|
28
|
+
context,
|
|
29
|
+
currentView = {},
|
|
30
|
+
} = options;
|
|
16
31
|
|
|
17
32
|
const temporalItems: One2manyItem = items.filter(
|
|
18
33
|
(item) => item.operation !== "original"
|
|
@@ -23,50 +38,72 @@ const readObjectValues = async (
|
|
|
23
38
|
.filter((item) => item.operation === "original")
|
|
24
39
|
.map((item) => item.id) as number[];
|
|
25
40
|
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
41
|
+
const fieldsToRetrieve: { [key: string]: any } = {
|
|
42
|
+
form: formView.fields,
|
|
43
|
+
tree: treeView.fields,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
let values = [],
|
|
47
|
+
evaluatedColorsForTree;
|
|
48
|
+
|
|
49
|
+
if (currentView === "tree" && treeView?.arch) {
|
|
50
|
+
const colors = getTree(treeView as TreeView)?.colors;
|
|
51
|
+
const results = await ConnectionProvider.getHandler().readEvalUiObjects({
|
|
52
|
+
model,
|
|
53
|
+
ids: idsToFetch,
|
|
54
|
+
arch: treeView?.arch!,
|
|
55
|
+
fields: treeView!.fields,
|
|
56
|
+
context,
|
|
57
|
+
attrs: colors && {
|
|
58
|
+
colors,
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
values = results[0];
|
|
62
|
+
evaluatedColorsForTree = getColorMap(results[1]);
|
|
63
|
+
} else {
|
|
64
|
+
values = await ConnectionProvider.getHandler().readObjects({
|
|
65
|
+
model,
|
|
66
|
+
ids: idsToFetch,
|
|
67
|
+
fields: fieldsToRetrieve[currentView as string],
|
|
68
|
+
context,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
32
71
|
|
|
33
|
-
const
|
|
72
|
+
const filteredValues = values.map((result: any) => {
|
|
34
73
|
const resultFormValues: any = {};
|
|
35
74
|
Object.keys(result).forEach((key) => {
|
|
36
|
-
if (
|
|
75
|
+
if (
|
|
76
|
+
fieldsToRetrieve[currentView as string].hasOwnProperty(key) ||
|
|
77
|
+
key === "id"
|
|
78
|
+
) {
|
|
37
79
|
resultFormValues[key] = result[key];
|
|
38
80
|
}
|
|
39
81
|
});
|
|
40
82
|
return resultFormValues;
|
|
41
83
|
});
|
|
42
84
|
|
|
43
|
-
const treeValues = values.map((result: any) => {
|
|
44
|
-
const resultTreeValues: any = {};
|
|
45
|
-
Object.keys(result).forEach((key) => {
|
|
46
|
-
if (treeFields.hasOwnProperty(key) || key === "id") {
|
|
47
|
-
resultTreeValues[key] = result[key];
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
return resultTreeValues;
|
|
51
|
-
});
|
|
52
|
-
|
|
53
85
|
// We fill the values property of the One2manyItem with the retrieved values from the API
|
|
54
86
|
const originalItemsWithFetchedValues: One2manyItem[] = items.map((item) => {
|
|
55
|
-
const
|
|
56
|
-
(itemValues: any) => itemValues.id === item.id
|
|
57
|
-
);
|
|
58
|
-
const fetchedTreeItemValues = treeValues.find(
|
|
87
|
+
const fetchedItemValues = filteredValues.find(
|
|
59
88
|
(itemValues: any) => itemValues.id === item.id
|
|
60
89
|
);
|
|
61
90
|
|
|
62
|
-
|
|
91
|
+
const itemWithFetchedValues = {
|
|
63
92
|
...item,
|
|
64
|
-
values: fetchedFormItemValues,
|
|
65
|
-
treeValues: fetchedTreeItemValues,
|
|
66
93
|
};
|
|
94
|
+
|
|
95
|
+
if (currentView === "form") {
|
|
96
|
+
itemWithFetchedValues["values"] = fetchedItemValues;
|
|
97
|
+
} else if (currentView === "tree") {
|
|
98
|
+
itemWithFetchedValues["treeValues"] = fetchedItemValues;
|
|
99
|
+
}
|
|
100
|
+
return itemWithFetchedValues;
|
|
67
101
|
});
|
|
68
102
|
|
|
69
|
-
return
|
|
103
|
+
return [
|
|
104
|
+
originalItemsWithFetchedValues.concat(temporalItems),
|
|
105
|
+
evaluatedColorsForTree,
|
|
106
|
+
];
|
|
70
107
|
};
|
|
71
108
|
|
|
72
109
|
type RemoveItemOptions = {
|
|
@@ -79,14 +116,8 @@ type RemoveItemOptions = {
|
|
|
79
116
|
};
|
|
80
117
|
|
|
81
118
|
const removeItems = async (options: RemoveItemOptions) => {
|
|
82
|
-
const {
|
|
83
|
-
|
|
84
|
-
activeId,
|
|
85
|
-
fieldName,
|
|
86
|
-
idsToRemove,
|
|
87
|
-
fields,
|
|
88
|
-
isMany2many,
|
|
89
|
-
} = options;
|
|
119
|
+
const { model, activeId, fieldName, idsToRemove, fields, isMany2many } =
|
|
120
|
+
options;
|
|
90
121
|
|
|
91
122
|
const values: any = {};
|
|
92
123
|
values[fieldName] = [];
|
|
@@ -136,4 +167,28 @@ const getNextPendingId = (items: One2manyItem[]) => {
|
|
|
136
167
|
}
|
|
137
168
|
};
|
|
138
169
|
|
|
139
|
-
|
|
170
|
+
const convertToPlain2ManyValues = (values: any, fields: any) => {
|
|
171
|
+
const result: any = {};
|
|
172
|
+
Object.keys(values).forEach((key) => {
|
|
173
|
+
if (
|
|
174
|
+
fields.hasOwnProperty(key) &&
|
|
175
|
+
(fields[key].type === "one2many" || fields[key].type === "many2many") &&
|
|
176
|
+
values[key] &&
|
|
177
|
+
values[key]?.items
|
|
178
|
+
) {
|
|
179
|
+
result[key] = values[key].items.filter(
|
|
180
|
+
(item: One2manyItem) => item.operation !== "pendingRemove"
|
|
181
|
+
);
|
|
182
|
+
} else {
|
|
183
|
+
result[key] = values[key];
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
return result;
|
|
187
|
+
};
|
|
188
|
+
export {
|
|
189
|
+
readObjectValues,
|
|
190
|
+
removeItems,
|
|
191
|
+
linkItem,
|
|
192
|
+
getNextPendingId,
|
|
193
|
+
convertToPlain2ManyValues,
|
|
194
|
+
};
|
|
@@ -5,14 +5,14 @@ const convertBooleanParamIfNeeded = (value: any) => {
|
|
|
5
5
|
return value;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
export const getParamsForFields = (values: any,
|
|
8
|
+
export const getParamsForFields = (values: any, widgetContainer: any) => {
|
|
9
9
|
const filteredValues = removeUndefinedFields(values);
|
|
10
10
|
const groupedDateTime = groupDateTimeValuesIfNeeded(filteredValues);
|
|
11
|
-
const groupedValues = ungroupDateValuesIfNeeded(groupedDateTime,
|
|
11
|
+
const groupedValues = ungroupDateValuesIfNeeded(groupedDateTime, widgetContainer);
|
|
12
12
|
|
|
13
13
|
const params = [
|
|
14
14
|
...Object.keys(groupedValues).map((key) => {
|
|
15
|
-
return getParamForField(key, groupedValues[key],
|
|
15
|
+
return getParamForField(key, groupedValues[key], widgetContainer);
|
|
16
16
|
}),
|
|
17
17
|
];
|
|
18
18
|
|
|
@@ -27,9 +27,9 @@ export const getParamsForFields = (values: any, fields: any) => {
|
|
|
27
27
|
return paramsForFields;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
const getParamForField = (key: string, value: any,
|
|
30
|
+
const getParamForField = (key: string, value: any, widgetContainer: any) => {
|
|
31
31
|
const filteredKey = key.split("#")[0];
|
|
32
|
-
const type =
|
|
32
|
+
const type = widgetContainer.findById(filteredKey)?.type;
|
|
33
33
|
|
|
34
34
|
if (
|
|
35
35
|
type === "char" ||
|
|
@@ -127,9 +127,10 @@ export const groupDateTimeValuesIfNeeded = (values: any) => {
|
|
|
127
127
|
return newValues;
|
|
128
128
|
};
|
|
129
129
|
|
|
130
|
-
const ungroupDateValuesIfNeeded = (values: any,
|
|
130
|
+
const ungroupDateValuesIfNeeded = (values: any, widgetContainer: any) => {
|
|
131
131
|
const dateFields = Object.keys(values).filter((key) => {
|
|
132
|
-
|
|
132
|
+
const widget = widgetContainer.findById(key);
|
|
133
|
+
return widget && widget.type === "date";
|
|
133
134
|
});
|
|
134
135
|
|
|
135
136
|
let newValues: any = { ...values };
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Tree as TreeOoui,
|
|
3
|
+
Selection,
|
|
4
|
+
Many2one,
|
|
5
|
+
Boolean,
|
|
6
|
+
Reference,
|
|
7
|
+
} from "@gisce/ooui";
|
|
2
8
|
import { TreeView, Column } from "@/types";
|
|
3
9
|
|
|
4
10
|
const getTree = (treeView: TreeView): TreeOoui => {
|
|
@@ -9,7 +15,11 @@ const getTree = (treeView: TreeView): TreeOoui => {
|
|
|
9
15
|
return tree;
|
|
10
16
|
};
|
|
11
17
|
|
|
12
|
-
const getTableColumns = (
|
|
18
|
+
const getTableColumns = (
|
|
19
|
+
tree: TreeOoui,
|
|
20
|
+
components: any,
|
|
21
|
+
context: any
|
|
22
|
+
): Array<Column> => {
|
|
13
23
|
const tableColumns = tree.columns.map((column) => {
|
|
14
24
|
const type = column.type;
|
|
15
25
|
const key = column.id;
|
|
@@ -18,7 +28,7 @@ const getTableColumns = (tree: TreeOoui, components: any): Array<Column> => {
|
|
|
18
28
|
|
|
19
29
|
if (component) {
|
|
20
30
|
render = (item: any) => {
|
|
21
|
-
return component(item);
|
|
31
|
+
return component(item, key, column, context);
|
|
22
32
|
};
|
|
23
33
|
}
|
|
24
34
|
|
|
@@ -54,9 +64,11 @@ const getTableItems = (treeOoui: TreeOoui, results: Array<any>): Array<any> => {
|
|
|
54
64
|
} else {
|
|
55
65
|
const widget = treeOoui.findById(key);
|
|
56
66
|
|
|
57
|
-
if (widget instanceof
|
|
67
|
+
if (widget instanceof Reference) {
|
|
68
|
+
parsedItem[key] = item[key];
|
|
69
|
+
} else if (widget instanceof Selection) {
|
|
58
70
|
const selection = widget;
|
|
59
|
-
parsedItem[key] =
|
|
71
|
+
parsedItem[key] = item[key];
|
|
60
72
|
} else if (widget instanceof Many2one) {
|
|
61
73
|
parsedItem[key] = item[key] &&
|
|
62
74
|
Array.isArray(item[key]) &&
|
|
@@ -0,0 +1,439 @@
|
|
|
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().delete({
|
|
185
|
+
model: "ir.exports",
|
|
186
|
+
ids: [pExport.id!],
|
|
187
|
+
});
|
|
188
|
+
},
|
|
189
|
+
[]
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
const getModelFields = useCallback(
|
|
193
|
+
async (model: string) => {
|
|
194
|
+
if (exportModelFields.current.has(model)) {
|
|
195
|
+
return exportModelFields.current.get(model);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const fieldsForModel = ConnectionProvider.getHandler().getFields({
|
|
199
|
+
model,
|
|
200
|
+
context,
|
|
201
|
+
fields: [],
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
exportModelFields.current.set(model, fieldsForModel);
|
|
205
|
+
},
|
|
206
|
+
[exportModelFields, context]
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
return {
|
|
210
|
+
onGetFields,
|
|
211
|
+
onGetFieldChilds,
|
|
212
|
+
onExport,
|
|
213
|
+
onGetPredefinedExports,
|
|
214
|
+
onSavePredefinedExport,
|
|
215
|
+
onRemovePredefinedExport,
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const convertToExportFields = ({
|
|
220
|
+
fields,
|
|
221
|
+
parentKey,
|
|
222
|
+
}: {
|
|
223
|
+
fields: any;
|
|
224
|
+
parentKey?: string;
|
|
225
|
+
}) => {
|
|
226
|
+
const exportFields = [];
|
|
227
|
+
|
|
228
|
+
for (const key of Object.keys(fields)) {
|
|
229
|
+
const valuesForField = fields[key];
|
|
230
|
+
|
|
231
|
+
if (valuesForField.relation && valuesForField.is_function === true) {
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const relationField = isRelationField(valuesForField);
|
|
236
|
+
|
|
237
|
+
exportFields.push({
|
|
238
|
+
key: compoundId({ key, parentKey }),
|
|
239
|
+
title: valuesForField.string,
|
|
240
|
+
tooltip: valuesForField.help,
|
|
241
|
+
required: valuesForField.required,
|
|
242
|
+
isLeaf: !relationField,
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
return exportFields;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const isRelationField = (fieldDefinition: any) => {
|
|
249
|
+
return (
|
|
250
|
+
fieldDefinition.type === "many2one" ||
|
|
251
|
+
fieldDefinition.type === "one2many" ||
|
|
252
|
+
fieldDefinition.type === "many2many"
|
|
253
|
+
);
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
const compoundId = ({
|
|
257
|
+
parentKey,
|
|
258
|
+
key,
|
|
259
|
+
}: {
|
|
260
|
+
parentKey?: string;
|
|
261
|
+
key: string;
|
|
262
|
+
}) => {
|
|
263
|
+
return `${parentKey ? parentKey + "/" : ""}${key}`;
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
const getParentKey = (key: string) => {
|
|
267
|
+
if (key.indexOf("/") === -1) {
|
|
268
|
+
return key;
|
|
269
|
+
}
|
|
270
|
+
const items = key.split("/");
|
|
271
|
+
return items.slice(0, -1).join("/");
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const getChildKey = (key: string) => {
|
|
275
|
+
if (key.indexOf("/") === -1) {
|
|
276
|
+
return key;
|
|
277
|
+
}
|
|
278
|
+
const items = key.split("/");
|
|
279
|
+
return items[items.length - 1];
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
const getFieldDefinition = (key: string, fields: any) => {
|
|
283
|
+
if (key.indexOf("/") === -1) {
|
|
284
|
+
return fields["/"];
|
|
285
|
+
} else {
|
|
286
|
+
return fields[getParentKey(key)];
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
const getTitle = ({
|
|
291
|
+
title,
|
|
292
|
+
parentTitle,
|
|
293
|
+
}: {
|
|
294
|
+
title: string;
|
|
295
|
+
parentTitle?: string;
|
|
296
|
+
}) => {
|
|
297
|
+
return `${parentTitle ? parentTitle + " → " : ""}${title}`;
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
const listPredefinedExports = async ({
|
|
301
|
+
model,
|
|
302
|
+
context,
|
|
303
|
+
}: {
|
|
304
|
+
model: string;
|
|
305
|
+
context: any;
|
|
306
|
+
}) => {
|
|
307
|
+
const pExports = await ConnectionProvider.getHandler().search({
|
|
308
|
+
model: "ir.exports",
|
|
309
|
+
params: [["resource", "=", model]],
|
|
310
|
+
context,
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
const exportLinesIds = pExports.flatMap((exp: any) => exp.export_fields);
|
|
314
|
+
|
|
315
|
+
// Now we must read each id of the export lines
|
|
316
|
+
const exportLinesObjects = await ConnectionProvider.getHandler().readObjects({
|
|
317
|
+
model: "ir.exports.line",
|
|
318
|
+
ids: exportLinesIds,
|
|
319
|
+
context,
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
return pExports.map((pExport) => ({
|
|
323
|
+
id: pExport.id,
|
|
324
|
+
name: pExport.name,
|
|
325
|
+
fields: pExport.export_fields.map((id: number) => {
|
|
326
|
+
const exportLine = exportLinesObjects.find((e: any) => e.id === id);
|
|
327
|
+
return {
|
|
328
|
+
key: exportLine.name,
|
|
329
|
+
};
|
|
330
|
+
}),
|
|
331
|
+
}));
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
const getKeysWithoutChildsInFields = ({
|
|
335
|
+
fields,
|
|
336
|
+
keys,
|
|
337
|
+
}: {
|
|
338
|
+
fields: any;
|
|
339
|
+
keys: string[];
|
|
340
|
+
}) => {
|
|
341
|
+
return splitAndSortKeys([
|
|
342
|
+
...new Set(
|
|
343
|
+
keys
|
|
344
|
+
.filter((key) => {
|
|
345
|
+
if (key.indexOf("/") === -1) {
|
|
346
|
+
return !fields["/"]?.[key];
|
|
347
|
+
} else {
|
|
348
|
+
const parentKey = getParentKey(key);
|
|
349
|
+
console.log({ key, parentKey, fields });
|
|
350
|
+
const exists = fields?.[getParentKey(key)]?.[key];
|
|
351
|
+
console.log({ exists });
|
|
352
|
+
return !fields?.[getParentKey(key)]?.[key];
|
|
353
|
+
}
|
|
354
|
+
})
|
|
355
|
+
.map((key) => getParentKey(key))
|
|
356
|
+
),
|
|
357
|
+
]);
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
const retrieveKeyFieldsForPredefinedExports = async ({
|
|
361
|
+
predefinedExports,
|
|
362
|
+
fields,
|
|
363
|
+
onGetFieldChilds,
|
|
364
|
+
}: {
|
|
365
|
+
predefinedExports: PredefinedExport[];
|
|
366
|
+
fields: any;
|
|
367
|
+
onGetFieldChilds: (key: string) => Promise<ExportField[]>;
|
|
368
|
+
}) => {
|
|
369
|
+
const allPredefinedExportKeys = predefinedExports.flatMap(
|
|
370
|
+
(exp: PredefinedExport) =>
|
|
371
|
+
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
|
+
};
|