@onehat/ui 0.3.374 → 0.3.377

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.3.374",
3
+ "version": "0.3.377",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -542,12 +542,8 @@ export default function withFilters(WrappedComponent) {
542
542
  newSlots = _.clone(modalSlots),
543
543
  i = searchAllText ? ixPlusOne : ix; // compensate for 'q' filter's possible presence
544
544
 
545
- if (newFilters[i]?.value) {
546
- newFilters[i].value = value;
547
- } else {
548
- newFilters[i] = getFormattedFilter(value);
549
- }
550
- newSlots[ix] = value;
545
+ newFilters[i] = getFormattedFilter(value);
546
+ newSlots[i] = value;
551
547
 
552
548
  setModalFilters(newFilters);
553
549
  setModalSlots(newSlots);
@@ -55,6 +55,10 @@ export default function withPresetButtons(WrappedComponent, isGrid = false) {
55
55
  canRecordBeEdited,
56
56
  canRecordBeDeleted,
57
57
  canRecordBeDuplicated,
58
+ uploadHeaders,
59
+ uploadParams,
60
+ downloadHeaders,
61
+ downloadParams,
58
62
  ...propsToPass
59
63
  } = props,
60
64
  {
@@ -382,6 +386,10 @@ export default function withPresetButtons(WrappedComponent, isGrid = false) {
382
386
  onClose={onModalClose}
383
387
  Repository={Repository}
384
388
  columnsConfig={props.columnsConfig}
389
+ uploadHeaders={uploadHeaders}
390
+ uploadParams={uploadParams}
391
+ downloadHeaders={downloadHeaders}
392
+ downloadParams={downloadParams}
385
393
  />
386
394
  </Modal>}
387
395
  </>;
@@ -10,21 +10,19 @@ import {
10
10
  UI_MODE_WEB,
11
11
  CURRENT_MODE,
12
12
  } from '../../Constants/UiModes.js';
13
+ import {
14
+ REPORT_TYPES__EXCEL,
15
+ REPORT_TYPES__PDF,
16
+ } from '../../Constants/ReportTypes.js';
13
17
  import Form from '../Form/Form.js';
14
18
  import withComponent from '../Hoc/withComponent.js';
15
19
  import testProps from '../../Functions/testProps.js';
16
20
  import ChartLine from '../Icons/ChartLine.js';
17
21
  import Pdf from '../Icons/Pdf.js';
18
22
  import Excel from '../Icons/Excel.js';
19
- import UiGlobals from '../../UiGlobals.js';
20
- import downloadInBackground from '../../Functions/downloadInBackground.js';
21
- import downloadWithFetch from '../../Functions/downloadWithFetch.js';
23
+ import getReport from '../../Functions/getReport.js';
22
24
  import _ from 'lodash';
23
25
 
24
- const
25
- PDF = 'PDF',
26
- EXCEL = 'PhpOffice';
27
-
28
26
  function Report(props) {
29
27
  if (CURRENT_MODE !== UI_MODE_WEB) {
30
28
  return <Text>Reports are web only!</Text>;
@@ -40,30 +38,7 @@ function Report(props) {
40
38
  showReportHeaders = true,
41
39
  h = '300px',
42
40
  } = props,
43
- url = UiGlobals.baseURL + 'Reports/getReport',
44
- buttons = [],
45
- getReport = (reportType, data) => {
46
- const params = {
47
- report_id: reportId,
48
- outputFileType: reportType,
49
- showReportHeaders,
50
- // download_token, // not sure this is needed
51
- ...data,
52
- };
53
-
54
- if (reportType === EXCEL) {
55
- downloadInBackground(url, params);
56
- } else {
57
- const options = {
58
- method: 'POST',
59
- headers: {
60
- 'Content-Type': 'application/json',
61
- },
62
- body: JSON.stringify(params),
63
- };
64
- downloadWithFetch(url, options);
65
- }
66
- };
41
+ buttons = [];
67
42
 
68
43
  const propsIcon = props._icon || {};
69
44
  propsIcon.size = 60;
@@ -86,7 +61,12 @@ function Report(props) {
86
61
  key: 'excelBtn',
87
62
  text: 'Download Excel',
88
63
  leftIcon: <Icon as={Excel} size="md" color="#fff" />,
89
- onPress: (data) => getReport(EXCEL, data),
64
+ onPress: (data) => getReport({
65
+ reportId,
66
+ data,
67
+ reportType: REPORT_TYPES__EXCEL,
68
+ showReportHeaders,
69
+ }),
90
70
  ml: 1,
91
71
  });
92
72
  }
@@ -96,7 +76,12 @@ function Report(props) {
96
76
  key: 'pdfBtn',
97
77
  text: 'Download PDF',
98
78
  leftIcon: <Icon as={Pdf} size="md" color="#fff" />,
99
- onPress: (data) => getReport(PDF, data),
79
+ onPress: (data) => getReport({
80
+ reportId,
81
+ data,
82
+ reportType: REPORT_TYPES__PDF,
83
+ showReportHeaders,
84
+ }),
100
85
  ml: 1,
101
86
  });
102
87
  }
@@ -0,0 +1,2 @@
1
+ export const REPORT_TYPES__EXCEL = 'PhpOffice';
2
+ export const REPORT_TYPES__PDF = 'PDF';
@@ -0,0 +1,42 @@
1
+ import {
2
+ REPORT_TYPES__EXCEL,
3
+ REPORT_TYPES__PDF,
4
+ } from '../Constants/ReportTypes.js';
5
+ import downloadInBackground from './downloadInBackground.js';
6
+ import downloadWithFetch from './downloadWithFetch.js';
7
+ import UiGlobals from '../UiGlobals.js';
8
+
9
+ export default function getReport(args) {
10
+ const {
11
+ reportId,
12
+ data,
13
+ reportType = REPORT_TYPES__EXCEL,
14
+ showReportHeaders = true,
15
+ } = args;
16
+
17
+ if (!reportId) {
18
+ throw Error('downloadReport: report_id is required');
19
+ }
20
+
21
+ const
22
+ url = UiGlobals.baseURL + 'Reports/getReport',
23
+ params = {
24
+ report_id: reportId,
25
+ outputFileType: reportType,
26
+ showReportHeaders,
27
+ ...data,
28
+ };
29
+
30
+ if (reportType === REPORT_TYPES__EXCEL) {
31
+ downloadInBackground(url, params);
32
+ } else {
33
+ const options = {
34
+ method: 'POST',
35
+ headers: {
36
+ 'Content-Type': 'application/json',
37
+ },
38
+ body: JSON.stringify(params),
39
+ };
40
+ downloadWithFetch(url, options);
41
+ }
42
+ };