@quillsql/react 2.12.28 → 2.12.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.d.ts.map +1 -1
- package/dist/cjs/Chart.js +10 -8
- package/dist/cjs/ChartBuilder.d.ts +35 -1
- package/dist/cjs/ChartBuilder.d.ts.map +1 -1
- package/dist/cjs/ChartBuilder.js +38 -4
- package/dist/cjs/Context.d.ts +1 -19
- package/dist/cjs/Context.d.ts.map +1 -1
- package/dist/cjs/Context.js +32 -83
- package/dist/cjs/Dashboard.d.ts.map +1 -1
- package/dist/cjs/Dashboard.js +76 -49
- package/dist/cjs/ReportBuilder.d.ts +9 -0
- package/dist/cjs/ReportBuilder.d.ts.map +1 -1
- package/dist/cjs/ReportBuilder.js +330 -100
- package/dist/cjs/SQLEditor.d.ts.map +1 -1
- package/dist/cjs/SQLEditor.js +98 -29
- package/dist/cjs/Table.d.ts.map +1 -1
- package/dist/cjs/Table.js +8 -8
- package/dist/cjs/components/Chart/ChartTooltip.d.ts.map +1 -1
- package/dist/cjs/components/Dashboard/DataLoader.d.ts.map +1 -1
- package/dist/cjs/components/Dashboard/DataLoader.js +20 -16
- package/dist/cjs/hooks/useDashboard.d.ts +1 -1
- package/dist/cjs/hooks/useDashboard.d.ts.map +1 -1
- package/dist/cjs/hooks/useDashboard.js +18 -4
- package/dist/cjs/internals/ReportBuilder/PivotModal.d.ts.map +1 -1
- package/dist/cjs/internals/ReportBuilder/PivotModal.js +56 -57
- package/dist/cjs/utils/columnProcessing.d.ts +1 -0
- package/dist/cjs/utils/columnProcessing.d.ts.map +1 -1
- package/dist/cjs/utils/columnProcessing.js +8 -1
- package/dist/cjs/utils/dashboard.js +1 -1
- package/dist/cjs/utils/dataFetcher.d.ts +1 -1
- package/dist/cjs/utils/dataFetcher.d.ts.map +1 -1
- package/dist/cjs/utils/dataFetcher.js +9 -4
- package/dist/cjs/utils/dates.d.ts +1 -0
- package/dist/cjs/utils/dates.d.ts.map +1 -1
- package/dist/cjs/utils/dates.js +12 -3
- package/dist/cjs/utils/monacoAutocomplete.d.ts +20 -0
- package/dist/cjs/utils/monacoAutocomplete.d.ts.map +1 -0
- package/dist/cjs/utils/monacoAutocomplete.js +145 -0
- package/dist/cjs/utils/pivotConstructor.d.ts.map +1 -1
- package/dist/cjs/utils/pivotConstructor.js +58 -5
- package/dist/cjs/utils/queryConstructor.d.ts +4 -2
- package/dist/cjs/utils/queryConstructor.d.ts.map +1 -1
- package/dist/cjs/utils/queryConstructor.js +118 -57
- package/dist/cjs/utils/queryConstructor.uspec.d.ts +2 -0
- package/dist/cjs/utils/queryConstructor.uspec.d.ts.map +1 -0
- package/dist/cjs/utils/queryConstructor.uspec.js +225 -0
- package/dist/cjs/utils/tableProcessing.d.ts +1 -0
- package/dist/cjs/utils/tableProcessing.d.ts.map +1 -1
- package/dist/cjs/utils/tableProcessing.js +42 -5
- package/dist/esm/Chart.d.ts.map +1 -1
- package/dist/esm/Chart.js +10 -8
- package/dist/esm/ChartBuilder.d.ts +35 -1
- package/dist/esm/ChartBuilder.d.ts.map +1 -1
- package/dist/esm/ChartBuilder.js +36 -3
- package/dist/esm/Context.d.ts +1 -19
- package/dist/esm/Context.d.ts.map +1 -1
- package/dist/esm/Context.js +32 -82
- package/dist/esm/Dashboard.d.ts.map +1 -1
- package/dist/esm/Dashboard.js +77 -50
- package/dist/esm/ReportBuilder.d.ts +9 -0
- package/dist/esm/ReportBuilder.d.ts.map +1 -1
- package/dist/esm/ReportBuilder.js +333 -103
- package/dist/esm/SQLEditor.d.ts.map +1 -1
- package/dist/esm/SQLEditor.js +99 -30
- package/dist/esm/Table.d.ts.map +1 -1
- package/dist/esm/Table.js +8 -8
- package/dist/esm/components/Chart/ChartTooltip.d.ts.map +1 -1
- package/dist/esm/components/Dashboard/DataLoader.d.ts.map +1 -1
- package/dist/esm/components/Dashboard/DataLoader.js +20 -16
- package/dist/esm/hooks/useDashboard.d.ts +1 -1
- package/dist/esm/hooks/useDashboard.d.ts.map +1 -1
- package/dist/esm/hooks/useDashboard.js +19 -5
- package/dist/esm/internals/ReportBuilder/PivotModal.d.ts.map +1 -1
- package/dist/esm/internals/ReportBuilder/PivotModal.js +57 -58
- package/dist/esm/utils/columnProcessing.d.ts +1 -0
- package/dist/esm/utils/columnProcessing.d.ts.map +1 -1
- package/dist/esm/utils/columnProcessing.js +6 -0
- package/dist/esm/utils/dashboard.js +1 -1
- package/dist/esm/utils/dataFetcher.d.ts +1 -1
- package/dist/esm/utils/dataFetcher.d.ts.map +1 -1
- package/dist/esm/utils/dataFetcher.js +9 -4
- package/dist/esm/utils/dates.d.ts +1 -0
- package/dist/esm/utils/dates.d.ts.map +1 -1
- package/dist/esm/utils/dates.js +10 -2
- package/dist/esm/utils/monacoAutocomplete.d.ts +20 -0
- package/dist/esm/utils/monacoAutocomplete.d.ts.map +1 -0
- package/dist/esm/utils/monacoAutocomplete.js +140 -0
- package/dist/esm/utils/pivotConstructor.d.ts.map +1 -1
- package/dist/esm/utils/pivotConstructor.js +58 -5
- package/dist/esm/utils/queryConstructor.d.ts +4 -2
- package/dist/esm/utils/queryConstructor.d.ts.map +1 -1
- package/dist/esm/utils/queryConstructor.js +115 -56
- package/dist/esm/utils/queryConstructor.uspec.d.ts +2 -0
- package/dist/esm/utils/queryConstructor.uspec.d.ts.map +1 -0
- package/dist/esm/utils/queryConstructor.uspec.js +223 -0
- package/dist/esm/utils/tableProcessing.d.ts +1 -0
- package/dist/esm/utils/tableProcessing.d.ts.map +1 -1
- package/dist/esm/utils/tableProcessing.js +41 -5
- package/package.json +1 -1
- package/dist/cjs/internals/ReportBuilder/PivotModal.spec.d.ts +0 -2
- package/dist/cjs/internals/ReportBuilder/PivotModal.spec.d.ts.map +0 -1
- package/dist/cjs/internals/ReportBuilder/PivotModal.spec.js +0 -213
- package/dist/esm/internals/ReportBuilder/PivotModal.spec.d.ts +0 -2
- package/dist/esm/internals/ReportBuilder/PivotModal.spec.d.ts.map +0 -1
- package/dist/esm/internals/ReportBuilder/PivotModal.spec.js +0 -211
|
@@ -41,6 +41,8 @@ const columnProcessing_1 = require("./utils/columnProcessing");
|
|
|
41
41
|
const astProcessing_1 = require("./utils/astProcessing");
|
|
42
42
|
const PivotForm_1 = __importDefault(require("./internals/ReportBuilder/PivotForm"));
|
|
43
43
|
const schema_1 = require("./utils/schema");
|
|
44
|
+
const constants_2 = require("./utils/constants");
|
|
45
|
+
const dates_1 = require("./utils/dates");
|
|
44
46
|
exports.QUILL_SERVER = (typeof process !== 'undefined' && process?.env?.QUILL_SERVER_HOST) ||
|
|
45
47
|
'https://quill-344421.uc.r.appspot.com';
|
|
46
48
|
/**
|
|
@@ -97,6 +99,7 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
97
99
|
const [rows, setRows] = (0, react_1.useState)([]);
|
|
98
100
|
const [formattedRows, setFormattedRows] = (0, react_1.useState)([]);
|
|
99
101
|
const [columns, setColumns] = (0, react_1.useState)([]);
|
|
102
|
+
const [tempReport, setTempReport] = (0, react_1.useState)({});
|
|
100
103
|
const [topLevelBinaryOperator, setTopLevelBinaryOperator] = (0, react_1.useState)('AND');
|
|
101
104
|
const [editPopoverKey, setEditPopoverKey] = (0, react_1.useState)(null);
|
|
102
105
|
const [uniqueValues, setUniqueValues] = (0, react_1.useState)({});
|
|
@@ -122,19 +125,23 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
122
125
|
const [pivotColumnField, setPivotColumnField] = (0, react_1.useState)(undefined);
|
|
123
126
|
const [pivotValueField, setPivotValueField] = (0, react_1.useState)(undefined);
|
|
124
127
|
const [pivotAggregation, setPivotAggregation] = (0, react_1.useState)(undefined);
|
|
128
|
+
const [dateRanges, setDateRanges] = (0, react_1.useState)(null);
|
|
125
129
|
// eslint-disable-next-line no-unused-vars
|
|
126
130
|
const [client, _setClient] = (0, react_1.useContext)(Context_1.ClientContext);
|
|
127
131
|
// JANK: This is temp and stupid
|
|
128
132
|
const [overrideRecommendations, setOverrideRecommendations] = (0, react_1.useState)(true);
|
|
129
133
|
const [customFields, setCustomFields] = (0, react_1.useContext)(Context_1.CustomFieldContext);
|
|
130
134
|
(0, react_1.useEffect)(() => {
|
|
135
|
+
if (!client) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
131
138
|
if (client.publicKey === '663416663aa9bc716e59a89d') {
|
|
132
139
|
setOverrideRecommendations(false);
|
|
133
140
|
}
|
|
134
141
|
if (!loadingSchema) {
|
|
135
142
|
fetchSchema();
|
|
136
143
|
}
|
|
137
|
-
}, [client
|
|
144
|
+
}, [client]);
|
|
138
145
|
(0, react_1.useEffect)(() => {
|
|
139
146
|
(0, width_1.updateFirstChildWidth)(askAIContainerRef, setAskAIInputWidth, { gap: 12 });
|
|
140
147
|
(0, width_1.updateFirstChildWidth)(askAILoadingContainerRef, setAskAILoadingContainerWidth, { gap: 12 });
|
|
@@ -152,8 +159,9 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
152
159
|
window.removeEventListener('resize', handleResize);
|
|
153
160
|
};
|
|
154
161
|
}, []);
|
|
155
|
-
const updatePivot = (changeField, fieldKey) => {
|
|
162
|
+
const updatePivot = async (changeField, fieldKey) => {
|
|
156
163
|
const newPivot = pivot;
|
|
164
|
+
setTableLoading(true);
|
|
157
165
|
// @ts-ignore
|
|
158
166
|
newPivot[fieldKey] = changeField;
|
|
159
167
|
if (fieldKey === 'rowField') {
|
|
@@ -171,11 +179,17 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
171
179
|
newPivot.sort = undefined;
|
|
172
180
|
}
|
|
173
181
|
}
|
|
174
|
-
|
|
175
|
-
const
|
|
182
|
+
let dateBucket = undefined;
|
|
183
|
+
const tempDateRange = dateRanges && dateRanges[newPivot.rowField];
|
|
184
|
+
if (tempDateRange) {
|
|
185
|
+
dateBucket = (0, dates_1.getDateBucketFromRange)(tempDateRange.dateRange);
|
|
186
|
+
}
|
|
187
|
+
const pivotedData = await (0, PivotModal_1.generatePivotTable)(pivot, rows, undefined, false, -1, undefined, dateBucket, tempReport, client, uniqueValues[currentTable]);
|
|
176
188
|
setPivotData(pivotedData || []);
|
|
177
189
|
const formattedRows = formatRows(pivotedData.rows, columns, true, newPivot.aggregationType);
|
|
190
|
+
setPivot(newPivot);
|
|
178
191
|
setFormattedRows(formattedRows);
|
|
192
|
+
setTableLoading(false);
|
|
179
193
|
};
|
|
180
194
|
const enforceOrderOnColumns = (columnNames) => {
|
|
181
195
|
if (pivot) {
|
|
@@ -220,10 +234,13 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
220
234
|
}, 0);
|
|
221
235
|
};
|
|
222
236
|
(0, react_1.useEffect)(() => {
|
|
237
|
+
if (!client) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
223
240
|
if (!initialLoad && client.publicKey) {
|
|
224
241
|
clearAllState();
|
|
225
242
|
}
|
|
226
|
-
}, [client
|
|
243
|
+
}, [client]);
|
|
227
244
|
(0, react_1.useEffect)(() => {
|
|
228
245
|
if (activePath !== null) {
|
|
229
246
|
// update the modal with the new subtree
|
|
@@ -360,6 +377,34 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
360
377
|
console.error(error);
|
|
361
378
|
}
|
|
362
379
|
};
|
|
380
|
+
const getUniqueStringValues = async (columns, tableName) => {
|
|
381
|
+
const convertedStringColumns = columns
|
|
382
|
+
.filter((column) => {
|
|
383
|
+
return (0, ast_1.isTextColumnType)(column.fieldType);
|
|
384
|
+
})
|
|
385
|
+
.map((column) => (0, columnProcessing_1.convertColumnInfoToColumnInternal)(column));
|
|
386
|
+
const stringNames = convertedStringColumns.map((column) => column.field);
|
|
387
|
+
const smallStringColumns = await (0, tableProcessing_1.getCountsByColumns)(convertedStringColumns, `Select ${stringNames.join(', ')} from ${tableName}`, client, customFields);
|
|
388
|
+
const smallStringNames = smallStringColumns.map((column) => column.field);
|
|
389
|
+
const newUniqueValues = await (0, tableProcessing_1.getUniqueValuesByColumns)(smallStringColumns, `Select ${smallStringNames.join(', ')} from ${tableName}`, [], client, customFields);
|
|
390
|
+
const joinedUniqueValues = (0, util_1.deepCopy)(uniqueValues);
|
|
391
|
+
joinedUniqueValues[tableName] = newUniqueValues;
|
|
392
|
+
return joinedUniqueValues;
|
|
393
|
+
};
|
|
394
|
+
const getDateRanges = async (columns, tableName) => {
|
|
395
|
+
const dateColumns = columns.filter((column) => {
|
|
396
|
+
return column.fieldType === 'date';
|
|
397
|
+
});
|
|
398
|
+
if (dateColumns.length === 0) {
|
|
399
|
+
return {};
|
|
400
|
+
}
|
|
401
|
+
const dateColumnNames = dateColumns.map((column) => {
|
|
402
|
+
//@ts-ignore
|
|
403
|
+
return column.field || column.name;
|
|
404
|
+
});
|
|
405
|
+
const dateRanges = await (0, tableProcessing_1.getDateRangeByColumns)(dateColumns, `Select ${dateColumnNames.join(', ')} from ${tableName}`, client, customFields);
|
|
406
|
+
return dateRanges;
|
|
407
|
+
};
|
|
363
408
|
// It's just like getColumnsInPivot but we expand the columnField
|
|
364
409
|
// if there is one to include all the variants just like it would
|
|
365
410
|
// show up in the table. (eg. category -> ...[Fuel, Food, Other])
|
|
@@ -386,18 +431,12 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
386
431
|
setLoading(true);
|
|
387
432
|
const tableInfo = tables.find((tableInfo) => tableInfo.name === initialTableName);
|
|
388
433
|
if (tableInfo) {
|
|
389
|
-
const
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
})
|
|
393
|
-
.map((column) => (0, columnProcessing_1.convertColumnInfoToColumnInternal)(column));
|
|
394
|
-
const stringNames = convertedStringColumns.map((column) => column.field);
|
|
395
|
-
const newUniqueValues = await (0, tableProcessing_1.getUniqueValuesByColumns)(convertedStringColumns, `Select ${stringNames.join(', ')} from ${initialTableName}`, [], client, customFields);
|
|
396
|
-
const joinedUniqueValues = (0, util_1.deepCopy)(uniqueValues);
|
|
397
|
-
joinedUniqueValues[initialTableName] = newUniqueValues;
|
|
398
|
-
if ((0, crypto_1.hashCode)(uniqueValues) !== (0, crypto_1.hashCode)(joinedUniqueValues)) {
|
|
399
|
-
setUniqueValues(joinedUniqueValues);
|
|
434
|
+
const newUniqueValues = await getUniqueStringValues(tableInfo.columns, initialTableName);
|
|
435
|
+
if ((0, crypto_1.hashCode)(uniqueValues) !== (0, crypto_1.hashCode)(newUniqueValues)) {
|
|
436
|
+
setUniqueValues(newUniqueValues);
|
|
400
437
|
}
|
|
438
|
+
const dateRangesTemp = await getDateRanges(tableInfo.columns, initialTableName);
|
|
439
|
+
setDateRanges(dateRangesTemp);
|
|
401
440
|
}
|
|
402
441
|
const columnsForTable = tables
|
|
403
442
|
.find((t) => t.name === initialTableName)
|
|
@@ -489,17 +528,13 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
489
528
|
setBaseAst(newAst);
|
|
490
529
|
const initialRows = await fetchUponChange(newAst, undefined);
|
|
491
530
|
const tableInfo = schemaInfo.find((table) => table.name === tableName);
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
const newUniqueValues = await (0, tableProcessing_1.getUniqueValuesByColumns)(stringColumns, `Select ${stringNames.join(', ')} from ${tableName}`, [], client, customFields);
|
|
500
|
-
const joinedUniqueValues = (0, util_1.deepCopy)(uniqueValues);
|
|
501
|
-
joinedUniqueValues[tableName] = newUniqueValues;
|
|
502
|
-
setUniqueValues(joinedUniqueValues);
|
|
531
|
+
let newUniqueValues = undefined;
|
|
532
|
+
let dateRangesTemp = undefined;
|
|
533
|
+
if (tableName) {
|
|
534
|
+
newUniqueValues = await getUniqueStringValues(tableInfo.columns, tableName);
|
|
535
|
+
setUniqueValues(newUniqueValues);
|
|
536
|
+
dateRangesTemp = await getDateRanges(tableInfo.columns, tableName);
|
|
537
|
+
setDateRanges(dateRangesTemp);
|
|
503
538
|
}
|
|
504
539
|
if (groupByPivot) {
|
|
505
540
|
// @ts-ignore
|
|
@@ -511,9 +546,16 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
511
546
|
// @ts-ignore
|
|
512
547
|
setPivotValueField(groupByPivot.valueField);
|
|
513
548
|
setPivot(groupByPivot);
|
|
514
|
-
|
|
549
|
+
let dateBucket = undefined;
|
|
550
|
+
const tempDateRange = dateRangesTemp &&
|
|
551
|
+
groupByPivot.rowField &&
|
|
552
|
+
dateRangesTemp[groupByPivot.rowField];
|
|
553
|
+
if (tempDateRange) {
|
|
554
|
+
dateBucket = (0, dates_1.getDateBucketFromRange)(tempDateRange.dateRange);
|
|
555
|
+
}
|
|
556
|
+
const pivotedData = await (0, PivotModal_1.generatePivotTable)(
|
|
515
557
|
// @ts-ignore
|
|
516
|
-
groupByPivot, initialRows, undefined,
|
|
558
|
+
groupByPivot, initialRows, tempDateRange, false, -1, undefined, dateBucket, report, client, newUniqueValues[tableName]);
|
|
517
559
|
setPivotData(pivotedData || []);
|
|
518
560
|
const formattedRows = formatRows(pivotedData.rows, report.columns, true,
|
|
519
561
|
// @ts-ignore
|
|
@@ -921,6 +963,89 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
921
963
|
return [{ label: (0, textProcessing_1.snakeAndCamelCaseToTitleCase)(pivot.valueField) }];
|
|
922
964
|
}
|
|
923
965
|
};
|
|
966
|
+
const [previousPage, setPreviousPage] = (0, react_1.useState)(0);
|
|
967
|
+
const [currentProcessing, setCurrentProcessing] = (0, react_1.useState)({
|
|
968
|
+
page: { currentPage: 0, rowsPerPage: 20 },
|
|
969
|
+
});
|
|
970
|
+
const [numberOfRows, setNumberOfRows] = (0, react_1.useState)(0);
|
|
971
|
+
const [tableLoading, setTableLoading] = (0, react_1.useState)(false);
|
|
972
|
+
const onPageChange = (page) => {
|
|
973
|
+
if (pivot) {
|
|
974
|
+
return;
|
|
975
|
+
}
|
|
976
|
+
if ((previousPage < page.currentPage &&
|
|
977
|
+
(page.currentPage * page.rowsPerPage) % constants_2.MAX_COLUMN_ROWS_LIMIT === 0) ||
|
|
978
|
+
(previousPage > page.currentPage &&
|
|
979
|
+
(previousPage * page.rowsPerPage) % constants_2.MAX_COLUMN_ROWS_LIMIT === 0)) {
|
|
980
|
+
handleRunQuery({ ...currentProcessing, page });
|
|
981
|
+
}
|
|
982
|
+
setPreviousPage(page.currentPage);
|
|
983
|
+
};
|
|
984
|
+
const onSortChange = (sort) => {
|
|
985
|
+
if (pivot) {
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
988
|
+
handleRunQuery({ sort, page: { currentPage: 0, rowsPerPage: 20 } });
|
|
989
|
+
setPreviousPage(0);
|
|
990
|
+
};
|
|
991
|
+
const handleRunQuery = async (processing) => {
|
|
992
|
+
try {
|
|
993
|
+
setErrorMessage('');
|
|
994
|
+
setTableLoading(true);
|
|
995
|
+
const hostedBody = {
|
|
996
|
+
metadata: {
|
|
997
|
+
query: activeQuery,
|
|
998
|
+
task: 'query',
|
|
999
|
+
orgId: client.customerId || '*',
|
|
1000
|
+
clientId: client.publicKey,
|
|
1001
|
+
databaseType: client?.databaseType,
|
|
1002
|
+
getCustomFields: !client.customerId || client.customerId === '*' ? false : true,
|
|
1003
|
+
customFieldsByTable: customFields,
|
|
1004
|
+
additionalProcessing: processing,
|
|
1005
|
+
useUpdatedDataGathering: true,
|
|
1006
|
+
},
|
|
1007
|
+
};
|
|
1008
|
+
const cloudBody = { activeQuery };
|
|
1009
|
+
const resp = await (0, dataFetcher_1.getData)(client, 'dashquery', 'same-origin', hostedBody, cloudBody);
|
|
1010
|
+
if (resp && resp.errorMessage) {
|
|
1011
|
+
setTableLoading(false);
|
|
1012
|
+
setErrorMessage('Failed to run SQL query: ' + resp.errorMessage);
|
|
1013
|
+
setRows([]);
|
|
1014
|
+
setColumns([]);
|
|
1015
|
+
return;
|
|
1016
|
+
}
|
|
1017
|
+
if (resp.rowCount) {
|
|
1018
|
+
setNumberOfRows(resp.rowCount);
|
|
1019
|
+
}
|
|
1020
|
+
setErrorMessage('');
|
|
1021
|
+
setCurrentProcessing(processing);
|
|
1022
|
+
if (resp.rows.length === 0) {
|
|
1023
|
+
setErrorMessage('No data found');
|
|
1024
|
+
}
|
|
1025
|
+
const temp_rows = resp.rows && resp.rows.length ? resp.rows : [];
|
|
1026
|
+
const processedFields = resp.fields.map((elem) => (0, columnProcessing_1.convertPostgresColumn)(elem));
|
|
1027
|
+
setRows(temp_rows);
|
|
1028
|
+
// setNumberOfRows(resp.compareRows[0]?.count || temp_rows.length);
|
|
1029
|
+
setFormattedRows(temp_rows.map((row) => {
|
|
1030
|
+
return processedFields.reduce((formattedRow, column) => {
|
|
1031
|
+
// Apply the format function to each field in the row
|
|
1032
|
+
const formattedValue = (0, valueFormatter_1.quillFormat)({
|
|
1033
|
+
value: row[column.field],
|
|
1034
|
+
format: column.format,
|
|
1035
|
+
});
|
|
1036
|
+
formattedRow[column.field] = formattedValue;
|
|
1037
|
+
return formattedRow;
|
|
1038
|
+
}, {});
|
|
1039
|
+
}));
|
|
1040
|
+
setColumns(processedFields);
|
|
1041
|
+
setTableLoading(false);
|
|
1042
|
+
}
|
|
1043
|
+
catch (e) {
|
|
1044
|
+
setTableLoading(false);
|
|
1045
|
+
console.log('ERROR: ', e);
|
|
1046
|
+
return;
|
|
1047
|
+
}
|
|
1048
|
+
};
|
|
924
1049
|
/**
|
|
925
1050
|
* Render form fields based on the type of the node
|
|
926
1051
|
* @param node the AST or subtree to render recursively
|
|
@@ -1786,7 +1911,8 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
1786
1911
|
task: 'patterns',
|
|
1787
1912
|
getCustomFields: false,
|
|
1788
1913
|
customFields,
|
|
1789
|
-
|
|
1914
|
+
additionalProcessing: { page: { currentPage: 0, rowsPerPage: 20 } },
|
|
1915
|
+
useUpdatedDataGathering: true,
|
|
1790
1916
|
},
|
|
1791
1917
|
};
|
|
1792
1918
|
const cloudBody = {};
|
|
@@ -1795,23 +1921,23 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
1795
1921
|
throw new Error(data2.errorMessage);
|
|
1796
1922
|
}
|
|
1797
1923
|
rows = data2.rows;
|
|
1924
|
+
if (data2.rowCount) {
|
|
1925
|
+
setNumberOfRows(data2.rowCount);
|
|
1926
|
+
}
|
|
1798
1927
|
const tables = (0, ast_1.getTableNames)(baseAst);
|
|
1799
1928
|
const table = tables.length >= 1 ? tables[0] : initialTableName;
|
|
1929
|
+
let newUniqueValues = uniqueValues;
|
|
1930
|
+
let dateRangesTemp = dateRanges;
|
|
1931
|
+
let curReport = undefined;
|
|
1800
1932
|
if (table !== currentTable) {
|
|
1801
1933
|
const tableInfo = schema.find((tableInfo) => tableInfo.name === table);
|
|
1802
1934
|
if (tableInfo) {
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
})
|
|
1807
|
-
.map((column) => (0, columnProcessing_1.convertColumnInfoToColumnInternal)(column));
|
|
1808
|
-
const stringNames = convertedStringColumns.map((column) => column.field);
|
|
1809
|
-
const newUniqueValues = await (0, tableProcessing_1.getUniqueValuesByColumns)(convertedStringColumns, `Select ${stringNames.join(', ')} from ${table}`, rows, client, customFields);
|
|
1810
|
-
const joinedUniqueValues = (0, util_1.deepCopy)(uniqueValues);
|
|
1811
|
-
joinedUniqueValues[table] = newUniqueValues;
|
|
1812
|
-
if ((0, crypto_1.hashCode)(uniqueValues) !== (0, crypto_1.hashCode)(joinedUniqueValues)) {
|
|
1813
|
-
setUniqueValues(joinedUniqueValues);
|
|
1935
|
+
newUniqueValues = await getUniqueStringValues(tableInfo.columns, table);
|
|
1936
|
+
if ((0, crypto_1.hashCode)(uniqueValues) !== (0, crypto_1.hashCode)(newUniqueValues)) {
|
|
1937
|
+
setUniqueValues(newUniqueValues);
|
|
1814
1938
|
}
|
|
1939
|
+
dateRangesTemp = await getDateRanges(tableInfo.columns, table);
|
|
1940
|
+
setDateRanges(dateRangesTemp || {});
|
|
1815
1941
|
}
|
|
1816
1942
|
setCurrentTable(table);
|
|
1817
1943
|
}
|
|
@@ -1824,6 +1950,22 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
1824
1950
|
setPivotData(null);
|
|
1825
1951
|
setRows(data2.rows);
|
|
1826
1952
|
setColumns(processedFields);
|
|
1953
|
+
if (data2.rowCount) {
|
|
1954
|
+
const processedFormData = report
|
|
1955
|
+
? report
|
|
1956
|
+
: (0, ChartBuilder_1.createInitialFormData)(processedFields);
|
|
1957
|
+
setNumberOfRows(data2.rowCount);
|
|
1958
|
+
curReport = {
|
|
1959
|
+
...formData,
|
|
1960
|
+
...processedFormData,
|
|
1961
|
+
itemQuery: data2.itemQuery,
|
|
1962
|
+
rowCount: data2.rowCount,
|
|
1963
|
+
filtersApplied: [],
|
|
1964
|
+
rows: data2.rows,
|
|
1965
|
+
columns: processedFields,
|
|
1966
|
+
};
|
|
1967
|
+
setTempReport(curReport);
|
|
1968
|
+
}
|
|
1827
1969
|
const formattedRows = formatRows(data2.rows, processedFields, false);
|
|
1828
1970
|
setFormattedRows(formattedRows);
|
|
1829
1971
|
return;
|
|
@@ -1835,12 +1977,36 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
1835
1977
|
return acc;
|
|
1836
1978
|
}, {});
|
|
1837
1979
|
uniqueFormatted[pivot.columnField] = uniqueRecords;
|
|
1838
|
-
|
|
1980
|
+
let dateBucket = undefined;
|
|
1981
|
+
const tempDateRange = dateRangesTemp &&
|
|
1982
|
+
pivot.rowField &&
|
|
1983
|
+
dateRangesTemp[pivot.rowField];
|
|
1984
|
+
if (tempDateRange) {
|
|
1985
|
+
dateBucket = (0, dates_1.getDateBucketFromRange)(tempDateRange.dateRange);
|
|
1986
|
+
}
|
|
1987
|
+
const pivotedData = await (0, PivotModal_1.generatePivotTable)(
|
|
1988
|
+
// @ts-ignore
|
|
1989
|
+
pivot, data2.rows, undefined, false, -1, undefined, dateBucket, curReport, client, uniqueFormatted[pivot.columnField]);
|
|
1839
1990
|
console.info(`%c[Pivot]: ${JSON.stringify(pivot)}`, 'color: dimgray');
|
|
1840
1991
|
const processedFields = data2.fields.map((elem) => (0, columnProcessing_1.convertPostgresColumn)(elem));
|
|
1841
1992
|
setPivotData(pivotedData);
|
|
1842
1993
|
setRows(data2.rows);
|
|
1843
1994
|
setColumns(processedFields);
|
|
1995
|
+
if (data2.rowCount) {
|
|
1996
|
+
const processedFormData = report
|
|
1997
|
+
? report
|
|
1998
|
+
: (0, ChartBuilder_1.createInitialFormData)(processedFields);
|
|
1999
|
+
setNumberOfRows(data2.rowCount);
|
|
2000
|
+
setTempReport({
|
|
2001
|
+
...formData,
|
|
2002
|
+
...processedFormData,
|
|
2003
|
+
itemQuery: data2.itemQuery,
|
|
2004
|
+
rowCount: data2.rowCount,
|
|
2005
|
+
filtersApplied: [],
|
|
2006
|
+
rows: data2.rows,
|
|
2007
|
+
columns: processedFields,
|
|
2008
|
+
});
|
|
2009
|
+
}
|
|
1844
2010
|
const formattedRows = formatRows(pivotedData.rows, processedFields, true, pivot.aggregationType);
|
|
1845
2011
|
setSelectedColumns(processedFields.map((column) => {
|
|
1846
2012
|
return `${table}.${column.field}`;
|
|
@@ -1851,6 +2017,21 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
1851
2017
|
const processedFields = data2.fields.map((elem) => (0, columnProcessing_1.convertPostgresColumn)(elem));
|
|
1852
2018
|
setRows(data2.rows);
|
|
1853
2019
|
setColumns(processedFields);
|
|
2020
|
+
if (data2.rowCount) {
|
|
2021
|
+
const processedFormData = report
|
|
2022
|
+
? report
|
|
2023
|
+
: (0, ChartBuilder_1.createInitialFormData)(processedFields);
|
|
2024
|
+
setNumberOfRows(data2.rowCount);
|
|
2025
|
+
setTempReport({
|
|
2026
|
+
...formData,
|
|
2027
|
+
...processedFormData,
|
|
2028
|
+
itemQuery: data2.itemQuery,
|
|
2029
|
+
rowCount: data2.rowCount,
|
|
2030
|
+
filtersApplied: [],
|
|
2031
|
+
rows: data2.rows,
|
|
2032
|
+
columns: processedFields,
|
|
2033
|
+
});
|
|
2034
|
+
}
|
|
1854
2035
|
setSelectedColumns(processedFields.map((column) => {
|
|
1855
2036
|
return `${table}.${column.field}`;
|
|
1856
2037
|
}));
|
|
@@ -2085,7 +2266,9 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
2085
2266
|
publicKey: client.publicKey,
|
|
2086
2267
|
orgId: client.customerId,
|
|
2087
2268
|
task: 'patterns',
|
|
2088
|
-
|
|
2269
|
+
additionalProcessing: { page: { currentPage: 0, rowsPerPage: 20 } },
|
|
2270
|
+
useUpdatedDataGathering: true,
|
|
2271
|
+
pivot: groupByPivot,
|
|
2089
2272
|
},
|
|
2090
2273
|
};
|
|
2091
2274
|
const cloudBody = {};
|
|
@@ -2094,20 +2277,16 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
2094
2277
|
throw new Error('Error querying data from patterns');
|
|
2095
2278
|
}
|
|
2096
2279
|
let currentUniqueValues = uniqueValues;
|
|
2280
|
+
let dateRangesTemp = dateRanges;
|
|
2097
2281
|
if (table !== currentTable) {
|
|
2098
2282
|
const tableInfo = schema.find((tableInfo) => tableInfo.name === table);
|
|
2099
2283
|
if (tableInfo) {
|
|
2100
|
-
const
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
})
|
|
2104
|
-
.map((column) => (0, columnProcessing_1.convertColumnInfoToColumnInternal)(column));
|
|
2105
|
-
const stringNames = convertedStringColumns.map((column) => column.field);
|
|
2106
|
-
const newUniqueValues = await (0, tableProcessing_1.getUniqueValuesByColumns)(convertedStringColumns, `Select ${stringNames.join(', ')} from ${table}`, rows, client, customFields);
|
|
2107
|
-
currentUniqueValues[table] = newUniqueValues;
|
|
2108
|
-
if ((0, crypto_1.hashCode)(uniqueValues) !== (0, crypto_1.hashCode)(currentUniqueValues)) {
|
|
2109
|
-
setUniqueValues(currentUniqueValues);
|
|
2284
|
+
const newUniqueValues = await getUniqueStringValues(tableInfo.columns, table);
|
|
2285
|
+
if ((0, crypto_1.hashCode)(uniqueValues) !== (0, crypto_1.hashCode)(newUniqueValues)) {
|
|
2286
|
+
setUniqueValues(newUniqueValues);
|
|
2110
2287
|
}
|
|
2288
|
+
dateRangesTemp = await getDateRanges(tableInfo.columns, table);
|
|
2289
|
+
setDateRanges(dateRangesTemp);
|
|
2111
2290
|
}
|
|
2112
2291
|
setCurrentTable(table);
|
|
2113
2292
|
}
|
|
@@ -2150,15 +2329,43 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
2150
2329
|
errored = true;
|
|
2151
2330
|
}
|
|
2152
2331
|
if (groupByPivot && possiblePivot) {
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2332
|
+
let curReport = report ? report : undefined;
|
|
2333
|
+
if (data2.rowCount) {
|
|
2334
|
+
const processedFormData = report
|
|
2335
|
+
? report
|
|
2336
|
+
: (0, ChartBuilder_1.createInitialFormData)(processedFields);
|
|
2337
|
+
setNumberOfRows(data2.rowCount);
|
|
2338
|
+
curReport = {
|
|
2339
|
+
...formData,
|
|
2340
|
+
...processedFormData,
|
|
2341
|
+
itemQuery: data2.itemQuery,
|
|
2342
|
+
rowCount: data2.rowCount,
|
|
2343
|
+
filtersApplied: [],
|
|
2344
|
+
rows: data2.rows,
|
|
2345
|
+
columns: processedFields,
|
|
2346
|
+
};
|
|
2347
|
+
setTempReport(curReport || null);
|
|
2348
|
+
}
|
|
2349
|
+
let dateBucket = undefined;
|
|
2350
|
+
const tempDateRange = dateRangesTemp &&
|
|
2351
|
+
groupByPivot.rowField &&
|
|
2352
|
+
dateRangesTemp[groupByPivot.rowField];
|
|
2353
|
+
if (tempDateRange) {
|
|
2354
|
+
dateBucket = (0, dates_1.getDateBucketFromRange)(tempDateRange.dateRange);
|
|
2355
|
+
}
|
|
2356
|
+
const pivotedData = await (0, PivotModal_1.generatePivotTable)(
|
|
2357
|
+
// @ts-ignore
|
|
2358
|
+
groupByPivot, data2.rows, undefined, false, -1, undefined, dateBucket, curReport, client, groupByPivot.columnField
|
|
2359
|
+
? currentUniqueValues[groupByPivot.columnField]
|
|
2360
|
+
: undefined);
|
|
2158
2361
|
console.info(`%c[Pivot]: ${JSON.stringify(groupByPivot)}`, 'color: dimgray');
|
|
2159
2362
|
setPivotData(pivotedData);
|
|
2160
2363
|
setPivot(groupByPivot);
|
|
2161
2364
|
setRows(data2.rows);
|
|
2365
|
+
setPivotRowField(groupByPivot?.rowField);
|
|
2366
|
+
setPivotColumnField(groupByPivot?.columnField);
|
|
2367
|
+
setPivotValueField(groupByPivot?.valueField);
|
|
2368
|
+
setPivotAggregation(groupByPivot?.aggregationType);
|
|
2162
2369
|
setColumns(processedFields);
|
|
2163
2370
|
const formattedRows = formatRows(pivotedData.rows, processedFields, true, groupByPivot.aggregationType);
|
|
2164
2371
|
setFormattedRows(formattedRows);
|
|
@@ -2167,6 +2374,17 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
2167
2374
|
const processedFields = data2.fields.map((elem) => (0, columnProcessing_1.convertPostgresColumn)(elem));
|
|
2168
2375
|
setRows(data2.rows);
|
|
2169
2376
|
setColumns(processedFields);
|
|
2377
|
+
if (data2.rowCount) {
|
|
2378
|
+
setNumberOfRows(data2.rowCount);
|
|
2379
|
+
setTempReport({
|
|
2380
|
+
...formData,
|
|
2381
|
+
itemQuery: data2.itemQuery,
|
|
2382
|
+
rowCount: data2.rowCount,
|
|
2383
|
+
filtersApplied: [],
|
|
2384
|
+
rows: data2.rows,
|
|
2385
|
+
columns: processedFields,
|
|
2386
|
+
});
|
|
2387
|
+
}
|
|
2170
2388
|
const formattedRows = formatRows(data2.rows, processedFields, false);
|
|
2171
2389
|
setFormattedRows(formattedRows);
|
|
2172
2390
|
}
|
|
@@ -2441,17 +2659,8 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
2441
2659
|
},
|
|
2442
2660
|
// TODOs
|
|
2443
2661
|
selectPivot: (pivot) => {
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
const newAst = { ...baseAst };
|
|
2447
|
-
newAst.orderby = null;
|
|
2448
|
-
setBaseAst(newAst); // trigger refetch
|
|
2449
|
-
setPivot(pivot);
|
|
2450
|
-
const pivotedData = (0, PivotModal_1.generatePivotTableInMemory)(pivot, rows, undefined, false);
|
|
2451
|
-
setPivotData(pivotedData || []);
|
|
2452
|
-
const formattedRows = formatRows(pivotedData.rows, columns, true, pivot.aggregationType);
|
|
2453
|
-
setFormattedRows(formattedRows);
|
|
2454
|
-
}, selectPivotOnEdit: true, showTrigger: !pivot, theme: theme, LabelComponent: LabelComponent, HeaderComponent: HeaderComponent, dateRange: undefined, pivotCountRequest: 4, SecondaryButtonComponent: SecondaryButtonComponent, query: activeQuery, initialUniqueValues: uniqueValues[currentTable], disabled: !loading && (!baseAst || !dataDisplayed), pivotRecommendationsEnabled: pivotRecommendationsEnabled && overrideRecommendations }), pivot && ((0, jsx_runtime_1.jsx)(PivotForm_1.default, { columns: columns, uniqueValues: uniqueValues[currentTable], setPivotRowField: (value) => {
|
|
2662
|
+
return;
|
|
2663
|
+
}, selectPivotOnEdit: true, showTrigger: !pivot, theme: theme, LabelComponent: LabelComponent, HeaderComponent: HeaderComponent, dateRange: undefined, pivotCountRequest: 4, SecondaryButtonComponent: SecondaryButtonComponent, query: activeQuery, initialUniqueValues: uniqueValues[currentTable], disabled: !loading && (!baseAst || !dataDisplayed), pivotRecommendationsEnabled: pivotRecommendationsEnabled && overrideRecommendations, report: tempReport ?? report }), pivot && ((0, jsx_runtime_1.jsx)(PivotForm_1.default, { columns: columns, uniqueValues: uniqueValues[currentTable], setPivotRowField: (value) => {
|
|
2455
2664
|
setPivotRowField(value);
|
|
2456
2665
|
}, setPivotColumnField: setPivotColumnField, setPivotValueField: setPivotValueField, setPivotAggregation: setPivotAggregation, pivotRowField: pivotRowField, pivotColumnField: pivotColumnField, pivotValueField: pivotValueField, pivotAggregation: pivotAggregation, onDelete: () => {
|
|
2457
2666
|
setPivot(null);
|
|
@@ -2745,7 +2954,7 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
2745
2954
|
setPivotData(null);
|
|
2746
2955
|
const formattedRows = formatRows(rows, columns, false);
|
|
2747
2956
|
setFormattedRows(formattedRows);
|
|
2748
|
-
}, selectPivot: (pivot) => {
|
|
2957
|
+
}, selectPivot: async (pivot, uniqueValues, dateRange, pivotTable) => {
|
|
2749
2958
|
if (!pivot)
|
|
2750
2959
|
return;
|
|
2751
2960
|
const newAst = { ...baseAst };
|
|
@@ -2755,13 +2964,19 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
2755
2964
|
pivot['sortDirection'] = 'ASC';
|
|
2756
2965
|
}
|
|
2757
2966
|
setBaseAst(newAst); // trigger refetch
|
|
2967
|
+
let dateBucket = undefined;
|
|
2968
|
+
if (dateRange) {
|
|
2969
|
+
dateBucket = (0, dates_1.getDateBucketFromRange)(dateRange);
|
|
2970
|
+
}
|
|
2971
|
+
if (!pivotTable) {
|
|
2972
|
+
pivotTable = await (0, PivotModal_1.generatePivotTable)(pivot, rows, undefined, false, -1, undefined, dateBucket, tempReport, client, uniqueValues);
|
|
2973
|
+
}
|
|
2974
|
+
setPivotData(pivotTable || []);
|
|
2758
2975
|
setPivot(pivot);
|
|
2759
|
-
const
|
|
2760
|
-
setPivotData(pivotedData || []);
|
|
2761
|
-
const formattedRows = formatRows(pivotedData.rows, columns, true, pivot.aggregationType);
|
|
2976
|
+
const formattedRows = formatRows(pivotTable.rows, columns, true, pivot.aggregationType);
|
|
2762
2977
|
setFormattedRows(formattedRows);
|
|
2763
2978
|
setErrorMessage('');
|
|
2764
|
-
}, selectPivotOnEdit: true, showTrigger: !pivot, theme: theme, LabelComponent: LabelComponent, HeaderComponent: HeaderComponent, dateRange: undefined, pivotCountRequest: 4, query: activeQuery, initialUniqueValues: uniqueValues[currentTable], disabled: !baseAst || !dataDisplayed, pivotRecommendationsEnabled: pivotRecommendationsEnabled && overrideRecommendations }), pivot && ((0, jsx_runtime_1.jsx)(PivotForm_1.default, { columns: columns, uniqueValues: uniqueValues[currentTable], setPivotRowField: (value) => {
|
|
2979
|
+
}, selectPivotOnEdit: true, showTrigger: !pivot, theme: theme, LabelComponent: LabelComponent, HeaderComponent: HeaderComponent, dateRange: undefined, pivotCountRequest: 4, query: activeQuery, initialUniqueValues: uniqueValues[currentTable], disabled: !baseAst || !dataDisplayed, pivotRecommendationsEnabled: pivotRecommendationsEnabled && overrideRecommendations, report: tempReport }), pivot && ((0, jsx_runtime_1.jsx)(PivotForm_1.default, { columns: columns, uniqueValues: uniqueValues[currentTable], setPivotRowField: (value) => {
|
|
2765
2980
|
setPivotRowField(value);
|
|
2766
2981
|
updatePivot(value, 'rowField');
|
|
2767
2982
|
}, setPivotColumnField: (value) => {
|
|
@@ -2793,10 +3008,18 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
2793
3008
|
`.${pivot.rowField}`,
|
|
2794
3009
|
`.${pivot.valueField || 'count'}`,
|
|
2795
3010
|
]
|
|
2796
|
-
: selectedColumns, setIsPending: setIsPending, setEditPopoverKey: setEditPopoverKey, setActiveEditItem: setActiveEditItem, setActivePath: setActivePath, setOpenPopover: setOpenPopover, SortPopover: SortPopoverComponent, EditPopover: AddSortPopover_1.AddSortPopover, handleDelete: () => {
|
|
3011
|
+
: selectedColumns, setIsPending: setIsPending, setEditPopoverKey: setEditPopoverKey, setActiveEditItem: setActiveEditItem, setActivePath: setActivePath, setOpenPopover: setOpenPopover, SortPopover: SortPopoverComponent, EditPopover: AddSortPopover_1.AddSortPopover, handleDelete: async () => {
|
|
2797
3012
|
if (pivot) {
|
|
2798
|
-
|
|
2799
|
-
|
|
3013
|
+
const tempPivot = { ...pivot, sort: false };
|
|
3014
|
+
let dateBucket = undefined;
|
|
3015
|
+
const tempDateRange = dateRanges &&
|
|
3016
|
+
pivot.rowField &&
|
|
3017
|
+
dateRanges[pivot.rowField];
|
|
3018
|
+
if (tempDateRange) {
|
|
3019
|
+
dateBucket = (0, dates_1.getDateBucketFromRange)(tempDateRange.dateRange);
|
|
3020
|
+
}
|
|
3021
|
+
setPivot(tempPivot);
|
|
3022
|
+
const pivotedData = await (0, PivotModal_1.generatePivotTable)(tempPivot, rows, undefined, false, -1, undefined, dateBucket, tempReport, client, uniqueValues[currentTable]);
|
|
2800
3023
|
setPivotData(pivotedData || []);
|
|
2801
3024
|
const formattedRows = formatRows(pivotedData.rows, columns, true, pivot.aggregationType);
|
|
2802
3025
|
setFormattedRows(formattedRows);
|
|
@@ -2805,25 +3028,27 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
2805
3028
|
}
|
|
2806
3029
|
setBaseAst((0, util_1.deepCopy)(baseAst));
|
|
2807
3030
|
fetchSqlQuery((0, util_1.deepCopy)(baseAst));
|
|
2808
|
-
}, onSave: (column, direction) => {
|
|
3031
|
+
}, onSave: async (column, direction) => {
|
|
2809
3032
|
if (pivot) {
|
|
2810
3033
|
const sortFieldType = column === (pivot.valueField || 'count')
|
|
2811
3034
|
? 'number'
|
|
2812
3035
|
: pivot.rowFieldType;
|
|
2813
|
-
|
|
2814
|
-
...pivot,
|
|
2815
|
-
sort: true,
|
|
2816
|
-
sortDirection: direction,
|
|
2817
|
-
sortField: column,
|
|
2818
|
-
sortFieldType: sortFieldType,
|
|
2819
|
-
});
|
|
2820
|
-
const pivotedData = (0, PivotModal_1.generatePivotTableInMemory)({
|
|
3036
|
+
const tempPivot = {
|
|
2821
3037
|
...pivot,
|
|
2822
3038
|
sort: true,
|
|
2823
3039
|
sortDirection: direction,
|
|
2824
3040
|
sortField: column,
|
|
2825
3041
|
sortFieldType: sortFieldType,
|
|
2826
|
-
}
|
|
3042
|
+
};
|
|
3043
|
+
setPivot(tempPivot);
|
|
3044
|
+
let dateBucket = undefined;
|
|
3045
|
+
const tempDateRange = dateRanges &&
|
|
3046
|
+
pivot.rowField &&
|
|
3047
|
+
dateRanges[pivot.rowField];
|
|
3048
|
+
if (tempDateRange) {
|
|
3049
|
+
dateBucket = (0, dates_1.getDateBucketFromRange)(tempDateRange.dateRange);
|
|
3050
|
+
}
|
|
3051
|
+
const pivotedData = await (0, PivotModal_1.generatePivotTable)(tempPivot, rows, undefined, false, -1, undefined, dateBucket, tempReport, client, uniqueValues[currentTable]);
|
|
2827
3052
|
setPivotData(pivotedData || []);
|
|
2828
3053
|
const formattedRows = formatRows(pivotedData.rows, columns, true, pivot.aggregationType);
|
|
2829
3054
|
setFormattedRows(formattedRows);
|
|
@@ -2904,27 +3129,29 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
2904
3129
|
`.${pivot.rowField}`,
|
|
2905
3130
|
`.${pivot.valueField || 'count'}`,
|
|
2906
3131
|
]
|
|
2907
|
-
: selectedColumns, Select: SelectComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent, onSave: (column, direction) => {
|
|
3132
|
+
: selectedColumns, Select: SelectComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent, onSave: async (column, direction) => {
|
|
2908
3133
|
if (column === '')
|
|
2909
3134
|
return;
|
|
2910
3135
|
if (pivot) {
|
|
2911
3136
|
const sortFieldType = column === (pivot.valueField || 'count')
|
|
2912
3137
|
? 'number'
|
|
2913
3138
|
: pivot.rowFieldType;
|
|
2914
|
-
|
|
3139
|
+
const tempPivot = {
|
|
2915
3140
|
...pivot,
|
|
2916
3141
|
sort: true,
|
|
2917
3142
|
sortDirection: direction,
|
|
2918
3143
|
sortField: column,
|
|
2919
3144
|
sortFieldType: sortFieldType,
|
|
2920
|
-
}
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
3145
|
+
};
|
|
3146
|
+
setPivot(tempPivot);
|
|
3147
|
+
let dateBucket = undefined;
|
|
3148
|
+
const tempDateRange = dateRanges &&
|
|
3149
|
+
pivot.rowField &&
|
|
3150
|
+
dateRanges[pivot.rowField];
|
|
3151
|
+
if (tempDateRange) {
|
|
3152
|
+
dateBucket = (0, dates_1.getDateBucketFromRange)(tempDateRange.dateRange);
|
|
3153
|
+
}
|
|
3154
|
+
const pivotedData = await (0, PivotModal_1.generatePivotTable)(tempPivot, rows, undefined, false, -1, undefined, dateBucket, tempReport, client, uniqueValues[currentTable]);
|
|
2928
3155
|
setErrorMessage('');
|
|
2929
3156
|
setPivotData(pivotedData || []);
|
|
2930
3157
|
const formattedRows = formatRows(pivotedData.rows, columns, true, pivot.aggregationType);
|
|
@@ -3017,14 +3244,16 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
3017
3244
|
? askAIInputWidth
|
|
3018
3245
|
: askAILoadingContainerWidth, onChange: (e) => setAiPrompt(e.target.value), placeholder: askedAQuestion
|
|
3019
3246
|
? 'Ask a follow-up question...'
|
|
3020
|
-
: 'Ask a question...' }), (0, jsx_runtime_1.jsx)(ButtonComponent, { onClick: handleAsk, label: 'Ask AI' }), ((baseAst && dataDisplayed) || initialLoad) && ((0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { label: 'New report', onClick: clearAllState }))] }) })), baseAst && ((0, jsx_runtime_1.jsx)(TableComponent, { isLoading:
|
|
3247
|
+
: 'Ask a question...' }), (0, jsx_runtime_1.jsx)(ButtonComponent, { onClick: handleAsk, label: 'Ask AI' }), ((baseAst && dataDisplayed) || initialLoad) && ((0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { label: 'New report', onClick: clearAllState }))] }) })), baseAst && ((0, jsx_runtime_1.jsx)(TableComponent, { isLoading: tableLoading ||
|
|
3248
|
+
(loading && errorMessage.length === 0) ||
|
|
3249
|
+
initalChartLoad, rows: formattedRows, rowCount: pivot ? undefined : numberOfRows, columns: pivot
|
|
3021
3250
|
? pivotData?.columns || emptyPivotColumns()
|
|
3022
3251
|
: enforceOrderOnColumns(Object.keys(rows[0] ?? {})).map((c) => {
|
|
3023
3252
|
return {
|
|
3024
3253
|
label: (0, textProcessing_1.snakeAndCamelCaseToTitleCase)(c),
|
|
3025
3254
|
field: c,
|
|
3026
3255
|
};
|
|
3027
|
-
}) })), (0, jsx_runtime_1.jsxs)("div", { style: {
|
|
3256
|
+
}), onPageChange: onPageChange, onSortChange: onSortChange })), (0, jsx_runtime_1.jsxs)("div", { style: {
|
|
3028
3257
|
display: 'flex',
|
|
3029
3258
|
flexDirection: 'row',
|
|
3030
3259
|
gap: '12px',
|
|
@@ -3040,6 +3269,7 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
3040
3269
|
}, label: report ? 'Save changes' : 'Add to dashboard' })] }))] })] }), (0, jsx_runtime_1.jsx)("style", { children: `body{margin:0;}` })] })), (!isChartBuilderHorizontalView || isChartBuilderOpen) && ((0, jsx_runtime_1.jsx)(ChartBuilder_1.ChartBuilderWithModal, { report: report
|
|
3041
3270
|
? {
|
|
3042
3271
|
...report,
|
|
3272
|
+
...tempReport,
|
|
3043
3273
|
pivot: pivot,
|
|
3044
3274
|
yAxisFields: report.pivot && !pivot ? [] : report.yAxisFields,
|
|
3045
3275
|
columns: report.columns.filter((col) => {
|
|
@@ -3050,6 +3280,6 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
3050
3280
|
queryString: activeQuery,
|
|
3051
3281
|
rows: rows,
|
|
3052
3282
|
}
|
|
3053
|
-
:
|
|
3283
|
+
: tempReport, rows: rows, columns: columns, pivot: pivot, query: activeQuery, showTableFormatOptions: showChartBuilderTableFormatOptions, showDateFieldOptions: isAdminEnabled, showAccessControlOptions: isAdminEnabled, title: report ? 'Save changes' : 'Add to dashboard', isHorizontalView: true, isOpen: isChartBuilderOpen, setIsOpen: setIsChartBuilderOpen, onAddToDashboardComplete: report ? onSubmitEditReport : onSubmitCreateReport, destinationDashboard: destinationDashboard, organizationName: organizationName, pivotData: pivotData, initialUniqueValues: uniqueValues[currentTable], pivotRecommendationsEnabled: pivotRecommendationsEnabled && overrideRecommendations, SelectComponent: SelectComponent, TextInputComponent: TextInputComponent, ButtonComponent: ButtonComponent, SecondaryButtonComponent: SecondaryButtonComponent, HeaderComponent: HeaderComponent, SubHeaderComponent: SubHeaderComponent, LabelComponent: LabelComponent, TextComponent: TextComponent, CardComponent: CardComponent, ModalComponent: ChartBuilderModalComponent, PopoverComponent: PopoverComponent, TableComponent: TableComponent, DeleteButtonComponent: DeleteButtonComponent, LoadingComponent: LoadingComponent, ChartBuilderInputRowContainer: ChartBuilderInputRowContainer, ChartBuilderInputColumnContainer: ChartBuilderInputColumnContainer, FormContainer: ChartBuilderFormContainer, hideDateRangeFilter: true, buttonLabel: report ? 'Save changes' : 'Add to dashboard', onClickChartElement: onClickChartElement }))] }));
|
|
3054
3284
|
}
|
|
3055
3285
|
exports.default = ReportBuilder;
|