@quillsql/react 2.10.28 → 2.10.29
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/dist/cjs/Chart.js +5 -4
- package/dist/cjs/Dashboard.d.ts +3 -1
- package/dist/cjs/Dashboard.d.ts.map +1 -1
- package/dist/cjs/Dashboard.js +3 -10
- package/dist/cjs/ReportBuilder.d.ts.map +1 -1
- package/dist/cjs/ReportBuilder.js +1 -5
- package/dist/cjs/SQLEditor.d.ts +1 -5
- package/dist/cjs/SQLEditor.d.ts.map +1 -1
- package/dist/cjs/SQLEditor.js +5 -10
- package/dist/cjs/components/Chart/ChartSkeleton.d.ts +4 -1
- package/dist/cjs/components/Chart/ChartSkeleton.d.ts.map +1 -1
- package/dist/cjs/components/Dashboard/DataLoader.d.ts +1 -1
- package/dist/cjs/components/Dashboard/DataLoader.d.ts.map +1 -1
- package/dist/cjs/components/Dashboard/DataLoader.js +7 -2
- package/dist/cjs/components/Dashboard/TableComponent.d.ts +1 -1
- package/dist/cjs/components/Dashboard/TableComponent.d.ts.map +1 -1
- package/dist/cjs/components/Dashboard/TableComponent.js +28 -57
- package/dist/cjs/components/QuillTable.d.ts +3 -0
- package/dist/cjs/components/QuillTable.d.ts.map +1 -0
- package/dist/cjs/{Table.js → components/QuillTable.js} +53 -206
- package/dist/cjs/components/UiComponents.d.ts +8 -2
- package/dist/cjs/components/UiComponents.d.ts.map +1 -1
- package/dist/cjs/components/UiComponents.js +3 -1
- package/dist/cjs/hooks/useFormat.d.ts +3 -1
- package/dist/cjs/hooks/useFormat.d.ts.map +1 -1
- package/dist/cjs/hooks/useFormat.js +13 -12
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +3 -3
- package/dist/cjs/utils/valueFormatter.d.ts +5 -0
- package/dist/cjs/utils/valueFormatter.d.ts.map +1 -1
- package/dist/cjs/utils/valueFormatter.js +59 -30
- package/dist/esm/Chart.js +5 -4
- package/dist/esm/Dashboard.d.ts +3 -1
- package/dist/esm/Dashboard.d.ts.map +1 -1
- package/dist/esm/Dashboard.js +3 -10
- package/dist/esm/ReportBuilder.d.ts.map +1 -1
- package/dist/esm/ReportBuilder.js +1 -5
- package/dist/esm/SQLEditor.d.ts +1 -5
- package/dist/esm/SQLEditor.d.ts.map +1 -1
- package/dist/esm/SQLEditor.js +5 -10
- package/dist/esm/components/Chart/ChartSkeleton.d.ts +4 -1
- package/dist/esm/components/Chart/ChartSkeleton.d.ts.map +1 -1
- package/dist/esm/components/Dashboard/DataLoader.d.ts +1 -1
- package/dist/esm/components/Dashboard/DataLoader.d.ts.map +1 -1
- package/dist/esm/components/Dashboard/DataLoader.js +9 -4
- package/dist/esm/components/Dashboard/TableComponent.d.ts +1 -1
- package/dist/esm/components/Dashboard/TableComponent.d.ts.map +1 -1
- package/dist/esm/components/Dashboard/TableComponent.js +25 -57
- package/dist/esm/components/QuillTable.d.ts +3 -0
- package/dist/esm/components/QuillTable.d.ts.map +1 -0
- package/dist/esm/{Table.js → components/QuillTable.js} +52 -204
- package/dist/esm/components/UiComponents.d.ts +8 -2
- package/dist/esm/components/UiComponents.d.ts.map +1 -1
- package/dist/esm/components/UiComponents.js +1 -0
- package/dist/esm/hooks/useFormat.d.ts +3 -1
- package/dist/esm/hooks/useFormat.d.ts.map +1 -1
- package/dist/esm/hooks/useFormat.js +13 -12
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/utils/valueFormatter.d.ts +5 -0
- package/dist/esm/utils/valueFormatter.d.ts.map +1 -1
- package/dist/esm/utils/valueFormatter.js +57 -29
- package/package.json +1 -1
- package/dist/cjs/Table.d.ts +0 -39
- package/dist/cjs/Table.d.ts.map +0 -1
- package/dist/esm/Table.d.ts +0 -39
- package/dist/esm/Table.d.ts.map +0 -1
|
@@ -1,62 +1,38 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import { mergeComparisonRange } from './utils/merge';
|
|
9
|
-
import { useExport } from './hooks/useExport';
|
|
10
|
-
const Table = ({ chartId, columns, rows, containerStyle, csvFilename, showDownloadCsvButton, LoadingComponent, loading, height, }) => {
|
|
11
|
-
const { dispatch, dashboard } = useContext(DashboardContext);
|
|
12
|
-
const { dashboardFilters } = useContext(DashboardFiltersContext);
|
|
13
|
-
const [client, _] = useContext(ClientContext);
|
|
14
|
-
const [theme] = useContext(ThemeContext);
|
|
15
|
-
if (!chartId && rows && columns) {
|
|
16
|
-
return (_jsx(SpecialTable, { showDownloadCsvButton: showDownloadCsvButton, csvFilename: csvFilename || 'table', columns: columns, rows: rows ?? [], height: containerStyle?.height || height || '100%', theme: theme, containerStyle: containerStyle, LoadingComponent: LoadingComponent, loading: loading }));
|
|
17
|
-
}
|
|
18
|
-
return (_jsx(ChartUpdater, { showDownloadCsvButton: showDownloadCsvButton, dispatch: dispatch, dashboard: dashboard, chartId: chartId, containerStyle: containerStyle, dashboardFilters: dashboardFilters, client: client, theme: theme, csvFilename: csvFilename, LoadingComponent: LoadingComponent }));
|
|
19
|
-
};
|
|
20
|
-
const compareValues = (a, b, column) => {
|
|
21
|
-
const valueA = a[column];
|
|
22
|
-
const valueB = b[column];
|
|
23
|
-
// Null checks
|
|
24
|
-
if (valueA === null && valueB === null) {
|
|
25
|
-
return 0; // Both values are null, consider them equal
|
|
26
|
-
}
|
|
27
|
-
else if (valueA === null) {
|
|
28
|
-
return -1; // ValueA is null, consider it smaller
|
|
29
|
-
}
|
|
30
|
-
else if (valueB === null) {
|
|
31
|
-
return 1; // ValueB is null, consider it smaller
|
|
32
|
-
}
|
|
33
|
-
// For numbers
|
|
34
|
-
if (!isNaN(valueA) && !isNaN(valueB)) {
|
|
35
|
-
return valueA - valueB;
|
|
36
|
-
}
|
|
37
|
-
// For dates
|
|
38
|
-
if (new Date(valueA) !== 'Invalid Date' &&
|
|
39
|
-
!isNaN(new Date(valueA)) &&
|
|
40
|
-
new Date(valueB) !== 'Invalid Date' &&
|
|
41
|
-
!isNaN(new Date(valueB))) {
|
|
42
|
-
return new Date(valueA) - new Date(valueB);
|
|
43
|
-
}
|
|
44
|
-
// For strings
|
|
45
|
-
return valueA.localeCompare(valueB);
|
|
46
|
-
};
|
|
47
|
-
export function SpecialTable({ columns, rows, height, containerStyle, loading, LoadingComponent, theme, showDownloadCsvButton = true, csvFilename, DownloadCSVButtonComponent, AddToDashboardButtonComponent, }) {
|
|
2
|
+
import { useContext, useEffect, useState, useMemo } from 'react';
|
|
3
|
+
import { LoadingSpinner } from './UiComponents';
|
|
4
|
+
import { useExport } from '../hooks/useExport';
|
|
5
|
+
import { compareValues, quillFormat } from '../utils/valueFormatter';
|
|
6
|
+
import { ThemeContext } from '../Context';
|
|
7
|
+
export default function QuillTable({ rows, columns, loading, showDownloadCSVButton, downloadFileName, containerStyle, LoadingComponent = () => _jsx(LoadingSpinner, {}), }) {
|
|
48
8
|
const [activeRows, setActiveRows] = useState([]);
|
|
49
9
|
const [page, setPage] = useState(1);
|
|
50
10
|
const [maxPage, setMaxPage] = useState(1);
|
|
51
11
|
const [sortColumn, setSortColumn] = useState(null);
|
|
52
12
|
const [sortDirection, setSortDirection] = useState('desc');
|
|
13
|
+
const [theme] = useContext(ThemeContext);
|
|
14
|
+
const [isFormatting, setIsFormatting] = useState(false);
|
|
15
|
+
const formattedRows = useMemo(() => {
|
|
16
|
+
setIsFormatting(true);
|
|
17
|
+
return rows.map((row) => {
|
|
18
|
+
return columns.reduce((formattedRow, column) => {
|
|
19
|
+
// Apply the format function to each field in the row
|
|
20
|
+
const formattedValue = quillFormat({
|
|
21
|
+
value: row[column.field],
|
|
22
|
+
format: column.format,
|
|
23
|
+
});
|
|
24
|
+
formattedRow[column.field] = formattedValue;
|
|
25
|
+
return formattedRow;
|
|
26
|
+
}, {});
|
|
27
|
+
});
|
|
28
|
+
}, [rows]);
|
|
53
29
|
const { downloadCSV } = useExport({
|
|
54
|
-
rows,
|
|
30
|
+
rows: formattedRows,
|
|
55
31
|
fields: columns,
|
|
56
|
-
name:
|
|
32
|
+
name: downloadFileName,
|
|
57
33
|
});
|
|
58
34
|
useEffect(() => {
|
|
59
|
-
const sortedRows = [...
|
|
35
|
+
const sortedRows = [...formattedRows];
|
|
60
36
|
if (sortColumn) {
|
|
61
37
|
sortedRows.sort((a, b) => {
|
|
62
38
|
const result = compareValues(a, b, sortColumn);
|
|
@@ -69,7 +45,8 @@ export function SpecialTable({ columns, rows, height, containerStyle, loading, L
|
|
|
69
45
|
setMaxPage(Math.ceil(sortedRows.length / 10));
|
|
70
46
|
}
|
|
71
47
|
setActiveRows(sortedRows.slice(start, end));
|
|
72
|
-
|
|
48
|
+
setIsFormatting(false);
|
|
49
|
+
}, [page, formattedRows, sortColumn, sortDirection]);
|
|
73
50
|
const increasePage = () => {
|
|
74
51
|
if (page === maxPage) {
|
|
75
52
|
return;
|
|
@@ -91,70 +68,40 @@ export function SpecialTable({ columns, rows, height, containerStyle, loading, L
|
|
|
91
68
|
setSortDirection('desc');
|
|
92
69
|
}
|
|
93
70
|
};
|
|
94
|
-
if (loading) {
|
|
71
|
+
if (loading || isFormatting) {
|
|
95
72
|
return (_jsx("div", { style: {
|
|
96
|
-
|
|
97
|
-
// paddingLeft: 25,
|
|
98
|
-
// paddingRight: 25,
|
|
99
|
-
// borderRadius: 8,
|
|
100
|
-
// marginTop: 25,
|
|
101
|
-
// overflow: 'visible',
|
|
73
|
+
height: '100%',
|
|
102
74
|
width: '100%',
|
|
103
|
-
height: height || '100%',
|
|
104
75
|
display: 'flex',
|
|
105
76
|
flexDirection: 'column',
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}, children:
|
|
110
|
-
height: '100%',
|
|
111
|
-
overflow: 'auto',
|
|
112
|
-
borderRadius: 6,
|
|
113
|
-
border: '1px solid rgb(229, 231, 235)',
|
|
114
|
-
padding: 0,
|
|
115
|
-
margin: 0,
|
|
116
|
-
// border: 'none',
|
|
117
|
-
boxSizing: 'border-box',
|
|
118
|
-
outline: 'none',
|
|
119
|
-
display: 'flex',
|
|
120
|
-
flexDirection: 'column',
|
|
121
|
-
justifyContent: 'center',
|
|
122
|
-
alignItems: 'center',
|
|
123
|
-
// maxHeight: 600,
|
|
124
|
-
}, children: [LoadingComponent && _jsx(LoadingComponent, {}), !LoadingComponent && (_jsxs("svg", { width: "24", height: "24", children: [_jsx("circle", { cx: "12", cy: "12", r: "9.375", strokeWidth: "3.75", strokeDasharray: "calc(2 * 3.14 * 9.375 / 3) calc(2 * 3.14 * 9.375 * 2 / 3)", strokeDashoffset: "calc(2 * 3.14 * 9.375 / 6)", stroke: theme?.primaryTextColor || '#364153', fill: "none", transform: "rotate(-90 12 12)", children: _jsx("animateTransform", { attributeName: "transform", attributeType: "XML", type: "rotate", from: "-180 12 12", to: "180 12 12", dur: "0.8s", repeatCount: "indefinite" }) }), _jsx("circle", { cx: "12", cy: "12", r: "9.375", strokeWidth: "3.75", strokeDasharray: "calc(2 * 3.14 * 9.375 / 3) calc(2 * 3.14 * 9.375 * 1 / 3)", strokeDashoffset: "calc(2 * 3.14 * 9.375 / 3) calc(2 * 3.14 * 9.375 * 2 / 3)", stroke: '#ADB1B9', fill: "none", transform: "rotate(90 12 12)", children: _jsx("animateTransform", { attributeName: "transform", attributeType: "XML", type: "rotate", from: "0 12 12", to: "360 12 12", dur: "0.8s", repeatCount: "indefinite" }) })] }))] }) }));
|
|
77
|
+
justifyContent: 'center',
|
|
78
|
+
alignItems: 'center',
|
|
79
|
+
...containerStyle,
|
|
80
|
+
}, children: _jsx(LoadingComponent, {}) }));
|
|
125
81
|
}
|
|
126
82
|
return (_jsxs("div", { style: {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
// paddingRight: 25,
|
|
130
|
-
// borderRadius: 8,
|
|
131
|
-
// marginTop: 25,
|
|
83
|
+
width: '100%',
|
|
84
|
+
height: '100%',
|
|
132
85
|
overflow: 'visible',
|
|
133
|
-
height: height,
|
|
134
86
|
display: 'flex',
|
|
135
87
|
flexDirection: 'column',
|
|
136
|
-
|
|
137
|
-
// @ts-ignore
|
|
138
|
-
// boxShadow: 'rgba(231, 231, 231, 0.5) 0px 1px 2px 0px',
|
|
88
|
+
...containerStyle,
|
|
139
89
|
}, children: [_jsx("div", { style: {
|
|
140
90
|
height: '100%',
|
|
91
|
+
width: '100%',
|
|
141
92
|
overflow: 'auto',
|
|
142
93
|
borderRadius: 6,
|
|
143
94
|
border: '1px solid rgb(229, 231, 235)',
|
|
144
95
|
padding: 0,
|
|
145
96
|
margin: 0,
|
|
146
|
-
// border: 'none',
|
|
147
97
|
boxSizing: 'border-box',
|
|
148
98
|
outline: 'none',
|
|
149
|
-
// maxHeight: 600,
|
|
150
99
|
}, children: _jsxs("div", { role: "table", className: "table", style: { minWidth: '0px', width: '100%', height: '100%' }, children: [_jsx("div", { className: "thead", children: _jsx("div", { role: "row", className: "tr", style: {
|
|
151
100
|
display: 'flex',
|
|
152
101
|
flex: '1 0 auto',
|
|
153
102
|
minWidth: '100px',
|
|
154
103
|
boxSizing: 'border-box',
|
|
155
|
-
}, children: columns.map((column, index) => (_jsxs("div", { onClick: () => toggleSort(column),
|
|
156
|
-
// @ts-ignore
|
|
157
|
-
style: {
|
|
104
|
+
}, children: columns.map((column, index) => (_jsxs("div", { onClick: () => toggleSort(column), style: {
|
|
158
105
|
boxSizing: 'border-box',
|
|
159
106
|
flex: '150 0 auto',
|
|
160
107
|
minWidth: '50px',
|
|
@@ -178,9 +125,7 @@ export function SpecialTable({ columns, rows, height, containerStyle, loading, L
|
|
|
178
125
|
display: 'flex',
|
|
179
126
|
flexDirection: 'row',
|
|
180
127
|
justifyContent: 'space-between',
|
|
181
|
-
}, children: [_jsx("div", { "aria-haspopup": "dialog", "aria-expanded": "false", "aria-controls": "mantine-r6-dropdown",
|
|
182
|
-
// @ts-ignore
|
|
183
|
-
style: {
|
|
128
|
+
}, children: [_jsx("div", { "aria-haspopup": "dialog", "aria-expanded": "false", "aria-controls": "mantine-r6-dropdown", style: {
|
|
184
129
|
// fontFamily:
|
|
185
130
|
// 'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji"',
|
|
186
131
|
WebkitTapHighlightColor: 'transparent',
|
|
@@ -198,7 +143,16 @@ export function SpecialTable({ columns, rows, height, containerStyle, loading, L
|
|
|
198
143
|
transform: sortDirection === 'desc'
|
|
199
144
|
? 'rotate(180deg)'
|
|
200
145
|
: undefined,
|
|
201
|
-
}, children: _jsx("path", { fillRule: "evenodd", d: "M10 3a.75.75 0 01.75.75v10.638l3.96-4.158a.75.75 0 111.08 1.04l-5.25 5.5a.75.75 0 01-1.08 0l-5.25-5.5a.75.75 0 111.08-1.04l3.96 4.158V3.75A.75.75 0 0110 3z", clipRule: "evenodd" }) }))] }, 'sqlcol' + index))) }) }),
|
|
146
|
+
}, children: _jsx("path", { fillRule: "evenodd", d: "M10 3a.75.75 0 01.75.75v10.638l3.96-4.158a.75.75 0 111.08 1.04l-5.25 5.5a.75.75 0 01-1.08 0l-5.25-5.5a.75.75 0 111.08-1.04l3.96 4.158V3.75A.75.75 0 0110 3z", clipRule: "evenodd" }) }))] }, 'sqlcol' + index))) }) }), activeRows.length === 0 || columns.length === 0 ? (_jsx("div", { style: {
|
|
147
|
+
paddingTop: '60px',
|
|
148
|
+
display: 'flex',
|
|
149
|
+
flex: '1 0 auto',
|
|
150
|
+
margin: 'auto',
|
|
151
|
+
justifyContent: 'center',
|
|
152
|
+
alignItems: 'center',
|
|
153
|
+
fontSize: 13,
|
|
154
|
+
color: theme?.secondaryTextColor || 'rgb(55, 65, 81)',
|
|
155
|
+
}, children: "No results returned." })) : (_jsx("div", { role: "rowgroup", className: "tbody", children: activeRows.map((row, rowIndex) => (_jsx("div", { role: "row", className: "tr", style: {
|
|
202
156
|
display: 'flex',
|
|
203
157
|
flex: '1 0 auto',
|
|
204
158
|
minWidth: '100px',
|
|
@@ -245,28 +199,7 @@ export function SpecialTable({ columns, rows, height, containerStyle, loading, L
|
|
|
245
199
|
overflow: 'hidden',
|
|
246
200
|
padding: '8px 16px',
|
|
247
201
|
userSelect: 'none',
|
|
248
|
-
}, children: column.
|
|
249
|
-
? valueFormatter({
|
|
250
|
-
value: row[column.field],
|
|
251
|
-
field: column.field,
|
|
252
|
-
fields: columns,
|
|
253
|
-
})
|
|
254
|
-
: typeof row[column.field] === 'object'
|
|
255
|
-
? JSON.stringify(row[column.field]).length > 55
|
|
256
|
-
? JSON.stringify(row[column.field]).substring(0, 52) + '...'
|
|
257
|
-
: JSON.stringify(row[column.field])
|
|
258
|
-
: row[column.field].length > 55
|
|
259
|
-
? row[column.field].substring(0, 52) + '...'
|
|
260
|
-
: row[column.field] }) }) }, 'sqlcell' + columnIndex))) }, 'sqlrow' + rowIndex))) }), (activeRows.length === 0 || !columns.length === 0) && (_jsx("div", { style: {
|
|
261
|
-
paddingTop: '60px',
|
|
262
|
-
display: 'flex',
|
|
263
|
-
flex: '1 0 auto',
|
|
264
|
-
margin: 'auto',
|
|
265
|
-
justifyContent: 'center',
|
|
266
|
-
alignItems: 'center',
|
|
267
|
-
fontSize: 13,
|
|
268
|
-
color: theme?.secondaryTextColor || 'rgb(55, 65, 81)',
|
|
269
|
-
}, children: "No results found for specified time period." }))] }) }), _jsx("div", { style: { position: 'relative' }, children: _jsx("div", { style: {
|
|
202
|
+
}, children: row[column.field] }) }) }, 'sqlcell' + columnIndex))) }, 'sqlrow' + rowIndex))) }))] }) }), _jsx("div", { style: { position: 'relative' }, children: _jsx("div", { style: {
|
|
270
203
|
display: 'flex',
|
|
271
204
|
flex: '1 0 auto',
|
|
272
205
|
minWidth: '100px',
|
|
@@ -290,7 +223,7 @@ export function SpecialTable({ columns, rows, height, containerStyle, loading, L
|
|
|
290
223
|
alignItems: 'center',
|
|
291
224
|
justifyContent: 'space-between',
|
|
292
225
|
width: '100%',
|
|
293
|
-
}, children: [_jsx("button", { onClick:
|
|
226
|
+
}, children: [showDownloadCSVButton ? (_jsx("button", { onClick: downloadCSV, style: {
|
|
294
227
|
fontSize: 14,
|
|
295
228
|
paddingLeft: 12,
|
|
296
229
|
fontFamily: theme?.fontFamily,
|
|
@@ -299,7 +232,7 @@ export function SpecialTable({ columns, rows, height, containerStyle, loading, L
|
|
|
299
232
|
fontWeight: 500,
|
|
300
233
|
cursor: 'pointer',
|
|
301
234
|
border: 'none',
|
|
302
|
-
}, children:
|
|
235
|
+
}, children: "Download CSV" })) : (_jsx("div", {})), _jsxs("div", { style: {
|
|
303
236
|
display: 'flex',
|
|
304
237
|
flexDirection: 'row',
|
|
305
238
|
alignItems: 'center',
|
|
@@ -317,88 +250,3 @@ export function SpecialTable({ columns, rows, height, containerStyle, loading, L
|
|
|
317
250
|
background: 'transparent',
|
|
318
251
|
}, children: _jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 20 20", fill: theme?.chartLabelFontFamily || theme?.fontFamily, height: "16px", width: "16px", children: _jsx("path", { fillRule: "evenodd", d: "M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z", clipRule: "evenodd" }) }) }), _jsx("div", { style: { width: 12 } })] })] }) }) })] }));
|
|
319
252
|
}
|
|
320
|
-
const ChartUpdater = ({ chartId, containerStyle, dashboard, dispatch, client, dashboardFilters, theme, downloadCSV, csvFilename, showDownloadCsvButton = true, LoadingComponent, }) => {
|
|
321
|
-
const [chartConfig, setChartConfig] = useState(null);
|
|
322
|
-
const [loading, setLoading] = useState(true);
|
|
323
|
-
useEffect(() => {
|
|
324
|
-
let isSubscribed = true;
|
|
325
|
-
async function getChartOptions() {
|
|
326
|
-
if (isSubscribed) {
|
|
327
|
-
setLoading(true);
|
|
328
|
-
try {
|
|
329
|
-
const hostedBody = { metadata: {
|
|
330
|
-
dashboardItemId: chartId,
|
|
331
|
-
orgId: client.customerId || '*',
|
|
332
|
-
task: 'item',
|
|
333
|
-
filters: [...Object.values(dashboardFilters)],
|
|
334
|
-
clientId: client.publicKey,
|
|
335
|
-
databaseType: client?.databaseType,
|
|
336
|
-
} };
|
|
337
|
-
const cloudBody = {
|
|
338
|
-
id: chartId,
|
|
339
|
-
filters: [...Object.values(dashboardFilters)],
|
|
340
|
-
};
|
|
341
|
-
const resp = await getData(client, 'itempost', 'omit', hostedBody, cloudBody);
|
|
342
|
-
if (resp && resp.name !== 'error') {
|
|
343
|
-
if (resp.compareRows) {
|
|
344
|
-
mergeComparisonRange(resp);
|
|
345
|
-
}
|
|
346
|
-
dispatch({
|
|
347
|
-
type: 'UPDATE_DASHBOARD_ITEM',
|
|
348
|
-
id: chartId,
|
|
349
|
-
data: {
|
|
350
|
-
...resp,
|
|
351
|
-
filtersApplied: dashboardFilters,
|
|
352
|
-
},
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
setLoading(false);
|
|
356
|
-
}
|
|
357
|
-
catch (e) {
|
|
358
|
-
console.log('Error fetching chart: ', e);
|
|
359
|
-
setLoading(false);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
getChartOptions();
|
|
364
|
-
return () => {
|
|
365
|
-
isSubscribed = false;
|
|
366
|
-
};
|
|
367
|
-
}, [dashboardFilters, client.customerId, chartId]);
|
|
368
|
-
// const dateFilter = Object.values(dashboardFilters).find(
|
|
369
|
-
// (filter) => filter.filterType == 'date_range',
|
|
370
|
-
// );
|
|
371
|
-
// const pivotTable = useMemo(() => {
|
|
372
|
-
// const pivot = dashboard[chartId]?.pivot;
|
|
373
|
-
// const data = dashboard[chartId];
|
|
374
|
-
// return pivot && data?.rows
|
|
375
|
-
// ? generatePivotTable(
|
|
376
|
-
// pivot,
|
|
377
|
-
// data.rows,
|
|
378
|
-
// dateFilter?.startDate
|
|
379
|
-
// ? [dateFilter?.startDate, dateFilter?.endDate, null]
|
|
380
|
-
// : [null, null, null],
|
|
381
|
-
// )
|
|
382
|
-
// : null;
|
|
383
|
-
// }, [dashboard, chartId, dateFilter]);
|
|
384
|
-
if (!dashboard[chartId] || loading) {
|
|
385
|
-
return (_jsx("div", {
|
|
386
|
-
// className="flex flex-col flex-1 h-[100%]"
|
|
387
|
-
style: {
|
|
388
|
-
...containerStyle,
|
|
389
|
-
// marginLeft: 25,
|
|
390
|
-
// marginRight: 25,
|
|
391
|
-
boxSizing: 'content-box',
|
|
392
|
-
height: '100%',
|
|
393
|
-
display: 'flex',
|
|
394
|
-
flexDirection: 'column',
|
|
395
|
-
flex: 1,
|
|
396
|
-
}, children: _jsx("div", { style: {
|
|
397
|
-
height: containerStyle?.height || 300,
|
|
398
|
-
width: '100%',
|
|
399
|
-
boxSizing: 'content-box',
|
|
400
|
-
}, children: _jsxs("svg", { width: "100%", height: "100%", xmlns: "http://www.w3.org/2000/svg", xmlnsXlink: "http://www.w3.org/1999/xlink", children: [_jsx("rect", { width: "100%", height: "100%", fill: "#F9F9FA" }), _jsx("defs", { fill: "#F9F9FA", children: _jsxs("linearGradient", { id: "skeletonGradient", x1: "0%", y1: "0%", x2: "10%", y2: "0%", gradientUnits: "userSpaceOnUse", children: [_jsx("stop", { offset: "0%", stopColor: "rgba(255,255,255,0)" }), _jsx("stop", { offset: "50%", stopColor: "#FEFEFE" }), _jsx("stop", { offset: "100%", stopColor: "rgba(255,255,255,0)" }), _jsx("animate", { attributeName: "x1", from: "-100%", to: "100%", dur: "2s", repeatCount: "indefinite" }), _jsx("animate", { attributeName: "x2", from: "-50%", to: "150%", dur: "2s", repeatCount: "indefinite" })] }) }), _jsx("rect", { width: "50%", height: "100%", fill: "url(#skeletonGradient)", children: _jsx("animate", { attributeName: "x", from: "-100%", to: "100%", dur: "2s", repeatCount: "indefinite" }) })] }) }) }));
|
|
401
|
-
}
|
|
402
|
-
return (_jsx(SpecialTable, { showDownloadCsvButton: showDownloadCsvButton, csvFilename: csvFilename || dashboard[chartId].name, columns: dashboard[chartId].columns, rows: dashboard[chartId].rows ?? [], height: containerStyle?.height || '100%', theme: theme, containerStyle: containerStyle, LoadingComponent: LoadingComponent }));
|
|
403
|
-
};
|
|
404
|
-
export default Table;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
export interface Option {
|
|
3
3
|
value: string;
|
|
4
4
|
label: string;
|
|
@@ -27,9 +27,12 @@ export interface ButtonComponentProps {
|
|
|
27
27
|
export interface TableComponentProps {
|
|
28
28
|
rows: any[];
|
|
29
29
|
columns: any[];
|
|
30
|
-
|
|
30
|
+
containerStyle?: React.CSSProperties;
|
|
31
31
|
loading?: boolean;
|
|
32
|
+
showDownloadCSVButton?: boolean;
|
|
33
|
+
downloadFileName?: string;
|
|
32
34
|
LoadingComponent?: () => JSX.Element;
|
|
35
|
+
DownloadCSVButtonComponent?: (props: ButtonComponentProps) => JSX.Element;
|
|
33
36
|
}
|
|
34
37
|
export interface TextInputComponentProps {
|
|
35
38
|
onChange: (e: any) => void;
|
|
@@ -121,4 +124,7 @@ export declare const MemoizedDeleteButton: ({ onClick, style }: {
|
|
|
121
124
|
onClick: any;
|
|
122
125
|
style: any;
|
|
123
126
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
127
|
+
export declare const LoadingSpinner: ({ ...props }: {
|
|
128
|
+
[x: string]: any;
|
|
129
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
124
130
|
//# sourceMappingURL=UiComponents.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UiComponents.d.ts","sourceRoot":"","sources":["../../../src/components/UiComponents.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"UiComponents.d.ts","sourceRoot":"","sources":["../../../src/components/UiComponents.tsx"],"names":[],"mappings":"AACA,OAAO,KAAwC,MAAM,OAAO,CAAC;AAK7D,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,GAAG,CAAC;CACZ;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,OAAO,EAAE,GAAG,EAAE,CAAC;IACf,cAAc,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IACrC,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,gBAAgB,CAAC,EAAE,MAAM,GAAG,CAAC,OAAO,CAAC;IACrC,0BAA0B,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,GAAG,CAAC,OAAO,CAAC;CAC3E;AAED,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,CAAC,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,GAAG,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IACrC,KAAK,CAAC,EAAE,GAAG,CAAC;CACb;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,GAAG,CAAC;CACf;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,GAAG,CAAC;CACf;AAED,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,GAAG,CAAC;CACf;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,KAAK,EAAE,GAAG,CAAC;CACZ;AAED,eAAO,MAAM,iBAAiB;;;;;6CAgC7B,CAAC;AAEF,eAAO,MAAM,cAAc;;;;6CAgC1B,CAAC;AAEF,eAAO,MAAM,uBAAuB;;;6CA6BnC,CAAC;AAEF,eAAO,MAAM,cAAc;;;;;;6CA4D1B,CAAC;AAEF,eAAO,MAAM,cAAc;;6CAa1B,CAAC;AAEF,eAAO,MAAM,aAAa;;6CAYzB,CAAC;AAEF,eAAO,MAAM,YAAY;;6CAYxB,CAAC;AAsBF,MAAM,WAAW,qBAAqB;IACpC,QAAQ,EAAE,GAAG,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,SAAS,CAAC,EAAE,GAAG,CAAC;IAChB,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;CACtC;AAED,wBAAgB,eAAe,CAAC,EAC9B,OAAO,EACP,SAAS,EACT,QAAQ,EACR,KAAU,EACV,OAAO,EACP,KAAK,EACL,WAAkB,EAClB,MAAM,EACN,SAAS,GACV;;;;;;;;;;CAAA,2CA4DA;AAED,wBAAgB,aAAa,CAAC,EAC5B,MAAM,EACN,OAAO,EACP,SAAS,EACT,KAAK,EACL,QAAQ,EACR,KAAK,GACN;;;;;;;CAAA,kDA2FA;AAED,eAAO,MAAM,oBAAoB;;;6CA0BhC,CAAC;AAEF,eAAO,MAAM,cAAc;;6CA6C1B,CAAC"}
|
|
@@ -245,3 +245,4 @@ export const MemoizedDeleteButton = ({ onClick, style }) => (_jsxs("button", { c
|
|
|
245
245
|
.quill-delete-button:hover {
|
|
246
246
|
background-color: rgba(56, 65, 81, 0.03);
|
|
247
247
|
}` }), _jsx(XIcon, { height: "20", width: "20", fill: "#6C727F" })] }));
|
|
248
|
+
export const LoadingSpinner = ({ ...props }) => (_jsxs("svg", { width: "24", height: "24", children: [_jsx("circle", { cx: "12", cy: "12", r: "9.375", strokeWidth: "3.75", strokeDasharray: "calc(2 * 3.14 * 9.375 / 3) calc(2 * 3.14 * 9.375 * 2 / 3)", strokeDashoffset: "calc(2 * 3.14 * 9.375 / 6)", stroke: "#364153", fill: "none", transform: "rotate(-90 12 12)", children: _jsx("animateTransform", { attributeName: "transform", attributeType: "XML", type: "rotate", from: "-180 12 12", to: "180 12 12", dur: "0.8s", repeatCount: "indefinite" }) }), _jsx("circle", { cx: "12", cy: "12", r: "9.375", strokeWidth: "3.75", strokeDasharray: "calc(2 * 3.14 * 9.375 / 3) calc(2 * 3.14 * 9.375 * 1 / 3)", strokeDashoffset: "calc(2 * 3.14 * 9.375 / 3) calc(2 * 3.14 * 9.375 * 2 / 3)", stroke: '#ADB1B9', fill: "none", transform: "rotate(90 12 12)", children: _jsx("animateTransform", { attributeName: "transform", attributeType: "XML", type: "rotate", from: "0 12 12", to: "360 12 12", dur: "0.8s", repeatCount: "indefinite" }) })] }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormat.d.ts","sourceRoot":"","sources":["../../../src/hooks/useFormat.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,eAAe,YAAa,MAAM
|
|
1
|
+
{"version":3,"file":"useFormat.d.ts","sourceRoot":"","sources":["../../../src/hooks/useFormat.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,eAAe,YAAa,MAAM;;;;CAwB9C,CAAC"}
|
|
@@ -3,18 +3,19 @@ import { useQuill } from './useQuill';
|
|
|
3
3
|
import { useMemo } from 'react';
|
|
4
4
|
export const useMemoizedRows = (chartId) => {
|
|
5
5
|
const { data } = useQuill(chartId);
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
});
|
|
6
|
+
if (!data)
|
|
7
|
+
return { formattedRows: [] };
|
|
8
|
+
const { rows, columns } = data;
|
|
9
|
+
const formattedRows = useMemo(() => rows.map((row) => {
|
|
10
|
+
return columns.reduce((formattedRow, column) => {
|
|
11
|
+
// Apply the format function to each field in the row
|
|
12
|
+
const formattedValue = quillFormat({
|
|
13
|
+
value: row[column.field],
|
|
14
|
+
format: column.format,
|
|
16
15
|
});
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
formattedRow[column.field] = formattedValue;
|
|
17
|
+
return formattedRow;
|
|
18
|
+
}, {});
|
|
19
|
+
}), [rows]);
|
|
19
20
|
return { formattedRows };
|
|
20
21
|
};
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { default as Dashboard, type DashboardProps, type DashboardItemProps, type DashboardItem, type AxisFormat, } from './Dashboard';
|
|
2
2
|
export { default as QuillProvider } from './QuillProvider';
|
|
3
3
|
export { default as Chart } from './Chart';
|
|
4
|
-
export { default as
|
|
4
|
+
export { default as QuillTable } from './components/QuillTable';
|
|
5
5
|
export { default as SQLEditor, SchemaListComponent } from './SQLEditor';
|
|
6
6
|
export { default as ReportBuilder } from './ReportBuilder';
|
|
7
7
|
export { default as ChartBuilder } from './ChartBuilder';
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,IAAI,SAAS,EACpB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,UAAU,GAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,OAAO,IAAI,SAAS,EACpB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,UAAU,GAChB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,WAAW,IAAI,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,YAAY,EACV,uBAAuB,EACvB,oBAAoB,EACpB,MAAM,EACN,qBAAqB,EACrB,mBAAmB,EACnB,mBAAmB,EACnB,WAAW,GACZ,MAAM,2BAA2B,CAAC;AACnC,YAAY,EACV,oBAAoB,EACpB,qBAAqB,EACrB,SAAS,GACV,MAAM,mCAAmC,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export { default as Dashboard, } from './Dashboard';
|
|
3
3
|
export { default as QuillProvider } from './QuillProvider';
|
|
4
4
|
export { default as Chart } from './Chart';
|
|
5
|
-
export { default as
|
|
5
|
+
export { default as QuillTable } from './components/QuillTable';
|
|
6
6
|
export { default as SQLEditor, SchemaListComponent } from './SQLEditor';
|
|
7
7
|
export { default as ReportBuilder } from './ReportBuilder';
|
|
8
8
|
export { default as ChartBuilder } from './ChartBuilder';
|
|
@@ -18,5 +18,10 @@ export declare const quillFormat: ({ value, format, }: {
|
|
|
18
18
|
value: any;
|
|
19
19
|
format: string;
|
|
20
20
|
}) => string;
|
|
21
|
+
export declare const compareValues: (a: {
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
}, b: {
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}, column: string) => number;
|
|
21
26
|
export {};
|
|
22
27
|
//# sourceMappingURL=valueFormatter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"valueFormatter.d.ts","sourceRoot":"","sources":["../../../src/utils/valueFormatter.ts"],"names":[],"mappings":"AAGA,KAAK,KAAK,GAAG;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,KAAK,KAAK,GAAG;IACX,KAAK,EAAE,GAAG,CAAC;IACX,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IACjC,MAAM,EAAE,KAAK,EAAE,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,iBAAiB,UAQ7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,6BAA8B,KAAK,KAAG,MAwChE,CAAC;AAEF,eAAO,MAAM,WAAW;WAIf,GAAG;YACF,MAAM;MACZ,
|
|
1
|
+
{"version":3,"file":"valueFormatter.d.ts","sourceRoot":"","sources":["../../../src/utils/valueFormatter.ts"],"names":[],"mappings":"AAGA,KAAK,KAAK,GAAG;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,SAAS,CAAC;CACnB,CAAC;AAEF,KAAK,KAAK,GAAG;IACX,KAAK,EAAE,GAAG,CAAC;IACX,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;IACjC,MAAM,EAAE,KAAK,EAAE,CAAC;CACjB,CAAC;AAEF,eAAO,MAAM,iBAAiB,UAQ7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,6BAA8B,KAAK,KAAG,MAwChE,CAAC;AAEF,eAAO,MAAM,WAAW;WAIf,GAAG;YACF,MAAM;MACZ,MAoCH,CAAC;AAmJF,eAAO,MAAM,aAAa;;;;WAGhB,MAAM,KACb,MA2BF,CAAC"}
|
|
@@ -50,6 +50,8 @@ export const valueFormatter = ({ value, field, fields }) => {
|
|
|
50
50
|
return formatString(value); // by default make this value a string
|
|
51
51
|
};
|
|
52
52
|
export const quillFormat = ({ value, format, }) => {
|
|
53
|
+
if (value === undefined || value === null)
|
|
54
|
+
return '';
|
|
53
55
|
const HANDLERS = {
|
|
54
56
|
percent: formatPercent,
|
|
55
57
|
dollar_amount: formatDollarAmount,
|
|
@@ -68,7 +70,7 @@ export const quillFormat = ({ value, format, }) => {
|
|
|
68
70
|
};
|
|
69
71
|
// try to handle this value using the associated formatType handler
|
|
70
72
|
const formatType = format;
|
|
71
|
-
if (
|
|
73
|
+
if (HANDLERS[formatType]) {
|
|
72
74
|
// if bigquery date type, we have to pull the value out of the json
|
|
73
75
|
if (DATE_FORMAT_TYPES.includes(formatType) &&
|
|
74
76
|
typeof value === 'object' &&
|
|
@@ -96,38 +98,38 @@ const formatString = (value) => {
|
|
|
96
98
|
*
|
|
97
99
|
* eg. @example format(1234.567) => "$1,235"
|
|
98
100
|
*/
|
|
101
|
+
const formatterDollar = new Intl.NumberFormat('en-US', {
|
|
102
|
+
style: 'currency',
|
|
103
|
+
currency: 'USD',
|
|
104
|
+
maximumFractionDigits: 0,
|
|
105
|
+
});
|
|
99
106
|
const formatDollarAmount = (value) => {
|
|
100
|
-
|
|
101
|
-
style: 'currency',
|
|
102
|
-
currency: 'USD',
|
|
103
|
-
maximumFractionDigits: 0,
|
|
104
|
-
});
|
|
105
|
-
return formatter.format(Number(value ?? 0));
|
|
107
|
+
return formatterDollar.format(Number(value ?? 0));
|
|
106
108
|
};
|
|
107
109
|
/**
|
|
108
110
|
* Formats the value as a (rounded) currency amount in dollars and cents.
|
|
109
111
|
*
|
|
110
112
|
* @example format(1234.567) => "$1,234.57"
|
|
111
113
|
*/
|
|
114
|
+
const formatterCentsDollar = new Intl.NumberFormat('en-US', {
|
|
115
|
+
style: 'currency',
|
|
116
|
+
currency: 'USD',
|
|
117
|
+
minimumFractionDigits: 2,
|
|
118
|
+
maximumFractionDigits: 2,
|
|
119
|
+
});
|
|
112
120
|
const formatDollarCents = (value) => {
|
|
113
|
-
|
|
114
|
-
style: 'currency',
|
|
115
|
-
currency: 'USD',
|
|
116
|
-
minimumFractionDigits: 2,
|
|
117
|
-
maximumFractionDigits: 2,
|
|
118
|
-
});
|
|
119
|
-
return formatter.format(Number(value ?? 0));
|
|
121
|
+
return formatterCentsDollar.format(Number(value ?? 0));
|
|
120
122
|
};
|
|
121
123
|
/**
|
|
122
124
|
* Formats the value as a (rounded) integer.
|
|
123
125
|
*
|
|
124
126
|
* @example format(1234.567) => "1,235"
|
|
125
127
|
*/
|
|
128
|
+
const wholeNumberFormatter = new Intl.NumberFormat('en-US', {
|
|
129
|
+
maximumFractionDigits: 0,
|
|
130
|
+
});
|
|
126
131
|
const formatWholeNumber = (value) => {
|
|
127
|
-
|
|
128
|
-
maximumFractionDigits: 0,
|
|
129
|
-
});
|
|
130
|
-
return formatter.format(Number(value));
|
|
132
|
+
return wholeNumberFormatter.format(Number(value));
|
|
131
133
|
};
|
|
132
134
|
/**
|
|
133
135
|
* Formats the value as a number rounded to exactly one decimal place.
|
|
@@ -146,12 +148,12 @@ const formatOneDecimalPlace = (value) => {
|
|
|
146
148
|
*
|
|
147
149
|
* @example format(1234.567) => "1,234.57"
|
|
148
150
|
*/
|
|
151
|
+
const formatterTwoDecimalPlaces = new Intl.NumberFormat('en-US', {
|
|
152
|
+
minimumFractionDigits: 2,
|
|
153
|
+
maximumFractionDigits: 2,
|
|
154
|
+
});
|
|
149
155
|
const formatTwoDecimalPlaces = (value) => {
|
|
150
|
-
|
|
151
|
-
minimumFractionDigits: 2,
|
|
152
|
-
maximumFractionDigits: 2,
|
|
153
|
-
});
|
|
154
|
-
return formatter.format(Number(value));
|
|
156
|
+
return formatterTwoDecimalPlaces.format(Number(value));
|
|
155
157
|
};
|
|
156
158
|
/**
|
|
157
159
|
* Formats the value as a percentage.
|
|
@@ -166,13 +168,13 @@ const formatTwoDecimalPlaces = (value) => {
|
|
|
166
168
|
* @example format(1234.567) => "123,456.70%"
|
|
167
169
|
* @example format(99) => "9,900.00%"
|
|
168
170
|
*/
|
|
171
|
+
const formatterPercent = new Intl.NumberFormat('en-US', {
|
|
172
|
+
style: 'percent',
|
|
173
|
+
minimumFractionDigits: 2,
|
|
174
|
+
maximumFractionDigits: 2,
|
|
175
|
+
});
|
|
169
176
|
const formatPercent = (value) => {
|
|
170
|
-
|
|
171
|
-
style: 'percent',
|
|
172
|
-
minimumFractionDigits: 2,
|
|
173
|
-
maximumFractionDigits: 2,
|
|
174
|
-
});
|
|
175
|
-
return formatter.format(Number(value));
|
|
177
|
+
return formatterPercent.format(Number(value));
|
|
176
178
|
};
|
|
177
179
|
// Converts the value to a UTC date with the given format string. If the
|
|
178
180
|
// resulting date is invalid, it returns "Invalid date".
|
|
@@ -216,3 +218,29 @@ const format_wo_yyyy = (value) => {
|
|
|
216
218
|
return 'Invalid date';
|
|
217
219
|
return `${getWeek(utcDate)},${utcDate.getFullYear()}`;
|
|
218
220
|
};
|
|
221
|
+
export const compareValues = (a, b, column) => {
|
|
222
|
+
const valueA = a[column];
|
|
223
|
+
const valueB = b[column];
|
|
224
|
+
// Null checks
|
|
225
|
+
if (valueA === null && valueB === null) {
|
|
226
|
+
return 0; // Both values are null, consider them equal
|
|
227
|
+
}
|
|
228
|
+
else if (valueA === null) {
|
|
229
|
+
return -1; // ValueA is null, consider it smaller
|
|
230
|
+
}
|
|
231
|
+
else if (valueB === null) {
|
|
232
|
+
return 1; // ValueB is null, consider it smaller
|
|
233
|
+
}
|
|
234
|
+
// For numbers
|
|
235
|
+
if (!isNaN(valueA) && !isNaN(valueB)) {
|
|
236
|
+
return valueA - valueB;
|
|
237
|
+
}
|
|
238
|
+
// For dates
|
|
239
|
+
const dateA = new Date(valueA);
|
|
240
|
+
const dateB = new Date(valueB);
|
|
241
|
+
if (!isNaN(dateA.getTime()) && !isNaN(dateB.getTime())) {
|
|
242
|
+
return dateA.getTime() - dateB.getTime();
|
|
243
|
+
}
|
|
244
|
+
// For strings
|
|
245
|
+
return valueA.localeCompare(valueB);
|
|
246
|
+
};
|