@quillsql/react 2.11.13 → 2.11.15
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/ReportBuilder.d.ts.map +1 -1
- package/dist/cjs/ReportBuilder.js +206 -139
- package/dist/cjs/components/Dashboard/MetricComponent.js +2 -2
- package/dist/cjs/components/QuillCard.d.ts.map +1 -1
- package/dist/cjs/components/QuillCard.js +2 -4
- package/dist/cjs/components/QuillTable.d.ts.map +1 -1
- package/dist/cjs/components/QuillTable.js +2 -2
- package/dist/cjs/components/ReportBuilder/AddSortPopover.js +2 -2
- package/dist/cjs/components/ReportBuilder/convert.d.ts.map +1 -1
- package/dist/cjs/components/ReportBuilder/convert.js +38 -12
- package/dist/cjs/components/ReportBuilder/ui.d.ts.map +1 -1
- package/dist/cjs/components/ReportBuilder/ui.js +14 -2
- package/dist/cjs/components/UiComponents.d.ts.map +1 -1
- package/dist/cjs/components/UiComponents.js +14 -9
- package/dist/cjs/internals/ReportBuilder/PivotList.d.ts.map +1 -1
- package/dist/cjs/internals/ReportBuilder/PivotList.js +28 -2
- package/dist/cjs/internals/ReportBuilder/PivotModal.d.ts.map +1 -1
- package/dist/cjs/internals/ReportBuilder/PivotModal.js +23 -3
- package/dist/esm/ReportBuilder.d.ts.map +1 -1
- package/dist/esm/ReportBuilder.js +206 -139
- package/dist/esm/components/Dashboard/MetricComponent.js +2 -2
- package/dist/esm/components/QuillCard.d.ts.map +1 -1
- package/dist/esm/components/QuillCard.js +2 -4
- package/dist/esm/components/QuillTable.d.ts.map +1 -1
- package/dist/esm/components/QuillTable.js +2 -2
- package/dist/esm/components/ReportBuilder/AddSortPopover.js +2 -2
- package/dist/esm/components/ReportBuilder/convert.d.ts.map +1 -1
- package/dist/esm/components/ReportBuilder/convert.js +38 -12
- package/dist/esm/components/ReportBuilder/ui.d.ts.map +1 -1
- package/dist/esm/components/ReportBuilder/ui.js +14 -2
- package/dist/esm/components/UiComponents.d.ts.map +1 -1
- package/dist/esm/components/UiComponents.js +14 -9
- package/dist/esm/internals/ReportBuilder/PivotList.d.ts.map +1 -1
- package/dist/esm/internals/ReportBuilder/PivotList.js +28 -2
- package/dist/esm/internals/ReportBuilder/PivotModal.d.ts.map +1 -1
- package/dist/esm/internals/ReportBuilder/PivotModal.js +23 -3
- package/package.json +1 -1
|
@@ -65,6 +65,8 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
65
65
|
const [showPivotPopover, setShowPivotPopover] = (0, react_1.useState)(false);
|
|
66
66
|
const [isEdittingPivot, setIsEdittingPivot] = (0, react_1.useState)(false);
|
|
67
67
|
const [selectedPivotIndex, setSelectedPivotIndex] = (0, react_1.useState)(-1);
|
|
68
|
+
const [initialLoad, setInitialLoad] = (0, react_1.useState)(true);
|
|
69
|
+
const [currentTable, setCurrentTable] = (0, react_1.useState)(initialTableName || '');
|
|
68
70
|
const parentRef = (0, react_1.useRef)(null);
|
|
69
71
|
const [theme] = (0, react_1.useContext)(Context_1.ThemeContext);
|
|
70
72
|
const [pivotRowField, setPivotRowField] = (0, react_1.useState)(undefined);
|
|
@@ -185,7 +187,9 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
185
187
|
}
|
|
186
188
|
setUniqueValues(newValues);
|
|
187
189
|
};
|
|
188
|
-
const fetchSqlQuery = async () => {
|
|
190
|
+
const fetchSqlQuery = async (ast, formData) => {
|
|
191
|
+
setLoading(true);
|
|
192
|
+
setErrorMessage('');
|
|
189
193
|
try {
|
|
190
194
|
const response = await fetch(`https://quill-344421.uc.r.appspot.com/sqlify`, {
|
|
191
195
|
method: 'POST',
|
|
@@ -193,32 +197,19 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
193
197
|
'Content-Type': 'application/json',
|
|
194
198
|
},
|
|
195
199
|
body: JSON.stringify({
|
|
196
|
-
ast: { ...
|
|
200
|
+
ast: { ...ast, where: formData },
|
|
197
201
|
publicKey: client.publicKey,
|
|
198
202
|
}),
|
|
199
203
|
});
|
|
200
204
|
const data = await response.json();
|
|
201
205
|
setActiveQuery(data.query);
|
|
202
|
-
fetchUponChange();
|
|
206
|
+
fetchUponChange(ast, formData);
|
|
203
207
|
}
|
|
204
208
|
catch (error) {
|
|
209
|
+
setLoading(false);
|
|
205
210
|
console.error(error);
|
|
206
211
|
}
|
|
207
212
|
};
|
|
208
|
-
(0, react_1.useEffect)(() => {
|
|
209
|
-
setErrorMessage('');
|
|
210
|
-
if (baseAst || formData) {
|
|
211
|
-
fetchSqlQuery();
|
|
212
|
-
}
|
|
213
|
-
}, [baseAst]);
|
|
214
|
-
// Returns an array of all the column names in the pivot config
|
|
215
|
-
// if there are any, otherwise returns [].
|
|
216
|
-
const getColumnsInPivot = () => {
|
|
217
|
-
if (!pivot)
|
|
218
|
-
return [];
|
|
219
|
-
const { valueField, rowField, columnField } = pivot;
|
|
220
|
-
return [valueField, rowField, columnField].filter(Boolean);
|
|
221
|
-
};
|
|
222
213
|
// It's just like getColumnsInPivot but we expand the columnField
|
|
223
214
|
// if there is one to include all the variants just like it would
|
|
224
215
|
// show up in the table. (eg. category -> ...[Fuel, Food, Other])
|
|
@@ -237,43 +228,38 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
237
228
|
result.push(valueField, rowField);
|
|
238
229
|
return result.filter(Boolean);
|
|
239
230
|
};
|
|
240
|
-
(
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
query: query,
|
|
258
|
-
}),
|
|
259
|
-
});
|
|
260
|
-
const data = await response.json();
|
|
261
|
-
if (data.errorMessage) {
|
|
262
|
-
// console.error(data.errorMessage);
|
|
263
|
-
return null;
|
|
264
|
-
}
|
|
265
|
-
const options = data.rows.map((r) => r[column]);
|
|
266
|
-
const newCheckboxValues = options.reduce((obj, col) => {
|
|
267
|
-
obj[col] = false;
|
|
268
|
-
return obj;
|
|
269
|
-
}, {});
|
|
270
|
-
return { table, column, values: newCheckboxValues };
|
|
271
|
-
}
|
|
272
|
-
catch (e) {
|
|
273
|
-
console.error(e);
|
|
231
|
+
const fetchDistinctHelper = async (column, table) => {
|
|
232
|
+
try {
|
|
233
|
+
const query = `SELECT DISTINCT ${column} FROM ${table};`;
|
|
234
|
+
const response = await fetch(`https://quill-344421.uc.r.appspot.com/dashquery`, {
|
|
235
|
+
method: 'POST',
|
|
236
|
+
headers: {
|
|
237
|
+
'Content-Type': 'application/json',
|
|
238
|
+
},
|
|
239
|
+
body: JSON.stringify({
|
|
240
|
+
orgId: client.customerId,
|
|
241
|
+
publicKey: client.publicKey,
|
|
242
|
+
query: query,
|
|
243
|
+
}),
|
|
244
|
+
});
|
|
245
|
+
const data = await response.json();
|
|
246
|
+
if (data.errorMessage) {
|
|
247
|
+
// console.error(data.errorMessage);
|
|
274
248
|
return null;
|
|
275
249
|
}
|
|
276
|
-
|
|
250
|
+
const options = data.rows.map((r) => r[column]);
|
|
251
|
+
const newCheckboxValues = options.reduce((obj, col) => {
|
|
252
|
+
obj[col] = false;
|
|
253
|
+
return obj;
|
|
254
|
+
}, {});
|
|
255
|
+
return { table, column, values: newCheckboxValues };
|
|
256
|
+
}
|
|
257
|
+
catch (e) {
|
|
258
|
+
console.error(e);
|
|
259
|
+
return null;
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
(0, react_1.useEffect)(() => {
|
|
277
263
|
const fetchSchema = async () => {
|
|
278
264
|
try {
|
|
279
265
|
const response = await fetch(`${client.queryEndpoint}`, {
|
|
@@ -306,31 +292,10 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
306
292
|
return -1;
|
|
307
293
|
return 0;
|
|
308
294
|
})));
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
if (!(0, ast_1.isTextColumnType)(column.fieldType))
|
|
314
|
-
continue;
|
|
315
|
-
const fetchPromise = fetchDistinctHelper(column.name, table.displayName);
|
|
316
|
-
pendingFetches.push(fetchPromise);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
const newUniqueValues = {};
|
|
320
|
-
const resolvedPromises = await Promise.all(pendingFetches);
|
|
321
|
-
for (const resolvedData of resolvedPromises) {
|
|
322
|
-
if (resolvedData) {
|
|
323
|
-
const { table, column, values } = resolvedData;
|
|
324
|
-
if (!newUniqueValues[table]) {
|
|
325
|
-
newUniqueValues[table] = {};
|
|
326
|
-
}
|
|
327
|
-
newUniqueValues[table][column] = values;
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
if ((0, crypto_1.hashCode)(uniqueValues) !== (0, crypto_1.hashCode)(newUniqueValues)) {
|
|
331
|
-
setUniqueValues(newUniqueValues);
|
|
332
|
-
}
|
|
333
|
-
if (initialTableName) {
|
|
295
|
+
if (initialTableName && initialLoad) {
|
|
296
|
+
setInitialLoad(false);
|
|
297
|
+
setLoading(true);
|
|
298
|
+
await getDistinctValues(initialTableName, tables);
|
|
334
299
|
const columnsForTable = tables
|
|
335
300
|
.find((t) => t.name === initialTableName)
|
|
336
301
|
?.columns.map((c) => c.name);
|
|
@@ -358,7 +323,7 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
358
323
|
const paths = globalPath.split('.').filter((p) => p);
|
|
359
324
|
if (paths.length === 0 && !isInsertion && !isReplaceSubtree) {
|
|
360
325
|
setFormData(null);
|
|
361
|
-
|
|
326
|
+
const newAst = (0, util_1.deepCopy)({
|
|
362
327
|
...constants_1.defaultAST,
|
|
363
328
|
...baseAst,
|
|
364
329
|
...(!baseAst?.columns && {
|
|
@@ -372,12 +337,13 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
372
337
|
from: [{ ...constants_1.defaultTable, table: initialTableName }],
|
|
373
338
|
}),
|
|
374
339
|
where: null,
|
|
375
|
-
})
|
|
340
|
+
});
|
|
341
|
+
setBaseAst(newAst);
|
|
342
|
+
fetchSqlQuery(newAst, null);
|
|
376
343
|
return;
|
|
377
344
|
}
|
|
378
345
|
if (!formData && isInsertion) {
|
|
379
|
-
|
|
380
|
-
setBaseAst((0, util_1.deepCopy)({
|
|
346
|
+
const newAst = (0, util_1.deepCopy)({
|
|
381
347
|
...constants_1.defaultAST,
|
|
382
348
|
...baseAst,
|
|
383
349
|
...(!baseAst?.columns && {
|
|
@@ -391,7 +357,10 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
391
357
|
from: [{ ...constants_1.defaultTable, table: initialTableName }],
|
|
392
358
|
}),
|
|
393
359
|
where: value,
|
|
394
|
-
})
|
|
360
|
+
});
|
|
361
|
+
setFormData(value);
|
|
362
|
+
setBaseAst(newAst);
|
|
363
|
+
fetchSqlQuery(newAst, value);
|
|
395
364
|
return;
|
|
396
365
|
}
|
|
397
366
|
let newState = (0, util_1.deepCopy)(formData);
|
|
@@ -475,7 +444,7 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
475
444
|
}
|
|
476
445
|
}
|
|
477
446
|
setFormData(newState);
|
|
478
|
-
|
|
447
|
+
const newAst = {
|
|
479
448
|
...constants_1.defaultAST,
|
|
480
449
|
...baseAst,
|
|
481
450
|
...(!baseAst?.columns && {
|
|
@@ -489,7 +458,9 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
489
458
|
from: [{ ...constants_1.defaultTable, table: initialTableName }],
|
|
490
459
|
}),
|
|
491
460
|
where: { ...newState },
|
|
492
|
-
}
|
|
461
|
+
};
|
|
462
|
+
setBaseAst(newAst);
|
|
463
|
+
fetchSqlQuery(newAst, newState);
|
|
493
464
|
});
|
|
494
465
|
};
|
|
495
466
|
// TODO: Merge this function with the updateFormData function
|
|
@@ -709,6 +680,23 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
709
680
|
.find((c) => c.name === columnName);
|
|
710
681
|
return column?.fieldType;
|
|
711
682
|
};
|
|
683
|
+
const emptyPivotColumns = () => {
|
|
684
|
+
if (pivot && pivot.rowField && pivot.columnField && pivot.valueField) {
|
|
685
|
+
return [
|
|
686
|
+
{ label: (0, textProcessing_1.snakeCaseToTitleCase)(pivot.rowField) },
|
|
687
|
+
{ label: (0, textProcessing_1.snakeCaseToTitleCase)(pivot.columnField) },
|
|
688
|
+
];
|
|
689
|
+
}
|
|
690
|
+
else if (pivot && pivot.rowField && pivot.valueField) {
|
|
691
|
+
return [
|
|
692
|
+
{ label: (0, textProcessing_1.snakeCaseToTitleCase)(pivot.rowField) },
|
|
693
|
+
{ label: (0, textProcessing_1.snakeCaseToTitleCase)(pivot.valueField) },
|
|
694
|
+
];
|
|
695
|
+
}
|
|
696
|
+
else {
|
|
697
|
+
return [{ label: (0, textProcessing_1.snakeCaseToTitleCase)(pivot.valueField) }];
|
|
698
|
+
}
|
|
699
|
+
};
|
|
712
700
|
/**
|
|
713
701
|
* Render form fields based on the type of the node
|
|
714
702
|
* @param node the AST or subtree to render recursively
|
|
@@ -1102,7 +1090,7 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
1102
1090
|
else {
|
|
1103
1091
|
handleDeleteVariant(keyPrefix + 'right.' + 'value', key);
|
|
1104
1092
|
}
|
|
1105
|
-
} }), (0, jsx_runtime_1.jsx)("span", { children: key })] }, key))) }, keyPrefix + 'right.'))] }));
|
|
1093
|
+
} }), (0, jsx_runtime_1.jsx)("span", { style: { fontFamily: theme.fontFamily }, children: key })] }, key))) }, keyPrefix + 'right.'))] }));
|
|
1106
1094
|
}
|
|
1107
1095
|
else {
|
|
1108
1096
|
const columnName = node.left.column;
|
|
@@ -1375,33 +1363,6 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
1375
1363
|
return 0;
|
|
1376
1364
|
}));
|
|
1377
1365
|
};
|
|
1378
|
-
const getDateColumns = () => {
|
|
1379
|
-
const allColumns = getAllPossibleColumns();
|
|
1380
|
-
return allColumns.filter((c) => (0, ast_1.isDateishColumnType)(c.fieldType));
|
|
1381
|
-
};
|
|
1382
|
-
const getNumericColumns = () => {
|
|
1383
|
-
const allColumns = getAllPossibleColumns();
|
|
1384
|
-
const selectedColumnNames = selectedColumns.map((col) => col.split('.')[1]);
|
|
1385
|
-
return allColumns
|
|
1386
|
-
.filter((column) => {
|
|
1387
|
-
return selectedColumnNames.includes(column.name);
|
|
1388
|
-
})
|
|
1389
|
-
.filter((c) => (0, ast_1.isNumericColumnType)(c.fieldType));
|
|
1390
|
-
};
|
|
1391
|
-
const getNonNumericColumns = () => {
|
|
1392
|
-
const allColumns = getAllPossibleColumns();
|
|
1393
|
-
const selectedColumnNames = selectedColumns.map((col) => col.split('.')[1]);
|
|
1394
|
-
return allColumns
|
|
1395
|
-
.filter((column) => selectedColumnNames.includes(column.name))
|
|
1396
|
-
.filter((c) => !(0, ast_1.isNumericColumnType)(c.fieldType));
|
|
1397
|
-
};
|
|
1398
|
-
const getStringColumns = () => {
|
|
1399
|
-
const allColumns = getAllPossibleColumns();
|
|
1400
|
-
const selectedColumnNames = selectedColumns.map((col) => col.split('.')[1]);
|
|
1401
|
-
return allColumns
|
|
1402
|
-
.filter((column) => selectedColumnNames.includes(column.name))
|
|
1403
|
-
.filter((c) => (0, ast_1.isTextColumnType)(c.fieldType));
|
|
1404
|
-
};
|
|
1405
1366
|
/**
|
|
1406
1367
|
* Return whether all columns have been selected (used to hide select all
|
|
1407
1368
|
* and show clear button).
|
|
@@ -1437,8 +1398,10 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
1437
1398
|
justifyContent: 'end',
|
|
1438
1399
|
}, children: (0, jsx_runtime_1.jsx)(Button, { onClick: onSave, label: 'Add condition' }) })] }));
|
|
1439
1400
|
};
|
|
1440
|
-
const fetchUponChange = async () => {
|
|
1441
|
-
if
|
|
1401
|
+
const fetchUponChange = async (baseAst, newFormData) => {
|
|
1402
|
+
// if newFormData is null still use it
|
|
1403
|
+
const curFormData = newFormData !== undefined ? newFormData : formData;
|
|
1404
|
+
if ((curFormData || baseAst) && !loading) {
|
|
1442
1405
|
try {
|
|
1443
1406
|
setLoading(true);
|
|
1444
1407
|
const res2 = await fetch('https://quill-344421.uc.r.appspot.com/patterns', {
|
|
@@ -1447,7 +1410,7 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
1447
1410
|
'Content-Type': 'application/json',
|
|
1448
1411
|
},
|
|
1449
1412
|
body: JSON.stringify({
|
|
1450
|
-
ast: { ...baseAst, where:
|
|
1413
|
+
ast: { ...baseAst, where: curFormData },
|
|
1451
1414
|
publicKey: client.publicKey,
|
|
1452
1415
|
orgId: client.customerId,
|
|
1453
1416
|
}),
|
|
@@ -1456,6 +1419,10 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
1456
1419
|
if (data2.rows && data2.rows.length) {
|
|
1457
1420
|
const tables = (0, ast_1.getTableNames)(baseAst);
|
|
1458
1421
|
const table = tables.length >= 1 ? tables[0] : initialTableName;
|
|
1422
|
+
if (table !== currentTable) {
|
|
1423
|
+
getDistinctValues(table);
|
|
1424
|
+
setCurrentTable(table);
|
|
1425
|
+
}
|
|
1459
1426
|
const sortedFields = data2.fields.sort((a, b) => {
|
|
1460
1427
|
const aIsId = a.name.toLowerCase() === 'id' ||
|
|
1461
1428
|
a.name.toLowerCase().endsWith('_id');
|
|
@@ -1477,7 +1444,7 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
1477
1444
|
uniqueFormatted[pivot.columnField] = uniqueRecords;
|
|
1478
1445
|
const pivotedData = (0, PivotModal_1.generatePivotTable)(pivot, data2.rows, [null, null, null], false);
|
|
1479
1446
|
console.info(`%c[Pivot]: ${JSON.stringify(pivot)}`, 'color: dimgray');
|
|
1480
|
-
setPivotData(pivotedData);
|
|
1447
|
+
setPivotData(pivotedData || []);
|
|
1481
1448
|
setRows(data2.rows);
|
|
1482
1449
|
setFields(data2.fields);
|
|
1483
1450
|
}
|
|
@@ -1600,6 +1567,33 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
1600
1567
|
}
|
|
1601
1568
|
return false;
|
|
1602
1569
|
};
|
|
1570
|
+
const getDistinctValues = async (table, overrideSchema) => {
|
|
1571
|
+
const schemaInfo = overrideSchema || schemaTables;
|
|
1572
|
+
const tableInfo = schemaInfo.find((tableInfo) => tableInfo.name === table);
|
|
1573
|
+
if (tableInfo) {
|
|
1574
|
+
const pendingFetches = [];
|
|
1575
|
+
for (let column of tableInfo.columns) {
|
|
1576
|
+
if (!(0, ast_1.isTextColumnType)(column.fieldType))
|
|
1577
|
+
continue;
|
|
1578
|
+
const fetchPromise = fetchDistinctHelper(column.name, tableInfo.displayName);
|
|
1579
|
+
pendingFetches.push(fetchPromise);
|
|
1580
|
+
}
|
|
1581
|
+
const newUniqueValues = {};
|
|
1582
|
+
const resolvedPromises = await Promise.all(pendingFetches);
|
|
1583
|
+
for (const resolvedData of resolvedPromises) {
|
|
1584
|
+
if (resolvedData) {
|
|
1585
|
+
const { table, column, values } = resolvedData;
|
|
1586
|
+
if (!newUniqueValues[table]) {
|
|
1587
|
+
newUniqueValues[table] = {};
|
|
1588
|
+
}
|
|
1589
|
+
newUniqueValues[table][column] = values;
|
|
1590
|
+
}
|
|
1591
|
+
}
|
|
1592
|
+
if ((0, crypto_1.hashCode)(uniqueValues) !== (0, crypto_1.hashCode)(newUniqueValues)) {
|
|
1593
|
+
setUniqueValues(newUniqueValues);
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
};
|
|
1603
1597
|
const handleAsk = async (overridePrompt = '') => {
|
|
1604
1598
|
if (!aiPrompt && !overridePrompt) {
|
|
1605
1599
|
return;
|
|
@@ -1668,11 +1662,14 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
1668
1662
|
newAst = (0, util_1.removeNonSelectedTableReferences)(newAst, tableAlias ?? table);
|
|
1669
1663
|
// newAst = convertDateComparison(newAst); // TODO
|
|
1670
1664
|
ast = newAst; // so we fetch data for newAst later.
|
|
1665
|
+
if (table !== currentTable) {
|
|
1666
|
+
getDistinctValues(table);
|
|
1667
|
+
setCurrentTable(table);
|
|
1668
|
+
}
|
|
1671
1669
|
setPivotRowField(groupByPivot?.rowField);
|
|
1672
1670
|
setPivotColumnField(groupByPivot?.columnField);
|
|
1673
1671
|
setPivotValueField(groupByPivot?.valueField);
|
|
1674
1672
|
setPivotAggregation(groupByPivot?.aggregationType);
|
|
1675
|
-
setPivot(groupByPivot);
|
|
1676
1673
|
setSelectedColumns((0, util_1.deepCopy)(newAst).columns?.map((column) => {
|
|
1677
1674
|
if (column.expr.type === 'column_ref') {
|
|
1678
1675
|
return `${table}.${column.expr.column}`;
|
|
@@ -1683,7 +1680,7 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
1683
1680
|
return `${table}.${column.expr.value}`;
|
|
1684
1681
|
}));
|
|
1685
1682
|
if (groupByPivot) {
|
|
1686
|
-
setBaseAst((0, util_1.deepCopy)({ ...newAst, orderby: null }));
|
|
1683
|
+
setBaseAst((0, util_1.deepCopy)({ ...newAst, orderby: null, limit: null }));
|
|
1687
1684
|
}
|
|
1688
1685
|
else {
|
|
1689
1686
|
setBaseAst((0, util_1.deepCopy)({ ...newAst }));
|
|
@@ -1692,8 +1689,6 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
1692
1689
|
setTopLevelBinaryOperator(
|
|
1693
1690
|
// @ts-ignore
|
|
1694
1691
|
newAst?.where ? newAst?.where?.operator : 'AND');
|
|
1695
|
-
if (groupByPivot)
|
|
1696
|
-
return; // the useEffect will handle the rest
|
|
1697
1692
|
}
|
|
1698
1693
|
const res2 = await fetch('https://quill-344421.uc.r.appspot.com/patterns', {
|
|
1699
1694
|
method: 'POST',
|
|
@@ -1709,11 +1704,13 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
1709
1704
|
const data2 = await res2.json();
|
|
1710
1705
|
if (data2.rows && data2.rows.length) {
|
|
1711
1706
|
const tables = (0, ast_1.getTableNames)(newAst);
|
|
1712
|
-
const table = tables.length >= 1 ? tables[0] : initialTableName;
|
|
1713
1707
|
if (groupByPivot) {
|
|
1714
|
-
const pivotedData = (0, PivotModal_1.generatePivotTable)(
|
|
1708
|
+
const pivotedData = (0, PivotModal_1.generatePivotTable)(
|
|
1709
|
+
// @ts-ignore
|
|
1710
|
+
groupByPivot, data2.rows, [null, null, null], false);
|
|
1715
1711
|
console.info(`%c[Pivot]: ${JSON.stringify(groupByPivot)}`, 'color: dimgray');
|
|
1716
1712
|
setPivotData(pivotedData);
|
|
1713
|
+
setPivot(groupByPivot);
|
|
1717
1714
|
setRows(data2.rows);
|
|
1718
1715
|
setFields(data2.fields);
|
|
1719
1716
|
}
|
|
@@ -1723,6 +1720,7 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
1723
1720
|
}
|
|
1724
1721
|
}
|
|
1725
1722
|
else {
|
|
1723
|
+
setPivotData([]);
|
|
1726
1724
|
setRows([]);
|
|
1727
1725
|
setFields([]);
|
|
1728
1726
|
}
|
|
@@ -1741,7 +1739,7 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
1741
1739
|
}
|
|
1742
1740
|
catch (e) {
|
|
1743
1741
|
console.error(e);
|
|
1744
|
-
setErrorMessage(
|
|
1742
|
+
setErrorMessage(`Error: Couldn't process your request, please re-word your prompt.`);
|
|
1745
1743
|
}
|
|
1746
1744
|
finally {
|
|
1747
1745
|
setLoading(false);
|
|
@@ -1767,11 +1765,17 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
1767
1765
|
clearAllState();
|
|
1768
1766
|
return;
|
|
1769
1767
|
}
|
|
1770
|
-
const newAst = { ...baseAst, columns };
|
|
1771
|
-
setBaseAst(
|
|
1768
|
+
const newAst = (0, util_1.deepCopy)({ ...baseAst, columns });
|
|
1769
|
+
setBaseAst(newAst);
|
|
1770
|
+
fetchSqlQuery(newAst);
|
|
1772
1771
|
};
|
|
1773
1772
|
function TopLevelBooleanSwitch({ node, keyPrefix, handleOperatorChange, }) {
|
|
1774
|
-
return ((0, jsx_runtime_1.jsx)("div", { style: { width: 'fit-content' }, children: (0, jsx_runtime_1.jsx)(Tabs, { defaultValue: node.operator, options: ui_1.DEFAULT_TAB_OPTIONS, onValueChange: (value) =>
|
|
1773
|
+
return ((0, jsx_runtime_1.jsx)("div", { style: { width: 'fit-content' }, children: (0, jsx_runtime_1.jsx)(Tabs, { defaultValue: node.operator, options: ui_1.DEFAULT_TAB_OPTIONS, onValueChange: (value) => {
|
|
1774
|
+
if (loading) {
|
|
1775
|
+
return;
|
|
1776
|
+
}
|
|
1777
|
+
handleOperatorChange(value, node, keyPrefix);
|
|
1778
|
+
} }) }));
|
|
1775
1779
|
}
|
|
1776
1780
|
const DraggableItem = ({ id, label, onDelete }) => {
|
|
1777
1781
|
const { attributes, listeners, setNodeRef, transform, transition } = (0, sortable_1.useSortable)({ id: id });
|
|
@@ -1817,6 +1821,7 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
1817
1821
|
};
|
|
1818
1822
|
const newAst = baseAst ? newBaseAst : fallbackAST;
|
|
1819
1823
|
setBaseAst(newAst);
|
|
1824
|
+
fetchSqlQuery(newAst);
|
|
1820
1825
|
}
|
|
1821
1826
|
}
|
|
1822
1827
|
const columnNamesInAst = baseAst?.columns.map((col) => {
|
|
@@ -1859,7 +1864,10 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
1859
1864
|
setActiveEditItem(null);
|
|
1860
1865
|
setActivePath(null);
|
|
1861
1866
|
setOpenPopover(null);
|
|
1862
|
-
}, orderedColumnNames: orderedColumnNames, setOrderedColumnNames: setOrderedColumnNames, selectedColumns: selectedColumns, setSelectedColumns: setSelectedColumns, isSelectedAllColumns: isSelectedAllColumns, clearAllState: clearAllState, nameToColumn: nameToColumn, baseAst: baseAst, setBaseAst:
|
|
1867
|
+
}, orderedColumnNames: orderedColumnNames, setOrderedColumnNames: setOrderedColumnNames, selectedColumns: selectedColumns, setSelectedColumns: setSelectedColumns, isSelectedAllColumns: isSelectedAllColumns, clearAllState: clearAllState, nameToColumn: nameToColumn, baseAst: baseAst, setBaseAst: (newAst) => {
|
|
1868
|
+
setBaseAst(newAst);
|
|
1869
|
+
fetchSqlQuery(newAst);
|
|
1870
|
+
}, pivot: pivot, initialTableName: initialTableName, defaultAST: constants_1.defaultAST, defaultTable: constants_1.defaultTable, setPivot: setPivot, TextInput: TextInput, SelectColumn: SelectColumn, SecondaryButton: SecondaryButton, Button: Button, HandleButton: HandleButton }) }), (0, jsx_runtime_1.jsx)("div", { style: { height: 28, width: '100%' } }), (0, jsx_runtime_1.jsx)(SidebarHeading, { label: "Filters" }), (0, jsx_runtime_1.jsx)("div", { style: { height: 4, width: '100%' } }), formData && ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
1863
1871
|
display: 'flex',
|
|
1864
1872
|
flexDirection: 'column',
|
|
1865
1873
|
gap: 8,
|
|
@@ -1870,6 +1878,9 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
1870
1878
|
gap: 2.5,
|
|
1871
1879
|
alignItems: 'flex-start',
|
|
1872
1880
|
}, children: [(0, jsx_runtime_1.jsx)(Popover, { isOpen: openPopover === 'AddFilterPopover', title: 'Add filter', trigger: (0, jsx_runtime_1.jsx)(SecondaryButton, { onClick: () => {
|
|
1881
|
+
if (!selectedColumns || selectedColumns.length === 0) {
|
|
1882
|
+
return;
|
|
1883
|
+
}
|
|
1873
1884
|
if (!openPopover) {
|
|
1874
1885
|
const value = orderedColumnNames[0];
|
|
1875
1886
|
const [_table, column] = value.split('.');
|
|
@@ -1956,14 +1967,18 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
1956
1967
|
} }) }))] }), (0, jsx_runtime_1.jsx)("div", { style: { height: 28, width: '100%' } }), (0, jsx_runtime_1.jsx)(SidebarHeading, { label: "Pivot" }), (0, jsx_runtime_1.jsx)("div", { style: { height: 4, width: '100%' } }), (0, jsx_runtime_1.jsx)(PivotModal_1.PivotModal, { pivotRowField: pivotRowField, setPivotRowField: setPivotRowField, pivotColumnField: pivotColumnField, setPivotColumnField: setPivotColumnField, pivotValueField: pivotValueField, setPivotValueField: setPivotValueField, pivotAggregation: pivotAggregation, setPivotAggregation: setPivotAggregation, createdPivots: createdPivots, setCreatedPivots: setCreatedPivots, recommendedPivots: recommendedPivots, setRecommendedPivots: setRecommendedPivots, popUpTitle: pivotPopUpTitle, setPopUpTitle: setPivotPopUpTitle, selectedTable: initialTableName, SelectComponent: Select, ButtonComponent: Button, PopoverComponent: PivotPopover, TextComponent: Text, isOpen: showPivotPopover, setIsOpen: setShowPivotPopover, showUpdatePivot: isEdittingPivot, setShowUpdatePivot: setIsEdittingPivot, parentRef: parentRef, data: rows, columns: processColumnsForChartBuilder(Object.keys(rows[0] ?? {})), triggerButtonText: 'Add pivot', selectedPivotIndex: selectedPivotIndex, setSelectedPivotIndex: setSelectedPivotIndex, removePivot: () => {
|
|
1957
1968
|
setPivot(null);
|
|
1958
1969
|
setPivotData(null);
|
|
1959
|
-
},
|
|
1970
|
+
},
|
|
1971
|
+
// TODOs
|
|
1972
|
+
selectPivot: (pivot) => {
|
|
1960
1973
|
if (!pivot)
|
|
1961
1974
|
return;
|
|
1962
1975
|
const newAst = { ...baseAst };
|
|
1963
1976
|
newAst.orderby = null;
|
|
1964
1977
|
setBaseAst(newAst); // trigger refetch
|
|
1965
1978
|
setPivot(pivot);
|
|
1966
|
-
|
|
1979
|
+
const pivotedData = (0, PivotModal_1.generatePivotTable)(pivot, rows, [null, null, null], false);
|
|
1980
|
+
setPivotData(pivotedData || []);
|
|
1981
|
+
}, selectPivotOnEdit: true, showTrigger: !pivot, theme: theme, LabelComponent: Label, HeaderComponent: Header, dateRange: [null, null, null], recommendPivotCount: 3, SecondaryButtonComponent: SecondaryButton }), pivot && ((0, jsx_runtime_1.jsx)(PivotList_1.PivotCard, { pivotTable: {
|
|
1967
1982
|
pivot: pivot,
|
|
1968
1983
|
rows: pivotData?.rows || [],
|
|
1969
1984
|
columns: pivotData?.columns || [],
|
|
@@ -1990,10 +2005,16 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
1990
2005
|
}, columns: selectedColumns, setIsPending: setIsPending, setEditPopoverKey: setEditPopoverKey, setActiveEditItem: setActiveEditItem, setOpenPopover: setOpenPopover, SortPopover: SortPopover, EditPopover: AddSortPopover_1.AddSortPopover, handleDelete: () => {
|
|
1991
2006
|
setPivot({ ...pivot, sort: false });
|
|
1992
2007
|
setBaseAst((0, util_1.deepCopy)(baseAst));
|
|
2008
|
+
if (!pivot) {
|
|
2009
|
+
fetchSqlQuery(baseAst);
|
|
2010
|
+
}
|
|
1993
2011
|
}, onSave: (column, direction) => {
|
|
1994
2012
|
setPivot({ ...pivot, sort: true, sortDirection: direction });
|
|
1995
2013
|
setOpenPopover(null);
|
|
1996
2014
|
setBaseAst((0, util_1.deepCopy)(baseAst));
|
|
2015
|
+
if (!pivot) {
|
|
2016
|
+
fetchSqlQuery(baseAst);
|
|
2017
|
+
}
|
|
1997
2018
|
} }, `sort-sentence-pivot`) })), baseAst && baseAst.orderby && ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
1998
2019
|
display: 'flex',
|
|
1999
2020
|
flexDirection: 'column',
|
|
@@ -2018,11 +2039,20 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
2018
2039
|
setActivePath(null);
|
|
2019
2040
|
setOpenPopover(null);
|
|
2020
2041
|
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2042
|
+
if (!pivot) {
|
|
2043
|
+
fetchSqlQuery(newAst);
|
|
2044
|
+
}
|
|
2021
2045
|
}, setIsPending: setIsPending, setEditPopoverKey: setEditPopoverKey, setActiveEditItem: setActiveEditItem, setOpenPopover: setOpenPopover, SortPopover: SortPopover, EditPopover: AddSortPopover_1.AddSortPopover, handleDelete: () => {
|
|
2022
2046
|
const newAst = { ...baseAst };
|
|
2023
2047
|
newAst.orderby.splice(id, 1);
|
|
2024
2048
|
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2049
|
+
if (!pivot) {
|
|
2050
|
+
fetchSqlQuery(newAst);
|
|
2051
|
+
}
|
|
2025
2052
|
} }, `sort-sentence-${id}`))) })), (0, jsx_runtime_1.jsx)(Popover, { isOpen: openPopover === 'AddSortPopover', setIsOpen: () => { }, trigger: (0, jsx_runtime_1.jsx)(SecondaryButton, { onClick: () => {
|
|
2053
|
+
if (!selectedColumns || selectedColumns.length === 0) {
|
|
2054
|
+
return;
|
|
2055
|
+
}
|
|
2026
2056
|
if (!openPopover) {
|
|
2027
2057
|
setOpenPopover('AddSortPopover');
|
|
2028
2058
|
}
|
|
@@ -2040,6 +2070,7 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
2040
2070
|
const newAst = { ...baseAst };
|
|
2041
2071
|
newAst.limit = null;
|
|
2042
2072
|
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2073
|
+
fetchSqlQuery(newAst);
|
|
2043
2074
|
}, onSave: (limit) => {
|
|
2044
2075
|
const newAst = { ...baseAst };
|
|
2045
2076
|
newAst.limit = {
|
|
@@ -2053,6 +2084,7 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
2053
2084
|
};
|
|
2054
2085
|
setOpenPopover(null);
|
|
2055
2086
|
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2087
|
+
fetchSqlQuery(newAst);
|
|
2056
2088
|
} }) })) : ((0, jsx_runtime_1.jsx)(Popover, { isOpen: openPopover === 'AddLimitPopover', setIsOpen: () => { }, trigger: (0, jsx_runtime_1.jsx)(SecondaryButton, { onClick: () => {
|
|
2057
2089
|
if (!openPopover) {
|
|
2058
2090
|
setOpenPopover('AddLimitPopover');
|
|
@@ -2069,11 +2101,11 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
2069
2101
|
flexDirection: 'row',
|
|
2070
2102
|
gap: 12,
|
|
2071
2103
|
padding: 1,
|
|
2072
|
-
}, children: [(0, jsx_runtime_1.jsx)(TextInput, { placeholder: baseAst ? 'Ask a follow-up question...' : 'Ask a question...', type: "text", style: { width: '100%', fontSize: 14 }, value: aiPrompt }), (0, jsx_runtime_1.jsx)(Button, { onClick: () => { }, label: 'Ask AI' }), baseAst && ((0, jsx_runtime_1.jsx)(SecondaryButton, { onClick: clearAllState, label: "New report" }))] })),
|
|
2104
|
+
}, children: [(0, jsx_runtime_1.jsx)(TextInput, { placeholder: baseAst ? 'Ask a follow-up question...' : 'Ask a question...', type: "text", style: { width: '100%', fontSize: 14 }, value: aiPrompt }), (0, jsx_runtime_1.jsx)(Button, { onClick: () => { }, label: 'Ask AI' }), baseAst && ((0, jsx_runtime_1.jsx)(SecondaryButton, { onClick: clearAllState, label: "New report" }))] })), (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(TableLoadingState, {}), (0, jsx_runtime_1.jsxs)("div", { style: {
|
|
2073
2105
|
display: 'flex',
|
|
2074
2106
|
flexDirection: 'row',
|
|
2075
2107
|
gap: '12px',
|
|
2076
|
-
}, children: [(0, jsx_runtime_1.jsx)("div", { style: { width: '100%' } }), (0, jsx_runtime_1.jsx)(SecondaryButton, { onClick: () => copyToClipboard(activeQuery), label: isCopying ? '✅ Copied' : 'Copy SQL' }), (0, jsx_runtime_1.jsx)(Button, { label: 'Add to dashboard', onClick: () => { } })] })] })
|
|
2108
|
+
}, children: [(0, jsx_runtime_1.jsx)("div", { style: { width: '100%' } }), (0, jsx_runtime_1.jsx)(SecondaryButton, { onClick: () => copyToClipboard(activeQuery), label: isCopying ? '✅ Copied' : 'Copy SQL' }), (0, jsx_runtime_1.jsx)(Button, { label: 'Add to dashboard', onClick: () => { } })] })] })] }), (0, jsx_runtime_1.jsx)("style", { children: `body{margin:0;}` })] }));
|
|
2077
2109
|
}
|
|
2078
2110
|
return ((0, jsx_runtime_1.jsxs)("div", { ref: parentRef, style: {
|
|
2079
2111
|
display: 'flex',
|
|
@@ -2098,7 +2130,10 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
2098
2130
|
setActiveEditItem(null);
|
|
2099
2131
|
setActivePath(null);
|
|
2100
2132
|
setOpenPopover(null);
|
|
2101
|
-
}, orderedColumnNames: orderedColumnNames, setOrderedColumnNames: setOrderedColumnNames, selectedColumns: selectedColumns, setSelectedColumns: setSelectedColumns, isSelectedAllColumns: isSelectedAllColumns, clearAllState: clearAllState, nameToColumn: nameToColumn, baseAst: baseAst, setBaseAst:
|
|
2133
|
+
}, orderedColumnNames: orderedColumnNames, setOrderedColumnNames: setOrderedColumnNames, selectedColumns: selectedColumns, setSelectedColumns: setSelectedColumns, isSelectedAllColumns: isSelectedAllColumns, clearAllState: clearAllState, nameToColumn: nameToColumn, baseAst: baseAst, setBaseAst: (ast) => {
|
|
2134
|
+
setBaseAst(ast);
|
|
2135
|
+
fetchSqlQuery(ast);
|
|
2136
|
+
}, pivot: pivot, initialTableName: initialTableName, defaultAST: constants_1.defaultAST, defaultTable: constants_1.defaultTable, setPivot: setPivot, TextInput: TextInput, SelectColumn: SelectColumn, SecondaryButton: SecondaryButton, Button: Button, HandleButton: HandleButton }) }), (0, jsx_runtime_1.jsx)("div", { style: { height: 28, width: '100%' } }), (0, jsx_runtime_1.jsx)(SidebarHeading, { label: "Filters" }), (0, jsx_runtime_1.jsx)("div", { style: { height: 4, width: '100%' } }), formData && ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
2102
2137
|
display: 'flex',
|
|
2103
2138
|
flexDirection: 'column',
|
|
2104
2139
|
gap: 8,
|
|
@@ -2109,6 +2144,9 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
2109
2144
|
gap: 2.5,
|
|
2110
2145
|
alignItems: 'flex-start',
|
|
2111
2146
|
}, children: [(0, jsx_runtime_1.jsx)(Popover, { title: 'Add filter', isOpen: openPopover === 'AddFilterPopover', trigger: (0, jsx_runtime_1.jsx)(SecondaryButton, { onClick: () => {
|
|
2147
|
+
if (!selectedColumns || selectedColumns.length === 0) {
|
|
2148
|
+
return;
|
|
2149
|
+
}
|
|
2112
2150
|
if (!openPopover) {
|
|
2113
2151
|
const value = orderedColumnNames[0];
|
|
2114
2152
|
const [_table, column] = value.split('.');
|
|
@@ -2208,7 +2246,9 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
2208
2246
|
}
|
|
2209
2247
|
setBaseAst(newAst); // trigger refetch
|
|
2210
2248
|
setPivot(pivot);
|
|
2211
|
-
|
|
2249
|
+
const pivotedData = (0, PivotModal_1.generatePivotTable)(pivot, rows, [null, null, null], false);
|
|
2250
|
+
setPivotData(pivotedData || []);
|
|
2251
|
+
}, selectPivotOnEdit: true, showTrigger: !pivot, theme: theme, LabelComponent: Label, HeaderComponent: Header, dateRange: [null, null, null], recommendPivotCount: 3 }), pivot && ((0, jsx_runtime_1.jsx)(PivotList_1.PivotCard, { pivotTable: {
|
|
2212
2252
|
pivot: pivot,
|
|
2213
2253
|
rows: pivotData?.rows || [],
|
|
2214
2254
|
columns: pivotData?.columns || [],
|
|
@@ -2223,7 +2263,7 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
2223
2263
|
}, selectedPivotIndex: -1, onEditPivot: () => { }, ButtonComponent: Button, HeaderComponent: Header, showEdit: false, onClose: () => {
|
|
2224
2264
|
setPivot(null);
|
|
2225
2265
|
setPivotData(null);
|
|
2226
|
-
setBaseAst((0, util_1.deepCopy)(baseAst));
|
|
2266
|
+
setBaseAst((0, util_1.deepCopy)(baseAst));
|
|
2227
2267
|
}, minHeight: 180, LabelComponent: Label, TextComponent: Text })), (0, jsx_runtime_1.jsx)("div", { style: { height: 28, width: '100%' } }), (0, jsx_runtime_1.jsx)(SidebarHeading, { label: "Sort" }), (0, jsx_runtime_1.jsx)("div", { style: { height: 4, width: '100%' } }), pivot && pivot.sort && ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
2228
2268
|
display: 'flex',
|
|
2229
2269
|
flexDirection: 'column',
|
|
@@ -2232,13 +2272,25 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
2232
2272
|
}, children: (0, jsx_runtime_1.jsx)(AddSortPopover_1.SortSentence, { sortData: {
|
|
2233
2273
|
type: pivot.sortDirection,
|
|
2234
2274
|
expr: { type: 'column_ref', column: pivot.rowField },
|
|
2235
|
-
}, columns: selectedColumns, setIsPending: setIsPending, setEditPopoverKey: setEditPopoverKey, setActiveEditItem: setActiveEditItem, setOpenPopover: setOpenPopover, SortPopover: SortPopover, EditPopover: AddSortPopover_1.AddSortPopover, handleDelete: () => {
|
|
2236
|
-
|
|
2275
|
+
}, columns: pivot ? [`.${pivot.rowField}`] : selectedColumns, setIsPending: setIsPending, setEditPopoverKey: setEditPopoverKey, setActiveEditItem: setActiveEditItem, setOpenPopover: setOpenPopover, SortPopover: SortPopover, EditPopover: AddSortPopover_1.AddSortPopover, handleDelete: () => {
|
|
2276
|
+
if (pivot) {
|
|
2277
|
+
setPivot({ ...pivot, sort: false });
|
|
2278
|
+
const pivotedData = (0, PivotModal_1.generatePivotTable)({ ...pivot, sort: false }, rows, [null, null, null], false);
|
|
2279
|
+
setPivotData(pivotedData || []);
|
|
2280
|
+
return;
|
|
2281
|
+
}
|
|
2237
2282
|
setBaseAst((0, util_1.deepCopy)(baseAst));
|
|
2283
|
+
fetchSqlQuery((0, util_1.deepCopy)(baseAst));
|
|
2238
2284
|
}, onSave: (column, direction) => {
|
|
2239
|
-
|
|
2285
|
+
if (pivot) {
|
|
2286
|
+
setPivot({ ...pivot, sort: true, sortDirection: direction });
|
|
2287
|
+
const pivotedData = (0, PivotModal_1.generatePivotTable)({ ...pivot, sort: true, sortDirection: direction }, rows, [null, null, null], false);
|
|
2288
|
+
setPivotData(pivotedData || []);
|
|
2289
|
+
return;
|
|
2290
|
+
}
|
|
2240
2291
|
setOpenPopover(null);
|
|
2241
2292
|
setBaseAst((0, util_1.deepCopy)(baseAst));
|
|
2293
|
+
fetchSqlQuery((0, util_1.deepCopy)(baseAst));
|
|
2242
2294
|
} }, `sort-sentence-pivot`) })), baseAst && baseAst.orderby && ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
2243
2295
|
display: 'flex',
|
|
2244
2296
|
flexDirection: 'column',
|
|
@@ -2252,6 +2304,7 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
2252
2304
|
const newAst = { ...baseAst };
|
|
2253
2305
|
newAst.orderby.splice(id, 1);
|
|
2254
2306
|
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2307
|
+
fetchSqlQuery((0, util_1.deepCopy)(newAst));
|
|
2255
2308
|
}, onSave: (column, direction) => {
|
|
2256
2309
|
if (pivot) {
|
|
2257
2310
|
setPivot({
|
|
@@ -2279,7 +2332,11 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
2279
2332
|
setActivePath(null);
|
|
2280
2333
|
setOpenPopover(null);
|
|
2281
2334
|
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2335
|
+
fetchSqlQuery((0, util_1.deepCopy)(newAst));
|
|
2282
2336
|
} }, `sort-sentence-${id}`))) })), (0, jsx_runtime_1.jsx)(Popover, { isOpen: openPopover === 'AddSortPopover', trigger: (0, jsx_runtime_1.jsx)(SecondaryButton, { onClick: () => {
|
|
2337
|
+
if (!selectedColumns || selectedColumns.length === 0) {
|
|
2338
|
+
return;
|
|
2339
|
+
}
|
|
2283
2340
|
if (!openPopover) {
|
|
2284
2341
|
setOpenPopover('AddSortPopover');
|
|
2285
2342
|
}
|
|
@@ -2293,6 +2350,8 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
2293
2350
|
return;
|
|
2294
2351
|
if (pivot) {
|
|
2295
2352
|
setPivot({ ...pivot, sort: true, sortDirection: direction });
|
|
2353
|
+
const pivotedData = (0, PivotModal_1.generatePivotTable)({ ...pivot, sort: true, sortDirection: direction }, rows, [null, null, null], false);
|
|
2354
|
+
setPivotData(pivotedData || []);
|
|
2296
2355
|
setActivePath(null);
|
|
2297
2356
|
setOpenPopover(null);
|
|
2298
2357
|
setBaseAst((0, util_1.deepCopy)(baseAst));
|
|
@@ -2309,6 +2368,7 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
2309
2368
|
setActivePath(null);
|
|
2310
2369
|
setOpenPopover(null);
|
|
2311
2370
|
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2371
|
+
fetchSqlQuery((0, util_1.deepCopy)(newAst));
|
|
2312
2372
|
} }) }), (0, jsx_runtime_1.jsx)("div", { style: { height: 28, width: '100%' } }), (0, jsx_runtime_1.jsx)(SidebarHeading, { label: "Limit" }), (0, jsx_runtime_1.jsx)("div", { style: { height: 4, width: '100%' } }), baseAst && baseAst.limit ? ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
2313
2373
|
display: 'flex',
|
|
2314
2374
|
flexDirection: 'column',
|
|
@@ -2318,6 +2378,7 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
2318
2378
|
const newAst = { ...baseAst };
|
|
2319
2379
|
newAst.limit = null;
|
|
2320
2380
|
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2381
|
+
fetchSqlQuery((0, util_1.deepCopy)(newAst));
|
|
2321
2382
|
}, onSave: (limit) => {
|
|
2322
2383
|
const newAst = { ...baseAst };
|
|
2323
2384
|
newAst.limit = {
|
|
@@ -2331,7 +2392,11 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
2331
2392
|
};
|
|
2332
2393
|
setOpenPopover(null);
|
|
2333
2394
|
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2395
|
+
fetchSqlQuery((0, util_1.deepCopy)(newAst));
|
|
2334
2396
|
} }) })) : ((0, jsx_runtime_1.jsx)(Popover, { isOpen: openPopover === 'AddLimitPopover', setIsOpen: () => { }, trigger: (0, jsx_runtime_1.jsx)(SecondaryButton, { onClick: () => {
|
|
2397
|
+
if (!selectedColumns || selectedColumns.length === 0) {
|
|
2398
|
+
return;
|
|
2399
|
+
}
|
|
2335
2400
|
if (!baseAst) {
|
|
2336
2401
|
return;
|
|
2337
2402
|
}
|
|
@@ -2356,6 +2421,7 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
2356
2421
|
};
|
|
2357
2422
|
setOpenPopover(null);
|
|
2358
2423
|
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2424
|
+
fetchSqlQuery((0, util_1.deepCopy)(newAst));
|
|
2359
2425
|
} }) }))] }), (0, jsx_runtime_1.jsxs)(Container, { children: [!hideAi && ((0, jsx_runtime_1.jsxs)("form", { onSubmit: (event) => {
|
|
2360
2426
|
event.preventDefault();
|
|
2361
2427
|
handleAsk();
|
|
@@ -2367,8 +2433,9 @@ function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () =>
|
|
|
2367
2433
|
}, children: [(0, jsx_runtime_1.jsx)(TextInput, { type: "text", value: aiPrompt, style: { width: '100%', fontSize: 14 }, onChange: (e) => setAiPrompt(e.target.value), placeholder: baseAst ? 'Ask a follow-up question...' : 'Ask a question...' }), (0, jsx_runtime_1.jsx)(Button, { onClick: handleAsk, label: 'Ask AI' }), baseAst && ((0, jsx_runtime_1.jsx)(SecondaryButton, { label: 'New report', onClick: clearAllState }))] })), baseAst && ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: loading && errorMessage.length === 0 ? ((0, jsx_runtime_1.jsx)(TableLoadingState, {})) : ((0, jsx_runtime_1.jsx)(Table, { rows: applyFormatting({
|
|
2368
2434
|
rows: pivotData?.rows || rows,
|
|
2369
2435
|
fields: pivotData?.fields || fields,
|
|
2370
|
-
}, baseAst?.columns ?? []), columns:
|
|
2371
|
-
|
|
2436
|
+
}, baseAst?.columns ?? []), columns: pivot
|
|
2437
|
+
? pivotData?.columns || emptyPivotColumns()
|
|
2438
|
+
: enforceOrderOnColumns(Object.keys(rows[0] ?? {})).map((c) => {
|
|
2372
2439
|
return { label: (0, textProcessing_1.snakeCaseToTitleCase)(c), field: c };
|
|
2373
2440
|
}), error: errorMessage, rowsPerPage: 20 })) })), (0, jsx_runtime_1.jsxs)("div", { style: {
|
|
2374
2441
|
display: 'flex',
|