@quillsql/react 2.11.15 → 2.11.16
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/ChartBuilder.d.ts +7 -4
- package/dist/cjs/ChartBuilder.d.ts.map +1 -1
- package/dist/cjs/ChartBuilder.js +11 -10
- package/dist/cjs/Dashboard.d.ts +1 -0
- package/dist/cjs/Dashboard.d.ts.map +1 -1
- package/dist/cjs/Dashboard.js +3 -3
- package/dist/cjs/ReportBuilder.d.ts +18 -10
- package/dist/cjs/ReportBuilder.d.ts.map +1 -1
- package/dist/cjs/ReportBuilder.js +125 -72
- package/dist/cjs/SQLEditor.d.ts +1 -7
- package/dist/cjs/SQLEditor.d.ts.map +1 -1
- package/dist/cjs/SQLEditor.js +19 -4
- package/dist/cjs/components/ReportBuilder/AddColumnPopover.d.ts +24 -1
- package/dist/cjs/components/ReportBuilder/AddColumnPopover.d.ts.map +1 -1
- package/dist/cjs/components/ReportBuilder/AddColumnPopover.js +26 -9
- package/dist/cjs/components/ReportBuilder/AddLimitPopover.d.ts +13 -2
- package/dist/cjs/components/ReportBuilder/AddLimitPopover.d.ts.map +1 -1
- package/dist/cjs/components/ReportBuilder/AddLimitPopover.js +18 -8
- package/dist/cjs/components/ReportBuilder/AddSortPopover.d.ts +2 -2
- package/dist/cjs/components/ReportBuilder/AddSortPopover.d.ts.map +1 -1
- package/dist/cjs/components/ReportBuilder/AddSortPopover.js +7 -7
- package/dist/cjs/components/ReportBuilder/ui.d.ts +0 -1
- package/dist/cjs/components/ReportBuilder/ui.d.ts.map +1 -1
- package/dist/cjs/components/ReportBuilder/ui.js +17 -22
- package/dist/cjs/components/ReportBuilder/util.d.ts +1 -0
- package/dist/cjs/components/ReportBuilder/util.d.ts.map +1 -1
- package/dist/cjs/components/ReportBuilder/util.js +20 -1
- package/dist/cjs/components/UiComponents.d.ts +15 -14
- package/dist/cjs/components/UiComponents.d.ts.map +1 -1
- package/dist/cjs/components/UiComponents.js +14 -9
- package/dist/cjs/utils/width.d.ts +12 -0
- package/dist/cjs/utils/width.d.ts.map +1 -0
- package/dist/cjs/utils/width.js +25 -0
- package/dist/esm/ChartBuilder.d.ts +7 -4
- package/dist/esm/ChartBuilder.d.ts.map +1 -1
- package/dist/esm/ChartBuilder.js +11 -10
- package/dist/esm/Dashboard.d.ts +1 -0
- package/dist/esm/Dashboard.d.ts.map +1 -1
- package/dist/esm/Dashboard.js +3 -3
- package/dist/esm/ReportBuilder.d.ts +18 -10
- package/dist/esm/ReportBuilder.d.ts.map +1 -1
- package/dist/esm/ReportBuilder.js +127 -74
- package/dist/esm/SQLEditor.d.ts +1 -7
- package/dist/esm/SQLEditor.d.ts.map +1 -1
- package/dist/esm/SQLEditor.js +19 -4
- package/dist/esm/components/ReportBuilder/AddColumnPopover.d.ts +24 -1
- package/dist/esm/components/ReportBuilder/AddColumnPopover.d.ts.map +1 -1
- package/dist/esm/components/ReportBuilder/AddColumnPopover.js +27 -10
- package/dist/esm/components/ReportBuilder/AddLimitPopover.d.ts +13 -2
- package/dist/esm/components/ReportBuilder/AddLimitPopover.d.ts.map +1 -1
- package/dist/esm/components/ReportBuilder/AddLimitPopover.js +19 -9
- package/dist/esm/components/ReportBuilder/AddSortPopover.d.ts +2 -2
- package/dist/esm/components/ReportBuilder/AddSortPopover.d.ts.map +1 -1
- package/dist/esm/components/ReportBuilder/AddSortPopover.js +7 -7
- package/dist/esm/components/ReportBuilder/ui.d.ts +0 -1
- package/dist/esm/components/ReportBuilder/ui.d.ts.map +1 -1
- package/dist/esm/components/ReportBuilder/ui.js +17 -21
- package/dist/esm/components/ReportBuilder/util.d.ts +1 -0
- package/dist/esm/components/ReportBuilder/util.d.ts.map +1 -1
- package/dist/esm/components/ReportBuilder/util.js +18 -0
- package/dist/esm/components/UiComponents.d.ts +15 -14
- package/dist/esm/components/UiComponents.d.ts.map +1 -1
- package/dist/esm/components/UiComponents.js +14 -9
- package/dist/esm/utils/width.d.ts +12 -0
- package/dist/esm/utils/width.d.ts.map +1 -0
- package/dist/esm/utils/width.js +21 -0
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useContext, useEffect, useRef, useState, } from 'react';
|
|
3
|
-
import { MemoizedButton, MemoizedCheckbox, MemoizedHeader, MemoizedLabel, MemoizedPopover, MemoizedSecondaryButton, MemoizedText, } from './components/UiComponents';
|
|
3
|
+
import { MemoizedButton, MemoizedCheckbox, MemoizedDeleteButton, MemoizedHeader, MemoizedLabel, MemoizedPopover, MemoizedSecondaryButton, MemoizedText, } from './components/UiComponents';
|
|
4
4
|
import { DndContext, closestCenter, KeyboardSensor, PointerSensor, useSensor, useSensors, } from '@dnd-kit/core';
|
|
5
5
|
import { arrayMove, SortableContext, sortableKeyboardCoordinates, verticalListSortingStrategy, useSortable, } from '@dnd-kit/sortable';
|
|
6
6
|
import { CSS as DND_CSS } from '@dnd-kit/utilities';
|
|
@@ -8,7 +8,8 @@ import { getQuarter } from 'date-fns';
|
|
|
8
8
|
import { ClientContext, ThemeContext } from './Context';
|
|
9
9
|
import { getTableAliases, getTableNames, isDateishColumnType, isNumericColumnType, isTextColumnType, } from './components/ReportBuilder/ast';
|
|
10
10
|
import { ChartBuilderWithModal } from './ChartBuilder';
|
|
11
|
-
import {
|
|
11
|
+
import { QuillTextInput } from './components/UiComponents';
|
|
12
|
+
import { QuillPopover, QuillTabs, QuillSidebar, CustomContainer, QuillHandleButton, QuillSelectColumn, QuillDraggableColumn, QuillButtonLoadingState, QuillTableLoadingState, QuillSidebarHeading, QuillSidebarSubHeading, QuillFilterPopover, QuillSortPopover, DEFAULT_TAB_OPTIONS, TagWrapper, EditPopover, AddFilterPopover, } from './components/ReportBuilder/ui';
|
|
12
13
|
import { generateCurrentPeriodPostgres, generateEqualsPostgres, generateLastNPeriodsPostgres, generatePreviousPeriodPostgres, } from './components/ReportBuilder/postgres';
|
|
13
14
|
import { convertBigQuery, convertGroupBy, convertRemoveSimpleParentheses, convertStringComparison, convertWildcardColumns, } from './components/ReportBuilder/convert';
|
|
14
15
|
import { deepCopy, formatDateComparisonNode, getDateFilterInfo, getInTheCurrentIntervalSentence, getInTheLastIntervalSentence, getInThePreviousIntervalSentence, getPostgresBasicType, isColumnComparison, isDateTruncEquals, isInTheLastInterval, isNodeEmptyCollection, isTheCurrentInterval, isThePreviousInterval, isTopLevelBoolean, showNodeAsRow, tryConvertDateEquality, removeNonSelectedTableReferences, } from './components/ReportBuilder/util';
|
|
@@ -23,6 +24,7 @@ import QuillTable from './components/QuillTable';
|
|
|
23
24
|
import { QuillSelectComponent } from './components/QuillSelect';
|
|
24
25
|
import { snakeCaseToTitleCase } from './utils/textProcessing';
|
|
25
26
|
import { AddLimitPopover, LimitSentence, } from './components/ReportBuilder/AddLimitPopover';
|
|
27
|
+
import { updateFirstChildWidth } from './utils/width';
|
|
26
28
|
/**
|
|
27
29
|
* Quill Report Builder
|
|
28
30
|
*
|
|
@@ -31,7 +33,7 @@ import { AddLimitPopover, LimitSentence, } from './components/ReportBuilder/AddL
|
|
|
31
33
|
* they can click a button and add that report to their dashboard or export it
|
|
32
34
|
* as a CSV.
|
|
33
35
|
*/
|
|
34
|
-
export default function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () => void null, destinationDashboard = undefined, organizationName = '', Button = MemoizedButton, SecondaryButton = MemoizedSecondaryButton, TextInput = QuillTextInput, Select = QuillSelectComponent, Table = QuillTable, Popover = QuillPopover, Tabs = QuillTabs, Checkbox = MemoizedCheckbox, Sidebar = QuillSidebar, Container = CustomContainer, HandleButton = QuillHandleButton, SelectColumn = QuillSelectColumn, DraggableColumn = QuillDraggableColumn, ButtonLoadingState = QuillButtonLoadingState, TableLoadingState = QuillTableLoadingState, SidebarHeading = QuillSidebarHeading, SidebarSubHeading = QuillSidebarSubHeading, FilterPopover = QuillFilterPopover, SortPopover = QuillSortPopover, Label = MemoizedLabel, Header = MemoizedHeader, Text = MemoizedText, PivotPopover = MemoizedPopover, admin = false, hideAi = false, containerStyle, }) {
|
|
36
|
+
export default function ReportBuilder({ initialTableName = '', onAddToDashboardComplete = () => void null, destinationDashboard = undefined, organizationName = '', Button = MemoizedButton, SecondaryButton = MemoizedSecondaryButton, DeleteButton = MemoizedDeleteButton, TextInput = QuillTextInput, Select = QuillSelectComponent, Table = QuillTable, Popover = QuillPopover, Tabs = QuillTabs, Checkbox = MemoizedCheckbox, Sidebar = QuillSidebar, Container = CustomContainer, HandleButton = QuillHandleButton, SelectColumn = QuillSelectColumn, DraggableColumn = QuillDraggableColumn, ButtonLoadingState = QuillButtonLoadingState, TableLoadingState = QuillTableLoadingState, SidebarHeading = QuillSidebarHeading, SidebarSubHeading = QuillSidebarSubHeading, FilterPopover = QuillFilterPopover, SortPopover = QuillSortPopover, Label = MemoizedLabel, Header = MemoizedHeader, Text = MemoizedText, PivotPopover = MemoizedPopover, admin = false, hideAi = false, containerStyle, }) {
|
|
35
37
|
const [aiPrompt, setAiPrompt] = useState('');
|
|
36
38
|
const [errorMessage, setErrorMessage] = useState('');
|
|
37
39
|
const [baseAst, setBaseAst] = useState(null);
|
|
@@ -44,6 +46,7 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
44
46
|
const [activePath, setActivePath] = useState(null);
|
|
45
47
|
const [openPopover, setOpenPopover] = useState(null);
|
|
46
48
|
const [loading, setLoading] = useState(false);
|
|
49
|
+
const [loadingSchema, setLoadingSchema] = useState(false);
|
|
47
50
|
const [isChartBuilderOpen, setIsChartBuilderOpen] = useState(false);
|
|
48
51
|
const [isPending, setIsPending] = useState(false);
|
|
49
52
|
const [isCopying, setIsCopying] = useState(false);
|
|
@@ -63,6 +66,10 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
63
66
|
const [initialLoad, setInitialLoad] = useState(true);
|
|
64
67
|
const [currentTable, setCurrentTable] = useState(initialTableName || '');
|
|
65
68
|
const parentRef = useRef(null);
|
|
69
|
+
const askAIContainerRef = useRef(null);
|
|
70
|
+
const askAILoadingContainerRef = useRef(null);
|
|
71
|
+
const [askAIInputWidth, setAskAIInputWidth] = useState(200);
|
|
72
|
+
const [askAILoadingContainerWidth, setAskAILoadingContainerWidth] = useState(200);
|
|
66
73
|
const [theme] = useContext(ThemeContext);
|
|
67
74
|
const [pivotRowField, setPivotRowField] = useState(undefined);
|
|
68
75
|
const [pivotColumnField, setPivotColumnField] = useState(undefined);
|
|
@@ -70,6 +77,19 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
70
77
|
const [pivotAggregation, setPivotAggregation] = useState(undefined);
|
|
71
78
|
// eslint-disable-next-line no-unused-vars
|
|
72
79
|
const [client, _setClient] = useContext(ClientContext);
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
// Since the TextInput component takes a required numeric width parameter,
|
|
82
|
+
// we dynamically calculate the width of this component here.
|
|
83
|
+
function handleResize() {
|
|
84
|
+
updateFirstChildWidth(askAIContainerRef, setAskAIInputWidth, { gap: 12 });
|
|
85
|
+
updateFirstChildWidth(askAILoadingContainerRef, setAskAILoadingContainerWidth, { gap: 12 });
|
|
86
|
+
}
|
|
87
|
+
handleResize();
|
|
88
|
+
window.addEventListener('resize', handleResize);
|
|
89
|
+
return () => {
|
|
90
|
+
window.removeEventListener('resize', handleResize);
|
|
91
|
+
};
|
|
92
|
+
}, [baseAst, loading]);
|
|
73
93
|
const enforceOrderOnColumns = (columnNames) => {
|
|
74
94
|
if (pivot) {
|
|
75
95
|
const rowName = pivot.rowField;
|
|
@@ -257,6 +277,7 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
257
277
|
useEffect(() => {
|
|
258
278
|
const fetchSchema = async () => {
|
|
259
279
|
try {
|
|
280
|
+
setLoadingSchema(true);
|
|
260
281
|
const response = await fetch(`${client.queryEndpoint}`, {
|
|
261
282
|
method: 'POST',
|
|
262
283
|
headers: {
|
|
@@ -296,6 +317,7 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
296
317
|
?.columns.map((c) => c.name);
|
|
297
318
|
await handleAsk(`get ${columnsForTable} from ${initialTableName}`);
|
|
298
319
|
}
|
|
320
|
+
setLoadingSchema(false);
|
|
299
321
|
}
|
|
300
322
|
catch (error) {
|
|
301
323
|
console.error(error);
|
|
@@ -711,7 +733,7 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
711
733
|
// see onChange callback handleChange
|
|
712
734
|
// eslint-disable-next-line no-unused-vars
|
|
713
735
|
dateColumnPath, dateFilterType, intervalCount, intervalType, intervalPaths, } = getDateFilterInfo(node);
|
|
714
|
-
const isPlural = intervalCount
|
|
736
|
+
const isPlural = intervalCount !== 1 ? 's' : '';
|
|
715
737
|
// Pull off the string literal date for "equals" comparisons
|
|
716
738
|
const rawDateStringEquals = node.right?.value ??
|
|
717
739
|
node.right?.args?.value[1]?.column ??
|
|
@@ -778,11 +800,15 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
778
800
|
{ label: 'in the previous', value: 'in the previous' },
|
|
779
801
|
{ label: 'in the current', value: 'in the current' },
|
|
780
802
|
{ label: 'equals', value: 'equals' },
|
|
781
|
-
] }), !['in the current', 'equals'].includes(dateFilterType) && (_jsx(TextInput, {
|
|
782
|
-
|
|
803
|
+
] }), !['in the current', 'equals'].includes(dateFilterType) && (_jsx(TextInput, { id: "date_filter_interval_count", value: intervalCount, width: 70, onChange: (e) => {
|
|
804
|
+
if (Number.isNaN(parseFloat(e.target.value || '0'))) {
|
|
805
|
+
alert('Please input a number.');
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
const isPluralNow = parseFloat(e.target.value || '0') !== 1 ? 's' : '';
|
|
783
809
|
intervalPaths.forEach((intervalPath) => handleChangeText([
|
|
784
810
|
{
|
|
785
|
-
value: `${e.target.value} ${intervalType}${isPluralNow}`,
|
|
811
|
+
value: `${e.target.value || 0} ${intervalType}${isPluralNow}`,
|
|
786
812
|
path: keyPrefix + intervalPath,
|
|
787
813
|
},
|
|
788
814
|
]));
|
|
@@ -820,7 +846,7 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
820
846
|
{ label: `week${isPlural}`, value: 'week' },
|
|
821
847
|
{ label: `day${isPlural}`, value: 'day' },
|
|
822
848
|
{ label: `hour${isPlural}`, value: 'hour' },
|
|
823
|
-
] }), dateFilterType === 'equals' && (_jsx(TextInput, {
|
|
849
|
+
] }), dateFilterType === 'equals' && (_jsx(TextInput, { id: "date_filter_equals_raw_date", value: rawDateStringEquals, width: 120, onChange: (e) => {
|
|
824
850
|
handleChangeText([
|
|
825
851
|
{
|
|
826
852
|
value: e.target.value,
|
|
@@ -835,36 +861,38 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
835
861
|
label: snakeCaseToTitleCase(column.displayName),
|
|
836
862
|
value: column.name,
|
|
837
863
|
}));
|
|
838
|
-
const plural = node.right.args.value[1].expr.value
|
|
864
|
+
const plural = node.right.args.value[1].expr.value !== 1 ? 's' : '';
|
|
839
865
|
return (_jsxs("div", { style: {
|
|
840
866
|
display: 'flex',
|
|
841
867
|
flexDirection: 'row',
|
|
842
868
|
alignItems: 'center',
|
|
843
869
|
gap: 20,
|
|
844
|
-
}, children: [_jsx(
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
870
|
+
}, children: [_jsx(Select, { theme: theme, value: node.left.column, onChange: (value) => {
|
|
871
|
+
const columnType = getColumnTypeByName(value);
|
|
872
|
+
if (isDateishColumnType(columnType)) {
|
|
873
|
+
// handleChange(value, keyPrefix + dateColumnPath, "text");
|
|
874
|
+
handleOperatorChange('IN_THE_LAST', node, keyPrefix, value);
|
|
875
|
+
}
|
|
876
|
+
else if (isNumericColumnType(columnType)) {
|
|
877
|
+
const newSubtree = deepCopy(defaultNumericComparison);
|
|
878
|
+
newSubtree.left.column = value;
|
|
879
|
+
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
880
|
+
}
|
|
881
|
+
else {
|
|
882
|
+
const newSubtree = deepCopy(defaultEntry);
|
|
883
|
+
newSubtree.left.args.value[0].column = value;
|
|
884
|
+
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
885
|
+
}
|
|
886
|
+
}, options: options }), _jsx(Select, { theme: theme, value: 'IN_THE_LAST', onChange: (value) => {
|
|
861
887
|
handleOperatorChange(value, node, keyPrefix, dateColumn);
|
|
862
888
|
}, options: [
|
|
863
889
|
{ label: 'in the last', value: 'IN_THE_LAST' },
|
|
864
890
|
{ label: 'in the previous', value: 'IN_THE_PREVIOUS' },
|
|
865
891
|
{ label: 'in the current', value: 'IN_THE_CURRENT' },
|
|
892
|
+
{ label: 'is not null', value: 'IS NOT' },
|
|
893
|
+
{ label: 'is null', value: 'IS' },
|
|
866
894
|
// { label: 'equals', value: 'equals' },
|
|
867
|
-
] }), _jsx(TextInput, {
|
|
895
|
+
] }), _jsx(TextInput, { id: 'date_window_interval_count', value: node.right.args.value[1].expr.value, width: 120, onChange: (e) => {
|
|
868
896
|
handleChange([
|
|
869
897
|
{
|
|
870
898
|
value: e.target.value,
|
|
@@ -913,6 +941,8 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
913
941
|
{ label: 'in the last', value: 'IN_THE_LAST' },
|
|
914
942
|
{ label: 'in the previous', value: 'IN_THE_PREVIOUS' },
|
|
915
943
|
{ label: 'in the current', value: 'IN_THE_CURRENT' },
|
|
944
|
+
{ label: 'is not null', value: 'IS NOT' },
|
|
945
|
+
{ label: 'is null', value: 'IS' },
|
|
916
946
|
// { label: 'equals', value: 'equals' },
|
|
917
947
|
] }), _jsx(Select, { theme: theme, value: node.left.args.value[1].column, onChange: (value) => {
|
|
918
948
|
handleChange([
|
|
@@ -952,12 +982,14 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
952
982
|
newSubtree.left.args.value[0].column = value;
|
|
953
983
|
handleReplaceSubtree(keyPrefix, newSubtree);
|
|
954
984
|
}
|
|
955
|
-
},
|
|
985
|
+
}, options: options }), _jsx(Select, { theme: theme, value: 'IN_THE_PREVIOUS', onChange: (value) => {
|
|
956
986
|
handleOperatorChange(value, node, keyPrefix, node.left.column);
|
|
957
987
|
}, options: [
|
|
958
988
|
{ label: 'in the last', value: 'IN_THE_LAST' },
|
|
959
989
|
{ label: 'in the previous', value: 'IN_THE_PREVIOUS' },
|
|
960
990
|
{ label: 'in the current', value: 'IN_THE_CURRENT' },
|
|
991
|
+
{ label: 'is not null', value: 'IS NOT' },
|
|
992
|
+
{ label: 'is null', value: 'IS' },
|
|
961
993
|
// { label: 'equals', value: 'equals' },
|
|
962
994
|
] }), _jsx(Select, { theme: theme, value: node.left.args.value[1].column, onChange: (value) => {
|
|
963
995
|
const dayConversion = {
|
|
@@ -1001,7 +1033,7 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
1001
1033
|
const tables = getTableNames(baseAst);
|
|
1002
1034
|
const table = tables.length === 1 ? tables[0] : initialTableName;
|
|
1003
1035
|
const columnType = column?.fieldType;
|
|
1004
|
-
|
|
1036
|
+
let operatorOptions = [
|
|
1005
1037
|
...(isNumericColumnType(columnType)
|
|
1006
1038
|
? [
|
|
1007
1039
|
{ label: 'equal to', value: '=' },
|
|
@@ -1038,6 +1070,10 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
1038
1070
|
]
|
|
1039
1071
|
: []),
|
|
1040
1072
|
];
|
|
1073
|
+
if (client.databaseType === 'BigQuery' &&
|
|
1074
|
+
isDateishColumnType(columnType)) {
|
|
1075
|
+
operatorOptions = operatorOptions.filter((option) => option.value !== 'equals');
|
|
1076
|
+
}
|
|
1041
1077
|
return (_jsxs("div", { style: {
|
|
1042
1078
|
display: 'flex',
|
|
1043
1079
|
gap: 12,
|
|
@@ -1150,11 +1186,9 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
1150
1186
|
const len = node.value.length;
|
|
1151
1187
|
return (_jsxs("div", { style: { display: 'flex', flexDirection: 'row', gap: 12 }, children: [node.value.map((elem, index) => {
|
|
1152
1188
|
if (elem.value) {
|
|
1153
|
-
return (_jsx(TextInput, {
|
|
1189
|
+
return (_jsx(TextInput, { id: `expr_list_${index}`, width: 200, value: elem.value, onChange: (e) => handleChange([
|
|
1154
1190
|
{
|
|
1155
|
-
value:
|
|
1156
|
-
? parseFloat(e.target.value)
|
|
1157
|
-
: e.target.value,
|
|
1191
|
+
value: e.target.value,
|
|
1158
1192
|
path: keyPrefix + `value.${index}.`,
|
|
1159
1193
|
},
|
|
1160
1194
|
]) }, `input_${index}`));
|
|
@@ -1164,23 +1198,19 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
1164
1198
|
}
|
|
1165
1199
|
case 'double_quote_string':
|
|
1166
1200
|
case 'single_quote_string':
|
|
1167
|
-
return (_jsx(TextInput, {
|
|
1201
|
+
return (_jsx(TextInput, { id: 'quoted_string', value: node.value.replaceAll('%', ''), width: 120, onChange: (e) => handleChange([
|
|
1168
1202
|
{
|
|
1169
|
-
value:
|
|
1170
|
-
? parseFloat(e.target.value)
|
|
1171
|
-
: e.target.value,
|
|
1203
|
+
value: e.target.value,
|
|
1172
1204
|
path: keyPrefix + 'value',
|
|
1173
1205
|
},
|
|
1174
1206
|
]) }));
|
|
1175
1207
|
case 'null':
|
|
1176
1208
|
return _jsx("div", {});
|
|
1177
1209
|
case 'number':
|
|
1178
|
-
return (_jsx(TextInput, {
|
|
1210
|
+
return (_jsx(TextInput, { id: "quill_number_input", value: node.value, width: 120, onChange: (e) => {
|
|
1179
1211
|
handleChange([
|
|
1180
1212
|
{
|
|
1181
|
-
value:
|
|
1182
|
-
? parseFloat(e.target.value)
|
|
1183
|
-
: e.target.value,
|
|
1213
|
+
value: e.target.value,
|
|
1184
1214
|
path: keyPrefix + 'value',
|
|
1185
1215
|
},
|
|
1186
1216
|
]);
|
|
@@ -1207,6 +1237,22 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
1207
1237
|
return null;
|
|
1208
1238
|
}
|
|
1209
1239
|
};
|
|
1240
|
+
const isValidPivot = (fields) => {
|
|
1241
|
+
let validPivot = true;
|
|
1242
|
+
if (pivot.rowField &&
|
|
1243
|
+
!fields.find((field) => field.name === pivot.rowField)) {
|
|
1244
|
+
validPivot = false;
|
|
1245
|
+
}
|
|
1246
|
+
if (pivot.valueField &&
|
|
1247
|
+
!fields.find((field) => field.name === pivot.valueField)) {
|
|
1248
|
+
validPivot = false;
|
|
1249
|
+
}
|
|
1250
|
+
if (pivot.columnField &&
|
|
1251
|
+
!fields.find((field) => field.name === pivot.columnField)) {
|
|
1252
|
+
validPivot = false;
|
|
1253
|
+
}
|
|
1254
|
+
return validPivot;
|
|
1255
|
+
};
|
|
1210
1256
|
const renderSentence = (formData, node, keyPrefix = '',
|
|
1211
1257
|
// @depreciated TODO: remove next update
|
|
1212
1258
|
// eslint-disable-next-line no-unused-vars
|
|
@@ -1410,26 +1456,24 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
1410
1456
|
orgId: client.customerId,
|
|
1411
1457
|
}),
|
|
1412
1458
|
});
|
|
1459
|
+
const tables = getTableNames(baseAst);
|
|
1460
|
+
const table = tables.length >= 1 ? tables[0] : initialTableName;
|
|
1461
|
+
if (table !== currentTable) {
|
|
1462
|
+
await getDistinctValues(table);
|
|
1463
|
+
setCurrentTable(table);
|
|
1464
|
+
}
|
|
1413
1465
|
const data2 = await res2.json();
|
|
1414
1466
|
if (data2.rows && data2.rows.length) {
|
|
1415
1467
|
const tables = getTableNames(baseAst);
|
|
1416
|
-
const table = tables.length >= 1 ? tables[0] : initialTableName;
|
|
1417
|
-
if (table !== currentTable) {
|
|
1418
|
-
getDistinctValues(table);
|
|
1419
|
-
setCurrentTable(table);
|
|
1420
|
-
}
|
|
1421
|
-
const sortedFields = data2.fields.sort((a, b) => {
|
|
1422
|
-
const aIsId = a.name.toLowerCase() === 'id' ||
|
|
1423
|
-
a.name.toLowerCase().endsWith('_id');
|
|
1424
|
-
const bIsId = b.name.toLowerCase() === 'id' ||
|
|
1425
|
-
b.name.toLowerCase().endsWith('_id');
|
|
1426
|
-
if (aIsId && !bIsId)
|
|
1427
|
-
return 1;
|
|
1428
|
-
if (bIsId && !aIsId)
|
|
1429
|
-
return -1;
|
|
1430
|
-
return 0;
|
|
1431
|
-
});
|
|
1432
1468
|
if (pivot) {
|
|
1469
|
+
// check if any of the pivot fields aren't in the data2.fields array
|
|
1470
|
+
if (!isValidPivot(data2.fields)) {
|
|
1471
|
+
setPivot(null);
|
|
1472
|
+
setPivotData(null);
|
|
1473
|
+
setRows(data2.rows);
|
|
1474
|
+
setFields(data2.fields);
|
|
1475
|
+
return;
|
|
1476
|
+
}
|
|
1433
1477
|
// Do all of this to make sure we have the right unique columns when applying a pivot
|
|
1434
1478
|
let uniqueFormatted = {};
|
|
1435
1479
|
const uniqueRecords = Array.from(new Set(data2.rows.map((row) => row[pivot.columnField]))).reduce((acc, curr) => {
|
|
@@ -1658,7 +1702,7 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
1658
1702
|
// newAst = convertDateComparison(newAst); // TODO
|
|
1659
1703
|
ast = newAst; // so we fetch data for newAst later.
|
|
1660
1704
|
if (table !== currentTable) {
|
|
1661
|
-
getDistinctValues(table);
|
|
1705
|
+
await getDistinctValues(table);
|
|
1662
1706
|
setCurrentTable(table);
|
|
1663
1707
|
}
|
|
1664
1708
|
setPivotRowField(groupByPivot?.rowField);
|
|
@@ -1847,6 +1891,8 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
1847
1891
|
height: '100%',
|
|
1848
1892
|
...containerStyle,
|
|
1849
1893
|
}, ref: parentRef, children: [_jsxs(Sidebar, { children: [_jsx(SidebarHeading, { label: "Columns" }), _jsx("div", { style: { height: 4, width: '100%' } }), _jsx(DraggableColumns, {}), _jsx(Popover, { isOpen: openPopover === 'AddColumnPopover', trigger: _jsx(SecondaryButton, { onClick: () => {
|
|
1894
|
+
if (loadingSchema)
|
|
1895
|
+
return;
|
|
1850
1896
|
if (!openPopover) {
|
|
1851
1897
|
setOpenPopover('AddColumnPopover');
|
|
1852
1898
|
}
|
|
@@ -1873,7 +1919,9 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
1873
1919
|
gap: 2.5,
|
|
1874
1920
|
alignItems: 'flex-start',
|
|
1875
1921
|
}, children: [_jsx(Popover, { isOpen: openPopover === 'AddFilterPopover', title: 'Add filter', trigger: _jsx(SecondaryButton, { onClick: () => {
|
|
1876
|
-
if (!selectedColumns ||
|
|
1922
|
+
if (!selectedColumns ||
|
|
1923
|
+
selectedColumns.length === 0 ||
|
|
1924
|
+
loading) {
|
|
1877
1925
|
return;
|
|
1878
1926
|
}
|
|
1879
1927
|
if (!openPopover) {
|
|
@@ -2010,7 +2058,7 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
2010
2058
|
if (!pivot) {
|
|
2011
2059
|
fetchSqlQuery(baseAst);
|
|
2012
2060
|
}
|
|
2013
|
-
} }, `sort-sentence-pivot`) })), baseAst && baseAst.orderby && (_jsx("div", { style: {
|
|
2061
|
+
}, Select: Select, Button: Button, SecondaryButton: SecondaryButton }, `sort-sentence-pivot`) })), baseAst && baseAst.orderby && (_jsx("div", { style: {
|
|
2014
2062
|
display: 'flex',
|
|
2015
2063
|
flexDirection: 'column',
|
|
2016
2064
|
gap: 8,
|
|
@@ -2044,7 +2092,7 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
2044
2092
|
if (!pivot) {
|
|
2045
2093
|
fetchSqlQuery(newAst);
|
|
2046
2094
|
}
|
|
2047
|
-
} }, `sort-sentence-${id}`))) })), _jsx(Popover, { isOpen: openPopover === 'AddSortPopover', setIsOpen: () => { }, trigger: _jsx(SecondaryButton, { onClick: () => {
|
|
2095
|
+
}, Select: Select, Button: Button, SecondaryButton: SecondaryButton }, `sort-sentence-${id}`))) })), _jsx(Popover, { isOpen: openPopover === 'AddSortPopover', setIsOpen: () => { }, trigger: _jsx(SecondaryButton, { onClick: () => {
|
|
2048
2096
|
if (!selectedColumns || selectedColumns.length === 0) {
|
|
2049
2097
|
return;
|
|
2050
2098
|
}
|
|
@@ -2080,7 +2128,7 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
2080
2128
|
setOpenPopover(null);
|
|
2081
2129
|
setBaseAst(deepCopy(newAst));
|
|
2082
2130
|
fetchSqlQuery(newAst);
|
|
2083
|
-
} }) })) : (_jsx(Popover, { isOpen: openPopover === 'AddLimitPopover', setIsOpen: () => { }, trigger: _jsx(SecondaryButton, { onClick: () => {
|
|
2131
|
+
}, TextInput: TextInput, Button: Button, SecondaryButton: SecondaryButton }) })) : (_jsx(Popover, { isOpen: openPopover === 'AddLimitPopover', setIsOpen: () => { }, trigger: _jsx(SecondaryButton, { onClick: () => {
|
|
2084
2132
|
if (!openPopover) {
|
|
2085
2133
|
setOpenPopover('AddLimitPopover');
|
|
2086
2134
|
}
|
|
@@ -2089,14 +2137,14 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
2089
2137
|
setActiveEditItem(null);
|
|
2090
2138
|
setActivePath(null);
|
|
2091
2139
|
setOpenPopover(null);
|
|
2092
|
-
}, children: _jsx(TextInput, {
|
|
2140
|
+
}, children: _jsx(TextInput, { id: "loading_input_limit", value: 0, width: 120, onChange: () => { } }) }))] }), _jsxs(Container, { children: [!hideAi && (_jsxs("form", { ref: askAILoadingContainerRef, onSubmit: (event) => {
|
|
2093
2141
|
event.preventDefault();
|
|
2094
2142
|
}, style: {
|
|
2095
2143
|
display: 'flex',
|
|
2096
2144
|
flexDirection: 'row',
|
|
2097
2145
|
gap: 12,
|
|
2098
2146
|
padding: 1,
|
|
2099
|
-
}, children: [_jsx(TextInput, { placeholder: baseAst ? 'Ask a follow-up question...' : 'Ask a question...',
|
|
2147
|
+
}, children: [_jsx(TextInput, { id: "ask_ai_loading_bar", placeholder: baseAst ? 'Ask a follow-up question...' : 'Ask a question...', width: askAILoadingContainerWidth, value: aiPrompt, onChange: () => { } }), _jsx(Button, { onClick: () => { }, label: "Ask AI" }), baseAst && (_jsx(SecondaryButton, { onClick: clearAllState, label: "New report" }))] })), _jsxs(_Fragment, { children: [_jsx(TableLoadingState, {}), _jsxs("div", { style: {
|
|
2100
2148
|
display: 'flex',
|
|
2101
2149
|
flexDirection: 'row',
|
|
2102
2150
|
gap: '12px',
|
|
@@ -2139,7 +2187,9 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
2139
2187
|
gap: 2.5,
|
|
2140
2188
|
alignItems: 'flex-start',
|
|
2141
2189
|
}, children: [_jsx(Popover, { title: 'Add filter', isOpen: openPopover === 'AddFilterPopover', trigger: _jsx(SecondaryButton, { onClick: () => {
|
|
2142
|
-
if (!selectedColumns ||
|
|
2190
|
+
if (!selectedColumns ||
|
|
2191
|
+
selectedColumns.length === 0 ||
|
|
2192
|
+
loading) {
|
|
2143
2193
|
return;
|
|
2144
2194
|
}
|
|
2145
2195
|
if (!openPopover) {
|
|
@@ -2286,7 +2336,7 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
2286
2336
|
setOpenPopover(null);
|
|
2287
2337
|
setBaseAst(deepCopy(baseAst));
|
|
2288
2338
|
fetchSqlQuery(deepCopy(baseAst));
|
|
2289
|
-
} }, `sort-sentence-pivot`) })), baseAst && baseAst.orderby && (_jsx("div", { style: {
|
|
2339
|
+
}, Select: Select, Button: Button, SecondaryButton: SecondaryButton }, `sort-sentence-pivot`) })), baseAst && baseAst.orderby && (_jsx("div", { style: {
|
|
2290
2340
|
display: 'flex',
|
|
2291
2341
|
flexDirection: 'column',
|
|
2292
2342
|
gap: 8,
|
|
@@ -2328,7 +2378,7 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
2328
2378
|
setOpenPopover(null);
|
|
2329
2379
|
setBaseAst(deepCopy(newAst));
|
|
2330
2380
|
fetchSqlQuery(deepCopy(newAst));
|
|
2331
|
-
} }, `sort-sentence-${id}`))) })), _jsx(Popover, { isOpen: openPopover === 'AddSortPopover', trigger: _jsx(SecondaryButton, { onClick: () => {
|
|
2381
|
+
}, Select: Select, Button: Button, SecondaryButton: SecondaryButton }, `sort-sentence-${id}`))) })), _jsx(Popover, { isOpen: openPopover === 'AddSortPopover', trigger: _jsx(SecondaryButton, { onClick: () => {
|
|
2332
2382
|
if (!selectedColumns || selectedColumns.length === 0) {
|
|
2333
2383
|
return;
|
|
2334
2384
|
}
|
|
@@ -2340,7 +2390,7 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
2340
2390
|
setActiveEditItem(null);
|
|
2341
2391
|
setActivePath(null);
|
|
2342
2392
|
setOpenPopover(null);
|
|
2343
|
-
}, children: _jsx(AddSortPopover, { columns: pivot ? [`.${pivot.rowField}`] : selectedColumns, Select: Select, Button: Button, onSave: (column, direction) => {
|
|
2393
|
+
}, children: _jsx(AddSortPopover, { columns: pivot ? [`.${pivot.rowField}`] : selectedColumns, Select: Select, Button: Button, SecondaryButton: SecondaryButton, onSave: (column, direction) => {
|
|
2344
2394
|
if (column === '')
|
|
2345
2395
|
return;
|
|
2346
2396
|
if (pivot) {
|
|
@@ -2388,7 +2438,7 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
2388
2438
|
setOpenPopover(null);
|
|
2389
2439
|
setBaseAst(deepCopy(newAst));
|
|
2390
2440
|
fetchSqlQuery(deepCopy(newAst));
|
|
2391
|
-
} }) })) : (_jsx(Popover, { isOpen: openPopover === 'AddLimitPopover', setIsOpen: () => { }, trigger: _jsx(SecondaryButton, { onClick: () => {
|
|
2441
|
+
}, TextInput: TextInput, Button: Button, SecondaryButton: SecondaryButton }) })) : (_jsx(Popover, { isOpen: openPopover === 'AddLimitPopover', setIsOpen: () => { }, trigger: _jsx(SecondaryButton, { onClick: () => {
|
|
2392
2442
|
if (!selectedColumns || selectedColumns.length === 0) {
|
|
2393
2443
|
return;
|
|
2394
2444
|
}
|
|
@@ -2403,7 +2453,7 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
2403
2453
|
setActiveEditItem(null);
|
|
2404
2454
|
setActivePath(null);
|
|
2405
2455
|
setOpenPopover(null);
|
|
2406
|
-
}, children: _jsx(AddLimitPopover, { TextInput: TextInput, onSave: (limit) => {
|
|
2456
|
+
}, children: _jsx(AddLimitPopover, { TextInput: TextInput, Button: Button, SecondaryButton: SecondaryButton, onSave: (limit) => {
|
|
2407
2457
|
const newAst = { ...baseAst };
|
|
2408
2458
|
newAst.limit = {
|
|
2409
2459
|
seperator: '',
|
|
@@ -2417,7 +2467,7 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
2417
2467
|
setOpenPopover(null);
|
|
2418
2468
|
setBaseAst(deepCopy(newAst));
|
|
2419
2469
|
fetchSqlQuery(deepCopy(newAst));
|
|
2420
|
-
} }) }))] }), _jsxs(Container, { children: [!hideAi && (_jsxs("form", { onSubmit: (event) => {
|
|
2470
|
+
} }) }))] }), _jsxs(Container, { children: [!hideAi && (_jsxs("form", { ref: askAIContainerRef, onSubmit: (event) => {
|
|
2421
2471
|
event.preventDefault();
|
|
2422
2472
|
handleAsk();
|
|
2423
2473
|
}, style: {
|
|
@@ -2425,14 +2475,14 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
2425
2475
|
flexDirection: 'row',
|
|
2426
2476
|
gap: 12,
|
|
2427
2477
|
padding: 1,
|
|
2428
|
-
}, children: [_jsx(TextInput, {
|
|
2478
|
+
}, children: [_jsx(TextInput, { id: "ask_ai_input_bar", value: aiPrompt, width: askAIInputWidth, onChange: (e) => setAiPrompt(e.target.value), placeholder: baseAst ? 'Ask a follow-up question...' : 'Ask a question...' }), _jsx(Button, { onClick: handleAsk, label: 'Ask AI' }), baseAst && (_jsx(SecondaryButton, { label: 'New report', onClick: clearAllState }))] })), baseAst && (_jsx(_Fragment, { children: loading && errorMessage.length === 0 ? (_jsx(TableLoadingState, {})) : (_jsx(Table, { rows: applyFormatting({
|
|
2429
2479
|
rows: pivotData?.rows || rows,
|
|
2430
2480
|
fields: pivotData?.fields || fields,
|
|
2431
2481
|
}, baseAst?.columns ?? []), columns: pivot
|
|
2432
2482
|
? pivotData?.columns || emptyPivotColumns()
|
|
2433
2483
|
: enforceOrderOnColumns(Object.keys(rows[0] ?? {})).map((c) => {
|
|
2434
2484
|
return { label: snakeCaseToTitleCase(c), field: c };
|
|
2435
|
-
}),
|
|
2485
|
+
}), rowsPerPage: 20 })) })), _jsxs("div", { style: {
|
|
2436
2486
|
display: 'flex',
|
|
2437
2487
|
flexDirection: 'row',
|
|
2438
2488
|
gap: '12px',
|
|
@@ -2443,5 +2493,8 @@ export default function ReportBuilder({ initialTableName = '', onAddToDashboardC
|
|
|
2443
2493
|
whiteSpace: 'nowrap',
|
|
2444
2494
|
}, children: errorMessage })), _jsx("div", { style: { width: '100%' } }), baseAst && (_jsxs(_Fragment, { children: [_jsx(SecondaryButton, { label: isCopying ? '✅ Copied' : 'Copy SQL', onClick: () => copyToClipboard(activeQuery) }), _jsx(Button, { onClick: () => {
|
|
2445
2495
|
setIsChartBuilderOpen(true);
|
|
2446
|
-
}, label: 'Add to dashboard' })] }))] })] }), _jsx("style", { children: `body{margin:0;}` }), _jsx(ChartBuilderWithModal, { rows: applyFormatting({ rows, fields }, baseAst?.columns ?? []), columns: processColumnsForChartBuilder(Object.keys(rows[0] ?? {})), fields: fields, pivot: pivot, query: activeQuery, showTableFormatOptions: admin ? true : false, showDateFieldOptions: admin ? true : false, showAccessControlOptions: admin ? true : false, title: "Add to dashboard", isEditMode: true, isOpen: isChartBuilderOpen, setIsOpen: setIsChartBuilderOpen, onAddToDashboardComplete: onAddToDashboardComplete, destinationDashboard: destinationDashboard, organizationName: organizationName, pivotData: pivotData
|
|
2496
|
+
}, label: 'Add to dashboard' })] }))] })] }), _jsx("style", { children: `body{margin:0;}` }), _jsx(ChartBuilderWithModal, { rows: applyFormatting({ rows, fields }, baseAst?.columns ?? []), columns: processColumnsForChartBuilder(Object.keys(rows[0] ?? {})), fields: fields, pivot: pivot, query: activeQuery, showTableFormatOptions: admin ? true : false, showDateFieldOptions: admin ? true : false, showAccessControlOptions: admin ? true : false, title: "Add to dashboard", isEditMode: true, isOpen: isChartBuilderOpen, setIsOpen: setIsChartBuilderOpen, onAddToDashboardComplete: onAddToDashboardComplete, destinationDashboard: destinationDashboard, organizationName: organizationName, pivotData: pivotData, Select: Select, TextInput: TextInput, Button: Button, SecondaryButton: SecondaryButton, Header: Header, Label: Label, Text: Text,
|
|
2497
|
+
// TODO: Modal={Modal}
|
|
2498
|
+
// TODO: Popover={Popover}
|
|
2499
|
+
DeleteButton: DeleteButton })] }));
|
|
2447
2500
|
}
|
package/dist/esm/SQLEditor.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { ModalComponentProps, TableComponentProps } from './components/UiComponents';
|
|
2
|
+
import { ModalComponentProps, TableComponentProps, TextInputComponentProps } from './components/UiComponents';
|
|
3
3
|
export declare function convertPostgresColumn(column: any): {
|
|
4
4
|
label: any;
|
|
5
5
|
field: any;
|
|
@@ -38,12 +38,6 @@ interface SQLEditorProps {
|
|
|
38
38
|
organizationName?: string;
|
|
39
39
|
chartBuilderHorizontalView?: boolean;
|
|
40
40
|
}
|
|
41
|
-
interface TextInputComponentProps {
|
|
42
|
-
onChange: (e: any) => void;
|
|
43
|
-
value: string;
|
|
44
|
-
id: string;
|
|
45
|
-
placeholder?: string;
|
|
46
|
-
}
|
|
47
41
|
export default function QueryEditor({ containerStyle, ButtonComponent, SecondaryButtonComponent, TextInputComponent, TableComponent, newQueryEnabled, LoadingComponent, ModalComponent, defaultQuery, onChangeQuery, onChangeData, onChangeColumns, onChangeFields, isEditMode, chartBuilderEnabled, showTableFormatOptions, showDateFieldOptions, showAccessControlOptions, destinationDashboard, chartBuilderTitle, chartBuilderButtonLabel, onAddToDashboardComplete, addToDashboardButtonLabel, dashboardItem, organizationName, chartBuilderHorizontalView, }: SQLEditorProps): import("react/jsx-runtime").JSX.Element;
|
|
48
42
|
export declare const SchemaListComponent: ({ schema, theme, loading, LoadingComponent, width, onClick, }: {
|
|
49
43
|
schema: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SQLEditor.d.ts","sourceRoot":"","sources":["../../src/SQLEditor.tsx"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"SQLEditor.d.ts","sourceRoot":"","sources":["../../src/SQLEditor.tsx"],"names":[],"mappings":"AAEA,OAAO,KAON,MAAM,OAAO,CAAC;AAQf,OAAO,EAGL,mBAAmB,EACnB,mBAAmB,EAEnB,uBAAuB,EACxB,MAAM,2BAA2B,CAAC;AAKnC,wBAAgB,qBAAqB,CAAC,MAAM,KAAA;;;;;EAwE3C;AA2BD,UAAU,oBAAoB;IAC5B,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,UAAU,cAAc;IACtB,cAAc,EAAE,KAAK,CAAC,aAAa,CAAC;IAEpC,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,GAAG,CAAC,OAAO,CAAC;IAC/D,wBAAwB,CAAC,EAAE,CAAC,KAAK,EAAE,oBAAoB,KAAK,GAAG,CAAC,OAAO,CAAC;IAExE,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,GAAG,CAAC,OAAO,CAAC;IACrE,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,GAAG,CAAC,OAAO,CAAC;IAC7D,gBAAgB,CAAC,EAAE,MAAM,GAAG,CAAC,OAAO,CAAC;IACrC,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,mBAAmB,KAAK,GAAG,CAAC,OAAO,CAAC;IAC9D,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IACxC,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAC9C,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAC5C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,GAAG,CAAC;IACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC,wBAAwB,CAAC,EAAE,MAAM,IAAI,CAAC;IACtC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,0BAA0B,CAAC,EAAE,OAAO,CAAC;CACtC;AA6CD,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAClC,cAAoC,EACpC,eAAgC,EAChC,wBAAkD,EAClD,kBAAmC,EACnC,cAA2B,EAC3B,eAAuB,EACvB,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,eAAe,EACf,cAAc,EACd,UAAkB,EAClB,mBAA2B,EAC3B,sBAA8B,EAC9B,oBAA4B,EAC5B,wBAAgC,EAChC,oBAAoB,EACpB,iBAAiB,EACjB,uBAAuB,EACvB,wBAAwB,EACxB,yBAA8C,EAC9C,aAAyB,EACzB,gBAA4B,EAC5B,0BAAkC,GACnC,EAAE,cAAc,2CAgYhB;AA6JD,eAAO,MAAM,mBAAmB;;;;;;;6CAuG/B,CAAC"}
|
package/dist/esm/SQLEditor.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
// @ts-nocheck
|
|
3
3
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4
|
-
import { useState, useContext, useEffect, } from 'react';
|
|
4
|
+
import { useState, useContext, useEffect, useRef, } from 'react';
|
|
5
5
|
import MonacoEditor from '@monaco-editor/react';
|
|
6
6
|
// import './nightOwlLight.css';
|
|
7
7
|
import { ClientContext, SchemaContext, ThemeContext } from './Context';
|
|
@@ -9,7 +9,8 @@ import QuillTable from './components/QuillTable';
|
|
|
9
9
|
import { getData, getDataFromCloud } from './utils/dataFetcher';
|
|
10
10
|
import { ChartBuilderWithModal } from './ChartBuilder';
|
|
11
11
|
import { MemoizedButton, MemoizedSecondaryButton, } from './components/UiComponents';
|
|
12
|
-
import { QuillTextInput } from './components/
|
|
12
|
+
import { QuillTextInput } from './components/UiComponents';
|
|
13
|
+
import { updateFirstChildWidth } from './utils/width';
|
|
13
14
|
export function convertPostgresColumn(column) {
|
|
14
15
|
let format;
|
|
15
16
|
let fieldType;
|
|
@@ -139,6 +140,20 @@ export default function QueryEditor({ containerStyle = { height: '100vh' }, Butt
|
|
|
139
140
|
const [schemaLoading, setSchemaLoading] = useState(false);
|
|
140
141
|
const [isChartBuilderOpen, setIsChartBuilderOpen] = useState(false);
|
|
141
142
|
const [displayTable, setDisplayTable] = useState(false);
|
|
143
|
+
const formRef = useRef(null);
|
|
144
|
+
const [searchBarWidth, setSearchBarWidth] = useState(200);
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
// Since the TextInput component takes a required numeric width parameter,
|
|
147
|
+
// we dynamically calculate the width of this component here.
|
|
148
|
+
function handleResize() {
|
|
149
|
+
updateFirstChildWidth(formRef, setSearchBarWidth, { gap: 12 });
|
|
150
|
+
}
|
|
151
|
+
handleResize();
|
|
152
|
+
window.addEventListener('resize', handleResize);
|
|
153
|
+
return () => {
|
|
154
|
+
window.removeEventListener('resize', handleResize);
|
|
155
|
+
};
|
|
156
|
+
}, []);
|
|
142
157
|
const getSchema = async (isSubscribed) => {
|
|
143
158
|
setSchemaLoading(true);
|
|
144
159
|
const { queryEndpoint, queryHeaders, publicKey } = client;
|
|
@@ -288,7 +303,7 @@ export default function QueryEditor({ containerStyle = { height: '100vh' }, Butt
|
|
|
288
303
|
width: 'calc(100% - 290px)',
|
|
289
304
|
height: '100%',
|
|
290
305
|
overflowX: 'hidden',
|
|
291
|
-
}, children: [_jsxs("form", { onSubmit: (e) => {
|
|
306
|
+
}, children: [_jsxs("form", { ref: formRef, onSubmit: (e) => {
|
|
292
307
|
e.preventDefault();
|
|
293
308
|
handleRunSqlPrompt();
|
|
294
309
|
}, style: {
|
|
@@ -297,7 +312,7 @@ export default function QueryEditor({ containerStyle = { height: '100vh' }, Butt
|
|
|
297
312
|
gap: 12,
|
|
298
313
|
paddingTop: 16,
|
|
299
314
|
paddingBottom: 16,
|
|
300
|
-
}, children: [_jsx(TextInputComponent, { id: "ai-search", value: sqlPrompt,
|
|
315
|
+
}, children: [_jsx(TextInputComponent, { id: "ai-search", value: sqlPrompt, width: searchBarWidth, onChange: (e) => setSqlPrompt(e.target.value), placeholder: "Ask a question..." }), (ButtonComponent && (_jsx(ButtonComponent, { onClick: handleRunSqlPrompt, label: "Ask AI" }))) || (_jsx(QuillButton, { theme: theme, onClick: handleRunSqlPrompt, label: "Ask AI" }))] }), _jsx("div", { style: { height: 'calc(50% - 40px)' }, children: _jsx(SQLEditorComponent, { query: query, setQuery: setQuery, handleRunQuery: handleRunQuery, handleFixWithAI: handleFixWithAI, newQueryEnabled: newQueryEnabled, handleClearQuery: handleClearQuery, theme: theme, defineEditorTheme: defineEditorTheme, setEditorTheme: setEditorTheme, ButtonComponent: ButtonComponent, SecondaryButtonComponent: SecondaryButtonComponent, loading: sqlResponseLoading, LoadingComponent: LoadingComponent }) }), _jsxs("div", { style: {
|
|
301
316
|
display: 'flex',
|
|
302
317
|
flexDirection: 'column',
|
|
303
318
|
height: 'calc(50% - 108px)',
|