@quillsql/react 2.8.5 → 2.8.7
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/AddToDashboardModal.js +146 -180
- package/dist/BarList.js +36 -43
- package/dist/Chart.js +99 -131
- package/dist/ChartBuilder.js +80 -88
- package/dist/ChartEditor.js +14 -20
- package/dist/Context.js +52 -56
- package/dist/Dashboard.d.ts.map +1 -1
- package/dist/Dashboard.js +246 -305
- package/dist/DateRangePicker/Calendar.js +41 -45
- package/dist/DateRangePicker/DateRangePicker.js +32 -60
- package/dist/DateRangePicker/DateRangePickerButton.js +14 -16
- package/dist/DateRangePicker/dateRangePickerUtils.d.ts +6 -0
- package/dist/DateRangePicker/dateRangePickerUtils.d.ts.map +1 -1
- package/dist/DateRangePicker/dateRangePickerUtils.js +89 -89
- package/dist/DateRangePicker/index.js +1 -8
- package/dist/PieChart.js +35 -69
- package/dist/QuillProvider.js +4 -6
- package/dist/ReportBuilder.js +120 -128
- package/dist/SQLEditor.js +56 -64
- package/dist/Table.d.ts +2 -1
- package/dist/Table.d.ts.map +1 -1
- package/dist/Table.js +71 -69
- package/dist/TableChart.js +17 -44
- package/dist/assets/ArrowDownHeadIcon.js +3 -5
- package/dist/assets/ArrowDownIcon.js +3 -5
- package/dist/assets/ArrowDownRightIcon.js +3 -5
- package/dist/assets/ArrowLeftHeadIcon.js +3 -5
- package/dist/assets/ArrowRightHeadIcon.js +3 -5
- package/dist/assets/ArrowRightIcon.js +3 -5
- package/dist/assets/ArrowUpHeadIcon.js +3 -5
- package/dist/assets/ArrowUpIcon.js +3 -5
- package/dist/assets/ArrowUpRightIcon.js +3 -5
- package/dist/assets/CalendarIcon.js +3 -5
- package/dist/assets/CalendarNormalIcon.js +3 -5
- package/dist/assets/DoubleArrowLeftHeadIcon.js +3 -5
- package/dist/assets/DoubleArrowRightHeadIcon.js +3 -5
- package/dist/assets/ExclamationFilledIcon.js +3 -5
- package/dist/assets/FilterIcon.js +3 -5
- package/dist/assets/LoadingSpinner.js +3 -5
- package/dist/assets/RefreshIcon.js +3 -5
- package/dist/assets/SearchIcon.js +3 -5
- package/dist/assets/UpLeftArrowsIcon.js +3 -5
- package/dist/assets/XCircleIcon.js +3 -5
- package/dist/assets/XIcon.js +3 -5
- package/dist/assets/index.js +21 -48
- package/dist/components/BigModal/BigModal.js +13 -38
- package/dist/components/Dropdown/Dropdown.js +24 -52
- package/dist/components/Dropdown/DropdownItem.js +9 -34
- package/dist/components/Dropdown/index.js +2 -10
- package/dist/components/Modal/Modal.js +13 -38
- package/dist/components/Modal/index.js +1 -8
- package/dist/components/QuillCard.js +8 -12
- package/dist/components/SqlTextEditor.d.ts +7 -0
- package/dist/components/SqlTextEditor.d.ts.map +1 -0
- package/dist/components/SqlTextEditor.js +14 -0
- package/dist/components/UiComponents.js +37 -50
- package/dist/components/selectUtils.js +6 -16
- package/dist/contexts/BaseColorContext.js +3 -5
- package/dist/contexts/HoveredValueContext.js +3 -5
- package/dist/contexts/RootStylesContext.js +3 -5
- package/dist/contexts/SelectedValueContext.js +3 -5
- package/dist/contexts/index.js +4 -14
- package/dist/hooks/index.js +4 -14
- package/dist/hooks/useDashboard.d.ts +7 -0
- package/dist/hooks/useDashboard.d.ts.map +1 -0
- package/dist/hooks/useDashboard.js +49 -0
- package/dist/hooks/useInternalState.js +3 -5
- package/dist/hooks/useOnClickOutside.js +3 -5
- package/dist/hooks/useOnWindowResize.js +4 -6
- package/dist/hooks/useQuill.js +11 -15
- package/dist/hooks/useSelectOnKeyDown.js +4 -6
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -28
- package/dist/internals/ReportBuilder/PivotList.js +14 -19
- package/dist/internals/ReportBuilder/PivotModal.js +84 -91
- package/dist/internals/ReportBuilder/PivotModal.spec.js +70 -72
- package/dist/lib/font.js +2 -5
- package/dist/lib/index.js +3 -19
- package/dist/lib/inputTypes.js +1 -2
- package/dist/lib/utils.js +8 -18
- package/dist/utils/aggregate.js +28 -34
- package/dist/utils/colorToHex.js +1 -4
- package/dist/utils/dataFetcher.js +2 -7
- package/dist/utils/downloadCSV.js +1 -5
- package/package.json +2 -1
package/dist/ChartBuilder.js
CHANGED
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.numberFormatOptions = exports.snakeCaseToTitleCase = void 0;
|
|
7
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
2
|
// @ts-nocheck
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
3
|
+
import { useEffect, useRef, useState, useContext, useMemo } from 'react';
|
|
4
|
+
import { ClientContext, DashboardContext, SchemaContext, ThemeContext, } from './Context';
|
|
5
|
+
import { getData, getDataFromCloud } from './utils/dataFetcher';
|
|
6
|
+
import { getPostgresBasicType } from './ReportBuilder';
|
|
7
|
+
import { PivotModal, generatePivotTable, isDateField, } from './internals/ReportBuilder/PivotModal';
|
|
8
|
+
import { PivotCard } from './internals/ReportBuilder/PivotList';
|
|
9
|
+
import Chart from './Chart';
|
|
10
|
+
import { MemoizedModal, MemoizedTextInput, MemoizedSelect, MemoizedButton, MemoizedSecondaryButton, MemoizedHeader, MemoizedLabel, MemoizedDeleteButton, MemoizedText, MemoizedPopover, } from './components/UiComponents';
|
|
17
11
|
const CHART_TYPES = ['column', 'line', 'table', 'metric', 'bar', 'pie'];
|
|
18
|
-
function snakeCaseToTitleCase(str) {
|
|
12
|
+
export function snakeCaseToTitleCase(str) {
|
|
19
13
|
if (!str) {
|
|
20
14
|
return str;
|
|
21
15
|
}
|
|
@@ -27,7 +21,6 @@ function snakeCaseToTitleCase(str) {
|
|
|
27
21
|
: word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
28
22
|
.join(' ');
|
|
29
23
|
}
|
|
30
|
-
exports.snakeCaseToTitleCase = snakeCaseToTitleCase;
|
|
31
24
|
const POSTGRES_DATE_TYPES = [
|
|
32
25
|
'timestamp',
|
|
33
26
|
'date',
|
|
@@ -39,7 +32,7 @@ async function getReferencedTables(client, sqlQuery, dbTables) {
|
|
|
39
32
|
// const parser = new Parser();
|
|
40
33
|
const tables = [];
|
|
41
34
|
const withAliases = [];
|
|
42
|
-
const resp = await
|
|
35
|
+
const resp = await getDataFromCloud(client, `astify`, { query: sqlQuery });
|
|
43
36
|
let ast = resp.ast;
|
|
44
37
|
ast = ast.length ? ast[0] : ast;
|
|
45
38
|
if (ast.with && ast.with.length) {
|
|
@@ -73,7 +66,7 @@ const AGGREGATION_TYPES = [
|
|
|
73
66
|
{ label: 'count', value: 'count' },
|
|
74
67
|
{ label: 'average', value: 'avg' },
|
|
75
68
|
];
|
|
76
|
-
|
|
69
|
+
export const numberFormatOptions = [
|
|
77
70
|
'whole_number',
|
|
78
71
|
'one_decimal_place',
|
|
79
72
|
'two_decimal_places',
|
|
@@ -97,30 +90,29 @@ const formatOptions = [
|
|
|
97
90
|
{ value: 'percent', label: 'percent' },
|
|
98
91
|
{ value: 'string', label: 'string' },
|
|
99
92
|
];
|
|
100
|
-
function ChartBuilder(props) {
|
|
101
|
-
const [theme] =
|
|
102
|
-
return ((
|
|
93
|
+
export default function ChartBuilder(props) {
|
|
94
|
+
const [theme] = useContext(ThemeContext);
|
|
95
|
+
return (_jsx(_Fragment, { children: props.Modal ? (_jsx(props.Modal, { isOpen: props.isOpen, setIsOpen: props.setIsOpen, title: props.title || 'Add to dashboard', onClose: () => props.setIsOpen(false), theme: theme, children: _jsx(ChartBuilderForm, { ...props }) })) : (_jsx(MemoizedModal, { setIsOpen: props.setIsOpen, isOpen: props.isOpen, onClose: () => props.setIsOpen(false), title: props.title || 'Add to dashboard', theme: theme, children: _jsx(ChartBuilderForm, { ...props }) })) }));
|
|
103
96
|
}
|
|
104
|
-
|
|
105
|
-
function ChartBuilderForm({ TextInput = UiComponents_1.MemoizedTextInput, Select = UiComponents_1.MemoizedSelect, Button = UiComponents_1.MemoizedButton, SecondaryButton = UiComponents_1.MemoizedSecondaryButton, Header = UiComponents_1.MemoizedHeader, Label = UiComponents_1.MemoizedLabel, DeleteButton = UiComponents_1.MemoizedDeleteButton, Text = UiComponents_1.MemoizedText, Modal = UiComponents_1.MemoizedModal, Popover = UiComponents_1.MemoizedPopover, isOpen, pivot, setIsOpen, rows, columns, query, queryNoDateColumn, dateRange: dr, formHeaderStyle, formLabelStyle, showTableFormatOptions = false, showDateFieldOptions = false, showAccessControlOptions = false, showDashboardDropdown = true, onAddToDashboardComplete, onDelete, fields: fieldsProp, dashboardItem = undefined, recommendedPivots: rp = [], createdPivots: cp = [], destinationDashboard, dateColumn, buttonLabel, }) {
|
|
97
|
+
function ChartBuilderForm({ TextInput = MemoizedTextInput, Select = MemoizedSelect, Button = MemoizedButton, SecondaryButton = MemoizedSecondaryButton, Header = MemoizedHeader, Label = MemoizedLabel, DeleteButton = MemoizedDeleteButton, Text = MemoizedText, Modal = MemoizedModal, Popover = MemoizedPopover, isOpen, pivot, setIsOpen, rows, columns, query, queryNoDateColumn, dateRange: dr, formHeaderStyle, formLabelStyle, showTableFormatOptions = false, showDateFieldOptions = false, showAccessControlOptions = false, showDashboardDropdown = true, onAddToDashboardComplete, onDelete, fields: fieldsProp, dashboardItem = undefined, recommendedPivots: rp = [], createdPivots: cp = [], destinationDashboard, dateColumn, buttonLabel, }) {
|
|
106
98
|
const dateRange = dr || [null, null, null];
|
|
107
|
-
const [client] =
|
|
108
|
-
const [theme] =
|
|
109
|
-
const [schema, setSchema] =
|
|
110
|
-
const [isSubmitting, setIsSubmitting] =
|
|
111
|
-
const [divWidth, setDivWidth] =
|
|
112
|
-
const { dispatch } =
|
|
99
|
+
const [client] = useContext(ClientContext);
|
|
100
|
+
const [theme] = useContext(ThemeContext);
|
|
101
|
+
const [schema, setSchema] = useContext(SchemaContext);
|
|
102
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
103
|
+
const [divWidth, setDivWidth] = useState(0);
|
|
104
|
+
const { dispatch } = useContext(DashboardContext);
|
|
113
105
|
const fields = fieldsProp?.map((field) => ({
|
|
114
106
|
field: field.name,
|
|
115
|
-
type:
|
|
107
|
+
type: getPostgresBasicType(field),
|
|
116
108
|
format: field.format,
|
|
117
109
|
label: field.name,
|
|
118
110
|
})) || [];
|
|
119
|
-
const parentRef =
|
|
120
|
-
const deleteRef =
|
|
111
|
+
const parentRef = useRef();
|
|
112
|
+
const deleteRef = useRef();
|
|
121
113
|
const modalPadding = 20;
|
|
122
114
|
const deleteButtonMargin = -13;
|
|
123
|
-
|
|
115
|
+
useEffect(() => {
|
|
124
116
|
const calculateWidth = () => {
|
|
125
117
|
return (parentRef.current.offsetWidth -
|
|
126
118
|
(deleteRef?.current
|
|
@@ -144,11 +136,11 @@ function ChartBuilderForm({ TextInput = UiComponents_1.MemoizedTextInput, Select
|
|
|
144
136
|
};
|
|
145
137
|
}, []);
|
|
146
138
|
// get schema
|
|
147
|
-
|
|
139
|
+
useEffect(() => {
|
|
148
140
|
let isSubscribed = true;
|
|
149
141
|
async function getSchema() {
|
|
150
142
|
if (!schema || !schema.length) {
|
|
151
|
-
const resp = await
|
|
143
|
+
const resp = await getDataFromCloud(client, `schema2/${client.publicKey}/`, null, 'GET');
|
|
152
144
|
if (isSubscribed) {
|
|
153
145
|
setSchema(resp.tables);
|
|
154
146
|
}
|
|
@@ -162,11 +154,11 @@ function ChartBuilderForm({ TextInput = UiComponents_1.MemoizedTextInput, Select
|
|
|
162
154
|
};
|
|
163
155
|
}, [schema]);
|
|
164
156
|
// get dashboards
|
|
165
|
-
const [dashboardOptions, setDashboardOptions] =
|
|
166
|
-
const [defaultDashboardName, setDefaultDashboardName] =
|
|
157
|
+
const [dashboardOptions, setDashboardOptions] = useState([]);
|
|
158
|
+
const [defaultDashboardName, setDefaultDashboardName] = useState(destinationDashboard ||
|
|
167
159
|
dashboardItem?.dashboardName ||
|
|
168
160
|
dashboardOptions[0]?.label);
|
|
169
|
-
|
|
161
|
+
useEffect(() => {
|
|
170
162
|
if (!destinationDashboard &&
|
|
171
163
|
!dashboardItem &&
|
|
172
164
|
dashboardOptions &&
|
|
@@ -174,31 +166,31 @@ function ChartBuilderForm({ TextInput = UiComponents_1.MemoizedTextInput, Select
|
|
|
174
166
|
setDefaultDashboardName(dashboardOptions[0]?.label);
|
|
175
167
|
}
|
|
176
168
|
}, [dashboardOptions]);
|
|
177
|
-
|
|
169
|
+
useEffect(() => {
|
|
178
170
|
async function getDashNames() {
|
|
179
|
-
const resp = await
|
|
171
|
+
const resp = await getDataFromCloud(client, `dashnames/${client.publicKey}/`, null, 'GET');
|
|
180
172
|
setDashboardOptions(resp.dashboardNames
|
|
181
173
|
.filter((elem) => elem !== null)
|
|
182
174
|
.map((key) => ({ label: key, value: key })));
|
|
183
175
|
}
|
|
184
176
|
getDashNames();
|
|
185
177
|
}, []);
|
|
186
|
-
const [showPivotPopover, setShowPivotPopover] =
|
|
187
|
-
const [isEdittingPivot, setIsEdittingPivot] =
|
|
188
|
-
const [selectedPivotIndex, setSelectedPivotIndex] =
|
|
189
|
-
const [tableName, setTableName] =
|
|
178
|
+
const [showPivotPopover, setShowPivotPopover] = useState(false);
|
|
179
|
+
const [isEdittingPivot, setIsEdittingPivot] = useState(false);
|
|
180
|
+
const [selectedPivotIndex, setSelectedPivotIndex] = useState(-1);
|
|
181
|
+
const [tableName, setTableName] = useState(null);
|
|
190
182
|
const selectedTable = schema?.find((t) => t.displayName === tableName);
|
|
191
|
-
const [pivotPopUpTitle, setPivotPopUpTitle] =
|
|
192
|
-
const [createdPivots, setCreatedPivots] =
|
|
193
|
-
const [recommendedPivots, setRecommendedPivots] =
|
|
194
|
-
const [pivotRowField, setPivotRowField] =
|
|
195
|
-
const [pivotColumnField, setPivotColumnField] =
|
|
196
|
-
const [pivotValueField, setPivotValueField] =
|
|
197
|
-
const [pivotAggregation, setPivotAggregation] =
|
|
183
|
+
const [pivotPopUpTitle, setPivotPopUpTitle] = useState('Add Pivot');
|
|
184
|
+
const [createdPivots, setCreatedPivots] = useState(pivot ? [pivot] : dashboardItem?.pivot ? [dashboardItem.pivot] : cp);
|
|
185
|
+
const [recommendedPivots, setRecommendedPivots] = useState(rp);
|
|
186
|
+
const [pivotRowField, setPivotRowField] = useState(undefined);
|
|
187
|
+
const [pivotColumnField, setPivotColumnField] = useState(undefined);
|
|
188
|
+
const [pivotValueField, setPivotValueField] = useState(undefined);
|
|
189
|
+
const [pivotAggregation, setPivotAggregation] = useState(undefined);
|
|
198
190
|
// initial state is the fields array passed in, but can eventually be changed to be the pivot fields
|
|
199
|
-
const [fieldOptions, setFieldOptions] =
|
|
200
|
-
const [dateFieldOptions, setDateFieldOptions] =
|
|
201
|
-
|
|
191
|
+
const [fieldOptions, setFieldOptions] = useState(fields);
|
|
192
|
+
const [dateFieldOptions, setDateFieldOptions] = useState([]);
|
|
193
|
+
useEffect(() => {
|
|
202
194
|
const fetchReferencedTables = async () => {
|
|
203
195
|
if (!query) {
|
|
204
196
|
return;
|
|
@@ -223,7 +215,7 @@ function ChartBuilderForm({ TextInput = UiComponents_1.MemoizedTextInput, Select
|
|
|
223
215
|
table: dateFieldOptions[0]?.name,
|
|
224
216
|
field: dateFieldOptions[0]?.columns[0]?.name,
|
|
225
217
|
};
|
|
226
|
-
const firstNumberColumn = columns?.find((col) =>
|
|
218
|
+
const firstNumberColumn = columns?.find((col) => numberFormatOptions.includes(col.format));
|
|
227
219
|
const formEmptyState = {
|
|
228
220
|
name: '',
|
|
229
221
|
dashboardName: dashboardOptions?.[0]?.label,
|
|
@@ -250,13 +242,13 @@ function ChartBuilderForm({ TextInput = UiComponents_1.MemoizedTextInput, Select
|
|
|
250
242
|
// date labels for pivots should be treated like strings since they are
|
|
251
243
|
// formatted in generatePivotTable
|
|
252
244
|
const yAxisIsDate = pivot.columnField
|
|
253
|
-
?
|
|
245
|
+
? isDateField(pivot.columnFieldType)
|
|
254
246
|
: false;
|
|
255
247
|
return {
|
|
256
248
|
pivot,
|
|
257
249
|
chartType: 'column',
|
|
258
250
|
xAxisField: pivot.rowField,
|
|
259
|
-
xAxisFormat:
|
|
251
|
+
xAxisFormat: isDateField(pivot.rowFieldType)
|
|
260
252
|
? 'string'
|
|
261
253
|
: columns.find((col) => col.field === pivot.rowField)?.format ||
|
|
262
254
|
'whole_number',
|
|
@@ -273,12 +265,12 @@ function ChartBuilderForm({ TextInput = UiComponents_1.MemoizedTextInput, Select
|
|
|
273
265
|
],
|
|
274
266
|
};
|
|
275
267
|
};
|
|
276
|
-
const [formData, setFormData] =
|
|
268
|
+
const [formData, setFormData] = useState(pivot
|
|
277
269
|
? { ...formEmptyState, ...pivotFormData(pivot) }
|
|
278
270
|
: dashboardItem || formEmptyState);
|
|
279
|
-
const selectedPivotTable =
|
|
271
|
+
const selectedPivotTable = useMemo(() => {
|
|
280
272
|
if (formData.pivot && rows) {
|
|
281
|
-
return
|
|
273
|
+
return generatePivotTable(formData.pivot, rows, dateRange);
|
|
282
274
|
}
|
|
283
275
|
else {
|
|
284
276
|
return {};
|
|
@@ -412,7 +404,7 @@ function ChartBuilderForm({ TextInput = UiComponents_1.MemoizedTextInput, Select
|
|
|
412
404
|
customerId: customerId,
|
|
413
405
|
}
|
|
414
406
|
: { clientId: publicKey }).toString();
|
|
415
|
-
const resp = await
|
|
407
|
+
const resp = await getDataFromCloud(client, `deletedash/${publicKey}/${customerId}/?${searchParams}`, cloudBody);
|
|
416
408
|
if (resp) {
|
|
417
409
|
if (onDelete) {
|
|
418
410
|
onDelete();
|
|
@@ -460,7 +452,7 @@ function ChartBuilderForm({ TextInput = UiComponents_1.MemoizedTextInput, Select
|
|
|
460
452
|
customerId: customerId,
|
|
461
453
|
}
|
|
462
454
|
: { clientId: publicKey }).toString();
|
|
463
|
-
const resp = await
|
|
455
|
+
const resp = await getData(client, `dashedit2?${searchParams}`, 'same-origin', hostedBody, cloudBody);
|
|
464
456
|
console.log(`RESP: ${resp}`);
|
|
465
457
|
if (resp) {
|
|
466
458
|
dispatch({
|
|
@@ -482,13 +474,13 @@ function ChartBuilderForm({ TextInput = UiComponents_1.MemoizedTextInput, Select
|
|
|
482
474
|
if (!schema) {
|
|
483
475
|
return;
|
|
484
476
|
}
|
|
485
|
-
return ((
|
|
477
|
+
return (_jsxs("div", { id: "quill-chart-modal", style: { padding: modalPadding }, children: [_jsx("div", { children: _jsx(Chart, { config: { ...formData, rows }, colors: theme.chartColors, containerStyle: {
|
|
486
478
|
width: formData.chartType === 'table' ? 640 : 'calc(100% - 24px)',
|
|
487
479
|
height: 300,
|
|
488
|
-
} }) }), (
|
|
480
|
+
} }) }), _jsx("div", { style: { height: 20 } }), _jsxs("form", { ref: parentRef, id: "quill-chart-form", onSubmit: handleSubmit, children: [_jsxs("div", { style: { display: 'flex', flexDirection: 'row', gap: 12 }, children: [_jsxs("div", { style: { display: 'flex', flexDirection: 'column' }, children: [_jsx(Label, { children: "Name" }), _jsx(TextInput, { value: formData.name, onChange: (e) => handleChange(e, 'name'), placeholder: "Name" })] }), showDashboardDropdown && !destinationDashboard && (_jsxs("div", { style: { display: 'flex', flexDirection: 'column' }, children: [_jsx(Label, { children: "Dashboard" }), _jsx(Select, { label: 'Dashboard', value: formData.dashboardName, onChange: (e) => handleChange(e, 'dashboardName'), options: dashboardOptions.map((elem) => ({
|
|
489
481
|
label: elem.label,
|
|
490
482
|
value: elem.label,
|
|
491
|
-
})) })] })), (
|
|
483
|
+
})) })] })), _jsxs("div", { style: { display: 'flex', flexDirection: 'column' }, children: [_jsx(Label, { children: "Chart type" }), _jsx(Select, { label: 'Chart Type', value: formData.chartType, onChange: (e) => handleChange(e, 'chartType'),
|
|
492
484
|
// filter out metric for all pivots
|
|
493
485
|
// filter out bar and pie for row and column pivot
|
|
494
486
|
options: CHART_TYPES.filter((elem) => !firstNumberColumn
|
|
@@ -496,21 +488,21 @@ function ChartBuilderForm({ TextInput = UiComponents_1.MemoizedTextInput, Select
|
|
|
496
488
|
: !((formData.pivot && elem === 'metric') ||
|
|
497
489
|
(formData.pivot &&
|
|
498
490
|
formData.pivot.columnField &&
|
|
499
|
-
(elem === 'bar' || elem === 'pie')))).map((elem) => ({ label: elem, value: elem })) })] })] }), (
|
|
491
|
+
(elem === 'bar' || elem === 'pie')))).map((elem) => ({ label: elem, value: elem })) })] })] }), _jsx("br", {}), _jsxs("div", { style: {
|
|
500
492
|
display: 'flex',
|
|
501
493
|
flexDirection: 'column',
|
|
502
494
|
gap: 12,
|
|
503
495
|
marginTop: 6,
|
|
504
|
-
}, children: [(
|
|
496
|
+
}, children: [_jsx(Header, { children: "Pivot" }), _jsxs("div", { style: { fontFamily: theme?.fontFamily }, children: [_jsx("div", { style: {
|
|
505
497
|
maxWidth: 200,
|
|
506
498
|
// marginTop: 6,
|
|
507
499
|
display: 'flex',
|
|
508
500
|
flexDirection: 'column',
|
|
509
|
-
}, children: (
|
|
501
|
+
}, children: _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: selectedTable, SelectComponent: Select, ButtonComponent: Button, PopoverComponent: Popover, LabelComponent: Label, TextComponent: Text, HeaderComponent: Header, theme: theme, isOpen: showPivotPopover, setIsOpen: setShowPivotPopover, showUpdatePivot: isEdittingPivot, setShowUpdatePivot: setIsEdittingPivot, parentRef: parentRef, data: rows, columns: columns, triggerButtonText: 'Add pivot +', selectedPivotIndex: selectedPivotIndex, setSelectedPivotIndex: setSelectedPivotIndex, removePivot: handleDeletePivot, selectPivot: handleAddPivot, dateRange: dateRange, selectPivotOnEdit: true, showTrigger: !formData.pivot }) }), formData.pivot && (_jsx("div", { style: {
|
|
510
502
|
// width: 592,
|
|
511
503
|
paddingRight: deleteRef?.current ? 42 : 0,
|
|
512
504
|
maxWidth: 750,
|
|
513
|
-
}, children: (
|
|
505
|
+
}, children: _jsx("div", { style: { width: divWidth }, children: _jsx(PivotCard, { pivotTable: {
|
|
514
506
|
pivot: formData.pivot,
|
|
515
507
|
rows: selectedPivotTable?.rows,
|
|
516
508
|
columns: selectedPivotTable?.columns,
|
|
@@ -522,23 +514,23 @@ function ChartBuilderForm({ TextInput = UiComponents_1.MemoizedTextInput, Select
|
|
|
522
514
|
setPivotValueField(formData.pivot?.valueField);
|
|
523
515
|
setPivotAggregation(formData.pivot?.aggregationType);
|
|
524
516
|
setPivotPopUpTitle('Edit Pivot');
|
|
525
|
-
}, selectedPivotIndex: -1, onEditPivot: () => { }, ButtonComponent: Button, HeaderComponent: Header, showEdit: false, onClose: handleDeletePivot, minHeight: 180, LabelComponent: Label, TextComponent: Text }) }) }))] })] }), (
|
|
517
|
+
}, selectedPivotIndex: -1, onEditPivot: () => { }, ButtonComponent: Button, HeaderComponent: Header, showEdit: false, onClose: handleDeletePivot, minHeight: 180, LabelComponent: Label, TextComponent: Text }) }) }))] })] }), _jsx("br", {}), (formData.pivot || formData.chartType !== 'table') && (_jsxs("div", { children: [_jsxs("div", { style: {
|
|
526
518
|
display: 'flex',
|
|
527
519
|
flexDirection: 'column',
|
|
528
520
|
gap: 6,
|
|
529
521
|
marginTop: 6,
|
|
530
|
-
}, children: [(
|
|
522
|
+
}, children: [_jsx(Header, { children: "Chart" }), _jsx(Label, { children: "X-axis" })] }), _jsxs("div", { style: { display: 'flex', flexDirection: 'row', gap: 12 }, children: [_jsx(Select, { label: 'X-axis Field', value: formData.xAxisField, onChange: (e) => handleChange(e, 'xAxisField'), disabled: formData.pivot !== null, options: fieldOptions.map((elem) => ({
|
|
531
523
|
label: formData.pivot
|
|
532
524
|
? `pivot row (${elem.field})`
|
|
533
525
|
: elem.field,
|
|
534
526
|
value: elem.field,
|
|
535
|
-
})) }), (
|
|
527
|
+
})) }), _jsx(TextInput, { value: formData.xAxisLabel, placeholder: "Column Label", onChange: (e) => handleChange(e, 'xAxisLabel') }), _jsx(Select, { label: 'X-axis Format', value: formData.xAxisFormat, onChange: (e) => handleChange(e, 'xAxisFormat'), options: formatOptions })] }, 'xAxisField0'), _jsx("br", {}), _jsx(Label, { children: "Y-axis" }), _jsx("div", { style: { display: 'flex', flexDirection: 'column', gap: 10 }, children: formData.yAxisFields.map((yAxisField, index) => (_jsxs("div", { style: { display: 'flex', flexDirection: 'row', gap: 12 }, children: [_jsx(Select, { label: 'Y-axis Field', value: yAxisField.field, onChange: (e) => handleChange(e, 'yAxisFields.field', index), disabled: formData.pivot !== null, options: [
|
|
536
528
|
{ label: 'Select', value: '' },
|
|
537
529
|
...fieldOptions
|
|
538
530
|
.filter((elem) => {
|
|
539
531
|
return (formData.chartType === 'table' ||
|
|
540
532
|
formData.pivot ||
|
|
541
|
-
|
|
533
|
+
numberFormatOptions.includes(columns.find((col) => col.field === elem.field)
|
|
542
534
|
?.format));
|
|
543
535
|
})
|
|
544
536
|
.map((elem) => ({
|
|
@@ -547,28 +539,28 @@ function ChartBuilderForm({ TextInput = UiComponents_1.MemoizedTextInput, Select
|
|
|
547
539
|
: elem.field,
|
|
548
540
|
value: elem.field,
|
|
549
541
|
})),
|
|
550
|
-
] }), (
|
|
542
|
+
] }), _jsx(TextInput, { value: yAxisField.label, placeholder: "Column Label", onChange: (e) => handleChange(e, 'yAxisFields.label', index) }), _jsx(Select, { label: 'Y-axis Format', value: yAxisField.format, onChange: (e) => handleChange(e, 'yAxisFields.format', index), options: [{ label: 'Select', value: '' }, ...formatOptions] }), formData.pivot === null && (_jsx("div", { ref: deleteRef, children: _jsx(DeleteButton, { style: { marginLeft: deleteButtonMargin }, onClick: () => handleRemoveField('yAxisFields', index) }) }))] }, 'yAxisField' + index))) }), formData.pivot === null && (_jsxs(_Fragment, { children: [_jsx("br", {}), _jsx(SecondaryButton, { onClick: () => handleAddField('yAxisFields'), label: "Add field +" })] })), _jsx("br", {}), _jsx("br", {})] })), (showTableFormatOptions || formData.chartType === 'table') && (_jsxs("div", { children: [_jsxs("div", { style: {
|
|
551
543
|
display: 'flex',
|
|
552
544
|
flexDirection: 'column',
|
|
553
545
|
gap: 6,
|
|
554
546
|
marginTop: 6,
|
|
555
|
-
}, children: [(
|
|
547
|
+
}, children: [_jsx(Header, { children: "Table" }), _jsx(Label, { children: "Columns" })] }), _jsx("div", { style: { display: 'flex', flexDirection: 'column', gap: 10 }, children: formData.columns.map((column, index) => (_jsxs("div", { style: { display: 'flex', flexDirection: 'row', gap: 12 }, children: [_jsx(Select, { label: 'Column Field', value: column.field, onChange: (e) => handleChange(e, 'columns.field', index), options: [
|
|
556
548
|
{ label: 'Select', value: '' },
|
|
557
549
|
...fields.map((elem) => ({
|
|
558
550
|
label: elem.field,
|
|
559
551
|
value: elem.field,
|
|
560
552
|
})),
|
|
561
|
-
] }), (
|
|
553
|
+
] }), _jsx(TextInput, { name: "label", value: column.label, placeholder: "Column Label", onChange: (e) => handleChange(e, 'columns.label', index) }), _jsx(Select, { label: 'Column Format', value: column.format, onChange: (e) => handleChange(e, 'columns.format', index), options: [{ label: 'Select', value: '' }, ...formatOptions] }), _jsx("div", { ref: deleteRef, children: _jsx(DeleteButton, { style: { marginLeft: deleteButtonMargin }, onClick: () => handleRemoveField('columns', index) }) })] }, 'column' + index))) }), _jsx("br", {}), _jsx(SecondaryButton, { onClick: () => handleAddField('columns'), label: "Add column +" }), _jsx("br", {}), _jsx("br", {})] })), showDateFieldOptions && (_jsxs("div", { style: {
|
|
562
554
|
display: 'flex',
|
|
563
555
|
flexDirection: 'column',
|
|
564
556
|
gap: 6,
|
|
565
557
|
marginTop: 6,
|
|
566
|
-
}, children: [(
|
|
558
|
+
}, children: [_jsx(Header, { children: "Date field" }), _jsxs("div", { style: {
|
|
567
559
|
display: 'flex',
|
|
568
560
|
flexDirection: 'row',
|
|
569
561
|
gap: 12,
|
|
570
562
|
// lmao part 2
|
|
571
|
-
}, children: [(
|
|
563
|
+
}, children: [_jsxs("div", { style: { display: 'flex', flexDirection: 'column' }, children: [_jsx(Label, { children: "Table" }), _jsx(Select, { label: 'Date Table', value: formData.dateField.table, onChange: (e) => handleChange(e, 'dateField.table'), options: [
|
|
572
564
|
{
|
|
573
565
|
label: 'Select',
|
|
574
566
|
value: '',
|
|
@@ -577,29 +569,29 @@ function ChartBuilderForm({ TextInput = UiComponents_1.MemoizedTextInput, Select
|
|
|
577
569
|
label: elem.name,
|
|
578
570
|
value: elem.name,
|
|
579
571
|
})),
|
|
580
|
-
] })] }), (
|
|
572
|
+
] })] }), _jsxs("div", { style: { display: 'flex', flexDirection: 'column' }, children: [_jsx(Label, { children: "Field" }), _jsx(Select, { label: 'Date Field', value: formData.dateField.field, onChange: (e) => handleChange(e, 'dateField.field'), options: dateFieldOptions
|
|
581
573
|
?.find((elem) => elem.name === formData.dateField.table)
|
|
582
574
|
?.columns?.map((elem) => ({
|
|
583
575
|
label: elem.name,
|
|
584
576
|
value: elem.name,
|
|
585
|
-
})) || [] })] })] }), (
|
|
577
|
+
})) || [] })] })] }), _jsx("br", {})] })), showAccessControlOptions && (_jsxs("div", { style: {
|
|
586
578
|
display: 'flex',
|
|
587
579
|
flexDirection: 'column',
|
|
588
580
|
gap: 12,
|
|
589
581
|
marginTop: 6,
|
|
590
|
-
}, children: [(
|
|
582
|
+
}, children: [_jsx(Header, { children: "Organization access" }), _jsx(SegmentedControl, { onChange: (e) => handleChange(e, 'template'), value: formData.template, theme: theme }), _jsx("br", {}), _jsx("br", {})] })), _jsxs("div", { style: {
|
|
591
583
|
display: 'flex',
|
|
592
584
|
flexDirection: 'row',
|
|
593
585
|
justifyContent: 'flex-end',
|
|
594
586
|
gap: 10,
|
|
595
|
-
}, children: [dashboardItem && ((
|
|
587
|
+
}, children: [dashboardItem && (_jsx(SecondaryButton, { onClick: deleteChart, label: 'Delete' })), _jsx(Button, { onClick: editChart, label: buttonLabel
|
|
596
588
|
? buttonLabel
|
|
597
589
|
: dashboardItem
|
|
598
590
|
? 'Save changes'
|
|
599
591
|
: 'Add to dashboard' })] })] })] }));
|
|
600
592
|
}
|
|
601
593
|
function SegmentedControl({ onChange, value, theme }) {
|
|
602
|
-
return ((
|
|
594
|
+
return (_jsxs("div", { style: {
|
|
603
595
|
display: 'flex',
|
|
604
596
|
flexDirection: 'row',
|
|
605
597
|
alignItems: 'center',
|
|
@@ -607,7 +599,7 @@ function SegmentedControl({ onChange, value, theme }) {
|
|
|
607
599
|
maxWidth: 418,
|
|
608
600
|
padding: 4,
|
|
609
601
|
borderRadius: 6,
|
|
610
|
-
}, children: [(
|
|
602
|
+
}, children: [_jsxs("button", { className: "quill-tab", onClick: () => onChange(true), style: {
|
|
611
603
|
border: value === true ? '1px solid #E7E7E7' : '1px solid transparent',
|
|
612
604
|
outline: 'none',
|
|
613
605
|
width: '100%',
|
|
@@ -620,7 +612,7 @@ function SegmentedControl({ onChange, value, theme }) {
|
|
|
620
612
|
fontWeight: value === true ? 600 : 500,
|
|
621
613
|
fontSize: 14,
|
|
622
614
|
fontFamily: theme?.fontFamily,
|
|
623
|
-
}, children: [(
|
|
615
|
+
}, children: [_jsx("style", { children: `
|
|
624
616
|
.quill-tab {
|
|
625
617
|
background-color: ${value === true ? 'white' : 'transparent'};
|
|
626
618
|
}
|
|
@@ -630,7 +622,7 @@ function SegmentedControl({ onChange, value, theme }) {
|
|
|
630
622
|
.quill-tab:active {
|
|
631
623
|
background-color: "rgba(56, 65, 81, 0.15)";
|
|
632
624
|
}
|
|
633
|
-
` }), 'All Organizations'] }), (
|
|
625
|
+
` }), 'All Organizations'] }), _jsxs("button", { className: "quill-tab2", onClick: () => onChange(false), style: {
|
|
634
626
|
border: value === false ? '1px solid #E7E7E7' : '1px solid transparent',
|
|
635
627
|
boxShadow: value === false
|
|
636
628
|
? '0px 1px 4px 0px rgba(56, 65, 81, 0.08)'
|
|
@@ -643,7 +635,7 @@ function SegmentedControl({ onChange, value, theme }) {
|
|
|
643
635
|
fontWeight: value === false ? 600 : 500,
|
|
644
636
|
fontSize: 14,
|
|
645
637
|
fontFamily: theme?.fontFamily,
|
|
646
|
-
}, children: [(
|
|
638
|
+
}, children: [_jsx("style", { children: `
|
|
647
639
|
.quill-tab2 {
|
|
648
640
|
background-color: ${value === false ? 'white' : 'transparent'};
|
|
649
641
|
}
|
package/dist/ChartEditor.js
CHANGED
|
@@ -1,25 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
2
|
// @ts-nocheck
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function ChartEditor({ isOpen, chartId, admin = false, destinationDashboard, chartBuilderTitle = 'Edit chart', chartBuilderButtonLabel, onDelete, setIsOpen, Select, TextInput, Button, SecondaryButton, Header, Label, Text, DeleteButton, Modal, Popover, }) {
|
|
13
|
-
const { dispatch, dashboard } =
|
|
14
|
-
const { dashboardFilters } =
|
|
15
|
-
const [client, _] =
|
|
16
|
-
const [dashboardItem, setDashboardItem] =
|
|
17
|
-
const [isLoading, setIsLoading] =
|
|
3
|
+
import { useContext, useEffect, useState } from 'react';
|
|
4
|
+
import ChartBuilder from './ChartBuilder';
|
|
5
|
+
import { DashboardContext, DashboardFiltersContext, ClientContext, } from './Context';
|
|
6
|
+
import { getData } from './utils/dataFetcher';
|
|
7
|
+
export default function ChartEditor({ isOpen, chartId, admin = false, destinationDashboard, chartBuilderTitle = 'Edit chart', chartBuilderButtonLabel, onDelete, setIsOpen, Select, TextInput, Button, SecondaryButton, Header, Label, Text, DeleteButton, Modal, Popover, }) {
|
|
8
|
+
const { dispatch, dashboard } = useContext(DashboardContext);
|
|
9
|
+
const { dashboardFilters } = useContext(DashboardFiltersContext);
|
|
10
|
+
const [client, _] = useContext(ClientContext);
|
|
11
|
+
const [dashboardItem, setDashboardItem] = useState(dashboard?.[chartId]);
|
|
12
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
18
13
|
const dateFilter = Object.values(dashboardFilters).find((filter) => filter.filterType == 'date_range');
|
|
19
14
|
const dateRange = dateFilter?.startDate
|
|
20
15
|
? [dateFilter?.startDate, dateFilter?.endDate, null]
|
|
21
16
|
: [null, null, null];
|
|
22
|
-
|
|
17
|
+
useEffect(() => {
|
|
23
18
|
let isSubscribed = true;
|
|
24
19
|
async function getChartOptions() {
|
|
25
20
|
if (isSubscribed && !isLoading) {
|
|
@@ -45,7 +40,7 @@ function ChartEditor({ isOpen, chartId, admin = false, destinationDashboard, cha
|
|
|
45
40
|
id: chartId,
|
|
46
41
|
filters: [],
|
|
47
42
|
};
|
|
48
|
-
const resp = await
|
|
43
|
+
const resp = await getData(client, 'itempost', 'omit', hostedBody, cloudBody);
|
|
49
44
|
if (resp) {
|
|
50
45
|
setDashboardItem(resp);
|
|
51
46
|
dispatch({
|
|
@@ -71,6 +66,5 @@ function ChartEditor({ isOpen, chartId, admin = false, destinationDashboard, cha
|
|
|
71
66
|
isSubscribed = false;
|
|
72
67
|
};
|
|
73
68
|
}, [client, chartId]);
|
|
74
|
-
return ((
|
|
69
|
+
return (_jsx("div", { children: dashboardItem && (_jsx(ChartBuilder, { dashboardItem: dashboardItem, rows: dashboardItem.rows, columns: dashboardItem.columns, fields: dashboardItem.fields, query: dashboardItem.queryString, isOpen: isOpen, setIsOpen: setIsOpen, showTableFormatOptions: admin, showDateFieldOptions: admin, showAccessControlOptions: admin, showDashboardDropdown: admin, destinationDashboard: destinationDashboard, dateRange: dateRange, Select: Select, TextInput: TextInput, Button: Button, SecondaryButton: SecondaryButton, Header: Header, Label: Label, Text: Text, DeleteButton: DeleteButton, Modal: Modal, Popover: Popover, onDelete: onDelete, title: chartBuilderTitle, buttonLabel: chartBuilderButtonLabel })) }));
|
|
75
70
|
}
|
|
76
|
-
exports.default = ChartEditor;
|