@quillsql/react 2.11.25 → 2.11.26
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 +15 -12
- 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 +6 -4
- package/dist/cjs/ReportBuilder.d.ts.map +1 -1
- package/dist/cjs/ReportBuilder.js +208 -126
- package/dist/cjs/SQLEditor.d.ts +4 -11
- package/dist/cjs/SQLEditor.d.ts.map +1 -1
- package/dist/cjs/SQLEditor.js +31 -97
- 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 +12 -10
- package/dist/cjs/components/QuillTable.d.ts +4 -1
- package/dist/cjs/components/QuillTable.d.ts.map +1 -1
- package/dist/cjs/components/QuillTable.js +1 -1
- package/dist/cjs/components/ReportBuilder/convert.d.ts +2 -2
- 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 +9 -2
- package/dist/cjs/internals/ReportBuilder/PivotModal.d.ts.map +1 -1
- package/dist/cjs/internals/ReportBuilder/PivotModal.js +46 -41
- 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 +15 -12
- 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 +6 -4
- package/dist/esm/ReportBuilder.d.ts.map +1 -1
- package/dist/esm/ReportBuilder.js +204 -122
- package/dist/esm/SQLEditor.d.ts +4 -11
- package/dist/esm/SQLEditor.d.ts.map +1 -1
- package/dist/esm/SQLEditor.js +30 -95
- 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 +12 -10
- package/dist/esm/components/QuillTable.d.ts +4 -1
- package/dist/esm/components/QuillTable.d.ts.map +1 -1
- package/dist/esm/components/QuillTable.js +1 -1
- package/dist/esm/components/ReportBuilder/convert.d.ts +2 -2
- 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 +9 -2
- package/dist/esm/internals/ReportBuilder/PivotModal.d.ts.map +1 -1
- package/dist/esm/internals/ReportBuilder/PivotModal.js +48 -43
- 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
|
@@ -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, ColumnSearchEmptyState = QuillColumnSearchEmptyState, ChartBuilderFormContainer = QuillChartBuilderFormContainer, isAdminEnabled = false, isAIEnabled = true, showChartBuilderTableFormatOptions = true, containerStyle, className, pivotRecommendationsEnabled = true, initialReportId, }) {
|
|
70
|
+
const { data: dashboardItem } = useQuill(initialReportId || '');
|
|
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 || !!initialReportId);
|
|
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,81 @@ 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
|
+
setFormattedRows([]);
|
|
391
|
+
setActiveQuery(dashboardItem.queryString);
|
|
392
|
+
// const initialRows = await handleAsk(dashboardItem.queryString);
|
|
393
|
+
const stringColumns = dashboardItem.columns.filter((column) => {
|
|
394
|
+
return column.format === 'string';
|
|
395
|
+
});
|
|
396
|
+
if (stringColumns.length !== 0 && tableName) {
|
|
397
|
+
const stringNames = stringColumns.map((column) => column.field);
|
|
398
|
+
const newUniqueValues = await getUniqueValuesByColumns(stringColumns, `Select ${stringNames.join(', ')} from ${tableName}`, [], client);
|
|
399
|
+
const joinedUniqueValues = deepCopy(uniqueValues);
|
|
400
|
+
joinedUniqueValues[tableName] = newUniqueValues;
|
|
401
|
+
setUniqueValues(joinedUniqueValues);
|
|
402
|
+
}
|
|
403
|
+
if (dashboardItem.pivot) {
|
|
331
404
|
// @ts-ignore
|
|
332
|
-
setPivotRowField(
|
|
405
|
+
setPivotRowField(dashboardItem.pivot.rowField);
|
|
333
406
|
// @ts-ignore
|
|
334
|
-
setPivotAggregation(
|
|
407
|
+
setPivotAggregation(dashboardItem.pivot.aggregationType);
|
|
335
408
|
// @ts-ignore
|
|
336
|
-
setPivotColumnField(
|
|
409
|
+
setPivotColumnField(dashboardItem.pivot.columnField);
|
|
337
410
|
// @ts-ignore
|
|
338
|
-
setPivotValueField(
|
|
339
|
-
setPivot(
|
|
340
|
-
const pivotedData = generatePivotTable(
|
|
341
|
-
//@ts-ignore
|
|
342
|
-
initialData.pivot, initialRows, [null, null, null], false);
|
|
411
|
+
setPivotValueField(dashboardItem.pivot.valueField);
|
|
412
|
+
setPivot(dashboardItem.pivot);
|
|
413
|
+
const pivotedData = generatePivotTable(dashboardItem.pivot, initialRows, undefined, false);
|
|
343
414
|
setPivotData(pivotedData || []);
|
|
415
|
+
const formattedRows = formatRows(pivotedData.rows, dashboardItem.columns, true,
|
|
416
|
+
// @ts-ignore
|
|
417
|
+
dashboardItem.pivot.aggregationType);
|
|
418
|
+
setFormattedRows(formattedRows);
|
|
344
419
|
}
|
|
420
|
+
else {
|
|
421
|
+
const formattedRows = formatRows(dashboardItem.rows, dashboardItem.columns);
|
|
422
|
+
setFormattedRows(formattedRows);
|
|
423
|
+
}
|
|
424
|
+
setCurrentTable(tableName);
|
|
425
|
+
// This handles a flashing issue
|
|
426
|
+
setTimeout(() => {
|
|
427
|
+
setInitalChartLoad(false);
|
|
428
|
+
}, 500);
|
|
345
429
|
};
|
|
346
|
-
if (
|
|
430
|
+
if (dashboardItem && dashboardItem.referencedTables.length === 1) {
|
|
347
431
|
loadChart();
|
|
348
432
|
}
|
|
349
|
-
}, [
|
|
433
|
+
}, [dashboardItem]);
|
|
350
434
|
useEffect(() => {
|
|
351
435
|
const loadTable = async (tables) => {
|
|
352
436
|
if (!tables)
|
|
353
437
|
return;
|
|
354
438
|
setLoading(true);
|
|
355
|
-
const tableInfo =
|
|
439
|
+
const tableInfo = tables.find((tableInfo) => tableInfo.name === initialTableName);
|
|
356
440
|
if (tableInfo) {
|
|
357
|
-
const
|
|
441
|
+
const convertedStringColumns = tableInfo.columns
|
|
442
|
+
.filter((column) => {
|
|
358
443
|
return isTextColumnType(column.fieldType);
|
|
359
|
-
})
|
|
360
|
-
|
|
361
|
-
const
|
|
444
|
+
})
|
|
445
|
+
.map((column) => convertColumnInfoToColumnInternal(column));
|
|
446
|
+
const stringNames = convertedStringColumns.map((column) => column.field);
|
|
447
|
+
const newUniqueValues = await getUniqueValuesByColumns(convertedStringColumns, `Select ${stringNames.join(', ')} from ${initialTableName}`, [], client);
|
|
362
448
|
const joinedUniqueValues = deepCopy(uniqueValues);
|
|
363
449
|
joinedUniqueValues[initialTableName] = newUniqueValues;
|
|
364
450
|
if (hashCode(uniqueValues) !== hashCode(joinedUniqueValues)) {
|
|
@@ -425,7 +511,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
425
511
|
return -1;
|
|
426
512
|
return 0;
|
|
427
513
|
})));
|
|
428
|
-
if (initialTableName
|
|
514
|
+
if (initialTableName) {
|
|
429
515
|
await loadTable(tables);
|
|
430
516
|
}
|
|
431
517
|
setLoadingSchema(false);
|
|
@@ -438,7 +524,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
438
524
|
if (schemaTables.length === 0) {
|
|
439
525
|
fetchSchema();
|
|
440
526
|
}
|
|
441
|
-
}, [schemaTables, initialTableName,
|
|
527
|
+
}, [schemaTables, initialTableName, initialReportId]);
|
|
442
528
|
const updateFormData = (updates, { isDeletion = false, isInsertion = false, isReplaceSubtree = false, isAddVariant = false, isDeleteVariant = false, topLevelBinOp = 'OR', isCondition = undefined, }) => {
|
|
443
529
|
// Function to immutably update or delete nodes based on their path
|
|
444
530
|
// TODO: fix the following horible code
|
|
@@ -801,12 +887,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
801
887
|
* @returns the fieldType string or undefined if not found.
|
|
802
888
|
*/
|
|
803
889
|
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);
|
|
890
|
+
const column = columns.find((col) => col.field === columnName);
|
|
810
891
|
return column?.fieldType;
|
|
811
892
|
};
|
|
812
893
|
const emptyPivotColumns = () => {
|
|
@@ -1673,9 +1754,10 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1673
1754
|
justifyContent: 'end',
|
|
1674
1755
|
}, children: _jsx(ButtonComponent, { onClick: onSave, label: 'Add condition' }) })] }));
|
|
1675
1756
|
};
|
|
1676
|
-
const fetchUponChange = async (baseAst, newFormData
|
|
1757
|
+
const fetchUponChange = async (baseAst, newFormData) => {
|
|
1677
1758
|
// if newFormData is null still use it
|
|
1678
1759
|
const curFormData = newFormData !== undefined ? newFormData : formData;
|
|
1760
|
+
let rows;
|
|
1679
1761
|
if ((curFormData || baseAst) && !loading) {
|
|
1680
1762
|
try {
|
|
1681
1763
|
setLoading(true);
|
|
@@ -1690,16 +1772,19 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1690
1772
|
};
|
|
1691
1773
|
const cloudBody = {};
|
|
1692
1774
|
const data2 = await getData(client, 'dashquery', 'same-origin', hostedBody, cloudBody);
|
|
1775
|
+
rows = data2.rows;
|
|
1693
1776
|
const tables = getTableNames(baseAst);
|
|
1694
1777
|
const table = tables.length >= 1 ? tables[0] : initialTableName;
|
|
1695
1778
|
if (table !== currentTable) {
|
|
1696
1779
|
const tableInfo = schemaTables.find((tableInfo) => tableInfo.name === table);
|
|
1697
1780
|
if (tableInfo) {
|
|
1698
|
-
const
|
|
1781
|
+
const convertedStringColumns = tableInfo.columns
|
|
1782
|
+
.filter((column) => {
|
|
1699
1783
|
return isTextColumnType(column.fieldType);
|
|
1700
|
-
})
|
|
1701
|
-
|
|
1702
|
-
const
|
|
1784
|
+
})
|
|
1785
|
+
.map((column) => convertColumnInfoToColumnInternal(column));
|
|
1786
|
+
const stringNames = convertedStringColumns.map((column) => column.field);
|
|
1787
|
+
const newUniqueValues = await getUniqueValuesByColumns(convertedStringColumns, `Select ${stringNames.join(', ')} from ${table}`, rows, client);
|
|
1703
1788
|
const joinedUniqueValues = deepCopy(uniqueValues);
|
|
1704
1789
|
joinedUniqueValues[table] = newUniqueValues;
|
|
1705
1790
|
if (hashCode(uniqueValues) !== hashCode(joinedUniqueValues)) {
|
|
@@ -1716,18 +1801,9 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1716
1801
|
setPivot(null);
|
|
1717
1802
|
setPivotData(null);
|
|
1718
1803
|
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
|
-
}));
|
|
1804
|
+
setColumns(processedFields);
|
|
1805
|
+
const formattedRows = formatRows(data2.rows, processedFields, false);
|
|
1806
|
+
setFormattedRows(formattedRows);
|
|
1731
1807
|
return;
|
|
1732
1808
|
}
|
|
1733
1809
|
// Do all of this to make sure we have the right unique columns when applying a pivot
|
|
@@ -1737,39 +1813,27 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1737
1813
|
return acc;
|
|
1738
1814
|
}, {});
|
|
1739
1815
|
uniqueFormatted[pivot.columnField] = uniqueRecords;
|
|
1740
|
-
const pivotedData = generatePivotTable(pivot, data2.rows,
|
|
1816
|
+
const pivotedData = generatePivotTable(pivot, data2.rows, undefined, false);
|
|
1741
1817
|
console.info(`%c[Pivot]: ${JSON.stringify(pivot)}`, 'color: dimgray');
|
|
1742
1818
|
const processedFields = data2.fields.map((elem) => convertPostgresColumn(elem));
|
|
1743
|
-
setPivotData(pivotedData
|
|
1819
|
+
setPivotData(pivotedData);
|
|
1744
1820
|
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
|
-
}, {});
|
|
1821
|
+
setColumns(processedFields);
|
|
1822
|
+
const formattedRows = formatRows(pivotedData.rows, processedFields, true, pivot.aggregationType);
|
|
1823
|
+
setSelectedColumns(processedFields.map((column) => {
|
|
1824
|
+
return `${table}.${column.field}`;
|
|
1756
1825
|
}));
|
|
1826
|
+
setFormattedRows(formattedRows);
|
|
1757
1827
|
}
|
|
1758
1828
|
else {
|
|
1759
1829
|
const processedFields = data2.fields.map((elem) => convertPostgresColumn(elem));
|
|
1760
1830
|
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
|
-
}, {});
|
|
1831
|
+
setColumns(processedFields);
|
|
1832
|
+
setSelectedColumns(processedFields.map((column) => {
|
|
1833
|
+
return `${table}.${column.field}`;
|
|
1772
1834
|
}));
|
|
1835
|
+
const formattedRows = formatRows(data2.rows, processedFields, false);
|
|
1836
|
+
setFormattedRows(formattedRows);
|
|
1773
1837
|
if (data2.errorMessage) {
|
|
1774
1838
|
setErrorMessage(`Error: ${data2.errorMessage}`);
|
|
1775
1839
|
}
|
|
@@ -1777,7 +1841,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1777
1841
|
}
|
|
1778
1842
|
else {
|
|
1779
1843
|
setRows([]);
|
|
1780
|
-
|
|
1844
|
+
setColumns([]);
|
|
1781
1845
|
setFormattedRows([]);
|
|
1782
1846
|
setPivotData(null);
|
|
1783
1847
|
}
|
|
@@ -1788,6 +1852,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1788
1852
|
finally {
|
|
1789
1853
|
setLoading(false);
|
|
1790
1854
|
setDataDisplayed(true);
|
|
1855
|
+
return rows;
|
|
1791
1856
|
}
|
|
1792
1857
|
}
|
|
1793
1858
|
};
|
|
@@ -2003,11 +2068,13 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2003
2068
|
if (table !== currentTable) {
|
|
2004
2069
|
const tableInfo = schemaTables.find((tableInfo) => tableInfo.name === table);
|
|
2005
2070
|
if (tableInfo) {
|
|
2006
|
-
const
|
|
2071
|
+
const convertedStringColumns = tableInfo.columns
|
|
2072
|
+
.filter((column) => {
|
|
2007
2073
|
return isTextColumnType(column.fieldType);
|
|
2008
|
-
})
|
|
2009
|
-
|
|
2010
|
-
const
|
|
2074
|
+
})
|
|
2075
|
+
.map((column) => convertColumnInfoToColumnInternal(column));
|
|
2076
|
+
const stringNames = convertedStringColumns.map((column) => column.field);
|
|
2077
|
+
const newUniqueValues = await getUniqueValuesByColumns(convertedStringColumns, `Select ${stringNames.join(', ')} from ${table}`, rows, client);
|
|
2011
2078
|
currentUniqueValues[table] = newUniqueValues;
|
|
2012
2079
|
if (hashCode(uniqueValues) !== hashCode(currentUniqueValues)) {
|
|
2013
2080
|
setUniqueValues(currentUniqueValues);
|
|
@@ -2058,48 +2125,28 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2058
2125
|
setPivotColumnField(groupByPivot?.columnField);
|
|
2059
2126
|
setPivotValueField(groupByPivot?.valueField);
|
|
2060
2127
|
setPivotAggregation(groupByPivot?.aggregationType);
|
|
2061
|
-
const pivotedData = generatePivotTable(
|
|
2062
|
-
// @ts-ignore
|
|
2063
|
-
groupByPivot, data2.rows, [null, null, null], false);
|
|
2128
|
+
const pivotedData = generatePivotTable(groupByPivot, data2.rows, undefined, false);
|
|
2064
2129
|
console.info(`%c[Pivot]: ${JSON.stringify(groupByPivot)}`, 'color: dimgray');
|
|
2065
2130
|
setPivotData(pivotedData);
|
|
2066
2131
|
setPivot(groupByPivot);
|
|
2067
2132
|
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
|
-
}));
|
|
2133
|
+
setColumns(processedFields);
|
|
2134
|
+
const formattedRows = formatRows(pivotedData.rows, processedFields, true, groupByPivot.aggregationType);
|
|
2135
|
+
setFormattedRows(formattedRows);
|
|
2080
2136
|
}
|
|
2081
2137
|
else {
|
|
2082
2138
|
const processedFields = data2.fields.map((elem) => convertPostgresColumn(elem));
|
|
2083
2139
|
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
|
-
}));
|
|
2140
|
+
setColumns(processedFields);
|
|
2141
|
+
const formattedRows = formatRows(data2.rows, processedFields, false);
|
|
2142
|
+
setFormattedRows(formattedRows);
|
|
2096
2143
|
}
|
|
2097
2144
|
return data2.rows;
|
|
2098
2145
|
}
|
|
2099
2146
|
else {
|
|
2100
2147
|
setPivotData([]);
|
|
2101
2148
|
setRows([]);
|
|
2102
|
-
|
|
2149
|
+
setColumns([]);
|
|
2103
2150
|
setFormattedRows([]);
|
|
2104
2151
|
}
|
|
2105
2152
|
if (data2.query) {
|
|
@@ -2223,7 +2270,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2223
2270
|
gap: 8,
|
|
2224
2271
|
}, children: [columnNamesInAst.map((name) => (_jsx(DraggableItem, { id: name, label: name, onDelete: () => handleDeleteColumn(name) }, name))), columnNamesInAst?.length > 0 && _jsx("div", { style: { height: 6 } })] }) }) }));
|
|
2225
2272
|
}
|
|
2226
|
-
if (loading) {
|
|
2273
|
+
if (loading || initalChartLoad) {
|
|
2227
2274
|
return (_jsxs("div", { style: {
|
|
2228
2275
|
display: 'flex',
|
|
2229
2276
|
flexDirection: 'row',
|
|
@@ -2354,9 +2401,11 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2354
2401
|
setActivePath(null);
|
|
2355
2402
|
setOpenPopover(null);
|
|
2356
2403
|
}
|
|
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:
|
|
2404
|
+
} }) })] }))] })] }), _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: columns, triggerButtonText: 'Add pivot', selectedPivotIndex: selectedPivotIndex, setSelectedPivotIndex: setSelectedPivotIndex, removePivot: () => {
|
|
2358
2405
|
setPivot(null);
|
|
2359
2406
|
setPivotData(null);
|
|
2407
|
+
const formattedRows = formatRows(rows, columns, false);
|
|
2408
|
+
setFormattedRows(formattedRows);
|
|
2360
2409
|
},
|
|
2361
2410
|
// TODOs
|
|
2362
2411
|
selectPivot: (pivot) => {
|
|
@@ -2366,9 +2415,11 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2366
2415
|
newAst.orderby = null;
|
|
2367
2416
|
setBaseAst(newAst); // trigger refetch
|
|
2368
2417
|
setPivot(pivot);
|
|
2369
|
-
const pivotedData = generatePivotTable(pivot, rows,
|
|
2418
|
+
const pivotedData = generatePivotTable(pivot, rows, undefined, false);
|
|
2370
2419
|
setPivotData(pivotedData || []);
|
|
2371
|
-
|
|
2420
|
+
const formattedRows = formatRows(pivotedData.rows, columns, true, pivot.aggregationType);
|
|
2421
|
+
setFormattedRows(formattedRows);
|
|
2422
|
+
}, 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
2423
|
pivot: pivot,
|
|
2373
2424
|
rows: pivotData?.rows || [],
|
|
2374
2425
|
columns: pivotData?.columns || [],
|
|
@@ -2383,6 +2434,8 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2383
2434
|
}, selectedPivotIndex: -1, onEditPivot: () => { }, CardComponent: CardComponent, ButtonComponent: ButtonComponent, HeaderComponent: HeaderComponent, showEdit: false, onClose: () => {
|
|
2384
2435
|
setPivot(null);
|
|
2385
2436
|
setPivotData(null);
|
|
2437
|
+
const formattedRows = formatRows(rows, columns, false);
|
|
2438
|
+
setFormattedRows(formattedRows);
|
|
2386
2439
|
setBaseAst(deepCopy(baseAst)); // trigger refetch
|
|
2387
2440
|
}, minHeight: 180, LabelComponent: LabelComponent, TextComponent: TextComponent }))] }), _jsxs("div", { style: { width: '100%' }, children: [_jsx(SidebarHeadingComponent, { label: "Sort" }), pivot && pivot.sort && (_jsx("div", { style: {
|
|
2388
2441
|
display: 'flex',
|
|
@@ -2517,7 +2570,9 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2517
2570
|
? 'Ask a follow-up question...'
|
|
2518
2571
|
: 'Ask a question...', width: askAIInputWidth !== -1
|
|
2519
2572
|
? askAIInputWidth
|
|
2520
|
-
: askAILoadingContainerWidth, value: aiPrompt, onChange: () => { } }), _jsx(ButtonComponent, { onClick: () => { }, label: "Ask AI" }), ((baseAst && dataDisplayed) ||
|
|
2573
|
+
: askAILoadingContainerWidth, value: aiPrompt, onChange: () => { } }), _jsx(ButtonComponent, { onClick: () => { }, label: "Ask AI" }), ((baseAst && dataDisplayed) ||
|
|
2574
|
+
initialLoad ||
|
|
2575
|
+
initalChartLoad) && (_jsx(SecondaryButtonComponent, { onClick: () => { }, label: "New report" }))] }) })), _jsxs(_Fragment, { children: [_jsx(TableComponent, { isLoading: true, rows: [], columns: [] }), baseAst && dataDisplayed && !initalChartLoad && (_jsxs("div", { style: {
|
|
2521
2576
|
display: 'flex',
|
|
2522
2577
|
flexDirection: 'row',
|
|
2523
2578
|
gap: '12px',
|
|
@@ -2663,9 +2718,11 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2663
2718
|
setOpenPopover(null);
|
|
2664
2719
|
clearCheckboxes();
|
|
2665
2720
|
}
|
|
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:
|
|
2721
|
+
} }) })] }))] })] }), _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: columns, triggerButtonText: 'Add pivot', selectedPivotIndex: selectedPivotIndex, setSelectedPivotIndex: setSelectedPivotIndex, removePivot: () => {
|
|
2667
2722
|
setPivot(null);
|
|
2668
2723
|
setPivotData(null);
|
|
2724
|
+
const formattedRows = formatRows(rows, columns, false);
|
|
2725
|
+
setFormattedRows(formattedRows);
|
|
2669
2726
|
}, selectPivot: (pivot) => {
|
|
2670
2727
|
if (!pivot)
|
|
2671
2728
|
return;
|
|
@@ -2677,10 +2734,12 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2677
2734
|
}
|
|
2678
2735
|
setBaseAst(newAst); // trigger refetch
|
|
2679
2736
|
setPivot(pivot);
|
|
2680
|
-
const pivotedData = generatePivotTable(pivot, rows,
|
|
2737
|
+
const pivotedData = generatePivotTable(pivot, rows, undefined, false);
|
|
2681
2738
|
setPivotData(pivotedData || []);
|
|
2739
|
+
const formattedRows = formatRows(pivotedData.rows, columns, true, pivot.aggregationType);
|
|
2740
|
+
setFormattedRows(formattedRows);
|
|
2682
2741
|
setErrorMessage('');
|
|
2683
|
-
}, selectPivotOnEdit: true, showTrigger: !pivot, theme: theme, LabelComponent: LabelComponent, HeaderComponent: HeaderComponent, dateRange:
|
|
2742
|
+
}, 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
2743
|
pivot: pivot,
|
|
2685
2744
|
rows: pivotData?.rows || [],
|
|
2686
2745
|
columns: pivotData?.columns || [],
|
|
@@ -2695,6 +2754,8 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2695
2754
|
}, selectedPivotIndex: -1, onEditPivot: () => { }, ButtonComponent: ButtonComponent, HeaderComponent: HeaderComponent, CardComponent: CardComponent, showEdit: false, onClose: () => {
|
|
2696
2755
|
setPivot(null);
|
|
2697
2756
|
setPivotData(null);
|
|
2757
|
+
const formattedRows = formatRows(rows, columns, false);
|
|
2758
|
+
setFormattedRows(formattedRows);
|
|
2698
2759
|
setBaseAst(deepCopy(baseAst));
|
|
2699
2760
|
}, minHeight: 180, LabelComponent: LabelComponent, TextComponent: TextComponent }))] }), _jsxs("div", { style: { width: '100%' }, children: [_jsx(SidebarHeadingComponent, { label: "Sort" }), pivot && pivot.sort && (_jsx("div", { style: {
|
|
2700
2761
|
display: 'flex',
|
|
@@ -2714,8 +2775,10 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2714
2775
|
: selectedColumns, setIsPending: setIsPending, setEditPopoverKey: setEditPopoverKey, setActiveEditItem: setActiveEditItem, setActivePath: setActivePath, setOpenPopover: setOpenPopover, SortPopover: SortPopoverComponent, EditPopover: AddSortPopover, handleDelete: () => {
|
|
2715
2776
|
if (pivot) {
|
|
2716
2777
|
setPivot({ ...pivot, sort: false });
|
|
2717
|
-
const pivotedData = generatePivotTable({ ...pivot, sort: false }, rows,
|
|
2778
|
+
const pivotedData = generatePivotTable({ ...pivot, sort: false }, rows, undefined, false);
|
|
2718
2779
|
setPivotData(pivotedData || []);
|
|
2780
|
+
const formattedRows = formatRows(pivotedData.rows, columns, true, pivot.aggregationType);
|
|
2781
|
+
setFormattedRows(formattedRows);
|
|
2719
2782
|
setErrorMessage('');
|
|
2720
2783
|
return;
|
|
2721
2784
|
}
|
|
@@ -2739,8 +2802,10 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2739
2802
|
sortDirection: direction,
|
|
2740
2803
|
sortField: column,
|
|
2741
2804
|
sortFieldType: sortFieldType,
|
|
2742
|
-
}, rows,
|
|
2805
|
+
}, rows, undefined, false);
|
|
2743
2806
|
setPivotData(pivotedData || []);
|
|
2807
|
+
const formattedRows = formatRows(pivotedData.rows, columns, true, pivot.aggregationType);
|
|
2808
|
+
setFormattedRows(formattedRows);
|
|
2744
2809
|
setErrorMessage('');
|
|
2745
2810
|
return;
|
|
2746
2811
|
}
|
|
@@ -2838,9 +2903,11 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2838
2903
|
sortDirection: direction,
|
|
2839
2904
|
sortField: column,
|
|
2840
2905
|
sortFieldType: sortFieldType,
|
|
2841
|
-
}, rows,
|
|
2906
|
+
}, rows, undefined, false);
|
|
2842
2907
|
setErrorMessage('');
|
|
2843
2908
|
setPivotData(pivotedData || []);
|
|
2909
|
+
const formattedRows = formatRows(pivotedData.rows, columns, true, pivot.aggregationType);
|
|
2910
|
+
setFormattedRows(formattedRows);
|
|
2844
2911
|
setActivePath(null);
|
|
2845
2912
|
setOpenPopover(null);
|
|
2846
2913
|
setBaseAst(deepCopy(baseAst));
|
|
@@ -2928,7 +2995,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2928
2995
|
: 'visible',
|
|
2929
2996
|
}, children: _jsxs(_Fragment, { children: [_jsx(TextInputComponent, { id: "ask_ai_input_bar", value: aiPrompt, width: askAIInputWidth !== -1
|
|
2930
2997
|
? 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:
|
|
2998
|
+
: 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
2999
|
? pivotData?.columns || emptyPivotColumns()
|
|
2933
3000
|
: enforceOrderOnColumns(Object.keys(rows[0] ?? {})).map((c) => {
|
|
2934
3001
|
return { label: snakeCaseToTitleCase(c), field: c };
|
|
@@ -2943,7 +3010,22 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2943
3010
|
overflow: 'hidden',
|
|
2944
3011
|
width: '100%',
|
|
2945
3012
|
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: () => {
|
|
3013
|
+
}, 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
3014
|
setIsChartBuilderOpen(true);
|
|
2948
|
-
}, label: 'Add to dashboard' })] }))] })] }), _jsx("style", { children: `body{margin:0;}` }), _jsx(ChartBuilderWithModal, {
|
|
3015
|
+
}, label: 'Add to dashboard' })] }))] })] }), _jsx("style", { children: `body{margin:0;}` }), _jsx(ChartBuilderWithModal, { dashboardItem: dashboardItem
|
|
3016
|
+
? {
|
|
3017
|
+
...dashboardItem,
|
|
3018
|
+
pivot: pivot,
|
|
3019
|
+
yAxisFields: dashboardItem.pivot && !pivot
|
|
3020
|
+
? []
|
|
3021
|
+
: dashboardItem.yAxisFields,
|
|
3022
|
+
columns: dashboardItem.columns.filter((col) => {
|
|
3023
|
+
return columns.find((c) => {
|
|
3024
|
+
return col.field === c.field;
|
|
3025
|
+
});
|
|
3026
|
+
}),
|
|
3027
|
+
queryString: activeQuery,
|
|
3028
|
+
rows: rows,
|
|
3029
|
+
}
|
|
3030
|
+
: undefined, rows: rows, columns: columns, pivot: pivot, query: activeQuery, showTableFormatOptions: showChartBuilderTableFormatOptions, showDateFieldOptions: isAdminEnabled, showAccessControlOptions: isAdminEnabled, title: dashboardItem ? 'Edit Chart' : '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 ? 'Edit Chart' : 'Add to dashboard' })] }));
|
|
2949
3031
|
}
|