@quillsql/react 2.11.23 → 2.11.25
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 +16 -0
- package/dist/cjs/Chart.d.ts.map +1 -1
- package/dist/cjs/Chart.js +34 -18
- package/dist/cjs/ChartBuilder.d.ts +55 -2
- package/dist/cjs/ChartBuilder.d.ts.map +1 -1
- package/dist/cjs/ChartBuilder.js +232 -212
- 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 +962 -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 +6 -2
- package/dist/cjs/components/Chart/LineChart.d.ts.map +1 -1
- package/dist/cjs/components/Chart/LineChart.js +35 -34
- 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 +442 -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 +16 -0
- package/dist/esm/Chart.d.ts.map +1 -1
- package/dist/esm/Chart.js +35 -19
- package/dist/esm/ChartBuilder.d.ts +55 -2
- package/dist/esm/ChartBuilder.d.ts.map +1 -1
- package/dist/esm/ChartBuilder.js +234 -214
- 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 +964 -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 +6 -2
- package/dist/esm/components/Chart/LineChart.d.ts.map +1 -1
- package/dist/esm/components/Chart/LineChart.js +35 -34
- 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 +443 -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
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
/* eslint-disable no-unused-vars */
|
|
3
3
|
import { useContext, useEffect, useRef, useState, } from 'react';
|
|
4
|
-
import { DEFAULT_TAB_OPTIONS, MemoizedButton, MemoizedCheckbox, MemoizedDeleteButton, MemoizedHeader, MemoizedLabel, MemoizedSecondaryButton, MemoizedText, MemoizedPopover, QuillTableComponent, QuillTabs, MemoizedModal, } from './components/UiComponents';
|
|
4
|
+
import { DEFAULT_TAB_OPTIONS, MemoizedButton, MemoizedCheckbox, MemoizedDeleteButton, MemoizedHeader, MemoizedLabel, MemoizedSecondaryButton, MemoizedText, MemoizedPopover, QuillTableComponent, QuillTabs, MemoizedModal, QuillChartBuilderInputRowContainer, QuillChartBuilderInputColumnContainer, MemoizedSubHeader, QuillErrorMessageComponent, QuillPivotRowContainer, QuillPivotColumnContainer, QuillColumnSearchEmptyState, QuillChartBuilderFormContainer, } from './components/UiComponents';
|
|
5
5
|
import { DndContext, closestCenter, KeyboardSensor, PointerSensor, useSensor, useSensors, } from '@dnd-kit/core';
|
|
6
6
|
import { arrayMove, SortableContext, sortableKeyboardCoordinates, verticalListSortingStrategy, useSortable, } from '@dnd-kit/sortable';
|
|
7
7
|
import { CSS as DND_CSS } from '@dnd-kit/utilities';
|
|
8
8
|
import { getQuarter } from 'date-fns';
|
|
9
9
|
import { ClientContext, ThemeContext } from './Context';
|
|
10
|
-
import { getTableAliases, getTableNames, isDateishColumnType, isNumericColumnType, isTextColumnType, } from './components/ReportBuilder/ast';
|
|
10
|
+
import { getTableAliases, getTableNames, isBoolColumnType, isDateishColumnType, isNumericColumnType, isTextColumnType, } from './components/ReportBuilder/ast';
|
|
11
11
|
import { ChartBuilderWithModal } from './ChartBuilder';
|
|
12
12
|
import { QuillTextInput } from './components/UiComponents';
|
|
13
13
|
import { QuillSidebar, CustomContainer, QuillSelectColumn, QuillDraggableColumn, QuillSidebarHeading, QuillFilterPopover, QuillSortPopover, TagWrapper, EditPopover, AddFilterPopover, QuillLimitPopover, } from './components/ReportBuilder/ui';
|
|
@@ -16,8 +16,8 @@ import { convertBigQuery, convertGroupBy, convertRemoveSimpleParentheses, conver
|
|
|
16
16
|
import { deepCopy, formatDateComparisonNode, getDateFilterInfo, getPostgresBasicType, isColumnComparison, isDateTruncEquals, isInTheLastInterval, isNodeEmptyCollection, isTheCurrentInterval, isThePreviousInterval, isTopLevelBoolean, showNodeAsRow, tryConvertDateEquality, removeNonSelectedTableReferences, getCustomSentence, isEquals, } from './components/ReportBuilder/util';
|
|
17
17
|
import { getDefaultOperatorSubtrees, OPERATOR_GROUPS, } from './components/ReportBuilder/operators';
|
|
18
18
|
import { hashCode } from './utils/crypto';
|
|
19
|
-
import { DATE_FMT, DAY_OF_WEEK, defaultAST, defaultColumn, defaultEntry, defaultNumericComparison, defaultTable, defaultVariant, MONTH_OF_YEAR, } from './components/ReportBuilder/constants';
|
|
20
|
-
import
|
|
19
|
+
import { DATE_FMT, DAY_OF_WEEK, defaultAST, defaultBoolComparison, defaultColumn, defaultEntry, defaultNumericComparison, defaultTable, defaultVariant, MONTH_OF_YEAR, } from './components/ReportBuilder/constants';
|
|
20
|
+
import AddColumnModal from './components/ReportBuilder/AddColumnModal';
|
|
21
21
|
import { AddSortPopover, SortSentence, } from './components/ReportBuilder/AddSortPopover';
|
|
22
22
|
import { PivotModal, generatePivotTable, } from './internals/ReportBuilder/PivotModal';
|
|
23
23
|
import { PivotCard } from './internals/ReportBuilder/PivotList';
|
|
@@ -27,6 +27,12 @@ import { updateFirstChildWidth } from './utils/width';
|
|
|
27
27
|
import { QuillSelectComponent } from './components/QuillSelect';
|
|
28
28
|
import { QuillCard } from './components/QuillCard';
|
|
29
29
|
import { convertPostgresColumn } from './SQLEditor';
|
|
30
|
+
import { getData } from './utils/dataFetcher';
|
|
31
|
+
import { quillFormat } from './utils/valueFormatter';
|
|
32
|
+
import { getPossiblePivotFieldOptions } from './utils/pivotProcessing';
|
|
33
|
+
import { getUniqueValuesByColumns } from './utils/tableProcessing';
|
|
34
|
+
import { useQuill } from './hooks/useQuill';
|
|
35
|
+
export const QUILL_SERVER = process.env.QUILL_SERVER_HOST ?? 'https://quill-344421.uc.r.appspot.com';
|
|
30
36
|
/**
|
|
31
37
|
* Quill Report Builder
|
|
32
38
|
*
|
|
@@ -58,7 +64,8 @@ import { convertPostgresColumn } from './SQLEditor';
|
|
|
58
64
|
* ### Report Builder API
|
|
59
65
|
* @see https://docs.quillsql.com/components/report-builder
|
|
60
66
|
*/
|
|
61
|
-
export default function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = () => void null, destinationDashboard = undefined, organizationName = '', ButtonComponent = MemoizedButton, SecondaryButtonComponent = MemoizedSecondaryButton, DeleteButtonComponent = MemoizedDeleteButton, ModalComponent = MemoizedModal, TextInputComponent = QuillTextInput, SelectComponent = QuillSelectComponent, TableComponent = QuillTableComponent, PopoverComponent = MemoizedPopover, TabsComponent = QuillTabs, CheckboxComponent = MemoizedCheckbox, SidebarComponent = QuillSidebar, ContainerComponent = CustomContainer, SelectColumnComponent = QuillSelectColumn, DraggableColumnComponent = QuillDraggableColumn, SidebarHeadingComponent = QuillSidebarHeading, FilterPopoverComponent = QuillFilterPopover, SortPopoverComponent = QuillSortPopover, LimitPopoverComponent = QuillLimitPopover, CardComponent = QuillCard, LabelComponent = MemoizedLabel, HeaderComponent = MemoizedHeader, TextComponent = MemoizedText, isAdminEnabled = false, isAIEnabled = true, showChartBuilderTableFormatOptions = true, containerStyle, className, }) {
|
|
67
|
+
export default function ReportBuilder({ initialTableName = '', onSubmitChartBuilder = (_) => void null, destinationDashboard = undefined, organizationName = '', ButtonComponent = MemoizedButton, SecondaryButtonComponent = MemoizedSecondaryButton, DeleteButtonComponent = MemoizedDeleteButton, ModalComponent = MemoizedModal, TextInputComponent = QuillTextInput, SelectComponent = QuillSelectComponent, TableComponent = QuillTableComponent, PopoverComponent = MemoizedPopover, TabsComponent = QuillTabs, CheckboxComponent = MemoizedCheckbox, SidebarComponent = QuillSidebar, ContainerComponent = CustomContainer, SelectColumnComponent = QuillSelectColumn, DraggableColumnComponent = QuillDraggableColumn, SidebarHeadingComponent = QuillSidebarHeading, FilterPopoverComponent = QuillFilterPopover, SortPopoverComponent = QuillSortPopover, LimitPopoverComponent = QuillLimitPopover, CardComponent = QuillCard, LabelComponent = MemoizedLabel, HeaderComponent = MemoizedHeader, SubHeaderComponent = MemoizedSubHeader, TextComponent = MemoizedText, ErrorMessageComponent = QuillErrorMessageComponent, ChartBuilderInputRowContainer = QuillChartBuilderInputRowContainer, ChartBuilderInputColumnContainer = QuillChartBuilderInputColumnContainer, PivotRowContainer = QuillPivotRowContainer, PivotColumnContainer = QuillPivotColumnContainer, ColumnSearchEmptyState = QuillColumnSearchEmptyState, ChartBuilderFormContainer = QuillChartBuilderFormContainer, isAdminEnabled = false, isAIEnabled = true, showChartBuilderTableFormatOptions = true, containerStyle, className, pivotRecommendationsEnabled = true, initialChartId, }) {
|
|
68
|
+
const { data: initialData } = useQuill(initialChartId || '');
|
|
62
69
|
const [aiPrompt, setAiPrompt] = useState('');
|
|
63
70
|
const [errorMessage, setErrorMessage] = useState('');
|
|
64
71
|
const [baseAst, setBaseAst] = useState(null);
|
|
@@ -78,6 +85,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
78
85
|
const [isCopying, setIsCopying] = useState(false);
|
|
79
86
|
const [dataDisplayed, setDataDisplayed] = useState(false);
|
|
80
87
|
const [rows, setRows] = useState([]);
|
|
88
|
+
const [formattedRows, setFormattedRows] = useState([]);
|
|
81
89
|
const [fields, setFields] = useState([]);
|
|
82
90
|
const [topLevelBinaryOperator, setTopLevelBinaryOperator] = useState('AND');
|
|
83
91
|
const [editPopoverKey, setEditPopoverKey] = useState(null);
|
|
@@ -86,17 +94,17 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
86
94
|
const [pivotData, setPivotData] = useState(null);
|
|
87
95
|
const [createdPivots, setCreatedPivots] = useState([]);
|
|
88
96
|
const [recommendedPivots, setRecommendedPivots] = useState([]);
|
|
89
|
-
const [pivotPopUpTitle, setPivotPopUpTitle] = useState('Add
|
|
97
|
+
const [pivotPopUpTitle, setPivotPopUpTitle] = useState('Add pivot');
|
|
90
98
|
const [showPivotPopover, setShowPivotPopover] = useState(false);
|
|
91
99
|
const [isEdittingPivot, setIsEdittingPivot] = useState(false);
|
|
92
100
|
const [selectedPivotIndex, setSelectedPivotIndex] = useState(-1);
|
|
93
|
-
const [initialLoad, setInitialLoad] = useState(!!initialTableName);
|
|
101
|
+
const [initialLoad, setInitialLoad] = useState(!!initialTableName || !!initialChartId);
|
|
94
102
|
const [currentTable, setCurrentTable] = useState(initialTableName || '');
|
|
95
103
|
const parentRef = useRef(null);
|
|
96
104
|
const askAIContainerRef = useRef(null);
|
|
97
105
|
const askAILoadingContainerRef = useRef(null);
|
|
98
|
-
const [askAIInputWidth, setAskAIInputWidth] = useState(
|
|
99
|
-
const [askAILoadingContainerWidth, setAskAILoadingContainerWidth] = useState(
|
|
106
|
+
const [askAIInputWidth, setAskAIInputWidth] = useState(-1);
|
|
107
|
+
const [askAILoadingContainerWidth, setAskAILoadingContainerWidth] = useState(-1);
|
|
100
108
|
const [theme] = useContext(ThemeContext);
|
|
101
109
|
const [pivotRowField, setPivotRowField] = useState(undefined);
|
|
102
110
|
const [pivotColumnField, setPivotColumnField] = useState(undefined);
|
|
@@ -104,6 +112,17 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
104
112
|
const [pivotAggregation, setPivotAggregation] = useState(undefined);
|
|
105
113
|
// eslint-disable-next-line no-unused-vars
|
|
106
114
|
const [client, _setClient] = useContext(ClientContext);
|
|
115
|
+
// JANK: This is temp and stupid
|
|
116
|
+
const [overrideRecommendations, setOverrideRecommendations] = useState(true);
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
if (client.publicKey === '663416663aa9bc716e59a89d') {
|
|
119
|
+
setOverrideRecommendations(false);
|
|
120
|
+
}
|
|
121
|
+
}, [client.publicKey]);
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
updateFirstChildWidth(askAIContainerRef, setAskAIInputWidth, { gap: 12 });
|
|
124
|
+
updateFirstChildWidth(askAILoadingContainerRef, setAskAILoadingContainerWidth, { gap: 12 });
|
|
125
|
+
}, [dataDisplayed]);
|
|
107
126
|
useEffect(() => {
|
|
108
127
|
// Since the TextInput component takes a required numeric width parameter,
|
|
109
128
|
// we dynamically calculate the width of this component here.
|
|
@@ -116,7 +135,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
116
135
|
return () => {
|
|
117
136
|
window.removeEventListener('resize', handleResize);
|
|
118
137
|
};
|
|
119
|
-
}, [
|
|
138
|
+
}, []);
|
|
120
139
|
const enforceOrderOnColumns = (columnNames) => {
|
|
121
140
|
if (pivot) {
|
|
122
141
|
const rowName = pivot.rowField;
|
|
@@ -130,39 +149,6 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
130
149
|
return columnNames.sort((a, b) => selectedOrderedColumns.indexOf(a) - selectedOrderedColumns.indexOf(b));
|
|
131
150
|
// return columnNames;
|
|
132
151
|
};
|
|
133
|
-
/**
|
|
134
|
-
* Transforms an array of column names into an array of columnInfo objects
|
|
135
|
-
* with label, field, format, and fieldType keys.
|
|
136
|
-
*/
|
|
137
|
-
const processColumnsForPivotModal = (columns) => {
|
|
138
|
-
return columns.map((col) => ({
|
|
139
|
-
label: col,
|
|
140
|
-
name: col,
|
|
141
|
-
displayName: snakeCaseToTitleCase(col),
|
|
142
|
-
field: col,
|
|
143
|
-
format: getPostgresBasicType(fields.find((f) => f.name === col))?.replace('number', 'whole_number') || 'string',
|
|
144
|
-
fieldType: schemaTables
|
|
145
|
-
.flatMap((t) => t.columns)
|
|
146
|
-
.find((c) => c.name === col)?.fieldType || 'text',
|
|
147
|
-
}));
|
|
148
|
-
};
|
|
149
|
-
/**
|
|
150
|
-
* Transforms an array of column names into an array of columnInfo objects
|
|
151
|
-
* with label, field, format, and fieldType keys.
|
|
152
|
-
*/
|
|
153
|
-
const processColumnsForChartBuilder = (columns) => {
|
|
154
|
-
return columns.map((col) => ({
|
|
155
|
-
label: col,
|
|
156
|
-
name: col,
|
|
157
|
-
displayName: snakeCaseToTitleCase(col),
|
|
158
|
-
field: col,
|
|
159
|
-
format: convertPostgresColumn(fields.find((f) => f.name === col)).format ||
|
|
160
|
-
'string',
|
|
161
|
-
fieldType: schemaTables
|
|
162
|
-
.flatMap((t) => t.columns)
|
|
163
|
-
.find((c) => c.name === col)?.fieldType || 'text',
|
|
164
|
-
}));
|
|
165
|
-
};
|
|
166
152
|
const clearAllState = () => {
|
|
167
153
|
// We're trying to not block the main thread while resetting all the state.
|
|
168
154
|
// This shouldn't be an issue since the dispatches shouldn't block, but
|
|
@@ -186,6 +172,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
186
172
|
setTopLevelBinaryOperator('AND');
|
|
187
173
|
setEditPopoverKey(null);
|
|
188
174
|
setErrorMessage('');
|
|
175
|
+
setFormattedRows([]);
|
|
189
176
|
// setUniqueValues({});
|
|
190
177
|
setPivot(null);
|
|
191
178
|
setPivotData(null);
|
|
@@ -196,7 +183,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
196
183
|
if (!initialLoad && client.publicKey) {
|
|
197
184
|
clearAllState();
|
|
198
185
|
}
|
|
199
|
-
}, [client.publicKey]);
|
|
186
|
+
}, [client.publicKey, client.customerId]);
|
|
200
187
|
useEffect(() => {
|
|
201
188
|
if (activePath !== null) {
|
|
202
189
|
// update the modal with the new subtree
|
|
@@ -259,7 +246,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
259
246
|
setErrorMessage('');
|
|
260
247
|
try {
|
|
261
248
|
const where = formData ? formData : ast?.where || null;
|
|
262
|
-
const response = await fetch(
|
|
249
|
+
const response = await fetch(`${QUILL_SERVER}/sqlify`, {
|
|
263
250
|
method: 'POST',
|
|
264
251
|
headers: {
|
|
265
252
|
'Content-Type': 'application/json',
|
|
@@ -272,7 +259,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
272
259
|
const data = await response.json();
|
|
273
260
|
setActiveQuery(data.query);
|
|
274
261
|
if (fetchData) {
|
|
275
|
-
fetchUponChange(ast, formData);
|
|
262
|
+
fetchUponChange(ast, formData, data.query);
|
|
276
263
|
}
|
|
277
264
|
}
|
|
278
265
|
catch (error) {
|
|
@@ -300,43 +287,84 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
300
287
|
result.push(valueField, rowField);
|
|
301
288
|
return result.filter(Boolean);
|
|
302
289
|
};
|
|
303
|
-
const
|
|
290
|
+
const fetchDistinctStrings = async (query, table) => {
|
|
304
291
|
try {
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
292
|
+
const hostedBody = {
|
|
293
|
+
metadata: {
|
|
294
|
+
query,
|
|
295
|
+
task: 'query',
|
|
296
|
+
orgId: client.customerId || '*',
|
|
297
|
+
clientId: client.publicKey,
|
|
298
|
+
databaseType: client?.databaseType,
|
|
310
299
|
},
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
query: query,
|
|
315
|
-
}),
|
|
316
|
-
});
|
|
317
|
-
const data = await response.json();
|
|
300
|
+
};
|
|
301
|
+
const cloudBody = { query };
|
|
302
|
+
const data = await getData(client, 'dashquery', 'same-origin', hostedBody, cloudBody);
|
|
318
303
|
if (data.errorMessage) {
|
|
319
|
-
// console.error(data.errorMessage);
|
|
320
304
|
return null;
|
|
321
305
|
}
|
|
322
|
-
const
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
306
|
+
const results = data.rows.map((columnInfo) => {
|
|
307
|
+
const column = columnInfo.field;
|
|
308
|
+
if (!columnInfo.string_values) {
|
|
309
|
+
return { table, column, values: {} };
|
|
310
|
+
}
|
|
311
|
+
const values = columnInfo.string_values.reduce((result, value) => {
|
|
312
|
+
result[value] = false;
|
|
313
|
+
return result;
|
|
314
|
+
}, {});
|
|
315
|
+
return { table, column, values };
|
|
316
|
+
});
|
|
317
|
+
return results;
|
|
328
318
|
}
|
|
329
319
|
catch (e) {
|
|
330
320
|
console.error(e);
|
|
331
321
|
return null;
|
|
332
322
|
}
|
|
333
323
|
};
|
|
324
|
+
useEffect(() => {
|
|
325
|
+
const loadChart = async () => {
|
|
326
|
+
if (!initialData || initialData.referencedTables.length !== 1) {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
const initialRows = await handleAsk(initialData.queryString);
|
|
330
|
+
if (initialData.pivot) {
|
|
331
|
+
// @ts-ignore
|
|
332
|
+
setPivotRowField(initialData.pivot.rowField);
|
|
333
|
+
// @ts-ignore
|
|
334
|
+
setPivotAggregation(initialData.pivot.aggregationType);
|
|
335
|
+
// @ts-ignore
|
|
336
|
+
setPivotColumnField(initialData.pivot.columnField);
|
|
337
|
+
// @ts-ignore
|
|
338
|
+
setPivotValueField(initialData.pivot.valueField);
|
|
339
|
+
setPivot(initialData.pivot);
|
|
340
|
+
const pivotedData = generatePivotTable(
|
|
341
|
+
//@ts-ignore
|
|
342
|
+
initialData.pivot, initialRows, [null, null, null], false);
|
|
343
|
+
setPivotData(pivotedData || []);
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
if (initialData && initialData.referencedTables.length === 1) {
|
|
347
|
+
loadChart();
|
|
348
|
+
}
|
|
349
|
+
}, [initialData]);
|
|
334
350
|
useEffect(() => {
|
|
335
351
|
const loadTable = async (tables) => {
|
|
336
352
|
if (!tables)
|
|
337
353
|
return;
|
|
338
354
|
setLoading(true);
|
|
339
|
-
|
|
355
|
+
const tableInfo = schemaTables.find((tableInfo) => tableInfo.name === initialTableName);
|
|
356
|
+
if (tableInfo) {
|
|
357
|
+
const stringColumns = tableInfo.columns.filter((column) => {
|
|
358
|
+
return isTextColumnType(column.fieldType);
|
|
359
|
+
});
|
|
360
|
+
const stringNames = stringColumns.map((column) => column.name);
|
|
361
|
+
const newUniqueValues = await getUniqueValuesByColumns(stringColumns, `Select ${stringNames.join(', ')} from ${initialTableName}`, [], client);
|
|
362
|
+
const joinedUniqueValues = deepCopy(uniqueValues);
|
|
363
|
+
joinedUniqueValues[initialTableName] = newUniqueValues;
|
|
364
|
+
if (hashCode(uniqueValues) !== hashCode(joinedUniqueValues)) {
|
|
365
|
+
setUniqueValues(joinedUniqueValues);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
340
368
|
const columnsForTable = tables
|
|
341
369
|
.find((t) => t.name === initialTableName)
|
|
342
370
|
?.columns.map((c) => c.name)
|
|
@@ -397,7 +425,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
397
425
|
return -1;
|
|
398
426
|
return 0;
|
|
399
427
|
})));
|
|
400
|
-
if (initialTableName && initialLoad) {
|
|
428
|
+
if (initialTableName && initialLoad && !initialChartId) {
|
|
401
429
|
await loadTable(tables);
|
|
402
430
|
}
|
|
403
431
|
setLoadingSchema(false);
|
|
@@ -410,7 +438,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
410
438
|
if (schemaTables.length === 0) {
|
|
411
439
|
fetchSchema();
|
|
412
440
|
}
|
|
413
|
-
}, [schemaTables, initialTableName]);
|
|
441
|
+
}, [schemaTables, initialTableName, initialLoad]);
|
|
414
442
|
const updateFormData = (updates, { isDeletion = false, isInsertion = false, isReplaceSubtree = false, isAddVariant = false, isDeleteVariant = false, topLevelBinOp = 'OR', isCondition = undefined, }) => {
|
|
415
443
|
// Function to immutably update or delete nodes based on their path
|
|
416
444
|
// TODO: fix the following horible code
|
|
@@ -840,6 +868,11 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
840
868
|
newSubtree.left.column = event.target.value;
|
|
841
869
|
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
842
870
|
}
|
|
871
|
+
else if (isBoolColumnType(columnType)) {
|
|
872
|
+
const newSubtree = deepCopy(defaultBoolComparison);
|
|
873
|
+
newSubtree.left.column = event.target.value;
|
|
874
|
+
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
875
|
+
}
|
|
843
876
|
else {
|
|
844
877
|
const newSubtree = deepCopy(defaultEntry);
|
|
845
878
|
newSubtree.left.args.value[0].column = event.target.value;
|
|
@@ -899,7 +932,8 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
899
932
|
},
|
|
900
933
|
]));
|
|
901
934
|
} })), _jsx(SelectComponent, { value: intervalType, onChange: (event) => {
|
|
902
|
-
if (intervalPaths.length === 1
|
|
935
|
+
if (intervalPaths.length === 1 &&
|
|
936
|
+
dateFilterType !== 'in the previous') {
|
|
903
937
|
handleChangeText([
|
|
904
938
|
{
|
|
905
939
|
value: intervalCount !== null
|
|
@@ -911,7 +945,14 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
911
945
|
return;
|
|
912
946
|
}
|
|
913
947
|
let newSubtree;
|
|
914
|
-
if (dateFilterType === '
|
|
948
|
+
if (dateFilterType === 'in the previous') {
|
|
949
|
+
newSubtree = generatePreviousPeriodPostgres({
|
|
950
|
+
dateField: dateColumn,
|
|
951
|
+
intervalPeriod: `${intervalCount ?? 1} ${event.target.value}`,
|
|
952
|
+
currentPeriod: event.target.value,
|
|
953
|
+
});
|
|
954
|
+
}
|
|
955
|
+
else if (dateFilterType === 'equals') {
|
|
915
956
|
newSubtree = generateEqualsPostgres({
|
|
916
957
|
dateField: dateColumn,
|
|
917
958
|
currentPeriod: event.target.value,
|
|
@@ -925,14 +966,23 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
925
966
|
});
|
|
926
967
|
}
|
|
927
968
|
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
928
|
-
}, options:
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
969
|
+
}, options: dateFilterType === 'in the previous' ||
|
|
970
|
+
dateFilterType === 'in the last'
|
|
971
|
+
? [
|
|
972
|
+
{ label: `year${isPlural}`, value: 'year' },
|
|
973
|
+
{ label: `month${isPlural}`, value: 'month' },
|
|
974
|
+
{ label: `week${isPlural}`, value: 'week' },
|
|
975
|
+
{ label: `day${isPlural}`, value: 'day' },
|
|
976
|
+
{ label: `hour${isPlural}`, value: 'hour' },
|
|
977
|
+
]
|
|
978
|
+
: [
|
|
979
|
+
{ label: `year${isPlural}`, value: 'year' },
|
|
980
|
+
{ label: `quarter${isPlural}`, value: 'quarter' },
|
|
981
|
+
{ label: `month${isPlural}`, value: 'month' },
|
|
982
|
+
{ label: `week${isPlural}`, value: 'week' },
|
|
983
|
+
{ label: `day${isPlural}`, value: 'day' },
|
|
984
|
+
{ label: `hour${isPlural}`, value: 'hour' },
|
|
985
|
+
], width: 200 }), dateFilterType === 'equals' && (_jsx(TextInputComponent, { id: "date_filter_equals_raw_date", value: rawDateStringEquals, width: 120, onChange: (e) => {
|
|
936
986
|
handleChangeText([
|
|
937
987
|
{
|
|
938
988
|
value: e.target.value,
|
|
@@ -964,6 +1014,11 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
964
1014
|
newSubtree.left.column = event.target.value;
|
|
965
1015
|
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
966
1016
|
}
|
|
1017
|
+
else if (isBoolColumnType(columnType)) {
|
|
1018
|
+
const newSubtree = deepCopy(defaultBoolComparison);
|
|
1019
|
+
newSubtree.left.column = event.target.value;
|
|
1020
|
+
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
1021
|
+
}
|
|
967
1022
|
else {
|
|
968
1023
|
const newSubtree = deepCopy(defaultEntry);
|
|
969
1024
|
newSubtree.left.args.value[0].column = event.target.value;
|
|
@@ -978,7 +1033,6 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
978
1033
|
{ label: 'equals', value: 'EQUALS' },
|
|
979
1034
|
{ label: 'is not null', value: 'IS NOT' },
|
|
980
1035
|
{ label: 'is null', value: 'IS' },
|
|
981
|
-
// { label: 'equals', value: 'equals' },
|
|
982
1036
|
], width: 200 }), _jsx(TextInputComponent, { id: 'date_window_interval_count', value: node.right.args.value[1].expr.value, width: 120, onChange: (e) => {
|
|
983
1037
|
handleChange([
|
|
984
1038
|
{
|
|
@@ -1020,6 +1074,11 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1020
1074
|
newSubtree.left.column = event.target.value;
|
|
1021
1075
|
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
1022
1076
|
}
|
|
1077
|
+
else if (isBoolColumnType(columnType)) {
|
|
1078
|
+
const newSubtree = deepCopy(defaultBoolComparison);
|
|
1079
|
+
newSubtree.left.column = event.target.value;
|
|
1080
|
+
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
1081
|
+
}
|
|
1023
1082
|
else {
|
|
1024
1083
|
const newSubtree = deepCopy(defaultEntry);
|
|
1025
1084
|
newSubtree.left.args.value[0].column = event.target.value;
|
|
@@ -1074,6 +1133,11 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1074
1133
|
newSubtree.left.column = event.target.value;
|
|
1075
1134
|
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
1076
1135
|
}
|
|
1136
|
+
else if (isBoolColumnType(columnType)) {
|
|
1137
|
+
const newSubtree = deepCopy(defaultBoolComparison);
|
|
1138
|
+
newSubtree.left.column = event.target.value;
|
|
1139
|
+
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
1140
|
+
}
|
|
1077
1141
|
else {
|
|
1078
1142
|
const newSubtree = deepCopy(defaultEntry);
|
|
1079
1143
|
newSubtree.left.args.value[0].column = event.target.value;
|
|
@@ -1138,6 +1202,11 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1138
1202
|
newSubtree.left.column = event.target.value;
|
|
1139
1203
|
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
1140
1204
|
}
|
|
1205
|
+
else if (isBoolColumnType(columnType)) {
|
|
1206
|
+
const newSubtree = deepCopy(defaultBoolComparison);
|
|
1207
|
+
newSubtree.left.column = event.target.value;
|
|
1208
|
+
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
1209
|
+
}
|
|
1141
1210
|
else {
|
|
1142
1211
|
const newSubtree = deepCopy(defaultEntry);
|
|
1143
1212
|
newSubtree.left.args.value[0].column = event.target.value;
|
|
@@ -1222,8 +1291,6 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1222
1291
|
},
|
|
1223
1292
|
{ label: 'in the current', value: 'IN_THE_CURRENT' },
|
|
1224
1293
|
{ label: 'equals', value: 'equals' },
|
|
1225
|
-
{ label: 'is not null', value: 'IS NOT' },
|
|
1226
|
-
{ label: 'is null', value: 'IS' },
|
|
1227
1294
|
]
|
|
1228
1295
|
: []),
|
|
1229
1296
|
];
|
|
@@ -1250,6 +1317,11 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1250
1317
|
newSubtree.left.column = event.target.value;
|
|
1251
1318
|
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
1252
1319
|
}
|
|
1320
|
+
else if (isBoolColumnType(columnType)) {
|
|
1321
|
+
const newSubtree = deepCopy(defaultBoolComparison);
|
|
1322
|
+
newSubtree.left.column = event.target.value;
|
|
1323
|
+
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
1324
|
+
}
|
|
1253
1325
|
else {
|
|
1254
1326
|
const newSubtree = deepCopy(defaultEntry);
|
|
1255
1327
|
newSubtree.left.args.value[0].column = event.target.value;
|
|
@@ -1372,6 +1444,22 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1372
1444
|
},
|
|
1373
1445
|
]);
|
|
1374
1446
|
} }));
|
|
1447
|
+
case 'bool':
|
|
1448
|
+
return (_jsx(SelectComponent, { value: node.value.toString(), onChange: (event) => {
|
|
1449
|
+
let formatted = true;
|
|
1450
|
+
if (event.target.value === 'false') {
|
|
1451
|
+
formatted = false;
|
|
1452
|
+
}
|
|
1453
|
+
handleChange([
|
|
1454
|
+
{
|
|
1455
|
+
value: formatted,
|
|
1456
|
+
path: keyPrefix + 'value',
|
|
1457
|
+
},
|
|
1458
|
+
]);
|
|
1459
|
+
}, options: [
|
|
1460
|
+
{ label: 'is true', value: 'true' },
|
|
1461
|
+
{ label: 'is false', value: 'false' },
|
|
1462
|
+
], width: 200 }));
|
|
1375
1463
|
case 'function':
|
|
1376
1464
|
if (!node.args) {
|
|
1377
1465
|
return _jsx("label", {});
|
|
@@ -1435,7 +1523,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1435
1523
|
'NOT IN': 'is not',
|
|
1436
1524
|
'NOT LIKE': 'is not exactly',
|
|
1437
1525
|
'!=': 'is not exactly',
|
|
1438
|
-
'=': 'is
|
|
1526
|
+
'=': 'is',
|
|
1439
1527
|
'<': 'is less than',
|
|
1440
1528
|
'>': 'is greater than',
|
|
1441
1529
|
'<=': 'is less than or equal to',
|
|
@@ -1447,7 +1535,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1447
1535
|
};
|
|
1448
1536
|
switch (node.type) {
|
|
1449
1537
|
case 'binary_expr':
|
|
1450
|
-
return (_jsx(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: EditPopover, Button: ButtonComponent, renderNode: renderNode, children: dateComparisonPartialMatch ??
|
|
1538
|
+
return (_jsx(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: EditPopover, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent, renderNode: renderNode, children: dateComparisonPartialMatch ??
|
|
1451
1539
|
dateEqualityPartialMatch ??
|
|
1452
1540
|
uniqueSentence ?? (_jsxs(_Fragment, { children: [node.left &&
|
|
1453
1541
|
renderSentence(formData, node.left, keyPrefix + 'left.', false, false, isRow), isRow ? (' ' + OPS[node.operator] + ' ') : isTopLevel || topLevelBinaryOperator === 'OR' ? (_jsx(TopLevelBooleanSwitch, { node: node, keyPrefix: keyPrefix, handleOperatorChange: handleOperatorChange, Select: SelectComponent })) : null, node.right &&
|
|
@@ -1472,6 +1560,8 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1472
1560
|
return node.value;
|
|
1473
1561
|
case 'null':
|
|
1474
1562
|
return 'null';
|
|
1563
|
+
case 'bool':
|
|
1564
|
+
return node.value.toString();
|
|
1475
1565
|
case 'interval':
|
|
1476
1566
|
if (node.unit) {
|
|
1477
1567
|
// eg. `INTERVAL '90' DAY` -> "90 days"
|
|
@@ -1583,39 +1673,61 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1583
1673
|
justifyContent: 'end',
|
|
1584
1674
|
}, children: _jsx(ButtonComponent, { onClick: onSave, label: 'Add condition' }) })] }));
|
|
1585
1675
|
};
|
|
1586
|
-
const fetchUponChange = async (baseAst, newFormData) => {
|
|
1676
|
+
const fetchUponChange = async (baseAst, newFormData, query) => {
|
|
1587
1677
|
// if newFormData is null still use it
|
|
1588
1678
|
const curFormData = newFormData !== undefined ? newFormData : formData;
|
|
1589
1679
|
if ((curFormData || baseAst) && !loading) {
|
|
1590
1680
|
try {
|
|
1591
1681
|
setLoading(true);
|
|
1592
|
-
const
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
'Content-Type': 'application/json',
|
|
1596
|
-
},
|
|
1597
|
-
body: JSON.stringify({
|
|
1682
|
+
const hostedBody = {
|
|
1683
|
+
metadata: {
|
|
1684
|
+
clientId: client.publicKey,
|
|
1598
1685
|
ast: { ...baseAst, where: curFormData },
|
|
1599
1686
|
publicKey: client.publicKey,
|
|
1600
1687
|
orgId: client.customerId,
|
|
1601
|
-
|
|
1602
|
-
|
|
1688
|
+
task: 'patterns',
|
|
1689
|
+
},
|
|
1690
|
+
};
|
|
1691
|
+
const cloudBody = {};
|
|
1692
|
+
const data2 = await getData(client, 'dashquery', 'same-origin', hostedBody, cloudBody);
|
|
1603
1693
|
const tables = getTableNames(baseAst);
|
|
1604
1694
|
const table = tables.length >= 1 ? tables[0] : initialTableName;
|
|
1605
1695
|
if (table !== currentTable) {
|
|
1606
|
-
|
|
1696
|
+
const tableInfo = schemaTables.find((tableInfo) => tableInfo.name === table);
|
|
1697
|
+
if (tableInfo) {
|
|
1698
|
+
const stringColumns = tableInfo.columns.filter((column) => {
|
|
1699
|
+
return isTextColumnType(column.fieldType);
|
|
1700
|
+
});
|
|
1701
|
+
const stringNames = stringColumns.map((column) => column.name);
|
|
1702
|
+
const newUniqueValues = await getUniqueValuesByColumns(stringColumns, `Select ${stringNames.join(', ')} from ${table}`, rows, client);
|
|
1703
|
+
const joinedUniqueValues = deepCopy(uniqueValues);
|
|
1704
|
+
joinedUniqueValues[table] = newUniqueValues;
|
|
1705
|
+
if (hashCode(uniqueValues) !== hashCode(joinedUniqueValues)) {
|
|
1706
|
+
setUniqueValues(joinedUniqueValues);
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1607
1709
|
setCurrentTable(table);
|
|
1608
1710
|
}
|
|
1609
|
-
const data2 = await res2.json();
|
|
1610
1711
|
if (data2.rows && data2.rows.length) {
|
|
1611
|
-
const tables = getTableNames(baseAst);
|
|
1612
1712
|
if (pivot) {
|
|
1613
1713
|
// check if any of the pivot fields aren't in the data2.fields array
|
|
1614
1714
|
if (!isValidPivot(data2.fields)) {
|
|
1715
|
+
const processedFields = data2.fields.map((elem) => convertPostgresColumn(elem));
|
|
1615
1716
|
setPivot(null);
|
|
1616
1717
|
setPivotData(null);
|
|
1617
1718
|
setRows(data2.rows);
|
|
1618
|
-
setFields(
|
|
1719
|
+
setFields(processedFields);
|
|
1720
|
+
setFormattedRows(data2.rows.map((row) => {
|
|
1721
|
+
return processedFields.reduce((formattedRow, column) => {
|
|
1722
|
+
// Apply the format function to each field in the row
|
|
1723
|
+
const formattedValue = quillFormat({
|
|
1724
|
+
value: row[column.field],
|
|
1725
|
+
format: column.format,
|
|
1726
|
+
});
|
|
1727
|
+
formattedRow[column.field] = formattedValue;
|
|
1728
|
+
return formattedRow;
|
|
1729
|
+
}, {});
|
|
1730
|
+
}));
|
|
1619
1731
|
return;
|
|
1620
1732
|
}
|
|
1621
1733
|
// Do all of this to make sure we have the right unique columns when applying a pivot
|
|
@@ -1627,13 +1739,37 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1627
1739
|
uniqueFormatted[pivot.columnField] = uniqueRecords;
|
|
1628
1740
|
const pivotedData = generatePivotTable(pivot, data2.rows, [null, null, null], false);
|
|
1629
1741
|
console.info(`%c[Pivot]: ${JSON.stringify(pivot)}`, 'color: dimgray');
|
|
1742
|
+
const processedFields = data2.fields.map((elem) => convertPostgresColumn(elem));
|
|
1630
1743
|
setPivotData(pivotedData || []);
|
|
1631
1744
|
setRows(data2.rows);
|
|
1632
|
-
setFields(
|
|
1745
|
+
setFields(processedFields);
|
|
1746
|
+
setFormattedRows(data2.rows.map((row) => {
|
|
1747
|
+
return processedFields.reduce((formattedRow, column) => {
|
|
1748
|
+
// Apply the format function to each field in the row
|
|
1749
|
+
const formattedValue = quillFormat({
|
|
1750
|
+
value: row[column.field],
|
|
1751
|
+
format: column.format,
|
|
1752
|
+
});
|
|
1753
|
+
formattedRow[column.field] = formattedValue;
|
|
1754
|
+
return formattedRow;
|
|
1755
|
+
}, {});
|
|
1756
|
+
}));
|
|
1633
1757
|
}
|
|
1634
1758
|
else {
|
|
1759
|
+
const processedFields = data2.fields.map((elem) => convertPostgresColumn(elem));
|
|
1635
1760
|
setRows(data2.rows);
|
|
1636
|
-
setFields(
|
|
1761
|
+
setFields(processedFields);
|
|
1762
|
+
setFormattedRows(data2.rows.map((row) => {
|
|
1763
|
+
return processedFields.reduce((formattedRow, column) => {
|
|
1764
|
+
// Apply the format function to each field in the row
|
|
1765
|
+
const formattedValue = quillFormat({
|
|
1766
|
+
value: row[column.field],
|
|
1767
|
+
format: column.format,
|
|
1768
|
+
});
|
|
1769
|
+
formattedRow[column.field] = formattedValue;
|
|
1770
|
+
return formattedRow;
|
|
1771
|
+
}, {});
|
|
1772
|
+
}));
|
|
1637
1773
|
if (data2.errorMessage) {
|
|
1638
1774
|
setErrorMessage(`Error: ${data2.errorMessage}`);
|
|
1639
1775
|
}
|
|
@@ -1642,6 +1778,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1642
1778
|
else {
|
|
1643
1779
|
setRows([]);
|
|
1644
1780
|
setFields([]);
|
|
1781
|
+
setFormattedRows([]);
|
|
1645
1782
|
setPivotData(null);
|
|
1646
1783
|
}
|
|
1647
1784
|
}
|
|
@@ -1721,6 +1858,14 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1721
1858
|
return x ?? 0.0;
|
|
1722
1859
|
};
|
|
1723
1860
|
}
|
|
1861
|
+
else if (formatType === 'boolean') {
|
|
1862
|
+
columnFormatters[field.name] = (x) => {
|
|
1863
|
+
if (x) {
|
|
1864
|
+
return 'True';
|
|
1865
|
+
}
|
|
1866
|
+
return 'False';
|
|
1867
|
+
};
|
|
1868
|
+
}
|
|
1724
1869
|
else {
|
|
1725
1870
|
columnFormatters[field.name] = (x) => x;
|
|
1726
1871
|
}
|
|
@@ -1751,39 +1896,14 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1751
1896
|
}
|
|
1752
1897
|
return false;
|
|
1753
1898
|
};
|
|
1754
|
-
const getDistinctValues = async (table, overrideSchema) => {
|
|
1755
|
-
const schemaInfo = overrideSchema || schemaTables;
|
|
1756
|
-
const tableInfo = schemaInfo.find((tableInfo) => tableInfo.name === table);
|
|
1757
|
-
if (tableInfo) {
|
|
1758
|
-
const pendingFetches = [];
|
|
1759
|
-
for (let column of tableInfo.columns) {
|
|
1760
|
-
if (!isTextColumnType(column.fieldType))
|
|
1761
|
-
continue;
|
|
1762
|
-
const fetchPromise = fetchDistinctHelper(column.name, tableInfo.displayName);
|
|
1763
|
-
pendingFetches.push(fetchPromise);
|
|
1764
|
-
}
|
|
1765
|
-
const newUniqueValues = {};
|
|
1766
|
-
const resolvedPromises = await Promise.all(pendingFetches);
|
|
1767
|
-
for (const resolvedData of resolvedPromises) {
|
|
1768
|
-
if (resolvedData) {
|
|
1769
|
-
const { table, column, values } = resolvedData;
|
|
1770
|
-
if (!newUniqueValues[table]) {
|
|
1771
|
-
newUniqueValues[table] = {};
|
|
1772
|
-
}
|
|
1773
|
-
newUniqueValues[table][column] = values;
|
|
1774
|
-
}
|
|
1775
|
-
}
|
|
1776
|
-
if (hashCode(uniqueValues) !== hashCode(newUniqueValues)) {
|
|
1777
|
-
setUniqueValues(newUniqueValues);
|
|
1778
|
-
}
|
|
1779
|
-
}
|
|
1780
|
-
};
|
|
1781
1899
|
const handleAsk = async (overridePrompt = '') => {
|
|
1782
1900
|
if (!aiPrompt && !overridePrompt) {
|
|
1783
1901
|
return;
|
|
1784
1902
|
}
|
|
1785
1903
|
try {
|
|
1904
|
+
let errored = false;
|
|
1786
1905
|
setLoading(true);
|
|
1906
|
+
setErrorMessage('');
|
|
1787
1907
|
let res, data, ast;
|
|
1788
1908
|
let numRetries = 0;
|
|
1789
1909
|
const MAX_RETRIES = 3;
|
|
@@ -1794,7 +1914,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1794
1914
|
if (numRetries === MAX_RETRIES)
|
|
1795
1915
|
break;
|
|
1796
1916
|
if (!activeQuery || (ast && (isTableJoin || isSubquery(ast?.where)))) {
|
|
1797
|
-
res = await fetch(
|
|
1917
|
+
res = await fetch(`${QUILL_SERVER}/magic`, {
|
|
1798
1918
|
method: 'POST',
|
|
1799
1919
|
headers: { 'Content-Type': 'application/json' },
|
|
1800
1920
|
body: JSON.stringify({
|
|
@@ -1804,7 +1924,7 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1804
1924
|
});
|
|
1805
1925
|
}
|
|
1806
1926
|
else {
|
|
1807
|
-
res = await fetch(
|
|
1927
|
+
res = await fetch(`${QUILL_SERVER}/magic/edit`, {
|
|
1808
1928
|
method: 'POST',
|
|
1809
1929
|
headers: { 'Content-Type': 'application/json' },
|
|
1810
1930
|
body: JSON.stringify({
|
|
@@ -1844,15 +1964,6 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1844
1964
|
const table = getTableNames(newAst)[0] ?? initialTableName;
|
|
1845
1965
|
const tableAlias = getTableAliases(newAst)[0] ?? initialTableName;
|
|
1846
1966
|
newAst = removeNonSelectedTableReferences(newAst, tableAlias ?? table, getAllPossibleColumns().map((col) => col.name));
|
|
1847
|
-
// newAst = convertDateComparison(newAst); // TODO
|
|
1848
|
-
if (table !== currentTable) {
|
|
1849
|
-
await getDistinctValues(table);
|
|
1850
|
-
setCurrentTable(table);
|
|
1851
|
-
}
|
|
1852
|
-
setPivotRowField(groupByPivot?.rowField);
|
|
1853
|
-
setPivotColumnField(groupByPivot?.columnField);
|
|
1854
|
-
setPivotValueField(groupByPivot?.valueField);
|
|
1855
|
-
setPivotAggregation(groupByPivot?.aggregationType);
|
|
1856
1967
|
setSelectedColumns(deepCopy(newAst).columns?.map((column) => {
|
|
1857
1968
|
if (column.expr.type === 'column_ref') {
|
|
1858
1969
|
return `${table}.${column.expr.column}`;
|
|
@@ -1875,21 +1986,78 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1875
1986
|
newAst?.where ? newAst?.where?.operator : 'AND');
|
|
1876
1987
|
}
|
|
1877
1988
|
ast = newAst; // so we fetch data for newAst later.
|
|
1878
|
-
const
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
ast: ast,
|
|
1989
|
+
const table = getTableNames(newAst)[0] ?? initialTableName;
|
|
1990
|
+
const tableAlias = getTableAliases(newAst)[0] ?? initialTableName;
|
|
1991
|
+
const hostedBody = {
|
|
1992
|
+
metadata: {
|
|
1993
|
+
clientId: client.publicKey,
|
|
1994
|
+
ast,
|
|
1885
1995
|
publicKey: client.publicKey,
|
|
1886
1996
|
orgId: client.customerId,
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1997
|
+
task: 'patterns',
|
|
1998
|
+
},
|
|
1999
|
+
};
|
|
2000
|
+
const cloudBody = {};
|
|
2001
|
+
const data2 = await getData(client, 'patterns', 'same-origin', hostedBody, cloudBody);
|
|
2002
|
+
let currentUniqueValues = uniqueValues;
|
|
2003
|
+
if (table !== currentTable) {
|
|
2004
|
+
const tableInfo = schemaTables.find((tableInfo) => tableInfo.name === table);
|
|
2005
|
+
if (tableInfo) {
|
|
2006
|
+
const stringColumns = tableInfo.columns.filter((column) => {
|
|
2007
|
+
return isTextColumnType(column.fieldType);
|
|
2008
|
+
});
|
|
2009
|
+
const stringNames = stringColumns.map((column) => column.name);
|
|
2010
|
+
const newUniqueValues = await getUniqueValuesByColumns(stringColumns, `Select ${stringNames.join(', ')} from ${table}`, rows, client);
|
|
2011
|
+
currentUniqueValues[table] = newUniqueValues;
|
|
2012
|
+
if (hashCode(uniqueValues) !== hashCode(currentUniqueValues)) {
|
|
2013
|
+
setUniqueValues(currentUniqueValues);
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
setCurrentTable(table);
|
|
2017
|
+
}
|
|
1890
2018
|
if (data2.rows && data2.rows.length) {
|
|
1891
|
-
const
|
|
1892
|
-
|
|
2019
|
+
const processedFields = data2.fields.map((elem) => convertPostgresColumn(elem));
|
|
2020
|
+
let possiblePivot = true;
|
|
2021
|
+
const possibleColumns = getPossiblePivotFieldOptions(processedFields, currentUniqueValues[table]);
|
|
2022
|
+
if (groupByPivot &&
|
|
2023
|
+
((groupByPivot.columnField &&
|
|
2024
|
+
!possibleColumns.columnFields.includes(groupByPivot?.columnField)) ||
|
|
2025
|
+
(groupByPivot.rowField &&
|
|
2026
|
+
!possibleColumns.rowFields.includes(groupByPivot?.rowField)) ||
|
|
2027
|
+
(groupByPivot.valueField &&
|
|
2028
|
+
!possibleColumns.valueFields.includes(groupByPivot?.valueField || '')))) {
|
|
2029
|
+
possiblePivot = false;
|
|
2030
|
+
let errorMessageEnding = '';
|
|
2031
|
+
if (groupByPivot.columnField &&
|
|
2032
|
+
!possibleColumns.columnFields.includes(groupByPivot?.columnField || '')) {
|
|
2033
|
+
if (currentUniqueValues[table][groupByPivot?.columnField || '']) {
|
|
2034
|
+
errorMessageEnding = `The column ${groupByPivot?.columnField} has more than 24 unique values to pivot on.`;
|
|
2035
|
+
}
|
|
2036
|
+
else {
|
|
2037
|
+
errorMessageEnding = `The column ${groupByPivot?.columnField} is not a proper column field.`;
|
|
2038
|
+
}
|
|
2039
|
+
}
|
|
2040
|
+
else if (groupByPivot.rowField &&
|
|
2041
|
+
!possibleColumns.rowFields.includes(groupByPivot?.rowField || '')) {
|
|
2042
|
+
if (currentUniqueValues[table][groupByPivot?.rowField || '']) {
|
|
2043
|
+
errorMessageEnding = `The column ${groupByPivot?.rowField} has more than 36 unique values to pivot on.`;
|
|
2044
|
+
}
|
|
2045
|
+
else {
|
|
2046
|
+
errorMessageEnding = `The column ${groupByPivot?.rowField} is not a proper row field.`;
|
|
2047
|
+
}
|
|
2048
|
+
}
|
|
2049
|
+
else if (groupByPivot.valueField &&
|
|
2050
|
+
!possibleColumns.valueFields.includes(groupByPivot?.valueField || '')) {
|
|
2051
|
+
errorMessageEnding = `The column ${groupByPivot?.valueField} is not a proper value field.`;
|
|
2052
|
+
}
|
|
2053
|
+
setErrorMessage(`The requested pivot is not supported. ${errorMessageEnding}`);
|
|
2054
|
+
errored = true;
|
|
2055
|
+
}
|
|
2056
|
+
if (groupByPivot && possiblePivot) {
|
|
2057
|
+
setPivotRowField(groupByPivot?.rowField);
|
|
2058
|
+
setPivotColumnField(groupByPivot?.columnField);
|
|
2059
|
+
setPivotValueField(groupByPivot?.valueField);
|
|
2060
|
+
setPivotAggregation(groupByPivot?.aggregationType);
|
|
1893
2061
|
const pivotedData = generatePivotTable(
|
|
1894
2062
|
// @ts-ignore
|
|
1895
2063
|
groupByPivot, data2.rows, [null, null, null], false);
|
|
@@ -1897,17 +2065,42 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1897
2065
|
setPivotData(pivotedData);
|
|
1898
2066
|
setPivot(groupByPivot);
|
|
1899
2067
|
setRows(data2.rows);
|
|
1900
|
-
setFields(
|
|
2068
|
+
setFields(processedFields);
|
|
2069
|
+
setFormattedRows(data2.rows.map((row) => {
|
|
2070
|
+
return processedFields.reduce((formattedRow, column) => {
|
|
2071
|
+
// Apply the format function to each field in the row
|
|
2072
|
+
const formattedValue = quillFormat({
|
|
2073
|
+
value: row[column.field],
|
|
2074
|
+
format: column.format,
|
|
2075
|
+
});
|
|
2076
|
+
formattedRow[column.field] = formattedValue;
|
|
2077
|
+
return formattedRow;
|
|
2078
|
+
}, {});
|
|
2079
|
+
}));
|
|
1901
2080
|
}
|
|
1902
2081
|
else {
|
|
2082
|
+
const processedFields = data2.fields.map((elem) => convertPostgresColumn(elem));
|
|
1903
2083
|
setRows(data2.rows);
|
|
1904
|
-
setFields(
|
|
2084
|
+
setFields(processedFields);
|
|
2085
|
+
setFormattedRows(data2.rows.map((row) => {
|
|
2086
|
+
return processedFields.reduce((formattedRow, column) => {
|
|
2087
|
+
// Apply the format function to each field in the row
|
|
2088
|
+
const formattedValue = quillFormat({
|
|
2089
|
+
value: row[column.field],
|
|
2090
|
+
format: column.format,
|
|
2091
|
+
});
|
|
2092
|
+
formattedRow[column.field] = formattedValue;
|
|
2093
|
+
return formattedRow;
|
|
2094
|
+
}, {});
|
|
2095
|
+
}));
|
|
1905
2096
|
}
|
|
2097
|
+
return data2.rows;
|
|
1906
2098
|
}
|
|
1907
2099
|
else {
|
|
1908
2100
|
setPivotData([]);
|
|
1909
2101
|
setRows([]);
|
|
1910
2102
|
setFields([]);
|
|
2103
|
+
setFormattedRows([]);
|
|
1911
2104
|
}
|
|
1912
2105
|
if (data2.query) {
|
|
1913
2106
|
setActiveQuery(data2.query);
|
|
@@ -1918,9 +2111,6 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1918
2111
|
if (data2.errorMessage) {
|
|
1919
2112
|
setErrorMessage(`Error: ${data2.errorMessage}`);
|
|
1920
2113
|
}
|
|
1921
|
-
else {
|
|
1922
|
-
setErrorMessage('');
|
|
1923
|
-
}
|
|
1924
2114
|
}
|
|
1925
2115
|
catch (e) {
|
|
1926
2116
|
console.error(e);
|
|
@@ -1929,7 +2119,6 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
1929
2119
|
finally {
|
|
1930
2120
|
setLoading(false);
|
|
1931
2121
|
setDataDisplayed(true);
|
|
1932
|
-
setAiPrompt('');
|
|
1933
2122
|
}
|
|
1934
2123
|
};
|
|
1935
2124
|
const handleDeleteColumn = (name) => {
|
|
@@ -2040,273 +2229,295 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2040
2229
|
flexDirection: 'row',
|
|
2041
2230
|
height: '100%',
|
|
2042
2231
|
...containerStyle,
|
|
2043
|
-
}, className: className, ref: parentRef, children: [_jsxs(SidebarComponent, { children: [
|
|
2044
|
-
|
|
2045
|
-
return;
|
|
2046
|
-
if (!openPopover) {
|
|
2047
|
-
setOpenPopover('AddColumnPopover');
|
|
2048
|
-
}
|
|
2049
|
-
}, label: 'Select columns' }), _jsx(PopoverComponent, { isOpen: openPopover === 'AddColumnPopover', setIsOpen: (isOpen) => {
|
|
2050
|
-
if (!isOpen) {
|
|
2051
|
-
setIsPending(false);
|
|
2052
|
-
setActiveEditItem(null);
|
|
2053
|
-
setActivePath(null);
|
|
2054
|
-
setOpenPopover(null);
|
|
2055
|
-
}
|
|
2056
|
-
}, popoverTitle: "Select columns", popoverChildren: _jsx(AddColumnPopover, { onSave: () => {
|
|
2057
|
-
setActiveEditItem(null);
|
|
2058
|
-
setActivePath(null);
|
|
2059
|
-
setOpenPopover(null);
|
|
2060
|
-
}, orderedColumnNames: orderedColumnNames, setOrderedColumnNames: setOrderedColumnNames, selectedColumns: selectedColumns, setSelectedColumns: setSelectedColumns, isSelectedAllColumns: isSelectedAllColumns, clearAllState: clearAllState, nameToColumn: nameToColumn, baseAst: baseAst, setBaseAst: (newAst) => {
|
|
2061
|
-
setBaseAst(newAst);
|
|
2062
|
-
fetchSqlQuery(newAst);
|
|
2063
|
-
}, pivot: pivot, initialTableName: initialTableName, defaultAST: defaultAST, defaultTable: defaultTable, setPivot: setPivot, TextInput: TextInputComponent, SelectColumn: SelectColumnComponent, SecondaryButton: SecondaryButtonComponent, Button: ButtonComponent }) }), _jsx("div", { style: { height: 28, width: '100%' } }), _jsx(SidebarHeadingComponent, { label: "Filters" }), _jsx("div", { style: { height: 4, width: '100%' } }), formData && (_jsx("div", { style: {
|
|
2064
|
-
display: 'flex',
|
|
2065
|
-
flexDirection: 'column',
|
|
2066
|
-
gap: 8,
|
|
2067
|
-
marginBottom: 12,
|
|
2068
|
-
}, children: renderSentence(formData, formData, '', true) })), _jsxs("div", { style: {
|
|
2069
|
-
display: 'flex',
|
|
2070
|
-
flexDirection: 'column',
|
|
2071
|
-
gap: 2.5,
|
|
2072
|
-
alignItems: 'flex-start',
|
|
2073
|
-
}, children: [_jsx(SecondaryButtonComponent, { onClick: () => {
|
|
2074
|
-
if (!selectedColumns ||
|
|
2075
|
-
selectedColumns.length === 0 ||
|
|
2076
|
-
loading) {
|
|
2232
|
+
}, className: className, ref: parentRef, children: [_jsxs(SidebarComponent, { children: [_jsxs("div", { style: { width: '100%' }, children: [_jsx(SidebarHeadingComponent, { label: "Columns" }), _jsx(DraggableColumns, {}), _jsx(SecondaryButtonComponent, { onClick: () => {
|
|
2233
|
+
if (loadingSchema)
|
|
2077
2234
|
return;
|
|
2078
|
-
}
|
|
2079
2235
|
if (!openPopover) {
|
|
2080
|
-
|
|
2081
|
-
const [_table, column] = value.split('.');
|
|
2082
|
-
const columnType = getColumnTypeByName(column);
|
|
2083
|
-
if (isNumericColumnType(columnType)) {
|
|
2084
|
-
const newSubtree = deepCopy(defaultNumericComparison);
|
|
2085
|
-
newSubtree.left.column = column;
|
|
2086
|
-
setActiveEditItem(newSubtree);
|
|
2087
|
-
}
|
|
2088
|
-
else {
|
|
2089
|
-
const newSubtree = deepCopy(defaultEntry);
|
|
2090
|
-
newSubtree.left.args.value[0].column = column;
|
|
2091
|
-
setActiveEditItem(newSubtree);
|
|
2092
|
-
}
|
|
2093
|
-
setOpenPopover('AddFilterPopover');
|
|
2094
|
-
setActivePath('');
|
|
2095
|
-
setIsPending(true);
|
|
2236
|
+
setOpenPopover('AddColumnModal');
|
|
2096
2237
|
}
|
|
2097
|
-
}, label: '
|
|
2238
|
+
}, label: 'Select columns' }), _jsx(PopoverComponent, { isOpen: openPopover === 'AddColumnModal', setIsOpen: (isOpen) => {
|
|
2098
2239
|
if (!isOpen) {
|
|
2099
2240
|
setIsPending(false);
|
|
2241
|
+
setActiveEditItem(null);
|
|
2100
2242
|
setActivePath(null);
|
|
2101
2243
|
setOpenPopover(null);
|
|
2102
|
-
clearCheckboxes();
|
|
2103
|
-
setTimeout(() => {
|
|
2104
|
-
setActiveEditItem(null);
|
|
2105
|
-
}, 300);
|
|
2106
2244
|
}
|
|
2107
|
-
}, popoverTitle:
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
_jsxs(_Fragment, { children: [_jsx(SecondaryButtonComponent, { onClick: () => {
|
|
2245
|
+
}, popoverTitle: "Select columns", popoverChildren: _jsx(AddColumnModal, { onSave: () => {
|
|
2246
|
+
setActiveEditItem(null);
|
|
2247
|
+
setActivePath(null);
|
|
2248
|
+
setOpenPopover(null);
|
|
2249
|
+
}, orderedColumnNames: orderedColumnNames, setOrderedColumnNames: setOrderedColumnNames, selectedColumns: selectedColumns, setSelectedColumns: setSelectedColumns, isSelectedAllColumns: isSelectedAllColumns, clearAllState: clearAllState, nameToColumn: nameToColumn, baseAst: baseAst, setBaseAst: (newAst) => {
|
|
2250
|
+
setBaseAst(newAst);
|
|
2251
|
+
fetchSqlQuery(newAst);
|
|
2252
|
+
}, pivot: pivot, initialTableName: initialTableName, defaultAST: defaultAST, defaultTable: defaultTable, setPivot: setPivot, TextInput: TextInputComponent, SelectColumn: SelectColumnComponent, SecondaryButton: SecondaryButtonComponent, Button: ButtonComponent, ColumnSearchEmptyState: ColumnSearchEmptyState }) })] }), _jsxs("div", { style: { width: '100%' }, children: [_jsx(SidebarHeadingComponent, { label: "Filters" }), formData && (_jsx("div", { style: {
|
|
2253
|
+
display: 'flex',
|
|
2254
|
+
flexDirection: 'column',
|
|
2255
|
+
gap: 8,
|
|
2256
|
+
marginBottom: 12,
|
|
2257
|
+
}, children: renderSentence(formData, formData, '', true) })), _jsxs("div", { style: {
|
|
2258
|
+
display: 'flex',
|
|
2259
|
+
flexDirection: 'column',
|
|
2260
|
+
alignItems: 'flex-start',
|
|
2261
|
+
}, children: [_jsx(SecondaryButtonComponent, { onClick: () => {
|
|
2262
|
+
if (!selectedColumns ||
|
|
2263
|
+
selectedColumns.length === 0 ||
|
|
2264
|
+
loading) {
|
|
2265
|
+
return;
|
|
2266
|
+
}
|
|
2130
2267
|
if (!openPopover) {
|
|
2131
|
-
|
|
2132
|
-
|
|
2268
|
+
const value = orderedColumnNames[0];
|
|
2269
|
+
const [_table, column] = value.split('.');
|
|
2270
|
+
const columnType = getColumnTypeByName(column);
|
|
2271
|
+
if (isNumericColumnType(columnType)) {
|
|
2272
|
+
const newSubtree = deepCopy(defaultNumericComparison);
|
|
2273
|
+
newSubtree.left.column = column;
|
|
2274
|
+
setActiveEditItem(newSubtree);
|
|
2275
|
+
}
|
|
2276
|
+
else {
|
|
2277
|
+
const newSubtree = deepCopy(defaultEntry);
|
|
2278
|
+
newSubtree.left.args.value[0].column = column;
|
|
2279
|
+
setActiveEditItem(newSubtree);
|
|
2280
|
+
}
|
|
2281
|
+
setOpenPopover('AddFilterPopover');
|
|
2133
2282
|
setActivePath('');
|
|
2134
2283
|
setIsPending(true);
|
|
2135
2284
|
}
|
|
2136
|
-
}, label:
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
}, 300);
|
|
2142
|
-
setActivePath(null);
|
|
2143
|
-
setOpenPopover(null);
|
|
2144
|
-
clearCheckboxes();
|
|
2145
|
-
}
|
|
2146
|
-
}, popoverTitle: "Add condition", popoverChildren: _jsx(AddConditionPopover, { onSave: () => {
|
|
2147
|
-
if (isNodeEmptyCollection(activeEditItem)) {
|
|
2285
|
+
}, label: 'Add filter' }), _jsx("div", { style: {
|
|
2286
|
+
position: 'relative',
|
|
2287
|
+
...(openPopover === 'AddFilterPopover' && { top: 12 }),
|
|
2288
|
+
}, children: _jsx(PopoverComponent, { isOpen: openPopover === 'AddFilterPopover', setIsOpen: (isOpen) => {
|
|
2289
|
+
if (!isOpen) {
|
|
2148
2290
|
setIsPending(false);
|
|
2149
|
-
setTimeout(() => {
|
|
2150
|
-
setActiveEditItem(null);
|
|
2151
|
-
}, 300);
|
|
2152
2291
|
setActivePath(null);
|
|
2153
2292
|
setOpenPopover(null);
|
|
2154
|
-
clearCheckboxes();
|
|
2155
|
-
}
|
|
2156
|
-
else {
|
|
2157
|
-
setIsPending(false);
|
|
2158
|
-
handleInsertion(activeEditItem, topLevelBinaryOperator, true);
|
|
2159
2293
|
setTimeout(() => {
|
|
2294
|
+
clearCheckboxes();
|
|
2160
2295
|
setActiveEditItem(null);
|
|
2161
2296
|
}, 300);
|
|
2162
|
-
setActivePath(null);
|
|
2163
|
-
setOpenPopover(null);
|
|
2164
|
-
clearCheckboxes();
|
|
2165
2297
|
}
|
|
2166
|
-
}
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
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
|
-
|
|
2298
|
+
}, popoverTitle: 'Add filter', popoverChildren: _jsx(AddFilterPopover, { onSave: () => {
|
|
2299
|
+
if (isNodeEmptyCollection(activeEditItem)) {
|
|
2300
|
+
setIsPending(false);
|
|
2301
|
+
setActivePath(null);
|
|
2302
|
+
setOpenPopover(null);
|
|
2303
|
+
setTimeout(() => {
|
|
2304
|
+
clearCheckboxes();
|
|
2305
|
+
setActiveEditItem(null);
|
|
2306
|
+
}, 300);
|
|
2307
|
+
}
|
|
2308
|
+
else {
|
|
2309
|
+
setIsPending(false);
|
|
2310
|
+
handleInsertion(activeEditItem, 'AND', false);
|
|
2311
|
+
setActivePath(null);
|
|
2312
|
+
setOpenPopover(null);
|
|
2313
|
+
setTimeout(() => {
|
|
2314
|
+
clearCheckboxes();
|
|
2315
|
+
setActiveEditItem(null);
|
|
2316
|
+
}, 300);
|
|
2317
|
+
}
|
|
2318
|
+
}, Button: ButtonComponent, renderNode: renderNode, activeEditItem: activeEditItem }) }) }), baseAst?.where &&
|
|
2319
|
+
false && ( // temp removed the AddConditionPopover
|
|
2320
|
+
_jsxs(_Fragment, { children: [_jsx(SecondaryButtonComponent, { onClick: () => {
|
|
2321
|
+
if (!openPopover) {
|
|
2322
|
+
setActiveEditItem(deepCopy(defaultEntry));
|
|
2323
|
+
setOpenPopover('AddConditionPopover');
|
|
2324
|
+
setActivePath('');
|
|
2325
|
+
setIsPending(true);
|
|
2326
|
+
}
|
|
2327
|
+
}, label: "Add condition" }), _jsx(PopoverComponent, { isOpen: openPopover === 'AddConditionPopover', setIsOpen: (isOpen) => {
|
|
2328
|
+
if (!isOpen) {
|
|
2329
|
+
setIsPending(false);
|
|
2330
|
+
setTimeout(() => {
|
|
2331
|
+
clearCheckboxes();
|
|
2332
|
+
setActiveEditItem(null);
|
|
2333
|
+
}, 300);
|
|
2334
|
+
setActivePath(null);
|
|
2335
|
+
setOpenPopover(null);
|
|
2336
|
+
}
|
|
2337
|
+
}, popoverTitle: "Add condition", popoverChildren: _jsx(AddConditionPopover, { onSave: () => {
|
|
2338
|
+
if (isNodeEmptyCollection(activeEditItem)) {
|
|
2339
|
+
setIsPending(false);
|
|
2340
|
+
setTimeout(() => {
|
|
2341
|
+
setActiveEditItem(null);
|
|
2342
|
+
clearCheckboxes();
|
|
2343
|
+
}, 300);
|
|
2344
|
+
setActivePath(null);
|
|
2345
|
+
setOpenPopover(null);
|
|
2346
|
+
}
|
|
2347
|
+
else {
|
|
2348
|
+
setIsPending(false);
|
|
2349
|
+
handleInsertion(activeEditItem, topLevelBinaryOperator, true);
|
|
2350
|
+
setTimeout(() => {
|
|
2351
|
+
setActiveEditItem(null);
|
|
2352
|
+
clearCheckboxes();
|
|
2353
|
+
}, 300);
|
|
2354
|
+
setActivePath(null);
|
|
2355
|
+
setOpenPopover(null);
|
|
2356
|
+
}
|
|
2357
|
+
} }) })] }))] })] }), _jsxs("div", { style: { width: '100%' }, children: [_jsx(SidebarHeadingComponent, { label: "Pivot" }), _jsx(PivotModal, { pivotRowField: pivotRowField, setPivotRowField: setPivotRowField, pivotColumnField: pivotColumnField, setPivotColumnField: setPivotColumnField, pivotValueField: pivotValueField, setPivotValueField: setPivotValueField, pivotAggregation: pivotAggregation, setPivotAggregation: setPivotAggregation, createdPivots: createdPivots, setCreatedPivots: setCreatedPivots, recommendedPivots: recommendedPivots, setRecommendedPivots: setRecommendedPivots, popUpTitle: pivotPopUpTitle, setPopUpTitle: setPivotPopUpTitle, selectedTable: initialTableName, CardComponent: CardComponent, SelectComponent: SelectComponent, ButtonComponent: ButtonComponent, PopoverComponent: PopoverComponent, TextComponent: TextComponent, ErrorMessageComponent: ErrorMessageComponent, PivotRowContainer: PivotRowContainer, PivotColumnContainer: PivotColumnContainer, isOpen: showPivotPopover, setIsOpen: setShowPivotPopover, showUpdatePivot: isEdittingPivot, setShowUpdatePivot: setIsEdittingPivot, parentRef: parentRef, data: rows, columns: fields, triggerButtonText: 'Add pivot', selectedPivotIndex: selectedPivotIndex, setSelectedPivotIndex: setSelectedPivotIndex, removePivot: () => {
|
|
2358
|
+
setPivot(null);
|
|
2359
|
+
setPivotData(null);
|
|
2360
|
+
},
|
|
2361
|
+
// TODOs
|
|
2362
|
+
selectPivot: (pivot) => {
|
|
2363
|
+
if (!pivot)
|
|
2364
|
+
return;
|
|
2365
|
+
const newAst = { ...baseAst };
|
|
2366
|
+
newAst.orderby = null;
|
|
2367
|
+
setBaseAst(newAst); // trigger refetch
|
|
2368
|
+
setPivot(pivot);
|
|
2369
|
+
const pivotedData = generatePivotTable(pivot, rows, [null, null, null], false);
|
|
2370
|
+
setPivotData(pivotedData || []);
|
|
2371
|
+
}, 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 && (_jsx(PivotCard, { pivotTable: {
|
|
2372
|
+
pivot: pivot,
|
|
2373
|
+
rows: pivotData?.rows || [],
|
|
2374
|
+
columns: pivotData?.columns || [],
|
|
2375
|
+
}, theme: theme, index: 0, onSelectPivot: () => {
|
|
2376
|
+
setIsEdittingPivot(true);
|
|
2377
|
+
setShowPivotPopover(true);
|
|
2378
|
+
setPivotRowField(pivot?.rowField);
|
|
2379
|
+
setPivotColumnField(pivot?.columnField);
|
|
2380
|
+
setPivotValueField(pivot?.valueField);
|
|
2381
|
+
setPivotAggregation(pivot?.aggregationType);
|
|
2382
|
+
setPivotPopUpTitle('Edit pivot');
|
|
2383
|
+
}, selectedPivotIndex: -1, onEditPivot: () => { }, CardComponent: CardComponent, ButtonComponent: ButtonComponent, HeaderComponent: HeaderComponent, showEdit: false, onClose: () => {
|
|
2384
|
+
setPivot(null);
|
|
2385
|
+
setPivotData(null);
|
|
2386
|
+
setBaseAst(deepCopy(baseAst)); // trigger refetch
|
|
2387
|
+
}, minHeight: 180, LabelComponent: LabelComponent, TextComponent: TextComponent }))] }), _jsxs("div", { style: { width: '100%' }, children: [_jsx(SidebarHeadingComponent, { label: "Sort" }), pivot && pivot.sort && (_jsx("div", { style: {
|
|
2388
|
+
display: 'flex',
|
|
2389
|
+
flexDirection: 'column',
|
|
2390
|
+
gap: 8,
|
|
2391
|
+
marginBottom: 12,
|
|
2392
|
+
}, children: _jsx(SortSentence, { sortData: {
|
|
2393
|
+
type: pivot.sortDirection,
|
|
2394
|
+
expr: { type: 'column_ref', column: pivot.sortField },
|
|
2395
|
+
}, columns: selectedColumns, setIsPending: setIsPending, setEditPopoverKey: setEditPopoverKey, setActiveEditItem: setActiveEditItem, setActivePath: setActivePath, setOpenPopover: setOpenPopover, SortPopover: SortPopoverComponent, EditPopover: AddSortPopover, handleDelete: () => {
|
|
2396
|
+
setPivot({ ...pivot, sort: false });
|
|
2397
|
+
setBaseAst(deepCopy(baseAst));
|
|
2398
|
+
if (!pivot) {
|
|
2399
|
+
fetchSqlQuery(baseAst);
|
|
2400
|
+
}
|
|
2401
|
+
}, onSave: (column, direction) => {
|
|
2402
|
+
const sortFieldType = column === (pivot.valueField || 'count')
|
|
2403
|
+
? 'number'
|
|
2404
|
+
: pivot.rowFieldType;
|
|
2405
|
+
setPivot({
|
|
2406
|
+
...pivot,
|
|
2407
|
+
sort: true,
|
|
2408
|
+
sortDirection: direction,
|
|
2409
|
+
sortField: column,
|
|
2410
|
+
sortFieldType: sortFieldType,
|
|
2411
|
+
});
|
|
2412
|
+
setOpenPopover(null);
|
|
2413
|
+
setBaseAst(deepCopy(baseAst));
|
|
2414
|
+
if (!pivot) {
|
|
2415
|
+
fetchSqlQuery(baseAst);
|
|
2416
|
+
}
|
|
2417
|
+
}, Select: SelectComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent }, `sort-sentence-pivot`) })), baseAst && baseAst.orderby && (_jsx("div", { style: {
|
|
2418
|
+
display: 'flex',
|
|
2419
|
+
flexDirection: 'column',
|
|
2420
|
+
gap: 8,
|
|
2421
|
+
marginBottom: 12,
|
|
2422
|
+
}, children: baseAst.orderby.map((sortData, id) => (_jsx(SortSentence, { sortData: sortData, columns: selectedColumns, onSave: (column, direction) => {
|
|
2423
|
+
setIsPending(false);
|
|
2424
|
+
setActiveEditItem(null);
|
|
2425
|
+
setOpenPopover(null);
|
|
2426
|
+
if (column === '')
|
|
2427
|
+
return;
|
|
2428
|
+
const newAst = { ...baseAst };
|
|
2429
|
+
newAst.orderby[id] = {
|
|
2430
|
+
expr: {
|
|
2431
|
+
type: 'column_ref',
|
|
2432
|
+
table: null,
|
|
2433
|
+
column: column,
|
|
2434
|
+
},
|
|
2435
|
+
type: direction,
|
|
2436
|
+
};
|
|
2437
|
+
// look through the columns
|
|
2438
|
+
setActivePath(null);
|
|
2439
|
+
setOpenPopover(null);
|
|
2440
|
+
setBaseAst(deepCopy(newAst));
|
|
2441
|
+
if (!pivot) {
|
|
2442
|
+
fetchSqlQuery(newAst);
|
|
2443
|
+
}
|
|
2444
|
+
}, setIsPending: setIsPending, setEditPopoverKey: setEditPopoverKey, setActiveEditItem: setActiveEditItem, setActivePath: setActivePath, setOpenPopover: setOpenPopover, SortPopover: SortPopoverComponent, EditPopover: AddSortPopover, handleDelete: () => {
|
|
2445
|
+
const newAst = { ...baseAst };
|
|
2446
|
+
newAst.orderby.splice(id, 1);
|
|
2447
|
+
setBaseAst(deepCopy(newAst));
|
|
2448
|
+
if (!pivot) {
|
|
2449
|
+
fetchSqlQuery(newAst);
|
|
2450
|
+
}
|
|
2451
|
+
}, Select: SelectComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent }, `sort-sentence-${id}`))) })), _jsx(SecondaryButtonComponent, { onClick: () => {
|
|
2452
|
+
if (!selectedColumns ||
|
|
2453
|
+
selectedColumns.length === 0 ||
|
|
2454
|
+
loading) {
|
|
2455
|
+
return;
|
|
2456
|
+
}
|
|
2290
2457
|
if (!openPopover) {
|
|
2291
|
-
setOpenPopover('
|
|
2458
|
+
setOpenPopover('AddSortPopover');
|
|
2292
2459
|
}
|
|
2293
|
-
}, label:
|
|
2460
|
+
}, label: "Add sort" }), _jsx(PopoverComponent, { isOpen: openPopover === 'AddSortPopover', setIsOpen: (isOpen) => {
|
|
2294
2461
|
if (!isOpen) {
|
|
2295
2462
|
setIsPending(false);
|
|
2296
2463
|
setActiveEditItem(null);
|
|
2297
2464
|
setActivePath(null);
|
|
2298
2465
|
setOpenPopover(null);
|
|
2299
2466
|
}
|
|
2300
|
-
}, popoverTitle: "
|
|
2467
|
+
}, popoverTitle: "Sort by", popoverChildren: _jsx(AddSortPopover, { columns: selectedColumns, Select: SelectComponent, Button: ButtonComponent, onSave: () => { } }) })] }), _jsxs("div", { style: { width: '100%' }, children: [_jsx(SidebarHeadingComponent, { label: "Limit" }), baseAst && baseAst.limit ? (_jsx("div", { style: {
|
|
2468
|
+
display: 'flex',
|
|
2469
|
+
flexDirection: 'column',
|
|
2470
|
+
gap: 8,
|
|
2471
|
+
marginBottom: 12,
|
|
2472
|
+
}, children: _jsx(LimitSentence, { limit: baseAst.limit, setOpenPopover: setOpenPopover, LimitPopover: LimitPopoverComponent, EditPopover: AddLimitPopover, handleDelete: () => {
|
|
2473
|
+
const newAst = { ...baseAst };
|
|
2474
|
+
newAst.limit = null;
|
|
2475
|
+
setBaseAst(deepCopy(newAst));
|
|
2476
|
+
fetchSqlQuery(newAst);
|
|
2477
|
+
}, onSave: (limit) => {
|
|
2478
|
+
const newAst = { ...baseAst };
|
|
2479
|
+
newAst.limit = {
|
|
2480
|
+
seperator: '',
|
|
2481
|
+
value: [
|
|
2482
|
+
{
|
|
2483
|
+
type: 'number',
|
|
2484
|
+
value: limit,
|
|
2485
|
+
},
|
|
2486
|
+
],
|
|
2487
|
+
};
|
|
2488
|
+
setOpenPopover(null);
|
|
2489
|
+
setBaseAst(deepCopy(newAst));
|
|
2490
|
+
fetchSqlQuery(newAst);
|
|
2491
|
+
}, TextInput: TextInputComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent }) })) : (_jsxs(_Fragment, { children: [_jsx(SecondaryButtonComponent, { onClick: () => {
|
|
2492
|
+
if (!selectedColumns ||
|
|
2493
|
+
selectedColumns.length === 0 ||
|
|
2494
|
+
loading) {
|
|
2495
|
+
return;
|
|
2496
|
+
}
|
|
2497
|
+
if (!openPopover) {
|
|
2498
|
+
setOpenPopover('AddLimitPopover');
|
|
2499
|
+
}
|
|
2500
|
+
}, label: 'Add limit' }), _jsx(PopoverComponent, { isOpen: openPopover === 'AddLimitPopover', setIsOpen: (isOpen) => {
|
|
2501
|
+
if (!isOpen) {
|
|
2502
|
+
setIsPending(false);
|
|
2503
|
+
setActiveEditItem(null);
|
|
2504
|
+
setActivePath(null);
|
|
2505
|
+
setOpenPopover(null);
|
|
2506
|
+
}
|
|
2507
|
+
}, popoverTitle: "Add limit", popoverChildren: _jsx(AddLimitPopover, { TextInput: TextInputComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent, onSave: () => { } }) })] }))] })] }), _jsxs(ContainerComponent, { children: [isAIEnabled && (_jsx("form", { ref: askAILoadingContainerRef, onSubmit: (event) => {
|
|
2301
2508
|
event.preventDefault();
|
|
2302
2509
|
}, style: {
|
|
2303
2510
|
display: 'flex',
|
|
2304
2511
|
flexDirection: 'row',
|
|
2305
2512
|
gap: 12,
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2513
|
+
visibility: askAIInputWidth === -1 && askAILoadingContainerWidth === -1
|
|
2514
|
+
? 'hidden'
|
|
2515
|
+
: 'visible',
|
|
2516
|
+
}, children: _jsxs(_Fragment, { children: [_jsx(TextInputComponent, { id: "ask_ai_loading_bar", placeholder: baseAst || initialLoad
|
|
2517
|
+
? 'Ask a follow-up question...'
|
|
2518
|
+
: 'Ask a question...', width: askAIInputWidth !== -1
|
|
2519
|
+
? askAIInputWidth
|
|
2520
|
+
: askAILoadingContainerWidth, value: aiPrompt, onChange: () => { } }), _jsx(ButtonComponent, { onClick: () => { }, label: "Ask AI" }), ((baseAst && dataDisplayed) || initialLoad) && (_jsx(SecondaryButtonComponent, { onClick: () => { }, label: "New report" }))] }) })), _jsxs(_Fragment, { children: [_jsx(TableComponent, { isLoading: true, rows: [], columns: [] }), baseAst && dataDisplayed && (_jsxs("div", { style: {
|
|
2310
2521
|
display: 'flex',
|
|
2311
2522
|
flexDirection: 'row',
|
|
2312
2523
|
gap: '12px',
|
|
@@ -2319,341 +2530,405 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2319
2530
|
overflowY: 'auto',
|
|
2320
2531
|
boxSizing: 'border-box',
|
|
2321
2532
|
...containerStyle,
|
|
2322
|
-
}, className: className, children: [_jsxs(SidebarComponent, { children: [
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
return;
|
|
2327
|
-
}
|
|
2328
|
-
if (!openPopover) {
|
|
2329
|
-
setOpenPopover('AddColumnPopover');
|
|
2330
|
-
}
|
|
2331
|
-
}, label: "Select columns" }), _jsx(PopoverComponent, { isOpen: openPopover === 'AddColumnPopover', setIsOpen: (isOpen) => {
|
|
2332
|
-
if (!isOpen) {
|
|
2333
|
-
// delay onClose callback so onClick no-ops
|
|
2334
|
-
setTimeout(() => {
|
|
2335
|
-
setIsPending(false);
|
|
2336
|
-
setActiveEditItem(null);
|
|
2337
|
-
setActivePath(null);
|
|
2338
|
-
setOpenPopover(null);
|
|
2339
|
-
}, 100);
|
|
2340
|
-
}
|
|
2341
|
-
}, popoverTitle: "Select columns", popoverChildren: _jsx(AddColumnPopover, { onSave: () => {
|
|
2342
|
-
setActiveEditItem(null);
|
|
2343
|
-
setActivePath(null);
|
|
2344
|
-
setOpenPopover(null);
|
|
2345
|
-
}, orderedColumnNames: orderedColumnNames, setOrderedColumnNames: setOrderedColumnNames, selectedColumns: selectedColumns, setSelectedColumns: setSelectedColumns, isSelectedAllColumns: isSelectedAllColumns, clearAllState: clearAllState, nameToColumn: nameToColumn, baseAst: baseAst, setBaseAst: (ast) => {
|
|
2346
|
-
setBaseAst(ast);
|
|
2347
|
-
fetchSqlQuery(ast);
|
|
2348
|
-
}, pivot: pivot, initialTableName: initialTableName, defaultAST: defaultAST, defaultTable: defaultTable, setPivot: setPivot, TextInput: TextInputComponent, SelectColumn: SelectColumnComponent, SecondaryButton: SecondaryButtonComponent, Button: ButtonComponent }) }), _jsx("div", { style: { height: 28, width: '100%' } }), _jsx(SidebarHeadingComponent, { label: "Filters" }), _jsx("div", { style: { height: 4, width: '100%' } }), formData && (_jsx("div", { style: {
|
|
2349
|
-
display: 'flex',
|
|
2350
|
-
flexDirection: 'column',
|
|
2351
|
-
gap: 8,
|
|
2352
|
-
marginBottom: 12,
|
|
2353
|
-
}, children: renderSentence(formData, formData, '', true) })), _jsxs("div", { style: {
|
|
2354
|
-
display: 'flex',
|
|
2355
|
-
flexDirection: 'column',
|
|
2356
|
-
gap: 2.5,
|
|
2357
|
-
alignItems: 'flex-start',
|
|
2358
|
-
}, children: [_jsx(SecondaryButtonComponent, { onClick: () => {
|
|
2359
|
-
if (!selectedColumns || selectedColumns.length === 0 || loading) {
|
|
2533
|
+
}, className: className, children: [_jsxs(SidebarComponent, { children: [_jsxs("div", { style: { width: '100%' }, children: [_jsx(SidebarHeadingComponent, { label: "Columns" }), _jsx(DraggableColumns, {}), _jsx(SecondaryButtonComponent, { onClick: () => {
|
|
2534
|
+
if (loadingSchema)
|
|
2535
|
+
return;
|
|
2536
|
+
if (!orderedColumnNames) {
|
|
2360
2537
|
return;
|
|
2361
2538
|
}
|
|
2362
2539
|
if (!openPopover) {
|
|
2363
|
-
|
|
2364
|
-
const [_table, column] = value.split('.');
|
|
2365
|
-
const columnType = getColumnTypeByName(column);
|
|
2366
|
-
if (isNumericColumnType(columnType)) {
|
|
2367
|
-
const newSubtree = deepCopy(defaultNumericComparison);
|
|
2368
|
-
newSubtree.left.column = column;
|
|
2369
|
-
setActiveEditItem(newSubtree);
|
|
2370
|
-
}
|
|
2371
|
-
else {
|
|
2372
|
-
const newSubtree = deepCopy(defaultEntry);
|
|
2373
|
-
newSubtree.left.args.value[0].column = column;
|
|
2374
|
-
setActiveEditItem(newSubtree);
|
|
2375
|
-
}
|
|
2376
|
-
setOpenPopover('AddFilterPopover');
|
|
2377
|
-
setActivePath('');
|
|
2378
|
-
setIsPending(true);
|
|
2540
|
+
setOpenPopover('AddColumnModal');
|
|
2379
2541
|
}
|
|
2380
|
-
}, label:
|
|
2542
|
+
}, label: "Select columns" }), _jsx(ModalComponent, { isOpen: openPopover === 'AddColumnModal', setIsOpen: (isOpen) => {
|
|
2381
2543
|
if (!isOpen) {
|
|
2382
2544
|
// delay onClose callback so onClick no-ops
|
|
2383
2545
|
setTimeout(() => {
|
|
2384
2546
|
setIsPending(false);
|
|
2385
|
-
setActivePath(null);
|
|
2386
|
-
setOpenPopover(null);
|
|
2387
|
-
clearCheckboxes();
|
|
2388
2547
|
setActiveEditItem(null);
|
|
2389
|
-
}, 200);
|
|
2390
|
-
}
|
|
2391
|
-
}, popoverTitle: "Add filter", popoverChildren: _jsx(AddFilterPopover, { onSave: () => {
|
|
2392
|
-
if (isNodeEmptyCollection(activeEditItem)) {
|
|
2393
|
-
setIsPending(false);
|
|
2394
|
-
setActivePath(null);
|
|
2395
|
-
setOpenPopover(null);
|
|
2396
|
-
clearCheckboxes();
|
|
2397
|
-
setTimeout(() => {
|
|
2398
|
-
setActiveEditItem(null);
|
|
2399
|
-
}, 300);
|
|
2400
|
-
}
|
|
2401
|
-
else {
|
|
2402
|
-
setIsPending(false);
|
|
2403
|
-
handleInsertion(activeEditItem, 'AND', false);
|
|
2404
2548
|
setActivePath(null);
|
|
2405
2549
|
setOpenPopover(null);
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2550
|
+
}, 100);
|
|
2551
|
+
}
|
|
2552
|
+
}, title: "Select columns", children: _jsx(AddColumnModal, { onSave: () => {
|
|
2553
|
+
setActiveEditItem(null);
|
|
2554
|
+
setActivePath(null);
|
|
2555
|
+
setOpenPopover(null);
|
|
2556
|
+
}, orderedColumnNames: orderedColumnNames, setOrderedColumnNames: setOrderedColumnNames, selectedColumns: selectedColumns, setSelectedColumns: setSelectedColumns, isSelectedAllColumns: isSelectedAllColumns, clearAllState: clearAllState, nameToColumn: nameToColumn, baseAst: baseAst, setBaseAst: (ast) => {
|
|
2557
|
+
setBaseAst(ast);
|
|
2558
|
+
fetchSqlQuery(ast);
|
|
2559
|
+
}, pivot: pivot, initialTableName: initialTableName, defaultAST: defaultAST, defaultTable: defaultTable, setPivot: setPivot, TextInput: TextInputComponent, SelectColumn: SelectColumnComponent, SecondaryButton: SecondaryButtonComponent, Button: ButtonComponent, ColumnSearchEmptyState: ColumnSearchEmptyState }) })] }), _jsxs("div", { style: { width: '100%' }, children: [_jsx(SidebarHeadingComponent, { label: "Filters" }), formData && (_jsx("div", { style: {
|
|
2560
|
+
display: 'flex',
|
|
2561
|
+
flexDirection: 'column',
|
|
2562
|
+
gap: 8,
|
|
2563
|
+
marginBottom: 12,
|
|
2564
|
+
}, children: renderSentence(formData, formData, '', true) })), _jsxs("div", { style: {
|
|
2565
|
+
display: 'flex',
|
|
2566
|
+
flexDirection: 'column',
|
|
2567
|
+
alignItems: 'flex-start',
|
|
2568
|
+
}, children: [_jsx(SecondaryButtonComponent, { disabled: !baseAst || !dataDisplayed, onClick: () => {
|
|
2569
|
+
if (!selectedColumns ||
|
|
2570
|
+
selectedColumns.length === 0 ||
|
|
2571
|
+
loading) {
|
|
2572
|
+
return;
|
|
2573
|
+
}
|
|
2414
2574
|
if (!openPopover) {
|
|
2415
|
-
|
|
2416
|
-
|
|
2575
|
+
const value = orderedColumnNames[0];
|
|
2576
|
+
const [_table, column] = value.split('.');
|
|
2577
|
+
const columnType = getColumnTypeByName(column);
|
|
2578
|
+
if (isNumericColumnType(columnType)) {
|
|
2579
|
+
const newSubtree = deepCopy(defaultNumericComparison);
|
|
2580
|
+
newSubtree.left.column = column;
|
|
2581
|
+
setActiveEditItem(newSubtree);
|
|
2582
|
+
}
|
|
2583
|
+
else {
|
|
2584
|
+
const newSubtree = deepCopy(defaultEntry);
|
|
2585
|
+
newSubtree.left.args.value[0].column = column;
|
|
2586
|
+
setActiveEditItem(newSubtree);
|
|
2587
|
+
}
|
|
2588
|
+
setOpenPopover('AddFilterPopover');
|
|
2417
2589
|
setActivePath('');
|
|
2418
2590
|
setIsPending(true);
|
|
2419
2591
|
}
|
|
2420
|
-
}, label: 'Add
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
setActivePath(null);
|
|
2427
|
-
setOpenPopover(null);
|
|
2428
|
-
clearCheckboxes();
|
|
2429
|
-
}, 200);
|
|
2430
|
-
}
|
|
2431
|
-
}, popoverChildren: _jsx(AddConditionPopover, { onSave: () => {
|
|
2432
|
-
if (isNodeEmptyCollection(activeEditItem)) {
|
|
2433
|
-
setIsPending(false);
|
|
2434
|
-
setTimeout(() => {
|
|
2435
|
-
setActiveEditItem(null);
|
|
2436
|
-
}, 300);
|
|
2437
|
-
setActivePath(null);
|
|
2592
|
+
}, label: 'Add filter' }), _jsx("div", { style: {
|
|
2593
|
+
position: 'relative',
|
|
2594
|
+
...(openPopover === 'AddFilterPopover' && { top: 12 }),
|
|
2595
|
+
}, children: _jsx(PopoverComponent, { isOpen: openPopover === 'AddFilterPopover', setIsOpen: (isOpen) => {
|
|
2596
|
+
if (!isOpen) {
|
|
2597
|
+
// delay onClose callback so onClick no-ops
|
|
2438
2598
|
setOpenPopover(null);
|
|
2439
|
-
clearCheckboxes();
|
|
2440
|
-
}
|
|
2441
|
-
else {
|
|
2442
|
-
setIsPending(false);
|
|
2443
|
-
handleInsertion(activeEditItem, topLevelBinaryOperator, true);
|
|
2444
2599
|
setTimeout(() => {
|
|
2600
|
+
setIsPending(false);
|
|
2601
|
+
setActivePath(null);
|
|
2602
|
+
clearCheckboxes();
|
|
2445
2603
|
setActiveEditItem(null);
|
|
2446
2604
|
}, 300);
|
|
2447
|
-
setActivePath(null);
|
|
2448
|
-
setOpenPopover(null);
|
|
2449
|
-
clearCheckboxes();
|
|
2450
2605
|
}
|
|
2451
|
-
}
|
|
2452
|
-
|
|
2453
|
-
|
|
2454
|
-
|
|
2455
|
-
|
|
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
|
-
if (pivot) {
|
|
2517
|
-
setPivot({ ...pivot, sort: false });
|
|
2518
|
-
return;
|
|
2519
|
-
}
|
|
2520
|
-
const newAst = { ...baseAst };
|
|
2521
|
-
newAst.orderby.splice(id, 1);
|
|
2522
|
-
setBaseAst(deepCopy(newAst));
|
|
2523
|
-
fetchSqlQuery(deepCopy(newAst));
|
|
2524
|
-
}, onSave: (column, direction) => {
|
|
2525
|
-
if (pivot) {
|
|
2526
|
-
setPivot({
|
|
2527
|
-
...pivot,
|
|
2528
|
-
sort: true,
|
|
2529
|
-
sortDirection: direction,
|
|
2530
|
-
});
|
|
2531
|
-
return;
|
|
2532
|
-
}
|
|
2533
|
-
setIsPending(false);
|
|
2534
|
-
setActiveEditItem(null);
|
|
2535
|
-
setOpenPopover(null);
|
|
2536
|
-
if (column === '')
|
|
2537
|
-
return;
|
|
2538
|
-
const newAst = { ...baseAst };
|
|
2539
|
-
newAst.orderby[id] = {
|
|
2540
|
-
expr: {
|
|
2541
|
-
type: 'column_ref',
|
|
2542
|
-
table: null,
|
|
2543
|
-
column: column,
|
|
2544
|
-
},
|
|
2545
|
-
type: direction,
|
|
2546
|
-
};
|
|
2547
|
-
// look through the columns
|
|
2548
|
-
setActivePath(null);
|
|
2549
|
-
setOpenPopover(null);
|
|
2550
|
-
setBaseAst(deepCopy(newAst));
|
|
2551
|
-
fetchSqlQuery(deepCopy(newAst));
|
|
2552
|
-
}, Select: SelectComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent }, `sort-sentence-${id}`))) })), _jsx(SecondaryButtonComponent, { onClick: () => {
|
|
2553
|
-
if (!selectedColumns || selectedColumns.length === 0) {
|
|
2554
|
-
return;
|
|
2555
|
-
}
|
|
2556
|
-
if (!openPopover) {
|
|
2557
|
-
setOpenPopover('AddSortPopover');
|
|
2558
|
-
}
|
|
2559
|
-
}, label: 'Add sort' }), _jsx(PopoverComponent, { isOpen: openPopover === 'AddSortPopover', setIsOpen: (isOpen) => {
|
|
2560
|
-
if (!isOpen) {
|
|
2561
|
-
setIsPending(false);
|
|
2562
|
-
setActiveEditItem(null);
|
|
2563
|
-
setActivePath(null);
|
|
2564
|
-
setOpenPopover(null);
|
|
2565
|
-
}
|
|
2566
|
-
}, popoverTitle: "Sort by", popoverChildren: _jsx(AddSortPopover, { columns: pivot ? [`.${pivot.rowField}`] : selectedColumns, Select: SelectComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent, onSave: (column, direction) => {
|
|
2567
|
-
if (column === '')
|
|
2568
|
-
return;
|
|
2569
|
-
if (pivot) {
|
|
2570
|
-
setPivot({ ...pivot, sort: true, sortDirection: direction });
|
|
2571
|
-
const pivotedData = generatePivotTable({ ...pivot, sort: true, sortDirection: direction }, rows, [null, null, null], false);
|
|
2572
|
-
setPivotData(pivotedData || []);
|
|
2573
|
-
setActivePath(null);
|
|
2574
|
-
setOpenPopover(null);
|
|
2575
|
-
setBaseAst(deepCopy(baseAst));
|
|
2576
|
-
return;
|
|
2577
|
-
}
|
|
2578
|
-
const newAst = { ...baseAst };
|
|
2579
|
-
if (!newAst.orderby)
|
|
2580
|
-
newAst.orderby = [];
|
|
2581
|
-
newAst.orderby.push({
|
|
2582
|
-
expr: { type: 'column_ref', column },
|
|
2583
|
-
type: direction,
|
|
2584
|
-
});
|
|
2585
|
-
// look through the columns
|
|
2586
|
-
setActivePath(null);
|
|
2587
|
-
setOpenPopover(null);
|
|
2588
|
-
setBaseAst(deepCopy(newAst));
|
|
2589
|
-
fetchSqlQuery(deepCopy(newAst));
|
|
2590
|
-
} }) }), _jsx("div", { style: { height: 28, width: '100%' } }), _jsx(SidebarHeadingComponent, { label: "Limit" }), _jsx("div", { style: { height: 4, width: '100%' } }), baseAst && baseAst.limit ? (_jsx("div", { style: {
|
|
2591
|
-
display: 'flex',
|
|
2592
|
-
flexDirection: 'column',
|
|
2593
|
-
gap: 8,
|
|
2594
|
-
marginBottom: 12,
|
|
2595
|
-
}, children: _jsx(LimitSentence, { limit: baseAst.limit, setOpenPopover: setOpenPopover, LimitPopover: LimitPopoverComponent, EditPopover: AddLimitPopover, handleDelete: () => {
|
|
2596
|
-
const newAst = { ...baseAst };
|
|
2597
|
-
newAst.limit = null;
|
|
2598
|
-
setBaseAst(deepCopy(newAst));
|
|
2599
|
-
fetchSqlQuery(deepCopy(newAst));
|
|
2600
|
-
}, onSave: (limit) => {
|
|
2601
|
-
const newAst = { ...baseAst };
|
|
2602
|
-
newAst.limit = {
|
|
2603
|
-
seperator: '',
|
|
2604
|
-
value: [
|
|
2605
|
-
{
|
|
2606
|
-
type: 'number',
|
|
2607
|
-
value: limit,
|
|
2608
|
-
},
|
|
2609
|
-
],
|
|
2610
|
-
};
|
|
2611
|
-
setOpenPopover(null);
|
|
2612
|
-
setBaseAst(deepCopy(newAst));
|
|
2613
|
-
fetchSqlQuery(deepCopy(newAst));
|
|
2614
|
-
}, TextInput: TextInputComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent }) })) : (_jsxs(_Fragment, { children: [_jsx(SecondaryButtonComponent, { onClick: () => {
|
|
2615
|
-
if (!selectedColumns || selectedColumns.length === 0) {
|
|
2616
|
-
return;
|
|
2617
|
-
}
|
|
2618
|
-
if (!baseAst) {
|
|
2606
|
+
}, popoverTitle: "Add filter", popoverChildren: _jsx(AddFilterPopover, { onSave: () => {
|
|
2607
|
+
if (isNodeEmptyCollection(activeEditItem)) {
|
|
2608
|
+
setOpenPopover(null);
|
|
2609
|
+
clearCheckboxes();
|
|
2610
|
+
setIsPending(false);
|
|
2611
|
+
setTimeout(() => {
|
|
2612
|
+
setActivePath(null);
|
|
2613
|
+
setActiveEditItem(null);
|
|
2614
|
+
}, 300);
|
|
2615
|
+
}
|
|
2616
|
+
else {
|
|
2617
|
+
setOpenPopover(null);
|
|
2618
|
+
setIsPending(false);
|
|
2619
|
+
handleInsertion(activeEditItem, 'AND', false);
|
|
2620
|
+
setActivePath(null);
|
|
2621
|
+
setTimeout(() => {
|
|
2622
|
+
clearCheckboxes();
|
|
2623
|
+
setActiveEditItem(null);
|
|
2624
|
+
}, 300);
|
|
2625
|
+
}
|
|
2626
|
+
}, Button: ButtonComponent, renderNode: renderNode, activeEditItem: activeEditItem }) }) }), baseAst?.where &&
|
|
2627
|
+
false && ( // temp removed the AddConditionPopover
|
|
2628
|
+
_jsxs(_Fragment, { children: [_jsx(SecondaryButtonComponent, { onClick: () => {
|
|
2629
|
+
if (!openPopover) {
|
|
2630
|
+
setActiveEditItem(deepCopy(defaultEntry));
|
|
2631
|
+
setOpenPopover('AddConditionPopover');
|
|
2632
|
+
setActivePath('');
|
|
2633
|
+
setIsPending(true);
|
|
2634
|
+
}
|
|
2635
|
+
}, label: 'Add condition' }), _jsx(PopoverComponent, { isOpen: openPopover === 'AddConditionPopover', setIsOpen: (isOpen) => {
|
|
2636
|
+
if (!isOpen) {
|
|
2637
|
+
// delay onClose callback so onClick no-ops
|
|
2638
|
+
setTimeout(() => {
|
|
2639
|
+
setIsPending(false);
|
|
2640
|
+
setActiveEditItem(null);
|
|
2641
|
+
setActivePath(null);
|
|
2642
|
+
setOpenPopover(null);
|
|
2643
|
+
clearCheckboxes();
|
|
2644
|
+
}, 200);
|
|
2645
|
+
}
|
|
2646
|
+
}, popoverChildren: _jsx(AddConditionPopover, { onSave: () => {
|
|
2647
|
+
if (isNodeEmptyCollection(activeEditItem)) {
|
|
2648
|
+
setIsPending(false);
|
|
2649
|
+
setTimeout(() => {
|
|
2650
|
+
setActiveEditItem(null);
|
|
2651
|
+
}, 300);
|
|
2652
|
+
setActivePath(null);
|
|
2653
|
+
setOpenPopover(null);
|
|
2654
|
+
clearCheckboxes();
|
|
2655
|
+
}
|
|
2656
|
+
else {
|
|
2657
|
+
setIsPending(false);
|
|
2658
|
+
handleInsertion(activeEditItem, topLevelBinaryOperator, true);
|
|
2659
|
+
setTimeout(() => {
|
|
2660
|
+
setActiveEditItem(null);
|
|
2661
|
+
}, 300);
|
|
2662
|
+
setActivePath(null);
|
|
2663
|
+
setOpenPopover(null);
|
|
2664
|
+
clearCheckboxes();
|
|
2665
|
+
}
|
|
2666
|
+
} }) })] }))] })] }), _jsxs("div", { style: { width: '100%' }, children: [_jsx(SidebarHeadingComponent, { label: "Pivot" }), _jsx(PivotModal, { pivotRowField: pivotRowField, setPivotRowField: setPivotRowField, pivotColumnField: pivotColumnField, setPivotColumnField: setPivotColumnField, pivotValueField: pivotValueField, setPivotValueField: setPivotValueField, pivotAggregation: pivotAggregation, setPivotAggregation: setPivotAggregation, createdPivots: createdPivots, setCreatedPivots: setCreatedPivots, recommendedPivots: recommendedPivots, setRecommendedPivots: setRecommendedPivots, popUpTitle: pivotPopUpTitle, setPopUpTitle: setPivotPopUpTitle, selectedTable: initialTableName, SelectComponent: SelectComponent, ButtonComponent: ButtonComponent, CardComponent: CardComponent, SecondaryButtonComponent: SecondaryButtonComponent, PopoverComponent: PopoverComponent, TextComponent: TextComponent, ErrorMessageComponent: ErrorMessageComponent, PivotRowContainer: PivotRowContainer, PivotColumnContainer: PivotColumnContainer, isOpen: showPivotPopover, setIsOpen: setShowPivotPopover, showUpdatePivot: isEdittingPivot, setShowUpdatePivot: setIsEdittingPivot, parentRef: parentRef, data: rows, columns: fields, triggerButtonText: 'Add pivot', selectedPivotIndex: selectedPivotIndex, setSelectedPivotIndex: setSelectedPivotIndex, removePivot: () => {
|
|
2667
|
+
setPivot(null);
|
|
2668
|
+
setPivotData(null);
|
|
2669
|
+
}, selectPivot: (pivot) => {
|
|
2670
|
+
if (!pivot)
|
|
2619
2671
|
return;
|
|
2672
|
+
const newAst = { ...baseAst };
|
|
2673
|
+
newAst.orderby = null;
|
|
2674
|
+
if (pivot.rowFieldType === 'date') {
|
|
2675
|
+
pivot['sort'] = true;
|
|
2676
|
+
pivot['sortDirection'] = 'ASC';
|
|
2620
2677
|
}
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2678
|
+
setBaseAst(newAst); // trigger refetch
|
|
2679
|
+
setPivot(pivot);
|
|
2680
|
+
const pivotedData = generatePivotTable(pivot, rows, [null, null, null], false);
|
|
2681
|
+
setPivotData(pivotedData || []);
|
|
2682
|
+
setErrorMessage('');
|
|
2683
|
+
}, 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 && (_jsx(PivotCard, { pivotTable: {
|
|
2684
|
+
pivot: pivot,
|
|
2685
|
+
rows: pivotData?.rows || [],
|
|
2686
|
+
columns: pivotData?.columns || [],
|
|
2687
|
+
}, theme: theme, index: 0, onSelectPivot: () => {
|
|
2688
|
+
setIsEdittingPivot(true);
|
|
2689
|
+
setShowPivotPopover(true);
|
|
2690
|
+
setPivotRowField(pivot?.rowField);
|
|
2691
|
+
setPivotColumnField(pivot?.columnField);
|
|
2692
|
+
setPivotValueField(pivot?.valueField);
|
|
2693
|
+
setPivotAggregation(pivot?.aggregationType);
|
|
2694
|
+
setPivotPopUpTitle('Edit pivot');
|
|
2695
|
+
}, selectedPivotIndex: -1, onEditPivot: () => { }, ButtonComponent: ButtonComponent, HeaderComponent: HeaderComponent, CardComponent: CardComponent, showEdit: false, onClose: () => {
|
|
2696
|
+
setPivot(null);
|
|
2697
|
+
setPivotData(null);
|
|
2698
|
+
setBaseAst(deepCopy(baseAst));
|
|
2699
|
+
}, minHeight: 180, LabelComponent: LabelComponent, TextComponent: TextComponent }))] }), _jsxs("div", { style: { width: '100%' }, children: [_jsx(SidebarHeadingComponent, { label: "Sort" }), pivot && pivot.sort && (_jsx("div", { style: {
|
|
2700
|
+
display: 'flex',
|
|
2701
|
+
flexDirection: 'column',
|
|
2702
|
+
gap: 8,
|
|
2703
|
+
marginBottom: 12,
|
|
2704
|
+
}, children: _jsx(SortSentence, { sortData: {
|
|
2705
|
+
type: pivot.sortDirection,
|
|
2706
|
+
expr: { type: 'column_ref', column: pivot.sortField },
|
|
2707
|
+
}, columns: pivot
|
|
2708
|
+
? pivot.columnField
|
|
2709
|
+
? [`.${pivot.rowField}`]
|
|
2710
|
+
: [
|
|
2711
|
+
`.${pivot.rowField}`,
|
|
2712
|
+
`.${pivot.valueField || 'count'}`,
|
|
2713
|
+
]
|
|
2714
|
+
: selectedColumns, setIsPending: setIsPending, setEditPopoverKey: setEditPopoverKey, setActiveEditItem: setActiveEditItem, setActivePath: setActivePath, setOpenPopover: setOpenPopover, SortPopover: SortPopoverComponent, EditPopover: AddSortPopover, handleDelete: () => {
|
|
2715
|
+
if (pivot) {
|
|
2716
|
+
setPivot({ ...pivot, sort: false });
|
|
2717
|
+
const pivotedData = generatePivotTable({ ...pivot, sort: false }, rows, [null, null, null], false);
|
|
2718
|
+
setPivotData(pivotedData || []);
|
|
2719
|
+
setErrorMessage('');
|
|
2720
|
+
return;
|
|
2721
|
+
}
|
|
2722
|
+
setBaseAst(deepCopy(baseAst));
|
|
2723
|
+
fetchSqlQuery(deepCopy(baseAst));
|
|
2724
|
+
}, onSave: (column, direction) => {
|
|
2725
|
+
if (pivot) {
|
|
2726
|
+
const sortFieldType = column === (pivot.valueField || 'count')
|
|
2727
|
+
? 'number'
|
|
2728
|
+
: pivot.rowFieldType;
|
|
2729
|
+
setPivot({
|
|
2730
|
+
...pivot,
|
|
2731
|
+
sort: true,
|
|
2732
|
+
sortDirection: direction,
|
|
2733
|
+
sortField: column,
|
|
2734
|
+
sortFieldType: sortFieldType,
|
|
2735
|
+
});
|
|
2736
|
+
const pivotedData = generatePivotTable({
|
|
2737
|
+
...pivot,
|
|
2738
|
+
sort: true,
|
|
2739
|
+
sortDirection: direction,
|
|
2740
|
+
sortField: column,
|
|
2741
|
+
sortFieldType: sortFieldType,
|
|
2742
|
+
}, rows, [null, null, null], false);
|
|
2743
|
+
setPivotData(pivotedData || []);
|
|
2744
|
+
setErrorMessage('');
|
|
2745
|
+
return;
|
|
2746
|
+
}
|
|
2747
|
+
setOpenPopover(null);
|
|
2748
|
+
setBaseAst(deepCopy(baseAst));
|
|
2749
|
+
fetchSqlQuery(deepCopy(baseAst));
|
|
2750
|
+
}, Select: SelectComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent }, `sort-sentence-pivot`) })), baseAst && baseAst.orderby && (_jsx("div", { style: {
|
|
2751
|
+
display: 'flex',
|
|
2752
|
+
flexDirection: 'column',
|
|
2753
|
+
gap: 8,
|
|
2754
|
+
marginBottom: 12,
|
|
2755
|
+
}, children: baseAst.orderby.map((sortData, id) => (_jsx(SortSentence, { sortData: sortData, columns: selectedColumns, setIsPending: setIsPending, setEditPopoverKey: setEditPopoverKey, setActiveEditItem: setActiveEditItem, setActivePath: setActivePath, setOpenPopover: setOpenPopover, SortPopover: SortPopoverComponent, EditPopover: AddSortPopover, handleDelete: () => {
|
|
2756
|
+
if (pivot) {
|
|
2757
|
+
setPivot({ ...pivot, sort: false });
|
|
2758
|
+
return;
|
|
2759
|
+
}
|
|
2760
|
+
const newAst = { ...baseAst };
|
|
2761
|
+
newAst.orderby.splice(id, 1);
|
|
2762
|
+
setBaseAst(deepCopy(newAst));
|
|
2763
|
+
fetchSqlQuery(deepCopy(newAst));
|
|
2764
|
+
}, onSave: (column, direction) => {
|
|
2765
|
+
if (pivot) {
|
|
2766
|
+
const sortFieldType = column === (pivot.valueField || 'count')
|
|
2767
|
+
? 'number'
|
|
2768
|
+
: pivot.rowFieldType;
|
|
2769
|
+
setPivot({
|
|
2770
|
+
...pivot,
|
|
2771
|
+
sort: true,
|
|
2772
|
+
sortDirection: direction,
|
|
2773
|
+
sortField: column,
|
|
2774
|
+
sortFieldType: sortFieldType,
|
|
2775
|
+
});
|
|
2776
|
+
return;
|
|
2777
|
+
}
|
|
2626
2778
|
setIsPending(false);
|
|
2627
2779
|
setActiveEditItem(null);
|
|
2780
|
+
setOpenPopover(null);
|
|
2781
|
+
if (column === '')
|
|
2782
|
+
return;
|
|
2783
|
+
const newAst = { ...baseAst };
|
|
2784
|
+
newAst.orderby[id] = {
|
|
2785
|
+
expr: {
|
|
2786
|
+
type: 'column_ref',
|
|
2787
|
+
table: null,
|
|
2788
|
+
column: column,
|
|
2789
|
+
},
|
|
2790
|
+
type: direction,
|
|
2791
|
+
};
|
|
2792
|
+
// look through the columns
|
|
2628
2793
|
setActivePath(null);
|
|
2629
2794
|
setOpenPopover(null);
|
|
2795
|
+
setBaseAst(deepCopy(newAst));
|
|
2796
|
+
fetchSqlQuery(deepCopy(newAst));
|
|
2797
|
+
}, Select: SelectComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent }, `sort-sentence-${id}`))) })), _jsx(SecondaryButtonComponent, { disabled: !baseAst || !dataDisplayed, onClick: () => {
|
|
2798
|
+
if (!selectedColumns || selectedColumns.length === 0) {
|
|
2799
|
+
return;
|
|
2800
|
+
}
|
|
2801
|
+
if (!openPopover) {
|
|
2802
|
+
setOpenPopover('AddSortPopover');
|
|
2630
2803
|
}
|
|
2631
|
-
},
|
|
2804
|
+
}, label: 'Add sort' }), _jsx("div", { style: {
|
|
2805
|
+
position: 'relative',
|
|
2806
|
+
...(openPopover === 'AddSortPopover' && { top: 12 }),
|
|
2807
|
+
}, children: _jsx(PopoverComponent, { isOpen: openPopover === 'AddSortPopover', setIsOpen: (isOpen) => {
|
|
2808
|
+
if (!isOpen) {
|
|
2809
|
+
setIsPending(false);
|
|
2810
|
+
setActiveEditItem(null);
|
|
2811
|
+
setActivePath(null);
|
|
2812
|
+
setOpenPopover(null);
|
|
2813
|
+
}
|
|
2814
|
+
}, popoverTitle: "Sort by", popoverChildren: _jsx(AddSortPopover, { columns: pivot
|
|
2815
|
+
? pivot.columnField
|
|
2816
|
+
? [`.${pivot.rowField}`]
|
|
2817
|
+
: [
|
|
2818
|
+
`.${pivot.rowField}`,
|
|
2819
|
+
`.${pivot.valueField || 'count'}`,
|
|
2820
|
+
]
|
|
2821
|
+
: selectedColumns, Select: SelectComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent, onSave: (column, direction) => {
|
|
2822
|
+
if (column === '')
|
|
2823
|
+
return;
|
|
2824
|
+
if (pivot) {
|
|
2825
|
+
const sortFieldType = column === (pivot.valueField || 'count')
|
|
2826
|
+
? 'number'
|
|
2827
|
+
: pivot.rowFieldType;
|
|
2828
|
+
setPivot({
|
|
2829
|
+
...pivot,
|
|
2830
|
+
sort: true,
|
|
2831
|
+
sortDirection: direction,
|
|
2832
|
+
sortField: column,
|
|
2833
|
+
sortFieldType: sortFieldType,
|
|
2834
|
+
});
|
|
2835
|
+
const pivotedData = generatePivotTable({
|
|
2836
|
+
...pivot,
|
|
2837
|
+
sort: true,
|
|
2838
|
+
sortDirection: direction,
|
|
2839
|
+
sortField: column,
|
|
2840
|
+
sortFieldType: sortFieldType,
|
|
2841
|
+
}, rows, [null, null, null], false);
|
|
2842
|
+
setErrorMessage('');
|
|
2843
|
+
setPivotData(pivotedData || []);
|
|
2844
|
+
setActivePath(null);
|
|
2845
|
+
setOpenPopover(null);
|
|
2846
|
+
setBaseAst(deepCopy(baseAst));
|
|
2847
|
+
return;
|
|
2848
|
+
}
|
|
2849
|
+
const newAst = { ...baseAst };
|
|
2850
|
+
if (!newAst.orderby)
|
|
2851
|
+
newAst.orderby = [];
|
|
2852
|
+
newAst.orderby.push({
|
|
2853
|
+
expr: { type: 'column_ref', column },
|
|
2854
|
+
type: direction,
|
|
2855
|
+
});
|
|
2856
|
+
// look through the columns
|
|
2857
|
+
setActivePath(null);
|
|
2858
|
+
setOpenPopover(null);
|
|
2859
|
+
setBaseAst(deepCopy(newAst));
|
|
2860
|
+
fetchSqlQuery(deepCopy(newAst));
|
|
2861
|
+
} }) }) })] }), _jsxs("div", { style: { width: '100%' }, children: [_jsx(SidebarHeadingComponent, { label: "Limit" }), baseAst && baseAst.limit ? (_jsx("div", { style: {
|
|
2862
|
+
display: 'flex',
|
|
2863
|
+
flexDirection: 'column',
|
|
2864
|
+
gap: 8,
|
|
2865
|
+
marginBottom: 12,
|
|
2866
|
+
}, children: _jsx(LimitSentence, { limit: baseAst.limit, setOpenPopover: setOpenPopover, LimitPopover: LimitPopoverComponent, EditPopover: AddLimitPopover, handleDelete: () => {
|
|
2867
|
+
const newAst = { ...baseAst };
|
|
2868
|
+
newAst.limit = null;
|
|
2869
|
+
setBaseAst(deepCopy(newAst));
|
|
2870
|
+
fetchSqlQuery(deepCopy(newAst));
|
|
2871
|
+
}, onSave: (limit) => {
|
|
2632
2872
|
const newAst = { ...baseAst };
|
|
2633
2873
|
newAst.limit = {
|
|
2634
2874
|
seperator: '',
|
|
2635
2875
|
value: [
|
|
2636
2876
|
{
|
|
2637
2877
|
type: 'number',
|
|
2638
|
-
value:
|
|
2878
|
+
value: limit,
|
|
2639
2879
|
},
|
|
2640
2880
|
],
|
|
2641
2881
|
};
|
|
2642
2882
|
setOpenPopover(null);
|
|
2643
2883
|
setBaseAst(deepCopy(newAst));
|
|
2644
2884
|
fetchSqlQuery(deepCopy(newAst));
|
|
2645
|
-
}
|
|
2885
|
+
}, TextInput: TextInputComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent }) })) : (_jsxs(_Fragment, { children: [_jsx(SecondaryButtonComponent, { disabled: !baseAst || !dataDisplayed, onClick: () => {
|
|
2886
|
+
if (!selectedColumns || selectedColumns.length === 0) {
|
|
2887
|
+
return;
|
|
2888
|
+
}
|
|
2889
|
+
if (!baseAst) {
|
|
2890
|
+
return;
|
|
2891
|
+
}
|
|
2892
|
+
if (!openPopover) {
|
|
2893
|
+
setOpenPopover('AddLimitPopover');
|
|
2894
|
+
}
|
|
2895
|
+
}, label: 'Add limit' }), _jsx("div", { style: {
|
|
2896
|
+
position: 'relative',
|
|
2897
|
+
...(openPopover === 'AddLimitPopover' && { top: 12 }),
|
|
2898
|
+
}, children: _jsx(PopoverComponent, { isOpen: openPopover === 'AddLimitPopover', setIsOpen: (isOpen) => {
|
|
2899
|
+
if (!isOpen) {
|
|
2900
|
+
setIsPending(false);
|
|
2901
|
+
setActiveEditItem(null);
|
|
2902
|
+
setActivePath(null);
|
|
2903
|
+
setOpenPopover(null);
|
|
2904
|
+
}
|
|
2905
|
+
}, popoverTitle: "Add limit", popoverChildren: _jsx(AddLimitPopover, { TextInput: TextInputComponent, Button: ButtonComponent, SecondaryButton: SecondaryButtonComponent, onSave: (limit) => {
|
|
2906
|
+
const newAst = { ...baseAst };
|
|
2907
|
+
newAst.limit = {
|
|
2908
|
+
seperator: '',
|
|
2909
|
+
value: [
|
|
2910
|
+
{
|
|
2911
|
+
type: 'number',
|
|
2912
|
+
value: Number(limit),
|
|
2913
|
+
},
|
|
2914
|
+
],
|
|
2915
|
+
};
|
|
2916
|
+
setOpenPopover(null);
|
|
2917
|
+
setBaseAst(deepCopy(newAst));
|
|
2918
|
+
fetchSqlQuery(deepCopy(newAst));
|
|
2919
|
+
} }) }) })] }))] })] }), _jsxs(ContainerComponent, { children: [isAIEnabled && (_jsx("form", { ref: askAIContainerRef, onSubmit: (event) => {
|
|
2646
2920
|
event.preventDefault();
|
|
2647
2921
|
handleAsk();
|
|
2648
2922
|
}, style: {
|
|
2649
2923
|
display: 'flex',
|
|
2650
2924
|
flexDirection: 'row',
|
|
2651
2925
|
gap: 12,
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2926
|
+
visibility: askAIInputWidth === -1 && askAILoadingContainerWidth === -1
|
|
2927
|
+
? 'hidden'
|
|
2928
|
+
: 'visible',
|
|
2929
|
+
}, children: _jsxs(_Fragment, { children: [_jsx(TextInputComponent, { id: "ask_ai_input_bar", value: aiPrompt, width: askAIInputWidth !== -1
|
|
2930
|
+
? askAIInputWidth
|
|
2931
|
+
: askAILoadingContainerWidth, onChange: (e) => setAiPrompt(e.target.value), placeholder: baseAst ? 'Ask a follow-up question...' : 'Ask a question...' }), _jsx(ButtonComponent, { onClick: handleAsk, label: 'Ask AI' }), ((baseAst && dataDisplayed) || initialLoad) && (_jsx(SecondaryButtonComponent, { label: 'New report', onClick: clearAllState }))] }) })), baseAst && (_jsx(TableComponent, { isLoading: loading && errorMessage.length === 0, rows: pivotData?.rows || formattedRows, columns: pivot
|
|
2657
2932
|
? pivotData?.columns || emptyPivotColumns()
|
|
2658
2933
|
: enforceOrderOnColumns(Object.keys(rows[0] ?? {})).map((c) => {
|
|
2659
2934
|
return { label: snakeCaseToTitleCase(c), field: c };
|
|
@@ -2661,12 +2936,14 @@ export default function ReportBuilder({ initialTableName = '', onSubmitChartBuil
|
|
|
2661
2936
|
display: 'flex',
|
|
2662
2937
|
flexDirection: 'row',
|
|
2663
2938
|
gap: '12px',
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2939
|
+
width: '100%',
|
|
2940
|
+
}, children: [errorMessage ? (_jsxs("div", { style: {
|
|
2941
|
+
display: 'flex',
|
|
2942
|
+
flexDirection: 'row',
|
|
2943
|
+
overflow: 'hidden',
|
|
2944
|
+
width: '100%',
|
|
2945
|
+
gap: 12,
|
|
2946
|
+
}, children: [_jsx(ErrorMessageComponent, { errorMessage: errorMessage }), _jsx(SecondaryButtonComponent, { onClick: handleAsk, label: 'Retry' })] })) : (_jsx("div", { style: { width: '100%' } })), baseAst && dataDisplayed && (_jsxs(_Fragment, { children: [_jsx(SecondaryButtonComponent, { label: isCopying ? '✅ Copied' : 'Copy SQL', onClick: () => copyToClipboard(activeQuery) }), _jsx(ButtonComponent, { onClick: () => {
|
|
2670
2947
|
setIsChartBuilderOpen(true);
|
|
2671
|
-
}, label: 'Add to dashboard' })] }))] })] }), _jsx("style", { children: `body{margin:0;}` }), _jsx(ChartBuilderWithModal, { rows: rows, columns:
|
|
2948
|
+
}, label: 'Add to dashboard' })] }))] })] }), _jsx("style", { children: `body{margin:0;}` }), _jsx(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 })] }));
|
|
2672
2949
|
}
|