datastake-daf 0.6.416 → 0.6.417

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.
@@ -13276,9 +13276,15 @@ DAFFooter.propTypes = {
13276
13276
  };
13277
13277
 
13278
13278
  const PAGE_HEIGHT = 1587;
13279
- // margin-top: 20, bottom: 20;
13280
13279
  const FOOTER_HEIGHT = 70;
13281
13280
  const HEADER_HEIGHT = 100;
13281
+ const SECTION_SPACING = 24;
13282
+ const TOP_PADDING = 30;
13283
+ const BOTTOM_PADDING = 30;
13284
+
13285
+ // Calculate usable height per page
13286
+ const USABLE_HEIGHT = PAGE_HEIGHT - HEADER_HEIGHT - FOOTER_HEIGHT - TOP_PADDING - BOTTOM_PADDING;
13287
+ const SPLIT_THRESHOLD = USABLE_HEIGHT * 0.80;
13282
13288
  const Row = _ref => {
13283
13289
  let {
13284
13290
  widgets,
@@ -13303,7 +13309,7 @@ const Row = _ref => {
13303
13309
  ref
13304
13310
  });
13305
13311
  }
13306
- }, [height]);
13312
+ }, [height, i, onChangeHeight]);
13307
13313
  return /*#__PURE__*/jsxRuntime.jsx("section", {
13308
13314
  ref: ref,
13309
13315
  style: widgets.style,
@@ -13325,51 +13331,92 @@ function PdfView(_ref2) {
13325
13331
  const [pages, setPages] = React.useState([1]);
13326
13332
  const doSizing = React.useCallback(() => {
13327
13333
  const keys = Object.keys(sectionsConfig);
13334
+ if (keys.length !== config.length) return;
13335
+
13336
+ // Check if all refs are ready
13337
+ const allRefsReady = keys.every(k => {
13338
+ const {
13339
+ ref
13340
+ } = sectionsConfig[k];
13341
+ return ref && ref.current;
13342
+ });
13343
+ if (!allRefsReady) return;
13328
13344
  let _pages = [1];
13329
- let _page = 1;
13330
- if (keys.length === config.length) {
13331
- let incrHeight = 0;
13332
- keys.forEach(k => {
13333
- const {
13334
- ref
13335
- } = sectionsConfig[k];
13345
+ let currentPage = 1;
13346
+ let remainingHeight = USABLE_HEIGHT;
13347
+
13348
+ // Reset all margins first
13349
+ keys.forEach(k => {
13350
+ const {
13351
+ ref
13352
+ } = sectionsConfig[k];
13353
+ if (ref.current) {
13354
+ ref.current.style.marginTop = '0px';
13336
13355
  ref.current.style.marginBottom = '0px';
13337
- // ref.current.style.marginTop = '15px';
13338
- });
13339
- keys.forEach((k, i) => {
13340
- const {
13341
- height,
13342
- ref
13343
- } = sectionsConfig[k];
13344
- if (i === 0) {
13345
- ref.current.style.marginTop = "".concat(HEADER_HEIGHT, "px");
13346
- incrHeight += HEADER_HEIGHT;
13347
- }
13348
- const newHeight = incrHeight + height;
13349
- if (i === keys.length - 1) {
13350
- ref.current.style.paddingBottom = '30px';
13351
- }
13352
- if (newHeight > PAGE_HEIGHT - 30 - FOOTER_HEIGHT - HEADER_HEIGHT) {
13353
- const dif = Math.abs(PAGE_HEIGHT - incrHeight);
13354
- ref.current.style.marginTop = '30px';
13355
- _page += 1;
13356
- _pages.push(_page);
13357
- if (sectionsConfig[keys[i - 1]]) {
13358
- const {
13359
- ref: topRef
13360
- } = sectionsConfig[keys[i - 1]];
13361
- topRef.current.style.marginBottom = "".concat(dif + HEADER_HEIGHT - 24, "px");
13362
- incrHeight = height + 24 + HEADER_HEIGHT;
13363
- // console.log('margin', dif);
13356
+ ref.current.style.paddingBottom = '0px';
13357
+ }
13358
+ });
13359
+ keys.forEach((k, i) => {
13360
+ const {
13361
+ height,
13362
+ ref
13363
+ } = sectionsConfig[k];
13364
+ if (!ref || !ref.current) return;
13365
+ const isFirst = i === 0;
13366
+ const isLast = i === keys.length - 1;
13367
+ const startOfPageMargin = HEADER_HEIGHT + TOP_PADDING;
13368
+
13369
+ // First section of first page gets header spacing
13370
+ if (isFirst) {
13371
+ ref.current.style.marginTop = "".concat(startOfPageMargin, "px");
13372
+ remainingHeight = USABLE_HEIGHT;
13373
+ }
13374
+
13375
+ // Calculate space needed for this section (including spacing if not first on page)
13376
+ const sectionTotalHeight = height + (isFirst || remainingHeight === USABLE_HEIGHT ? 0 : SECTION_SPACING);
13377
+
13378
+ // Check if adding this section would exceed the remaining height
13379
+ const wouldExceedPage = sectionTotalHeight > remainingHeight;
13380
+
13381
+ // Check if the accumulated height on current page + this section exceeds 65% threshold
13382
+ const currentPageUsed = USABLE_HEIGHT - remainingHeight;
13383
+ const totalWithThisSection = currentPageUsed + sectionTotalHeight;
13384
+ const wouldExceedThreshold = totalWithThisSection > SPLIT_THRESHOLD;
13385
+ if (!isFirst && (wouldExceedPage || wouldExceedThreshold)) {
13386
+ // Move to next page
13387
+ const previousKey = keys[i - 1];
13388
+ if (sectionsConfig[previousKey]) {
13389
+ const {
13390
+ ref: prevRef
13391
+ } = sectionsConfig[previousKey];
13392
+ if (prevRef && prevRef.current) {
13393
+ // Add margin to push to next page
13394
+ prevRef.current.style.marginBottom = "".concat(remainingHeight * 0.4 + HEADER_HEIGHT, "px");
13364
13395
  }
13396
+ }
13397
+
13398
+ // Start new page - position after header and top padding
13399
+ currentPage += 1;
13400
+ _pages.push(currentPage);
13401
+ ref.current.style.marginTop = "".concat(startOfPageMargin, "px");
13402
+ remainingHeight = USABLE_HEIGHT - height;
13403
+ } else {
13404
+ // Section fits on current page
13405
+ if (!isFirst && remainingHeight !== USABLE_HEIGHT) {
13406
+ ref.current.style.marginTop = "".concat(SECTION_SPACING, "px");
13407
+ remainingHeight -= height + SECTION_SPACING;
13365
13408
  } else {
13366
- incrHeight = newHeight + 24;
13409
+ remainingHeight -= height;
13367
13410
  }
13368
- // console.groupEnd();
13369
- });
13370
- setPages(_pages);
13371
- }
13372
- }, [sectionsConfig]);
13411
+ }
13412
+
13413
+ // Add padding to last section
13414
+ if (isLast) {
13415
+ ref.current.style.paddingBottom = "".concat(BOTTOM_PADDING, "px");
13416
+ }
13417
+ });
13418
+ setPages(_pages);
13419
+ }, [sectionsConfig, config.length]);
13373
13420
  React.useEffect(() => {
13374
13421
  doSizing();
13375
13422
  }, [doSizing]);
@@ -13390,27 +13437,17 @@ function PdfView(_ref2) {
13390
13437
  widgets: widgets,
13391
13438
  i: i,
13392
13439
  onChangeHeight: onChangeHeight
13393
- }, "dashboard-sections=".concat(i + 1)))
13440
+ }, "dashboard-sections-".concat(i + 1)))
13394
13441
  })
13395
13442
  })
13396
13443
  });
13397
13444
  }, [config, onChangeHeight]);
13398
-
13399
- // <div className="daf-analysis">
13400
- // <Header title={t('Dashboard Title')} />
13401
-
13402
- // <div className="content">
13403
- // <div className="view-content">
13404
- // <div className="daf-analysis-layout">
13405
- // <div className='sections-cont w-pt'>
13406
- // <section>
13407
-
13408
13445
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
13409
13446
  className: contClassName,
13410
13447
  style: {
13411
13448
  position: 'relative'
13412
13449
  },
13413
- children: [renderDashboard(), pages.map(page => /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
13450
+ children: [renderDashboard(), pages.map(page => /*#__PURE__*/jsxRuntime.jsxs("div", {
13414
13451
  children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
13415
13452
  style: {
13416
13453
  top: (page - 1) * PAGE_HEIGHT,
@@ -13433,7 +13470,7 @@ function PdfView(_ref2) {
13433
13470
  alt: "logo"
13434
13471
  })
13435
13472
  })]
13436
- }, "headers-".concat(page)), /*#__PURE__*/jsxRuntime.jsxs("div", {
13473
+ }), /*#__PURE__*/jsxRuntime.jsxs("div", {
13437
13474
  style: {
13438
13475
  top: page * PAGE_HEIGHT - FOOTER_HEIGHT,
13439
13476
  width: '100%',
@@ -13476,8 +13513,8 @@ function PdfView(_ref2) {
13476
13513
  children: page
13477
13514
  })
13478
13515
  })]
13479
- }, "footers-".concat(page))]
13480
- }))]
13516
+ })]
13517
+ }, "page-".concat(page)))]
13481
13518
  });
13482
13519
  }
13483
13520
  PdfView.propTypes = {
@@ -13487,7 +13524,8 @@ PdfView.propTypes = {
13487
13524
  imgSrc: PropTypes__default["default"].string,
13488
13525
  userId: PropTypes__default["default"].string,
13489
13526
  accountId: PropTypes__default["default"].string,
13490
- documentId: PropTypes__default["default"].string
13527
+ documentId: PropTypes__default["default"].string,
13528
+ downloadId: PropTypes__default["default"].string
13491
13529
  };
13492
13530
 
13493
13531
  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.416",
3
+ "version": "0.6.417",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.2.5",
6
6
  "@antv/g2": "^5.1.1",
@@ -4,9 +4,15 @@ import { useCallback, useEffect, useRef, useState } from "react";
4
4
  import { formatClassname } from "../../../../../helpers/ClassesHelper";
5
5
 
6
6
  const PAGE_HEIGHT = 1587;
7
- // margin-top: 20, bottom: 20;
8
7
  const FOOTER_HEIGHT = 70;
9
8
  const HEADER_HEIGHT = 100;
9
+ const SECTION_SPACING = 24;
10
+ const TOP_PADDING = 30;
11
+ const BOTTOM_PADDING = 30;
12
+
13
+ // Calculate usable height per page
14
+ const USABLE_HEIGHT = PAGE_HEIGHT - HEADER_HEIGHT - FOOTER_HEIGHT - TOP_PADDING - BOTTOM_PADDING;
15
+ const SPLIT_THRESHOLD = USABLE_HEIGHT * 0.80;
10
16
 
11
17
  const Row = ({ widgets, i, onChangeHeight = () => { } }) => {
12
18
  const ref = useRef();
@@ -28,7 +34,7 @@ const Row = ({ widgets, i, onChangeHeight = () => { } }) => {
28
34
  if (height) {
29
35
  onChangeHeight(i, { height, ref });
30
36
  }
31
- }, [height])
37
+ }, [height, i, onChangeHeight])
32
38
 
33
39
  return (
34
40
  <section ref={ref} style={widgets.style}>
@@ -52,52 +58,90 @@ export default function PdfView({
52
58
 
53
59
  const doSizing = useCallback(() => {
54
60
  const keys = Object.keys(sectionsConfig);
55
- let _pages = [1];
56
- let _page = 1;
57
-
58
- if (keys.length === config.length) {
59
- let incrHeight = 0;
61
+
62
+ if (keys.length !== config.length) return;
60
63
 
61
- keys.forEach(k => {
62
- const { ref } = sectionsConfig[k];
63
- ref.current.style.marginBottom = '0px';
64
- // ref.current.style.marginTop = '15px';
65
- })
64
+ // Check if all refs are ready
65
+ const allRefsReady = keys.every(k => {
66
+ const { ref } = sectionsConfig[k];
67
+ return ref && ref.current;
68
+ });
66
69
 
67
- keys.forEach((k, i) => {
68
- const { height, ref } = sectionsConfig[k];
70
+ if (!allRefsReady) return;
69
71
 
70
- if (i === 0) {
71
- ref.current.style.marginTop = `${HEADER_HEIGHT}px`;
72
- incrHeight += HEADER_HEIGHT;
73
- }
72
+ let _pages = [1];
73
+ let currentPage = 1;
74
+ let remainingHeight = USABLE_HEIGHT;
75
+
76
+ // Reset all margins first
77
+ keys.forEach(k => {
78
+ const { ref } = sectionsConfig[k];
79
+ if (ref.current) {
80
+ ref.current.style.marginTop = '0px';
81
+ ref.current.style.marginBottom = '0px';
82
+ ref.current.style.paddingBottom = '0px';
83
+ }
84
+ });
74
85
 
75
- const newHeight = incrHeight + height;
86
+ keys.forEach((k, i) => {
87
+ const { height, ref } = sectionsConfig[k];
88
+ if (!ref || !ref.current) return;
89
+
90
+ const isFirst = i === 0;
91
+ const isLast = i === keys.length - 1;
92
+ const startOfPageMargin = HEADER_HEIGHT + TOP_PADDING;
93
+
94
+ // First section of first page gets header spacing
95
+ if (isFirst) {
96
+ ref.current.style.marginTop = `${startOfPageMargin}px`;
97
+ remainingHeight = USABLE_HEIGHT;
98
+ }
76
99
 
77
- if (i === keys.length - 1) {
78
- ref.current.style.paddingBottom = '30px';
100
+ // Calculate space needed for this section (including spacing if not first on page)
101
+ const sectionTotalHeight = height + (isFirst || remainingHeight === USABLE_HEIGHT ? 0 : SECTION_SPACING);
102
+
103
+ // Check if adding this section would exceed the remaining height
104
+ const wouldExceedPage = sectionTotalHeight > remainingHeight;
105
+
106
+ // Check if the accumulated height on current page + this section exceeds 65% threshold
107
+ const currentPageUsed = USABLE_HEIGHT - remainingHeight;
108
+ const totalWithThisSection = currentPageUsed + sectionTotalHeight;
109
+ const wouldExceedThreshold = totalWithThisSection > SPLIT_THRESHOLD;
110
+
111
+ if (!isFirst && (wouldExceedPage || wouldExceedThreshold)) {
112
+ // Move to next page
113
+ const previousKey = keys[i - 1];
114
+ if (sectionsConfig[previousKey]) {
115
+ const { ref: prevRef } = sectionsConfig[previousKey];
116
+ if (prevRef && prevRef.current) {
117
+ // Add margin to push to next page
118
+ prevRef.current.style.marginBottom = `${(remainingHeight * 0.4) + HEADER_HEIGHT}px`;
119
+ }
79
120
  }
80
121
 
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
- topRef.current.style.marginBottom = `${dif + HEADER_HEIGHT - 24}px`;
90
- incrHeight = height + 24 + HEADER_HEIGHT;
91
- // console.log('margin', dif);
92
- }
122
+ // Start new page - position after header and top padding
123
+ currentPage += 1;
124
+ _pages.push(currentPage);
125
+ ref.current.style.marginTop = `${startOfPageMargin}px`;
126
+ remainingHeight = USABLE_HEIGHT - height;
127
+ } else {
128
+ // Section fits on current page
129
+ if (!isFirst && remainingHeight !== USABLE_HEIGHT) {
130
+ ref.current.style.marginTop = `${SECTION_SPACING}px`;
131
+ remainingHeight -= (height + SECTION_SPACING);
93
132
  } else {
94
- incrHeight = newHeight + 24;
133
+ remainingHeight -= height;
95
134
  }
96
- // console.groupEnd();
97
- })
98
- setPages(_pages);
99
- }
100
- }, [sectionsConfig]);
135
+ }
136
+
137
+ // Add padding to last section
138
+ if (isLast) {
139
+ ref.current.style.paddingBottom = `${BOTTOM_PADDING}px`;
140
+ }
141
+ });
142
+
143
+ setPages(_pages);
144
+ }, [sectionsConfig, config.length]);
101
145
 
102
146
  useEffect(() => {
103
147
  doSizing();
@@ -117,7 +161,7 @@ export default function PdfView({
117
161
  {config.map((widgets, i) => (
118
162
  <Row
119
163
  widgets={widgets}
120
- key={`dashboard-sections=${i + 1}`}
164
+ key={`dashboard-sections-${i + 1}`}
121
165
  i={i}
122
166
  onChangeHeight={onChangeHeight}
123
167
  />
@@ -128,23 +172,20 @@ export default function PdfView({
128
172
  );
129
173
  }, [config, onChangeHeight]);
130
174
 
131
- // <div className="daf-analysis">
132
- // <Header title={t('Dashboard Title')} />
133
-
134
- // <div className="content">
135
- // <div className="view-content">
136
- // <div className="daf-analysis-layout">
137
- // <div className='sections-cont w-pt'>
138
- // <section>
139
-
140
175
  return (
141
176
  <div className={contClassName} style={{ position: 'relative' }}>
142
177
  {renderDashboard()}
143
178
  {pages.map((page) => (
144
- <>
179
+ <div key={`page-${page}`}>
145
180
  <div
146
- style={{ top: ((page - 1) * PAGE_HEIGHT), width: '100%', height: HEADER_HEIGHT - 24, position: 'absolute', left: 0, zIndex: 1000000 }}
147
- key={`headers-${page}`}
181
+ style={{
182
+ top: ((page - 1) * PAGE_HEIGHT),
183
+ width: '100%',
184
+ height: HEADER_HEIGHT - 24,
185
+ position: 'absolute',
186
+ left: 0,
187
+ zIndex: 1000000
188
+ }}
148
189
  className="flex-row dashboard-header"
149
190
  >
150
191
  <div className="flex flex-column justify-center flex-1">
@@ -155,8 +196,14 @@ export default function PdfView({
155
196
  </div>
156
197
  </div>
157
198
  <div
158
- style={{ top: (page * PAGE_HEIGHT) - FOOTER_HEIGHT, width: '100%', height: FOOTER_HEIGHT, position: 'absolute', left: 0, zIndex: 1000000 }}
159
- key={`footers-${page}`}
199
+ style={{
200
+ top: (page * PAGE_HEIGHT) - FOOTER_HEIGHT,
201
+ width: '100%',
202
+ height: FOOTER_HEIGHT,
203
+ position: 'absolute',
204
+ left: 0,
205
+ zIndex: 1000000
206
+ }}
160
207
  className="dashboard-footer flex-row"
161
208
  >
162
209
  <div className="flex flex-column justify-center">
@@ -190,7 +237,7 @@ export default function PdfView({
190
237
  <h5>{page}</h5>
191
238
  </div>
192
239
  </div>
193
- </>
240
+ </div>
194
241
  ))}
195
242
  </div>
196
243
  );
@@ -204,4 +251,5 @@ PdfView.propTypes = {
204
251
  userId: PropTypes.string,
205
252
  accountId: PropTypes.string,
206
253
  documentId: PropTypes.string,
207
- }
254
+ downloadId: PropTypes.string,
255
+ }