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