@quillsql/react 2.11.25 → 2.11.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Chart.d.ts.map +1 -1
- package/dist/cjs/Chart.js +16 -13
- package/dist/cjs/ChartBuilder.d.ts +7 -20
- package/dist/cjs/ChartBuilder.d.ts.map +1 -1
- package/dist/cjs/ChartBuilder.js +25 -25
- package/dist/cjs/ChartEditor.d.ts.map +1 -1
- package/dist/cjs/ChartEditor.js +3 -3
- package/dist/cjs/Dashboard.d.ts +2 -1
- package/dist/cjs/Dashboard.d.ts.map +1 -1
- package/dist/cjs/ReportBuilder.d.ts +11 -5
- package/dist/cjs/ReportBuilder.d.ts.map +1 -1
- package/dist/cjs/ReportBuilder.js +208 -127
- package/dist/cjs/SQLEditor.d.ts +4 -11
- package/dist/cjs/SQLEditor.d.ts.map +1 -1
- package/dist/cjs/SQLEditor.js +57 -124
- package/dist/cjs/Table.d.ts +1 -1
- package/dist/cjs/Table.js +4 -4
- package/dist/cjs/components/Dashboard/DashboardFilter.js +1 -1
- package/dist/cjs/components/Dashboard/MetricComponent.d.ts.map +1 -1
- package/dist/cjs/components/Dashboard/MetricComponent.js +9 -12
- package/dist/cjs/components/Dashboard/TableComponent.d.ts.map +1 -1
- package/dist/cjs/components/Dashboard/TableComponent.js +13 -11
- package/dist/cjs/components/QuillTable.d.ts +6 -3
- package/dist/cjs/components/QuillTable.d.ts.map +1 -1
- package/dist/cjs/components/QuillTable.js +3 -3
- package/dist/cjs/components/ReportBuilder/convert.d.ts +2 -2
- package/dist/cjs/components/ReportBuilder/ui.js +1 -1
- package/dist/cjs/components/UiComponents.d.ts +1 -0
- package/dist/cjs/components/UiComponents.d.ts.map +1 -1
- package/dist/cjs/components/UiComponents.js +17 -1
- package/dist/cjs/internals/ReportBuilder/PivotList.d.ts +27 -24
- package/dist/cjs/internals/ReportBuilder/PivotList.d.ts.map +1 -1
- package/dist/cjs/internals/ReportBuilder/PivotList.js +9 -7
- package/dist/cjs/internals/ReportBuilder/PivotModal.d.ts +11 -3
- package/dist/cjs/internals/ReportBuilder/PivotModal.d.ts.map +1 -1
- package/dist/cjs/internals/ReportBuilder/PivotModal.js +52 -67
- package/dist/cjs/models/Columns.d.ts +11 -0
- package/dist/cjs/models/Columns.d.ts.map +1 -0
- package/dist/cjs/models/Columns.js +2 -0
- package/dist/cjs/models/Tables.d.ts +0 -8
- package/dist/cjs/models/Tables.d.ts.map +1 -1
- package/dist/cjs/utils/astProcessing.d.ts +3 -0
- package/dist/cjs/utils/astProcessing.d.ts.map +1 -0
- package/dist/cjs/utils/astProcessing.js +20 -0
- package/dist/cjs/utils/columnProcessing.d.ts +9 -0
- package/dist/cjs/utils/columnProcessing.d.ts.map +1 -0
- package/dist/cjs/utils/columnProcessing.js +207 -0
- package/dist/cjs/utils/dashboard.js +9 -9
- package/dist/cjs/utils/pivotProcessing.d.ts +2 -1
- package/dist/cjs/utils/pivotProcessing.d.ts.map +1 -1
- package/dist/cjs/utils/pivotProcessing.js +3 -8
- package/dist/cjs/utils/tableProcessing.d.ts +2 -2
- package/dist/cjs/utils/tableProcessing.d.ts.map +1 -1
- package/dist/cjs/utils/tableProcessing.js +1 -3
- package/dist/cjs/utils/valueFormatter.d.ts +2 -1
- package/dist/cjs/utils/valueFormatter.d.ts.map +1 -1
- package/dist/cjs/utils/valueFormatter.js +12 -1
- package/dist/esm/Chart.d.ts.map +1 -1
- package/dist/esm/Chart.js +16 -13
- package/dist/esm/ChartBuilder.d.ts +7 -20
- package/dist/esm/ChartBuilder.d.ts.map +1 -1
- package/dist/esm/ChartBuilder.js +25 -25
- package/dist/esm/ChartEditor.d.ts.map +1 -1
- package/dist/esm/ChartEditor.js +3 -3
- package/dist/esm/Dashboard.d.ts +2 -1
- package/dist/esm/Dashboard.d.ts.map +1 -1
- package/dist/esm/ReportBuilder.d.ts +11 -5
- package/dist/esm/ReportBuilder.d.ts.map +1 -1
- package/dist/esm/ReportBuilder.js +205 -124
- package/dist/esm/SQLEditor.d.ts +4 -11
- package/dist/esm/SQLEditor.d.ts.map +1 -1
- package/dist/esm/SQLEditor.js +57 -123
- package/dist/esm/Table.d.ts +1 -1
- package/dist/esm/Table.js +4 -4
- package/dist/esm/components/Dashboard/DashboardFilter.js +1 -1
- package/dist/esm/components/Dashboard/MetricComponent.d.ts.map +1 -1
- package/dist/esm/components/Dashboard/MetricComponent.js +9 -12
- package/dist/esm/components/Dashboard/TableComponent.d.ts.map +1 -1
- package/dist/esm/components/Dashboard/TableComponent.js +13 -11
- package/dist/esm/components/QuillTable.d.ts +6 -3
- package/dist/esm/components/QuillTable.d.ts.map +1 -1
- package/dist/esm/components/QuillTable.js +3 -3
- package/dist/esm/components/ReportBuilder/convert.d.ts +2 -2
- package/dist/esm/components/ReportBuilder/ui.js +1 -1
- package/dist/esm/components/UiComponents.d.ts +1 -0
- package/dist/esm/components/UiComponents.d.ts.map +1 -1
- package/dist/esm/components/UiComponents.js +15 -0
- package/dist/esm/internals/ReportBuilder/PivotList.d.ts +27 -24
- package/dist/esm/internals/ReportBuilder/PivotList.d.ts.map +1 -1
- package/dist/esm/internals/ReportBuilder/PivotList.js +9 -7
- package/dist/esm/internals/ReportBuilder/PivotModal.d.ts +11 -3
- package/dist/esm/internals/ReportBuilder/PivotModal.d.ts.map +1 -1
- package/dist/esm/internals/ReportBuilder/PivotModal.js +55 -70
- package/dist/esm/models/Columns.d.ts +11 -0
- package/dist/esm/models/Columns.d.ts.map +1 -0
- package/dist/esm/models/Columns.js +1 -0
- package/dist/esm/models/Tables.d.ts +0 -8
- package/dist/esm/models/Tables.d.ts.map +1 -1
- package/dist/esm/utils/astProcessing.d.ts +3 -0
- package/dist/esm/utils/astProcessing.d.ts.map +1 -0
- package/dist/esm/utils/astProcessing.js +16 -0
- package/dist/esm/utils/columnProcessing.d.ts +9 -0
- package/dist/esm/utils/columnProcessing.d.ts.map +1 -0
- package/dist/esm/utils/columnProcessing.js +201 -0
- package/dist/esm/utils/dashboard.js +9 -9
- package/dist/esm/utils/pivotProcessing.d.ts +2 -1
- package/dist/esm/utils/pivotProcessing.d.ts.map +1 -1
- package/dist/esm/utils/pivotProcessing.js +3 -8
- package/dist/esm/utils/tableProcessing.d.ts +2 -2
- package/dist/esm/utils/tableProcessing.d.ts.map +1 -1
- package/dist/esm/utils/tableProcessing.js +1 -3
- package/dist/esm/utils/valueFormatter.d.ts +2 -1
- package/dist/esm/utils/valueFormatter.d.ts.map +1 -1
- package/dist/esm/utils/valueFormatter.js +11 -0
- package/package.json +1 -1
- package/dist/cjs/utils/types.d.ts +0 -4
- package/dist/cjs/utils/types.d.ts.map +0 -1
- package/dist/cjs/utils/types.js +0 -52
- package/dist/cjs/utils/valueFormatterCSV.d.ts +0 -17
- package/dist/cjs/utils/valueFormatterCSV.d.ts.map +0 -1
- package/dist/cjs/utils/valueFormatterCSV.js +0 -99
- package/dist/esm/utils/types.d.ts +0 -4
- package/dist/esm/utils/types.d.ts.map +0 -1
- package/dist/esm/utils/types.js +0 -48
- package/dist/esm/utils/valueFormatterCSV.d.ts +0 -17
- package/dist/esm/utils/valueFormatterCSV.d.ts.map +0 -1
- package/dist/esm/utils/valueFormatterCSV.js +0 -95
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
/* eslint-disable no-unused-vars */
|
|
3
3
|
import { useContext, useEffect, useRef, useState, } from 'react';
|
|
4
|
-
import { DEFAULT_TAB_OPTIONS, MemoizedButton, MemoizedCheckbox, MemoizedDeleteButton, MemoizedHeader, MemoizedLabel, MemoizedSecondaryButton, MemoizedText, MemoizedPopover, QuillTableComponent, QuillTabs, MemoizedModal, QuillChartBuilderInputRowContainer, QuillChartBuilderInputColumnContainer, MemoizedSubHeader, QuillErrorMessageComponent, QuillPivotRowContainer, QuillPivotColumnContainer, QuillColumnSearchEmptyState, QuillChartBuilderFormContainer, } from './components/UiComponents';
|
|
4
|
+
import { DEFAULT_TAB_OPTIONS, MemoizedButton, MemoizedCheckbox, MemoizedDeleteButton, MemoizedHeader, MemoizedLabel, MemoizedSecondaryButton, MemoizedText, MemoizedPopover, QuillTableComponent, QuillTabs, MemoizedModal, QuillChartBuilderInputRowContainer, QuillChartBuilderInputColumnContainer, MemoizedSubHeader, QuillErrorMessageComponent, QuillPivotRowContainer, QuillPivotColumnContainer, QuillColumnSearchEmptyState, QuillChartBuilderFormContainer, QuillLoadingComponent, } from './components/UiComponents';
|
|
5
5
|
import { DndContext, closestCenter, KeyboardSensor, PointerSensor, useSensor, useSensors, } from '@dnd-kit/core';
|
|
6
6
|
import { arrayMove, SortableContext, sortableKeyboardCoordinates, verticalListSortingStrategy, useSortable, } from '@dnd-kit/sortable';
|
|
7
7
|
import { CSS as DND_CSS } from '@dnd-kit/utilities';
|
|
@@ -26,12 +26,14 @@ import { AddLimitPopover, LimitSentence, } from './components/ReportBuilder/AddL
|
|
|
26
26
|
import { updateFirstChildWidth } from './utils/width';
|
|
27
27
|
import { QuillSelectComponent } from './components/QuillSelect';
|
|
28
28
|
import { QuillCard } from './components/QuillCard';
|
|
29
|
-
import { convertPostgresColumn } from './SQLEditor';
|
|
30
29
|
import { getData } from './utils/dataFetcher';
|
|
31
|
-
import { quillFormat } from './utils/valueFormatter';
|
|
30
|
+
import { DATE_FORMAT_TYPES, quillFormat } from './utils/valueFormatter';
|
|
32
31
|
import { getPossiblePivotFieldOptions } from './utils/pivotProcessing';
|
|
33
32
|
import { getUniqueValuesByColumns } from './utils/tableProcessing';
|
|
34
33
|
import { useQuill } from './hooks/useQuill';
|
|
34
|
+
import { getDataFromCloud } from './utils/dataFetcher';
|
|
35
|
+
import { convertColumnInfoToColumnInternal, convertPostgresColumn, } from './utils/columnProcessing';
|
|
36
|
+
import { processStarColumn } from './utils/astProcessing';
|
|
35
37
|
export const QUILL_SERVER = process.env.QUILL_SERVER_HOST ?? 'https://quill-344421.uc.r.appspot.com';
|
|
36
38
|
/**
|
|
37
39
|
* Quill Report Builder
|
|
@@ -64,8 +66,8 @@ export const QUILL_SERVER = process.env.QUILL_SERVER_HOST ?? 'https://quill-3444
|
|
|
64
66
|
* ### Report Builder API
|
|
65
67
|
* @see https://docs.quillsql.com/components/report-builder
|
|
66
68
|
*/
|
|
67
|
-
export default function ReportBuilder({ initialTableName = '',
|
|
68
|
-
const { data:
|
|
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, }) {
|
|
70
|
+
const { data: dashboardItem } = useQuill(reportId || '');
|
|
69
71
|
const [aiPrompt, setAiPrompt] = useState('');
|
|
70
72
|
const [errorMessage, setErrorMessage] = useState('');
|
|
71
73
|
const [baseAst, setBaseAst] = useState(null);
|
|
@@ -86,7 +88,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
86
88
|
const [dataDisplayed, setDataDisplayed] = useState(false);
|
|
87
89
|
const [rows, setRows] = useState([]);
|
|
88
90
|
const [formattedRows, setFormattedRows] = useState([]);
|
|
89
|
-
const [
|
|
91
|
+
const [columns, setColumns] = useState([]);
|
|
90
92
|
const [topLevelBinaryOperator, setTopLevelBinaryOperator] = useState('AND');
|
|
91
93
|
const [editPopoverKey, setEditPopoverKey] = useState(null);
|
|
92
94
|
const [uniqueValues, setUniqueValues] = useState({});
|
|
@@ -97,8 +99,9 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
97
99
|
const [pivotPopUpTitle, setPivotPopUpTitle] = useState('Add pivot');
|
|
98
100
|
const [showPivotPopover, setShowPivotPopover] = useState(false);
|
|
99
101
|
const [isEdittingPivot, setIsEdittingPivot] = useState(false);
|
|
102
|
+
const [initalChartLoad, setInitalChartLoad] = useState(false);
|
|
100
103
|
const [selectedPivotIndex, setSelectedPivotIndex] = useState(-1);
|
|
101
|
-
const [initialLoad, setInitialLoad] = useState(!!initialTableName || !!
|
|
104
|
+
const [initialLoad, setInitialLoad] = useState(!!initialTableName || !!reportId);
|
|
102
105
|
const [currentTable, setCurrentTable] = useState(initialTableName || '');
|
|
103
106
|
const parentRef = useRef(null);
|
|
104
107
|
const askAIContainerRef = useRef(null);
|
|
@@ -168,7 +171,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
168
171
|
setIsPending(false);
|
|
169
172
|
setDataDisplayed(false);
|
|
170
173
|
setRows([]);
|
|
171
|
-
|
|
174
|
+
setColumns([]);
|
|
172
175
|
setTopLevelBinaryOperator('AND');
|
|
173
176
|
setEditPopoverKey(null);
|
|
174
177
|
setErrorMessage('');
|
|
@@ -190,6 +193,50 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
190
193
|
setActiveEditItem(getByKey(formData, activePath));
|
|
191
194
|
}
|
|
192
195
|
}, [formData]);
|
|
196
|
+
const formatRows = (rows, columns, pivot, aggregationType) => {
|
|
197
|
+
const copiedRows = deepCopy(rows);
|
|
198
|
+
if (pivot) {
|
|
199
|
+
const formattedRows = copiedRows.map((row) => {
|
|
200
|
+
const formattedRow = row;
|
|
201
|
+
Object.keys(row).forEach((key, index) => {
|
|
202
|
+
let column = columns.find((c) => c.field === key);
|
|
203
|
+
let format = 'string';
|
|
204
|
+
if (!column) {
|
|
205
|
+
format =
|
|
206
|
+
aggregationType === 'count'
|
|
207
|
+
? 'whole_number'
|
|
208
|
+
: 'two_decimal_places';
|
|
209
|
+
}
|
|
210
|
+
else {
|
|
211
|
+
format = DATE_FORMAT_TYPES.includes(column.format)
|
|
212
|
+
? 'date'
|
|
213
|
+
: 'string';
|
|
214
|
+
}
|
|
215
|
+
const formattedValue = quillFormat({
|
|
216
|
+
value: row[key],
|
|
217
|
+
format,
|
|
218
|
+
});
|
|
219
|
+
formattedRow[key] = formattedValue;
|
|
220
|
+
});
|
|
221
|
+
return formattedRow;
|
|
222
|
+
});
|
|
223
|
+
return formattedRows;
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
const formattedRows = copiedRows.map((row) => {
|
|
227
|
+
return columns.reduce((formattedRow, column) => {
|
|
228
|
+
// Apply the format function to each field in the row
|
|
229
|
+
const formattedValue = quillFormat({
|
|
230
|
+
value: row[column.field],
|
|
231
|
+
format: column.format,
|
|
232
|
+
});
|
|
233
|
+
formattedRow[column.field] = formattedValue;
|
|
234
|
+
return formattedRow;
|
|
235
|
+
}, {});
|
|
236
|
+
});
|
|
237
|
+
return formattedRows;
|
|
238
|
+
}
|
|
239
|
+
};
|
|
193
240
|
const getByKey = (formData, path) => {
|
|
194
241
|
if (!path)
|
|
195
242
|
return deepCopy(formData);
|
|
@@ -259,7 +306,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
259
306
|
const data = await response.json();
|
|
260
307
|
setActiveQuery(data.query);
|
|
261
308
|
if (fetchData) {
|
|
262
|
-
fetchUponChange(ast, formData
|
|
309
|
+
fetchUponChange(ast, formData);
|
|
263
310
|
}
|
|
264
311
|
}
|
|
265
312
|
catch (error) {
|
|
@@ -323,42 +370,80 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
323
370
|
};
|
|
324
371
|
useEffect(() => {
|
|
325
372
|
const loadChart = async () => {
|
|
326
|
-
|
|
373
|
+
setInitalChartLoad(true);
|
|
374
|
+
if (!dashboardItem || dashboardItem.referencedTables.length !== 1) {
|
|
375
|
+
setInitalChartLoad(false);
|
|
327
376
|
return;
|
|
328
377
|
}
|
|
329
|
-
const
|
|
330
|
-
if (
|
|
378
|
+
const tableName = dashboardItem.referencedTables[0];
|
|
379
|
+
if (!tableName) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
const resp = await getDataFromCloud(client, `astify`, {
|
|
383
|
+
query: dashboardItem.queryString,
|
|
384
|
+
});
|
|
385
|
+
const ast = resp.ast.select ? resp.ast.select : resp.ast;
|
|
386
|
+
const initialRows = await fetchUponChange(ast, undefined);
|
|
387
|
+
const convertedAst = processStarColumn(ast, dashboardItem.columns);
|
|
388
|
+
setBaseAst(convertedAst);
|
|
389
|
+
setFormData(deepCopy(convertedAst.where));
|
|
390
|
+
setActiveQuery(dashboardItem.queryString);
|
|
391
|
+
// const initialRows = await handleAsk(dashboardItem.queryString);
|
|
392
|
+
const stringColumns = dashboardItem.columns.filter((column) => {
|
|
393
|
+
return column.format === 'string';
|
|
394
|
+
});
|
|
395
|
+
if (stringColumns.length !== 0 && tableName) {
|
|
396
|
+
const stringNames = stringColumns.map((column) => column.field);
|
|
397
|
+
const newUniqueValues = await getUniqueValuesByColumns(stringColumns, `Select ${stringNames.join(', ')} from ${tableName}`, [], client);
|
|
398
|
+
const joinedUniqueValues = deepCopy(uniqueValues);
|
|
399
|
+
joinedUniqueValues[tableName] = newUniqueValues;
|
|
400
|
+
setUniqueValues(joinedUniqueValues);
|
|
401
|
+
}
|
|
402
|
+
if (dashboardItem.pivot) {
|
|
331
403
|
// @ts-ignore
|
|
332
|
-
setPivotRowField(
|
|
404
|
+
setPivotRowField(dashboardItem.pivot.rowField);
|
|
333
405
|
// @ts-ignore
|
|
334
|
-
setPivotAggregation(
|
|
406
|
+
setPivotAggregation(dashboardItem.pivot.aggregationType);
|
|
335
407
|
// @ts-ignore
|
|
336
|
-
setPivotColumnField(
|
|
408
|
+
setPivotColumnField(dashboardItem.pivot.columnField);
|
|
337
409
|
// @ts-ignore
|
|
338
|
-
setPivotValueField(
|
|
339
|
-
setPivot(
|
|
340
|
-
const pivotedData = generatePivotTable(
|
|
341
|
-
//@ts-ignore
|
|
342
|
-
initialData.pivot, initialRows, [null, null, null], false);
|
|
410
|
+
setPivotValueField(dashboardItem.pivot.valueField);
|
|
411
|
+
setPivot(dashboardItem.pivot);
|
|
412
|
+
const pivotedData = generatePivotTable(dashboardItem.pivot, initialRows, undefined, false);
|
|
343
413
|
setPivotData(pivotedData || []);
|
|
414
|
+
const formattedRows = formatRows(pivotedData.rows, dashboardItem.columns, true,
|
|
415
|
+
// @ts-ignore
|
|
416
|
+
dashboardItem.pivot.aggregationType);
|
|
417
|
+
setFormattedRows(formattedRows);
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
const formattedRows = formatRows(dashboardItem.rows, dashboardItem.columns);
|
|
421
|
+
setFormattedRows(formattedRows);
|
|
344
422
|
}
|
|
423
|
+
setCurrentTable(tableName);
|
|
424
|
+
// This handles a flashing issue
|
|
425
|
+
setTimeout(() => {
|
|
426
|
+
setInitalChartLoad(false);
|
|
427
|
+
}, 500);
|
|
345
428
|
};
|
|
346
|
-
if (
|
|
429
|
+
if (dashboardItem && dashboardItem.referencedTables.length === 1) {
|
|
347
430
|
loadChart();
|
|
348
431
|
}
|
|
349
|
-
}, [
|
|
432
|
+
}, [dashboardItem]);
|
|
350
433
|
useEffect(() => {
|
|
351
434
|
const loadTable = async (tables) => {
|
|
352
435
|
if (!tables)
|
|
353
436
|
return;
|
|
354
437
|
setLoading(true);
|
|
355
|
-
const tableInfo =
|
|
438
|
+
const tableInfo = tables.find((tableInfo) => tableInfo.name === initialTableName);
|
|
356
439
|
if (tableInfo) {
|
|
357
|
-
const
|
|
440
|
+
const convertedStringColumns = tableInfo.columns
|
|
441
|
+
.filter((column) => {
|
|
358
442
|
return isTextColumnType(column.fieldType);
|
|
359
|
-
})
|
|
360
|
-
|
|
361
|
-
const
|
|
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);
|
|
362
447
|
const joinedUniqueValues = deepCopy(uniqueValues);
|
|
363
448
|
joinedUniqueValues[initialTableName] = newUniqueValues;
|
|
364
449
|
if (hashCode(uniqueValues) !== hashCode(joinedUniqueValues)) {
|
|
@@ -425,7 +510,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
425
510
|
return -1;
|
|
426
511
|
return 0;
|
|
427
512
|
})));
|
|
428
|
-
if (initialTableName
|
|
513
|
+
if (initialTableName) {
|
|
429
514
|
await loadTable(tables);
|
|
430
515
|
}
|
|
431
516
|
setLoadingSchema(false);
|
|
@@ -438,7 +523,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
438
523
|
if (schemaTables.length === 0) {
|
|
439
524
|
fetchSchema();
|
|
440
525
|
}
|
|
441
|
-
}, [schemaTables, initialTableName,
|
|
526
|
+
}, [schemaTables, initialTableName, reportId]);
|
|
442
527
|
const updateFormData = (updates, { isDeletion = false, isInsertion = false, isReplaceSubtree = false, isAddVariant = false, isDeleteVariant = false, topLevelBinOp = 'OR', isCondition = undefined, }) => {
|
|
443
528
|
// Function to immutably update or delete nodes based on their path
|
|
444
529
|
// TODO: fix the following horible code
|
|
@@ -801,12 +886,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
801
886
|
* @returns the fieldType string or undefined if not found.
|
|
802
887
|
*/
|
|
803
888
|
const getColumnTypeByName = (columnName) => {
|
|
804
|
-
const
|
|
805
|
-
if (field)
|
|
806
|
-
return getPostgresBasicType(field);
|
|
807
|
-
const column = schemaTables
|
|
808
|
-
.flatMap((t) => t.columns)
|
|
809
|
-
.find((c) => c.name === columnName);
|
|
889
|
+
const column = columns.find((col) => col.field === columnName);
|
|
810
890
|
return column?.fieldType;
|
|
811
891
|
};
|
|
812
892
|
const emptyPivotColumns = () => {
|
|
@@ -1673,9 +1753,10 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1673
1753
|
justifyContent: 'end',
|
|
1674
1754
|
}, children: _jsx(ButtonComponent, { onClick: onSave, label: 'Add condition' }) })] }));
|
|
1675
1755
|
};
|
|
1676
|
-
const fetchUponChange = async (baseAst, newFormData
|
|
1756
|
+
const fetchUponChange = async (baseAst, newFormData) => {
|
|
1677
1757
|
// if newFormData is null still use it
|
|
1678
1758
|
const curFormData = newFormData !== undefined ? newFormData : formData;
|
|
1759
|
+
let rows;
|
|
1679
1760
|
if ((curFormData || baseAst) && !loading) {
|
|
1680
1761
|
try {
|
|
1681
1762
|
setLoading(true);
|
|
@@ -1690,16 +1771,19 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1690
1771
|
};
|
|
1691
1772
|
const cloudBody = {};
|
|
1692
1773
|
const data2 = await getData(client, 'dashquery', 'same-origin', hostedBody, cloudBody);
|
|
1774
|
+
rows = data2.rows;
|
|
1693
1775
|
const tables = getTableNames(baseAst);
|
|
1694
1776
|
const table = tables.length >= 1 ? tables[0] : initialTableName;
|
|
1695
1777
|
if (table !== currentTable) {
|
|
1696
1778
|
const tableInfo = schemaTables.find((tableInfo) => tableInfo.name === table);
|
|
1697
1779
|
if (tableInfo) {
|
|
1698
|
-
const
|
|
1780
|
+
const convertedStringColumns = tableInfo.columns
|
|
1781
|
+
.filter((column) => {
|
|
1699
1782
|
return isTextColumnType(column.fieldType);
|
|
1700
|
-
})
|
|
1701
|
-
|
|
1702
|
-
const
|
|
1783
|
+
})
|
|
1784
|
+
.map((column) => convertColumnInfoToColumnInternal(column));
|
|
1785
|
+
const stringNames = convertedStringColumns.map((column) => column.field);
|
|
1786
|
+
const newUniqueValues = await getUniqueValuesByColumns(convertedStringColumns, `Select ${stringNames.join(', ')} from ${table}`, rows, client);
|
|
1703
1787
|
const joinedUniqueValues = deepCopy(uniqueValues);
|
|
1704
1788
|
joinedUniqueValues[table] = newUniqueValues;
|
|
1705
1789
|
if (hashCode(uniqueValues) !== hashCode(joinedUniqueValues)) {
|
|
@@ -1716,18 +1800,9 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1716
1800
|
setPivot(null);
|
|
1717
1801
|
setPivotData(null);
|
|
1718
1802
|
setRows(data2.rows);
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
// Apply the format function to each field in the row
|
|
1723
|
-
const formattedValue = quillFormat({
|
|
1724
|
-
value: row[column.field],
|
|
1725
|
-
format: column.format,
|
|
1726
|
-
});
|
|
1727
|
-
formattedRow[column.field] = formattedValue;
|
|
1728
|
-
return formattedRow;
|
|
1729
|
-
}, {});
|
|
1730
|
-
}));
|
|
1803
|
+
setColumns(processedFields);
|
|
1804
|
+
const formattedRows = formatRows(data2.rows, processedFields, false);
|
|
1805
|
+
setFormattedRows(formattedRows);
|
|
1731
1806
|
return;
|
|
1732
1807
|
}
|
|
1733
1808
|
// Do all of this to make sure we have the right unique columns when applying a pivot
|
|
@@ -1737,39 +1812,27 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1737
1812
|
return acc;
|
|
1738
1813
|
}, {});
|
|
1739
1814
|
uniqueFormatted[pivot.columnField] = uniqueRecords;
|
|
1740
|
-
const pivotedData = generatePivotTable(pivot, data2.rows,
|
|
1815
|
+
const pivotedData = generatePivotTable(pivot, data2.rows, undefined, false);
|
|
1741
1816
|
console.info(`%c[Pivot]: ${JSON.stringify(pivot)}`, 'color: dimgray');
|
|
1742
1817
|
const processedFields = data2.fields.map((elem) => convertPostgresColumn(elem));
|
|
1743
|
-
setPivotData(pivotedData
|
|
1818
|
+
setPivotData(pivotedData);
|
|
1744
1819
|
setRows(data2.rows);
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
const formattedValue = quillFormat({
|
|
1750
|
-
value: row[column.field],
|
|
1751
|
-
format: column.format,
|
|
1752
|
-
});
|
|
1753
|
-
formattedRow[column.field] = formattedValue;
|
|
1754
|
-
return formattedRow;
|
|
1755
|
-
}, {});
|
|
1820
|
+
setColumns(processedFields);
|
|
1821
|
+
const formattedRows = formatRows(pivotedData.rows, processedFields, true, pivot.aggregationType);
|
|
1822
|
+
setSelectedColumns(processedFields.map((column) => {
|
|
1823
|
+
return `${table}.${column.field}`;
|
|
1756
1824
|
}));
|
|
1825
|
+
setFormattedRows(formattedRows);
|
|
1757
1826
|
}
|
|
1758
1827
|
else {
|
|
1759
1828
|
const processedFields = data2.fields.map((elem) => convertPostgresColumn(elem));
|
|
1760
1829
|
setRows(data2.rows);
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
return
|
|
1764
|
-
// Apply the format function to each field in the row
|
|
1765
|
-
const formattedValue = quillFormat({
|
|
1766
|
-
value: row[column.field],
|
|
1767
|
-
format: column.format,
|
|
1768
|
-
});
|
|
1769
|
-
formattedRow[column.field] = formattedValue;
|
|
1770
|
-
return formattedRow;
|
|
1771
|
-
}, {});
|
|
1830
|
+
setColumns(processedFields);
|
|
1831
|
+
setSelectedColumns(processedFields.map((column) => {
|
|
1832
|
+
return `${table}.${column.field}`;
|
|
1772
1833
|
}));
|
|
1834
|
+
const formattedRows = formatRows(data2.rows, processedFields, false);
|
|
1835
|
+
setFormattedRows(formattedRows);
|
|
1773
1836
|
if (data2.errorMessage) {
|
|
1774
1837
|
setErrorMessage(`Error: ${data2.errorMessage}`);
|
|
1775
1838
|
}
|
|
@@ -1777,7 +1840,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1777
1840
|
}
|
|
1778
1841
|
else {
|
|
1779
1842
|
setRows([]);
|
|
1780
|
-
|
|
1843
|
+
setColumns([]);
|
|
1781
1844
|
setFormattedRows([]);
|
|
1782
1845
|
setPivotData(null);
|
|
1783
1846
|
}
|
|
@@ -1788,6 +1851,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1788
1851
|
finally {
|
|
1789
1852
|
setLoading(false);
|
|
1790
1853
|
setDataDisplayed(true);
|
|
1854
|
+
return rows;
|
|
1791
1855
|
}
|
|
1792
1856
|
}
|
|
1793
1857
|
};
|
|
@@ -2003,11 +2067,13 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2003
2067
|
if (table !== currentTable) {
|
|
2004
2068
|
const tableInfo = schemaTables.find((tableInfo) => tableInfo.name === table);
|
|
2005
2069
|
if (tableInfo) {
|
|
2006
|
-
const
|
|
2070
|
+
const convertedStringColumns = tableInfo.columns
|
|
2071
|
+
.filter((column) => {
|
|
2007
2072
|
return isTextColumnType(column.fieldType);
|
|
2008
|
-
})
|
|
2009
|
-
|
|
2010
|
-
const
|
|
2073
|
+
})
|
|
2074
|
+
.map((column) => convertColumnInfoToColumnInternal(column));
|
|
2075
|
+
const stringNames = convertedStringColumns.map((column) => column.field);
|
|
2076
|
+
const newUniqueValues = await getUniqueValuesByColumns(convertedStringColumns, `Select ${stringNames.join(', ')} from ${table}`, rows, client);
|
|
2011
2077
|
currentUniqueValues[table] = newUniqueValues;
|
|
2012
2078
|
if (hashCode(uniqueValues) !== hashCode(currentUniqueValues)) {
|
|
2013
2079
|
setUniqueValues(currentUniqueValues);
|
|
@@ -2058,48 +2124,28 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2058
2124
|
setPivotColumnField(groupByPivot?.columnField);
|
|
2059
2125
|
setPivotValueField(groupByPivot?.valueField);
|
|
2060
2126
|
setPivotAggregation(groupByPivot?.aggregationType);
|
|
2061
|
-
const pivotedData = generatePivotTable(
|
|
2062
|
-
// @ts-ignore
|
|
2063
|
-
groupByPivot, data2.rows, [null, null, null], false);
|
|
2127
|
+
const pivotedData = generatePivotTable(groupByPivot, data2.rows, undefined, false);
|
|
2064
2128
|
console.info(`%c[Pivot]: ${JSON.stringify(groupByPivot)}`, 'color: dimgray');
|
|
2065
2129
|
setPivotData(pivotedData);
|
|
2066
2130
|
setPivot(groupByPivot);
|
|
2067
2131
|
setRows(data2.rows);
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
// Apply the format function to each field in the row
|
|
2072
|
-
const formattedValue = quillFormat({
|
|
2073
|
-
value: row[column.field],
|
|
2074
|
-
format: column.format,
|
|
2075
|
-
});
|
|
2076
|
-
formattedRow[column.field] = formattedValue;
|
|
2077
|
-
return formattedRow;
|
|
2078
|
-
}, {});
|
|
2079
|
-
}));
|
|
2132
|
+
setColumns(processedFields);
|
|
2133
|
+
const formattedRows = formatRows(pivotedData.rows, processedFields, true, groupByPivot.aggregationType);
|
|
2134
|
+
setFormattedRows(formattedRows);
|
|
2080
2135
|
}
|
|
2081
2136
|
else {
|
|
2082
2137
|
const processedFields = data2.fields.map((elem) => convertPostgresColumn(elem));
|
|
2083
2138
|
setRows(data2.rows);
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
// Apply the format function to each field in the row
|
|
2088
|
-
const formattedValue = quillFormat({
|
|
2089
|
-
value: row[column.field],
|
|
2090
|
-
format: column.format,
|
|
2091
|
-
});
|
|
2092
|
-
formattedRow[column.field] = formattedValue;
|
|
2093
|
-
return formattedRow;
|
|
2094
|
-
}, {});
|
|
2095
|
-
}));
|
|
2139
|
+
setColumns(processedFields);
|
|
2140
|
+
const formattedRows = formatRows(data2.rows, processedFields, false);
|
|
2141
|
+
setFormattedRows(formattedRows);
|
|
2096
2142
|
}
|
|
2097
2143
|
return data2.rows;
|
|
2098
2144
|
}
|
|
2099
2145
|
else {
|
|
2100
2146
|
setPivotData([]);
|
|
2101
2147
|
setRows([]);
|
|
2102
|
-
|
|
2148
|
+
setColumns([]);
|
|
2103
2149
|
setFormattedRows([]);
|
|
2104
2150
|
}
|
|
2105
2151
|
if (data2.query) {
|
|
@@ -2223,7 +2269,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2223
2269
|
gap: 8,
|
|
2224
2270
|
}, children: [columnNamesInAst.map((name) => (_jsx(DraggableItem, { id: name, label: name, onDelete: () => handleDeleteColumn(name) }, name))), columnNamesInAst?.length > 0 && _jsx("div", { style: { height: 6 } })] }) }) }));
|
|
2225
2271
|
}
|
|
2226
|
-
if (loading) {
|
|
2272
|
+
if (loading || initalChartLoad) {
|
|
2227
2273
|
return (_jsxs("div", { style: {
|
|
2228
2274
|
display: 'flex',
|
|
2229
2275
|
flexDirection: 'row',
|
|
@@ -2354,9 +2400,11 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2354
2400
|
setActivePath(null);
|
|
2355
2401
|
setOpenPopover(null);
|
|
2356
2402
|
}
|
|
2357
|
-
} }) })] }))] })] }), _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, CardComponent: CardComponent, SelectComponent: SelectComponent, ButtonComponent: ButtonComponent, PopoverComponent: PopoverComponent, TextComponent: TextComponent, ErrorMessageComponent: ErrorMessageComponent, PivotRowContainer: PivotRowContainer, PivotColumnContainer: PivotColumnContainer, isOpen: showPivotPopover, setIsOpen: setShowPivotPopover, showUpdatePivot: isEdittingPivot, setShowUpdatePivot: setIsEdittingPivot, parentRef: parentRef, data: rows, columns:
|
|
2403
|
+
} }) })] }))] })] }), _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, CardComponent: CardComponent, SelectComponent: SelectComponent, ButtonComponent: ButtonComponent, 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: () => {
|
|
2358
2404
|
setPivot(null);
|
|
2359
2405
|
setPivotData(null);
|
|
2406
|
+
const formattedRows = formatRows(rows, columns, false);
|
|
2407
|
+
setFormattedRows(formattedRows);
|
|
2360
2408
|
},
|
|
2361
2409
|
// TODOs
|
|
2362
2410
|
selectPivot: (pivot) => {
|
|
@@ -2366,9 +2414,11 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2366
2414
|
newAst.orderby = null;
|
|
2367
2415
|
setBaseAst(newAst); // trigger refetch
|
|
2368
2416
|
setPivot(pivot);
|
|
2369
|
-
const pivotedData = generatePivotTable(pivot, rows,
|
|
2417
|
+
const pivotedData = generatePivotTable(pivot, rows, undefined, false);
|
|
2370
2418
|
setPivotData(pivotedData || []);
|
|
2371
|
-
|
|
2419
|
+
const formattedRows = formatRows(pivotedData.rows, columns, true, pivot.aggregationType);
|
|
2420
|
+
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(PivotCard, { pivotTable: {
|
|
2372
2422
|
pivot: pivot,
|
|
2373
2423
|
rows: pivotData?.rows || [],
|
|
2374
2424
|
columns: pivotData?.columns || [],
|
|
@@ -2383,6 +2433,8 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2383
2433
|
}, selectedPivotIndex: -1, onEditPivot: () => { }, CardComponent: CardComponent, ButtonComponent: ButtonComponent, HeaderComponent: HeaderComponent, showEdit: false, onClose: () => {
|
|
2384
2434
|
setPivot(null);
|
|
2385
2435
|
setPivotData(null);
|
|
2436
|
+
const formattedRows = formatRows(rows, columns, false);
|
|
2437
|
+
setFormattedRows(formattedRows);
|
|
2386
2438
|
setBaseAst(deepCopy(baseAst)); // trigger refetch
|
|
2387
2439
|
}, minHeight: 180, LabelComponent: LabelComponent, TextComponent: TextComponent }))] }), _jsxs("div", { style: { width: '100%' }, children: [_jsx(SidebarHeadingComponent, { label: "Sort" }), pivot && pivot.sort && (_jsx("div", { style: {
|
|
2388
2440
|
display: 'flex',
|
|
@@ -2517,11 +2569,13 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2517
2569
|
? 'Ask a follow-up question...'
|
|
2518
2570
|
: 'Ask a question...', width: askAIInputWidth !== -1
|
|
2519
2571
|
? askAIInputWidth
|
|
2520
|
-
: askAILoadingContainerWidth, value: aiPrompt, onChange: () => { } }), _jsx(ButtonComponent, { onClick: () => { }, label: "Ask AI" }), ((baseAst && dataDisplayed) ||
|
|
2572
|
+
: askAILoadingContainerWidth, value: aiPrompt, onChange: () => { } }), _jsx(ButtonComponent, { onClick: () => { }, label: "Ask AI" }), ((baseAst && dataDisplayed) ||
|
|
2573
|
+
initialLoad ||
|
|
2574
|
+
initalChartLoad) && (_jsx(SecondaryButtonComponent, { onClick: () => { }, label: "New report" }))] }) })), _jsxs(_Fragment, { children: [_jsx(TableComponent, { isLoading: true, rows: [], columns: [] }), baseAst && dataDisplayed && !initalChartLoad && (_jsxs("div", { style: {
|
|
2521
2575
|
display: 'flex',
|
|
2522
2576
|
flexDirection: 'row',
|
|
2523
2577
|
gap: '12px',
|
|
2524
|
-
}, children: [_jsx("div", { style: { width: '100%' } }), _jsx(SecondaryButtonComponent, { onClick: () => copyToClipboard(activeQuery), label: isCopying ? '✅ Copied' : 'Copy SQL' }), _jsx(ButtonComponent, { label: 'Add to dashboard', onClick: () => { } })] }))] })] }), _jsx("style", { children: `body{margin:0;}` })] }));
|
|
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;}` })] }));
|
|
2525
2579
|
}
|
|
2526
2580
|
return (_jsxs("div", { ref: parentRef, style: {
|
|
2527
2581
|
display: 'flex',
|
|
@@ -2663,9 +2717,11 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2663
2717
|
setOpenPopover(null);
|
|
2664
2718
|
clearCheckboxes();
|
|
2665
2719
|
}
|
|
2666
|
-
} }) })] }))] })] }), _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, isOpen: showPivotPopover, setIsOpen: setShowPivotPopover, showUpdatePivot: isEdittingPivot, setShowUpdatePivot: setIsEdittingPivot, parentRef: parentRef, data: rows, columns:
|
|
2720
|
+
} }) })] }))] })] }), _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: () => {
|
|
2667
2721
|
setPivot(null);
|
|
2668
2722
|
setPivotData(null);
|
|
2723
|
+
const formattedRows = formatRows(rows, columns, false);
|
|
2724
|
+
setFormattedRows(formattedRows);
|
|
2669
2725
|
}, selectPivot: (pivot) => {
|
|
2670
2726
|
if (!pivot)
|
|
2671
2727
|
return;
|
|
@@ -2677,10 +2733,12 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2677
2733
|
}
|
|
2678
2734
|
setBaseAst(newAst); // trigger refetch
|
|
2679
2735
|
setPivot(pivot);
|
|
2680
|
-
const pivotedData = generatePivotTable(pivot, rows,
|
|
2736
|
+
const pivotedData = generatePivotTable(pivot, rows, undefined, false);
|
|
2681
2737
|
setPivotData(pivotedData || []);
|
|
2738
|
+
const formattedRows = formatRows(pivotedData.rows, columns, true, pivot.aggregationType);
|
|
2739
|
+
setFormattedRows(formattedRows);
|
|
2682
2740
|
setErrorMessage('');
|
|
2683
|
-
}, selectPivotOnEdit: true, showTrigger: !pivot, theme: theme, LabelComponent: LabelComponent, HeaderComponent: HeaderComponent, dateRange:
|
|
2741
|
+
}, 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(PivotCard, { pivotTable: {
|
|
2684
2742
|
pivot: pivot,
|
|
2685
2743
|
rows: pivotData?.rows || [],
|
|
2686
2744
|
columns: pivotData?.columns || [],
|
|
@@ -2695,6 +2753,8 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2695
2753
|
}, selectedPivotIndex: -1, onEditPivot: () => { }, ButtonComponent: ButtonComponent, HeaderComponent: HeaderComponent, CardComponent: CardComponent, showEdit: false, onClose: () => {
|
|
2696
2754
|
setPivot(null);
|
|
2697
2755
|
setPivotData(null);
|
|
2756
|
+
const formattedRows = formatRows(rows, columns, false);
|
|
2757
|
+
setFormattedRows(formattedRows);
|
|
2698
2758
|
setBaseAst(deepCopy(baseAst));
|
|
2699
2759
|
}, minHeight: 180, LabelComponent: LabelComponent, TextComponent: TextComponent }))] }), _jsxs("div", { style: { width: '100%' }, children: [_jsx(SidebarHeadingComponent, { label: "Sort" }), pivot && pivot.sort && (_jsx("div", { style: {
|
|
2700
2760
|
display: 'flex',
|
|
@@ -2714,8 +2774,10 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2714
2774
|
: selectedColumns, setIsPending: setIsPending, setEditPopoverKey: setEditPopoverKey, setActiveEditItem: setActiveEditItem, setActivePath: setActivePath, setOpenPopover: setOpenPopover, SortPopover: SortPopoverComponent, EditPopover: AddSortPopover, handleDelete: () => {
|
|
2715
2775
|
if (pivot) {
|
|
2716
2776
|
setPivot({ ...pivot, sort: false });
|
|
2717
|
-
const pivotedData = generatePivotTable({ ...pivot, sort: false }, rows,
|
|
2777
|
+
const pivotedData = generatePivotTable({ ...pivot, sort: false }, rows, undefined, false);
|
|
2718
2778
|
setPivotData(pivotedData || []);
|
|
2779
|
+
const formattedRows = formatRows(pivotedData.rows, columns, true, pivot.aggregationType);
|
|
2780
|
+
setFormattedRows(formattedRows);
|
|
2719
2781
|
setErrorMessage('');
|
|
2720
2782
|
return;
|
|
2721
2783
|
}
|
|
@@ -2739,8 +2801,10 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2739
2801
|
sortDirection: direction,
|
|
2740
2802
|
sortField: column,
|
|
2741
2803
|
sortFieldType: sortFieldType,
|
|
2742
|
-
}, rows,
|
|
2804
|
+
}, rows, undefined, false);
|
|
2743
2805
|
setPivotData(pivotedData || []);
|
|
2806
|
+
const formattedRows = formatRows(pivotedData.rows, columns, true, pivot.aggregationType);
|
|
2807
|
+
setFormattedRows(formattedRows);
|
|
2744
2808
|
setErrorMessage('');
|
|
2745
2809
|
return;
|
|
2746
2810
|
}
|
|
@@ -2838,9 +2902,11 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2838
2902
|
sortDirection: direction,
|
|
2839
2903
|
sortField: column,
|
|
2840
2904
|
sortFieldType: sortFieldType,
|
|
2841
|
-
}, rows,
|
|
2905
|
+
}, rows, undefined, false);
|
|
2842
2906
|
setErrorMessage('');
|
|
2843
2907
|
setPivotData(pivotedData || []);
|
|
2908
|
+
const formattedRows = formatRows(pivotedData.rows, columns, true, pivot.aggregationType);
|
|
2909
|
+
setFormattedRows(formattedRows);
|
|
2844
2910
|
setActivePath(null);
|
|
2845
2911
|
setOpenPopover(null);
|
|
2846
2912
|
setBaseAst(deepCopy(baseAst));
|
|
@@ -2928,7 +2994,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2928
2994
|
: 'visible',
|
|
2929
2995
|
}, children: _jsxs(_Fragment, { children: [_jsx(TextInputComponent, { id: "ask_ai_input_bar", value: aiPrompt, width: askAIInputWidth !== -1
|
|
2930
2996
|
? askAIInputWidth
|
|
2931
|
-
: askAILoadingContainerWidth, onChange: (e) => setAiPrompt(e.target.value), placeholder: baseAst ? 'Ask a follow-up question...' : '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, rows:
|
|
2997
|
+
: askAILoadingContainerWidth, onChange: (e) => setAiPrompt(e.target.value), placeholder: baseAst ? 'Ask a follow-up question...' : '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
|
|
2932
2998
|
? pivotData?.columns || emptyPivotColumns()
|
|
2933
2999
|
: enforceOrderOnColumns(Object.keys(rows[0] ?? {})).map((c) => {
|
|
2934
3000
|
return { label: snakeCaseToTitleCase(c), field: c };
|
|
@@ -2943,7 +3009,22 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2943
3009
|
overflow: 'hidden',
|
|
2944
3010
|
width: '100%',
|
|
2945
3011
|
gap: 12,
|
|
2946
|
-
}, children: [_jsx(ErrorMessageComponent, { errorMessage: errorMessage }), _jsx(SecondaryButtonComponent, { onClick: handleAsk, label: 'Retry' })] })) : (_jsx("div", { style: { width: '100%' } })), baseAst && dataDisplayed && (_jsxs(_Fragment, { children: [_jsx(SecondaryButtonComponent, { label: isCopying ? '✅ Copied' : 'Copy SQL', onClick: () => copyToClipboard(activeQuery) }), _jsx(ButtonComponent, { onClick: () => {
|
|
3012
|
+
}, children: [_jsx(ErrorMessageComponent, { errorMessage: errorMessage }), _jsx(SecondaryButtonComponent, { onClick: handleAsk, label: 'Retry' })] })) : (_jsx("div", { style: { width: '100%' } })), baseAst && dataDisplayed && !initalChartLoad && (_jsxs(_Fragment, { children: [_jsx(SecondaryButtonComponent, { label: isCopying ? '✅ Copied' : 'Copy SQL', onClick: () => copyToClipboard(activeQuery) }), _jsx(ButtonComponent, { onClick: () => {
|
|
2947
3013
|
setIsChartBuilderOpen(true);
|
|
2948
|
-
}, label: 'Add to dashboard' })] }))] })] }), _jsx("style", { children: `body{margin:0;}` }), _jsx(ChartBuilderWithModal, {
|
|
3014
|
+
}, label: dashboardItem ? 'Save changes' : 'Add to dashboard' })] }))] })] }), _jsx("style", { children: `body{margin:0;}` }), _jsx(ChartBuilderWithModal, { dashboardItem: dashboardItem
|
|
3015
|
+
? {
|
|
3016
|
+
...dashboardItem,
|
|
3017
|
+
pivot: pivot,
|
|
3018
|
+
yAxisFields: dashboardItem.pivot && !pivot
|
|
3019
|
+
? []
|
|
3020
|
+
: dashboardItem.yAxisFields,
|
|
3021
|
+
columns: dashboardItem.columns.filter((col) => {
|
|
3022
|
+
return columns.find((c) => {
|
|
3023
|
+
return col.field === c.field;
|
|
3024
|
+
});
|
|
3025
|
+
}),
|
|
3026
|
+
queryString: activeQuery,
|
|
3027
|
+
rows: rows,
|
|
3028
|
+
}
|
|
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: ModalComponent, PopoverComponent: PopoverComponent, TableComponent: TableComponent, DeleteButtonComponent: DeleteButtonComponent, ChartBuilderInputRowContainer: ChartBuilderInputRowContainer, ChartBuilderInputColumnContainer: ChartBuilderInputColumnContainer, FormContainer: ChartBuilderFormContainer, hideDateRangeFilter: true, buttonLabel: dashboardItem ? 'Save changes' : 'Add to dashboard' })] }));
|
|
2949
3030
|
}
|