@onehat/ui 0.4.42 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/ui",
3
- "version": "0.4.42",
3
+ "version": "0.4.44",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -1303,7 +1303,7 @@ function Form(props) {
1303
1303
  Form-inlineFooter
1304
1304
  absolute
1305
1305
  top-[5px]
1306
- left-[100px]
1306
+ left-[40px]
1307
1307
  w-[100px]
1308
1308
  min-w-[300px]
1309
1309
  py-2
@@ -16,8 +16,7 @@ export default function withData(WrappedComponent) {
16
16
  return <WrappedComponent {...props} ref={ref} />;
17
17
  }
18
18
 
19
- const
20
- {
19
+ const {
21
20
  // For @onehat/data repositories
22
21
  Repository,
23
22
  setRepository,
@@ -189,7 +189,7 @@ export default function withModal(WrappedComponent) {
189
189
  {isModalShown &&
190
190
  <Modal
191
191
  isOpen={true}
192
- onClose={onCancel}
192
+ onClose={onCancel || (canClose ? hideModal : null)}
193
193
  className="withModal-Modal"
194
194
  {...testProps(testID)}
195
195
  >
@@ -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
  />,
@@ -736,8 +736,8 @@ function TreeComponent(props) {
736
736
  }
737
737
 
738
738
  const
739
- depthChildren = await datum.item.loadChildren(depth),
740
- directChildren = _.filter(depthChildren, (child) => { // narrow list to only direct descendants, so buildTreeNodeData can work correctly
739
+ node = await datum.item.loadChildren(depth),
740
+ directChildren = _.filter(node.children, (child) => { // narrow list to only direct descendants, so buildTreeNodeData can work correctly
741
741
  return child.depth === datum.item.depth + 1;
742
742
  });
743
743
 
@@ -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
- fetchWindow = downloadWithFetch(url, options, win),
75
- interval = setInterval(function() {
76
- const cookie = Cookies.get(download_token);
77
- if (fetchWindow.window && cookie) {
78
- clearInterval(interval);
79
- Cookies.remove(download_token);
80
- fetchWindow.window.close();
81
- }
82
- }, 1000);
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
- onUpload = async () => {
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: onUpload,
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( res => res.blob() )
5
- .then( blob => {
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
- // link.download = true;
30
+ link.download = filename; // Set the filename from the Content-Disposition header
21
31
  link.target = "_blank";
22
32
  link.click();
23
33