@quillsql/react 2.11.27 → 2.11.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/ChartBuilder.d.ts.map +1 -1
- package/dist/cjs/ChartBuilder.js +81 -48
- package/dist/cjs/ReportBuilder.d.ts +22 -1
- package/dist/cjs/ReportBuilder.d.ts.map +1 -1
- package/dist/cjs/ReportBuilder.js +562 -527
- package/dist/cjs/components/UiComponents.d.ts.map +1 -1
- package/dist/cjs/components/UiComponents.js +0 -1
- package/dist/cjs/internals/ReportBuilder/PivotForm.d.ts +28 -0
- package/dist/cjs/internals/ReportBuilder/PivotForm.d.ts.map +1 -0
- package/dist/cjs/internals/ReportBuilder/PivotForm.js +58 -0
- package/dist/cjs/utils/astProcessing.d.ts +23 -0
- package/dist/cjs/utils/astProcessing.d.ts.map +1 -1
- package/dist/cjs/utils/astProcessing.js +241 -1
- 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 +13 -1
- package/dist/esm/ChartBuilder.d.ts.map +1 -1
- package/dist/esm/ChartBuilder.js +81 -48
- package/dist/esm/ReportBuilder.d.ts +22 -1
- package/dist/esm/ReportBuilder.d.ts.map +1 -1
- package/dist/esm/ReportBuilder.js +563 -528
- package/dist/esm/components/UiComponents.d.ts.map +1 -1
- package/dist/esm/components/UiComponents.js +0 -1
- package/dist/esm/internals/ReportBuilder/PivotForm.d.ts +28 -0
- package/dist/esm/internals/ReportBuilder/PivotForm.d.ts.map +1 -0
- package/dist/esm/internals/ReportBuilder/PivotForm.js +55 -0
- package/dist/esm/utils/astProcessing.d.ts +23 -0
- package/dist/esm/utils/astProcessing.d.ts.map +1 -1
- package/dist/esm/utils/astProcessing.js +231 -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 +11 -0
- package/package.json +1 -1
|
@@ -26,7 +26,6 @@ const constants_1 = require("./components/ReportBuilder/constants");
|
|
|
26
26
|
const AddColumnModal_1 = __importDefault(require("./components/ReportBuilder/AddColumnModal"));
|
|
27
27
|
const AddSortPopover_1 = require("./components/ReportBuilder/AddSortPopover");
|
|
28
28
|
const PivotModal_1 = require("./internals/ReportBuilder/PivotModal");
|
|
29
|
-
const PivotList_1 = require("./internals/ReportBuilder/PivotList");
|
|
30
29
|
const textProcessing_1 = require("./utils/textProcessing");
|
|
31
30
|
const AddLimitPopover_1 = require("./components/ReportBuilder/AddLimitPopover");
|
|
32
31
|
const width_1 = require("./utils/width");
|
|
@@ -40,6 +39,7 @@ const useQuill_1 = require("./hooks/useQuill");
|
|
|
40
39
|
const dataFetcher_2 = require("./utils/dataFetcher");
|
|
41
40
|
const columnProcessing_1 = require("./utils/columnProcessing");
|
|
42
41
|
const astProcessing_1 = require("./utils/astProcessing");
|
|
42
|
+
const PivotForm_1 = __importDefault(require("./internals/ReportBuilder/PivotForm"));
|
|
43
43
|
exports.QUILL_SERVER = process.env.QUILL_SERVER_HOST ?? 'https://quill-344421.uc.r.appspot.com';
|
|
44
44
|
/**
|
|
45
45
|
* Quill Report Builder
|
|
@@ -72,7 +72,7 @@ exports.QUILL_SERVER = process.env.QUILL_SERVER_HOST ?? 'https://quill-344421.uc
|
|
|
72
72
|
* ### Report Builder API
|
|
73
73
|
* @see https://docs.quillsql.com/components/report-builder
|
|
74
74
|
*/
|
|
75
|
-
function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void null, onSubmitCreateReport = (_) => void null, destinationDashboard = undefined, organizationName = '', ButtonComponent = UiComponents_1.MemoizedButton, SecondaryButtonComponent = UiComponents_1.MemoizedSecondaryButton, DeleteButtonComponent = UiComponents_1.MemoizedDeleteButton, ModalComponent = UiComponents_1.MemoizedModal, TextInputComponent = UiComponents_2.QuillTextInput, SelectComponent = QuillSelect_1.QuillSelectComponent, TableComponent = UiComponents_1.QuillTableComponent, PopoverComponent = UiComponents_1.MemoizedPopover, TabsComponent = UiComponents_1.QuillTabs, CheckboxComponent = UiComponents_1.MemoizedCheckbox, SidebarComponent = ui_1.QuillSidebar, ContainerComponent = ui_1.CustomContainer, SelectColumnComponent = ui_1.QuillSelectColumn, DraggableColumnComponent = ui_1.QuillDraggableColumn, SidebarHeadingComponent = ui_1.QuillSidebarHeading, FilterPopoverComponent = ui_1.QuillFilterPopover, SortPopoverComponent = ui_1.QuillSortPopover, LimitPopoverComponent = ui_1.QuillLimitPopover, CardComponent = QuillCard_1.QuillCard, LabelComponent = UiComponents_1.MemoizedLabel, HeaderComponent = UiComponents_1.MemoizedHeader, SubHeaderComponent = UiComponents_1.MemoizedSubHeader, TextComponent = UiComponents_1.MemoizedText, ErrorMessageComponent = UiComponents_1.QuillErrorMessageComponent, ChartBuilderInputRowContainer = UiComponents_1.QuillChartBuilderInputRowContainer, ChartBuilderInputColumnContainer = UiComponents_1.QuillChartBuilderInputColumnContainer, PivotRowContainer = UiComponents_1.QuillPivotRowContainer, PivotColumnContainer = UiComponents_1.QuillPivotColumnContainer, LoadingComponent = UiComponents_1.QuillLoadingComponent, ColumnSearchEmptyState = UiComponents_1.QuillColumnSearchEmptyState, ChartBuilderFormContainer = UiComponents_1.QuillChartBuilderFormContainer, isAdminEnabled = false, isAIEnabled = true, showChartBuilderTableFormatOptions = true, containerStyle, className, pivotRecommendationsEnabled = true, reportId, }) {
|
|
75
|
+
function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void null, onSubmitCreateReport = (_) => void null, destinationDashboard = undefined, organizationName = '', ButtonComponent = UiComponents_1.MemoizedButton, SecondaryButtonComponent = UiComponents_1.MemoizedSecondaryButton, DeleteButtonComponent = UiComponents_1.MemoizedDeleteButton, ModalComponent = UiComponents_1.MemoizedModal, TextInputComponent = UiComponents_2.QuillTextInput, SelectComponent = QuillSelect_1.QuillSelectComponent, TableComponent = UiComponents_1.QuillTableComponent, PopoverComponent = UiComponents_1.MemoizedPopover, TabsComponent = UiComponents_1.QuillTabs, CheckboxComponent = UiComponents_1.MemoizedCheckbox, SidebarComponent = ui_1.QuillSidebar, ContainerComponent = ui_1.CustomContainer, SelectColumnComponent = ui_1.QuillSelectColumn, DraggableColumnComponent = ui_1.QuillDraggableColumn, SidebarHeadingComponent = ui_1.QuillSidebarHeading, FilterPopoverComponent = ui_1.QuillFilterPopover, SortPopoverComponent = ui_1.QuillSortPopover, LimitPopoverComponent = ui_1.QuillLimitPopover, CardComponent = QuillCard_1.QuillCard, LabelComponent = UiComponents_1.MemoizedLabel, HeaderComponent = UiComponents_1.MemoizedHeader, SubHeaderComponent = UiComponents_1.MemoizedSubHeader, TextComponent = UiComponents_1.MemoizedText, ErrorMessageComponent = UiComponents_1.QuillErrorMessageComponent, ChartBuilderInputRowContainer = UiComponents_1.QuillChartBuilderInputRowContainer, ChartBuilderInputColumnContainer = UiComponents_1.QuillChartBuilderInputColumnContainer, PivotRowContainer = UiComponents_1.QuillPivotRowContainer, PivotColumnContainer = UiComponents_1.QuillPivotColumnContainer, LoadingComponent = UiComponents_1.QuillLoadingComponent, ColumnSearchEmptyState = UiComponents_1.QuillColumnSearchEmptyState, ChartBuilderFormContainer = UiComponents_1.QuillChartBuilderFormContainer, ChartBuilderModalComponent = UiComponents_1.MemoizedModal, isAdminEnabled = false, isAIEnabled = true, showChartBuilderTableFormatOptions = true, containerStyle, className, pivotRecommendationsEnabled = true, reportId, hideCopySQL = true, isChartBuilderHorizontalView = true, }) {
|
|
76
76
|
const { data: dashboardItem } = (0, useQuill_1.useQuill)(reportId || '');
|
|
77
77
|
const [aiPrompt, setAiPrompt] = (0, react_1.useState)('');
|
|
78
78
|
const [errorMessage, setErrorMessage] = (0, react_1.useState)('');
|
|
@@ -106,6 +106,7 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
106
106
|
const [showPivotPopover, setShowPivotPopover] = (0, react_1.useState)(false);
|
|
107
107
|
const [isEdittingPivot, setIsEdittingPivot] = (0, react_1.useState)(false);
|
|
108
108
|
const [initalChartLoad, setInitalChartLoad] = (0, react_1.useState)(false);
|
|
109
|
+
const [askedAQuestion, setAskedAQuestion] = (0, react_1.useState)(false);
|
|
109
110
|
const [selectedPivotIndex, setSelectedPivotIndex] = (0, react_1.useState)(-1);
|
|
110
111
|
const [initialLoad, setInitialLoad] = (0, react_1.useState)(!!initialTableName || !!reportId);
|
|
111
112
|
const [currentTable, setCurrentTable] = (0, react_1.useState)(initialTableName || '');
|
|
@@ -145,6 +146,31 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
145
146
|
window.removeEventListener('resize', handleResize);
|
|
146
147
|
};
|
|
147
148
|
}, []);
|
|
149
|
+
const updatePivot = (changeField, fieldKey) => {
|
|
150
|
+
const newPivot = pivot;
|
|
151
|
+
// @ts-ignore
|
|
152
|
+
newPivot[fieldKey] = changeField;
|
|
153
|
+
if (fieldKey === 'rowField') {
|
|
154
|
+
// check to see if the new rowField value is a date field
|
|
155
|
+
const column = columns.find((c) => c.field === changeField);
|
|
156
|
+
if (column?.jsType === 'date') {
|
|
157
|
+
newPivot.rowFieldType = 'date';
|
|
158
|
+
newPivot.sort = 'true';
|
|
159
|
+
newPivot.sortField = changeField;
|
|
160
|
+
newPivot.sortFieldType = column.format;
|
|
161
|
+
newPivot.sortDirection = 'ASC';
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
newPivot.rowFieldType = 'string';
|
|
165
|
+
newPivot.sort = undefined;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
setPivot(newPivot);
|
|
169
|
+
const pivotedData = (0, PivotModal_1.generatePivotTable)(newPivot, rows, undefined, false);
|
|
170
|
+
setPivotData(pivotedData || []);
|
|
171
|
+
const formattedRows = formatRows(pivotedData.rows, columns, true, newPivot.aggregationType);
|
|
172
|
+
setFormattedRows(formattedRows);
|
|
173
|
+
};
|
|
148
174
|
const enforceOrderOnColumns = (columnNames) => {
|
|
149
175
|
if (pivot) {
|
|
150
176
|
const rowName = pivot.rowField;
|
|
@@ -163,6 +189,7 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
163
189
|
// This shouldn't be an issue since the dispatches shouldn't block, but
|
|
164
190
|
// this seems to work for now. ¯\_(ツ)_/¯
|
|
165
191
|
setTimeout(() => {
|
|
192
|
+
setAskedAQuestion(false);
|
|
166
193
|
setAiPrompt('');
|
|
167
194
|
setBaseAst(null);
|
|
168
195
|
setFormData(null);
|
|
@@ -215,7 +242,7 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
215
242
|
}
|
|
216
243
|
else {
|
|
217
244
|
format = valueFormatter_1.DATE_FORMAT_TYPES.includes(column.format)
|
|
218
|
-
? '
|
|
245
|
+
? 'MMM_yyyy'
|
|
219
246
|
: 'string';
|
|
220
247
|
}
|
|
221
248
|
const formattedValue = (0, valueFormatter_1.quillFormat)({
|
|
@@ -374,6 +401,96 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
374
401
|
return null;
|
|
375
402
|
}
|
|
376
403
|
};
|
|
404
|
+
const loadTable = async (tables) => {
|
|
405
|
+
if (!tables)
|
|
406
|
+
return;
|
|
407
|
+
setLoading(true);
|
|
408
|
+
const tableInfo = tables.find((tableInfo) => tableInfo.name === initialTableName);
|
|
409
|
+
if (tableInfo) {
|
|
410
|
+
const convertedStringColumns = tableInfo.columns
|
|
411
|
+
.filter((column) => {
|
|
412
|
+
return (0, ast_1.isTextColumnType)(column.fieldType);
|
|
413
|
+
})
|
|
414
|
+
.map((column) => (0, columnProcessing_1.convertColumnInfoToColumnInternal)(column));
|
|
415
|
+
const stringNames = convertedStringColumns.map((column) => column.field);
|
|
416
|
+
const newUniqueValues = await (0, tableProcessing_1.getUniqueValuesByColumns)(convertedStringColumns, `Select ${stringNames.join(', ')} from ${initialTableName}`, [], client);
|
|
417
|
+
const joinedUniqueValues = (0, util_1.deepCopy)(uniqueValues);
|
|
418
|
+
joinedUniqueValues[initialTableName] = newUniqueValues;
|
|
419
|
+
if ((0, crypto_1.hashCode)(uniqueValues) !== (0, crypto_1.hashCode)(joinedUniqueValues)) {
|
|
420
|
+
setUniqueValues(joinedUniqueValues);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
const columnsForTable = tables
|
|
424
|
+
.find((t) => t.name === initialTableName)
|
|
425
|
+
?.columns.map((c) => c.name)
|
|
426
|
+
.sort((a, b) => {
|
|
427
|
+
const aIsId = a.endsWith('.id') ||
|
|
428
|
+
a.endsWith('_id') ||
|
|
429
|
+
a.endsWith('Id') ||
|
|
430
|
+
a === 'id';
|
|
431
|
+
const bIsId = b.endsWith('.id') ||
|
|
432
|
+
b.endsWith('_id') ||
|
|
433
|
+
b.endsWith('Id') ||
|
|
434
|
+
b === 'id';
|
|
435
|
+
if (aIsId && !bIsId)
|
|
436
|
+
return 1;
|
|
437
|
+
if (bIsId && !aIsId)
|
|
438
|
+
return -1;
|
|
439
|
+
return 0;
|
|
440
|
+
});
|
|
441
|
+
await handleAsk(`get ${columnsForTable} from ${initialTableName}`);
|
|
442
|
+
setInitialLoad(false);
|
|
443
|
+
};
|
|
444
|
+
const fetchSchema = async () => {
|
|
445
|
+
try {
|
|
446
|
+
setLoadingSchema(true);
|
|
447
|
+
const response = await fetch(`${client.queryEndpoint}`, {
|
|
448
|
+
method: 'POST',
|
|
449
|
+
headers: {
|
|
450
|
+
...client.queryHeaders,
|
|
451
|
+
'Content-Type': 'application/json',
|
|
452
|
+
},
|
|
453
|
+
body: JSON.stringify({
|
|
454
|
+
metadata: {
|
|
455
|
+
clientId: client.publicKey,
|
|
456
|
+
publicKey: client.publicKey,
|
|
457
|
+
task: 'schema',
|
|
458
|
+
removeCustomerField: true,
|
|
459
|
+
},
|
|
460
|
+
}),
|
|
461
|
+
});
|
|
462
|
+
const results = await response.json();
|
|
463
|
+
// Filter out hidden columns on tables back from schema2.
|
|
464
|
+
const tables = results.data.tables || results.data.data.tables;
|
|
465
|
+
setSchemaTables(tables ?? []);
|
|
466
|
+
setOrderedColumnNames((tables ?? []).flatMap((table) => table.columns
|
|
467
|
+
.map((c) => `${table.name}.${c.name}`)
|
|
468
|
+
.sort((a, b) => {
|
|
469
|
+
const aIsId = a.endsWith('.id') ||
|
|
470
|
+
a.endsWith('_id') ||
|
|
471
|
+
a.endsWith('Id') ||
|
|
472
|
+
a === 'id';
|
|
473
|
+
const bIsId = b.endsWith('.id') ||
|
|
474
|
+
b.endsWith('_id') ||
|
|
475
|
+
b.endsWith('Id') ||
|
|
476
|
+
b === 'id';
|
|
477
|
+
if (aIsId && !bIsId)
|
|
478
|
+
return 1;
|
|
479
|
+
if (bIsId && !aIsId)
|
|
480
|
+
return -1;
|
|
481
|
+
return 0;
|
|
482
|
+
})));
|
|
483
|
+
if (initialTableName) {
|
|
484
|
+
await loadTable(tables);
|
|
485
|
+
}
|
|
486
|
+
setLoadingSchema(false);
|
|
487
|
+
setInitialLoad(false);
|
|
488
|
+
return tables;
|
|
489
|
+
}
|
|
490
|
+
catch (error) {
|
|
491
|
+
console.error(error);
|
|
492
|
+
}
|
|
493
|
+
};
|
|
377
494
|
(0, react_1.useEffect)(() => {
|
|
378
495
|
const loadChart = async () => {
|
|
379
496
|
setInitalChartLoad(true);
|
|
@@ -388,12 +505,22 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
388
505
|
const resp = await (0, dataFetcher_2.getDataFromCloud)(client, `astify`, {
|
|
389
506
|
query: dashboardItem.queryString,
|
|
390
507
|
});
|
|
391
|
-
const ast =
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
508
|
+
const ast = (0, astProcessing_1.getSelectFromAST)(resp.ast);
|
|
509
|
+
let convertedAst = (0, astProcessing_1.processStarColumn)(ast, dashboardItem.columns);
|
|
510
|
+
(0, astProcessing_1.processApostrophe)(convertedAst, ['type', 'value']);
|
|
511
|
+
convertedAst = (0, convert_1.convertBigQuery)(convertedAst);
|
|
512
|
+
let schemaInfo = schemaTables.length !== 0 ? schemaTables : await fetchSchema();
|
|
513
|
+
let newAst, groupByPivot;
|
|
514
|
+
({ ast: newAst, pivot: groupByPivot } = (0, convert_1.convertGroupBy)(convertedAst,
|
|
515
|
+
// @ts-ignore
|
|
516
|
+
dashboardItem.pivot, schemaInfo));
|
|
517
|
+
if (convertedAst.where) {
|
|
518
|
+
setFormData((0, util_1.deepCopy)(convertedAst.where));
|
|
519
|
+
}
|
|
396
520
|
setActiveQuery(dashboardItem.queryString);
|
|
521
|
+
newAst = groupByPivot ? newAst : convertedAst;
|
|
522
|
+
setBaseAst(newAst);
|
|
523
|
+
const initialRows = await fetchUponChange(newAst, undefined);
|
|
397
524
|
// const initialRows = await handleAsk(dashboardItem.queryString);
|
|
398
525
|
const stringColumns = dashboardItem.columns.filter((column) => {
|
|
399
526
|
return column.format === 'string';
|
|
@@ -405,21 +532,23 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
405
532
|
joinedUniqueValues[tableName] = newUniqueValues;
|
|
406
533
|
setUniqueValues(joinedUniqueValues);
|
|
407
534
|
}
|
|
408
|
-
if (
|
|
535
|
+
if (groupByPivot) {
|
|
536
|
+
// @ts-ignore
|
|
537
|
+
setPivotRowField(groupByPivot.rowField);
|
|
409
538
|
// @ts-ignore
|
|
410
|
-
|
|
539
|
+
setPivotAggregation(groupByPivot.aggregationType);
|
|
411
540
|
// @ts-ignore
|
|
412
|
-
|
|
541
|
+
setPivotColumnField(groupByPivot.columnField);
|
|
413
542
|
// @ts-ignore
|
|
414
|
-
|
|
543
|
+
setPivotValueField(groupByPivot.valueField);
|
|
544
|
+
setPivot(groupByPivot);
|
|
545
|
+
const pivotedData = (0, PivotModal_1.generatePivotTable)(
|
|
415
546
|
// @ts-ignore
|
|
416
|
-
|
|
417
|
-
setPivot(dashboardItem.pivot);
|
|
418
|
-
const pivotedData = (0, PivotModal_1.generatePivotTable)(dashboardItem.pivot, initialRows, undefined, false);
|
|
547
|
+
groupByPivot, initialRows, undefined, false);
|
|
419
548
|
setPivotData(pivotedData || []);
|
|
420
549
|
const formattedRows = formatRows(pivotedData.rows, dashboardItem.columns, true,
|
|
421
550
|
// @ts-ignore
|
|
422
|
-
|
|
551
|
+
groupByPivot.aggregationType);
|
|
423
552
|
setFormattedRows(formattedRows);
|
|
424
553
|
}
|
|
425
554
|
else {
|
|
@@ -437,95 +566,6 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
437
566
|
}
|
|
438
567
|
}, [dashboardItem]);
|
|
439
568
|
(0, react_1.useEffect)(() => {
|
|
440
|
-
const loadTable = async (tables) => {
|
|
441
|
-
if (!tables)
|
|
442
|
-
return;
|
|
443
|
-
setLoading(true);
|
|
444
|
-
const tableInfo = tables.find((tableInfo) => tableInfo.name === initialTableName);
|
|
445
|
-
if (tableInfo) {
|
|
446
|
-
const convertedStringColumns = tableInfo.columns
|
|
447
|
-
.filter((column) => {
|
|
448
|
-
return (0, ast_1.isTextColumnType)(column.fieldType);
|
|
449
|
-
})
|
|
450
|
-
.map((column) => (0, columnProcessing_1.convertColumnInfoToColumnInternal)(column));
|
|
451
|
-
const stringNames = convertedStringColumns.map((column) => column.field);
|
|
452
|
-
const newUniqueValues = await (0, tableProcessing_1.getUniqueValuesByColumns)(convertedStringColumns, `Select ${stringNames.join(', ')} from ${initialTableName}`, [], client);
|
|
453
|
-
const joinedUniqueValues = (0, util_1.deepCopy)(uniqueValues);
|
|
454
|
-
joinedUniqueValues[initialTableName] = newUniqueValues;
|
|
455
|
-
if ((0, crypto_1.hashCode)(uniqueValues) !== (0, crypto_1.hashCode)(joinedUniqueValues)) {
|
|
456
|
-
setUniqueValues(joinedUniqueValues);
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
const columnsForTable = tables
|
|
460
|
-
.find((t) => t.name === initialTableName)
|
|
461
|
-
?.columns.map((c) => c.name)
|
|
462
|
-
.sort((a, b) => {
|
|
463
|
-
const aIsId = a.endsWith('.id') ||
|
|
464
|
-
a.endsWith('_id') ||
|
|
465
|
-
a.endsWith('Id') ||
|
|
466
|
-
a === 'id';
|
|
467
|
-
const bIsId = b.endsWith('.id') ||
|
|
468
|
-
b.endsWith('_id') ||
|
|
469
|
-
b.endsWith('Id') ||
|
|
470
|
-
b === 'id';
|
|
471
|
-
if (aIsId && !bIsId)
|
|
472
|
-
return 1;
|
|
473
|
-
if (bIsId && !aIsId)
|
|
474
|
-
return -1;
|
|
475
|
-
return 0;
|
|
476
|
-
});
|
|
477
|
-
await handleAsk(`get ${columnsForTable} from ${initialTableName}`);
|
|
478
|
-
setInitialLoad(false);
|
|
479
|
-
};
|
|
480
|
-
const fetchSchema = async () => {
|
|
481
|
-
try {
|
|
482
|
-
setLoadingSchema(true);
|
|
483
|
-
const response = await fetch(`${client.queryEndpoint}`, {
|
|
484
|
-
method: 'POST',
|
|
485
|
-
headers: {
|
|
486
|
-
...client.queryHeaders,
|
|
487
|
-
'Content-Type': 'application/json',
|
|
488
|
-
},
|
|
489
|
-
body: JSON.stringify({
|
|
490
|
-
metadata: {
|
|
491
|
-
clientId: client.publicKey,
|
|
492
|
-
publicKey: client.publicKey,
|
|
493
|
-
task: 'schema',
|
|
494
|
-
removeCustomerField: true,
|
|
495
|
-
},
|
|
496
|
-
}),
|
|
497
|
-
});
|
|
498
|
-
const results = await response.json();
|
|
499
|
-
// Filter out hidden columns on tables back from schema2.
|
|
500
|
-
const tables = results.data.tables || results.data.data.tables;
|
|
501
|
-
setSchemaTables(tables ?? []);
|
|
502
|
-
setOrderedColumnNames((tables ?? []).flatMap((table) => table.columns
|
|
503
|
-
.map((c) => `${table.name}.${c.name}`)
|
|
504
|
-
.sort((a, b) => {
|
|
505
|
-
const aIsId = a.endsWith('.id') ||
|
|
506
|
-
a.endsWith('_id') ||
|
|
507
|
-
a.endsWith('Id') ||
|
|
508
|
-
a === 'id';
|
|
509
|
-
const bIsId = b.endsWith('.id') ||
|
|
510
|
-
b.endsWith('_id') ||
|
|
511
|
-
b.endsWith('Id') ||
|
|
512
|
-
b === 'id';
|
|
513
|
-
if (aIsId && !bIsId)
|
|
514
|
-
return 1;
|
|
515
|
-
if (bIsId && !aIsId)
|
|
516
|
-
return -1;
|
|
517
|
-
return 0;
|
|
518
|
-
})));
|
|
519
|
-
if (initialTableName) {
|
|
520
|
-
await loadTable(tables);
|
|
521
|
-
}
|
|
522
|
-
setLoadingSchema(false);
|
|
523
|
-
setInitialLoad(false);
|
|
524
|
-
}
|
|
525
|
-
catch (error) {
|
|
526
|
-
console.error(error);
|
|
527
|
-
}
|
|
528
|
-
};
|
|
529
569
|
if (schemaTables.length === 0) {
|
|
530
570
|
fetchSchema();
|
|
531
571
|
}
|
|
@@ -1973,6 +2013,7 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
1973
2013
|
try {
|
|
1974
2014
|
let errored = false;
|
|
1975
2015
|
setLoading(true);
|
|
2016
|
+
setAskedAQuestion(true);
|
|
1976
2017
|
setErrorMessage('');
|
|
1977
2018
|
let res, data, ast;
|
|
1978
2019
|
let numRetries = 0;
|
|
@@ -2287,20 +2328,23 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
2287
2328
|
if (!openPopover) {
|
|
2288
2329
|
setOpenPopover('AddColumnModal');
|
|
2289
2330
|
}
|
|
2290
|
-
}, label: 'Select columns' }), (0, jsx_runtime_1.jsx)(
|
|
2331
|
+
}, label: 'Select columns' }), (0, jsx_runtime_1.jsx)(ModalComponent, { isOpen: openPopover === 'AddColumnModal', setIsOpen: (isOpen) => {
|
|
2291
2332
|
if (!isOpen) {
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
|
|
2333
|
+
// delay onClose callback so onClick no-ops
|
|
2334
|
+
setTimeout(() => {
|
|
2335
|
+
setIsPending(false);
|
|
2336
|
+
setActiveEditItem(null);
|
|
2337
|
+
setActivePath(null);
|
|
2338
|
+
setOpenPopover(null);
|
|
2339
|
+
}, 100);
|
|
2296
2340
|
}
|
|
2297
|
-
},
|
|
2341
|
+
}, title: "Select columns", children: (0, jsx_runtime_1.jsx)(AddColumnModal_1.default, { onSave: () => {
|
|
2298
2342
|
setActiveEditItem(null);
|
|
2299
2343
|
setActivePath(null);
|
|
2300
2344
|
setOpenPopover(null);
|
|
2301
|
-
}, orderedColumnNames: orderedColumnNames, setOrderedColumnNames: setOrderedColumnNames, selectedColumns: selectedColumns, setSelectedColumns: setSelectedColumns, isSelectedAllColumns: isSelectedAllColumns, clearAllState: clearAllState, nameToColumn: nameToColumn, baseAst: baseAst, setBaseAst: (
|
|
2302
|
-
setBaseAst(
|
|
2303
|
-
fetchSqlQuery(
|
|
2345
|
+
}, orderedColumnNames: orderedColumnNames, setOrderedColumnNames: setOrderedColumnNames, selectedColumns: selectedColumns, setSelectedColumns: setSelectedColumns, isSelectedAllColumns: isSelectedAllColumns, clearAllState: clearAllState, nameToColumn: nameToColumn, baseAst: baseAst, setBaseAst: (ast) => {
|
|
2346
|
+
setBaseAst(ast);
|
|
2347
|
+
fetchSqlQuery(ast);
|
|
2304
2348
|
}, pivot: pivot, initialTableName: initialTableName, defaultAST: constants_1.defaultAST, defaultTable: constants_1.defaultTable, setPivot: setPivot, TextInput: TextInputComponent, SelectColumn: SelectColumnComponent, SecondaryButton: SecondaryButtonComponent, Button: ButtonComponent, ColumnSearchEmptyState: ColumnSearchEmptyState }) })] }), (0, jsx_runtime_1.jsxs)("div", { style: { width: '100%' }, children: [(0, jsx_runtime_1.jsx)(SidebarHeadingComponent, { label: "Filters" }), formData && ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
2305
2349
|
display: 'flex',
|
|
2306
2350
|
flexDirection: 'column',
|
|
@@ -2424,25 +2468,14 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
2424
2468
|
setPivotData(pivotedData || []);
|
|
2425
2469
|
const formattedRows = formatRows(pivotedData.rows, columns, true, pivot.aggregationType);
|
|
2426
2470
|
setFormattedRows(formattedRows);
|
|
2427
|
-
}, 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)(
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
columns: pivotData?.columns || [],
|
|
2431
|
-
}, theme: theme, index: 0, onSelectPivot: () => {
|
|
2432
|
-
setIsEdittingPivot(true);
|
|
2433
|
-
setShowPivotPopover(true);
|
|
2434
|
-
setPivotRowField(pivot?.rowField);
|
|
2435
|
-
setPivotColumnField(pivot?.columnField);
|
|
2436
|
-
setPivotValueField(pivot?.valueField);
|
|
2437
|
-
setPivotAggregation(pivot?.aggregationType);
|
|
2438
|
-
setPivotPopUpTitle('Edit pivot');
|
|
2439
|
-
}, selectedPivotIndex: -1, onEditPivot: () => { }, CardComponent: CardComponent, ButtonComponent: ButtonComponent, HeaderComponent: HeaderComponent, showEdit: false, onClose: () => {
|
|
2471
|
+
}, 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) => {
|
|
2472
|
+
setPivotRowField(value);
|
|
2473
|
+
}, setPivotColumnField: setPivotColumnField, setPivotValueField: setPivotValueField, setPivotAggregation: setPivotAggregation, pivotRowField: pivotRowField, pivotColumnField: pivotColumnField, pivotValueField: pivotValueField, pivotAggregation: pivotAggregation, onDelete: () => {
|
|
2440
2474
|
setPivot(null);
|
|
2441
|
-
setPivotData(
|
|
2475
|
+
setPivotData([]);
|
|
2442
2476
|
const formattedRows = formatRows(rows, columns, false);
|
|
2443
2477
|
setFormattedRows(formattedRows);
|
|
2444
|
-
|
|
2445
|
-
}, minHeight: 180, LabelComponent: LabelComponent, TextComponent: TextComponent }))] }), (0, jsx_runtime_1.jsxs)("div", { style: { width: '100%' }, children: [(0, jsx_runtime_1.jsx)(SidebarHeadingComponent, { label: "Sort" }), pivot && pivot.sort && ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
2478
|
+
}, SecondaryButtonComponent: SecondaryButtonComponent, SelectComponent: SelectComponent, PivotColumnContainer: PivotColumnContainer }))] }), (0, jsx_runtime_1.jsxs)("div", { style: { width: '100%' }, children: [(0, jsx_runtime_1.jsx)(SidebarHeadingComponent, { label: "Sort" }), pivot && pivot.sort && ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
2446
2479
|
display: 'flex',
|
|
2447
2480
|
flexDirection: 'column',
|
|
2448
2481
|
gap: 8,
|
|
@@ -2571,7 +2604,7 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
2571
2604
|
visibility: askAIInputWidth === -1 && askAILoadingContainerWidth === -1
|
|
2572
2605
|
? 'hidden'
|
|
2573
2606
|
: 'visible',
|
|
2574
|
-
}, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(TextInputComponent, { id: "ask_ai_loading_bar", placeholder:
|
|
2607
|
+
}, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(TextInputComponent, { id: "ask_ai_loading_bar", placeholder: askedAQuestion
|
|
2575
2608
|
? 'Ask a follow-up question...'
|
|
2576
2609
|
: 'Ask a question...', width: askAIInputWidth !== -1
|
|
2577
2610
|
? askAIInputWidth
|
|
@@ -2581,443 +2614,445 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
2581
2614
|
display: 'flex',
|
|
2582
2615
|
flexDirection: 'row',
|
|
2583
2616
|
gap: '12px',
|
|
2584
|
-
}, children: [(0, jsx_runtime_1.jsx)("div", { style: { width: '100%' } }), (0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: () => copyToClipboard(activeQuery), label: isCopying ? '✅ Copied' : 'Copy SQL' }), (0, jsx_runtime_1.jsx)(ButtonComponent, { label: dashboardItem ? 'Save changes' : 'Add to dashboard', onClick: () => { } })] }))] })] }), (0, jsx_runtime_1.jsx)("style", { children: `body{margin:0;}` })] }));
|
|
2617
|
+
}, children: [(0, jsx_runtime_1.jsx)("div", { style: { width: '100%' } }), !hideCopySQL && ((0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: () => copyToClipboard(activeQuery), label: isCopying ? '✅ Copied' : 'Copy SQL' })), (0, jsx_runtime_1.jsx)(ButtonComponent, { label: dashboardItem ? 'Save changes' : 'Add to dashboard', onClick: () => { } })] }))] })] }), (0, jsx_runtime_1.jsx)("style", { children: `body{margin:0;}` })] }));
|
|
2585
2618
|
}
|
|
2586
|
-
return ((0, jsx_runtime_1.jsxs)("div", {
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
|
|
2597
|
-
|
|
2598
|
-
}
|
|
2599
|
-
if (!openPopover) {
|
|
2600
|
-
setOpenPopover('AddColumnModal');
|
|
2601
|
-
}
|
|
2602
|
-
}, label: "Select columns" }), (0, jsx_runtime_1.jsx)(ModalComponent, { isOpen: openPopover === 'AddColumnModal', setIsOpen: (isOpen) => {
|
|
2603
|
-
if (!isOpen) {
|
|
2604
|
-
// delay onClose callback so onClick no-ops
|
|
2605
|
-
setTimeout(() => {
|
|
2606
|
-
setIsPending(false);
|
|
2607
|
-
setActiveEditItem(null);
|
|
2608
|
-
setActivePath(null);
|
|
2609
|
-
setOpenPopover(null);
|
|
2610
|
-
}, 100);
|
|
2611
|
-
}
|
|
2612
|
-
}, title: "Select columns", children: (0, jsx_runtime_1.jsx)(AddColumnModal_1.default, { onSave: () => {
|
|
2613
|
-
setActiveEditItem(null);
|
|
2614
|
-
setActivePath(null);
|
|
2615
|
-
setOpenPopover(null);
|
|
2616
|
-
}, orderedColumnNames: orderedColumnNames, setOrderedColumnNames: setOrderedColumnNames, selectedColumns: selectedColumns, setSelectedColumns: setSelectedColumns, isSelectedAllColumns: isSelectedAllColumns, clearAllState: clearAllState, nameToColumn: nameToColumn, baseAst: baseAst, setBaseAst: (ast) => {
|
|
2617
|
-
setBaseAst(ast);
|
|
2618
|
-
fetchSqlQuery(ast);
|
|
2619
|
-
}, pivot: pivot, initialTableName: initialTableName, defaultAST: constants_1.defaultAST, defaultTable: constants_1.defaultTable, setPivot: setPivot, TextInput: TextInputComponent, SelectColumn: SelectColumnComponent, SecondaryButton: SecondaryButtonComponent, Button: ButtonComponent, ColumnSearchEmptyState: ColumnSearchEmptyState }) })] }), (0, jsx_runtime_1.jsxs)("div", { style: { width: '100%' }, children: [(0, jsx_runtime_1.jsx)(SidebarHeadingComponent, { label: "Filters" }), formData && ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
2620
|
-
display: 'flex',
|
|
2621
|
-
flexDirection: 'column',
|
|
2622
|
-
gap: 8,
|
|
2623
|
-
marginBottom: 12,
|
|
2624
|
-
}, children: renderSentence(formData, formData, '', true) })), (0, jsx_runtime_1.jsxs)("div", { style: {
|
|
2625
|
-
display: 'flex',
|
|
2626
|
-
flexDirection: 'column',
|
|
2627
|
-
alignItems: 'flex-start',
|
|
2628
|
-
}, children: [(0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { disabled: !baseAst || !dataDisplayed, onClick: () => {
|
|
2629
|
-
if (!selectedColumns ||
|
|
2630
|
-
selectedColumns.length === 0 ||
|
|
2631
|
-
loading) {
|
|
2619
|
+
return ((0, jsx_runtime_1.jsxs)("div", { style: { backgroundColor: theme.backgroundColor, ...containerStyle }, className: className, children: [(!isChartBuilderHorizontalView ||
|
|
2620
|
+
(isChartBuilderHorizontalView && !isChartBuilderOpen)) && ((0, jsx_runtime_1.jsxs)("div", { ref: parentRef, style: {
|
|
2621
|
+
display: 'flex',
|
|
2622
|
+
flexDirection: 'row',
|
|
2623
|
+
height: '100%',
|
|
2624
|
+
overflowY: 'auto',
|
|
2625
|
+
boxSizing: 'border-box',
|
|
2626
|
+
...containerStyle,
|
|
2627
|
+
}, className: className, children: [(0, jsx_runtime_1.jsxs)(SidebarComponent, { children: [(0, jsx_runtime_1.jsxs)("div", { style: { width: '100%' }, children: [(0, jsx_runtime_1.jsx)(SidebarHeadingComponent, { label: "Columns" }), (0, jsx_runtime_1.jsx)(DraggableColumns, {}), (0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: () => {
|
|
2628
|
+
if (loadingSchema)
|
|
2629
|
+
return;
|
|
2630
|
+
if (!orderedColumnNames) {
|
|
2632
2631
|
return;
|
|
2633
2632
|
}
|
|
2634
2633
|
if (!openPopover) {
|
|
2635
|
-
|
|
2636
|
-
const [_table, column] = value.split('.');
|
|
2637
|
-
const columnType = getColumnTypeByName(column);
|
|
2638
|
-
if ((0, ast_1.isNumericColumnType)(columnType)) {
|
|
2639
|
-
const newSubtree = (0, util_1.deepCopy)(constants_1.defaultNumericComparison);
|
|
2640
|
-
newSubtree.left.column = column;
|
|
2641
|
-
setActiveEditItem(newSubtree);
|
|
2642
|
-
}
|
|
2643
|
-
else {
|
|
2644
|
-
const newSubtree = (0, util_1.deepCopy)(constants_1.defaultEntry);
|
|
2645
|
-
newSubtree.left.args.value[0].column = column;
|
|
2646
|
-
setActiveEditItem(newSubtree);
|
|
2647
|
-
}
|
|
2648
|
-
setOpenPopover('AddFilterPopover');
|
|
2649
|
-
setActivePath('');
|
|
2650
|
-
setIsPending(true);
|
|
2634
|
+
setOpenPopover('AddColumnModal');
|
|
2651
2635
|
}
|
|
2652
|
-
}, label:
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2636
|
+
}, label: "Select columns" }), (0, jsx_runtime_1.jsx)(ModalComponent, { isOpen: openPopover === 'AddColumnModal', setIsOpen: (isOpen) => {
|
|
2637
|
+
if (!isOpen) {
|
|
2638
|
+
// delay onClose callback so onClick no-ops
|
|
2639
|
+
setTimeout(() => {
|
|
2640
|
+
setIsPending(false);
|
|
2641
|
+
setActiveEditItem(null);
|
|
2642
|
+
setActivePath(null);
|
|
2658
2643
|
setOpenPopover(null);
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
clearCheckboxes();
|
|
2683
|
-
setActiveEditItem(null);
|
|
2684
|
-
}, 300);
|
|
2644
|
+
}, 100);
|
|
2645
|
+
}
|
|
2646
|
+
}, title: "Select columns", children: (0, jsx_runtime_1.jsx)(AddColumnModal_1.default, { onSave: () => {
|
|
2647
|
+
setActiveEditItem(null);
|
|
2648
|
+
setActivePath(null);
|
|
2649
|
+
setOpenPopover(null);
|
|
2650
|
+
}, orderedColumnNames: orderedColumnNames, setOrderedColumnNames: setOrderedColumnNames, selectedColumns: selectedColumns, setSelectedColumns: setSelectedColumns, isSelectedAllColumns: isSelectedAllColumns, clearAllState: clearAllState, nameToColumn: nameToColumn, baseAst: baseAst, setBaseAst: (ast) => {
|
|
2651
|
+
setBaseAst(ast);
|
|
2652
|
+
fetchSqlQuery(ast);
|
|
2653
|
+
}, pivot: pivot, initialTableName: initialTableName, defaultAST: constants_1.defaultAST, defaultTable: constants_1.defaultTable, setPivot: setPivot, TextInput: TextInputComponent, SelectColumn: SelectColumnComponent, SecondaryButton: SecondaryButtonComponent, Button: ButtonComponent, ColumnSearchEmptyState: ColumnSearchEmptyState }) })] }), (0, jsx_runtime_1.jsxs)("div", { style: { width: '100%' }, children: [(0, jsx_runtime_1.jsx)(SidebarHeadingComponent, { label: "Filters" }), formData && ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
2654
|
+
display: 'flex',
|
|
2655
|
+
flexDirection: 'column',
|
|
2656
|
+
gap: 8,
|
|
2657
|
+
marginBottom: 12,
|
|
2658
|
+
}, children: renderSentence(formData, formData, '', true) })), (0, jsx_runtime_1.jsxs)("div", { style: {
|
|
2659
|
+
display: 'flex',
|
|
2660
|
+
flexDirection: 'column',
|
|
2661
|
+
alignItems: 'flex-start',
|
|
2662
|
+
}, children: [(0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { disabled: !baseAst || !dataDisplayed, onClick: () => {
|
|
2663
|
+
if (!selectedColumns ||
|
|
2664
|
+
selectedColumns.length === 0 ||
|
|
2665
|
+
loading) {
|
|
2666
|
+
return;
|
|
2685
2667
|
}
|
|
2686
|
-
}, Button: ButtonComponent, renderNode: renderNode, activeEditItem: activeEditItem }) }) }), baseAst?.where &&
|
|
2687
|
-
false && ( // temp removed the AddConditionPopover
|
|
2688
|
-
(0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: () => {
|
|
2689
2668
|
if (!openPopover) {
|
|
2690
|
-
|
|
2691
|
-
|
|
2669
|
+
const value = orderedColumnNames[0];
|
|
2670
|
+
const [_table, column] = value.split('.');
|
|
2671
|
+
const columnType = getColumnTypeByName(column);
|
|
2672
|
+
if ((0, ast_1.isNumericColumnType)(columnType)) {
|
|
2673
|
+
const newSubtree = (0, util_1.deepCopy)(constants_1.defaultNumericComparison);
|
|
2674
|
+
newSubtree.left.column = column;
|
|
2675
|
+
setActiveEditItem(newSubtree);
|
|
2676
|
+
}
|
|
2677
|
+
else {
|
|
2678
|
+
const newSubtree = (0, util_1.deepCopy)(constants_1.defaultEntry);
|
|
2679
|
+
newSubtree.left.args.value[0].column = column;
|
|
2680
|
+
setActiveEditItem(newSubtree);
|
|
2681
|
+
}
|
|
2682
|
+
setOpenPopover('AddFilterPopover');
|
|
2692
2683
|
setActivePath('');
|
|
2693
2684
|
setIsPending(true);
|
|
2694
2685
|
}
|
|
2695
|
-
}, label: 'Add
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
setActivePath(null);
|
|
2702
|
-
setOpenPopover(null);
|
|
2703
|
-
clearCheckboxes();
|
|
2704
|
-
}, 200);
|
|
2705
|
-
}
|
|
2706
|
-
}, popoverChildren: (0, jsx_runtime_1.jsx)(AddConditionPopover, { onSave: () => {
|
|
2707
|
-
if ((0, util_1.isNodeEmptyCollection)(activeEditItem)) {
|
|
2708
|
-
setIsPending(false);
|
|
2709
|
-
setTimeout(() => {
|
|
2710
|
-
setActiveEditItem(null);
|
|
2711
|
-
}, 300);
|
|
2712
|
-
setActivePath(null);
|
|
2686
|
+
}, label: 'Add filter' }), (0, jsx_runtime_1.jsx)("div", { style: {
|
|
2687
|
+
position: 'relative',
|
|
2688
|
+
...(openPopover === 'AddFilterPopover' && { top: 12 }),
|
|
2689
|
+
}, children: (0, jsx_runtime_1.jsx)(PopoverComponent, { isOpen: openPopover === 'AddFilterPopover', setIsOpen: (isOpen) => {
|
|
2690
|
+
if (!isOpen) {
|
|
2691
|
+
// delay onClose callback so onClick no-ops
|
|
2713
2692
|
setOpenPopover(null);
|
|
2714
|
-
clearCheckboxes();
|
|
2715
|
-
}
|
|
2716
|
-
else {
|
|
2717
|
-
setIsPending(false);
|
|
2718
|
-
handleInsertion(activeEditItem, topLevelBinaryOperator, true);
|
|
2719
2693
|
setTimeout(() => {
|
|
2694
|
+
setIsPending(false);
|
|
2695
|
+
setActivePath(null);
|
|
2696
|
+
clearCheckboxes();
|
|
2720
2697
|
setActiveEditItem(null);
|
|
2721
2698
|
}, 300);
|
|
2722
|
-
setActivePath(null);
|
|
2723
|
-
setOpenPopover(null);
|
|
2724
|
-
clearCheckboxes();
|
|
2725
2699
|
}
|
|
2726
|
-
}
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2700
|
+
}, popoverTitle: "Add filter", popoverChildren: (0, jsx_runtime_1.jsx)(ui_1.AddFilterPopover, { onSave: () => {
|
|
2701
|
+
if ((0, util_1.isNodeEmptyCollection)(activeEditItem)) {
|
|
2702
|
+
setOpenPopover(null);
|
|
2703
|
+
clearCheckboxes();
|
|
2704
|
+
setIsPending(false);
|
|
2705
|
+
setTimeout(() => {
|
|
2706
|
+
setActivePath(null);
|
|
2707
|
+
setActiveEditItem(null);
|
|
2708
|
+
}, 300);
|
|
2709
|
+
}
|
|
2710
|
+
else {
|
|
2711
|
+
setOpenPopover(null);
|
|
2712
|
+
setIsPending(false);
|
|
2713
|
+
handleInsertion(activeEditItem, 'AND', false);
|
|
2714
|
+
setActivePath(null);
|
|
2715
|
+
setTimeout(() => {
|
|
2716
|
+
clearCheckboxes();
|
|
2717
|
+
setActiveEditItem(null);
|
|
2718
|
+
}, 300);
|
|
2719
|
+
}
|
|
2720
|
+
}, Button: ButtonComponent, renderNode: renderNode, activeEditItem: activeEditItem }) }) }), baseAst?.where &&
|
|
2721
|
+
false && ( // temp removed the AddConditionPopover
|
|
2722
|
+
(0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: () => {
|
|
2723
|
+
if (!openPopover) {
|
|
2724
|
+
setActiveEditItem((0, util_1.deepCopy)(constants_1.defaultEntry));
|
|
2725
|
+
setOpenPopover('AddConditionPopover');
|
|
2726
|
+
setActivePath('');
|
|
2727
|
+
setIsPending(true);
|
|
2728
|
+
}
|
|
2729
|
+
}, label: 'Add condition' }), (0, jsx_runtime_1.jsx)(PopoverComponent, { isOpen: openPopover === 'AddConditionPopover', setIsOpen: (isOpen) => {
|
|
2730
|
+
if (!isOpen) {
|
|
2731
|
+
// delay onClose callback so onClick no-ops
|
|
2732
|
+
setTimeout(() => {
|
|
2733
|
+
setIsPending(false);
|
|
2734
|
+
setActiveEditItem(null);
|
|
2735
|
+
setActivePath(null);
|
|
2736
|
+
setOpenPopover(null);
|
|
2737
|
+
clearCheckboxes();
|
|
2738
|
+
}, 200);
|
|
2739
|
+
}
|
|
2740
|
+
}, popoverChildren: (0, jsx_runtime_1.jsx)(AddConditionPopover, { onSave: () => {
|
|
2741
|
+
if ((0, util_1.isNodeEmptyCollection)(activeEditItem)) {
|
|
2742
|
+
setIsPending(false);
|
|
2743
|
+
setTimeout(() => {
|
|
2744
|
+
setActiveEditItem(null);
|
|
2745
|
+
}, 300);
|
|
2746
|
+
setActivePath(null);
|
|
2747
|
+
setOpenPopover(null);
|
|
2748
|
+
clearCheckboxes();
|
|
2749
|
+
}
|
|
2750
|
+
else {
|
|
2751
|
+
setIsPending(false);
|
|
2752
|
+
handleInsertion(activeEditItem, topLevelBinaryOperator, true);
|
|
2753
|
+
setTimeout(() => {
|
|
2754
|
+
setActiveEditItem(null);
|
|
2755
|
+
}, 300);
|
|
2756
|
+
setActivePath(null);
|
|
2757
|
+
setOpenPopover(null);
|
|
2758
|
+
clearCheckboxes();
|
|
2759
|
+
}
|
|
2760
|
+
} }) })] }))] })] }), (0, jsx_runtime_1.jsxs)("div", { style: { width: '100%' }, children: [(0, jsx_runtime_1.jsx)(SidebarHeadingComponent, { label: "Pivot" }), (0, jsx_runtime_1.jsx)(PivotModal_1.PivotModal, { pivotRowField: pivotRowField, setPivotRowField: setPivotRowField, pivotColumnField: pivotColumnField, setPivotColumnField: setPivotColumnField, pivotValueField: pivotValueField, setPivotValueField: setPivotValueField, pivotAggregation: pivotAggregation, setPivotAggregation: setPivotAggregation, createdPivots: createdPivots, setCreatedPivots: setCreatedPivots, recommendedPivots: recommendedPivots, setRecommendedPivots: setRecommendedPivots, popUpTitle: pivotPopUpTitle, setPopUpTitle: setPivotPopUpTitle, selectedTable: initialTableName, SelectComponent: SelectComponent, ButtonComponent: ButtonComponent, CardComponent: CardComponent, SecondaryButtonComponent: SecondaryButtonComponent, PopoverComponent: PopoverComponent, TextComponent: TextComponent, ErrorMessageComponent: ErrorMessageComponent, PivotRowContainer: PivotRowContainer, PivotColumnContainer: PivotColumnContainer, LoadingComponent: LoadingComponent, isOpen: showPivotPopover, setIsOpen: setShowPivotPopover, showUpdatePivot: isEdittingPivot, setShowUpdatePivot: setIsEdittingPivot, parentRef: parentRef, data: rows, columns: columns, triggerButtonText: 'Add pivot', selectedPivotIndex: selectedPivotIndex, setSelectedPivotIndex: setSelectedPivotIndex, removePivot: () => {
|
|
2761
|
+
setPivot(null);
|
|
2762
|
+
setPivotData(null);
|
|
2763
|
+
const formattedRows = formatRows(rows, columns, false);
|
|
2786
2764
|
setFormattedRows(formattedRows);
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
setPivot(
|
|
2798
|
-
|
|
2799
|
-
sort: true,
|
|
2800
|
-
sortDirection: direction,
|
|
2801
|
-
sortField: column,
|
|
2802
|
-
sortFieldType: sortFieldType,
|
|
2803
|
-
});
|
|
2804
|
-
const pivotedData = (0, PivotModal_1.generatePivotTable)({
|
|
2805
|
-
...pivot,
|
|
2806
|
-
sort: true,
|
|
2807
|
-
sortDirection: direction,
|
|
2808
|
-
sortField: column,
|
|
2809
|
-
sortFieldType: sortFieldType,
|
|
2810
|
-
}, rows, undefined, false);
|
|
2765
|
+
}, selectPivot: (pivot) => {
|
|
2766
|
+
if (!pivot)
|
|
2767
|
+
return;
|
|
2768
|
+
const newAst = { ...baseAst };
|
|
2769
|
+
newAst.orderby = null;
|
|
2770
|
+
if (pivot.rowFieldType === 'date') {
|
|
2771
|
+
pivot['sort'] = true;
|
|
2772
|
+
pivot['sortDirection'] = 'ASC';
|
|
2773
|
+
}
|
|
2774
|
+
setBaseAst(newAst); // trigger refetch
|
|
2775
|
+
setPivot(pivot);
|
|
2776
|
+
const pivotedData = (0, PivotModal_1.generatePivotTable)(pivot, rows, undefined, false);
|
|
2811
2777
|
setPivotData(pivotedData || []);
|
|
2812
2778
|
const formattedRows = formatRows(pivotedData.rows, columns, true, pivot.aggregationType);
|
|
2813
2779
|
setFormattedRows(formattedRows);
|
|
2814
2780
|
setErrorMessage('');
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
: pivot.
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
},
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
}, popoverTitle: "Sort by", popoverChildren: (0, jsx_runtime_1.jsx)(AddSortPopover_1.AddSortPopover, { columns: pivot
|
|
2885
|
-
? pivot.columnField
|
|
2886
|
-
? [`.${pivot.rowField}`]
|
|
2887
|
-
: [
|
|
2888
|
-
`.${pivot.rowField}`,
|
|
2889
|
-
`.${pivot.valueField || 'count'}`,
|
|
2890
|
-
]
|
|
2891
|
-
: selectedColumns, Select: SelectComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent, onSave: (column, direction) => {
|
|
2892
|
-
if (column === '')
|
|
2893
|
-
return;
|
|
2894
|
-
if (pivot) {
|
|
2895
|
-
const sortFieldType = column === (pivot.valueField || 'count')
|
|
2896
|
-
? 'number'
|
|
2897
|
-
: pivot.rowFieldType;
|
|
2898
|
-
setPivot({
|
|
2899
|
-
...pivot,
|
|
2900
|
-
sort: true,
|
|
2901
|
-
sortDirection: direction,
|
|
2902
|
-
sortField: column,
|
|
2903
|
-
sortFieldType: sortFieldType,
|
|
2904
|
-
});
|
|
2905
|
-
const pivotedData = (0, PivotModal_1.generatePivotTable)({
|
|
2906
|
-
...pivot,
|
|
2907
|
-
sort: true,
|
|
2908
|
-
sortDirection: direction,
|
|
2909
|
-
sortField: column,
|
|
2910
|
-
sortFieldType: sortFieldType,
|
|
2911
|
-
}, rows, undefined, false);
|
|
2912
|
-
setErrorMessage('');
|
|
2913
|
-
setPivotData(pivotedData || []);
|
|
2914
|
-
const formattedRows = formatRows(pivotedData.rows, columns, true, pivot.aggregationType);
|
|
2915
|
-
setFormattedRows(formattedRows);
|
|
2916
|
-
setActivePath(null);
|
|
2781
|
+
}, 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) => {
|
|
2782
|
+
setPivotRowField(value);
|
|
2783
|
+
updatePivot(value, 'rowField');
|
|
2784
|
+
}, setPivotColumnField: (value) => {
|
|
2785
|
+
setPivotColumnField(value);
|
|
2786
|
+
updatePivot(value, 'columnField');
|
|
2787
|
+
}, setPivotValueField: (value) => {
|
|
2788
|
+
setPivotValueField(value);
|
|
2789
|
+
updatePivot(value, 'valueField');
|
|
2790
|
+
}, setPivotAggregation: (value) => {
|
|
2791
|
+
setPivotAggregation(value);
|
|
2792
|
+
updatePivot(value, 'aggregationType');
|
|
2793
|
+
}, onDelete: () => {
|
|
2794
|
+
setPivot(null);
|
|
2795
|
+
setPivotData([]);
|
|
2796
|
+
const formattedRows = formatRows(rows, columns, false);
|
|
2797
|
+
setFormattedRows(formattedRows);
|
|
2798
|
+
}, pivotRowField: pivotRowField, pivotColumnField: pivotColumnField, pivotValueField: pivotValueField, pivotAggregation: pivotAggregation, SecondaryButtonComponent: SecondaryButtonComponent, SelectComponent: SelectComponent, PivotColumnContainer: PivotColumnContainer }))] }), (0, jsx_runtime_1.jsxs)("div", { style: { width: '100%' }, children: [(0, jsx_runtime_1.jsx)(SidebarHeadingComponent, { label: "Sort" }), pivot && pivot.sort && ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
2799
|
+
display: 'flex',
|
|
2800
|
+
flexDirection: 'column',
|
|
2801
|
+
gap: 8,
|
|
2802
|
+
marginBottom: 12,
|
|
2803
|
+
}, children: (0, jsx_runtime_1.jsx)(AddSortPopover_1.SortSentence, { sortData: {
|
|
2804
|
+
type: pivot.sortDirection,
|
|
2805
|
+
expr: { type: 'column_ref', column: pivot.sortField },
|
|
2806
|
+
}, columns: pivot
|
|
2807
|
+
? pivot.columnField
|
|
2808
|
+
? [`.${pivot.rowField}`]
|
|
2809
|
+
: [
|
|
2810
|
+
`.${pivot.rowField}`,
|
|
2811
|
+
`.${pivot.valueField || 'count'}`,
|
|
2812
|
+
]
|
|
2813
|
+
: selectedColumns, setIsPending: setIsPending, setEditPopoverKey: setEditPopoverKey, setActiveEditItem: setActiveEditItem, setActivePath: setActivePath, setOpenPopover: setOpenPopover, SortPopover: SortPopoverComponent, EditPopover: AddSortPopover_1.AddSortPopover, handleDelete: () => {
|
|
2814
|
+
if (pivot) {
|
|
2815
|
+
setPivot({ ...pivot, sort: false });
|
|
2816
|
+
const pivotedData = (0, PivotModal_1.generatePivotTable)({ ...pivot, sort: false }, rows, undefined, false);
|
|
2817
|
+
setPivotData(pivotedData || []);
|
|
2818
|
+
const formattedRows = formatRows(pivotedData.rows, columns, true, pivot.aggregationType);
|
|
2819
|
+
setFormattedRows(formattedRows);
|
|
2820
|
+
setErrorMessage('');
|
|
2821
|
+
return;
|
|
2822
|
+
}
|
|
2823
|
+
setBaseAst((0, util_1.deepCopy)(baseAst));
|
|
2824
|
+
fetchSqlQuery((0, util_1.deepCopy)(baseAst));
|
|
2825
|
+
}, onSave: (column, direction) => {
|
|
2826
|
+
if (pivot) {
|
|
2827
|
+
const sortFieldType = column === (pivot.valueField || 'count')
|
|
2828
|
+
? 'number'
|
|
2829
|
+
: pivot.rowFieldType;
|
|
2830
|
+
setPivot({
|
|
2831
|
+
...pivot,
|
|
2832
|
+
sort: true,
|
|
2833
|
+
sortDirection: direction,
|
|
2834
|
+
sortField: column,
|
|
2835
|
+
sortFieldType: sortFieldType,
|
|
2836
|
+
});
|
|
2837
|
+
const pivotedData = (0, PivotModal_1.generatePivotTable)({
|
|
2838
|
+
...pivot,
|
|
2839
|
+
sort: true,
|
|
2840
|
+
sortDirection: direction,
|
|
2841
|
+
sortField: column,
|
|
2842
|
+
sortFieldType: sortFieldType,
|
|
2843
|
+
}, rows, undefined, false);
|
|
2844
|
+
setPivotData(pivotedData || []);
|
|
2845
|
+
const formattedRows = formatRows(pivotedData.rows, columns, true, pivot.aggregationType);
|
|
2846
|
+
setFormattedRows(formattedRows);
|
|
2847
|
+
setErrorMessage('');
|
|
2848
|
+
return;
|
|
2849
|
+
}
|
|
2917
2850
|
setOpenPopover(null);
|
|
2918
2851
|
setBaseAst((0, util_1.deepCopy)(baseAst));
|
|
2919
|
-
|
|
2920
|
-
}
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
|
|
2852
|
+
fetchSqlQuery((0, util_1.deepCopy)(baseAst));
|
|
2853
|
+
}, Select: SelectComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent }, `sort-sentence-pivot`) })), baseAst && baseAst.orderby && ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
2854
|
+
display: 'flex',
|
|
2855
|
+
flexDirection: 'column',
|
|
2856
|
+
gap: 8,
|
|
2857
|
+
marginBottom: 12,
|
|
2858
|
+
}, children: baseAst.orderby.map((sortData, id) => ((0, jsx_runtime_1.jsx)(AddSortPopover_1.SortSentence, { sortData: sortData, columns: selectedColumns, setIsPending: setIsPending, setEditPopoverKey: setEditPopoverKey, setActiveEditItem: setActiveEditItem, setActivePath: setActivePath, setOpenPopover: setOpenPopover, SortPopover: SortPopoverComponent, EditPopover: AddSortPopover_1.AddSortPopover, handleDelete: () => {
|
|
2859
|
+
if (pivot) {
|
|
2860
|
+
setPivot({ ...pivot, sort: false });
|
|
2861
|
+
return;
|
|
2862
|
+
}
|
|
2863
|
+
const newAst = { ...baseAst };
|
|
2864
|
+
newAst.orderby.splice(id, 1);
|
|
2865
|
+
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2866
|
+
fetchSqlQuery((0, util_1.deepCopy)(newAst));
|
|
2867
|
+
}, onSave: (column, direction) => {
|
|
2868
|
+
if (pivot) {
|
|
2869
|
+
const sortFieldType = column === (pivot.valueField || 'count')
|
|
2870
|
+
? 'number'
|
|
2871
|
+
: pivot.rowFieldType;
|
|
2872
|
+
setPivot({
|
|
2873
|
+
...pivot,
|
|
2874
|
+
sort: true,
|
|
2875
|
+
sortDirection: direction,
|
|
2876
|
+
sortField: column,
|
|
2877
|
+
sortFieldType: sortFieldType,
|
|
2878
|
+
});
|
|
2879
|
+
return;
|
|
2880
|
+
}
|
|
2881
|
+
setIsPending(false);
|
|
2882
|
+
setActiveEditItem(null);
|
|
2883
|
+
setOpenPopover(null);
|
|
2884
|
+
if (column === '')
|
|
2885
|
+
return;
|
|
2886
|
+
const newAst = { ...baseAst };
|
|
2887
|
+
newAst.orderby[id] = {
|
|
2888
|
+
expr: {
|
|
2889
|
+
type: 'column_ref',
|
|
2890
|
+
table: null,
|
|
2891
|
+
column: column,
|
|
2892
|
+
},
|
|
2893
|
+
type: direction,
|
|
2894
|
+
};
|
|
2895
|
+
// look through the columns
|
|
2896
|
+
setActivePath(null);
|
|
2897
|
+
setOpenPopover(null);
|
|
2898
|
+
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2899
|
+
fetchSqlQuery((0, util_1.deepCopy)(newAst));
|
|
2900
|
+
}, Select: SelectComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent }, `sort-sentence-${id}`))) })), (0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { disabled: !baseAst || !dataDisplayed, onClick: () => {
|
|
2958
2901
|
if (!selectedColumns || selectedColumns.length === 0) {
|
|
2959
2902
|
return;
|
|
2960
2903
|
}
|
|
2961
|
-
if (!baseAst) {
|
|
2962
|
-
return;
|
|
2963
|
-
}
|
|
2964
2904
|
if (!openPopover) {
|
|
2965
|
-
setOpenPopover('
|
|
2905
|
+
setOpenPopover('AddSortPopover');
|
|
2966
2906
|
}
|
|
2967
|
-
}, label: 'Add
|
|
2907
|
+
}, label: 'Add sort' }), (0, jsx_runtime_1.jsx)("div", { style: {
|
|
2968
2908
|
position: 'relative',
|
|
2969
|
-
...(openPopover === '
|
|
2970
|
-
}, children: (0, jsx_runtime_1.jsx)(PopoverComponent, { isOpen: openPopover === '
|
|
2909
|
+
...(openPopover === 'AddSortPopover' && { top: 12 }),
|
|
2910
|
+
}, children: (0, jsx_runtime_1.jsx)(PopoverComponent, { isOpen: openPopover === 'AddSortPopover', setIsOpen: (isOpen) => {
|
|
2971
2911
|
if (!isOpen) {
|
|
2972
2912
|
setIsPending(false);
|
|
2973
2913
|
setActiveEditItem(null);
|
|
2974
2914
|
setActivePath(null);
|
|
2975
2915
|
setOpenPopover(null);
|
|
2976
2916
|
}
|
|
2977
|
-
}, popoverTitle: "
|
|
2917
|
+
}, popoverTitle: "Sort by", popoverChildren: (0, jsx_runtime_1.jsx)(AddSortPopover_1.AddSortPopover, { columns: pivot
|
|
2918
|
+
? pivot.columnField
|
|
2919
|
+
? [`.${pivot.rowField}`]
|
|
2920
|
+
: [
|
|
2921
|
+
`.${pivot.rowField}`,
|
|
2922
|
+
`.${pivot.valueField || 'count'}`,
|
|
2923
|
+
]
|
|
2924
|
+
: selectedColumns, Select: SelectComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent, onSave: (column, direction) => {
|
|
2925
|
+
if (column === '')
|
|
2926
|
+
return;
|
|
2927
|
+
if (pivot) {
|
|
2928
|
+
const sortFieldType = column === (pivot.valueField || 'count')
|
|
2929
|
+
? 'number'
|
|
2930
|
+
: pivot.rowFieldType;
|
|
2931
|
+
setPivot({
|
|
2932
|
+
...pivot,
|
|
2933
|
+
sort: true,
|
|
2934
|
+
sortDirection: direction,
|
|
2935
|
+
sortField: column,
|
|
2936
|
+
sortFieldType: sortFieldType,
|
|
2937
|
+
});
|
|
2938
|
+
const pivotedData = (0, PivotModal_1.generatePivotTable)({
|
|
2939
|
+
...pivot,
|
|
2940
|
+
sort: true,
|
|
2941
|
+
sortDirection: direction,
|
|
2942
|
+
sortField: column,
|
|
2943
|
+
sortFieldType: sortFieldType,
|
|
2944
|
+
}, rows, undefined, false);
|
|
2945
|
+
setErrorMessage('');
|
|
2946
|
+
setPivotData(pivotedData || []);
|
|
2947
|
+
const formattedRows = formatRows(pivotedData.rows, columns, true, pivot.aggregationType);
|
|
2948
|
+
setFormattedRows(formattedRows);
|
|
2949
|
+
setActivePath(null);
|
|
2950
|
+
setOpenPopover(null);
|
|
2951
|
+
setBaseAst((0, util_1.deepCopy)(baseAst));
|
|
2952
|
+
return;
|
|
2953
|
+
}
|
|
2978
2954
|
const newAst = { ...baseAst };
|
|
2979
|
-
newAst.
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
};
|
|
2955
|
+
if (!newAst.orderby)
|
|
2956
|
+
newAst.orderby = [];
|
|
2957
|
+
newAst.orderby.push({
|
|
2958
|
+
expr: { type: 'column_ref', column },
|
|
2959
|
+
type: direction,
|
|
2960
|
+
});
|
|
2961
|
+
// look through the columns
|
|
2962
|
+
setActivePath(null);
|
|
2988
2963
|
setOpenPopover(null);
|
|
2989
2964
|
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2990
2965
|
fetchSqlQuery((0, util_1.deepCopy)(newAst));
|
|
2991
|
-
} }) }) })] })
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
2966
|
+
} }) }) })] }), (0, jsx_runtime_1.jsxs)("div", { style: { width: '100%' }, children: [(0, jsx_runtime_1.jsx)(SidebarHeadingComponent, { label: "Limit" }), baseAst && baseAst.limit ? ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
2967
|
+
display: 'flex',
|
|
2968
|
+
flexDirection: 'column',
|
|
2969
|
+
gap: 8,
|
|
2970
|
+
marginBottom: 12,
|
|
2971
|
+
}, children: (0, jsx_runtime_1.jsx)(AddLimitPopover_1.LimitSentence, { limit: baseAst.limit, setOpenPopover: setOpenPopover, LimitPopover: LimitPopoverComponent, EditPopover: AddLimitPopover_1.AddLimitPopover, handleDelete: () => {
|
|
2972
|
+
const newAst = { ...baseAst };
|
|
2973
|
+
newAst.limit = null;
|
|
2974
|
+
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2975
|
+
fetchSqlQuery((0, util_1.deepCopy)(newAst));
|
|
2976
|
+
}, onSave: (limit) => {
|
|
2977
|
+
const newAst = { ...baseAst };
|
|
2978
|
+
newAst.limit = {
|
|
2979
|
+
seperator: '',
|
|
2980
|
+
value: [
|
|
2981
|
+
{
|
|
2982
|
+
type: 'number',
|
|
2983
|
+
value: limit,
|
|
2984
|
+
},
|
|
2985
|
+
],
|
|
2986
|
+
};
|
|
2987
|
+
setOpenPopover(null);
|
|
2988
|
+
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2989
|
+
fetchSqlQuery((0, util_1.deepCopy)(newAst));
|
|
2990
|
+
}, TextInput: TextInputComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent }) })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { disabled: !baseAst || !dataDisplayed, onClick: () => {
|
|
2991
|
+
if (!selectedColumns || selectedColumns.length === 0) {
|
|
2992
|
+
return;
|
|
2993
|
+
}
|
|
2994
|
+
if (!baseAst) {
|
|
2995
|
+
return;
|
|
2996
|
+
}
|
|
2997
|
+
if (!openPopover) {
|
|
2998
|
+
setOpenPopover('AddLimitPopover');
|
|
2999
|
+
}
|
|
3000
|
+
}, label: 'Add limit' }), (0, jsx_runtime_1.jsx)("div", { style: {
|
|
3001
|
+
position: 'relative',
|
|
3002
|
+
...(openPopover === 'AddLimitPopover' && { top: 12 }),
|
|
3003
|
+
}, children: (0, jsx_runtime_1.jsx)(PopoverComponent, { isOpen: openPopover === 'AddLimitPopover', setIsOpen: (isOpen) => {
|
|
3004
|
+
if (!isOpen) {
|
|
3005
|
+
setIsPending(false);
|
|
3006
|
+
setActiveEditItem(null);
|
|
3007
|
+
setActivePath(null);
|
|
3008
|
+
setOpenPopover(null);
|
|
3009
|
+
}
|
|
3010
|
+
}, popoverTitle: "Add limit", popoverChildren: (0, jsx_runtime_1.jsx)(AddLimitPopover_1.AddLimitPopover, { TextInput: TextInputComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent, onSave: (limit) => {
|
|
3011
|
+
const newAst = { ...baseAst };
|
|
3012
|
+
newAst.limit = {
|
|
3013
|
+
seperator: '',
|
|
3014
|
+
value: [
|
|
3015
|
+
{
|
|
3016
|
+
type: 'number',
|
|
3017
|
+
value: Number(limit),
|
|
3018
|
+
},
|
|
3019
|
+
],
|
|
3020
|
+
};
|
|
3021
|
+
setOpenPopover(null);
|
|
3022
|
+
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
3023
|
+
fetchSqlQuery((0, util_1.deepCopy)(newAst));
|
|
3024
|
+
} }) }) })] }))] })] }), (0, jsx_runtime_1.jsxs)(ContainerComponent, { children: [isAIEnabled && ((0, jsx_runtime_1.jsx)("form", { ref: askAIContainerRef, onSubmit: (event) => {
|
|
3025
|
+
event.preventDefault();
|
|
3026
|
+
handleAsk();
|
|
3027
|
+
}, style: {
|
|
3013
3028
|
display: 'flex',
|
|
3014
3029
|
flexDirection: 'row',
|
|
3015
|
-
overflow: 'hidden',
|
|
3016
|
-
width: '100%',
|
|
3017
3030
|
gap: 12,
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3031
|
+
visibility: askAIInputWidth === -1 && askAILoadingContainerWidth === -1
|
|
3032
|
+
? 'hidden'
|
|
3033
|
+
: 'visible',
|
|
3034
|
+
}, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(TextInputComponent, { id: "ask_ai_input_bar", value: aiPrompt, width: askAIInputWidth !== -1
|
|
3035
|
+
? askAIInputWidth
|
|
3036
|
+
: askAILoadingContainerWidth, onChange: (e) => setAiPrompt(e.target.value), placeholder: askedAQuestion
|
|
3037
|
+
? 'Ask a follow-up question...'
|
|
3038
|
+
: '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: (loading && errorMessage.length === 0) || initalChartLoad, rows: formattedRows, columns: pivot
|
|
3039
|
+
? pivotData?.columns || emptyPivotColumns()
|
|
3040
|
+
: enforceOrderOnColumns(Object.keys(rows[0] ?? {})).map((c) => {
|
|
3041
|
+
return { label: (0, textProcessing_1.snakeCaseToTitleCase)(c), field: c };
|
|
3042
|
+
}) })), (0, jsx_runtime_1.jsxs)("div", { style: {
|
|
3043
|
+
display: 'flex',
|
|
3044
|
+
flexDirection: 'row',
|
|
3045
|
+
gap: '12px',
|
|
3046
|
+
width: '100%',
|
|
3047
|
+
}, children: [errorMessage ? ((0, jsx_runtime_1.jsxs)("div", { style: {
|
|
3048
|
+
display: 'flex',
|
|
3049
|
+
flexDirection: 'row',
|
|
3050
|
+
overflow: 'hidden',
|
|
3051
|
+
width: '100%',
|
|
3052
|
+
gap: 12,
|
|
3053
|
+
}, children: [(0, jsx_runtime_1.jsx)(ErrorMessageComponent, { errorMessage: errorMessage }), (0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: handleAsk, label: 'Retry' })] })) : ((0, jsx_runtime_1.jsx)("div", { style: { width: '100%' } })), baseAst && dataDisplayed && !initalChartLoad && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [!hideCopySQL && ((0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { label: isCopying ? '✅ Copied' : 'Copy SQL', onClick: () => copyToClipboard(activeQuery) })), (0, jsx_runtime_1.jsx)(ButtonComponent, { onClick: () => {
|
|
3054
|
+
setIsChartBuilderOpen(true);
|
|
3055
|
+
}, label: dashboardItem ? '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, { dashboardItem: dashboardItem
|
|
3021
3056
|
? {
|
|
3022
3057
|
...dashboardItem,
|
|
3023
3058
|
pivot: pivot,
|
|
@@ -3032,6 +3067,6 @@ function ReportBuilder({ initialTableName = '', onSubmitEditReport = (_) => void
|
|
|
3032
3067
|
queryString: activeQuery,
|
|
3033
3068
|
rows: rows,
|
|
3034
3069
|
}
|
|
3035
|
-
: undefined, rows: rows, columns: columns, pivot: pivot, query: activeQuery, showTableFormatOptions: showChartBuilderTableFormatOptions, showDateFieldOptions: isAdminEnabled, showAccessControlOptions: isAdminEnabled, title: dashboardItem ? 'Save changes' : 'Add to dashboard', isHorizontalView: true, isOpen: isChartBuilderOpen, setIsOpen: setIsChartBuilderOpen, onAddToDashboardComplete: dashboardItem ? 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:
|
|
3070
|
+
: undefined, rows: rows, columns: columns, pivot: pivot, query: activeQuery, showTableFormatOptions: showChartBuilderTableFormatOptions, showDateFieldOptions: isAdminEnabled, showAccessControlOptions: isAdminEnabled, title: dashboardItem ? 'Save changes' : 'Add to dashboard', isHorizontalView: true, isOpen: isChartBuilderOpen, setIsOpen: setIsChartBuilderOpen, onAddToDashboardComplete: dashboardItem ? 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, ChartBuilderInputRowContainer: ChartBuilderInputRowContainer, ChartBuilderInputColumnContainer: ChartBuilderInputColumnContainer, FormContainer: ChartBuilderFormContainer, hideDateRangeFilter: true, buttonLabel: dashboardItem ? 'Save changes' : 'Add to dashboard' }))] }));
|
|
3036
3071
|
}
|
|
3037
3072
|
exports.default = ReportBuilder;
|