@quillsql/react 2.13.18 → 2.13.20
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.d.ts +3 -3
- package/dist/cjs/Chart.d.ts.map +1 -1
- package/dist/cjs/Chart.js +83 -187
- package/dist/cjs/ChartBuilder.d.ts.map +1 -1
- package/dist/cjs/ChartBuilder.js +3 -5
- package/dist/cjs/Context.d.ts +24 -3
- package/dist/cjs/Context.d.ts.map +1 -1
- package/dist/cjs/Context.js +316 -7
- package/dist/cjs/Dashboard.js +1 -1
- package/dist/cjs/ReportBuilder.d.ts.map +1 -1
- package/dist/cjs/ReportBuilder.js +0 -2
- package/dist/cjs/SQLEditor.d.ts.map +1 -1
- package/dist/cjs/SQLEditor.js +1 -4
- package/dist/cjs/Table.d.ts.map +1 -1
- package/dist/cjs/Table.js +34 -32
- package/dist/cjs/components/Dashboard/DashboardFilter.js +1 -1
- package/dist/cjs/components/Dashboard/DataLoader.d.ts +4 -2
- package/dist/cjs/components/Dashboard/DataLoader.d.ts.map +1 -1
- package/dist/cjs/components/Dashboard/DataLoader.js +136 -57
- package/dist/cjs/hooks/useDashboard.d.ts.map +1 -1
- package/dist/cjs/hooks/useDashboard.js +2 -49
- package/dist/cjs/hooks/useQuill.d.ts.map +1 -1
- package/dist/cjs/hooks/useQuill.js +64 -42
- package/dist/cjs/internals/ReportBuilder/PivotModal.d.ts +1 -1
- package/dist/cjs/internals/ReportBuilder/PivotModal.d.ts.map +1 -1
- package/dist/cjs/internals/ReportBuilder/PivotModal.js +0 -1
- package/dist/cjs/models/Report.d.ts +4 -3
- package/dist/cjs/models/Report.d.ts.map +1 -1
- package/dist/cjs/utils/columnProcessing.d.ts +2 -1
- package/dist/cjs/utils/columnProcessing.d.ts.map +1 -1
- package/dist/cjs/utils/columnProcessing.js +2 -2
- package/dist/cjs/utils/dataProcessing.js +2 -2
- package/dist/cjs/utils/filterProcessing.d.ts +6 -1
- package/dist/cjs/utils/filterProcessing.d.ts.map +1 -1
- package/dist/cjs/utils/filterProcessing.js +81 -3
- package/dist/cjs/utils/pivotConstructor.js +1 -1
- package/dist/cjs/utils/queryConstructor.d.ts.map +1 -1
- package/dist/cjs/utils/queryConstructor.js +0 -1
- package/dist/cjs/utils/report.d.ts +13 -1
- package/dist/cjs/utils/report.d.ts.map +1 -1
- package/dist/cjs/utils/report.js +79 -51
- package/dist/esm/Chart.d.ts +3 -3
- package/dist/esm/Chart.d.ts.map +1 -1
- package/dist/esm/Chart.js +88 -196
- package/dist/esm/ChartBuilder.d.ts.map +1 -1
- package/dist/esm/ChartBuilder.js +3 -5
- package/dist/esm/Context.d.ts +24 -3
- package/dist/esm/Context.d.ts.map +1 -1
- package/dist/esm/Context.js +315 -6
- package/dist/esm/Dashboard.js +1 -1
- package/dist/esm/ReportBuilder.d.ts.map +1 -1
- package/dist/esm/ReportBuilder.js +0 -2
- package/dist/esm/SQLEditor.d.ts.map +1 -1
- package/dist/esm/SQLEditor.js +1 -4
- package/dist/esm/Table.d.ts.map +1 -1
- package/dist/esm/Table.js +34 -32
- package/dist/esm/components/Dashboard/DashboardFilter.js +1 -1
- package/dist/esm/components/Dashboard/DataLoader.d.ts +4 -2
- package/dist/esm/components/Dashboard/DataLoader.d.ts.map +1 -1
- package/dist/esm/components/Dashboard/DataLoader.js +137 -58
- package/dist/esm/hooks/useDashboard.d.ts.map +1 -1
- package/dist/esm/hooks/useDashboard.js +3 -50
- package/dist/esm/hooks/useQuill.d.ts.map +1 -1
- package/dist/esm/hooks/useQuill.js +66 -44
- package/dist/esm/internals/ReportBuilder/PivotModal.d.ts +1 -1
- package/dist/esm/internals/ReportBuilder/PivotModal.d.ts.map +1 -1
- package/dist/esm/internals/ReportBuilder/PivotModal.js +0 -1
- package/dist/esm/models/Report.d.ts +4 -3
- package/dist/esm/models/Report.d.ts.map +1 -1
- package/dist/esm/utils/columnProcessing.d.ts +2 -1
- package/dist/esm/utils/columnProcessing.d.ts.map +1 -1
- package/dist/esm/utils/columnProcessing.js +2 -2
- package/dist/esm/utils/dataProcessing.js +2 -2
- package/dist/esm/utils/filterProcessing.d.ts +6 -1
- package/dist/esm/utils/filterProcessing.d.ts.map +1 -1
- package/dist/esm/utils/filterProcessing.js +78 -2
- package/dist/esm/utils/pivotConstructor.js +1 -1
- package/dist/esm/utils/queryConstructor.d.ts.map +1 -1
- package/dist/esm/utils/queryConstructor.js +0 -1
- package/dist/esm/utils/report.d.ts +13 -1
- package/dist/esm/utils/report.d.ts.map +1 -1
- package/dist/esm/utils/report.js +77 -51
- package/package.json +1 -1
|
@@ -14,11 +14,12 @@ export type DataLoaderChildProps = {
|
|
|
14
14
|
rowCount?: number;
|
|
15
15
|
rowCountIsLoading?: boolean;
|
|
16
16
|
};
|
|
17
|
-
export default function DataLoader({ item, children, filters, userFilters, additionalProcessing: defaultAdditionalProcessing, }: {
|
|
17
|
+
export default function DataLoader({ item, children, filters, userFilters, additionalProcessing: defaultAdditionalProcessing, reportMode, }: {
|
|
18
18
|
item: QuillReport;
|
|
19
19
|
filters: DashboardFilter[];
|
|
20
20
|
userFilters?: InternalFilter[];
|
|
21
21
|
additionalProcessing: AdditionalProcessing;
|
|
22
|
+
reportMode?: boolean;
|
|
22
23
|
children: ({ isLoading, error, onPageChange, onSortChange, data, }: DataLoaderChildProps) => JSX.Element;
|
|
23
24
|
}): JSX.Element;
|
|
24
25
|
type ColorMapType = {
|
|
@@ -39,13 +40,14 @@ export type ChartDataLoaderChildProps = {
|
|
|
39
40
|
rowCount?: number;
|
|
40
41
|
rowCountIsLoading?: boolean;
|
|
41
42
|
};
|
|
42
|
-
export declare const ChartDataLoader: ({ item, children, dateBucket, additionalProcessing, filters, userFilters, }: {
|
|
43
|
+
export declare const ChartDataLoader: ({ item, children, dateBucket, additionalProcessing, filters, userFilters, reportMode, }: {
|
|
43
44
|
item: QuillReport;
|
|
44
45
|
dateBucket?: string;
|
|
45
46
|
mapColorsToFields?: (_report: QuillReport, _theme: QuillTheme) => ColorMapType;
|
|
46
47
|
additionalProcessing: AdditionalProcessing;
|
|
47
48
|
filters: DashboardFilter[];
|
|
48
49
|
userFilters?: InternalFilter[];
|
|
50
|
+
reportMode?: boolean;
|
|
49
51
|
children: ({ isLoading, error, data, dateBucket, rowCount, rowCountIsLoading, }: ChartDataLoaderChildProps) => JSX.Element;
|
|
50
52
|
}) => JSX.Element;
|
|
51
53
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataLoader.d.ts","sourceRoot":"","sources":["../../../../src/components/Dashboard/DataLoader.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DataLoader.d.ts","sourceRoot":"","sources":["../../../../src/components/Dashboard/DataLoader.tsx"],"names":[],"mappings":"AASA,OAAO,EAAE,WAAW,EAAuB,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAajD,OAAO,EACL,oBAAoB,EAErB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AA2BtE,MAAM,MAAM,oBAAoB,GAAG;IACjC,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,YAAY,EAAE,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACnE,IAAI,EAAE,WAAW,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAuFF,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EACjC,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,WAAW,EACX,oBAAoB,EAAE,2BAA2B,EACjD,UAAkB,GACnB,EAAE;IACD,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,WAAW,CAAC,EAAE,cAAc,EAAE,CAAC;IAC/B,oBAAoB,EAAE,oBAAoB,CAAC;IAC3C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,CAAC,EACT,SAAS,EACT,KAAK,EACL,YAAY,EACZ,YAAY,EACZ,IAAI,GACL,EAAE,oBAAoB,KAAK,GAAG,CAAC,OAAO,CAAC;CACzC,GAAG,GAAG,CAAC,OAAO,CAuTd;AAED,KAAK,YAAY,GAAG;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG;QACb,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,oBAAoB,CAAC,EAAE,MAAM,CAAC;QAC9B,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,uBAAuB,CAAC,EAAE,MAAM,CAAC;QACjC,sBAAsB,CAAC,EAAE,MAAM,CAAC;KACjC,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,WAAW,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,CAAC;AAIF,eAAO,MAAM,eAAe,4FAQzB;IACD,IAAI,EAAE,WAAW,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB,CAAC,EAAE,CAClB,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,UAAU,KACf,YAAY,CAAC;IAClB,oBAAoB,EAAE,oBAAoB,CAAC;IAC3C,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,WAAW,CAAC,EAAE,cAAc,EAAE,CAAC;IAC/B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,EAAE,CAAC,EACT,SAAS,EACT,KAAK,EACL,IAAI,EACJ,UAAU,EACV,QAAQ,EACR,iBAAiB,GAClB,EAAE,yBAAyB,KAAK,GAAG,CAAC,OAAO,CAAC;CAC9C,KAAG,GAAG,CAAC,OA2JP,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
|
-
import { ClientContext, DashboardContext, DashboardFiltersContext, SchemaDataContext, } from '../../Context';
|
|
3
|
+
import { ClientContext, DashboardContext, DashboardFiltersContext, ReportFiltersContext, ReportsContext, SchemaDataContext, } from '../../Context';
|
|
4
4
|
import { convertInternalReportToReport, EMPTY_INTERNAL_REPORT, fetchReport, fetchReportRowCount, } from '../../utils/report';
|
|
5
5
|
import { shouldFetchMore, DEFAULT_PAGINATION, shouldSortInMemory, } from '../../utils/paginationProcessing';
|
|
6
6
|
import { fetchResultsByReport, } from '../../utils/tableProcessing';
|
|
@@ -50,8 +50,8 @@ function filterValuesEquivalent(filters1, filters2) {
|
|
|
50
50
|
mappedFilters1[key].label !== mappedFilters2[key]?.label ||
|
|
51
51
|
mappedFilters1[key].table !== mappedFilters2[key]?.table ||
|
|
52
52
|
mappedFilters1[key].filterType !== mappedFilters2[key]?.filterType ||
|
|
53
|
-
mappedFilters1[key].startDate
|
|
54
|
-
mappedFilters1[key].endDate
|
|
53
|
+
!equal(mappedFilters1[key].startDate, mappedFilters2[key]?.startDate) ||
|
|
54
|
+
!equal(mappedFilters1[key].endDate, mappedFilters2[key]?.endDate) ||
|
|
55
55
|
!equal(mappedFilters1[key].comparisonRange, mappedFilters2[key]?.comparisonRange)) {
|
|
56
56
|
return false;
|
|
57
57
|
}
|
|
@@ -79,7 +79,7 @@ function userFilterValuesEquivalent(filters1, filters2) {
|
|
|
79
79
|
return acc;
|
|
80
80
|
}, {});
|
|
81
81
|
for (const key in mappedFilters1) {
|
|
82
|
-
if (mappedFilters1[key]?.value
|
|
82
|
+
if (!equal(mappedFilters1[key]?.value, mappedFilters2[key]?.value) ||
|
|
83
83
|
mappedFilters1[key]?.operator !== mappedFilters2[key]?.operator ||
|
|
84
84
|
mappedFilters1[key]?.fieldType !== mappedFilters2[key]?.fieldType ||
|
|
85
85
|
mappedFilters1[key]?.filterType !== mappedFilters2[key]?.filterType) {
|
|
@@ -88,19 +88,35 @@ function userFilterValuesEquivalent(filters1, filters2) {
|
|
|
88
88
|
}
|
|
89
89
|
return true;
|
|
90
90
|
}
|
|
91
|
-
export default function DataLoader({ item, children, filters, userFilters, additionalProcessing: defaultAdditionalProcessing, }) {
|
|
91
|
+
export default function DataLoader({ item, children, filters, userFilters, additionalProcessing: defaultAdditionalProcessing, reportMode = false, }) {
|
|
92
92
|
const [client] = useContext(ClientContext);
|
|
93
93
|
const [dashboard, dispatch] = useContext(DashboardContext);
|
|
94
94
|
const { dashboardFilters } = useContext(DashboardFiltersContext);
|
|
95
|
+
const { reports, reportsDispatch, fetchIndividualReport } = useContext(ReportsContext);
|
|
96
|
+
const { reportFilters } = useContext(ReportFiltersContext);
|
|
97
|
+
const contextFilters = () => {
|
|
98
|
+
return reportMode
|
|
99
|
+
? Object.values(reportFilters[item.id] ?? {}).map((f) => f.filter)
|
|
100
|
+
: Object.values(dashboardFilters[item.dashboardName] ?? {}).map((f) => f.filter);
|
|
101
|
+
};
|
|
95
102
|
const [schemaData] = useContext(SchemaDataContext);
|
|
96
103
|
const [loading, setLoading] = useState(!dashboard[item.id]);
|
|
97
104
|
const [error, setError] = useState(undefined);
|
|
98
105
|
const [previousPage, setPreviousPage] = useState(0);
|
|
99
106
|
const [additionalProcessing, setAdditionalProcessing] = useState(defaultAdditionalProcessing);
|
|
100
107
|
const chartReport = useMemo(() => {
|
|
101
|
-
const report = dashboard[item.id]
|
|
102
|
-
|
|
103
|
-
|
|
108
|
+
const report = (reportMode ? reports : dashboard)[item.id];
|
|
109
|
+
if (report) {
|
|
110
|
+
return convertInternalReportToReport(mergeComparisonRange(report), contextFilters());
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
return constructReportFromItem(item);
|
|
114
|
+
}
|
|
115
|
+
}, [
|
|
116
|
+
(reportMode ? reports : dashboard)[item.id],
|
|
117
|
+
reportFilters,
|
|
118
|
+
dashboardFilters,
|
|
119
|
+
]);
|
|
104
120
|
const previousFilters = useRef(null);
|
|
105
121
|
const previousUserFilters = useRef(null);
|
|
106
122
|
const [rowCountIsLoading, setRowCountIsLoading] = useState(false);
|
|
@@ -123,11 +139,20 @@ export default function DataLoader({ item, children, filters, userFilters, addit
|
|
|
123
139
|
const rowCount = await fetchReportRowCount(item.id, client, true, mergeCustomFilters(filters, userFilters ?? []), processing, schemaData.customFields, rowCountAbortController.current.signal);
|
|
124
140
|
rowCountAbortController.current = null;
|
|
125
141
|
if (rowCount) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
142
|
+
if (reportMode) {
|
|
143
|
+
reportsDispatch({
|
|
144
|
+
type: 'UPDATE_REPORT',
|
|
145
|
+
id: item.id,
|
|
146
|
+
data: { rowCount },
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
dispatch({
|
|
151
|
+
type: 'UPDATE_DASHBOARD_ITEM',
|
|
152
|
+
id: item.id,
|
|
153
|
+
data: { rowCount },
|
|
154
|
+
});
|
|
155
|
+
}
|
|
131
156
|
}
|
|
132
157
|
}
|
|
133
158
|
catch (e) {
|
|
@@ -158,7 +183,7 @@ export default function DataLoader({ item, children, filters, userFilters, addit
|
|
|
158
183
|
}
|
|
159
184
|
};
|
|
160
185
|
const onSortChange = (sort) => {
|
|
161
|
-
const report = dashboard[item.id];
|
|
186
|
+
const report = (reportMode ? reports : dashboard)[item.id];
|
|
162
187
|
if (shouldSortInMemory(additionalProcessing.page ?? DEFAULT_PAGINATION, report?.rowCount, !!report?.pivot)) {
|
|
163
188
|
return;
|
|
164
189
|
}
|
|
@@ -185,17 +210,26 @@ export default function DataLoader({ item, children, filters, userFilters, addit
|
|
|
185
210
|
throw new Error('Error fetching chart');
|
|
186
211
|
}
|
|
187
212
|
let tempRows = [
|
|
188
|
-
...(dashboard[item.id]?.rows ?? []),
|
|
213
|
+
...((reportMode ? reports : dashboard)[item.id]?.rows ?? []),
|
|
189
214
|
...paginatedRows.rows,
|
|
190
215
|
];
|
|
191
216
|
if (resetRows) {
|
|
192
217
|
tempRows = paginatedRows.rows;
|
|
193
218
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
219
|
+
if (reportMode) {
|
|
220
|
+
reportsDispatch({
|
|
221
|
+
type: 'UPDATE_REPORT',
|
|
222
|
+
id: item.id,
|
|
223
|
+
data: { rows: tempRows, filtersApplied: userFilters },
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
dispatch({
|
|
228
|
+
type: 'UPDATE_DASHBOARD_ITEM',
|
|
229
|
+
id: item.id,
|
|
230
|
+
data: { rows: tempRows },
|
|
231
|
+
});
|
|
232
|
+
}
|
|
199
233
|
setAdditionalProcessing(updatedProcessing);
|
|
200
234
|
}
|
|
201
235
|
catch (e) {
|
|
@@ -214,7 +248,7 @@ export default function DataLoader({ item, children, filters, userFilters, addit
|
|
|
214
248
|
}
|
|
215
249
|
const fetchRowsRequestId = rowsRequestId.current + 1;
|
|
216
250
|
rowsRequestId.current = fetchRowsRequestId;
|
|
217
|
-
const tempReport = dashboard[item.id];
|
|
251
|
+
const tempReport = (reportMode ? reports : dashboard)[item.id];
|
|
218
252
|
if (tempReport &&
|
|
219
253
|
!didFiltersChange(tempReport, filters) &&
|
|
220
254
|
userFilterValuesEquivalent(userFilters ?? [], previousUserFilters.current ?? []) &&
|
|
@@ -227,16 +261,30 @@ export default function DataLoader({ item, children, filters, userFilters, addit
|
|
|
227
261
|
rowsAbortController.current?.abort();
|
|
228
262
|
rowsAbortController.current = new AbortController();
|
|
229
263
|
try {
|
|
230
|
-
|
|
231
|
-
|
|
264
|
+
if (reportMode) {
|
|
265
|
+
try {
|
|
266
|
+
await fetchIndividualReport(item.id, 'Chart', true, filters, userFilters, processing, undefined, rowsAbortController.current || undefined);
|
|
267
|
+
setError(undefined);
|
|
268
|
+
}
|
|
269
|
+
catch (e) {
|
|
270
|
+
setError(e.message ?? 'Error fetching report');
|
|
271
|
+
}
|
|
272
|
+
rowsAbortController.current = null;
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
const { report: fetchedReport, error } = await fetchReport(item.id, client, true, mergeCustomFilters(filters, userFilters ?? []), processing, undefined, schemaData.customFields, true, false, rowsAbortController.current.signal);
|
|
276
|
+
rowsAbortController.current = null;
|
|
277
|
+
dispatch({
|
|
278
|
+
type: 'ADD_DASHBOARD_ITEM',
|
|
279
|
+
id: item.id,
|
|
280
|
+
data: { ...fetchedReport, triggerReload: false, rowCount: 0 }, // rowCount 0 indicates it's still loading if row length is nonzero
|
|
281
|
+
appliedFilters: userFilters,
|
|
282
|
+
loading: false,
|
|
283
|
+
});
|
|
284
|
+
setError(error);
|
|
285
|
+
}
|
|
232
286
|
fetchRowCount(processing);
|
|
233
|
-
dispatch({
|
|
234
|
-
type: 'ADD_DASHBOARD_ITEM',
|
|
235
|
-
id: item.id,
|
|
236
|
-
data: { ...fetchedReport, triggerReload: false, rowCount: 0 }, // rowCount 0 indicates it's still loading if row length is nonzero
|
|
237
|
-
});
|
|
238
287
|
setAdditionalProcessing(processing);
|
|
239
|
-
setError(error);
|
|
240
288
|
}
|
|
241
289
|
catch (e) {
|
|
242
290
|
if (e instanceof Error && e.name === 'AbortError') {
|
|
@@ -254,9 +302,9 @@ export default function DataLoader({ item, children, filters, userFilters, addit
|
|
|
254
302
|
if (!filters) {
|
|
255
303
|
return;
|
|
256
304
|
}
|
|
257
|
-
if ((previousFilters.current ||
|
|
258
|
-
|
|
259
|
-
|
|
305
|
+
if ((previousFilters.current ||
|
|
306
|
+
(reportMode ? reports : dashboard)[item.id]?.rows?.length) &&
|
|
307
|
+
filterValuesEquivalent(previousFilters.current ?? contextFilters(), filters) &&
|
|
260
308
|
userFilterValuesEquivalent(previousUserFilters.current ?? [], userFilters ?? [])) {
|
|
261
309
|
previousFilters.current = filters;
|
|
262
310
|
return;
|
|
@@ -266,26 +314,33 @@ export default function DataLoader({ item, children, filters, userFilters, addit
|
|
|
266
314
|
fetchReportHelper(additionalProcessing);
|
|
267
315
|
}, [filters, userFilters, item.id]);
|
|
268
316
|
useEffect(() => {
|
|
269
|
-
if (dashboard[item.id]?.triggerReload) {
|
|
317
|
+
if ((reportMode ? reports : dashboard)[item.id]?.triggerReload) {
|
|
270
318
|
fetchReportHelper(additionalProcessing);
|
|
271
319
|
}
|
|
272
|
-
}, [dashboard[item.id]]);
|
|
320
|
+
}, [(reportMode ? reports : dashboard)[item.id]]);
|
|
273
321
|
return (_jsx(_Fragment, { children: children({
|
|
274
322
|
isLoading: loading,
|
|
275
323
|
error,
|
|
276
324
|
onPageChange,
|
|
277
325
|
onSortChange,
|
|
278
326
|
data: chartReport,
|
|
279
|
-
rowCount: chartReport
|
|
327
|
+
rowCount: chartReport?.rowCount,
|
|
280
328
|
rowCountIsLoading,
|
|
281
329
|
}) }));
|
|
282
330
|
}
|
|
283
331
|
// The same data-loader pattern as above, but with special logic for charts
|
|
284
332
|
// At some point these may be able to get merged into one function.
|
|
285
|
-
export const ChartDataLoader = ({ item, children, dateBucket, additionalProcessing, filters, userFilters, }) => {
|
|
333
|
+
export const ChartDataLoader = ({ item, children, dateBucket, additionalProcessing, filters, userFilters, reportMode = false, }) => {
|
|
286
334
|
const [dashboard, dispatch] = useContext(DashboardContext);
|
|
287
335
|
const { dashboardFilters } = useContext(DashboardFiltersContext);
|
|
288
|
-
const
|
|
336
|
+
const { reports, fetchIndividualReport } = useContext(ReportsContext);
|
|
337
|
+
const { reportFilters } = useContext(ReportFiltersContext);
|
|
338
|
+
const contextFilters = () => {
|
|
339
|
+
return reportMode
|
|
340
|
+
? Object.values(reportFilters[item.id] ?? {}).map((f) => f.filter)
|
|
341
|
+
: Object.values(dashboardFilters[item.dashboardName] ?? {}).map((f) => f.filter);
|
|
342
|
+
};
|
|
343
|
+
const [loading, setLoading] = useState(!(reportMode ? reports : dashboard)[item.id]);
|
|
289
344
|
const [error, setError] = useState(undefined);
|
|
290
345
|
const [client] = useContext(ClientContext);
|
|
291
346
|
const [schemaData] = useContext(SchemaDataContext);
|
|
@@ -294,14 +349,21 @@ export const ChartDataLoader = ({ item, children, dateBucket, additionalProcessi
|
|
|
294
349
|
const previousDateBucket = useRef(undefined);
|
|
295
350
|
const fetchReportAbortController = useRef(null);
|
|
296
351
|
const chartReport = useMemo(() => {
|
|
297
|
-
const report =
|
|
298
|
-
|
|
299
|
-
|
|
352
|
+
const report = reportMode ? reports[item.id] : dashboard[item.id];
|
|
353
|
+
if (!report) {
|
|
354
|
+
return constructReportFromItem(item);
|
|
355
|
+
}
|
|
356
|
+
return convertInternalReportToReport(mergeComparisonRange(report), contextFilters());
|
|
357
|
+
}, [
|
|
358
|
+
(reportMode ? reports : dashboard)[item.id],
|
|
359
|
+
reportFilters,
|
|
360
|
+
dashboardFilters,
|
|
361
|
+
]);
|
|
300
362
|
const fetchReportHelper = async (useReportTask = true) => {
|
|
301
363
|
if (!client || !filters) {
|
|
302
364
|
return;
|
|
303
365
|
}
|
|
304
|
-
const tempReport = dashboard[item.id];
|
|
366
|
+
const tempReport = (reportMode ? reports : dashboard)[item.id];
|
|
305
367
|
if (tempReport &&
|
|
306
368
|
!didFiltersChange(tempReport, filters) &&
|
|
307
369
|
userFilterValuesEquivalent(userFilters ?? [], previousUserFilters.current ?? []) &&
|
|
@@ -316,17 +378,34 @@ export const ChartDataLoader = ({ item, children, dateBucket, additionalProcessi
|
|
|
316
378
|
fetchReportAbortController.current?.abort();
|
|
317
379
|
fetchReportAbortController.current = new AbortController();
|
|
318
380
|
try {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
381
|
+
if (reportMode) {
|
|
382
|
+
try {
|
|
383
|
+
await fetchIndividualReport(item.id, 'Chart', true, filters, userFilters, {
|
|
384
|
+
...additionalProcessing,
|
|
385
|
+
...(item.pivot ? {} : { page: DEFAULT_PAGINATION }),
|
|
386
|
+
}, dateBucket, fetchReportAbortController.current);
|
|
387
|
+
setError(undefined);
|
|
388
|
+
}
|
|
389
|
+
catch (e) {
|
|
390
|
+
setError(e.message ?? 'Error fetching report');
|
|
391
|
+
}
|
|
392
|
+
fetchReportAbortController.current = null;
|
|
393
|
+
}
|
|
394
|
+
else {
|
|
395
|
+
const { report, error } = await fetchReport(item.id, client, useReportTask, mergeCustomFilters(filters, userFilters ?? []), {
|
|
396
|
+
...additionalProcessing,
|
|
397
|
+
...(item.pivot ? {} : { page: DEFAULT_PAGINATION }),
|
|
398
|
+
}, dateBucket, schemaData.customFields, undefined, undefined, fetchReportAbortController.current.signal);
|
|
399
|
+
fetchReportAbortController.current = null;
|
|
400
|
+
dispatch({
|
|
401
|
+
type: 'ADD_DASHBOARD_ITEM',
|
|
402
|
+
id: item.id,
|
|
403
|
+
data: { ...report, triggerReload: false },
|
|
404
|
+
appliedFilters: userFilters,
|
|
405
|
+
loading: false,
|
|
406
|
+
});
|
|
407
|
+
setError(error);
|
|
408
|
+
}
|
|
330
409
|
}
|
|
331
410
|
catch (e) {
|
|
332
411
|
if (e instanceof Error && e.name === 'AbortError') {
|
|
@@ -342,9 +421,9 @@ export const ChartDataLoader = ({ item, children, dateBucket, additionalProcessi
|
|
|
342
421
|
if (!filters) {
|
|
343
422
|
return;
|
|
344
423
|
}
|
|
345
|
-
if ((previousFilters.current ||
|
|
346
|
-
|
|
347
|
-
|
|
424
|
+
if ((previousFilters.current ||
|
|
425
|
+
(reportMode ? reports : dashboard)[item.id]?.rows?.length) &&
|
|
426
|
+
filterValuesEquivalent(previousFilters.current ?? contextFilters(), filters) &&
|
|
348
427
|
userFilterValuesEquivalent(previousUserFilters.current ?? [], userFilters ?? []) &&
|
|
349
428
|
previousDateBucket.current === dateBucket) {
|
|
350
429
|
previousFilters.current = filters;
|
|
@@ -354,13 +433,13 @@ export const ChartDataLoader = ({ item, children, dateBucket, additionalProcessi
|
|
|
354
433
|
fetchReportHelper();
|
|
355
434
|
}, [filters, userFilters, item.id, dateBucket]);
|
|
356
435
|
useEffect(() => {
|
|
357
|
-
const tempReport = dashboard[item.id];
|
|
436
|
+
const tempReport = (reportMode ? reports : dashboard)[item.id];
|
|
358
437
|
if (tempReport && tempReport.triggerReload) {
|
|
359
438
|
fetchReportHelper();
|
|
360
439
|
}
|
|
361
|
-
}, [dashboard[item.id]]);
|
|
440
|
+
}, [(reportMode ? reports : dashboard)[item.id]]);
|
|
362
441
|
return children({
|
|
363
|
-
isLoading: loading,
|
|
442
|
+
isLoading: !chartReport || loading,
|
|
364
443
|
data: chartReport,
|
|
365
444
|
error,
|
|
366
445
|
dateBucket,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDashboard.d.ts","sourceRoot":"","sources":["../../../src/hooks/useDashboard.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"useDashboard.d.ts","sourceRoot":"","sources":["../../../src/hooks/useDashboard.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEpE,OAAO,EACL,eAAe,EAEf,cAAc,EACf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtD,eAAO,MAAM,UAAU;uCAYR,CAAC,MAAM,EAAE,mBAAmB,KAAK,OAAO;CAYtD,CAAC;AAEF,eAAO,MAAM,YAAY,kBACR,MAAM,GAAG,IAAI,kBACZ,cAAc,EAAE;;;;2CA8Gc,MAAM;qCApF1B,MAAM,4CAEf;QACb,MAAM,EAAE,WAAW,GAAG;YAAE,EAAE,EAAE,MAAM,CAAA;SAAE,CAAC;QACrC,MAAM,EAAE,QAAQ,GAAG,QAAQ,CAAC;KAC7B,oBACiB;QAChB,OAAO,EAAE,eAAe,EAAE,CAAC;QAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC;KAC5B;CA8FJ,CAAC;AAEF,eAAO,MAAM,aAAa;;;;;;;sDAuBrB;QACD,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,eAAe,EAAE,CAAC;QAC3B,UAAU,CAAC,EAAE,eAAe,CAAC;KAC9B;4BA+CO,MAAM,oDAMT;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,eAAe,EAAE,CAAC;QAC3B,UAAU,CAAC,EAAE,eAAe,CAAC;QAC7B,aAAa,CAAC,EAAE,cAAc,EAAE,CAAC;KAClC;4BA2FkC,MAAM;CA8B5C,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { useContext, useMemo } from 'react';
|
|
2
2
|
import { ClientContext, DashboardConfigContext, DashboardContext, DashboardFiltersContext, } from '../Context';
|
|
3
|
-
import {
|
|
3
|
+
import { PRIMARY_RANGE } from '../DateRangePicker/dateRangePickerUtils';
|
|
4
4
|
import { DashboardFilterType, } from '../models/Filter';
|
|
5
|
+
import { createDefaultDateFilter } from '../utils/filterProcessing';
|
|
5
6
|
export const useReports = () => {
|
|
6
7
|
const [dashboard, dispatch] = useContext(DashboardContext);
|
|
7
8
|
const reloadReport = (id) => {
|
|
@@ -69,56 +70,8 @@ export const useDashboard = (dashboardName, customFilters) => {
|
|
|
69
70
|
filter.filter.options)) {
|
|
70
71
|
return;
|
|
71
72
|
}
|
|
72
|
-
const getComparisonRange = (dateFilter, rangeType) => {
|
|
73
|
-
const range = dateFilter?.presetRanges?.find((range) => range.value === dateFilter?.primaryRange?.value) ?? PRIMARY_RANGE[dateFilter?.primaryRange?.value ?? 'LAST_30_DAYS'];
|
|
74
|
-
return (dateFilter?.comparisonRange?.[rangeType] ??
|
|
75
|
-
COMPARISON_RANGE[dateFilter?.defaultComparisonRange ??
|
|
76
|
-
'NO_COMPARISON']({
|
|
77
|
-
startDate: !range.startDate || range.startDate instanceof Date
|
|
78
|
-
? range.startDate
|
|
79
|
-
: new Date(range.startDate), // when range.startDate is a string
|
|
80
|
-
endDate: !range.endDate || range.endDate instanceof Date
|
|
81
|
-
? range.endDate
|
|
82
|
-
: new Date(range.endDate), // when range.endDate is a string
|
|
83
|
-
})?.[rangeType]);
|
|
84
|
-
};
|
|
85
|
-
const comparisonRangeStart = getComparisonRange(dashboard?.dateFilter, 'startDate');
|
|
86
|
-
const comparisonRangeEnd = getComparisonRange(dashboard?.dateFilter, 'endDate');
|
|
87
|
-
const range = dashboard?.dateFilter?.presetRanges?.find((range) => range.value === dashboard?.dateFilter?.primaryRange?.value) ??
|
|
88
|
-
PRIMARY_RANGE[dashboard?.dateFilter?.primaryRange?.value ?? 'LAST_30_DAYS'] ??
|
|
89
|
-
PRIMARY_RANGE['LAST_30_DAYS'];
|
|
90
73
|
const dateFilter = dashboard?.dateFilter
|
|
91
|
-
? {
|
|
92
|
-
...dashboard?.dateFilter,
|
|
93
|
-
startDate: !range.startDate || range.startDate instanceof Date
|
|
94
|
-
? range.startDate
|
|
95
|
-
: new Date(range.startDate), // when range.startDate is a string
|
|
96
|
-
endDate: !range.endDate || range.endDate instanceof Date
|
|
97
|
-
? range.endDate
|
|
98
|
-
: new Date(range.endDate), // when range.endDate is a string
|
|
99
|
-
filterType: DashboardFilterType.Date,
|
|
100
|
-
dateField: [
|
|
101
|
-
...new Map(Object.values(dashboard?.sections ?? {})
|
|
102
|
-
.flat()
|
|
103
|
-
.map((report) => {
|
|
104
|
-
const key = JSON.stringify(report.dateField);
|
|
105
|
-
return [key, report.dateField];
|
|
106
|
-
})).values(),
|
|
107
|
-
],
|
|
108
|
-
preset: dashboard?.dateFilter.primaryRange,
|
|
109
|
-
dashboardName: overrideDashboardName ?? dashboardName,
|
|
110
|
-
comparisonRange: dashboard?.dateFilter.comparison &&
|
|
111
|
-
comparisonRangeStart &&
|
|
112
|
-
comparisonRangeEnd
|
|
113
|
-
? {
|
|
114
|
-
startDate: comparisonRangeStart,
|
|
115
|
-
endDate: comparisonRangeEnd,
|
|
116
|
-
value: dashboard?.dateFilter.comparisonRange?.value ??
|
|
117
|
-
dashboard.dateFilter?.defaultComparisonRange ??
|
|
118
|
-
'NO_COMPARISON',
|
|
119
|
-
}
|
|
120
|
-
: undefined,
|
|
121
|
-
}
|
|
74
|
+
? createDefaultDateFilter(dashboard?.dateFilter, Object.values(dashboard?.sections ?? {}).flat(), dashboardName)
|
|
122
75
|
: undefined;
|
|
123
76
|
// Append dateFilter to the filters unless it's undefined
|
|
124
77
|
loadFiltersForDashboard(dashboardName, [...(dateFilter ? [dateFilter] : []), ...(dashboard?.filters ?? [])], undefined, customFilters);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQuill.d.ts","sourceRoot":"","sources":["../../../src/hooks/useQuill.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useQuill.d.ts","sourceRoot":"","sources":["../../../src/hooks/useQuill.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EACL,WAAW,EAIZ,MAAM,yBAAyB,CAAC;AAIjC,MAAM,WAAW,KAAK;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,gBAAgB,EAAE,MAAM,CAAC;IACzB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,QAAQ,cACR,MAAM,eACJ;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,KAC3D;IACD,IAAI,EAAE,WAAW,GAAG,IAAI,CAAC;IACzB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IACpD,SAAS,EACL,CAAC,CAAC,QAAQ,EAAE,WAAW,KAAK,MAAM,GAAG,SAAS,CAAC,GAC/C,CAAC,MAAM,SAAS,CAAC,CAAC;CA4MvB,CAAC"}
|
|
@@ -1,54 +1,60 @@
|
|
|
1
1
|
import { useContext, useEffect, useMemo, useState } from 'react';
|
|
2
|
-
import { ClientContext, DashboardContext, DashboardFiltersContext, SchemaDataContext, } from '../Context';
|
|
3
|
-
import { convertInternalReportToReport
|
|
2
|
+
import { ClientContext, DashboardContext, DashboardFiltersContext, ReportFiltersContext, ReportsContext, SchemaDataContext, } from '../Context';
|
|
3
|
+
import { convertInternalReportToReport } from '../utils/report';
|
|
4
4
|
import { shouldFetchMore } from '../utils/paginationProcessing';
|
|
5
5
|
import { fetchResultsByReport, } from '../utils/tableProcessing';
|
|
6
6
|
import { getPointToPointPercentageChange, getSimplePercentageChange, getSumOfFields, } from '../utils/dataProcessing';
|
|
7
7
|
import { mergeComparisonRange } from '../utils/merge';
|
|
8
8
|
export const useQuill = (reportId, pagination) => {
|
|
9
|
-
const
|
|
9
|
+
const { reports, reportsDispatch, fetchIndividualReport } = useContext(ReportsContext);
|
|
10
|
+
const [dashboard] = useContext(DashboardContext);
|
|
10
11
|
const { dashboardFilters } = useContext(DashboardFiltersContext);
|
|
12
|
+
const { reportFilters, reportFiltersDispatch } = useContext(ReportFiltersContext);
|
|
11
13
|
const specificDashboardFilters = useMemo(() => {
|
|
12
14
|
if (!reportId)
|
|
13
15
|
return [];
|
|
14
|
-
const dashboardName =
|
|
16
|
+
const dashboardName = reports[reportId]?.dashboardName;
|
|
15
17
|
if (!dashboardName)
|
|
16
18
|
return [];
|
|
17
19
|
return Object.values(dashboardFilters[dashboardName] ?? {}).map((f) => f.filter);
|
|
18
20
|
}, [dashboardFilters, reportId, dashboard]);
|
|
21
|
+
const specificReportFilters = useMemo(() => {
|
|
22
|
+
if (!reportId)
|
|
23
|
+
return [];
|
|
24
|
+
return Object.values(reportFilters[reportId] ?? []).map((f) => f.filter);
|
|
25
|
+
}, [reportFilters, reportId]);
|
|
19
26
|
const [schemaData] = useContext(SchemaDataContext);
|
|
20
27
|
const [client] = useContext(ClientContext);
|
|
21
|
-
const [data, setData] = useState(null);
|
|
22
28
|
const [loading, setLoading] = useState(true);
|
|
23
29
|
const [error, setError] = useState(undefined);
|
|
24
30
|
const [previousPage, setPreviousPage] = useState(0);
|
|
25
31
|
const processedReport = useMemo(() => {
|
|
26
|
-
return reportId && dashboard[reportId]
|
|
27
|
-
? convertInternalReportToReport(mergeComparisonRange(dashboard[reportId]))
|
|
32
|
+
return reportId && (reports[reportId] || dashboard[reportId])
|
|
33
|
+
? convertInternalReportToReport(mergeComparisonRange(reports[reportId] || dashboard[reportId]), specificReportFilters)
|
|
28
34
|
: undefined;
|
|
29
|
-
}, [
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
}, [
|
|
36
|
+
reportId,
|
|
37
|
+
reportId && (reports[reportId] || dashboard[reportId]),
|
|
38
|
+
specificReportFilters,
|
|
39
|
+
]);
|
|
34
40
|
const [additionalProcessing, setAdditionProcessing] = useState(pagination
|
|
35
41
|
? {
|
|
36
42
|
page: pagination,
|
|
37
43
|
}
|
|
38
44
|
: undefined);
|
|
39
45
|
function calculateFunction(calcType, options) {
|
|
40
|
-
if (!
|
|
46
|
+
if (!processedReport || !processedReport.rows) {
|
|
41
47
|
return undefined;
|
|
42
48
|
}
|
|
43
49
|
switch (calcType) {
|
|
44
50
|
case 'SIMPLE_PERCENTAGE_CHANGE':
|
|
45
|
-
return getSimplePercentageChange(
|
|
51
|
+
return getSimplePercentageChange(processedReport);
|
|
46
52
|
case 'POINT_TO_POINT_PERCENTAGE_CHANGE':
|
|
47
|
-
return getPointToPointPercentageChange(
|
|
53
|
+
return getPointToPointPercentageChange(processedReport);
|
|
48
54
|
case 'SUM':
|
|
49
|
-
return getSumOfFields(
|
|
55
|
+
return getSumOfFields(processedReport, options?.comparison ? true : false);
|
|
50
56
|
default:
|
|
51
|
-
return getSimplePercentageChange(
|
|
57
|
+
return getSimplePercentageChange(processedReport);
|
|
52
58
|
}
|
|
53
59
|
}
|
|
54
60
|
const fetchMore = (page) => {
|
|
@@ -83,19 +89,26 @@ export const useQuill = (reportId, pagination) => {
|
|
|
83
89
|
if (!client) {
|
|
84
90
|
return;
|
|
85
91
|
}
|
|
86
|
-
if (!loading && reportId &&
|
|
92
|
+
if (!loading && reportId && processedReport) {
|
|
87
93
|
setLoading(true);
|
|
88
94
|
try {
|
|
89
95
|
const updatedProcessing = { ...additionalProcessing, ...processing };
|
|
90
|
-
const paginatedRows = await fetchResultsByReport(reportId, client, updatedProcessing,
|
|
96
|
+
const paginatedRows = await fetchResultsByReport(reportId, client, updatedProcessing, reportFilters[reportId], schemaData.customFields);
|
|
91
97
|
if (paginatedRows.error) {
|
|
92
98
|
throw new Error('Error fetching chart');
|
|
93
99
|
}
|
|
94
|
-
let tempRows = [...
|
|
100
|
+
let tempRows = [...processedReport.rows, ...paginatedRows.rows];
|
|
95
101
|
if (resetRows) {
|
|
96
102
|
tempRows = paginatedRows.rows;
|
|
97
103
|
}
|
|
98
|
-
|
|
104
|
+
reportsDispatch({
|
|
105
|
+
type: 'UPDATE_REPORT',
|
|
106
|
+
id: reportId,
|
|
107
|
+
data: {
|
|
108
|
+
...reports[reportId],
|
|
109
|
+
rows: tempRows,
|
|
110
|
+
},
|
|
111
|
+
});
|
|
99
112
|
setTimeout(() => {
|
|
100
113
|
setLoading(false);
|
|
101
114
|
}, 200);
|
|
@@ -106,46 +119,55 @@ export const useQuill = (reportId, pagination) => {
|
|
|
106
119
|
}
|
|
107
120
|
}
|
|
108
121
|
};
|
|
109
|
-
const fetchReportHelper = async (curReportId,
|
|
122
|
+
const fetchReportHelper = async (curReportId, additionalProcessing) => {
|
|
110
123
|
if (!client) {
|
|
111
124
|
return;
|
|
112
125
|
}
|
|
113
|
-
if
|
|
114
|
-
|
|
126
|
+
//FIXME: these two early returns don't check if the pagination lines up
|
|
127
|
+
if (reports[curReportId]) {
|
|
128
|
+
setLoading(false);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (dashboard[curReportId]) {
|
|
132
|
+
reportsDispatch({
|
|
133
|
+
type: 'ADD_REPORT',
|
|
134
|
+
id: curReportId,
|
|
135
|
+
data: reports[curReportId],
|
|
136
|
+
});
|
|
115
137
|
setLoading(false);
|
|
116
138
|
return;
|
|
117
139
|
}
|
|
140
|
+
if (specificDashboardFilters.length && !specificReportFilters.length) {
|
|
141
|
+
reportFiltersDispatch({
|
|
142
|
+
type: 'ADD_REPORT_FILTERS',
|
|
143
|
+
id: curReportId,
|
|
144
|
+
data: Object.values(dashboardFilters[curReportId] ?? []),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
118
147
|
setLoading(true);
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
});
|
|
129
|
-
setData(convertInternalReportToReport(mergeComparisonRange(report)));
|
|
130
|
-
setError(error);
|
|
131
|
-
setLoading(false);
|
|
148
|
+
try {
|
|
149
|
+
await fetchIndividualReport(curReportId, 'useQuill', true, specificReportFilters, [], additionalProcessing);
|
|
150
|
+
}
|
|
151
|
+
catch (error) {
|
|
152
|
+
setError(error.message ?? 'Error fetching report');
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
setLoading(false);
|
|
156
|
+
}
|
|
132
157
|
};
|
|
133
158
|
useEffect(() => {
|
|
134
159
|
if (reportId) {
|
|
135
|
-
fetchReportHelper(reportId,
|
|
160
|
+
fetchReportHelper(reportId, {
|
|
136
161
|
page: pagination,
|
|
137
162
|
});
|
|
138
163
|
}
|
|
139
|
-
}, [reportId
|
|
140
|
-
useEffect(() => {
|
|
141
|
-
setCalculate(() => calculateFunction);
|
|
142
|
-
}, [data]);
|
|
164
|
+
}, [reportId]);
|
|
143
165
|
return {
|
|
144
|
-
data: processedReport ??
|
|
166
|
+
data: processedReport ?? null,
|
|
145
167
|
loading,
|
|
146
168
|
error,
|
|
147
169
|
fetchMore,
|
|
148
170
|
setSort,
|
|
149
|
-
calculate,
|
|
171
|
+
calculate: calculateFunction,
|
|
150
172
|
};
|
|
151
173
|
};
|