datastake-daf 0.6.430 → 0.6.432

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.
@@ -13302,10 +13302,11 @@ DAFFooter.propTypes = {
13302
13302
  isViewMode: PropTypes__default["default"].bool
13303
13303
  };
13304
13304
 
13305
- const PAGE_HEIGHT = 1587;
13306
- // margin-top: 20, bottom: 20;
13305
+ const PAGE_HEIGHT = 1587; // full page height in px
13307
13306
  const FOOTER_HEIGHT = 70;
13308
13307
  const HEADER_HEIGHT = 100;
13308
+ const GAP = 24; // space between rows
13309
+
13309
13310
  const Row = _ref => {
13310
13311
  let {
13311
13312
  widgets,
@@ -13334,81 +13335,76 @@ const Row = _ref => {
13334
13335
  return /*#__PURE__*/jsxRuntime.jsx("section", {
13335
13336
  ref: ref,
13336
13337
  style: widgets.style,
13337
- children: typeof widgets.render === 'function' ? widgets.render() : null
13338
+ children: typeof widgets.render === "function" ? widgets.render() : null
13338
13339
  });
13339
13340
  };
13340
13341
  function PdfView(_ref2) {
13341
13342
  let {
13342
13343
  config = [],
13343
13344
  customClassName,
13344
- title = 'Title',
13345
- imgSrc = '',
13346
- userId = 'IDD-0000000',
13347
- accountId = 'IDD-0000000',
13348
- documentId = 'IDD-0000000',
13349
- downloadId = 'DWL-00000123'
13345
+ title = "Title",
13346
+ imgSrc = "",
13347
+ userId = "IDD-0000000",
13348
+ accountId = "IDD-0000000",
13349
+ documentId = "IDD-0000000",
13350
+ downloadId = "DWL-00000123"
13350
13351
  } = _ref2;
13351
13352
  const [sectionsConfig, setSectionsConfig] = React.useState({});
13352
13353
  const [pages, setPages] = React.useState([1]);
13354
+ const onChangeHeight = React.useCallback((index, conf) => {
13355
+ setSectionsConfig(prev => _objectSpread2(_objectSpread2({}, prev), {}, {
13356
+ [index]: conf
13357
+ }));
13358
+ }, []);
13353
13359
  const doSizing = React.useCallback(() => {
13354
13360
  const keys = Object.keys(sectionsConfig);
13361
+ if (keys.length !== config.length) return;
13355
13362
  let _pages = [1];
13356
- let _page = 1;
13357
- if (keys.length === config.length) {
13358
- let incrHeight = 0;
13359
- keys.forEach(k => {
13360
- const {
13361
- ref
13362
- } = sectionsConfig[k];
13363
- ref.current.style.marginBottom = '0px';
13364
- // ref.current.style.marginTop = '15px';
13365
- });
13366
- keys.forEach((k, i) => {
13367
- const {
13368
- height,
13369
- ref
13370
- } = sectionsConfig[k];
13371
- if (i === 0) {
13372
- ref.current.style.marginTop = "".concat(HEADER_HEIGHT, "px");
13373
- incrHeight += HEADER_HEIGHT;
13374
- }
13375
- const newHeight = incrHeight + height;
13376
- if (i === keys.length - 1) {
13377
- ref.current.style.paddingBottom = '30px';
13378
- }
13379
- if (newHeight > PAGE_HEIGHT - 30 - FOOTER_HEIGHT - HEADER_HEIGHT) {
13380
- const dif = Math.abs(PAGE_HEIGHT - incrHeight);
13381
- ref.current.style.marginTop = '30px';
13382
- _page += 1;
13383
- _pages.push(_page);
13384
- if (sectionsConfig[keys[i - 1]]) {
13385
- const {
13386
- ref: topRef
13387
- } = sectionsConfig[keys[i - 1]];
13388
- console.log({
13389
- dif
13390
- });
13391
- topRef.current.style.marginBottom = "".concat(250, "px");
13392
- incrHeight = height + 24 + HEADER_HEIGHT;
13393
- // console.log('margin', dif);
13394
- }
13395
- } else {
13396
- incrHeight = newHeight + 24;
13397
- }
13398
- // console.groupEnd();
13399
- });
13400
- setPages(_pages);
13401
- }
13402
- }, [sectionsConfig]);
13363
+ let currentPage = 1;
13364
+ let accumulatedHeight = HEADER_HEIGHT;
13365
+
13366
+ // Reset margins before recalculation
13367
+ keys.forEach(k => {
13368
+ const {
13369
+ ref
13370
+ } = sectionsConfig[k];
13371
+ ref.current.style.marginTop = "0px";
13372
+ ref.current.style.marginBottom = "0px";
13373
+ ref.current.style.pageBreakBefore = "auto";
13374
+ });
13375
+ keys.forEach((k, i) => {
13376
+ const {
13377
+ height,
13378
+ ref
13379
+ } = sectionsConfig[k];
13380
+ const totalWithGap = accumulatedHeight + height + (i > 0 ? GAP : 0);
13381
+ const maxContentHeight = PAGE_HEIGHT - FOOTER_HEIGHT - HEADER_HEIGHT - 30;
13382
+ if (totalWithGap > maxContentHeight) {
13383
+ // start a new page
13384
+ currentPage += 1;
13385
+ _pages.push(currentPage);
13386
+
13387
+ // push element down to next page visually
13388
+ const overflow = PAGE_HEIGHT - accumulatedHeight;
13389
+ ref.current.style.marginTop = "".concat(overflow + HEADER_HEIGHT, "px");
13390
+
13391
+ // reset accumulated height for next page
13392
+ accumulatedHeight = HEADER_HEIGHT + height + GAP;
13393
+ } else {
13394
+ accumulatedHeight = totalWithGap;
13395
+ }
13396
+
13397
+ // Add bottom padding for last element
13398
+ if (i === keys.length - 1) {
13399
+ ref.current.style.paddingBottom = "30px";
13400
+ }
13401
+ });
13402
+ setPages(_pages);
13403
+ }, [sectionsConfig, config.length]);
13403
13404
  React.useEffect(() => {
13404
13405
  doSizing();
13405
13406
  }, [doSizing]);
13406
- const onChangeHeight = React.useCallback((index, conf) => {
13407
- setSectionsConfig(prev => _objectSpread2(_objectSpread2({}, prev), {}, {
13408
- [index]: conf
13409
- }));
13410
- }, []);
13411
- const contClassName = formatClassname(['daf-analysis daf-pdf-view', customClassName]);
13407
+ const contClassName = formatClassname(["daf-analysis daf-pdf-view", customClassName]);
13412
13408
  const renderDashboard = React.useCallback(() => {
13413
13409
  return /*#__PURE__*/jsxRuntime.jsx("div", {
13414
13410
  className: "view-content",
@@ -13420,33 +13416,23 @@ function PdfView(_ref2) {
13420
13416
  widgets: widgets,
13421
13417
  i: i,
13422
13418
  onChangeHeight: onChangeHeight
13423
- }, "dashboard-sections=".concat(i + 1)))
13419
+ }, "dashboard-section-".concat(i)))
13424
13420
  })
13425
13421
  })
13426
13422
  });
13427
13423
  }, [config, onChangeHeight]);
13428
-
13429
- // <div className="daf-analysis">
13430
- // <Header title={t('Dashboard Title')} />
13431
-
13432
- // <div className="content">
13433
- // <div className="view-content">
13434
- // <div className="daf-analysis-layout">
13435
- // <div className='sections-cont w-pt'>
13436
- // <section>
13437
-
13438
13424
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
13439
13425
  className: contClassName,
13440
13426
  style: {
13441
- position: 'relative'
13427
+ position: "relative"
13442
13428
  },
13443
- children: [renderDashboard(), pages.map(page => /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
13429
+ children: [renderDashboard(), pages.map(page => /*#__PURE__*/jsxRuntime.jsxs("div", {
13444
13430
  children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
13445
13431
  style: {
13446
13432
  top: (page - 1) * PAGE_HEIGHT,
13447
- width: '100%',
13448
- height: HEADER_HEIGHT - 24,
13449
- position: 'absolute',
13433
+ width: "100%",
13434
+ height: HEADER_HEIGHT,
13435
+ position: "absolute",
13450
13436
  left: 0,
13451
13437
  zIndex: 1000000
13452
13438
  },
@@ -13463,12 +13449,12 @@ function PdfView(_ref2) {
13463
13449
  alt: "logo"
13464
13450
  })
13465
13451
  })]
13466
- }, "headers-".concat(page)), /*#__PURE__*/jsxRuntime.jsxs("div", {
13452
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
13467
13453
  style: {
13468
13454
  top: page * PAGE_HEIGHT - FOOTER_HEIGHT,
13469
- width: '100%',
13455
+ width: "100%",
13470
13456
  height: FOOTER_HEIGHT,
13471
- position: 'absolute',
13457
+ position: "absolute",
13472
13458
  left: 0,
13473
13459
  zIndex: 1000000
13474
13460
  },
@@ -13476,26 +13462,26 @@ function PdfView(_ref2) {
13476
13462
  children: [/*#__PURE__*/jsxRuntime.jsx("div", {
13477
13463
  className: "flex flex-column justify-center",
13478
13464
  children: /*#__PURE__*/jsxRuntime.jsx("h5", {
13479
- children: moment__default["default"]().format('DD MMM YYYY')
13465
+ children: moment__default["default"]().format("DD MMM YYYY")
13480
13466
  })
13481
13467
  }), /*#__PURE__*/jsxRuntime.jsx("div", {
13482
13468
  className: "flex flex-column justify-center",
13483
13469
  children: /*#__PURE__*/jsxRuntime.jsxs("div", {
13484
13470
  className: "flex gap-2",
13485
13471
  children: [/*#__PURE__*/jsxRuntime.jsxs("h5", {
13486
- children: ["User ID:", ' ', /*#__PURE__*/jsxRuntime.jsx("strong", {
13472
+ children: ["User ID: ", /*#__PURE__*/jsxRuntime.jsx("strong", {
13487
13473
  children: userId
13488
13474
  })]
13489
13475
  }), /*#__PURE__*/jsxRuntime.jsxs("h5", {
13490
- children: ["Account ID:", ' ', /*#__PURE__*/jsxRuntime.jsx("strong", {
13476
+ children: ["Account ID: ", /*#__PURE__*/jsxRuntime.jsx("strong", {
13491
13477
  children: accountId
13492
13478
  })]
13493
13479
  }), /*#__PURE__*/jsxRuntime.jsxs("h5", {
13494
- children: ["Document ID:", ' ', /*#__PURE__*/jsxRuntime.jsx("strong", {
13480
+ children: ["Document ID: ", /*#__PURE__*/jsxRuntime.jsx("strong", {
13495
13481
  children: documentId
13496
13482
  })]
13497
13483
  }), /*#__PURE__*/jsxRuntime.jsxs("h5", {
13498
- children: ["Download ID:", ' ', /*#__PURE__*/jsxRuntime.jsx("strong", {
13484
+ children: ["Download ID: ", /*#__PURE__*/jsxRuntime.jsx("strong", {
13499
13485
  children: downloadId
13500
13486
  })]
13501
13487
  })]
@@ -13506,8 +13492,8 @@ function PdfView(_ref2) {
13506
13492
  children: page
13507
13493
  })
13508
13494
  })]
13509
- }, "footers-".concat(page))]
13510
- }))]
13495
+ })]
13496
+ }, "page-".concat(page)))]
13511
13497
  });
13512
13498
  }
13513
13499
  PdfView.propTypes = {
@@ -13517,7 +13503,8 @@ PdfView.propTypes = {
13517
13503
  imgSrc: PropTypes__default["default"].string,
13518
13504
  userId: PropTypes__default["default"].string,
13519
13505
  accountId: PropTypes__default["default"].string,
13520
- documentId: PropTypes__default["default"].string
13506
+ documentId: PropTypes__default["default"].string,
13507
+ downloadId: PropTypes__default["default"].string
13521
13508
  };
13522
13509
 
13523
13510
  const ajaxSelectFieldData = async (value, config, getApiBaseUrl = () => {}, getAppHeader = () => {}, app, formValues = {}) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datastake-daf",
3
- "version": "0.6.430",
3
+ "version": "0.6.432",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.2.5",
6
6
  "@antv/g2": "^5.1.1",
@@ -1,14 +1,14 @@
1
1
  import moment from "moment";
2
- import PropTypes from 'prop-types';
2
+ import PropTypes from "prop-types";
3
3
  import { useCallback, useEffect, useRef, useState } from "react";
4
4
  import { formatClassname } from "../../../../../helpers/ClassesHelper";
5
5
 
6
- const PAGE_HEIGHT = 1587;
7
- // margin-top: 20, bottom: 20;
6
+ const PAGE_HEIGHT = 1587; // full page height in px
8
7
  const FOOTER_HEIGHT = 70;
9
8
  const HEADER_HEIGHT = 100;
9
+ const GAP = 24; // space between rows
10
10
 
11
- const Row = ({ widgets, i, onChangeHeight = () => { } }) => {
11
+ const Row = ({ widgets, i, onChangeHeight = () => {} }) => {
12
12
  const ref = useRef();
13
13
  const [height, setHeight] = useState(0);
14
14
 
@@ -20,7 +20,6 @@ const Row = ({ widgets, i, onChangeHeight = () => { } }) => {
20
20
  });
21
21
 
22
22
  observer.observe(ref.current);
23
-
24
23
  return () => observer.disconnect();
25
24
  }, []);
26
25
 
@@ -28,97 +27,95 @@ const Row = ({ widgets, i, onChangeHeight = () => { } }) => {
28
27
  if (height) {
29
28
  onChangeHeight(i, { height, ref });
30
29
  }
31
- }, [height])
30
+ }, [height]);
32
31
 
33
32
  return (
34
33
  <section ref={ref} style={widgets.style}>
35
- {typeof widgets.render === 'function' ? widgets.render() : null}
34
+ {typeof widgets.render === "function" ? widgets.render() : null}
36
35
  </section>
37
- )
36
+ );
38
37
  };
39
38
 
40
39
  export default function PdfView({
41
40
  config = [],
42
41
  customClassName,
43
- title = 'Title',
44
- imgSrc = '',
45
- userId = 'IDD-0000000',
46
- accountId = 'IDD-0000000',
47
- documentId = 'IDD-0000000',
48
- downloadId = 'DWL-00000123',
42
+ title = "Title",
43
+ imgSrc = "",
44
+ userId = "IDD-0000000",
45
+ accountId = "IDD-0000000",
46
+ documentId = "IDD-0000000",
47
+ downloadId = "DWL-00000123",
49
48
  }) {
50
49
  const [sectionsConfig, setSectionsConfig] = useState({});
51
50
  const [pages, setPages] = useState([1]);
52
51
 
52
+ const onChangeHeight = useCallback((index, conf) => {
53
+ setSectionsConfig((prev) => ({ ...prev, [index]: conf }));
54
+ }, []);
55
+
53
56
  const doSizing = useCallback(() => {
54
57
  const keys = Object.keys(sectionsConfig);
58
+ if (keys.length !== config.length) return;
59
+
55
60
  let _pages = [1];
56
- let _page = 1;
57
-
58
- if (keys.length === config.length) {
59
- let incrHeight = 0;
60
-
61
- keys.forEach(k => {
62
- const { ref } = sectionsConfig[k];
63
- ref.current.style.marginBottom = '0px';
64
- // ref.current.style.marginTop = '15px';
65
- })
66
-
67
- keys.forEach((k, i) => {
68
- const { height, ref } = sectionsConfig[k];
69
-
70
- if (i === 0) {
71
- ref.current.style.marginTop = `${HEADER_HEIGHT}px`;
72
- incrHeight += HEADER_HEIGHT;
73
- }
74
-
75
- const newHeight = incrHeight + height;
76
-
77
- if (i === keys.length - 1) {
78
- ref.current.style.paddingBottom = '30px';
79
- }
80
-
81
- if (newHeight > PAGE_HEIGHT - 30 - FOOTER_HEIGHT - HEADER_HEIGHT) {
82
- const dif = Math.abs(PAGE_HEIGHT - incrHeight);
83
- ref.current.style.marginTop = '30px';
84
- _page += 1;
85
- _pages.push(_page);
86
-
87
- if (sectionsConfig[keys[i - 1]]) {
88
- const { ref: topRef } = sectionsConfig[keys[i - 1]];
89
- console.log({dif})
90
- topRef.current.style.marginBottom = `${250}px`;
91
- incrHeight = height + 24 + HEADER_HEIGHT;
92
- // console.log('margin', dif);
93
- }
94
- } else {
95
- incrHeight = newHeight + 24;
96
- }
97
- // console.groupEnd();
98
- })
99
- setPages(_pages);
100
- }
101
- }, [sectionsConfig]);
61
+ let currentPage = 1;
62
+ let accumulatedHeight = HEADER_HEIGHT;
63
+
64
+ // Reset margins before recalculation
65
+ keys.forEach((k) => {
66
+ const { ref } = sectionsConfig[k];
67
+ ref.current.style.marginTop = "0px";
68
+ ref.current.style.marginBottom = "0px";
69
+ ref.current.style.pageBreakBefore = "auto";
70
+ });
71
+
72
+ keys.forEach((k, i) => {
73
+ const { height, ref } = sectionsConfig[k];
74
+ const totalWithGap = accumulatedHeight + height + (i > 0 ? GAP : 0);
75
+ const maxContentHeight = PAGE_HEIGHT - FOOTER_HEIGHT - HEADER_HEIGHT - 30;
76
+
77
+ if (totalWithGap > maxContentHeight) {
78
+ // start a new page
79
+ currentPage += 1;
80
+ _pages.push(currentPage);
81
+
82
+ // push element down to next page visually
83
+ const overflow = PAGE_HEIGHT - accumulatedHeight;
84
+ ref.current.style.marginTop = `${overflow + HEADER_HEIGHT}px`;
85
+
86
+ // reset accumulated height for next page
87
+ accumulatedHeight = HEADER_HEIGHT + height + GAP;
88
+ } else {
89
+ accumulatedHeight = totalWithGap;
90
+ }
91
+
92
+ // Add bottom padding for last element
93
+ if (i === keys.length - 1) {
94
+ ref.current.style.paddingBottom = "30px";
95
+ }
96
+ });
97
+
98
+ setPages(_pages);
99
+ }, [sectionsConfig, config.length]);
102
100
 
103
101
  useEffect(() => {
104
102
  doSizing();
105
103
  }, [doSizing]);
106
104
 
107
- const onChangeHeight = useCallback((index, conf) => {
108
- setSectionsConfig((prev) => ({ ...prev, [index]: conf }))
109
- }, []);
110
-
111
- const contClassName = formatClassname(['daf-analysis daf-pdf-view', customClassName]);
105
+ const contClassName = formatClassname([
106
+ "daf-analysis daf-pdf-view",
107
+ customClassName,
108
+ ]);
112
109
 
113
110
  const renderDashboard = useCallback(() => {
114
111
  return (
115
112
  <div className="view-content">
116
113
  <div className="daf-analysis-layout">
117
- <div className='sections-cont'>
114
+ <div className="sections-cont">
118
115
  {config.map((widgets, i) => (
119
116
  <Row
120
117
  widgets={widgets}
121
- key={`dashboard-sections=${i + 1}`}
118
+ key={`dashboard-section-${i}`}
122
119
  i={i}
123
120
  onChangeHeight={onChangeHeight}
124
121
  />
@@ -129,23 +126,22 @@ export default function PdfView({
129
126
  );
130
127
  }, [config, onChangeHeight]);
131
128
 
132
- // <div className="daf-analysis">
133
- // <Header title={t('Dashboard Title')} />
134
-
135
- // <div className="content">
136
- // <div className="view-content">
137
- // <div className="daf-analysis-layout">
138
- // <div className='sections-cont w-pt'>
139
- // <section>
140
-
141
129
  return (
142
- <div className={contClassName} style={{ position: 'relative' }}>
130
+ <div className={contClassName} style={{ position: "relative" }}>
143
131
  {renderDashboard()}
132
+
144
133
  {pages.map((page) => (
145
- <>
134
+ <div key={`page-${page}`}>
135
+ {/* HEADER */}
146
136
  <div
147
- style={{ top: ((page - 1) * PAGE_HEIGHT), width: '100%', height: HEADER_HEIGHT - 24, position: 'absolute', left: 0, zIndex: 1000000 }}
148
- key={`headers-${page}`}
137
+ style={{
138
+ top: (page - 1) * PAGE_HEIGHT,
139
+ width: "100%",
140
+ height: HEADER_HEIGHT,
141
+ position: "absolute",
142
+ left: 0,
143
+ zIndex: 1000000,
144
+ }}
149
145
  className="flex-row dashboard-header"
150
146
  >
151
147
  <div className="flex flex-column justify-center flex-1">
@@ -155,35 +151,35 @@ export default function PdfView({
155
151
  <img src={imgSrc} alt="logo" />
156
152
  </div>
157
153
  </div>
154
+
155
+ {/* FOOTER */}
158
156
  <div
159
- style={{ top: (page * PAGE_HEIGHT) - FOOTER_HEIGHT, width: '100%', height: FOOTER_HEIGHT, position: 'absolute', left: 0, zIndex: 1000000 }}
160
- key={`footers-${page}`}
157
+ style={{
158
+ top: page * PAGE_HEIGHT - FOOTER_HEIGHT,
159
+ width: "100%",
160
+ height: FOOTER_HEIGHT,
161
+ position: "absolute",
162
+ left: 0,
163
+ zIndex: 1000000,
164
+ }}
161
165
  className="dashboard-footer flex-row"
162
166
  >
163
167
  <div className="flex flex-column justify-center">
164
- <h5>{moment().format('DD MMM YYYY')}</h5>
168
+ <h5>{moment().format("DD MMM YYYY")}</h5>
165
169
  </div>
166
170
  <div className="flex flex-column justify-center">
167
171
  <div className="flex gap-2">
168
172
  <h5>
169
- User ID:
170
- {' '}
171
- <strong>{userId}</strong>
173
+ User ID: <strong>{userId}</strong>
172
174
  </h5>
173
175
  <h5>
174
- Account ID:
175
- {' '}
176
- <strong>{accountId}</strong>
176
+ Account ID: <strong>{accountId}</strong>
177
177
  </h5>
178
178
  <h5>
179
- Document ID:
180
- {' '}
181
- <strong>{documentId}</strong>
179
+ Document ID: <strong>{documentId}</strong>
182
180
  </h5>
183
181
  <h5>
184
- Download ID:
185
- {' '}
186
- <strong>{downloadId}</strong>
182
+ Download ID: <strong>{downloadId}</strong>
187
183
  </h5>
188
184
  </div>
189
185
  </div>
@@ -191,7 +187,7 @@ export default function PdfView({
191
187
  <h5>{page}</h5>
192
188
  </div>
193
189
  </div>
194
- </>
190
+ </div>
195
191
  ))}
196
192
  </div>
197
193
  );
@@ -205,4 +201,5 @@ PdfView.propTypes = {
205
201
  userId: PropTypes.string,
206
202
  accountId: PropTypes.string,
207
203
  documentId: PropTypes.string,
208
- }
204
+ downloadId: PropTypes.string,
205
+ };