@webitel/ui-sdk 24.6.44 → 24.6.46
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/package.json
CHANGED
|
@@ -227,9 +227,20 @@ export default {
|
|
|
227
227
|
}
|
|
228
228
|
} else {
|
|
229
229
|
// for backwards compatibility
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
230
|
+
|
|
231
|
+
// https://webitel.atlassian.net/browse/WTEL-4634
|
|
232
|
+
// Value for _isSelected must be assigned explicitly.
|
|
233
|
+
// Because allSelected recomputes after each change
|
|
234
|
+
|
|
235
|
+
if (this.isAllSelected) {
|
|
236
|
+
this.data.forEach((item) => {
|
|
237
|
+
item._isSelected = false;
|
|
238
|
+
});
|
|
239
|
+
} else {
|
|
240
|
+
this.data.forEach((item) => {
|
|
241
|
+
item._isSelected = true;
|
|
242
|
+
});
|
|
243
|
+
}
|
|
233
244
|
}
|
|
234
245
|
},
|
|
235
246
|
handleSelection(row, select) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as XLSX from 'xlsx';
|
|
2
2
|
import { saveAs } from 'file-saver-es';
|
|
3
|
+
import { objSnakeToCamel } from '../../scripts/caseConverters.js';
|
|
3
4
|
|
|
4
5
|
export default class XLSExport {
|
|
5
6
|
filename = 'export';
|
|
@@ -18,8 +19,42 @@ export default class XLSExport {
|
|
|
18
19
|
this.downloadProgress = { count: 0 };
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
// NOTE: if the value is an object with a name property, extract the name to display it in the EXEL file
|
|
23
|
+
extractNameFromObject(value) {
|
|
24
|
+
if (value && typeof value === 'object' && value.name) {
|
|
25
|
+
return value.name;
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// NOTE: creates a new object that only includes the properties specified in the columns array
|
|
31
|
+
filterDataByColumns(data, columns) {
|
|
32
|
+
return data.map(item => {
|
|
33
|
+
let filteredItem = {};
|
|
34
|
+
columns.forEach(column => {
|
|
35
|
+
const value = item.hasOwnProperty(column) ? this.extractNameFromObject(item[column]) : ''; // '' needed to display column that has no data
|
|
36
|
+
filteredItem[column] = value;
|
|
37
|
+
});
|
|
38
|
+
return filteredItem;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// NOTE: calculates the width of the columns based on the data to display it in the EXEL file
|
|
43
|
+
calculateColumnWidths(data, columns) {
|
|
44
|
+
return columns.map(column => {
|
|
45
|
+
const maxLength = data.reduce((max, item) => {
|
|
46
|
+
const value = item[column] || '';
|
|
47
|
+
return Math.max(max, value.toString().length);
|
|
48
|
+
}, column.length);
|
|
49
|
+
return { wch: maxLength + 2 }; // Adding some padding
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
save(data, columns) {
|
|
54
|
+
const filteredData = this.filterDataByColumns(data, columns);
|
|
55
|
+
const ws = XLSX.utils.json_to_sheet(filteredData);
|
|
56
|
+
const columnWidths = this.calculateColumnWidths(filteredData, columns);
|
|
57
|
+
ws['!cols'] = columnWidths;
|
|
23
58
|
const wb = XLSX.utils.book_new();
|
|
24
59
|
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
|
|
25
60
|
const wbout = XLSX.write(wb, { bookType: 'xlsx', type: 'array' });
|
|
@@ -27,10 +62,12 @@ export default class XLSExport {
|
|
|
27
62
|
saveAs(blob, `${this.filename}.xlsx`);
|
|
28
63
|
}
|
|
29
64
|
|
|
30
|
-
async
|
|
65
|
+
async fetchAndPrepareData(params) {
|
|
31
66
|
let data = [];
|
|
32
67
|
let isNext = false;
|
|
33
68
|
let page = 1;
|
|
69
|
+
let columns = params._columns ||
|
|
70
|
+
(params?.fields ? objSnakeToCamel(params?.fields) : []);
|
|
34
71
|
|
|
35
72
|
do {
|
|
36
73
|
const { items, next } = await this.fetchMethod({
|
|
@@ -43,8 +80,12 @@ export default class XLSExport {
|
|
|
43
80
|
isNext = next;
|
|
44
81
|
page += 1;
|
|
45
82
|
} while (isNext);
|
|
83
|
+
return { data, columns };
|
|
84
|
+
}
|
|
46
85
|
|
|
47
|
-
|
|
86
|
+
async export(params) {
|
|
87
|
+
const { data, columns } = await this.fetchAndPrepareData(params);
|
|
88
|
+
this.save(data, columns);
|
|
48
89
|
this.resetProgress();
|
|
49
90
|
}
|
|
50
91
|
}
|
|
@@ -4,6 +4,7 @@ export default {
|
|
|
4
4
|
data: () => ({
|
|
5
5
|
XLSExport: null,
|
|
6
6
|
}),
|
|
7
|
+
|
|
7
8
|
computed: {
|
|
8
9
|
isXLSLoading() {
|
|
9
10
|
return !!this.XLSDownloadProgress;
|
|
@@ -12,7 +13,14 @@ export default {
|
|
|
12
13
|
XLSDownloadProgress() {
|
|
13
14
|
return this.XLSExport ? this.XLSExport.downloadProgress.count : 0;
|
|
14
15
|
},
|
|
15
|
-
|
|
16
|
+
selectedIds() {
|
|
17
|
+
return this.dataList
|
|
18
|
+
.filter((item) => item._isSelected)
|
|
19
|
+
.map((item) => item.id);
|
|
20
|
+
},
|
|
21
|
+
isAnySelected() {
|
|
22
|
+
return !!this.selectedIds.length;
|
|
23
|
+
},
|
|
16
24
|
},
|
|
17
25
|
methods: {
|
|
18
26
|
initXLSExport(fetchMethod, options) {
|
|
@@ -33,6 +41,5 @@ export default {
|
|
|
33
41
|
throw err;
|
|
34
42
|
}
|
|
35
43
|
},
|
|
36
|
-
|
|
37
44
|
},
|
|
38
45
|
};
|