datastake-daf 0.6.433 → 0.6.435

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": "datastake-daf",
3
- "version": "0.6.433",
3
+ "version": "0.6.435",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.2.5",
6
6
  "@antv/g2": "^5.1.1",
@@ -1,25 +1,26 @@
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; // full page height in px
6
+ const PAGE_HEIGHT = 1587;
7
+ // margin-top: 20, bottom: 20;
7
8
  const FOOTER_HEIGHT = 70;
8
9
  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
 
15
15
  useEffect(() => {
16
16
  const observer = new ResizeObserver((entries) => {
17
17
  for (const entry of entries) {
18
- setHeight(entry.contentRect.height);
18
+ setHeight(entry.contentRect.height * 0.8);
19
19
  }
20
20
  });
21
21
 
22
22
  observer.observe(ref.current);
23
+
23
24
  return () => observer.disconnect();
24
25
  }, []);
25
26
 
@@ -27,95 +28,96 @@ const Row = ({ widgets, i, onChangeHeight = () => {} }) => {
27
28
  if (height) {
28
29
  onChangeHeight(i, { height, ref });
29
30
  }
30
- }, [height]);
31
+ }, [height])
31
32
 
32
33
  return (
33
34
  <section ref={ref} style={widgets.style}>
34
- {typeof widgets.render === "function" ? widgets.render() : null}
35
+ {typeof widgets.render === 'function' ? widgets.render() : null}
35
36
  </section>
36
- );
37
+ )
37
38
  };
38
39
 
39
40
  export default function PdfView({
40
41
  config = [],
41
42
  customClassName,
42
- title = "Title",
43
- imgSrc = "",
44
- userId = "IDD-0000000",
45
- accountId = "IDD-0000000",
46
- documentId = "IDD-0000000",
47
- downloadId = "DWL-00000123",
43
+ title = 'Title',
44
+ imgSrc = '',
45
+ userId = 'IDD-0000000',
46
+ accountId = 'IDD-0000000',
47
+ documentId = 'IDD-0000000',
48
+ downloadId = 'DWL-00000123',
48
49
  }) {
49
50
  const [sectionsConfig, setSectionsConfig] = useState({});
50
51
  const [pages, setPages] = useState([1]);
51
52
 
52
- const onChangeHeight = useCallback((index, conf) => {
53
- setSectionsConfig((prev) => ({ ...prev, [index]: conf }));
54
- }, []);
55
-
56
53
  const doSizing = useCallback(() => {
57
54
  const keys = Object.keys(sectionsConfig);
58
- if (keys.length !== config.length) return;
59
-
60
55
  let _pages = [1];
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 = `${120}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]);
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
+ topRef.current.style.marginBottom = `${dif + HEADER_HEIGHT - 24}px`;
90
+ incrHeight = height + 24 + HEADER_HEIGHT;
91
+ // console.log('margin', dif);
92
+ }
93
+ } else {
94
+ incrHeight = newHeight + 24;
95
+ }
96
+ // console.groupEnd();
97
+ })
98
+ setPages(_pages);
99
+ }
100
+ }, [sectionsConfig]);
100
101
 
101
102
  useEffect(() => {
102
103
  doSizing();
103
104
  }, [doSizing]);
104
105
 
105
- const contClassName = formatClassname([
106
- "daf-analysis daf-pdf-view",
107
- customClassName,
108
- ]);
106
+ const onChangeHeight = useCallback((index, conf) => {
107
+ setSectionsConfig((prev) => ({ ...prev, [index]: conf }))
108
+ }, []);
109
+
110
+ const contClassName = formatClassname(['daf-analysis daf-pdf-view', customClassName]);
109
111
 
110
112
  const renderDashboard = useCallback(() => {
111
113
  return (
112
114
  <div className="view-content">
113
115
  <div className="daf-analysis-layout">
114
- <div className="sections-cont">
116
+ <div className='sections-cont'>
115
117
  {config.map((widgets, i) => (
116
118
  <Row
117
119
  widgets={widgets}
118
- key={`dashboard-section-${i}`}
120
+ key={`dashboard-sections=${i + 1}`}
119
121
  i={i}
120
122
  onChangeHeight={onChangeHeight}
121
123
  />
@@ -126,22 +128,23 @@ export default function PdfView({
126
128
  );
127
129
  }, [config, onChangeHeight]);
128
130
 
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
+
129
140
  return (
130
- <div className={contClassName} style={{ position: "relative" }}>
141
+ <div className={contClassName} style={{ position: 'relative' }}>
131
142
  {renderDashboard()}
132
-
133
143
  {pages.map((page) => (
134
- <div key={`page-${page}`}>
135
- {/* HEADER */}
144
+ <>
136
145
  <div
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
- }}
146
+ style={{ top: ((page - 1) * PAGE_HEIGHT), width: '100%', height: HEADER_HEIGHT - 24, position: 'absolute', left: 0, zIndex: 1000000 }}
147
+ key={`headers-${page}`}
145
148
  className="flex-row dashboard-header"
146
149
  >
147
150
  <div className="flex flex-column justify-center flex-1">
@@ -151,35 +154,35 @@ export default function PdfView({
151
154
  <img src={imgSrc} alt="logo" />
152
155
  </div>
153
156
  </div>
154
-
155
- {/* FOOTER */}
156
157
  <div
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
- }}
158
+ style={{ top: (page * PAGE_HEIGHT) - FOOTER_HEIGHT, width: '100%', height: FOOTER_HEIGHT, position: 'absolute', left: 0, zIndex: 1000000 }}
159
+ key={`footers-${page}`}
165
160
  className="dashboard-footer flex-row"
166
161
  >
167
162
  <div className="flex flex-column justify-center">
168
- <h5>{moment().format("DD MMM YYYY")}</h5>
163
+ <h5>{moment().format('DD MMM YYYY')}</h5>
169
164
  </div>
170
165
  <div className="flex flex-column justify-center">
171
166
  <div className="flex gap-2">
172
167
  <h5>
173
- User ID: <strong>{userId}</strong>
168
+ User ID:
169
+ {' '}
170
+ <strong>{userId}</strong>
174
171
  </h5>
175
172
  <h5>
176
- Account ID: <strong>{accountId}</strong>
173
+ Account ID:
174
+ {' '}
175
+ <strong>{accountId}</strong>
177
176
  </h5>
178
177
  <h5>
179
- Document ID: <strong>{documentId}</strong>
178
+ Document ID:
179
+ {' '}
180
+ <strong>{documentId}</strong>
180
181
  </h5>
181
182
  <h5>
182
- Download ID: <strong>{downloadId}</strong>
183
+ Download ID:
184
+ {' '}
185
+ <strong>{downloadId}</strong>
183
186
  </h5>
184
187
  </div>
185
188
  </div>
@@ -187,7 +190,7 @@ export default function PdfView({
187
190
  <h5>{page}</h5>
188
191
  </div>
189
192
  </div>
190
- </div>
193
+ </>
191
194
  ))}
192
195
  </div>
193
196
  );
@@ -201,5 +204,4 @@ PdfView.propTypes = {
201
204
  userId: PropTypes.string,
202
205
  accountId: PropTypes.string,
203
206
  documentId: PropTypes.string,
204
- downloadId: PropTypes.string,
205
- };
207
+ }