@onehat/ui 0.4.43 → 0.4.44
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
|
@@ -50,6 +50,7 @@ export default function withPresetButtons(WrappedComponent, isGrid = false) {
|
|
|
50
50
|
useUploadDownload = false,
|
|
51
51
|
uploadHeaders,
|
|
52
52
|
uploadParams,
|
|
53
|
+
onUpload,
|
|
53
54
|
downloadHeaders,
|
|
54
55
|
downloadParams,
|
|
55
56
|
onChangeColumnsConfig,
|
|
@@ -369,6 +370,7 @@ export default function withPresetButtons(WrappedComponent, isGrid = false) {
|
|
|
369
370
|
columnsConfig={props.columnsConfig}
|
|
370
371
|
uploadHeaders={uploadHeaders}
|
|
371
372
|
uploadParams={uploadParams}
|
|
373
|
+
onUpload={onUpload}
|
|
372
374
|
downloadHeaders={downloadHeaders}
|
|
373
375
|
downloadParams={downloadParams}
|
|
374
376
|
/>,
|
|
@@ -18,14 +18,14 @@ import Cookies from 'js-cookie';
|
|
|
18
18
|
import _ from 'lodash';
|
|
19
19
|
|
|
20
20
|
function UploadsDownloadsWindow(props) {
|
|
21
|
-
const
|
|
22
|
-
{
|
|
21
|
+
const {
|
|
23
22
|
Repository,
|
|
24
23
|
columnsConfig = [],
|
|
25
24
|
uploadHeaders,
|
|
26
25
|
downloadHeaders,
|
|
27
26
|
uploadParams = {},
|
|
28
27
|
downloadParams = {},
|
|
28
|
+
onUpload,
|
|
29
29
|
|
|
30
30
|
// withComponent
|
|
31
31
|
self,
|
|
@@ -70,21 +70,21 @@ function UploadsDownloadsWindow(props) {
|
|
|
70
70
|
...downloadParams,
|
|
71
71
|
}),
|
|
72
72
|
headers: _.merge({ 'Content-Type': 'application/json' }, Repository.headers, downloadHeaders),
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
73
|
+
};
|
|
74
|
+
downloadWithFetch(url, options);
|
|
75
|
+
const interval = setInterval(function() {
|
|
76
|
+
const cookie = Cookies.get(download_token);
|
|
77
|
+
if (win.window && cookie) {
|
|
78
|
+
clearInterval(interval);
|
|
79
|
+
Cookies.remove(download_token);
|
|
80
|
+
win.window.close();
|
|
81
|
+
}
|
|
82
|
+
}, 1000);
|
|
83
83
|
},
|
|
84
84
|
onDownloadTemplate = () => {
|
|
85
85
|
onDownload(true);
|
|
86
86
|
},
|
|
87
|
-
|
|
87
|
+
onUploadLocal = async () => {
|
|
88
88
|
const
|
|
89
89
|
url = Repository.api.baseURL + Repository.name + '/uploadBatch',
|
|
90
90
|
result = await Repository._send('POST', url, { importFile, ...uploadParams, }, uploadHeaders)
|
|
@@ -123,6 +123,9 @@ function UploadsDownloadsWindow(props) {
|
|
|
123
123
|
setImportFile(null);
|
|
124
124
|
self.formSetValue('file', null);
|
|
125
125
|
showInfo("Upload successful.\n");
|
|
126
|
+
if (onUpload) {
|
|
127
|
+
onUpload();
|
|
128
|
+
}
|
|
126
129
|
}
|
|
127
130
|
};
|
|
128
131
|
|
|
@@ -191,7 +194,7 @@ function UploadsDownloadsWindow(props) {
|
|
|
191
194
|
size: 'md',
|
|
192
195
|
},
|
|
193
196
|
isDisabled: !importFile,
|
|
194
|
-
onPress:
|
|
197
|
+
onPress: onUploadLocal,
|
|
195
198
|
},
|
|
196
199
|
{
|
|
197
200
|
type: 'Button',
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
const downloadWithFetch = (url, options = {}, win = null) => {
|
|
2
2
|
let obj = {};
|
|
3
3
|
fetch(url, options)
|
|
4
|
-
.then(
|
|
5
|
-
|
|
4
|
+
.then((res) => {
|
|
5
|
+
const contentDisposition = res.headers.get('Content-Disposition');
|
|
6
|
+
let filename = 'download';
|
|
7
|
+
if (contentDisposition && contentDisposition.indexOf('attachment') !== -1) {
|
|
8
|
+
const matches = /filename="([^"]*)"/.exec(contentDisposition);
|
|
9
|
+
if (matches != null && matches[1]) {
|
|
10
|
+
filename = matches[1];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return res.blob().then((blob) => ({ blob, filename }));
|
|
14
|
+
})
|
|
15
|
+
.then(({ blob, filename }) => {
|
|
6
16
|
// if (!win) {
|
|
7
17
|
// const
|
|
8
18
|
// winName = 'Download',
|
|
@@ -17,7 +27,7 @@ const downloadWithFetch = (url, options = {}, win = null) => {
|
|
|
17
27
|
// const link = win.document.createElement('a');
|
|
18
28
|
const link = document.createElement('a');
|
|
19
29
|
link.href = file;
|
|
20
|
-
|
|
30
|
+
link.download = filename; // Set the filename from the Content-Disposition header
|
|
21
31
|
link.target = "_blank";
|
|
22
32
|
link.click();
|
|
23
33
|
|