@quillsql/react 2.11.23 → 2.11.24
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 +32 -16
- package/dist/cjs/ChartBuilder.d.ts +55 -2
- package/dist/cjs/ChartBuilder.d.ts.map +1 -1
- package/dist/cjs/ChartBuilder.js +223 -206
- package/dist/cjs/ChartEditor.d.ts +49 -2
- package/dist/cjs/ChartEditor.d.ts.map +1 -1
- package/dist/cjs/ChartEditor.js +3 -3
- package/dist/cjs/Dashboard.d.ts +5 -1
- package/dist/cjs/Dashboard.d.ts.map +1 -1
- package/dist/cjs/Dashboard.js +42 -18
- package/dist/cjs/DateRangePicker/QuillDateRangePicker.d.ts +2 -1
- package/dist/cjs/DateRangePicker/QuillDateRangePicker.d.ts.map +1 -1
- package/dist/cjs/DateRangePicker/QuillDateRangePicker.js +4 -3
- package/dist/cjs/ReportBuilder.d.ts +57 -2
- package/dist/cjs/ReportBuilder.d.ts.map +1 -1
- package/dist/cjs/ReportBuilder.js +969 -684
- package/dist/cjs/SQLEditor.d.ts +83 -2
- package/dist/cjs/SQLEditor.d.ts.map +1 -1
- package/dist/cjs/SQLEditor.js +10 -2
- package/dist/cjs/components/Chart/BarChart.d.ts.map +1 -1
- package/dist/cjs/components/Chart/BarChart.js +8 -6
- package/dist/cjs/components/Chart/BarList.d.ts.map +1 -1
- package/dist/cjs/components/Chart/BarList.js +0 -153
- package/dist/cjs/components/Chart/ChartError.d.ts +1 -1
- package/dist/cjs/components/Chart/ChartError.d.ts.map +1 -1
- package/dist/cjs/components/Chart/ChartError.js +13 -7
- package/dist/cjs/components/Chart/ChartTooltip.d.ts +1 -0
- package/dist/cjs/components/Chart/ChartTooltip.d.ts.map +1 -1
- package/dist/cjs/components/Chart/ChartTooltip.js +6 -7
- package/dist/cjs/components/Chart/LineChart.d.ts +1 -1
- package/dist/cjs/components/Chart/LineChart.d.ts.map +1 -1
- package/dist/cjs/components/Chart/LineChart.js +32 -31
- package/dist/cjs/components/Dashboard/DashboardFilter.d.ts +1 -1
- package/dist/cjs/components/Dashboard/DashboardFilter.d.ts.map +1 -1
- package/dist/cjs/components/Dashboard/DashboardFilter.js +21 -21
- package/dist/cjs/components/Dashboard/DataLoader.d.ts +24 -0
- package/dist/cjs/components/Dashboard/DataLoader.d.ts.map +1 -1
- package/dist/cjs/components/Dashboard/DataLoader.js +84 -0
- package/dist/cjs/components/Dashboard/MetricComponent.d.ts.map +1 -1
- package/dist/cjs/components/Dashboard/MetricComponent.js +4 -1
- package/dist/cjs/components/QuillSelect.js +1 -1
- package/dist/cjs/components/QuillTable.d.ts.map +1 -1
- package/dist/cjs/components/QuillTable.js +11 -12
- package/dist/cjs/components/ReportBuilder/{AddColumnPopover.d.ts → AddColumnModal.d.ts} +3 -2
- package/dist/cjs/components/ReportBuilder/AddColumnModal.d.ts.map +1 -0
- package/dist/cjs/components/ReportBuilder/{AddColumnPopover.js → AddColumnModal.js} +12 -8
- package/dist/cjs/components/ReportBuilder/AddLimitPopover.d.ts.map +1 -1
- package/dist/cjs/components/ReportBuilder/AddLimitPopover.js +1 -1
- package/dist/cjs/components/ReportBuilder/AddSortPopover.d.ts +1 -1
- package/dist/cjs/components/ReportBuilder/AddSortPopover.d.ts.map +1 -1
- package/dist/cjs/components/ReportBuilder/AddSortPopover.js +5 -5
- package/dist/cjs/components/ReportBuilder/ast.d.ts +6 -0
- package/dist/cjs/components/ReportBuilder/ast.d.ts.map +1 -1
- package/dist/cjs/components/ReportBuilder/ast.js +13 -2
- package/dist/cjs/components/ReportBuilder/constants.d.ts +13 -0
- package/dist/cjs/components/ReportBuilder/constants.d.ts.map +1 -1
- package/dist/cjs/components/ReportBuilder/constants.js +14 -1
- package/dist/cjs/components/ReportBuilder/convert.d.ts +18 -1
- package/dist/cjs/components/ReportBuilder/convert.d.ts.map +1 -1
- package/dist/cjs/components/ReportBuilder/convert.js +14 -3
- package/dist/cjs/components/ReportBuilder/operators.d.ts +15 -23
- package/dist/cjs/components/ReportBuilder/operators.d.ts.map +1 -1
- package/dist/cjs/components/ReportBuilder/operators.js +19 -27
- package/dist/cjs/components/ReportBuilder/pivot.d.ts +2 -0
- package/dist/cjs/components/ReportBuilder/pivot.d.ts.map +1 -1
- package/dist/cjs/components/ReportBuilder/ui.d.ts +3 -2
- package/dist/cjs/components/ReportBuilder/ui.d.ts.map +1 -1
- package/dist/cjs/components/ReportBuilder/ui.js +54 -28
- package/dist/cjs/components/ReportBuilder/util.d.ts +1 -1
- package/dist/cjs/components/ReportBuilder/util.d.ts.map +1 -1
- package/dist/cjs/components/ReportBuilder/util.js +3 -0
- package/dist/cjs/components/UiComponents.d.ts +34 -4
- package/dist/cjs/components/UiComponents.d.ts.map +1 -1
- package/dist/cjs/components/UiComponents.js +165 -68
- package/dist/cjs/hooks/useQuill.d.ts +1 -0
- package/dist/cjs/hooks/useQuill.d.ts.map +1 -1
- package/dist/cjs/internals/ReportBuilder/PivotList.d.ts +1 -2
- package/dist/cjs/internals/ReportBuilder/PivotList.d.ts.map +1 -1
- package/dist/cjs/internals/ReportBuilder/PivotList.js +5 -7
- package/dist/cjs/internals/ReportBuilder/PivotModal.d.ts +31 -5
- package/dist/cjs/internals/ReportBuilder/PivotModal.d.ts.map +1 -1
- package/dist/cjs/internals/ReportBuilder/PivotModal.js +437 -282
- package/dist/cjs/utils/axisFormatter.js +3 -3
- package/dist/cjs/utils/getDomain.d.ts.map +1 -1
- package/dist/cjs/utils/getDomain.js +3 -0
- package/dist/cjs/utils/merge.d.ts.map +1 -1
- package/dist/cjs/utils/merge.js +2 -0
- package/dist/cjs/utils/pivotProcessing.d.ts +20 -0
- package/dist/cjs/utils/pivotProcessing.d.ts.map +1 -0
- package/dist/cjs/utils/pivotProcessing.js +177 -0
- package/dist/cjs/utils/queryConstructor.d.ts +2 -0
- package/dist/cjs/utils/queryConstructor.d.ts.map +1 -0
- package/dist/cjs/utils/queryConstructor.js +11 -0
- package/dist/cjs/utils/tableProcessing.d.ts +7 -0
- package/dist/cjs/utils/tableProcessing.d.ts.map +1 -0
- package/dist/cjs/utils/tableProcessing.js +84 -0
- package/dist/cjs/utils/valueFormatter.d.ts.map +1 -1
- package/dist/cjs/utils/valueFormatter.js +40 -8
- package/dist/esm/Chart.d.ts.map +1 -1
- package/dist/esm/Chart.js +33 -17
- package/dist/esm/ChartBuilder.d.ts +55 -2
- package/dist/esm/ChartBuilder.d.ts.map +1 -1
- package/dist/esm/ChartBuilder.js +225 -208
- package/dist/esm/ChartEditor.d.ts +49 -2
- package/dist/esm/ChartEditor.d.ts.map +1 -1
- package/dist/esm/ChartEditor.js +4 -4
- package/dist/esm/Dashboard.d.ts +5 -1
- package/dist/esm/Dashboard.d.ts.map +1 -1
- package/dist/esm/Dashboard.js +21 -20
- package/dist/esm/DateRangePicker/QuillDateRangePicker.d.ts +2 -1
- package/dist/esm/DateRangePicker/QuillDateRangePicker.d.ts.map +1 -1
- package/dist/esm/DateRangePicker/QuillDateRangePicker.js +4 -3
- package/dist/esm/ReportBuilder.d.ts +57 -2
- package/dist/esm/ReportBuilder.d.ts.map +1 -1
- package/dist/esm/ReportBuilder.js +971 -687
- package/dist/esm/SQLEditor.d.ts +83 -2
- package/dist/esm/SQLEditor.d.ts.map +1 -1
- package/dist/esm/SQLEditor.js +11 -3
- package/dist/esm/components/Chart/BarChart.d.ts.map +1 -1
- package/dist/esm/components/Chart/BarChart.js +8 -6
- package/dist/esm/components/Chart/BarList.d.ts.map +1 -1
- package/dist/esm/components/Chart/BarList.js +0 -153
- package/dist/esm/components/Chart/ChartError.d.ts +1 -1
- package/dist/esm/components/Chart/ChartError.d.ts.map +1 -1
- package/dist/esm/components/Chart/ChartError.js +13 -7
- package/dist/esm/components/Chart/ChartTooltip.d.ts +1 -0
- package/dist/esm/components/Chart/ChartTooltip.d.ts.map +1 -1
- package/dist/esm/components/Chart/ChartTooltip.js +6 -7
- package/dist/esm/components/Chart/LineChart.d.ts +1 -1
- package/dist/esm/components/Chart/LineChart.d.ts.map +1 -1
- package/dist/esm/components/Chart/LineChart.js +32 -31
- package/dist/esm/components/Dashboard/DashboardFilter.d.ts +1 -1
- package/dist/esm/components/Dashboard/DashboardFilter.d.ts.map +1 -1
- package/dist/esm/components/Dashboard/DashboardFilter.js +21 -21
- package/dist/esm/components/Dashboard/DataLoader.d.ts +24 -0
- package/dist/esm/components/Dashboard/DataLoader.d.ts.map +1 -1
- package/dist/esm/components/Dashboard/DataLoader.js +82 -0
- package/dist/esm/components/Dashboard/MetricComponent.d.ts.map +1 -1
- package/dist/esm/components/Dashboard/MetricComponent.js +4 -1
- package/dist/esm/components/QuillSelect.js +1 -1
- package/dist/esm/components/QuillTable.d.ts.map +1 -1
- package/dist/esm/components/QuillTable.js +11 -12
- package/dist/esm/components/ReportBuilder/{AddColumnPopover.d.ts → AddColumnModal.d.ts} +3 -2
- package/dist/esm/components/ReportBuilder/AddColumnModal.d.ts.map +1 -0
- package/dist/esm/components/ReportBuilder/{AddColumnPopover.js → AddColumnModal.js} +11 -7
- package/dist/esm/components/ReportBuilder/AddLimitPopover.d.ts.map +1 -1
- package/dist/esm/components/ReportBuilder/AddLimitPopover.js +1 -1
- package/dist/esm/components/ReportBuilder/AddSortPopover.d.ts +1 -1
- package/dist/esm/components/ReportBuilder/AddSortPopover.d.ts.map +1 -1
- package/dist/esm/components/ReportBuilder/AddSortPopover.js +5 -5
- package/dist/esm/components/ReportBuilder/ast.d.ts +6 -0
- package/dist/esm/components/ReportBuilder/ast.d.ts.map +1 -1
- package/dist/esm/components/ReportBuilder/ast.js +11 -1
- package/dist/esm/components/ReportBuilder/constants.d.ts +13 -0
- package/dist/esm/components/ReportBuilder/constants.d.ts.map +1 -1
- package/dist/esm/components/ReportBuilder/constants.js +13 -0
- package/dist/esm/components/ReportBuilder/convert.d.ts +18 -1
- package/dist/esm/components/ReportBuilder/convert.d.ts.map +1 -1
- package/dist/esm/components/ReportBuilder/convert.js +14 -3
- package/dist/esm/components/ReportBuilder/operators.d.ts +15 -23
- package/dist/esm/components/ReportBuilder/operators.d.ts.map +1 -1
- package/dist/esm/components/ReportBuilder/operators.js +19 -27
- package/dist/esm/components/ReportBuilder/pivot.d.ts +2 -0
- package/dist/esm/components/ReportBuilder/pivot.d.ts.map +1 -1
- package/dist/esm/components/ReportBuilder/ui.d.ts +3 -2
- package/dist/esm/components/ReportBuilder/ui.d.ts.map +1 -1
- package/dist/esm/components/ReportBuilder/ui.js +55 -29
- package/dist/esm/components/ReportBuilder/util.d.ts +1 -1
- package/dist/esm/components/ReportBuilder/util.d.ts.map +1 -1
- package/dist/esm/components/ReportBuilder/util.js +3 -0
- package/dist/esm/components/UiComponents.d.ts +34 -4
- package/dist/esm/components/UiComponents.d.ts.map +1 -1
- package/dist/esm/components/UiComponents.js +155 -66
- package/dist/esm/hooks/useQuill.d.ts +1 -0
- package/dist/esm/hooks/useQuill.d.ts.map +1 -1
- package/dist/esm/internals/ReportBuilder/PivotList.d.ts +1 -2
- package/dist/esm/internals/ReportBuilder/PivotList.d.ts.map +1 -1
- package/dist/esm/internals/ReportBuilder/PivotList.js +5 -7
- package/dist/esm/internals/ReportBuilder/PivotModal.d.ts +31 -5
- package/dist/esm/internals/ReportBuilder/PivotModal.d.ts.map +1 -1
- package/dist/esm/internals/ReportBuilder/PivotModal.js +438 -284
- package/dist/esm/utils/axisFormatter.js +3 -3
- package/dist/esm/utils/getDomain.d.ts.map +1 -1
- package/dist/esm/utils/getDomain.js +3 -0
- package/dist/esm/utils/merge.d.ts.map +1 -1
- package/dist/esm/utils/merge.js +2 -0
- package/dist/esm/utils/pivotProcessing.d.ts +20 -0
- package/dist/esm/utils/pivotProcessing.d.ts.map +1 -0
- package/dist/esm/utils/pivotProcessing.js +170 -0
- package/dist/esm/utils/queryConstructor.d.ts +2 -0
- package/dist/esm/utils/queryConstructor.d.ts.map +1 -0
- package/dist/esm/utils/queryConstructor.js +7 -0
- package/dist/esm/utils/tableProcessing.d.ts +7 -0
- package/dist/esm/utils/tableProcessing.d.ts.map +1 -0
- package/dist/esm/utils/tableProcessing.js +80 -0
- package/dist/esm/utils/valueFormatter.d.ts.map +1 -1
- package/dist/esm/utils/valueFormatter.js +41 -9
- package/package.json +1 -1
- package/dist/cjs/components/ReportBuilder/AddColumnPopover.d.ts.map +0 -1
- package/dist/esm/components/ReportBuilder/AddColumnPopover.d.ts.map +0 -1
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.QUILL_SERVER = void 0;
|
|
6
7
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
8
|
/* eslint-disable no-unused-vars */
|
|
8
9
|
const react_1 = require("react");
|
|
@@ -22,7 +23,7 @@ const util_1 = require("./components/ReportBuilder/util");
|
|
|
22
23
|
const operators_1 = require("./components/ReportBuilder/operators");
|
|
23
24
|
const crypto_1 = require("./utils/crypto");
|
|
24
25
|
const constants_1 = require("./components/ReportBuilder/constants");
|
|
25
|
-
const
|
|
26
|
+
const AddColumnModal_1 = __importDefault(require("./components/ReportBuilder/AddColumnModal"));
|
|
26
27
|
const AddSortPopover_1 = require("./components/ReportBuilder/AddSortPopover");
|
|
27
28
|
const PivotModal_1 = require("./internals/ReportBuilder/PivotModal");
|
|
28
29
|
const PivotList_1 = require("./internals/ReportBuilder/PivotList");
|
|
@@ -32,6 +33,12 @@ const width_1 = require("./utils/width");
|
|
|
32
33
|
const QuillSelect_1 = require("./components/QuillSelect");
|
|
33
34
|
const QuillCard_1 = require("./components/QuillCard");
|
|
34
35
|
const SQLEditor_1 = require("./SQLEditor");
|
|
36
|
+
const dataFetcher_1 = require("./utils/dataFetcher");
|
|
37
|
+
const valueFormatter_1 = require("./utils/valueFormatter");
|
|
38
|
+
const pivotProcessing_1 = require("./utils/pivotProcessing");
|
|
39
|
+
const tableProcessing_1 = require("./utils/tableProcessing");
|
|
40
|
+
const useQuill_1 = require("./hooks/useQuill");
|
|
41
|
+
exports.QUILL_SERVER = process.env.QUILL_SERVER_HOST ?? 'https://quill-344421.uc.r.appspot.com';
|
|
35
42
|
/**
|
|
36
43
|
* Quill Report Builder
|
|
37
44
|
*
|
|
@@ -63,7 +70,8 @@ const SQLEditor_1 = require("./SQLEditor");
|
|
|
63
70
|
* ### Report Builder API
|
|
64
71
|
* @see https://docs.quillsql.com/components/report-builder
|
|
65
72
|
*/
|
|
66
|
-
function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => void null, destinationDashboard = undefined, organizationName = '', ButtonComponent = UiComponents_1.MemoizedButton, SecondaryButtonComponent = UiComponents_1.MemoizedSecondaryButton, DeleteButtonComponent = UiComponents_1.MemoizedDeleteButton, ModalComponent = UiComponents_1.MemoizedModal, TextInputComponent = UiComponents_2.QuillTextInput, SelectComponent = QuillSelect_1.QuillSelectComponent, TableComponent = UiComponents_1.QuillTableComponent, PopoverComponent = UiComponents_1.MemoizedPopover, TabsComponent = UiComponents_1.QuillTabs, CheckboxComponent = UiComponents_1.MemoizedCheckbox, SidebarComponent = ui_1.QuillSidebar, ContainerComponent = ui_1.CustomContainer, SelectColumnComponent = ui_1.QuillSelectColumn, DraggableColumnComponent = ui_1.QuillDraggableColumn, SidebarHeadingComponent = ui_1.QuillSidebarHeading, FilterPopoverComponent = ui_1.QuillFilterPopover, SortPopoverComponent = ui_1.QuillSortPopover, LimitPopoverComponent = ui_1.QuillLimitPopover, CardComponent = QuillCard_1.QuillCard, LabelComponent = UiComponents_1.MemoizedLabel, HeaderComponent = UiComponents_1.MemoizedHeader, TextComponent = UiComponents_1.MemoizedText, isAdminEnabled = false, isAIEnabled = true, showChartBuilderTableFormatOptions = true, containerStyle, className, }) {
|
|
73
|
+
function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = (_) => void null, destinationDashboard = undefined, organizationName = '', ButtonComponent = UiComponents_1.MemoizedButton, SecondaryButtonComponent = UiComponents_1.MemoizedSecondaryButton, DeleteButtonComponent = UiComponents_1.MemoizedDeleteButton, ModalComponent = UiComponents_1.MemoizedModal, TextInputComponent = UiComponents_2.QuillTextInput, SelectComponent = QuillSelect_1.QuillSelectComponent, TableComponent = UiComponents_1.QuillTableComponent, PopoverComponent = UiComponents_1.MemoizedPopover, TabsComponent = UiComponents_1.QuillTabs, CheckboxComponent = UiComponents_1.MemoizedCheckbox, SidebarComponent = ui_1.QuillSidebar, ContainerComponent = ui_1.CustomContainer, SelectColumnComponent = ui_1.QuillSelectColumn, DraggableColumnComponent = ui_1.QuillDraggableColumn, SidebarHeadingComponent = ui_1.QuillSidebarHeading, FilterPopoverComponent = ui_1.QuillFilterPopover, SortPopoverComponent = ui_1.QuillSortPopover, LimitPopoverComponent = ui_1.QuillLimitPopover, CardComponent = QuillCard_1.QuillCard, LabelComponent = UiComponents_1.MemoizedLabel, HeaderComponent = UiComponents_1.MemoizedHeader, SubHeaderComponent = UiComponents_1.MemoizedSubHeader, TextComponent = UiComponents_1.MemoizedText, ErrorMessageComponent = UiComponents_1.QuillErrorMessageComponent, ChartBuilderInputRowContainer = UiComponents_1.QuillChartBuilderInputRowContainer, ChartBuilderInputColumnContainer = UiComponents_1.QuillChartBuilderInputColumnContainer, PivotRowContainer = UiComponents_1.QuillPivotRowContainer, PivotColumnContainer = UiComponents_1.QuillPivotColumnContainer, ColumnSearchEmptyState = UiComponents_1.QuillColumnSearchEmptyState, ChartBuilderFormContainer = UiComponents_1.QuillChartBuilderFormContainer, isAdminEnabled = false, isAIEnabled = true, showChartBuilderTableFormatOptions = true, containerStyle, className, pivotRecommendationsEnabled = true, initialChartId, }) {
|
|
74
|
+
const { data: initialData } = (0, useQuill_1.useQuill)(initialChartId || '');
|
|
67
75
|
const [aiPrompt, setAiPrompt] = (0, react_1.useState)('');
|
|
68
76
|
const [errorMessage, setErrorMessage] = (0, react_1.useState)('');
|
|
69
77
|
const [baseAst, setBaseAst] = (0, react_1.useState)(null);
|
|
@@ -83,6 +91,7 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
83
91
|
const [isCopying, setIsCopying] = (0, react_1.useState)(false);
|
|
84
92
|
const [dataDisplayed, setDataDisplayed] = (0, react_1.useState)(false);
|
|
85
93
|
const [rows, setRows] = (0, react_1.useState)([]);
|
|
94
|
+
const [formattedRows, setFormattedRows] = (0, react_1.useState)([]);
|
|
86
95
|
const [fields, setFields] = (0, react_1.useState)([]);
|
|
87
96
|
const [topLevelBinaryOperator, setTopLevelBinaryOperator] = (0, react_1.useState)('AND');
|
|
88
97
|
const [editPopoverKey, setEditPopoverKey] = (0, react_1.useState)(null);
|
|
@@ -91,17 +100,17 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
91
100
|
const [pivotData, setPivotData] = (0, react_1.useState)(null);
|
|
92
101
|
const [createdPivots, setCreatedPivots] = (0, react_1.useState)([]);
|
|
93
102
|
const [recommendedPivots, setRecommendedPivots] = (0, react_1.useState)([]);
|
|
94
|
-
const [pivotPopUpTitle, setPivotPopUpTitle] = (0, react_1.useState)('Add
|
|
103
|
+
const [pivotPopUpTitle, setPivotPopUpTitle] = (0, react_1.useState)('Add pivot');
|
|
95
104
|
const [showPivotPopover, setShowPivotPopover] = (0, react_1.useState)(false);
|
|
96
105
|
const [isEdittingPivot, setIsEdittingPivot] = (0, react_1.useState)(false);
|
|
97
106
|
const [selectedPivotIndex, setSelectedPivotIndex] = (0, react_1.useState)(-1);
|
|
98
|
-
const [initialLoad, setInitialLoad] = (0, react_1.useState)(!!initialTableName);
|
|
107
|
+
const [initialLoad, setInitialLoad] = (0, react_1.useState)(!!initialTableName || !!initialChartId);
|
|
99
108
|
const [currentTable, setCurrentTable] = (0, react_1.useState)(initialTableName || '');
|
|
100
109
|
const parentRef = (0, react_1.useRef)(null);
|
|
101
110
|
const askAIContainerRef = (0, react_1.useRef)(null);
|
|
102
111
|
const askAILoadingContainerRef = (0, react_1.useRef)(null);
|
|
103
|
-
const [askAIInputWidth, setAskAIInputWidth] = (0, react_1.useState)(
|
|
104
|
-
const [askAILoadingContainerWidth, setAskAILoadingContainerWidth] = (0, react_1.useState)(
|
|
112
|
+
const [askAIInputWidth, setAskAIInputWidth] = (0, react_1.useState)(-1);
|
|
113
|
+
const [askAILoadingContainerWidth, setAskAILoadingContainerWidth] = (0, react_1.useState)(-1);
|
|
105
114
|
const [theme] = (0, react_1.useContext)(Context_1.ThemeContext);
|
|
106
115
|
const [pivotRowField, setPivotRowField] = (0, react_1.useState)(undefined);
|
|
107
116
|
const [pivotColumnField, setPivotColumnField] = (0, react_1.useState)(undefined);
|
|
@@ -109,6 +118,17 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
109
118
|
const [pivotAggregation, setPivotAggregation] = (0, react_1.useState)(undefined);
|
|
110
119
|
// eslint-disable-next-line no-unused-vars
|
|
111
120
|
const [client, _setClient] = (0, react_1.useContext)(Context_1.ClientContext);
|
|
121
|
+
// JANK: This is temp and stupid
|
|
122
|
+
const [overrideRecommendations, setOverrideRecommendations] = (0, react_1.useState)(true);
|
|
123
|
+
(0, react_1.useEffect)(() => {
|
|
124
|
+
if (client.publicKey === '663416663aa9bc716e59a89d') {
|
|
125
|
+
setOverrideRecommendations(false);
|
|
126
|
+
}
|
|
127
|
+
}, [client.publicKey]);
|
|
128
|
+
(0, react_1.useEffect)(() => {
|
|
129
|
+
(0, width_1.updateFirstChildWidth)(askAIContainerRef, setAskAIInputWidth, { gap: 12 });
|
|
130
|
+
(0, width_1.updateFirstChildWidth)(askAILoadingContainerRef, setAskAILoadingContainerWidth, { gap: 12 });
|
|
131
|
+
}, [dataDisplayed]);
|
|
112
132
|
(0, react_1.useEffect)(() => {
|
|
113
133
|
// Since the TextInput component takes a required numeric width parameter,
|
|
114
134
|
// we dynamically calculate the width of this component here.
|
|
@@ -121,7 +141,7 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
121
141
|
return () => {
|
|
122
142
|
window.removeEventListener('resize', handleResize);
|
|
123
143
|
};
|
|
124
|
-
}, [
|
|
144
|
+
}, []);
|
|
125
145
|
const enforceOrderOnColumns = (columnNames) => {
|
|
126
146
|
if (pivot) {
|
|
127
147
|
const rowName = pivot.rowField;
|
|
@@ -135,39 +155,6 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
135
155
|
return columnNames.sort((a, b) => selectedOrderedColumns.indexOf(a) - selectedOrderedColumns.indexOf(b));
|
|
136
156
|
// return columnNames;
|
|
137
157
|
};
|
|
138
|
-
/**
|
|
139
|
-
* Transforms an array of column names into an array of columnInfo objects
|
|
140
|
-
* with label, field, format, and fieldType keys.
|
|
141
|
-
*/
|
|
142
|
-
const processColumnsForPivotModal = (columns) => {
|
|
143
|
-
return columns.map((col) => ({
|
|
144
|
-
label: col,
|
|
145
|
-
name: col,
|
|
146
|
-
displayName: (0, textProcessing_1.snakeCaseToTitleCase)(col),
|
|
147
|
-
field: col,
|
|
148
|
-
format: (0, util_1.getPostgresBasicType)(fields.find((f) => f.name === col))?.replace('number', 'whole_number') || 'string',
|
|
149
|
-
fieldType: schemaTables
|
|
150
|
-
.flatMap((t) => t.columns)
|
|
151
|
-
.find((c) => c.name === col)?.fieldType || 'text',
|
|
152
|
-
}));
|
|
153
|
-
};
|
|
154
|
-
/**
|
|
155
|
-
* Transforms an array of column names into an array of columnInfo objects
|
|
156
|
-
* with label, field, format, and fieldType keys.
|
|
157
|
-
*/
|
|
158
|
-
const processColumnsForChartBuilder = (columns) => {
|
|
159
|
-
return columns.map((col) => ({
|
|
160
|
-
label: col,
|
|
161
|
-
name: col,
|
|
162
|
-
displayName: (0, textProcessing_1.snakeCaseToTitleCase)(col),
|
|
163
|
-
field: col,
|
|
164
|
-
format: (0, SQLEditor_1.convertPostgresColumn)(fields.find((f) => f.name === col)).format ||
|
|
165
|
-
'string',
|
|
166
|
-
fieldType: schemaTables
|
|
167
|
-
.flatMap((t) => t.columns)
|
|
168
|
-
.find((c) => c.name === col)?.fieldType || 'text',
|
|
169
|
-
}));
|
|
170
|
-
};
|
|
171
158
|
const clearAllState = () => {
|
|
172
159
|
// We're trying to not block the main thread while resetting all the state.
|
|
173
160
|
// This shouldn't be an issue since the dispatches shouldn't block, but
|
|
@@ -191,6 +178,7 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
191
178
|
setTopLevelBinaryOperator('AND');
|
|
192
179
|
setEditPopoverKey(null);
|
|
193
180
|
setErrorMessage('');
|
|
181
|
+
setFormattedRows([]);
|
|
194
182
|
// setUniqueValues({});
|
|
195
183
|
setPivot(null);
|
|
196
184
|
setPivotData(null);
|
|
@@ -201,7 +189,7 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
201
189
|
if (!initialLoad && client.publicKey) {
|
|
202
190
|
clearAllState();
|
|
203
191
|
}
|
|
204
|
-
}, [client.publicKey]);
|
|
192
|
+
}, [client.publicKey, client.customerId]);
|
|
205
193
|
(0, react_1.useEffect)(() => {
|
|
206
194
|
if (activePath !== null) {
|
|
207
195
|
// update the modal with the new subtree
|
|
@@ -264,7 +252,7 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
264
252
|
setErrorMessage('');
|
|
265
253
|
try {
|
|
266
254
|
const where = formData ? formData : ast?.where || null;
|
|
267
|
-
const response = await fetch(
|
|
255
|
+
const response = await fetch(`${exports.QUILL_SERVER}/sqlify`, {
|
|
268
256
|
method: 'POST',
|
|
269
257
|
headers: {
|
|
270
258
|
'Content-Type': 'application/json',
|
|
@@ -277,7 +265,7 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
277
265
|
const data = await response.json();
|
|
278
266
|
setActiveQuery(data.query);
|
|
279
267
|
if (fetchData) {
|
|
280
|
-
fetchUponChange(ast, formData);
|
|
268
|
+
fetchUponChange(ast, formData, data.query);
|
|
281
269
|
}
|
|
282
270
|
}
|
|
283
271
|
catch (error) {
|
|
@@ -305,43 +293,84 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
305
293
|
result.push(valueField, rowField);
|
|
306
294
|
return result.filter(Boolean);
|
|
307
295
|
};
|
|
308
|
-
const
|
|
296
|
+
const fetchDistinctStrings = async (query, table) => {
|
|
309
297
|
try {
|
|
310
|
-
const
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
298
|
+
const hostedBody = {
|
|
299
|
+
metadata: {
|
|
300
|
+
query,
|
|
301
|
+
task: 'query',
|
|
302
|
+
orgId: client.customerId || '*',
|
|
303
|
+
clientId: client.publicKey,
|
|
304
|
+
databaseType: client?.databaseType,
|
|
315
305
|
},
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
query: query,
|
|
320
|
-
}),
|
|
321
|
-
});
|
|
322
|
-
const data = await response.json();
|
|
306
|
+
};
|
|
307
|
+
const cloudBody = { query };
|
|
308
|
+
const data = await (0, dataFetcher_1.getData)(client, 'dashquery', 'same-origin', hostedBody, cloudBody);
|
|
323
309
|
if (data.errorMessage) {
|
|
324
|
-
// console.error(data.errorMessage);
|
|
325
310
|
return null;
|
|
326
311
|
}
|
|
327
|
-
const
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
312
|
+
const results = data.rows.map((columnInfo) => {
|
|
313
|
+
const column = columnInfo.field;
|
|
314
|
+
if (!columnInfo.string_values) {
|
|
315
|
+
return { table, column, values: {} };
|
|
316
|
+
}
|
|
317
|
+
const values = columnInfo.string_values.reduce((result, value) => {
|
|
318
|
+
result[value] = false;
|
|
319
|
+
return result;
|
|
320
|
+
}, {});
|
|
321
|
+
return { table, column, values };
|
|
322
|
+
});
|
|
323
|
+
return results;
|
|
333
324
|
}
|
|
334
325
|
catch (e) {
|
|
335
326
|
console.error(e);
|
|
336
327
|
return null;
|
|
337
328
|
}
|
|
338
329
|
};
|
|
330
|
+
(0, react_1.useEffect)(() => {
|
|
331
|
+
const loadChart = async () => {
|
|
332
|
+
if (!initialData || initialData.referencedTables.length !== 1) {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
const initialRows = await handleAsk(initialData.queryString);
|
|
336
|
+
if (initialData.pivot) {
|
|
337
|
+
// @ts-ignore
|
|
338
|
+
setPivotRowField(initialData.pivot.rowField);
|
|
339
|
+
// @ts-ignore
|
|
340
|
+
setPivotAggregation(initialData.pivot.aggregationType);
|
|
341
|
+
// @ts-ignore
|
|
342
|
+
setPivotColumnField(initialData.pivot.columnField);
|
|
343
|
+
// @ts-ignore
|
|
344
|
+
setPivotValueField(initialData.pivot.valueField);
|
|
345
|
+
setPivot(initialData.pivot);
|
|
346
|
+
const pivotedData = (0, PivotModal_1.generatePivotTable)(
|
|
347
|
+
//@ts-ignore
|
|
348
|
+
initialData.pivot, initialRows, [null, null, null], false);
|
|
349
|
+
setPivotData(pivotedData || []);
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
if (initialData && initialData.referencedTables.length === 1) {
|
|
353
|
+
loadChart();
|
|
354
|
+
}
|
|
355
|
+
}, [initialData]);
|
|
339
356
|
(0, react_1.useEffect)(() => {
|
|
340
357
|
const loadTable = async (tables) => {
|
|
341
358
|
if (!tables)
|
|
342
359
|
return;
|
|
343
360
|
setLoading(true);
|
|
344
|
-
|
|
361
|
+
const tableInfo = schemaTables.find((tableInfo) => tableInfo.name === initialTableName);
|
|
362
|
+
if (tableInfo) {
|
|
363
|
+
const stringColumns = tableInfo.columns.filter((column) => {
|
|
364
|
+
return (0, ast_1.isTextColumnType)(column.fieldType);
|
|
365
|
+
});
|
|
366
|
+
const stringNames = stringColumns.map((column) => column.name);
|
|
367
|
+
const newUniqueValues = await (0, tableProcessing_1.getUniqueValuesByColumns)(stringColumns, `Select ${stringNames.join(', ')} from ${initialTableName}`, [], client);
|
|
368
|
+
const joinedUniqueValues = (0, util_1.deepCopy)(uniqueValues);
|
|
369
|
+
joinedUniqueValues[initialTableName] = newUniqueValues;
|
|
370
|
+
if ((0, crypto_1.hashCode)(uniqueValues) !== (0, crypto_1.hashCode)(joinedUniqueValues)) {
|
|
371
|
+
setUniqueValues(joinedUniqueValues);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
345
374
|
const columnsForTable = tables
|
|
346
375
|
.find((t) => t.name === initialTableName)
|
|
347
376
|
?.columns.map((c) => c.name)
|
|
@@ -402,7 +431,7 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
402
431
|
return -1;
|
|
403
432
|
return 0;
|
|
404
433
|
})));
|
|
405
|
-
if (initialTableName && initialLoad) {
|
|
434
|
+
if (initialTableName && initialLoad && !initialChartId) {
|
|
406
435
|
await loadTable(tables);
|
|
407
436
|
}
|
|
408
437
|
setLoadingSchema(false);
|
|
@@ -415,7 +444,7 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
415
444
|
if (schemaTables.length === 0) {
|
|
416
445
|
fetchSchema();
|
|
417
446
|
}
|
|
418
|
-
}, [schemaTables, initialTableName]);
|
|
447
|
+
}, [schemaTables, initialTableName, initialLoad]);
|
|
419
448
|
const updateFormData = (updates, { isDeletion = false, isInsertion = false, isReplaceSubtree = false, isAddVariant = false, isDeleteVariant = false, topLevelBinOp = 'OR', isCondition = undefined, }) => {
|
|
420
449
|
// Function to immutably update or delete nodes based on their path
|
|
421
450
|
// TODO: fix the following horible code
|
|
@@ -845,6 +874,11 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
845
874
|
newSubtree.left.column = event.target.value;
|
|
846
875
|
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
847
876
|
}
|
|
877
|
+
else if ((0, ast_1.isBoolColumnType)(columnType)) {
|
|
878
|
+
const newSubtree = (0, util_1.deepCopy)(constants_1.defaultBoolComparison);
|
|
879
|
+
newSubtree.left.column = event.target.value;
|
|
880
|
+
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
881
|
+
}
|
|
848
882
|
else {
|
|
849
883
|
const newSubtree = (0, util_1.deepCopy)(constants_1.defaultEntry);
|
|
850
884
|
newSubtree.left.args.value[0].column = event.target.value;
|
|
@@ -904,7 +938,8 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
904
938
|
},
|
|
905
939
|
]));
|
|
906
940
|
} })), (0, jsx_runtime_1.jsx)(SelectComponent, { value: intervalType, onChange: (event) => {
|
|
907
|
-
if (intervalPaths.length === 1
|
|
941
|
+
if (intervalPaths.length === 1 &&
|
|
942
|
+
dateFilterType !== 'in the previous') {
|
|
908
943
|
handleChangeText([
|
|
909
944
|
{
|
|
910
945
|
value: intervalCount !== null
|
|
@@ -916,7 +951,14 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
916
951
|
return;
|
|
917
952
|
}
|
|
918
953
|
let newSubtree;
|
|
919
|
-
if (dateFilterType === '
|
|
954
|
+
if (dateFilterType === 'in the previous') {
|
|
955
|
+
newSubtree = (0, postgres_1.generatePreviousPeriodPostgres)({
|
|
956
|
+
dateField: dateColumn,
|
|
957
|
+
intervalPeriod: `${intervalCount ?? 1} ${event.target.value}`,
|
|
958
|
+
currentPeriod: event.target.value,
|
|
959
|
+
});
|
|
960
|
+
}
|
|
961
|
+
else if (dateFilterType === 'equals') {
|
|
920
962
|
newSubtree = (0, postgres_1.generateEqualsPostgres)({
|
|
921
963
|
dateField: dateColumn,
|
|
922
964
|
currentPeriod: event.target.value,
|
|
@@ -930,14 +972,23 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
930
972
|
});
|
|
931
973
|
}
|
|
932
974
|
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
933
|
-
}, options:
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
975
|
+
}, options: dateFilterType === 'in the previous' ||
|
|
976
|
+
dateFilterType === 'in the last'
|
|
977
|
+
? [
|
|
978
|
+
{ label: `year${isPlural}`, value: 'year' },
|
|
979
|
+
{ label: `month${isPlural}`, value: 'month' },
|
|
980
|
+
{ label: `week${isPlural}`, value: 'week' },
|
|
981
|
+
{ label: `day${isPlural}`, value: 'day' },
|
|
982
|
+
{ label: `hour${isPlural}`, value: 'hour' },
|
|
983
|
+
]
|
|
984
|
+
: [
|
|
985
|
+
{ label: `year${isPlural}`, value: 'year' },
|
|
986
|
+
{ label: `quarter${isPlural}`, value: 'quarter' },
|
|
987
|
+
{ label: `month${isPlural}`, value: 'month' },
|
|
988
|
+
{ label: `week${isPlural}`, value: 'week' },
|
|
989
|
+
{ label: `day${isPlural}`, value: 'day' },
|
|
990
|
+
{ label: `hour${isPlural}`, value: 'hour' },
|
|
991
|
+
], width: 200 }), dateFilterType === 'equals' && ((0, jsx_runtime_1.jsx)(TextInputComponent, { id: "date_filter_equals_raw_date", value: rawDateStringEquals, width: 120, onChange: (e) => {
|
|
941
992
|
handleChangeText([
|
|
942
993
|
{
|
|
943
994
|
value: e.target.value,
|
|
@@ -969,6 +1020,11 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
969
1020
|
newSubtree.left.column = event.target.value;
|
|
970
1021
|
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
971
1022
|
}
|
|
1023
|
+
else if ((0, ast_1.isBoolColumnType)(columnType)) {
|
|
1024
|
+
const newSubtree = (0, util_1.deepCopy)(constants_1.defaultBoolComparison);
|
|
1025
|
+
newSubtree.left.column = event.target.value;
|
|
1026
|
+
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
1027
|
+
}
|
|
972
1028
|
else {
|
|
973
1029
|
const newSubtree = (0, util_1.deepCopy)(constants_1.defaultEntry);
|
|
974
1030
|
newSubtree.left.args.value[0].column = event.target.value;
|
|
@@ -983,7 +1039,6 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
983
1039
|
{ label: 'equals', value: 'EQUALS' },
|
|
984
1040
|
{ label: 'is not null', value: 'IS NOT' },
|
|
985
1041
|
{ label: 'is null', value: 'IS' },
|
|
986
|
-
// { label: 'equals', value: 'equals' },
|
|
987
1042
|
], width: 200 }), (0, jsx_runtime_1.jsx)(TextInputComponent, { id: 'date_window_interval_count', value: node.right.args.value[1].expr.value, width: 120, onChange: (e) => {
|
|
988
1043
|
handleChange([
|
|
989
1044
|
{
|
|
@@ -1025,6 +1080,11 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
1025
1080
|
newSubtree.left.column = event.target.value;
|
|
1026
1081
|
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
1027
1082
|
}
|
|
1083
|
+
else if ((0, ast_1.isBoolColumnType)(columnType)) {
|
|
1084
|
+
const newSubtree = (0, util_1.deepCopy)(constants_1.defaultBoolComparison);
|
|
1085
|
+
newSubtree.left.column = event.target.value;
|
|
1086
|
+
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
1087
|
+
}
|
|
1028
1088
|
else {
|
|
1029
1089
|
const newSubtree = (0, util_1.deepCopy)(constants_1.defaultEntry);
|
|
1030
1090
|
newSubtree.left.args.value[0].column = event.target.value;
|
|
@@ -1079,6 +1139,11 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
1079
1139
|
newSubtree.left.column = event.target.value;
|
|
1080
1140
|
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
1081
1141
|
}
|
|
1142
|
+
else if ((0, ast_1.isBoolColumnType)(columnType)) {
|
|
1143
|
+
const newSubtree = (0, util_1.deepCopy)(constants_1.defaultBoolComparison);
|
|
1144
|
+
newSubtree.left.column = event.target.value;
|
|
1145
|
+
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
1146
|
+
}
|
|
1082
1147
|
else {
|
|
1083
1148
|
const newSubtree = (0, util_1.deepCopy)(constants_1.defaultEntry);
|
|
1084
1149
|
newSubtree.left.args.value[0].column = event.target.value;
|
|
@@ -1143,6 +1208,11 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
1143
1208
|
newSubtree.left.column = event.target.value;
|
|
1144
1209
|
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
1145
1210
|
}
|
|
1211
|
+
else if ((0, ast_1.isBoolColumnType)(columnType)) {
|
|
1212
|
+
const newSubtree = (0, util_1.deepCopy)(constants_1.defaultBoolComparison);
|
|
1213
|
+
newSubtree.left.column = event.target.value;
|
|
1214
|
+
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
1215
|
+
}
|
|
1146
1216
|
else {
|
|
1147
1217
|
const newSubtree = (0, util_1.deepCopy)(constants_1.defaultEntry);
|
|
1148
1218
|
newSubtree.left.args.value[0].column = event.target.value;
|
|
@@ -1227,8 +1297,6 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
1227
1297
|
},
|
|
1228
1298
|
{ label: 'in the current', value: 'IN_THE_CURRENT' },
|
|
1229
1299
|
{ label: 'equals', value: 'equals' },
|
|
1230
|
-
{ label: 'is not null', value: 'IS NOT' },
|
|
1231
|
-
{ label: 'is null', value: 'IS' },
|
|
1232
1300
|
]
|
|
1233
1301
|
: []),
|
|
1234
1302
|
];
|
|
@@ -1255,6 +1323,11 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
1255
1323
|
newSubtree.left.column = event.target.value;
|
|
1256
1324
|
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
1257
1325
|
}
|
|
1326
|
+
else if ((0, ast_1.isBoolColumnType)(columnType)) {
|
|
1327
|
+
const newSubtree = (0, util_1.deepCopy)(constants_1.defaultBoolComparison);
|
|
1328
|
+
newSubtree.left.column = event.target.value;
|
|
1329
|
+
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
1330
|
+
}
|
|
1258
1331
|
else {
|
|
1259
1332
|
const newSubtree = (0, util_1.deepCopy)(constants_1.defaultEntry);
|
|
1260
1333
|
newSubtree.left.args.value[0].column = event.target.value;
|
|
@@ -1377,6 +1450,22 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
1377
1450
|
},
|
|
1378
1451
|
]);
|
|
1379
1452
|
} }));
|
|
1453
|
+
case 'bool':
|
|
1454
|
+
return ((0, jsx_runtime_1.jsx)(SelectComponent, { value: node.value.toString(), onChange: (event) => {
|
|
1455
|
+
let formatted = true;
|
|
1456
|
+
if (event.target.value === 'false') {
|
|
1457
|
+
formatted = false;
|
|
1458
|
+
}
|
|
1459
|
+
handleChange([
|
|
1460
|
+
{
|
|
1461
|
+
value: formatted,
|
|
1462
|
+
path: keyPrefix + 'value',
|
|
1463
|
+
},
|
|
1464
|
+
]);
|
|
1465
|
+
}, options: [
|
|
1466
|
+
{ label: 'is true', value: 'true' },
|
|
1467
|
+
{ label: 'is false', value: 'false' },
|
|
1468
|
+
], width: 200 }));
|
|
1380
1469
|
case 'function':
|
|
1381
1470
|
if (!node.args) {
|
|
1382
1471
|
return (0, jsx_runtime_1.jsx)("label", {});
|
|
@@ -1440,7 +1529,7 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
1440
1529
|
'NOT IN': 'is not',
|
|
1441
1530
|
'NOT LIKE': 'is not exactly',
|
|
1442
1531
|
'!=': 'is not exactly',
|
|
1443
|
-
'=': 'is
|
|
1532
|
+
'=': 'is',
|
|
1444
1533
|
'<': 'is less than',
|
|
1445
1534
|
'>': 'is greater than',
|
|
1446
1535
|
'<=': 'is less than or equal to',
|
|
@@ -1452,7 +1541,7 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
1452
1541
|
};
|
|
1453
1542
|
switch (node.type) {
|
|
1454
1543
|
case 'binary_expr':
|
|
1455
|
-
return ((0, jsx_runtime_1.jsx)(ui_1.TagWrapper, { keyPrefix: keyPrefix, formData: formData, activeEditItem: activeEditItem, setEditPopoverKey: setEditPopoverKey, setActiveEditItem: setActiveEditItem, setCheckboxes: setCheckboxes, handleReplaceSubtree: handleReplaceSubtree, FilterPopover: FilterPopoverComponent, setActivePath: setActivePath, setOpenPopover: setOpenPopover, setIsPending: setIsPending, clearCheckboxes: clearCheckboxes, handleDelete: handleDelete, editPopoverKey: editPopoverKey, isCard: isCard, isRow: isRow, getByKey: getByKey, EditPopover: ui_1.EditPopover, Button: ButtonComponent, renderNode: renderNode, children: dateComparisonPartialMatch ??
|
|
1544
|
+
return ((0, jsx_runtime_1.jsx)(ui_1.TagWrapper, { keyPrefix: keyPrefix, formData: formData, activeEditItem: activeEditItem, setEditPopoverKey: setEditPopoverKey, setActiveEditItem: setActiveEditItem, setCheckboxes: setCheckboxes, handleReplaceSubtree: handleReplaceSubtree, FilterPopover: FilterPopoverComponent, setActivePath: setActivePath, setOpenPopover: setOpenPopover, setIsPending: setIsPending, clearCheckboxes: clearCheckboxes, handleDelete: handleDelete, editPopoverKey: editPopoverKey, isCard: isCard, isRow: isRow, getByKey: getByKey, EditPopover: ui_1.EditPopover, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent, renderNode: renderNode, children: dateComparisonPartialMatch ??
|
|
1456
1545
|
dateEqualityPartialMatch ??
|
|
1457
1546
|
uniqueSentence ?? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [node.left &&
|
|
1458
1547
|
renderSentence(formData, node.left, keyPrefix + 'left.', false, false, isRow), isRow ? (' ' + OPS[node.operator] + ' ') : isTopLevel || topLevelBinaryOperator === 'OR' ? ((0, jsx_runtime_1.jsx)(TopLevelBooleanSwitch, { node: node, keyPrefix: keyPrefix, handleOperatorChange: handleOperatorChange, Select: SelectComponent })) : null, node.right &&
|
|
@@ -1477,6 +1566,8 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
1477
1566
|
return node.value;
|
|
1478
1567
|
case 'null':
|
|
1479
1568
|
return 'null';
|
|
1569
|
+
case 'bool':
|
|
1570
|
+
return node.value.toString();
|
|
1480
1571
|
case 'interval':
|
|
1481
1572
|
if (node.unit) {
|
|
1482
1573
|
// eg. `INTERVAL '90' DAY` -> "90 days"
|
|
@@ -1588,39 +1679,61 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
1588
1679
|
justifyContent: 'end',
|
|
1589
1680
|
}, children: (0, jsx_runtime_1.jsx)(ButtonComponent, { onClick: onSave, label: 'Add condition' }) })] }));
|
|
1590
1681
|
};
|
|
1591
|
-
const fetchUponChange = async (baseAst, newFormData) => {
|
|
1682
|
+
const fetchUponChange = async (baseAst, newFormData, query) => {
|
|
1592
1683
|
// if newFormData is null still use it
|
|
1593
1684
|
const curFormData = newFormData !== undefined ? newFormData : formData;
|
|
1594
1685
|
if ((curFormData || baseAst) && !loading) {
|
|
1595
1686
|
try {
|
|
1596
1687
|
setLoading(true);
|
|
1597
|
-
const
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
'Content-Type': 'application/json',
|
|
1601
|
-
},
|
|
1602
|
-
body: JSON.stringify({
|
|
1688
|
+
const hostedBody = {
|
|
1689
|
+
metadata: {
|
|
1690
|
+
clientId: client.publicKey,
|
|
1603
1691
|
ast: { ...baseAst, where: curFormData },
|
|
1604
1692
|
publicKey: client.publicKey,
|
|
1605
1693
|
orgId: client.customerId,
|
|
1606
|
-
|
|
1607
|
-
|
|
1694
|
+
task: 'patterns',
|
|
1695
|
+
},
|
|
1696
|
+
};
|
|
1697
|
+
const cloudBody = {};
|
|
1698
|
+
const data2 = await (0, dataFetcher_1.getData)(client, 'dashquery', 'same-origin', hostedBody, cloudBody);
|
|
1608
1699
|
const tables = (0, ast_1.getTableNames)(baseAst);
|
|
1609
1700
|
const table = tables.length >= 1 ? tables[0] : initialTableName;
|
|
1610
1701
|
if (table !== currentTable) {
|
|
1611
|
-
|
|
1702
|
+
const tableInfo = schemaTables.find((tableInfo) => tableInfo.name === table);
|
|
1703
|
+
if (tableInfo) {
|
|
1704
|
+
const stringColumns = tableInfo.columns.filter((column) => {
|
|
1705
|
+
return (0, ast_1.isTextColumnType)(column.fieldType);
|
|
1706
|
+
});
|
|
1707
|
+
const stringNames = stringColumns.map((column) => column.name);
|
|
1708
|
+
const newUniqueValues = await (0, tableProcessing_1.getUniqueValuesByColumns)(stringColumns, `Select ${stringNames.join(', ')} from ${table}`, rows, client);
|
|
1709
|
+
const joinedUniqueValues = (0, util_1.deepCopy)(uniqueValues);
|
|
1710
|
+
joinedUniqueValues[table] = newUniqueValues;
|
|
1711
|
+
if ((0, crypto_1.hashCode)(uniqueValues) !== (0, crypto_1.hashCode)(joinedUniqueValues)) {
|
|
1712
|
+
setUniqueValues(joinedUniqueValues);
|
|
1713
|
+
}
|
|
1714
|
+
}
|
|
1612
1715
|
setCurrentTable(table);
|
|
1613
1716
|
}
|
|
1614
|
-
const data2 = await res2.json();
|
|
1615
1717
|
if (data2.rows && data2.rows.length) {
|
|
1616
|
-
const tables = (0, ast_1.getTableNames)(baseAst);
|
|
1617
1718
|
if (pivot) {
|
|
1618
1719
|
// check if any of the pivot fields aren't in the data2.fields array
|
|
1619
1720
|
if (!isValidPivot(data2.fields)) {
|
|
1721
|
+
const processedFields = data2.fields.map((elem) => (0, SQLEditor_1.convertPostgresColumn)(elem));
|
|
1620
1722
|
setPivot(null);
|
|
1621
1723
|
setPivotData(null);
|
|
1622
1724
|
setRows(data2.rows);
|
|
1623
|
-
setFields(
|
|
1725
|
+
setFields(processedFields);
|
|
1726
|
+
setFormattedRows(data2.rows.map((row) => {
|
|
1727
|
+
return processedFields.reduce((formattedRow, column) => {
|
|
1728
|
+
// Apply the format function to each field in the row
|
|
1729
|
+
const formattedValue = (0, valueFormatter_1.quillFormat)({
|
|
1730
|
+
value: row[column.field],
|
|
1731
|
+
format: column.format,
|
|
1732
|
+
});
|
|
1733
|
+
formattedRow[column.field] = formattedValue;
|
|
1734
|
+
return formattedRow;
|
|
1735
|
+
}, {});
|
|
1736
|
+
}));
|
|
1624
1737
|
return;
|
|
1625
1738
|
}
|
|
1626
1739
|
// Do all of this to make sure we have the right unique columns when applying a pivot
|
|
@@ -1632,13 +1745,37 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
1632
1745
|
uniqueFormatted[pivot.columnField] = uniqueRecords;
|
|
1633
1746
|
const pivotedData = (0, PivotModal_1.generatePivotTable)(pivot, data2.rows, [null, null, null], false);
|
|
1634
1747
|
console.info(`%c[Pivot]: ${JSON.stringify(pivot)}`, 'color: dimgray');
|
|
1748
|
+
const processedFields = data2.fields.map((elem) => (0, SQLEditor_1.convertPostgresColumn)(elem));
|
|
1635
1749
|
setPivotData(pivotedData || []);
|
|
1636
1750
|
setRows(data2.rows);
|
|
1637
|
-
setFields(
|
|
1751
|
+
setFields(processedFields);
|
|
1752
|
+
setFormattedRows(data2.rows.map((row) => {
|
|
1753
|
+
return processedFields.reduce((formattedRow, column) => {
|
|
1754
|
+
// Apply the format function to each field in the row
|
|
1755
|
+
const formattedValue = (0, valueFormatter_1.quillFormat)({
|
|
1756
|
+
value: row[column.field],
|
|
1757
|
+
format: column.format,
|
|
1758
|
+
});
|
|
1759
|
+
formattedRow[column.field] = formattedValue;
|
|
1760
|
+
return formattedRow;
|
|
1761
|
+
}, {});
|
|
1762
|
+
}));
|
|
1638
1763
|
}
|
|
1639
1764
|
else {
|
|
1765
|
+
const processedFields = data2.fields.map((elem) => (0, SQLEditor_1.convertPostgresColumn)(elem));
|
|
1640
1766
|
setRows(data2.rows);
|
|
1641
|
-
setFields(
|
|
1767
|
+
setFields(processedFields);
|
|
1768
|
+
setFormattedRows(data2.rows.map((row) => {
|
|
1769
|
+
return processedFields.reduce((formattedRow, column) => {
|
|
1770
|
+
// Apply the format function to each field in the row
|
|
1771
|
+
const formattedValue = (0, valueFormatter_1.quillFormat)({
|
|
1772
|
+
value: row[column.field],
|
|
1773
|
+
format: column.format,
|
|
1774
|
+
});
|
|
1775
|
+
formattedRow[column.field] = formattedValue;
|
|
1776
|
+
return formattedRow;
|
|
1777
|
+
}, {});
|
|
1778
|
+
}));
|
|
1642
1779
|
if (data2.errorMessage) {
|
|
1643
1780
|
setErrorMessage(`Error: ${data2.errorMessage}`);
|
|
1644
1781
|
}
|
|
@@ -1647,6 +1784,7 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
1647
1784
|
else {
|
|
1648
1785
|
setRows([]);
|
|
1649
1786
|
setFields([]);
|
|
1787
|
+
setFormattedRows([]);
|
|
1650
1788
|
setPivotData(null);
|
|
1651
1789
|
}
|
|
1652
1790
|
}
|
|
@@ -1726,6 +1864,14 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
1726
1864
|
return x ?? 0.0;
|
|
1727
1865
|
};
|
|
1728
1866
|
}
|
|
1867
|
+
else if (formatType === 'boolean') {
|
|
1868
|
+
columnFormatters[field.name] = (x) => {
|
|
1869
|
+
if (x) {
|
|
1870
|
+
return 'True';
|
|
1871
|
+
}
|
|
1872
|
+
return 'False';
|
|
1873
|
+
};
|
|
1874
|
+
}
|
|
1729
1875
|
else {
|
|
1730
1876
|
columnFormatters[field.name] = (x) => x;
|
|
1731
1877
|
}
|
|
@@ -1756,39 +1902,14 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
1756
1902
|
}
|
|
1757
1903
|
return false;
|
|
1758
1904
|
};
|
|
1759
|
-
const getDistinctValues = async (table, overrideSchema) => {
|
|
1760
|
-
const schemaInfo = overrideSchema || schemaTables;
|
|
1761
|
-
const tableInfo = schemaInfo.find((tableInfo) => tableInfo.name === table);
|
|
1762
|
-
if (tableInfo) {
|
|
1763
|
-
const pendingFetches = [];
|
|
1764
|
-
for (let column of tableInfo.columns) {
|
|
1765
|
-
if (!(0, ast_1.isTextColumnType)(column.fieldType))
|
|
1766
|
-
continue;
|
|
1767
|
-
const fetchPromise = fetchDistinctHelper(column.name, tableInfo.displayName);
|
|
1768
|
-
pendingFetches.push(fetchPromise);
|
|
1769
|
-
}
|
|
1770
|
-
const newUniqueValues = {};
|
|
1771
|
-
const resolvedPromises = await Promise.all(pendingFetches);
|
|
1772
|
-
for (const resolvedData of resolvedPromises) {
|
|
1773
|
-
if (resolvedData) {
|
|
1774
|
-
const { table, column, values } = resolvedData;
|
|
1775
|
-
if (!newUniqueValues[table]) {
|
|
1776
|
-
newUniqueValues[table] = {};
|
|
1777
|
-
}
|
|
1778
|
-
newUniqueValues[table][column] = values;
|
|
1779
|
-
}
|
|
1780
|
-
}
|
|
1781
|
-
if ((0, crypto_1.hashCode)(uniqueValues) !== (0, crypto_1.hashCode)(newUniqueValues)) {
|
|
1782
|
-
setUniqueValues(newUniqueValues);
|
|
1783
|
-
}
|
|
1784
|
-
}
|
|
1785
|
-
};
|
|
1786
1905
|
const handleAsk = async (overridePrompt = '') => {
|
|
1787
1906
|
if (!aiPrompt && !overridePrompt) {
|
|
1788
1907
|
return;
|
|
1789
1908
|
}
|
|
1790
1909
|
try {
|
|
1910
|
+
let errored = false;
|
|
1791
1911
|
setLoading(true);
|
|
1912
|
+
setErrorMessage('');
|
|
1792
1913
|
let res, data, ast;
|
|
1793
1914
|
let numRetries = 0;
|
|
1794
1915
|
const MAX_RETRIES = 3;
|
|
@@ -1799,7 +1920,7 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
1799
1920
|
if (numRetries === MAX_RETRIES)
|
|
1800
1921
|
break;
|
|
1801
1922
|
if (!activeQuery || (ast && (isTableJoin || isSubquery(ast?.where)))) {
|
|
1802
|
-
res = await fetch(
|
|
1923
|
+
res = await fetch(`${exports.QUILL_SERVER}/magic`, {
|
|
1803
1924
|
method: 'POST',
|
|
1804
1925
|
headers: { 'Content-Type': 'application/json' },
|
|
1805
1926
|
body: JSON.stringify({
|
|
@@ -1809,7 +1930,7 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
1809
1930
|
});
|
|
1810
1931
|
}
|
|
1811
1932
|
else {
|
|
1812
|
-
res = await fetch(
|
|
1933
|
+
res = await fetch(`${exports.QUILL_SERVER}/magic/edit`, {
|
|
1813
1934
|
method: 'POST',
|
|
1814
1935
|
headers: { 'Content-Type': 'application/json' },
|
|
1815
1936
|
body: JSON.stringify({
|
|
@@ -1849,15 +1970,6 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
1849
1970
|
const table = (0, ast_1.getTableNames)(newAst)[0] ?? initialTableName;
|
|
1850
1971
|
const tableAlias = (0, ast_1.getTableAliases)(newAst)[0] ?? initialTableName;
|
|
1851
1972
|
newAst = (0, util_1.removeNonSelectedTableReferences)(newAst, tableAlias ?? table, getAllPossibleColumns().map((col) => col.name));
|
|
1852
|
-
// newAst = convertDateComparison(newAst); // TODO
|
|
1853
|
-
if (table !== currentTable) {
|
|
1854
|
-
await getDistinctValues(table);
|
|
1855
|
-
setCurrentTable(table);
|
|
1856
|
-
}
|
|
1857
|
-
setPivotRowField(groupByPivot?.rowField);
|
|
1858
|
-
setPivotColumnField(groupByPivot?.columnField);
|
|
1859
|
-
setPivotValueField(groupByPivot?.valueField);
|
|
1860
|
-
setPivotAggregation(groupByPivot?.aggregationType);
|
|
1861
1973
|
setSelectedColumns((0, util_1.deepCopy)(newAst).columns?.map((column) => {
|
|
1862
1974
|
if (column.expr.type === 'column_ref') {
|
|
1863
1975
|
return `${table}.${column.expr.column}`;
|
|
@@ -1880,21 +1992,78 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
1880
1992
|
newAst?.where ? newAst?.where?.operator : 'AND');
|
|
1881
1993
|
}
|
|
1882
1994
|
ast = newAst; // so we fetch data for newAst later.
|
|
1883
|
-
const
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
ast: ast,
|
|
1995
|
+
const table = (0, ast_1.getTableNames)(newAst)[0] ?? initialTableName;
|
|
1996
|
+
const tableAlias = (0, ast_1.getTableAliases)(newAst)[0] ?? initialTableName;
|
|
1997
|
+
const hostedBody = {
|
|
1998
|
+
metadata: {
|
|
1999
|
+
clientId: client.publicKey,
|
|
2000
|
+
ast,
|
|
1890
2001
|
publicKey: client.publicKey,
|
|
1891
2002
|
orgId: client.customerId,
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
2003
|
+
task: 'patterns',
|
|
2004
|
+
},
|
|
2005
|
+
};
|
|
2006
|
+
const cloudBody = {};
|
|
2007
|
+
const data2 = await (0, dataFetcher_1.getData)(client, 'patterns', 'same-origin', hostedBody, cloudBody);
|
|
2008
|
+
let currentUniqueValues = uniqueValues;
|
|
2009
|
+
if (table !== currentTable) {
|
|
2010
|
+
const tableInfo = schemaTables.find((tableInfo) => tableInfo.name === table);
|
|
2011
|
+
if (tableInfo) {
|
|
2012
|
+
const stringColumns = tableInfo.columns.filter((column) => {
|
|
2013
|
+
return (0, ast_1.isTextColumnType)(column.fieldType);
|
|
2014
|
+
});
|
|
2015
|
+
const stringNames = stringColumns.map((column) => column.name);
|
|
2016
|
+
const newUniqueValues = await (0, tableProcessing_1.getUniqueValuesByColumns)(stringColumns, `Select ${stringNames.join(', ')} from ${table}`, rows, client);
|
|
2017
|
+
currentUniqueValues[table] = newUniqueValues;
|
|
2018
|
+
if ((0, crypto_1.hashCode)(uniqueValues) !== (0, crypto_1.hashCode)(currentUniqueValues)) {
|
|
2019
|
+
setUniqueValues(currentUniqueValues);
|
|
2020
|
+
}
|
|
2021
|
+
}
|
|
2022
|
+
setCurrentTable(table);
|
|
2023
|
+
}
|
|
1895
2024
|
if (data2.rows && data2.rows.length) {
|
|
1896
|
-
const
|
|
1897
|
-
|
|
2025
|
+
const processedFields = data2.fields.map((elem) => (0, SQLEditor_1.convertPostgresColumn)(elem));
|
|
2026
|
+
let possiblePivot = true;
|
|
2027
|
+
const possibleColumns = (0, pivotProcessing_1.getPossiblePivotFieldOptions)(processedFields, currentUniqueValues[table]);
|
|
2028
|
+
if (groupByPivot &&
|
|
2029
|
+
((groupByPivot.columnField &&
|
|
2030
|
+
!possibleColumns.columnFields.includes(groupByPivot?.columnField)) ||
|
|
2031
|
+
(groupByPivot.rowField &&
|
|
2032
|
+
!possibleColumns.rowFields.includes(groupByPivot?.rowField)) ||
|
|
2033
|
+
(groupByPivot.valueField &&
|
|
2034
|
+
!possibleColumns.valueFields.includes(groupByPivot?.valueField || '')))) {
|
|
2035
|
+
possiblePivot = false;
|
|
2036
|
+
let errorMessageEnding = '';
|
|
2037
|
+
if (groupByPivot.columnField &&
|
|
2038
|
+
!possibleColumns.columnFields.includes(groupByPivot?.columnField || '')) {
|
|
2039
|
+
if (currentUniqueValues[table][groupByPivot?.columnField || '']) {
|
|
2040
|
+
errorMessageEnding = `The column ${groupByPivot?.columnField} has more than 24 unique values to pivot on.`;
|
|
2041
|
+
}
|
|
2042
|
+
else {
|
|
2043
|
+
errorMessageEnding = `The column ${groupByPivot?.columnField} is not a proper column field.`;
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
else if (groupByPivot.rowField &&
|
|
2047
|
+
!possibleColumns.rowFields.includes(groupByPivot?.rowField || '')) {
|
|
2048
|
+
if (currentUniqueValues[table][groupByPivot?.rowField || '']) {
|
|
2049
|
+
errorMessageEnding = `The column ${groupByPivot?.rowField} has more than 36 unique values to pivot on.`;
|
|
2050
|
+
}
|
|
2051
|
+
else {
|
|
2052
|
+
errorMessageEnding = `The column ${groupByPivot?.rowField} is not a proper row field.`;
|
|
2053
|
+
}
|
|
2054
|
+
}
|
|
2055
|
+
else if (groupByPivot.valueField &&
|
|
2056
|
+
!possibleColumns.valueFields.includes(groupByPivot?.valueField || '')) {
|
|
2057
|
+
errorMessageEnding = `The column ${groupByPivot?.valueField} is not a proper value field.`;
|
|
2058
|
+
}
|
|
2059
|
+
setErrorMessage(`The requested pivot is not supported. ${errorMessageEnding}`);
|
|
2060
|
+
errored = true;
|
|
2061
|
+
}
|
|
2062
|
+
if (groupByPivot && possiblePivot) {
|
|
2063
|
+
setPivotRowField(groupByPivot?.rowField);
|
|
2064
|
+
setPivotColumnField(groupByPivot?.columnField);
|
|
2065
|
+
setPivotValueField(groupByPivot?.valueField);
|
|
2066
|
+
setPivotAggregation(groupByPivot?.aggregationType);
|
|
1898
2067
|
const pivotedData = (0, PivotModal_1.generatePivotTable)(
|
|
1899
2068
|
// @ts-ignore
|
|
1900
2069
|
groupByPivot, data2.rows, [null, null, null], false);
|
|
@@ -1902,17 +2071,42 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
1902
2071
|
setPivotData(pivotedData);
|
|
1903
2072
|
setPivot(groupByPivot);
|
|
1904
2073
|
setRows(data2.rows);
|
|
1905
|
-
setFields(
|
|
2074
|
+
setFields(processedFields);
|
|
2075
|
+
setFormattedRows(data2.rows.map((row) => {
|
|
2076
|
+
return processedFields.reduce((formattedRow, column) => {
|
|
2077
|
+
// Apply the format function to each field in the row
|
|
2078
|
+
const formattedValue = (0, valueFormatter_1.quillFormat)({
|
|
2079
|
+
value: row[column.field],
|
|
2080
|
+
format: column.format,
|
|
2081
|
+
});
|
|
2082
|
+
formattedRow[column.field] = formattedValue;
|
|
2083
|
+
return formattedRow;
|
|
2084
|
+
}, {});
|
|
2085
|
+
}));
|
|
1906
2086
|
}
|
|
1907
2087
|
else {
|
|
2088
|
+
const processedFields = data2.fields.map((elem) => (0, SQLEditor_1.convertPostgresColumn)(elem));
|
|
1908
2089
|
setRows(data2.rows);
|
|
1909
|
-
setFields(
|
|
2090
|
+
setFields(processedFields);
|
|
2091
|
+
setFormattedRows(data2.rows.map((row) => {
|
|
2092
|
+
return processedFields.reduce((formattedRow, column) => {
|
|
2093
|
+
// Apply the format function to each field in the row
|
|
2094
|
+
const formattedValue = (0, valueFormatter_1.quillFormat)({
|
|
2095
|
+
value: row[column.field],
|
|
2096
|
+
format: column.format,
|
|
2097
|
+
});
|
|
2098
|
+
formattedRow[column.field] = formattedValue;
|
|
2099
|
+
return formattedRow;
|
|
2100
|
+
}, {});
|
|
2101
|
+
}));
|
|
1910
2102
|
}
|
|
2103
|
+
return data2.rows;
|
|
1911
2104
|
}
|
|
1912
2105
|
else {
|
|
1913
2106
|
setPivotData([]);
|
|
1914
2107
|
setRows([]);
|
|
1915
2108
|
setFields([]);
|
|
2109
|
+
setFormattedRows([]);
|
|
1916
2110
|
}
|
|
1917
2111
|
if (data2.query) {
|
|
1918
2112
|
setActiveQuery(data2.query);
|
|
@@ -1923,9 +2117,6 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
1923
2117
|
if (data2.errorMessage) {
|
|
1924
2118
|
setErrorMessage(`Error: ${data2.errorMessage}`);
|
|
1925
2119
|
}
|
|
1926
|
-
else {
|
|
1927
|
-
setErrorMessage('');
|
|
1928
|
-
}
|
|
1929
2120
|
}
|
|
1930
2121
|
catch (e) {
|
|
1931
2122
|
console.error(e);
|
|
@@ -1934,7 +2125,6 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
1934
2125
|
finally {
|
|
1935
2126
|
setLoading(false);
|
|
1936
2127
|
setDataDisplayed(true);
|
|
1937
|
-
setAiPrompt('');
|
|
1938
2128
|
}
|
|
1939
2129
|
};
|
|
1940
2130
|
const handleDeleteColumn = (name) => {
|
|
@@ -2045,273 +2235,295 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
2045
2235
|
flexDirection: 'row',
|
|
2046
2236
|
height: '100%',
|
|
2047
2237
|
...containerStyle,
|
|
2048
|
-
}, className: className, ref: parentRef, children: [(0, jsx_runtime_1.jsxs)(SidebarComponent, { children: [(0, jsx_runtime_1.
|
|
2049
|
-
|
|
2050
|
-
return;
|
|
2051
|
-
if (!openPopover) {
|
|
2052
|
-
setOpenPopover('AddColumnPopover');
|
|
2053
|
-
}
|
|
2054
|
-
}, label: 'Select columns' }), (0, jsx_runtime_1.jsx)(PopoverComponent, { isOpen: openPopover === 'AddColumnPopover', setIsOpen: (isOpen) => {
|
|
2055
|
-
if (!isOpen) {
|
|
2056
|
-
setIsPending(false);
|
|
2057
|
-
setActiveEditItem(null);
|
|
2058
|
-
setActivePath(null);
|
|
2059
|
-
setOpenPopover(null);
|
|
2060
|
-
}
|
|
2061
|
-
}, popoverTitle: "Select columns", popoverChildren: (0, jsx_runtime_1.jsx)(AddColumnPopover_1.default, { onSave: () => {
|
|
2062
|
-
setActiveEditItem(null);
|
|
2063
|
-
setActivePath(null);
|
|
2064
|
-
setOpenPopover(null);
|
|
2065
|
-
}, orderedColumnNames: orderedColumnNames, setOrderedColumnNames: setOrderedColumnNames, selectedColumns: selectedColumns, setSelectedColumns: setSelectedColumns, isSelectedAllColumns: isSelectedAllColumns, clearAllState: clearAllState, nameToColumn: nameToColumn, baseAst: baseAst, setBaseAst: (newAst) => {
|
|
2066
|
-
setBaseAst(newAst);
|
|
2067
|
-
fetchSqlQuery(newAst);
|
|
2068
|
-
}, pivot: pivot, initialTableName: initialTableName, defaultAST: constants_1.defaultAST, defaultTable: constants_1.defaultTable, setPivot: setPivot, TextInput: TextInputComponent, SelectColumn: SelectColumnComponent, SecondaryButton: SecondaryButtonComponent, Button: ButtonComponent }) }), (0, jsx_runtime_1.jsx)("div", { style: { height: 28, width: '100%' } }), (0, jsx_runtime_1.jsx)(SidebarHeadingComponent, { label: "Filters" }), (0, jsx_runtime_1.jsx)("div", { style: { height: 4, width: '100%' } }), formData && ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
2069
|
-
display: 'flex',
|
|
2070
|
-
flexDirection: 'column',
|
|
2071
|
-
gap: 8,
|
|
2072
|
-
marginBottom: 12,
|
|
2073
|
-
}, children: renderSentence(formData, formData, '', true) })), (0, jsx_runtime_1.jsxs)("div", { style: {
|
|
2074
|
-
display: 'flex',
|
|
2075
|
-
flexDirection: 'column',
|
|
2076
|
-
gap: 2.5,
|
|
2077
|
-
alignItems: 'flex-start',
|
|
2078
|
-
}, children: [(0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: () => {
|
|
2079
|
-
if (!selectedColumns ||
|
|
2080
|
-
selectedColumns.length === 0 ||
|
|
2081
|
-
loading) {
|
|
2238
|
+
}, className: className, ref: parentRef, children: [(0, jsx_runtime_1.jsxs)(SidebarComponent, { children: [(0, jsx_runtime_1.jsxs)("div", { style: { width: '100%' }, children: [(0, jsx_runtime_1.jsx)(SidebarHeadingComponent, { label: "Columns" }), (0, jsx_runtime_1.jsx)(DraggableColumns, {}), (0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: () => {
|
|
2239
|
+
if (loadingSchema)
|
|
2082
2240
|
return;
|
|
2083
|
-
}
|
|
2084
2241
|
if (!openPopover) {
|
|
2085
|
-
|
|
2086
|
-
const [_table, column] = value.split('.');
|
|
2087
|
-
const columnType = getColumnTypeByName(column);
|
|
2088
|
-
if ((0, ast_1.isNumericColumnType)(columnType)) {
|
|
2089
|
-
const newSubtree = (0, util_1.deepCopy)(constants_1.defaultNumericComparison);
|
|
2090
|
-
newSubtree.left.column = column;
|
|
2091
|
-
setActiveEditItem(newSubtree);
|
|
2092
|
-
}
|
|
2093
|
-
else {
|
|
2094
|
-
const newSubtree = (0, util_1.deepCopy)(constants_1.defaultEntry);
|
|
2095
|
-
newSubtree.left.args.value[0].column = column;
|
|
2096
|
-
setActiveEditItem(newSubtree);
|
|
2097
|
-
}
|
|
2098
|
-
setOpenPopover('AddFilterPopover');
|
|
2099
|
-
setActivePath('');
|
|
2100
|
-
setIsPending(true);
|
|
2242
|
+
setOpenPopover('AddColumnModal');
|
|
2101
2243
|
}
|
|
2102
|
-
}, label: '
|
|
2244
|
+
}, label: 'Select columns' }), (0, jsx_runtime_1.jsx)(PopoverComponent, { isOpen: openPopover === 'AddColumnModal', setIsOpen: (isOpen) => {
|
|
2103
2245
|
if (!isOpen) {
|
|
2104
2246
|
setIsPending(false);
|
|
2247
|
+
setActiveEditItem(null);
|
|
2105
2248
|
setActivePath(null);
|
|
2106
2249
|
setOpenPopover(null);
|
|
2107
|
-
clearCheckboxes();
|
|
2108
|
-
setTimeout(() => {
|
|
2109
|
-
setActiveEditItem(null);
|
|
2110
|
-
}, 300);
|
|
2111
2250
|
}
|
|
2112
|
-
}, popoverTitle:
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
(0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: () => {
|
|
2251
|
+
}, popoverTitle: "Select columns", popoverChildren: (0, jsx_runtime_1.jsx)(AddColumnModal_1.default, { onSave: () => {
|
|
2252
|
+
setActiveEditItem(null);
|
|
2253
|
+
setActivePath(null);
|
|
2254
|
+
setOpenPopover(null);
|
|
2255
|
+
}, orderedColumnNames: orderedColumnNames, setOrderedColumnNames: setOrderedColumnNames, selectedColumns: selectedColumns, setSelectedColumns: setSelectedColumns, isSelectedAllColumns: isSelectedAllColumns, clearAllState: clearAllState, nameToColumn: nameToColumn, baseAst: baseAst, setBaseAst: (newAst) => {
|
|
2256
|
+
setBaseAst(newAst);
|
|
2257
|
+
fetchSqlQuery(newAst);
|
|
2258
|
+
}, pivot: pivot, initialTableName: initialTableName, defaultAST: constants_1.defaultAST, defaultTable: constants_1.defaultTable, setPivot: setPivot, TextInput: TextInputComponent, SelectColumn: SelectColumnComponent, SecondaryButton: SecondaryButtonComponent, Button: ButtonComponent, ColumnSearchEmptyState: ColumnSearchEmptyState }) })] }), (0, jsx_runtime_1.jsxs)("div", { style: { width: '100%' }, children: [(0, jsx_runtime_1.jsx)(SidebarHeadingComponent, { label: "Filters" }), formData && ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
2259
|
+
display: 'flex',
|
|
2260
|
+
flexDirection: 'column',
|
|
2261
|
+
gap: 8,
|
|
2262
|
+
marginBottom: 12,
|
|
2263
|
+
}, children: renderSentence(formData, formData, '', true) })), (0, jsx_runtime_1.jsxs)("div", { style: {
|
|
2264
|
+
display: 'flex',
|
|
2265
|
+
flexDirection: 'column',
|
|
2266
|
+
alignItems: 'flex-start',
|
|
2267
|
+
}, children: [(0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: () => {
|
|
2268
|
+
if (!selectedColumns ||
|
|
2269
|
+
selectedColumns.length === 0 ||
|
|
2270
|
+
loading) {
|
|
2271
|
+
return;
|
|
2272
|
+
}
|
|
2135
2273
|
if (!openPopover) {
|
|
2136
|
-
|
|
2137
|
-
|
|
2274
|
+
const value = orderedColumnNames[0];
|
|
2275
|
+
const [_table, column] = value.split('.');
|
|
2276
|
+
const columnType = getColumnTypeByName(column);
|
|
2277
|
+
if ((0, ast_1.isNumericColumnType)(columnType)) {
|
|
2278
|
+
const newSubtree = (0, util_1.deepCopy)(constants_1.defaultNumericComparison);
|
|
2279
|
+
newSubtree.left.column = column;
|
|
2280
|
+
setActiveEditItem(newSubtree);
|
|
2281
|
+
}
|
|
2282
|
+
else {
|
|
2283
|
+
const newSubtree = (0, util_1.deepCopy)(constants_1.defaultEntry);
|
|
2284
|
+
newSubtree.left.args.value[0].column = column;
|
|
2285
|
+
setActiveEditItem(newSubtree);
|
|
2286
|
+
}
|
|
2287
|
+
setOpenPopover('AddFilterPopover');
|
|
2138
2288
|
setActivePath('');
|
|
2139
2289
|
setIsPending(true);
|
|
2140
2290
|
}
|
|
2141
|
-
}, label:
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
}, 300);
|
|
2147
|
-
setActivePath(null);
|
|
2148
|
-
setOpenPopover(null);
|
|
2149
|
-
clearCheckboxes();
|
|
2150
|
-
}
|
|
2151
|
-
}, popoverTitle: "Add condition", popoverChildren: (0, jsx_runtime_1.jsx)(AddConditionPopover, { onSave: () => {
|
|
2152
|
-
if ((0, util_1.isNodeEmptyCollection)(activeEditItem)) {
|
|
2291
|
+
}, label: 'Add filter' }), (0, jsx_runtime_1.jsx)("div", { style: {
|
|
2292
|
+
position: 'relative',
|
|
2293
|
+
...(openPopover === 'AddFilterPopover' && { top: 12 }),
|
|
2294
|
+
}, children: (0, jsx_runtime_1.jsx)(PopoverComponent, { isOpen: openPopover === 'AddFilterPopover', setIsOpen: (isOpen) => {
|
|
2295
|
+
if (!isOpen) {
|
|
2153
2296
|
setIsPending(false);
|
|
2154
|
-
setTimeout(() => {
|
|
2155
|
-
setActiveEditItem(null);
|
|
2156
|
-
}, 300);
|
|
2157
2297
|
setActivePath(null);
|
|
2158
2298
|
setOpenPopover(null);
|
|
2159
|
-
clearCheckboxes();
|
|
2160
|
-
}
|
|
2161
|
-
else {
|
|
2162
|
-
setIsPending(false);
|
|
2163
|
-
handleInsertion(activeEditItem, topLevelBinaryOperator, true);
|
|
2164
2299
|
setTimeout(() => {
|
|
2300
|
+
clearCheckboxes();
|
|
2165
2301
|
setActiveEditItem(null);
|
|
2166
2302
|
}, 300);
|
|
2167
|
-
setActivePath(null);
|
|
2168
|
-
setOpenPopover(null);
|
|
2169
|
-
clearCheckboxes();
|
|
2170
2303
|
}
|
|
2171
|
-
}
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
}
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2304
|
+
}, popoverTitle: 'Add filter', popoverChildren: (0, jsx_runtime_1.jsx)(ui_1.AddFilterPopover, { onSave: () => {
|
|
2305
|
+
if ((0, util_1.isNodeEmptyCollection)(activeEditItem)) {
|
|
2306
|
+
setIsPending(false);
|
|
2307
|
+
setActivePath(null);
|
|
2308
|
+
setOpenPopover(null);
|
|
2309
|
+
setTimeout(() => {
|
|
2310
|
+
clearCheckboxes();
|
|
2311
|
+
setActiveEditItem(null);
|
|
2312
|
+
}, 300);
|
|
2313
|
+
}
|
|
2314
|
+
else {
|
|
2315
|
+
setIsPending(false);
|
|
2316
|
+
handleInsertion(activeEditItem, 'AND', false);
|
|
2317
|
+
setActivePath(null);
|
|
2318
|
+
setOpenPopover(null);
|
|
2319
|
+
setTimeout(() => {
|
|
2320
|
+
clearCheckboxes();
|
|
2321
|
+
setActiveEditItem(null);
|
|
2322
|
+
}, 300);
|
|
2323
|
+
}
|
|
2324
|
+
}, Button: ButtonComponent, renderNode: renderNode, activeEditItem: activeEditItem }) }) }), baseAst?.where &&
|
|
2325
|
+
false && ( // temp removed the AddConditionPopover
|
|
2326
|
+
(0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: () => {
|
|
2327
|
+
if (!openPopover) {
|
|
2328
|
+
setActiveEditItem((0, util_1.deepCopy)(constants_1.defaultEntry));
|
|
2329
|
+
setOpenPopover('AddConditionPopover');
|
|
2330
|
+
setActivePath('');
|
|
2331
|
+
setIsPending(true);
|
|
2332
|
+
}
|
|
2333
|
+
}, label: "Add condition" }), (0, jsx_runtime_1.jsx)(PopoverComponent, { isOpen: openPopover === 'AddConditionPopover', setIsOpen: (isOpen) => {
|
|
2334
|
+
if (!isOpen) {
|
|
2335
|
+
setIsPending(false);
|
|
2336
|
+
setTimeout(() => {
|
|
2337
|
+
clearCheckboxes();
|
|
2338
|
+
setActiveEditItem(null);
|
|
2339
|
+
}, 300);
|
|
2340
|
+
setActivePath(null);
|
|
2341
|
+
setOpenPopover(null);
|
|
2342
|
+
}
|
|
2343
|
+
}, popoverTitle: "Add condition", popoverChildren: (0, jsx_runtime_1.jsx)(AddConditionPopover, { onSave: () => {
|
|
2344
|
+
if ((0, util_1.isNodeEmptyCollection)(activeEditItem)) {
|
|
2345
|
+
setIsPending(false);
|
|
2346
|
+
setTimeout(() => {
|
|
2347
|
+
setActiveEditItem(null);
|
|
2348
|
+
clearCheckboxes();
|
|
2349
|
+
}, 300);
|
|
2350
|
+
setActivePath(null);
|
|
2351
|
+
setOpenPopover(null);
|
|
2352
|
+
}
|
|
2353
|
+
else {
|
|
2354
|
+
setIsPending(false);
|
|
2355
|
+
handleInsertion(activeEditItem, topLevelBinaryOperator, true);
|
|
2356
|
+
setTimeout(() => {
|
|
2357
|
+
setActiveEditItem(null);
|
|
2358
|
+
clearCheckboxes();
|
|
2359
|
+
}, 300);
|
|
2360
|
+
setActivePath(null);
|
|
2361
|
+
setOpenPopover(null);
|
|
2362
|
+
}
|
|
2363
|
+
} }) })] }))] })] }), (0, jsx_runtime_1.jsxs)("div", { style: { width: '100%' }, children: [(0, jsx_runtime_1.jsx)(SidebarHeadingComponent, { label: "Pivot" }), (0, jsx_runtime_1.jsx)(PivotModal_1.PivotModal, { pivotRowField: pivotRowField, setPivotRowField: setPivotRowField, pivotColumnField: pivotColumnField, setPivotColumnField: setPivotColumnField, pivotValueField: pivotValueField, setPivotValueField: setPivotValueField, pivotAggregation: pivotAggregation, setPivotAggregation: setPivotAggregation, createdPivots: createdPivots, setCreatedPivots: setCreatedPivots, recommendedPivots: recommendedPivots, setRecommendedPivots: setRecommendedPivots, popUpTitle: pivotPopUpTitle, setPopUpTitle: setPivotPopUpTitle, selectedTable: initialTableName, 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: fields, triggerButtonText: 'Add pivot', selectedPivotIndex: selectedPivotIndex, setSelectedPivotIndex: setSelectedPivotIndex, removePivot: () => {
|
|
2364
|
+
setPivot(null);
|
|
2365
|
+
setPivotData(null);
|
|
2366
|
+
},
|
|
2367
|
+
// TODOs
|
|
2368
|
+
selectPivot: (pivot) => {
|
|
2369
|
+
if (!pivot)
|
|
2370
|
+
return;
|
|
2371
|
+
const newAst = { ...baseAst };
|
|
2372
|
+
newAst.orderby = null;
|
|
2373
|
+
setBaseAst(newAst); // trigger refetch
|
|
2374
|
+
setPivot(pivot);
|
|
2375
|
+
const pivotedData = (0, PivotModal_1.generatePivotTable)(pivot, rows, [null, null, null], false);
|
|
2376
|
+
setPivotData(pivotedData || []);
|
|
2377
|
+
}, selectPivotOnEdit: true, showTrigger: !pivot, theme: theme, LabelComponent: LabelComponent, HeaderComponent: HeaderComponent, dateRange: [null, null, null], pivotCountRequest: 4, SecondaryButtonComponent: SecondaryButtonComponent, query: activeQuery, initialUniqueValues: uniqueValues[currentTable], disabled: !loading && (!baseAst || !dataDisplayed), pivotRecommendationsEnabled: pivotRecommendationsEnabled && overrideRecommendations }), pivot && ((0, jsx_runtime_1.jsx)(PivotList_1.PivotCard, { pivotTable: {
|
|
2378
|
+
pivot: pivot,
|
|
2379
|
+
rows: pivotData?.rows || [],
|
|
2380
|
+
columns: pivotData?.columns || [],
|
|
2381
|
+
}, theme: theme, index: 0, onSelectPivot: () => {
|
|
2382
|
+
setIsEdittingPivot(true);
|
|
2383
|
+
setShowPivotPopover(true);
|
|
2384
|
+
setPivotRowField(pivot?.rowField);
|
|
2385
|
+
setPivotColumnField(pivot?.columnField);
|
|
2386
|
+
setPivotValueField(pivot?.valueField);
|
|
2387
|
+
setPivotAggregation(pivot?.aggregationType);
|
|
2388
|
+
setPivotPopUpTitle('Edit pivot');
|
|
2389
|
+
}, selectedPivotIndex: -1, onEditPivot: () => { }, CardComponent: CardComponent, ButtonComponent: ButtonComponent, HeaderComponent: HeaderComponent, showEdit: false, onClose: () => {
|
|
2390
|
+
setPivot(null);
|
|
2391
|
+
setPivotData(null);
|
|
2392
|
+
setBaseAst((0, util_1.deepCopy)(baseAst)); // trigger refetch
|
|
2393
|
+
}, minHeight: 180, LabelComponent: LabelComponent, TextComponent: TextComponent }))] }), (0, jsx_runtime_1.jsxs)("div", { style: { width: '100%' }, children: [(0, jsx_runtime_1.jsx)(SidebarHeadingComponent, { label: "Sort" }), pivot && pivot.sort && ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
2394
|
+
display: 'flex',
|
|
2395
|
+
flexDirection: 'column',
|
|
2396
|
+
gap: 8,
|
|
2397
|
+
marginBottom: 12,
|
|
2398
|
+
}, children: (0, jsx_runtime_1.jsx)(AddSortPopover_1.SortSentence, { sortData: {
|
|
2399
|
+
type: pivot.sortDirection,
|
|
2400
|
+
expr: { type: 'column_ref', column: pivot.sortField },
|
|
2401
|
+
}, columns: selectedColumns, setIsPending: setIsPending, setEditPopoverKey: setEditPopoverKey, setActiveEditItem: setActiveEditItem, setActivePath: setActivePath, setOpenPopover: setOpenPopover, SortPopover: SortPopoverComponent, EditPopover: AddSortPopover_1.AddSortPopover, handleDelete: () => {
|
|
2402
|
+
setPivot({ ...pivot, sort: false });
|
|
2403
|
+
setBaseAst((0, util_1.deepCopy)(baseAst));
|
|
2404
|
+
if (!pivot) {
|
|
2405
|
+
fetchSqlQuery(baseAst);
|
|
2406
|
+
}
|
|
2407
|
+
}, onSave: (column, direction) => {
|
|
2408
|
+
const sortFieldType = column === (pivot.valueField || 'count')
|
|
2409
|
+
? 'number'
|
|
2410
|
+
: pivot.rowFieldType;
|
|
2411
|
+
setPivot({
|
|
2412
|
+
...pivot,
|
|
2413
|
+
sort: true,
|
|
2414
|
+
sortDirection: direction,
|
|
2415
|
+
sortField: column,
|
|
2416
|
+
sortFieldType: sortFieldType,
|
|
2417
|
+
});
|
|
2418
|
+
setOpenPopover(null);
|
|
2419
|
+
setBaseAst((0, util_1.deepCopy)(baseAst));
|
|
2420
|
+
if (!pivot) {
|
|
2421
|
+
fetchSqlQuery(baseAst);
|
|
2422
|
+
}
|
|
2423
|
+
}, Select: SelectComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent }, `sort-sentence-pivot`) })), baseAst && baseAst.orderby && ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
2424
|
+
display: 'flex',
|
|
2425
|
+
flexDirection: 'column',
|
|
2426
|
+
gap: 8,
|
|
2427
|
+
marginBottom: 12,
|
|
2428
|
+
}, children: baseAst.orderby.map((sortData, id) => ((0, jsx_runtime_1.jsx)(AddSortPopover_1.SortSentence, { sortData: sortData, columns: selectedColumns, onSave: (column, direction) => {
|
|
2429
|
+
setIsPending(false);
|
|
2430
|
+
setActiveEditItem(null);
|
|
2431
|
+
setOpenPopover(null);
|
|
2432
|
+
if (column === '')
|
|
2433
|
+
return;
|
|
2434
|
+
const newAst = { ...baseAst };
|
|
2435
|
+
newAst.orderby[id] = {
|
|
2436
|
+
expr: {
|
|
2437
|
+
type: 'column_ref',
|
|
2438
|
+
table: null,
|
|
2439
|
+
column: column,
|
|
2440
|
+
},
|
|
2441
|
+
type: direction,
|
|
2442
|
+
};
|
|
2443
|
+
// look through the columns
|
|
2444
|
+
setActivePath(null);
|
|
2445
|
+
setOpenPopover(null);
|
|
2446
|
+
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2447
|
+
if (!pivot) {
|
|
2448
|
+
fetchSqlQuery(newAst);
|
|
2449
|
+
}
|
|
2450
|
+
}, setIsPending: setIsPending, setEditPopoverKey: setEditPopoverKey, setActiveEditItem: setActiveEditItem, setActivePath: setActivePath, setOpenPopover: setOpenPopover, SortPopover: SortPopoverComponent, EditPopover: AddSortPopover_1.AddSortPopover, handleDelete: () => {
|
|
2451
|
+
const newAst = { ...baseAst };
|
|
2452
|
+
newAst.orderby.splice(id, 1);
|
|
2453
|
+
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2454
|
+
if (!pivot) {
|
|
2455
|
+
fetchSqlQuery(newAst);
|
|
2456
|
+
}
|
|
2457
|
+
}, Select: SelectComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent }, `sort-sentence-${id}`))) })), (0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: () => {
|
|
2458
|
+
if (!selectedColumns ||
|
|
2459
|
+
selectedColumns.length === 0 ||
|
|
2460
|
+
loading) {
|
|
2461
|
+
return;
|
|
2462
|
+
}
|
|
2295
2463
|
if (!openPopover) {
|
|
2296
|
-
setOpenPopover('
|
|
2464
|
+
setOpenPopover('AddSortPopover');
|
|
2297
2465
|
}
|
|
2298
|
-
}, label:
|
|
2466
|
+
}, label: "Add sort" }), (0, jsx_runtime_1.jsx)(PopoverComponent, { isOpen: openPopover === 'AddSortPopover', setIsOpen: (isOpen) => {
|
|
2299
2467
|
if (!isOpen) {
|
|
2300
2468
|
setIsPending(false);
|
|
2301
2469
|
setActiveEditItem(null);
|
|
2302
2470
|
setActivePath(null);
|
|
2303
2471
|
setOpenPopover(null);
|
|
2304
2472
|
}
|
|
2305
|
-
}, popoverTitle: "
|
|
2473
|
+
}, popoverTitle: "Sort by", popoverChildren: (0, jsx_runtime_1.jsx)(AddSortPopover_1.AddSortPopover, { columns: selectedColumns, Select: SelectComponent, Button: ButtonComponent, onSave: () => { } }) })] }), (0, jsx_runtime_1.jsxs)("div", { style: { width: '100%' }, children: [(0, jsx_runtime_1.jsx)(SidebarHeadingComponent, { label: "Limit" }), baseAst && baseAst.limit ? ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
2474
|
+
display: 'flex',
|
|
2475
|
+
flexDirection: 'column',
|
|
2476
|
+
gap: 8,
|
|
2477
|
+
marginBottom: 12,
|
|
2478
|
+
}, children: (0, jsx_runtime_1.jsx)(AddLimitPopover_1.LimitSentence, { limit: baseAst.limit, setOpenPopover: setOpenPopover, LimitPopover: LimitPopoverComponent, EditPopover: AddLimitPopover_1.AddLimitPopover, handleDelete: () => {
|
|
2479
|
+
const newAst = { ...baseAst };
|
|
2480
|
+
newAst.limit = null;
|
|
2481
|
+
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2482
|
+
fetchSqlQuery(newAst);
|
|
2483
|
+
}, onSave: (limit) => {
|
|
2484
|
+
const newAst = { ...baseAst };
|
|
2485
|
+
newAst.limit = {
|
|
2486
|
+
seperator: '',
|
|
2487
|
+
value: [
|
|
2488
|
+
{
|
|
2489
|
+
type: 'number',
|
|
2490
|
+
value: limit,
|
|
2491
|
+
},
|
|
2492
|
+
],
|
|
2493
|
+
};
|
|
2494
|
+
setOpenPopover(null);
|
|
2495
|
+
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2496
|
+
fetchSqlQuery(newAst);
|
|
2497
|
+
}, TextInput: TextInputComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent }) })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: () => {
|
|
2498
|
+
if (!selectedColumns ||
|
|
2499
|
+
selectedColumns.length === 0 ||
|
|
2500
|
+
loading) {
|
|
2501
|
+
return;
|
|
2502
|
+
}
|
|
2503
|
+
if (!openPopover) {
|
|
2504
|
+
setOpenPopover('AddLimitPopover');
|
|
2505
|
+
}
|
|
2506
|
+
}, label: 'Add limit' }), (0, jsx_runtime_1.jsx)(PopoverComponent, { isOpen: openPopover === 'AddLimitPopover', setIsOpen: (isOpen) => {
|
|
2507
|
+
if (!isOpen) {
|
|
2508
|
+
setIsPending(false);
|
|
2509
|
+
setActiveEditItem(null);
|
|
2510
|
+
setActivePath(null);
|
|
2511
|
+
setOpenPopover(null);
|
|
2512
|
+
}
|
|
2513
|
+
}, popoverTitle: "Add limit", popoverChildren: (0, jsx_runtime_1.jsx)(AddLimitPopover_1.AddLimitPopover, { TextInput: TextInputComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent, onSave: () => { } }) })] }))] })] }), (0, jsx_runtime_1.jsxs)(ContainerComponent, { children: [isAIEnabled && ((0, jsx_runtime_1.jsx)("form", { ref: askAILoadingContainerRef, onSubmit: (event) => {
|
|
2306
2514
|
event.preventDefault();
|
|
2307
2515
|
}, style: {
|
|
2308
2516
|
display: 'flex',
|
|
2309
2517
|
flexDirection: 'row',
|
|
2310
2518
|
gap: 12,
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2519
|
+
visibility: askAIInputWidth === -1 && askAILoadingContainerWidth === -1
|
|
2520
|
+
? 'hidden'
|
|
2521
|
+
: 'visible',
|
|
2522
|
+
}, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(TextInputComponent, { id: "ask_ai_loading_bar", placeholder: baseAst || initialLoad
|
|
2523
|
+
? 'Ask a follow-up question...'
|
|
2524
|
+
: 'Ask a question...', width: askAIInputWidth !== -1
|
|
2525
|
+
? askAIInputWidth
|
|
2526
|
+
: askAILoadingContainerWidth, value: aiPrompt, onChange: () => { } }), (0, jsx_runtime_1.jsx)(ButtonComponent, { onClick: () => { }, label: "Ask AI" }), ((baseAst && dataDisplayed) || initialLoad) && ((0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: () => { }, label: "New report" }))] }) })), (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(TableComponent, { isLoading: true, rows: [], columns: [] }), baseAst && dataDisplayed && ((0, jsx_runtime_1.jsxs)("div", { style: {
|
|
2315
2527
|
display: 'flex',
|
|
2316
2528
|
flexDirection: 'row',
|
|
2317
2529
|
gap: '12px',
|
|
@@ -2324,341 +2536,405 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
2324
2536
|
overflowY: 'auto',
|
|
2325
2537
|
boxSizing: 'border-box',
|
|
2326
2538
|
...containerStyle,
|
|
2327
|
-
}, className: className, children: [(0, jsx_runtime_1.jsxs)(SidebarComponent, { children: [(0, jsx_runtime_1.
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
return;
|
|
2332
|
-
}
|
|
2333
|
-
if (!openPopover) {
|
|
2334
|
-
setOpenPopover('AddColumnPopover');
|
|
2335
|
-
}
|
|
2336
|
-
}, label: "Select columns" }), (0, jsx_runtime_1.jsx)(PopoverComponent, { isOpen: openPopover === 'AddColumnPopover', setIsOpen: (isOpen) => {
|
|
2337
|
-
if (!isOpen) {
|
|
2338
|
-
// delay onClose callback so onClick no-ops
|
|
2339
|
-
setTimeout(() => {
|
|
2340
|
-
setIsPending(false);
|
|
2341
|
-
setActiveEditItem(null);
|
|
2342
|
-
setActivePath(null);
|
|
2343
|
-
setOpenPopover(null);
|
|
2344
|
-
}, 100);
|
|
2345
|
-
}
|
|
2346
|
-
}, popoverTitle: "Select columns", popoverChildren: (0, jsx_runtime_1.jsx)(AddColumnPopover_1.default, { onSave: () => {
|
|
2347
|
-
setActiveEditItem(null);
|
|
2348
|
-
setActivePath(null);
|
|
2349
|
-
setOpenPopover(null);
|
|
2350
|
-
}, orderedColumnNames: orderedColumnNames, setOrderedColumnNames: setOrderedColumnNames, selectedColumns: selectedColumns, setSelectedColumns: setSelectedColumns, isSelectedAllColumns: isSelectedAllColumns, clearAllState: clearAllState, nameToColumn: nameToColumn, baseAst: baseAst, setBaseAst: (ast) => {
|
|
2351
|
-
setBaseAst(ast);
|
|
2352
|
-
fetchSqlQuery(ast);
|
|
2353
|
-
}, pivot: pivot, initialTableName: initialTableName, defaultAST: constants_1.defaultAST, defaultTable: constants_1.defaultTable, setPivot: setPivot, TextInput: TextInputComponent, SelectColumn: SelectColumnComponent, SecondaryButton: SecondaryButtonComponent, Button: ButtonComponent }) }), (0, jsx_runtime_1.jsx)("div", { style: { height: 28, width: '100%' } }), (0, jsx_runtime_1.jsx)(SidebarHeadingComponent, { label: "Filters" }), (0, jsx_runtime_1.jsx)("div", { style: { height: 4, width: '100%' } }), formData && ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
2354
|
-
display: 'flex',
|
|
2355
|
-
flexDirection: 'column',
|
|
2356
|
-
gap: 8,
|
|
2357
|
-
marginBottom: 12,
|
|
2358
|
-
}, children: renderSentence(formData, formData, '', true) })), (0, jsx_runtime_1.jsxs)("div", { style: {
|
|
2359
|
-
display: 'flex',
|
|
2360
|
-
flexDirection: 'column',
|
|
2361
|
-
gap: 2.5,
|
|
2362
|
-
alignItems: 'flex-start',
|
|
2363
|
-
}, children: [(0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: () => {
|
|
2364
|
-
if (!selectedColumns || selectedColumns.length === 0 || loading) {
|
|
2539
|
+
}, className: className, children: [(0, jsx_runtime_1.jsxs)(SidebarComponent, { children: [(0, jsx_runtime_1.jsxs)("div", { style: { width: '100%' }, children: [(0, jsx_runtime_1.jsx)(SidebarHeadingComponent, { label: "Columns" }), (0, jsx_runtime_1.jsx)(DraggableColumns, {}), (0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: () => {
|
|
2540
|
+
if (loadingSchema)
|
|
2541
|
+
return;
|
|
2542
|
+
if (!orderedColumnNames) {
|
|
2365
2543
|
return;
|
|
2366
2544
|
}
|
|
2367
2545
|
if (!openPopover) {
|
|
2368
|
-
|
|
2369
|
-
const [_table, column] = value.split('.');
|
|
2370
|
-
const columnType = getColumnTypeByName(column);
|
|
2371
|
-
if ((0, ast_1.isNumericColumnType)(columnType)) {
|
|
2372
|
-
const newSubtree = (0, util_1.deepCopy)(constants_1.defaultNumericComparison);
|
|
2373
|
-
newSubtree.left.column = column;
|
|
2374
|
-
setActiveEditItem(newSubtree);
|
|
2375
|
-
}
|
|
2376
|
-
else {
|
|
2377
|
-
const newSubtree = (0, util_1.deepCopy)(constants_1.defaultEntry);
|
|
2378
|
-
newSubtree.left.args.value[0].column = column;
|
|
2379
|
-
setActiveEditItem(newSubtree);
|
|
2380
|
-
}
|
|
2381
|
-
setOpenPopover('AddFilterPopover');
|
|
2382
|
-
setActivePath('');
|
|
2383
|
-
setIsPending(true);
|
|
2546
|
+
setOpenPopover('AddColumnModal');
|
|
2384
2547
|
}
|
|
2385
|
-
}, label:
|
|
2548
|
+
}, label: "Select columns" }), (0, jsx_runtime_1.jsx)(ModalComponent, { isOpen: openPopover === 'AddColumnModal', setIsOpen: (isOpen) => {
|
|
2386
2549
|
if (!isOpen) {
|
|
2387
2550
|
// delay onClose callback so onClick no-ops
|
|
2388
2551
|
setTimeout(() => {
|
|
2389
2552
|
setIsPending(false);
|
|
2390
|
-
setActivePath(null);
|
|
2391
|
-
setOpenPopover(null);
|
|
2392
|
-
clearCheckboxes();
|
|
2393
2553
|
setActiveEditItem(null);
|
|
2394
|
-
}, 200);
|
|
2395
|
-
}
|
|
2396
|
-
}, popoverTitle: "Add filter", popoverChildren: (0, jsx_runtime_1.jsx)(ui_1.AddFilterPopover, { onSave: () => {
|
|
2397
|
-
if ((0, util_1.isNodeEmptyCollection)(activeEditItem)) {
|
|
2398
|
-
setIsPending(false);
|
|
2399
|
-
setActivePath(null);
|
|
2400
|
-
setOpenPopover(null);
|
|
2401
|
-
clearCheckboxes();
|
|
2402
|
-
setTimeout(() => {
|
|
2403
|
-
setActiveEditItem(null);
|
|
2404
|
-
}, 300);
|
|
2405
|
-
}
|
|
2406
|
-
else {
|
|
2407
|
-
setIsPending(false);
|
|
2408
|
-
handleInsertion(activeEditItem, 'AND', false);
|
|
2409
2554
|
setActivePath(null);
|
|
2410
2555
|
setOpenPopover(null);
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2556
|
+
}, 100);
|
|
2557
|
+
}
|
|
2558
|
+
}, title: "Select columns", children: (0, jsx_runtime_1.jsx)(AddColumnModal_1.default, { onSave: () => {
|
|
2559
|
+
setActiveEditItem(null);
|
|
2560
|
+
setActivePath(null);
|
|
2561
|
+
setOpenPopover(null);
|
|
2562
|
+
}, orderedColumnNames: orderedColumnNames, setOrderedColumnNames: setOrderedColumnNames, selectedColumns: selectedColumns, setSelectedColumns: setSelectedColumns, isSelectedAllColumns: isSelectedAllColumns, clearAllState: clearAllState, nameToColumn: nameToColumn, baseAst: baseAst, setBaseAst: (ast) => {
|
|
2563
|
+
setBaseAst(ast);
|
|
2564
|
+
fetchSqlQuery(ast);
|
|
2565
|
+
}, pivot: pivot, initialTableName: initialTableName, defaultAST: constants_1.defaultAST, defaultTable: constants_1.defaultTable, setPivot: setPivot, TextInput: TextInputComponent, SelectColumn: SelectColumnComponent, SecondaryButton: SecondaryButtonComponent, Button: ButtonComponent, ColumnSearchEmptyState: ColumnSearchEmptyState }) })] }), (0, jsx_runtime_1.jsxs)("div", { style: { width: '100%' }, children: [(0, jsx_runtime_1.jsx)(SidebarHeadingComponent, { label: "Filters" }), formData && ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
2566
|
+
display: 'flex',
|
|
2567
|
+
flexDirection: 'column',
|
|
2568
|
+
gap: 8,
|
|
2569
|
+
marginBottom: 12,
|
|
2570
|
+
}, children: renderSentence(formData, formData, '', true) })), (0, jsx_runtime_1.jsxs)("div", { style: {
|
|
2571
|
+
display: 'flex',
|
|
2572
|
+
flexDirection: 'column',
|
|
2573
|
+
alignItems: 'flex-start',
|
|
2574
|
+
}, children: [(0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { disabled: !baseAst || !dataDisplayed, onClick: () => {
|
|
2575
|
+
if (!selectedColumns ||
|
|
2576
|
+
selectedColumns.length === 0 ||
|
|
2577
|
+
loading) {
|
|
2578
|
+
return;
|
|
2579
|
+
}
|
|
2419
2580
|
if (!openPopover) {
|
|
2420
|
-
|
|
2421
|
-
|
|
2581
|
+
const value = orderedColumnNames[0];
|
|
2582
|
+
const [_table, column] = value.split('.');
|
|
2583
|
+
const columnType = getColumnTypeByName(column);
|
|
2584
|
+
if ((0, ast_1.isNumericColumnType)(columnType)) {
|
|
2585
|
+
const newSubtree = (0, util_1.deepCopy)(constants_1.defaultNumericComparison);
|
|
2586
|
+
newSubtree.left.column = column;
|
|
2587
|
+
setActiveEditItem(newSubtree);
|
|
2588
|
+
}
|
|
2589
|
+
else {
|
|
2590
|
+
const newSubtree = (0, util_1.deepCopy)(constants_1.defaultEntry);
|
|
2591
|
+
newSubtree.left.args.value[0].column = column;
|
|
2592
|
+
setActiveEditItem(newSubtree);
|
|
2593
|
+
}
|
|
2594
|
+
setOpenPopover('AddFilterPopover');
|
|
2422
2595
|
setActivePath('');
|
|
2423
2596
|
setIsPending(true);
|
|
2424
2597
|
}
|
|
2425
|
-
}, label: 'Add
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
setActivePath(null);
|
|
2432
|
-
setOpenPopover(null);
|
|
2433
|
-
clearCheckboxes();
|
|
2434
|
-
}, 200);
|
|
2435
|
-
}
|
|
2436
|
-
}, popoverChildren: (0, jsx_runtime_1.jsx)(AddConditionPopover, { onSave: () => {
|
|
2437
|
-
if ((0, util_1.isNodeEmptyCollection)(activeEditItem)) {
|
|
2438
|
-
setIsPending(false);
|
|
2439
|
-
setTimeout(() => {
|
|
2440
|
-
setActiveEditItem(null);
|
|
2441
|
-
}, 300);
|
|
2442
|
-
setActivePath(null);
|
|
2598
|
+
}, label: 'Add filter' }), (0, jsx_runtime_1.jsx)("div", { style: {
|
|
2599
|
+
position: 'relative',
|
|
2600
|
+
...(openPopover === 'AddFilterPopover' && { top: 12 }),
|
|
2601
|
+
}, children: (0, jsx_runtime_1.jsx)(PopoverComponent, { isOpen: openPopover === 'AddFilterPopover', setIsOpen: (isOpen) => {
|
|
2602
|
+
if (!isOpen) {
|
|
2603
|
+
// delay onClose callback so onClick no-ops
|
|
2443
2604
|
setOpenPopover(null);
|
|
2444
|
-
clearCheckboxes();
|
|
2445
|
-
}
|
|
2446
|
-
else {
|
|
2447
|
-
setIsPending(false);
|
|
2448
|
-
handleInsertion(activeEditItem, topLevelBinaryOperator, true);
|
|
2449
2605
|
setTimeout(() => {
|
|
2606
|
+
setIsPending(false);
|
|
2607
|
+
setActivePath(null);
|
|
2608
|
+
clearCheckboxes();
|
|
2450
2609
|
setActiveEditItem(null);
|
|
2451
2610
|
}, 300);
|
|
2452
|
-
setActivePath(null);
|
|
2453
|
-
setOpenPopover(null);
|
|
2454
|
-
clearCheckboxes();
|
|
2455
2611
|
}
|
|
2456
|
-
}
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
if (pivot) {
|
|
2522
|
-
setPivot({ ...pivot, sort: false });
|
|
2523
|
-
return;
|
|
2524
|
-
}
|
|
2525
|
-
const newAst = { ...baseAst };
|
|
2526
|
-
newAst.orderby.splice(id, 1);
|
|
2527
|
-
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2528
|
-
fetchSqlQuery((0, util_1.deepCopy)(newAst));
|
|
2529
|
-
}, onSave: (column, direction) => {
|
|
2530
|
-
if (pivot) {
|
|
2531
|
-
setPivot({
|
|
2532
|
-
...pivot,
|
|
2533
|
-
sort: true,
|
|
2534
|
-
sortDirection: direction,
|
|
2535
|
-
});
|
|
2536
|
-
return;
|
|
2537
|
-
}
|
|
2538
|
-
setIsPending(false);
|
|
2539
|
-
setActiveEditItem(null);
|
|
2540
|
-
setOpenPopover(null);
|
|
2541
|
-
if (column === '')
|
|
2542
|
-
return;
|
|
2543
|
-
const newAst = { ...baseAst };
|
|
2544
|
-
newAst.orderby[id] = {
|
|
2545
|
-
expr: {
|
|
2546
|
-
type: 'column_ref',
|
|
2547
|
-
table: null,
|
|
2548
|
-
column: column,
|
|
2549
|
-
},
|
|
2550
|
-
type: direction,
|
|
2551
|
-
};
|
|
2552
|
-
// look through the columns
|
|
2553
|
-
setActivePath(null);
|
|
2554
|
-
setOpenPopover(null);
|
|
2555
|
-
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2556
|
-
fetchSqlQuery((0, util_1.deepCopy)(newAst));
|
|
2557
|
-
}, Select: SelectComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent }, `sort-sentence-${id}`))) })), (0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: () => {
|
|
2558
|
-
if (!selectedColumns || selectedColumns.length === 0) {
|
|
2559
|
-
return;
|
|
2560
|
-
}
|
|
2561
|
-
if (!openPopover) {
|
|
2562
|
-
setOpenPopover('AddSortPopover');
|
|
2563
|
-
}
|
|
2564
|
-
}, label: 'Add sort' }), (0, jsx_runtime_1.jsx)(PopoverComponent, { isOpen: openPopover === 'AddSortPopover', setIsOpen: (isOpen) => {
|
|
2565
|
-
if (!isOpen) {
|
|
2566
|
-
setIsPending(false);
|
|
2567
|
-
setActiveEditItem(null);
|
|
2568
|
-
setActivePath(null);
|
|
2569
|
-
setOpenPopover(null);
|
|
2570
|
-
}
|
|
2571
|
-
}, popoverTitle: "Sort by", popoverChildren: (0, jsx_runtime_1.jsx)(AddSortPopover_1.AddSortPopover, { columns: pivot ? [`.${pivot.rowField}`] : selectedColumns, Select: SelectComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent, onSave: (column, direction) => {
|
|
2572
|
-
if (column === '')
|
|
2573
|
-
return;
|
|
2574
|
-
if (pivot) {
|
|
2575
|
-
setPivot({ ...pivot, sort: true, sortDirection: direction });
|
|
2576
|
-
const pivotedData = (0, PivotModal_1.generatePivotTable)({ ...pivot, sort: true, sortDirection: direction }, rows, [null, null, null], false);
|
|
2577
|
-
setPivotData(pivotedData || []);
|
|
2578
|
-
setActivePath(null);
|
|
2579
|
-
setOpenPopover(null);
|
|
2580
|
-
setBaseAst((0, util_1.deepCopy)(baseAst));
|
|
2581
|
-
return;
|
|
2582
|
-
}
|
|
2583
|
-
const newAst = { ...baseAst };
|
|
2584
|
-
if (!newAst.orderby)
|
|
2585
|
-
newAst.orderby = [];
|
|
2586
|
-
newAst.orderby.push({
|
|
2587
|
-
expr: { type: 'column_ref', column },
|
|
2588
|
-
type: direction,
|
|
2589
|
-
});
|
|
2590
|
-
// look through the columns
|
|
2591
|
-
setActivePath(null);
|
|
2592
|
-
setOpenPopover(null);
|
|
2593
|
-
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2594
|
-
fetchSqlQuery((0, util_1.deepCopy)(newAst));
|
|
2595
|
-
} }) }), (0, jsx_runtime_1.jsx)("div", { style: { height: 28, width: '100%' } }), (0, jsx_runtime_1.jsx)(SidebarHeadingComponent, { label: "Limit" }), (0, jsx_runtime_1.jsx)("div", { style: { height: 4, width: '100%' } }), baseAst && baseAst.limit ? ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
2596
|
-
display: 'flex',
|
|
2597
|
-
flexDirection: 'column',
|
|
2598
|
-
gap: 8,
|
|
2599
|
-
marginBottom: 12,
|
|
2600
|
-
}, children: (0, jsx_runtime_1.jsx)(AddLimitPopover_1.LimitSentence, { limit: baseAst.limit, setOpenPopover: setOpenPopover, LimitPopover: LimitPopoverComponent, EditPopover: AddLimitPopover_1.AddLimitPopover, handleDelete: () => {
|
|
2601
|
-
const newAst = { ...baseAst };
|
|
2602
|
-
newAst.limit = null;
|
|
2603
|
-
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2604
|
-
fetchSqlQuery((0, util_1.deepCopy)(newAst));
|
|
2605
|
-
}, onSave: (limit) => {
|
|
2606
|
-
const newAst = { ...baseAst };
|
|
2607
|
-
newAst.limit = {
|
|
2608
|
-
seperator: '',
|
|
2609
|
-
value: [
|
|
2610
|
-
{
|
|
2611
|
-
type: 'number',
|
|
2612
|
-
value: limit,
|
|
2613
|
-
},
|
|
2614
|
-
],
|
|
2615
|
-
};
|
|
2616
|
-
setOpenPopover(null);
|
|
2617
|
-
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2618
|
-
fetchSqlQuery((0, util_1.deepCopy)(newAst));
|
|
2619
|
-
}, TextInput: TextInputComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent }) })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: () => {
|
|
2620
|
-
if (!selectedColumns || selectedColumns.length === 0) {
|
|
2621
|
-
return;
|
|
2622
|
-
}
|
|
2623
|
-
if (!baseAst) {
|
|
2612
|
+
}, popoverTitle: "Add filter", popoverChildren: (0, jsx_runtime_1.jsx)(ui_1.AddFilterPopover, { onSave: () => {
|
|
2613
|
+
if ((0, util_1.isNodeEmptyCollection)(activeEditItem)) {
|
|
2614
|
+
setOpenPopover(null);
|
|
2615
|
+
clearCheckboxes();
|
|
2616
|
+
setIsPending(false);
|
|
2617
|
+
setTimeout(() => {
|
|
2618
|
+
setActivePath(null);
|
|
2619
|
+
setActiveEditItem(null);
|
|
2620
|
+
}, 300);
|
|
2621
|
+
}
|
|
2622
|
+
else {
|
|
2623
|
+
setOpenPopover(null);
|
|
2624
|
+
setIsPending(false);
|
|
2625
|
+
handleInsertion(activeEditItem, 'AND', false);
|
|
2626
|
+
setActivePath(null);
|
|
2627
|
+
setTimeout(() => {
|
|
2628
|
+
clearCheckboxes();
|
|
2629
|
+
setActiveEditItem(null);
|
|
2630
|
+
}, 300);
|
|
2631
|
+
}
|
|
2632
|
+
}, Button: ButtonComponent, renderNode: renderNode, activeEditItem: activeEditItem }) }) }), baseAst?.where &&
|
|
2633
|
+
false && ( // temp removed the AddConditionPopover
|
|
2634
|
+
(0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: () => {
|
|
2635
|
+
if (!openPopover) {
|
|
2636
|
+
setActiveEditItem((0, util_1.deepCopy)(constants_1.defaultEntry));
|
|
2637
|
+
setOpenPopover('AddConditionPopover');
|
|
2638
|
+
setActivePath('');
|
|
2639
|
+
setIsPending(true);
|
|
2640
|
+
}
|
|
2641
|
+
}, label: 'Add condition' }), (0, jsx_runtime_1.jsx)(PopoverComponent, { isOpen: openPopover === 'AddConditionPopover', setIsOpen: (isOpen) => {
|
|
2642
|
+
if (!isOpen) {
|
|
2643
|
+
// delay onClose callback so onClick no-ops
|
|
2644
|
+
setTimeout(() => {
|
|
2645
|
+
setIsPending(false);
|
|
2646
|
+
setActiveEditItem(null);
|
|
2647
|
+
setActivePath(null);
|
|
2648
|
+
setOpenPopover(null);
|
|
2649
|
+
clearCheckboxes();
|
|
2650
|
+
}, 200);
|
|
2651
|
+
}
|
|
2652
|
+
}, popoverChildren: (0, jsx_runtime_1.jsx)(AddConditionPopover, { onSave: () => {
|
|
2653
|
+
if ((0, util_1.isNodeEmptyCollection)(activeEditItem)) {
|
|
2654
|
+
setIsPending(false);
|
|
2655
|
+
setTimeout(() => {
|
|
2656
|
+
setActiveEditItem(null);
|
|
2657
|
+
}, 300);
|
|
2658
|
+
setActivePath(null);
|
|
2659
|
+
setOpenPopover(null);
|
|
2660
|
+
clearCheckboxes();
|
|
2661
|
+
}
|
|
2662
|
+
else {
|
|
2663
|
+
setIsPending(false);
|
|
2664
|
+
handleInsertion(activeEditItem, topLevelBinaryOperator, true);
|
|
2665
|
+
setTimeout(() => {
|
|
2666
|
+
setActiveEditItem(null);
|
|
2667
|
+
}, 300);
|
|
2668
|
+
setActivePath(null);
|
|
2669
|
+
setOpenPopover(null);
|
|
2670
|
+
clearCheckboxes();
|
|
2671
|
+
}
|
|
2672
|
+
} }) })] }))] })] }), (0, jsx_runtime_1.jsxs)("div", { style: { width: '100%' }, children: [(0, jsx_runtime_1.jsx)(SidebarHeadingComponent, { label: "Pivot" }), (0, jsx_runtime_1.jsx)(PivotModal_1.PivotModal, { pivotRowField: pivotRowField, setPivotRowField: setPivotRowField, pivotColumnField: pivotColumnField, setPivotColumnField: setPivotColumnField, pivotValueField: pivotValueField, setPivotValueField: setPivotValueField, pivotAggregation: pivotAggregation, setPivotAggregation: setPivotAggregation, createdPivots: createdPivots, setCreatedPivots: setCreatedPivots, recommendedPivots: recommendedPivots, setRecommendedPivots: setRecommendedPivots, popUpTitle: pivotPopUpTitle, setPopUpTitle: setPivotPopUpTitle, selectedTable: initialTableName, SelectComponent: SelectComponent, ButtonComponent: ButtonComponent, CardComponent: CardComponent, SecondaryButtonComponent: SecondaryButtonComponent, PopoverComponent: PopoverComponent, TextComponent: TextComponent, ErrorMessageComponent: ErrorMessageComponent, PivotRowContainer: PivotRowContainer, PivotColumnContainer: PivotColumnContainer, isOpen: showPivotPopover, setIsOpen: setShowPivotPopover, showUpdatePivot: isEdittingPivot, setShowUpdatePivot: setIsEdittingPivot, parentRef: parentRef, data: rows, columns: fields, triggerButtonText: 'Add pivot', selectedPivotIndex: selectedPivotIndex, setSelectedPivotIndex: setSelectedPivotIndex, removePivot: () => {
|
|
2673
|
+
setPivot(null);
|
|
2674
|
+
setPivotData(null);
|
|
2675
|
+
}, selectPivot: (pivot) => {
|
|
2676
|
+
if (!pivot)
|
|
2624
2677
|
return;
|
|
2678
|
+
const newAst = { ...baseAst };
|
|
2679
|
+
newAst.orderby = null;
|
|
2680
|
+
if (pivot.rowFieldType === 'date') {
|
|
2681
|
+
pivot['sort'] = true;
|
|
2682
|
+
pivot['sortDirection'] = 'ASC';
|
|
2625
2683
|
}
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2684
|
+
setBaseAst(newAst); // trigger refetch
|
|
2685
|
+
setPivot(pivot);
|
|
2686
|
+
const pivotedData = (0, PivotModal_1.generatePivotTable)(pivot, rows, [null, null, null], false);
|
|
2687
|
+
setPivotData(pivotedData || []);
|
|
2688
|
+
setErrorMessage('');
|
|
2689
|
+
}, selectPivotOnEdit: true, showTrigger: !pivot, theme: theme, LabelComponent: LabelComponent, HeaderComponent: HeaderComponent, dateRange: [null, null, null], pivotCountRequest: 4, query: activeQuery, initialUniqueValues: uniqueValues[currentTable], disabled: !baseAst || !dataDisplayed, pivotRecommendationsEnabled: pivotRecommendationsEnabled && overrideRecommendations }), pivot && ((0, jsx_runtime_1.jsx)(PivotList_1.PivotCard, { pivotTable: {
|
|
2690
|
+
pivot: pivot,
|
|
2691
|
+
rows: pivotData?.rows || [],
|
|
2692
|
+
columns: pivotData?.columns || [],
|
|
2693
|
+
}, theme: theme, index: 0, onSelectPivot: () => {
|
|
2694
|
+
setIsEdittingPivot(true);
|
|
2695
|
+
setShowPivotPopover(true);
|
|
2696
|
+
setPivotRowField(pivot?.rowField);
|
|
2697
|
+
setPivotColumnField(pivot?.columnField);
|
|
2698
|
+
setPivotValueField(pivot?.valueField);
|
|
2699
|
+
setPivotAggregation(pivot?.aggregationType);
|
|
2700
|
+
setPivotPopUpTitle('Edit pivot');
|
|
2701
|
+
}, selectedPivotIndex: -1, onEditPivot: () => { }, ButtonComponent: ButtonComponent, HeaderComponent: HeaderComponent, CardComponent: CardComponent, showEdit: false, onClose: () => {
|
|
2702
|
+
setPivot(null);
|
|
2703
|
+
setPivotData(null);
|
|
2704
|
+
setBaseAst((0, util_1.deepCopy)(baseAst));
|
|
2705
|
+
}, minHeight: 180, LabelComponent: LabelComponent, TextComponent: TextComponent }))] }), (0, jsx_runtime_1.jsxs)("div", { style: { width: '100%' }, children: [(0, jsx_runtime_1.jsx)(SidebarHeadingComponent, { label: "Sort" }), pivot && pivot.sort && ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
2706
|
+
display: 'flex',
|
|
2707
|
+
flexDirection: 'column',
|
|
2708
|
+
gap: 8,
|
|
2709
|
+
marginBottom: 12,
|
|
2710
|
+
}, children: (0, jsx_runtime_1.jsx)(AddSortPopover_1.SortSentence, { sortData: {
|
|
2711
|
+
type: pivot.sortDirection,
|
|
2712
|
+
expr: { type: 'column_ref', column: pivot.sortField },
|
|
2713
|
+
}, columns: pivot
|
|
2714
|
+
? pivot.columnField
|
|
2715
|
+
? [`.${pivot.rowField}`]
|
|
2716
|
+
: [
|
|
2717
|
+
`.${pivot.rowField}`,
|
|
2718
|
+
`.${pivot.valueField || 'count'}`,
|
|
2719
|
+
]
|
|
2720
|
+
: selectedColumns, setIsPending: setIsPending, setEditPopoverKey: setEditPopoverKey, setActiveEditItem: setActiveEditItem, setActivePath: setActivePath, setOpenPopover: setOpenPopover, SortPopover: SortPopoverComponent, EditPopover: AddSortPopover_1.AddSortPopover, handleDelete: () => {
|
|
2721
|
+
if (pivot) {
|
|
2722
|
+
setPivot({ ...pivot, sort: false });
|
|
2723
|
+
const pivotedData = (0, PivotModal_1.generatePivotTable)({ ...pivot, sort: false }, rows, [null, null, null], false);
|
|
2724
|
+
setPivotData(pivotedData || []);
|
|
2725
|
+
setErrorMessage('');
|
|
2726
|
+
return;
|
|
2727
|
+
}
|
|
2728
|
+
setBaseAst((0, util_1.deepCopy)(baseAst));
|
|
2729
|
+
fetchSqlQuery((0, util_1.deepCopy)(baseAst));
|
|
2730
|
+
}, onSave: (column, direction) => {
|
|
2731
|
+
if (pivot) {
|
|
2732
|
+
const sortFieldType = column === (pivot.valueField || 'count')
|
|
2733
|
+
? 'number'
|
|
2734
|
+
: pivot.rowFieldType;
|
|
2735
|
+
setPivot({
|
|
2736
|
+
...pivot,
|
|
2737
|
+
sort: true,
|
|
2738
|
+
sortDirection: direction,
|
|
2739
|
+
sortField: column,
|
|
2740
|
+
sortFieldType: sortFieldType,
|
|
2741
|
+
});
|
|
2742
|
+
const pivotedData = (0, PivotModal_1.generatePivotTable)({
|
|
2743
|
+
...pivot,
|
|
2744
|
+
sort: true,
|
|
2745
|
+
sortDirection: direction,
|
|
2746
|
+
sortField: column,
|
|
2747
|
+
sortFieldType: sortFieldType,
|
|
2748
|
+
}, rows, [null, null, null], false);
|
|
2749
|
+
setPivotData(pivotedData || []);
|
|
2750
|
+
setErrorMessage('');
|
|
2751
|
+
return;
|
|
2752
|
+
}
|
|
2753
|
+
setOpenPopover(null);
|
|
2754
|
+
setBaseAst((0, util_1.deepCopy)(baseAst));
|
|
2755
|
+
fetchSqlQuery((0, util_1.deepCopy)(baseAst));
|
|
2756
|
+
}, Select: SelectComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent }, `sort-sentence-pivot`) })), baseAst && baseAst.orderby && ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
2757
|
+
display: 'flex',
|
|
2758
|
+
flexDirection: 'column',
|
|
2759
|
+
gap: 8,
|
|
2760
|
+
marginBottom: 12,
|
|
2761
|
+
}, children: baseAst.orderby.map((sortData, id) => ((0, jsx_runtime_1.jsx)(AddSortPopover_1.SortSentence, { sortData: sortData, columns: selectedColumns, setIsPending: setIsPending, setEditPopoverKey: setEditPopoverKey, setActiveEditItem: setActiveEditItem, setActivePath: setActivePath, setOpenPopover: setOpenPopover, SortPopover: SortPopoverComponent, EditPopover: AddSortPopover_1.AddSortPopover, handleDelete: () => {
|
|
2762
|
+
if (pivot) {
|
|
2763
|
+
setPivot({ ...pivot, sort: false });
|
|
2764
|
+
return;
|
|
2765
|
+
}
|
|
2766
|
+
const newAst = { ...baseAst };
|
|
2767
|
+
newAst.orderby.splice(id, 1);
|
|
2768
|
+
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2769
|
+
fetchSqlQuery((0, util_1.deepCopy)(newAst));
|
|
2770
|
+
}, onSave: (column, direction) => {
|
|
2771
|
+
if (pivot) {
|
|
2772
|
+
const sortFieldType = column === (pivot.valueField || 'count')
|
|
2773
|
+
? 'number'
|
|
2774
|
+
: pivot.rowFieldType;
|
|
2775
|
+
setPivot({
|
|
2776
|
+
...pivot,
|
|
2777
|
+
sort: true,
|
|
2778
|
+
sortDirection: direction,
|
|
2779
|
+
sortField: column,
|
|
2780
|
+
sortFieldType: sortFieldType,
|
|
2781
|
+
});
|
|
2782
|
+
return;
|
|
2783
|
+
}
|
|
2631
2784
|
setIsPending(false);
|
|
2632
2785
|
setActiveEditItem(null);
|
|
2786
|
+
setOpenPopover(null);
|
|
2787
|
+
if (column === '')
|
|
2788
|
+
return;
|
|
2789
|
+
const newAst = { ...baseAst };
|
|
2790
|
+
newAst.orderby[id] = {
|
|
2791
|
+
expr: {
|
|
2792
|
+
type: 'column_ref',
|
|
2793
|
+
table: null,
|
|
2794
|
+
column: column,
|
|
2795
|
+
},
|
|
2796
|
+
type: direction,
|
|
2797
|
+
};
|
|
2798
|
+
// look through the columns
|
|
2633
2799
|
setActivePath(null);
|
|
2634
2800
|
setOpenPopover(null);
|
|
2801
|
+
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2802
|
+
fetchSqlQuery((0, util_1.deepCopy)(newAst));
|
|
2803
|
+
}, Select: SelectComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent }, `sort-sentence-${id}`))) })), (0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { disabled: !baseAst || !dataDisplayed, onClick: () => {
|
|
2804
|
+
if (!selectedColumns || selectedColumns.length === 0) {
|
|
2805
|
+
return;
|
|
2806
|
+
}
|
|
2807
|
+
if (!openPopover) {
|
|
2808
|
+
setOpenPopover('AddSortPopover');
|
|
2635
2809
|
}
|
|
2636
|
-
},
|
|
2810
|
+
}, label: 'Add sort' }), (0, jsx_runtime_1.jsx)("div", { style: {
|
|
2811
|
+
position: 'relative',
|
|
2812
|
+
...(openPopover === 'AddSortPopover' && { top: 12 }),
|
|
2813
|
+
}, children: (0, jsx_runtime_1.jsx)(PopoverComponent, { isOpen: openPopover === 'AddSortPopover', setIsOpen: (isOpen) => {
|
|
2814
|
+
if (!isOpen) {
|
|
2815
|
+
setIsPending(false);
|
|
2816
|
+
setActiveEditItem(null);
|
|
2817
|
+
setActivePath(null);
|
|
2818
|
+
setOpenPopover(null);
|
|
2819
|
+
}
|
|
2820
|
+
}, popoverTitle: "Sort by", popoverChildren: (0, jsx_runtime_1.jsx)(AddSortPopover_1.AddSortPopover, { columns: pivot
|
|
2821
|
+
? pivot.columnField
|
|
2822
|
+
? [`.${pivot.rowField}`]
|
|
2823
|
+
: [
|
|
2824
|
+
`.${pivot.rowField}`,
|
|
2825
|
+
`.${pivot.valueField || 'count'}`,
|
|
2826
|
+
]
|
|
2827
|
+
: selectedColumns, Select: SelectComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent, onSave: (column, direction) => {
|
|
2828
|
+
if (column === '')
|
|
2829
|
+
return;
|
|
2830
|
+
if (pivot) {
|
|
2831
|
+
const sortFieldType = column === (pivot.valueField || 'count')
|
|
2832
|
+
? 'number'
|
|
2833
|
+
: pivot.rowFieldType;
|
|
2834
|
+
setPivot({
|
|
2835
|
+
...pivot,
|
|
2836
|
+
sort: true,
|
|
2837
|
+
sortDirection: direction,
|
|
2838
|
+
sortField: column,
|
|
2839
|
+
sortFieldType: sortFieldType,
|
|
2840
|
+
});
|
|
2841
|
+
const pivotedData = (0, PivotModal_1.generatePivotTable)({
|
|
2842
|
+
...pivot,
|
|
2843
|
+
sort: true,
|
|
2844
|
+
sortDirection: direction,
|
|
2845
|
+
sortField: column,
|
|
2846
|
+
sortFieldType: sortFieldType,
|
|
2847
|
+
}, rows, [null, null, null], false);
|
|
2848
|
+
setErrorMessage('');
|
|
2849
|
+
setPivotData(pivotedData || []);
|
|
2850
|
+
setActivePath(null);
|
|
2851
|
+
setOpenPopover(null);
|
|
2852
|
+
setBaseAst((0, util_1.deepCopy)(baseAst));
|
|
2853
|
+
return;
|
|
2854
|
+
}
|
|
2855
|
+
const newAst = { ...baseAst };
|
|
2856
|
+
if (!newAst.orderby)
|
|
2857
|
+
newAst.orderby = [];
|
|
2858
|
+
newAst.orderby.push({
|
|
2859
|
+
expr: { type: 'column_ref', column },
|
|
2860
|
+
type: direction,
|
|
2861
|
+
});
|
|
2862
|
+
// look through the columns
|
|
2863
|
+
setActivePath(null);
|
|
2864
|
+
setOpenPopover(null);
|
|
2865
|
+
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2866
|
+
fetchSqlQuery((0, util_1.deepCopy)(newAst));
|
|
2867
|
+
} }) }) })] }), (0, jsx_runtime_1.jsxs)("div", { style: { width: '100%' }, children: [(0, jsx_runtime_1.jsx)(SidebarHeadingComponent, { label: "Limit" }), baseAst && baseAst.limit ? ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
2868
|
+
display: 'flex',
|
|
2869
|
+
flexDirection: 'column',
|
|
2870
|
+
gap: 8,
|
|
2871
|
+
marginBottom: 12,
|
|
2872
|
+
}, children: (0, jsx_runtime_1.jsx)(AddLimitPopover_1.LimitSentence, { limit: baseAst.limit, setOpenPopover: setOpenPopover, LimitPopover: LimitPopoverComponent, EditPopover: AddLimitPopover_1.AddLimitPopover, handleDelete: () => {
|
|
2873
|
+
const newAst = { ...baseAst };
|
|
2874
|
+
newAst.limit = null;
|
|
2875
|
+
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2876
|
+
fetchSqlQuery((0, util_1.deepCopy)(newAst));
|
|
2877
|
+
}, onSave: (limit) => {
|
|
2637
2878
|
const newAst = { ...baseAst };
|
|
2638
2879
|
newAst.limit = {
|
|
2639
2880
|
seperator: '',
|
|
2640
2881
|
value: [
|
|
2641
2882
|
{
|
|
2642
2883
|
type: 'number',
|
|
2643
|
-
value:
|
|
2884
|
+
value: limit,
|
|
2644
2885
|
},
|
|
2645
2886
|
],
|
|
2646
2887
|
};
|
|
2647
2888
|
setOpenPopover(null);
|
|
2648
2889
|
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2649
2890
|
fetchSqlQuery((0, util_1.deepCopy)(newAst));
|
|
2650
|
-
}
|
|
2891
|
+
}, TextInput: TextInputComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent }) })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { disabled: !baseAst || !dataDisplayed, onClick: () => {
|
|
2892
|
+
if (!selectedColumns || selectedColumns.length === 0) {
|
|
2893
|
+
return;
|
|
2894
|
+
}
|
|
2895
|
+
if (!baseAst) {
|
|
2896
|
+
return;
|
|
2897
|
+
}
|
|
2898
|
+
if (!openPopover) {
|
|
2899
|
+
setOpenPopover('AddLimitPopover');
|
|
2900
|
+
}
|
|
2901
|
+
}, label: 'Add limit' }), (0, jsx_runtime_1.jsx)("div", { style: {
|
|
2902
|
+
position: 'relative',
|
|
2903
|
+
...(openPopover === 'AddLimitPopover' && { top: 12 }),
|
|
2904
|
+
}, children: (0, jsx_runtime_1.jsx)(PopoverComponent, { isOpen: openPopover === 'AddLimitPopover', setIsOpen: (isOpen) => {
|
|
2905
|
+
if (!isOpen) {
|
|
2906
|
+
setIsPending(false);
|
|
2907
|
+
setActiveEditItem(null);
|
|
2908
|
+
setActivePath(null);
|
|
2909
|
+
setOpenPopover(null);
|
|
2910
|
+
}
|
|
2911
|
+
}, popoverTitle: "Add limit", popoverChildren: (0, jsx_runtime_1.jsx)(AddLimitPopover_1.AddLimitPopover, { TextInput: TextInputComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent, onSave: (limit) => {
|
|
2912
|
+
const newAst = { ...baseAst };
|
|
2913
|
+
newAst.limit = {
|
|
2914
|
+
seperator: '',
|
|
2915
|
+
value: [
|
|
2916
|
+
{
|
|
2917
|
+
type: 'number',
|
|
2918
|
+
value: Number(limit),
|
|
2919
|
+
},
|
|
2920
|
+
],
|
|
2921
|
+
};
|
|
2922
|
+
setOpenPopover(null);
|
|
2923
|
+
setBaseAst((0, util_1.deepCopy)(newAst));
|
|
2924
|
+
fetchSqlQuery((0, util_1.deepCopy)(newAst));
|
|
2925
|
+
} }) }) })] }))] })] }), (0, jsx_runtime_1.jsxs)(ContainerComponent, { children: [isAIEnabled && ((0, jsx_runtime_1.jsx)("form", { ref: askAIContainerRef, onSubmit: (event) => {
|
|
2651
2926
|
event.preventDefault();
|
|
2652
2927
|
handleAsk();
|
|
2653
2928
|
}, style: {
|
|
2654
2929
|
display: 'flex',
|
|
2655
2930
|
flexDirection: 'row',
|
|
2656
2931
|
gap: 12,
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2932
|
+
visibility: askAIInputWidth === -1 && askAILoadingContainerWidth === -1
|
|
2933
|
+
? 'hidden'
|
|
2934
|
+
: 'visible',
|
|
2935
|
+
}, children: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(TextInputComponent, { id: "ask_ai_input_bar", value: aiPrompt, width: askAIInputWidth !== -1
|
|
2936
|
+
? askAIInputWidth
|
|
2937
|
+
: askAILoadingContainerWidth, onChange: (e) => setAiPrompt(e.target.value), placeholder: baseAst ? 'Ask a follow-up question...' : 'Ask a question...' }), (0, jsx_runtime_1.jsx)(ButtonComponent, { onClick: handleAsk, label: 'Ask AI' }), ((baseAst && dataDisplayed) || initialLoad) && ((0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { label: 'New report', onClick: clearAllState }))] }) })), baseAst && ((0, jsx_runtime_1.jsx)(TableComponent, { isLoading: loading && errorMessage.length === 0, rows: pivotData?.rows || formattedRows, columns: pivot
|
|
2662
2938
|
? pivotData?.columns || emptyPivotColumns()
|
|
2663
2939
|
: enforceOrderOnColumns(Object.keys(rows[0] ?? {})).map((c) => {
|
|
2664
2940
|
return { label: (0, textProcessing_1.snakeCaseToTitleCase)(c), field: c };
|
|
@@ -2666,13 +2942,22 @@ function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => voi
|
|
|
2666
2942
|
display: 'flex',
|
|
2667
2943
|
flexDirection: 'row',
|
|
2668
2944
|
gap: '12px',
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2945
|
+
width: '100%',
|
|
2946
|
+
}, children: [errorMessage ? ((0, jsx_runtime_1.jsxs)("div", { style: {
|
|
2947
|
+
display: 'flex',
|
|
2948
|
+
flexDirection: 'row',
|
|
2949
|
+
alignItems: 'center',
|
|
2950
|
+
overflow: 'hidden',
|
|
2951
|
+
width: '100%',
|
|
2952
|
+
gap: 12,
|
|
2953
|
+
}, children: [(0, jsx_runtime_1.jsx)("div", { style: {
|
|
2954
|
+
color: 'red',
|
|
2955
|
+
fontSize: 14,
|
|
2956
|
+
textOverflow: 'ellipsis',
|
|
2957
|
+
whiteSpace: 'nowrap',
|
|
2958
|
+
overflow: 'hidden',
|
|
2959
|
+
}, children: errorMessage }), (0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { onClick: handleAsk, label: 'Retry' })] })) : ((0, jsx_runtime_1.jsx)("div", { style: { width: '100%' } })), baseAst && dataDisplayed && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(SecondaryButtonComponent, { label: isCopying ? '✅ Copied' : 'Copy SQL', onClick: () => copyToClipboard(activeQuery) }), (0, jsx_runtime_1.jsx)(ButtonComponent, { onClick: () => {
|
|
2675
2960
|
setIsChartBuilderOpen(true);
|
|
2676
|
-
}, label: 'Add to dashboard' })] }))] })] }), (0, jsx_runtime_1.jsx)("style", { children: `body{margin:0;}` }), (0, jsx_runtime_1.jsx)(ChartBuilder_1.ChartBuilderWithModal, { rows: rows, columns:
|
|
2961
|
+
}, label: 'Add to dashboard' })] }))] })] }), (0, jsx_runtime_1.jsx)("style", { children: `body{margin:0;}` }), (0, jsx_runtime_1.jsx)(ChartBuilder_1.ChartBuilderWithModal, { rows: rows, columns: fields, fields: fields, pivot: pivot, query: activeQuery, showTableFormatOptions: showChartBuilderTableFormatOptions, showDateFieldOptions: isAdminEnabled, showAccessControlOptions: isAdminEnabled, title: "Add to dashboard", isHorizontalView: true, isOpen: isChartBuilderOpen, setIsOpen: setIsChartBuilderOpen, onAddToDashboardComplete: onSubmitChartBuilder, 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 })] }));
|
|
2677
2962
|
}
|
|
2678
2963
|
exports.default = ReportBuilder;
|