@quillsql/react 2.13.18 → 2.13.19
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 +2 -2
- package/dist/cjs/Chart.d.ts.map +1 -1
- package/dist/cjs/Chart.js +53 -175
- package/dist/cjs/ChartBuilder.d.ts.map +1 -1
- package/dist/cjs/ChartBuilder.js +3 -3
- package/dist/cjs/Context.d.ts +24 -3
- package/dist/cjs/Context.d.ts.map +1 -1
- package/dist/cjs/Context.js +323 -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 +141 -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 +66 -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 +81 -51
- package/dist/esm/Chart.d.ts +2 -2
- package/dist/esm/Chart.d.ts.map +1 -1
- package/dist/esm/Chart.js +66 -179
- package/dist/esm/ChartBuilder.d.ts.map +1 -1
- package/dist/esm/ChartBuilder.js +3 -3
- package/dist/esm/Context.d.ts +24 -3
- package/dist/esm/Context.d.ts.map +1 -1
- package/dist/esm/Context.js +322 -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 +142 -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 +68 -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 +79 -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,CAwTd;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,OAgKP,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,27 @@ 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 },
|
|
224
|
+
filtersApplied: userFilters,
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
dispatch({
|
|
229
|
+
type: 'UPDATE_DASHBOARD_ITEM',
|
|
230
|
+
id: item.id,
|
|
231
|
+
data: { rows: tempRows },
|
|
232
|
+
});
|
|
233
|
+
}
|
|
199
234
|
setAdditionalProcessing(updatedProcessing);
|
|
200
235
|
}
|
|
201
236
|
catch (e) {
|
|
@@ -214,7 +249,7 @@ export default function DataLoader({ item, children, filters, userFilters, addit
|
|
|
214
249
|
}
|
|
215
250
|
const fetchRowsRequestId = rowsRequestId.current + 1;
|
|
216
251
|
rowsRequestId.current = fetchRowsRequestId;
|
|
217
|
-
const tempReport = dashboard[item.id];
|
|
252
|
+
const tempReport = (reportMode ? reports : dashboard)[item.id];
|
|
218
253
|
if (tempReport &&
|
|
219
254
|
!didFiltersChange(tempReport, filters) &&
|
|
220
255
|
userFilterValuesEquivalent(userFilters ?? [], previousUserFilters.current ?? []) &&
|
|
@@ -227,16 +262,30 @@ export default function DataLoader({ item, children, filters, userFilters, addit
|
|
|
227
262
|
rowsAbortController.current?.abort();
|
|
228
263
|
rowsAbortController.current = new AbortController();
|
|
229
264
|
try {
|
|
230
|
-
|
|
231
|
-
|
|
265
|
+
if (reportMode) {
|
|
266
|
+
try {
|
|
267
|
+
await fetchIndividualReport(item.id, 'Chart', true, filters, userFilters, processing, undefined, rowsAbortController.current || undefined);
|
|
268
|
+
setError(undefined);
|
|
269
|
+
}
|
|
270
|
+
catch (e) {
|
|
271
|
+
setError(e.message ?? 'Error fetching report');
|
|
272
|
+
}
|
|
273
|
+
rowsAbortController.current = null;
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
const { report: fetchedReport, error } = await fetchReport(item.id, client, true, mergeCustomFilters(filters, userFilters ?? []), processing, undefined, schemaData.customFields, true, false, rowsAbortController.current.signal);
|
|
277
|
+
rowsAbortController.current = null;
|
|
278
|
+
dispatch({
|
|
279
|
+
type: 'ADD_DASHBOARD_ITEM',
|
|
280
|
+
id: item.id,
|
|
281
|
+
data: { ...fetchedReport, triggerReload: false, rowCount: 0 }, // rowCount 0 indicates it's still loading if row length is nonzero
|
|
282
|
+
appliedFilters: userFilters,
|
|
283
|
+
loading: false,
|
|
284
|
+
});
|
|
285
|
+
setError(error);
|
|
286
|
+
}
|
|
232
287
|
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
288
|
setAdditionalProcessing(processing);
|
|
239
|
-
setError(error);
|
|
240
289
|
}
|
|
241
290
|
catch (e) {
|
|
242
291
|
if (e instanceof Error && e.name === 'AbortError') {
|
|
@@ -254,9 +303,9 @@ export default function DataLoader({ item, children, filters, userFilters, addit
|
|
|
254
303
|
if (!filters) {
|
|
255
304
|
return;
|
|
256
305
|
}
|
|
257
|
-
if ((previousFilters.current ||
|
|
258
|
-
|
|
259
|
-
|
|
306
|
+
if ((previousFilters.current ||
|
|
307
|
+
(reportMode ? reports : dashboard)[item.id]?.rows?.length) &&
|
|
308
|
+
filterValuesEquivalent(previousFilters.current ?? contextFilters(), filters) &&
|
|
260
309
|
userFilterValuesEquivalent(previousUserFilters.current ?? [], userFilters ?? [])) {
|
|
261
310
|
previousFilters.current = filters;
|
|
262
311
|
return;
|
|
@@ -266,26 +315,33 @@ export default function DataLoader({ item, children, filters, userFilters, addit
|
|
|
266
315
|
fetchReportHelper(additionalProcessing);
|
|
267
316
|
}, [filters, userFilters, item.id]);
|
|
268
317
|
useEffect(() => {
|
|
269
|
-
if (dashboard[item.id]?.triggerReload) {
|
|
318
|
+
if ((reportMode ? reports : dashboard)[item.id]?.triggerReload) {
|
|
270
319
|
fetchReportHelper(additionalProcessing);
|
|
271
320
|
}
|
|
272
|
-
}, [dashboard[item.id]]);
|
|
321
|
+
}, [(reportMode ? reports : dashboard)[item.id]]);
|
|
273
322
|
return (_jsx(_Fragment, { children: children({
|
|
274
323
|
isLoading: loading,
|
|
275
324
|
error,
|
|
276
325
|
onPageChange,
|
|
277
326
|
onSortChange,
|
|
278
327
|
data: chartReport,
|
|
279
|
-
rowCount: chartReport
|
|
328
|
+
rowCount: chartReport?.rowCount,
|
|
280
329
|
rowCountIsLoading,
|
|
281
330
|
}) }));
|
|
282
331
|
}
|
|
283
332
|
// The same data-loader pattern as above, but with special logic for charts
|
|
284
333
|
// At some point these may be able to get merged into one function.
|
|
285
|
-
export const ChartDataLoader = ({ item, children, dateBucket, additionalProcessing, filters, userFilters, }) => {
|
|
334
|
+
export const ChartDataLoader = ({ item, children, dateBucket, additionalProcessing, filters, userFilters, reportMode = false, }) => {
|
|
286
335
|
const [dashboard, dispatch] = useContext(DashboardContext);
|
|
287
336
|
const { dashboardFilters } = useContext(DashboardFiltersContext);
|
|
288
|
-
const
|
|
337
|
+
const { reports, fetchIndividualReport } = useContext(ReportsContext);
|
|
338
|
+
const { reportFilters } = useContext(ReportFiltersContext);
|
|
339
|
+
const contextFilters = () => {
|
|
340
|
+
return reportMode
|
|
341
|
+
? Object.values(reportFilters[item.id] ?? {}).map((f) => f.filter)
|
|
342
|
+
: Object.values(dashboardFilters[item.dashboardName] ?? {}).map((f) => f.filter);
|
|
343
|
+
};
|
|
344
|
+
const [loading, setLoading] = useState(!(reportMode ? reports : dashboard)[item.id]);
|
|
289
345
|
const [error, setError] = useState(undefined);
|
|
290
346
|
const [client] = useContext(ClientContext);
|
|
291
347
|
const [schemaData] = useContext(SchemaDataContext);
|
|
@@ -294,14 +350,24 @@ export const ChartDataLoader = ({ item, children, dateBucket, additionalProcessi
|
|
|
294
350
|
const previousDateBucket = useRef(undefined);
|
|
295
351
|
const fetchReportAbortController = useRef(null);
|
|
296
352
|
const chartReport = useMemo(() => {
|
|
297
|
-
const report =
|
|
298
|
-
|
|
299
|
-
|
|
353
|
+
const report = reportMode ? reports[item.id] : dashboard[item.id];
|
|
354
|
+
if (!report) {
|
|
355
|
+
return constructReportFromItem(item);
|
|
356
|
+
}
|
|
357
|
+
return convertInternalReportToReport(mergeComparisonRange(report), contextFilters());
|
|
358
|
+
}, [
|
|
359
|
+
(reportMode ? reports : dashboard)[item.id],
|
|
360
|
+
reportFilters,
|
|
361
|
+
dashboardFilters,
|
|
362
|
+
]);
|
|
363
|
+
useEffect(() => {
|
|
364
|
+
console.log('chartReport memo', chartReport);
|
|
365
|
+
}, [chartReport]);
|
|
300
366
|
const fetchReportHelper = async (useReportTask = true) => {
|
|
301
367
|
if (!client || !filters) {
|
|
302
368
|
return;
|
|
303
369
|
}
|
|
304
|
-
const tempReport = dashboard[item.id];
|
|
370
|
+
const tempReport = (reportMode ? reports : dashboard)[item.id];
|
|
305
371
|
if (tempReport &&
|
|
306
372
|
!didFiltersChange(tempReport, filters) &&
|
|
307
373
|
userFilterValuesEquivalent(userFilters ?? [], previousUserFilters.current ?? []) &&
|
|
@@ -316,17 +382,34 @@ export const ChartDataLoader = ({ item, children, dateBucket, additionalProcessi
|
|
|
316
382
|
fetchReportAbortController.current?.abort();
|
|
317
383
|
fetchReportAbortController.current = new AbortController();
|
|
318
384
|
try {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
385
|
+
if (reportMode) {
|
|
386
|
+
try {
|
|
387
|
+
await fetchIndividualReport(item.id, 'Chart', true, filters, userFilters, {
|
|
388
|
+
...additionalProcessing,
|
|
389
|
+
...(item.pivot ? {} : { page: DEFAULT_PAGINATION }),
|
|
390
|
+
}, dateBucket, fetchReportAbortController.current);
|
|
391
|
+
setError(undefined);
|
|
392
|
+
}
|
|
393
|
+
catch (e) {
|
|
394
|
+
setError(e.message ?? 'Error fetching report');
|
|
395
|
+
}
|
|
396
|
+
fetchReportAbortController.current = null;
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
const { report, error } = await fetchReport(item.id, client, useReportTask, mergeCustomFilters(filters, userFilters ?? []), {
|
|
400
|
+
...additionalProcessing,
|
|
401
|
+
...(item.pivot ? {} : { page: DEFAULT_PAGINATION }),
|
|
402
|
+
}, dateBucket, schemaData.customFields, undefined, undefined, fetchReportAbortController.current.signal);
|
|
403
|
+
fetchReportAbortController.current = null;
|
|
404
|
+
dispatch({
|
|
405
|
+
type: 'ADD_DASHBOARD_ITEM',
|
|
406
|
+
id: item.id,
|
|
407
|
+
data: { ...report, triggerReload: false },
|
|
408
|
+
appliedFilters: userFilters,
|
|
409
|
+
loading: false,
|
|
410
|
+
});
|
|
411
|
+
setError(error);
|
|
412
|
+
}
|
|
330
413
|
}
|
|
331
414
|
catch (e) {
|
|
332
415
|
if (e instanceof Error && e.name === 'AbortError') {
|
|
@@ -342,9 +425,9 @@ export const ChartDataLoader = ({ item, children, dateBucket, additionalProcessi
|
|
|
342
425
|
if (!filters) {
|
|
343
426
|
return;
|
|
344
427
|
}
|
|
345
|
-
if ((previousFilters.current ||
|
|
346
|
-
|
|
347
|
-
|
|
428
|
+
if ((previousFilters.current ||
|
|
429
|
+
(reportMode ? reports : dashboard)[item.id]?.rows?.length) &&
|
|
430
|
+
filterValuesEquivalent(previousFilters.current ?? contextFilters(), filters) &&
|
|
348
431
|
userFilterValuesEquivalent(previousUserFilters.current ?? [], userFilters ?? []) &&
|
|
349
432
|
previousDateBucket.current === dateBucket) {
|
|
350
433
|
previousFilters.current = filters;
|
|
@@ -354,13 +437,14 @@ export const ChartDataLoader = ({ item, children, dateBucket, additionalProcessi
|
|
|
354
437
|
fetchReportHelper();
|
|
355
438
|
}, [filters, userFilters, item.id, dateBucket]);
|
|
356
439
|
useEffect(() => {
|
|
357
|
-
const tempReport = dashboard[item.id];
|
|
440
|
+
const tempReport = (reportMode ? reports : dashboard)[item.id];
|
|
358
441
|
if (tempReport && tempReport.triggerReload) {
|
|
359
442
|
fetchReportHelper();
|
|
360
443
|
}
|
|
361
|
-
}, [dashboard[item.id]]);
|
|
444
|
+
}, [(reportMode ? reports : dashboard)[item.id]]);
|
|
445
|
+
console.log('chartReport', chartReport);
|
|
362
446
|
return children({
|
|
363
|
-
isLoading: loading,
|
|
447
|
+
isLoading: !chartReport || loading,
|
|
364
448
|
data: chartReport,
|
|
365
449
|
error,
|
|
366
450
|
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;CA8MvB,CAAC"}
|