@quillsql/react 2.10.16 → 2.10.18
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/ChartEditor.d.ts.map +1 -1
- package/dist/cjs/Dashboard.d.ts +26 -18
- package/dist/cjs/Dashboard.d.ts.map +1 -1
- package/dist/cjs/Dashboard.js +86 -478
- package/dist/cjs/DateRangePicker/QuillDateRangePicker.d.ts +3 -0
- package/dist/cjs/DateRangePicker/QuillDateRangePicker.d.ts.map +1 -0
- package/dist/cjs/DateRangePicker/QuillDateRangePicker.js +260 -0
- package/dist/cjs/DateRangePicker/dateRangePickerUtils.d.ts +20 -1
- package/dist/cjs/DateRangePicker/dateRangePickerUtils.d.ts.map +1 -1
- package/dist/cjs/DateRangePicker/dateRangePickerUtils.js +93 -4
- package/dist/cjs/QuillProvider.d.ts +1 -0
- package/dist/cjs/QuillProvider.d.ts.map +1 -1
- package/dist/cjs/QuillProvider.js +1 -0
- package/dist/cjs/ReportBuilder.d.ts.map +1 -1
- package/dist/cjs/ReportBuilder.js +1 -2
- package/dist/cjs/components/Dashboard/DataLoader.d.ts.map +1 -1
- package/dist/cjs/components/Dashboard/DataLoader.js +11 -0
- package/dist/cjs/components/QuillSelect.d.ts +3 -0
- package/dist/cjs/components/QuillSelect.d.ts.map +1 -0
- package/dist/cjs/components/QuillSelect.js +109 -0
- package/dist/cjs/components/UiComponents.d.ts +1 -0
- package/dist/cjs/components/UiComponents.d.ts.map +1 -1
- package/dist/cjs/index.d.ts +1 -2
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -3
- package/dist/cjs/internals/ReportBuilder/PivotModal.d.ts.map +1 -1
- package/dist/cjs/internals/ReportBuilder/PivotModal.js +9 -0
- package/dist/cjs/utils/aggregate.js +2 -2
- package/dist/cjs/utils/dashboard.d.ts +2 -2
- package/dist/cjs/utils/dashboard.d.ts.map +1 -1
- package/dist/cjs/utils/dashboard.js +26 -2
- package/dist/esm/ChartEditor.d.ts.map +1 -1
- package/dist/esm/Dashboard.d.ts +26 -18
- package/dist/esm/Dashboard.d.ts.map +1 -1
- package/dist/esm/Dashboard.js +84 -475
- package/dist/esm/DateRangePicker/QuillDateRangePicker.d.ts +3 -0
- package/dist/esm/DateRangePicker/QuillDateRangePicker.d.ts.map +1 -0
- package/dist/esm/DateRangePicker/QuillDateRangePicker.js +256 -0
- package/dist/esm/DateRangePicker/dateRangePickerUtils.d.ts +20 -1
- package/dist/esm/DateRangePicker/dateRangePickerUtils.d.ts.map +1 -1
- package/dist/esm/DateRangePicker/dateRangePickerUtils.js +91 -3
- package/dist/esm/QuillProvider.d.ts +1 -0
- package/dist/esm/QuillProvider.d.ts.map +1 -1
- package/dist/esm/QuillProvider.js +1 -0
- package/dist/esm/ReportBuilder.d.ts.map +1 -1
- package/dist/esm/ReportBuilder.js +0 -1
- package/dist/esm/components/Dashboard/DataLoader.d.ts.map +1 -1
- package/dist/esm/components/Dashboard/DataLoader.js +11 -0
- package/dist/esm/components/QuillSelect.d.ts +3 -0
- package/dist/esm/components/QuillSelect.d.ts.map +1 -0
- package/dist/esm/components/QuillSelect.js +105 -0
- package/dist/esm/components/UiComponents.d.ts +1 -0
- package/dist/esm/components/UiComponents.d.ts.map +1 -1
- package/dist/esm/index.d.ts +1 -2
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +0 -1
- package/dist/esm/internals/ReportBuilder/PivotModal.d.ts.map +1 -1
- package/dist/esm/internals/ReportBuilder/PivotModal.js +10 -1
- package/dist/esm/utils/aggregate.js +1 -1
- package/dist/esm/utils/dashboard.d.ts +2 -2
- package/dist/esm/utils/dashboard.d.ts.map +1 -1
- package/dist/esm/utils/dashboard.js +26 -2
- package/package.json +1 -1
- package/dist/cjs/AddToDashboardModal.d.ts +0 -82
- package/dist/cjs/AddToDashboardModal.d.ts.map +0 -1
- package/dist/cjs/AddToDashboardModal.js +0 -1469
- package/dist/esm/AddToDashboardModal.d.ts +0 -82
- package/dist/esm/AddToDashboardModal.d.ts.map +0 -1
- package/dist/esm/AddToDashboardModal.js +0 -1435
|
@@ -1,1435 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
// @ts-nocheck
|
|
3
|
-
import React, { useContext, useEffect, useState } from 'react';
|
|
4
|
-
import { sub, startOfToday, endOfToday } from 'date-fns';
|
|
5
|
-
import { getData, getDataFromCloud } from './utils/dataFetcher';
|
|
6
|
-
import { ClientContext, SchemaContext, ThemeContext, DateFilterContext, DashboardContext, DashboardFiltersContext, } from './Context';
|
|
7
|
-
import { differenceInDays, differenceInHours, differenceInMonths, differenceInYears, startOfDay, startOfHour, startOfMonth, startOfYear, } from 'date-fns';
|
|
8
|
-
import Chart from './Chart';
|
|
9
|
-
import { getPostgresBasicType } from './ReportBuilder';
|
|
10
|
-
import { aggregate } from './utils/aggregate';
|
|
11
|
-
import { ArrowDownHeadIcon } from './assets';
|
|
12
|
-
import { mergeComparisonRange } from './utils/merge';
|
|
13
|
-
function convertPostgresColumn(column) {
|
|
14
|
-
let format;
|
|
15
|
-
switch (column.dataTypeID) {
|
|
16
|
-
case 20: // int8
|
|
17
|
-
case 21: // int2
|
|
18
|
-
case 23: // int4
|
|
19
|
-
format = 'whole_number';
|
|
20
|
-
break;
|
|
21
|
-
case 700: // float4
|
|
22
|
-
case 701: // float8
|
|
23
|
-
case 1700: // numeric
|
|
24
|
-
format = 'two_decimal_places';
|
|
25
|
-
break;
|
|
26
|
-
case 1082: // date
|
|
27
|
-
case 1083: // time
|
|
28
|
-
case 1184: // timestamptz
|
|
29
|
-
case 1114: // timestamp
|
|
30
|
-
format = 'MMM_dd_yyyy';
|
|
31
|
-
break;
|
|
32
|
-
case 1043: // varchar
|
|
33
|
-
default:
|
|
34
|
-
format = 'string';
|
|
35
|
-
}
|
|
36
|
-
return {
|
|
37
|
-
label: column.name,
|
|
38
|
-
field: column.field,
|
|
39
|
-
format: format,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
function updateLabels(yAxisFields, values) {
|
|
43
|
-
return yAxisFields.map((item, index) => {
|
|
44
|
-
const updatedItem = { ...item };
|
|
45
|
-
if (values[`yAxisLabel-${index}`]) {
|
|
46
|
-
updatedItem.label = values[`yAxisLabel-${index}`];
|
|
47
|
-
}
|
|
48
|
-
if (values[`yAxisField-${index}`]) {
|
|
49
|
-
updatedItem.field = values[`yAxisField-${index}`];
|
|
50
|
-
}
|
|
51
|
-
if (values[`yAxisFormat-${index}`]) {
|
|
52
|
-
updatedItem.format = values[`yAxisFormat-${index}`];
|
|
53
|
-
}
|
|
54
|
-
return updatedItem;
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
const DefaultSelectComponent = function DefaultSelect({ onChange, value, options, form, field, theme, }) {
|
|
58
|
-
return (_jsxs("div", { style: { position: 'relative' }, children: [_jsx("select", { onChange: (event) => onChange(event.target.value), value: value, id: 'reportbuilderdropdown', style: {
|
|
59
|
-
width: 200,
|
|
60
|
-
outline: 'none',
|
|
61
|
-
textAlign: 'left',
|
|
62
|
-
whiteSpace: 'nowrap',
|
|
63
|
-
overflow: 'hidden',
|
|
64
|
-
textOverflow: 'ellipsis',
|
|
65
|
-
WebkitAppearance: 'none',
|
|
66
|
-
borderRadius: 6,
|
|
67
|
-
paddingLeft: 12,
|
|
68
|
-
paddingRight: 12,
|
|
69
|
-
height: 38,
|
|
70
|
-
borderWidth: theme.borderWidth,
|
|
71
|
-
borderColor: theme.borderColor,
|
|
72
|
-
boxSizing: 'border-box',
|
|
73
|
-
background: theme.backgroundColor,
|
|
74
|
-
color: theme.primaryTextColor,
|
|
75
|
-
boxShadow: '0 1px 2px 0 rgba(0,0,0,.05)',
|
|
76
|
-
fontFamily: theme.fontFamily,
|
|
77
|
-
}, children: options.map((option, index) => (_jsx("option", { value: option.value, children: option.label }, option.label + index))) }), _jsx(ArrowDownHeadIcon, { style: {
|
|
78
|
-
height: '20px',
|
|
79
|
-
width: '20px',
|
|
80
|
-
flex: 'none',
|
|
81
|
-
position: 'absolute',
|
|
82
|
-
right: 8,
|
|
83
|
-
top: 9,
|
|
84
|
-
color: theme?.secondaryTextColor,
|
|
85
|
-
}, "aria-hidden": "true" })] }));
|
|
86
|
-
};
|
|
87
|
-
const MemoizedDefaultSelectComponent = React.memo(DefaultSelectComponent);
|
|
88
|
-
const DefaultTextInputComponent = function DefaultText({ onChange, value, id, theme, placeholder, }) {
|
|
89
|
-
return (_jsx("input", { style: {
|
|
90
|
-
outline: 'none',
|
|
91
|
-
textAlign: 'left',
|
|
92
|
-
whiteSpace: 'nowrap',
|
|
93
|
-
overflow: 'hidden',
|
|
94
|
-
textOverflow: 'ellipsis',
|
|
95
|
-
borderRadius: 6,
|
|
96
|
-
paddingLeft: 12,
|
|
97
|
-
paddingRight: 12,
|
|
98
|
-
margin: 0,
|
|
99
|
-
paddingTop: 0,
|
|
100
|
-
paddingBottom: 0,
|
|
101
|
-
boxSizing: 'border-box',
|
|
102
|
-
width: 200,
|
|
103
|
-
height: 38,
|
|
104
|
-
borderWidth: theme.borderWidth,
|
|
105
|
-
borderColor: theme.borderColor,
|
|
106
|
-
borderStyle: 'solid',
|
|
107
|
-
background: theme.backgroundColor,
|
|
108
|
-
color: theme.primaryTextColor,
|
|
109
|
-
boxShadow: '0 1px 2px 0 rgba(0,0,0,.05)',
|
|
110
|
-
fontFamily: theme.fontFamily,
|
|
111
|
-
}, id: id, onChange: onChange, value: value, placeholder: placeholder }));
|
|
112
|
-
};
|
|
113
|
-
const MemoizedDefaultTextInputComponent = React.memo(DefaultTextInputComponent);
|
|
114
|
-
export default function AddToDashboardModal({ isOpen, setIsOpen, SelectComponent, TextInputComponent, ButtonComponent, SecondaryButtonComponent, rows, columns, query, report, ModalComponent, formHeaderStyle, formLabelStyle, showTableFormatOptions = false, showDateFieldOptions = false, showAccessControlOptions = false, onAddToDashboardComplete, fields, }) {
|
|
115
|
-
const [theme] = useContext(ThemeContext);
|
|
116
|
-
const [client] = useContext(ClientContext);
|
|
117
|
-
const [schema, setSchema] = useContext(SchemaContext);
|
|
118
|
-
// const [organization, setOrganization] = useState([]);
|
|
119
|
-
const { dispatch } = useContext(DashboardContext);
|
|
120
|
-
const { dashboardFilters } = useContext(DashboardFiltersContext);
|
|
121
|
-
// showTableFormatOptions = false;
|
|
122
|
-
// showDateFieldOptions = false;
|
|
123
|
-
// showAccessControlOptions = false;3
|
|
124
|
-
useEffect(() => {
|
|
125
|
-
let isSubscribed = true;
|
|
126
|
-
async function getSchema() {
|
|
127
|
-
if (!schema || !schema.length) {
|
|
128
|
-
const { queryEndpoint, queryHeaders, publicKey } = client;
|
|
129
|
-
const response = await fetch(`${queryEndpoint}`, {
|
|
130
|
-
method: 'POST',
|
|
131
|
-
headers: {
|
|
132
|
-
...queryHeaders,
|
|
133
|
-
'Content-Type': 'application/json',
|
|
134
|
-
},
|
|
135
|
-
body: JSON.stringify({
|
|
136
|
-
metadata: {
|
|
137
|
-
clientId: publicKey,
|
|
138
|
-
publicKey: publicKey,
|
|
139
|
-
task: 'schema',
|
|
140
|
-
},
|
|
141
|
-
}),
|
|
142
|
-
});
|
|
143
|
-
const data = await response.json();
|
|
144
|
-
if (isSubscribed) {
|
|
145
|
-
setSchema(data.data.tables);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
if (isSubscribed) {
|
|
150
|
-
getSchema();
|
|
151
|
-
}
|
|
152
|
-
return () => {
|
|
153
|
-
isSubscribed = false;
|
|
154
|
-
};
|
|
155
|
-
}, [schema]);
|
|
156
|
-
const editChart = async ({ report, setIsSubmitting, values, yAxisFields, columns, query, buckets, showTableFormatOptions, }) => {
|
|
157
|
-
const { publicKey, customerId, databaseType } = client;
|
|
158
|
-
const { xAxisLabel, chartName, chartType, xAxisField, xAxisFormat, dashboardName, dateFieldTable, dateField, template, } = values;
|
|
159
|
-
if (!chartName) {
|
|
160
|
-
alert('Please enter a chart name');
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
if (!dashboardName) {
|
|
164
|
-
alert('Please choose a dashboard name');
|
|
165
|
-
return;
|
|
166
|
-
}
|
|
167
|
-
if (!xAxisLabel && chartType !== 'pie' && chartType !== 'table') {
|
|
168
|
-
alert('Please enter a label for the x-axis');
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
if (!xAxisField) {
|
|
172
|
-
alert('Please enter a label for the x-axis');
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
if (!yAxisFields.map((field) => field.label).every(Boolean) &&
|
|
176
|
-
chartType !== 'pie' &&
|
|
177
|
-
chartType !== 'table') {
|
|
178
|
-
alert('Please enter a label for the y-axis');
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
if (!columns.map((yAxisField, _) => yAxisField.label).every(Boolean) &&
|
|
182
|
-
showTableFormatOptions &&
|
|
183
|
-
chartType !== 'table') {
|
|
184
|
-
alert('Please enter a label for the table y-axis');
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
setIsSubmitting(true);
|
|
188
|
-
if (!client) {
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
let defaultDateField;
|
|
192
|
-
if (!showDateFieldOptions) {
|
|
193
|
-
const result = await getReferencedTables(client, query, schema);
|
|
194
|
-
defaultDateField = {
|
|
195
|
-
table: result[0].name,
|
|
196
|
-
field: result[0].columns[0].name,
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
const hostedBody = {
|
|
200
|
-
metadata: customerId
|
|
201
|
-
? report
|
|
202
|
-
? {
|
|
203
|
-
dashboardItemId: report._id,
|
|
204
|
-
name: chartName,
|
|
205
|
-
xAxisField,
|
|
206
|
-
yAxisFields,
|
|
207
|
-
xAxisLabel,
|
|
208
|
-
xAxisFormat,
|
|
209
|
-
chartType,
|
|
210
|
-
dashboardName,
|
|
211
|
-
columns: showTableFormatOptions && chartType !== 'table'
|
|
212
|
-
? columns
|
|
213
|
-
: [
|
|
214
|
-
...yAxisFields,
|
|
215
|
-
{
|
|
216
|
-
field: xAxisField,
|
|
217
|
-
label: xAxisLabel,
|
|
218
|
-
format: xAxisFormat,
|
|
219
|
-
},
|
|
220
|
-
],
|
|
221
|
-
dateField: showDateFieldOptions
|
|
222
|
-
? { table: dateFieldTable, field: dateField }
|
|
223
|
-
: defaultDateField,
|
|
224
|
-
query: query,
|
|
225
|
-
task: 'create',
|
|
226
|
-
orgId: customerId,
|
|
227
|
-
template: template,
|
|
228
|
-
buckets,
|
|
229
|
-
clientId: publicKey,
|
|
230
|
-
databaseType: databaseType,
|
|
231
|
-
}
|
|
232
|
-
: {
|
|
233
|
-
name: chartName,
|
|
234
|
-
xAxisField,
|
|
235
|
-
yAxisFields,
|
|
236
|
-
xAxisLabel,
|
|
237
|
-
xAxisFormat,
|
|
238
|
-
chartType,
|
|
239
|
-
dashboardName,
|
|
240
|
-
columns: showTableFormatOptions && chartType !== 'table'
|
|
241
|
-
? columns
|
|
242
|
-
: [...yAxisFields],
|
|
243
|
-
dateField: showDateFieldOptions
|
|
244
|
-
? { table: dateFieldTable, field: dateField }
|
|
245
|
-
: defaultDateField,
|
|
246
|
-
query: query,
|
|
247
|
-
task: 'create',
|
|
248
|
-
orgId: customerId,
|
|
249
|
-
template: template,
|
|
250
|
-
buckets,
|
|
251
|
-
clientId: publicKey,
|
|
252
|
-
databaseType: databaseType,
|
|
253
|
-
}
|
|
254
|
-
: {
|
|
255
|
-
name: chartName,
|
|
256
|
-
xAxisField,
|
|
257
|
-
yAxisFields,
|
|
258
|
-
xAxisLabel,
|
|
259
|
-
xAxisFormat,
|
|
260
|
-
chartType,
|
|
261
|
-
dashboardName,
|
|
262
|
-
columns: showTableFormatOptions && chartType !== 'table'
|
|
263
|
-
? columns
|
|
264
|
-
: [
|
|
265
|
-
...yAxisFields,
|
|
266
|
-
{
|
|
267
|
-
field: xAxisField,
|
|
268
|
-
label: xAxisLabel,
|
|
269
|
-
format: xAxisFormat,
|
|
270
|
-
},
|
|
271
|
-
],
|
|
272
|
-
dateField: showDateFieldOptions
|
|
273
|
-
? { table: dateFieldTable, field: dateField }
|
|
274
|
-
: defaultDateField,
|
|
275
|
-
query: query,
|
|
276
|
-
task: 'create',
|
|
277
|
-
template: template,
|
|
278
|
-
buckets,
|
|
279
|
-
clientId: publicKey,
|
|
280
|
-
databaseType: databaseType,
|
|
281
|
-
},
|
|
282
|
-
};
|
|
283
|
-
const cloudBody = report
|
|
284
|
-
? {
|
|
285
|
-
dashboardItemId: report._id,
|
|
286
|
-
name: chartName,
|
|
287
|
-
xAxisField,
|
|
288
|
-
yAxisFields,
|
|
289
|
-
xAxisLabel,
|
|
290
|
-
xAxisFormat,
|
|
291
|
-
chartType,
|
|
292
|
-
dashboardName,
|
|
293
|
-
columns: showTableFormatOptions
|
|
294
|
-
? columns
|
|
295
|
-
: [
|
|
296
|
-
...yAxisFields,
|
|
297
|
-
{
|
|
298
|
-
field: xAxisField,
|
|
299
|
-
label: xAxisLabel,
|
|
300
|
-
format: xAxisFormat,
|
|
301
|
-
},
|
|
302
|
-
],
|
|
303
|
-
dateField: showDateFieldOptions
|
|
304
|
-
? { table: dateFieldTable, field: dateField }
|
|
305
|
-
: defaultDateField,
|
|
306
|
-
query: query,
|
|
307
|
-
template: template,
|
|
308
|
-
buckets,
|
|
309
|
-
}
|
|
310
|
-
: {
|
|
311
|
-
name: chartName,
|
|
312
|
-
xAxisField,
|
|
313
|
-
yAxisFields,
|
|
314
|
-
xAxisLabel,
|
|
315
|
-
xAxisFormat,
|
|
316
|
-
chartType,
|
|
317
|
-
dashboardName,
|
|
318
|
-
columns: showTableFormatOptions
|
|
319
|
-
? columns
|
|
320
|
-
: [
|
|
321
|
-
...yAxisFields,
|
|
322
|
-
{
|
|
323
|
-
field: xAxisField,
|
|
324
|
-
label: xAxisLabel,
|
|
325
|
-
format: xAxisFormat,
|
|
326
|
-
},
|
|
327
|
-
],
|
|
328
|
-
dateField: showDateFieldOptions
|
|
329
|
-
? { table: dateFieldTable, field: dateField }
|
|
330
|
-
: defaultDateField,
|
|
331
|
-
query: query,
|
|
332
|
-
template: template,
|
|
333
|
-
buckets,
|
|
334
|
-
};
|
|
335
|
-
const searchParams = new URLSearchParams(customerId
|
|
336
|
-
? {
|
|
337
|
-
clientId: publicKey,
|
|
338
|
-
customerId: customerId,
|
|
339
|
-
}
|
|
340
|
-
: { clientId: publicKey }).toString();
|
|
341
|
-
const resp = await getData(client, `dashedit2?${searchParams}`, 'same-origin', hostedBody, cloudBody);
|
|
342
|
-
if (resp) {
|
|
343
|
-
if (resp.compareRows) {
|
|
344
|
-
mergeComparisonRange(resp);
|
|
345
|
-
}
|
|
346
|
-
dispatch({
|
|
347
|
-
type: 'UPDATE_DASHBOARD_ITEM',
|
|
348
|
-
id: resp._id,
|
|
349
|
-
data: {
|
|
350
|
-
...resp,
|
|
351
|
-
rows,
|
|
352
|
-
fields,
|
|
353
|
-
filtersApplied: dashboardFilters,
|
|
354
|
-
},
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
setIsOpen(false);
|
|
358
|
-
if (onAddToDashboardComplete) {
|
|
359
|
-
onAddToDashboardComplete();
|
|
360
|
-
}
|
|
361
|
-
if (!resp) {
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
};
|
|
365
|
-
return (
|
|
366
|
-
// <BigModal theme={theme} showModal={isOpen} setShowModal={setIsOpen}>
|
|
367
|
-
_jsx(_Fragment, { children: ModalComponent ? (_jsx(ModalComponent, { isOpen: isOpen, title: 'Add to dashboard', onClose: () => setIsOpen(false), children: _jsx(ChartForm, { editChart: editChart, theme: theme, schema: schema, data: rows, fields: columns, report: report, query: query, client: client,
|
|
368
|
-
// organizationName={organization?.name}
|
|
369
|
-
SelectComponent: SelectComponent, TextInputComponent: TextInputComponent, ButtonComponent: ButtonComponent, SecondaryButtonComponent: SecondaryButtonComponent, formHeaderStyle: formHeaderStyle, formLabelStyle: formLabelStyle, showTableFormatOptions: showTableFormatOptions, showDateFieldOptions: showDateFieldOptions, showAccessControlOptions: showAccessControlOptions, newFields: fields }) })) : (_jsx(QuillModal, { isOpen: isOpen, onClose: () => setIsOpen(false), title: 'Add to dashboard', children: _jsx(ChartForm, { editChart: editChart, theme: theme, schema: schema, data: rows, fields: columns, report: report, client: client, query: query,
|
|
370
|
-
// organizationName={organization?.name}
|
|
371
|
-
SelectComponent: SelectComponent, TextInputComponent: TextInputComponent, ButtonComponent: ButtonComponent, SecondaryButtonComponent: SecondaryButtonComponent, formHeaderStyle: formHeaderStyle, formLabelStyle: formLabelStyle, showTableFormatOptions: showTableFormatOptions, showDateFieldOptions: showDateFieldOptions, showAccessControlOptions: showAccessControlOptions, newFields: fields }) })) }));
|
|
372
|
-
}
|
|
373
|
-
function QuillModal({ isOpen, onClose, setIsOpen, title, children }) {
|
|
374
|
-
const scrollPosition = 0;
|
|
375
|
-
// useEffect(() => {
|
|
376
|
-
// if (isOpen) {
|
|
377
|
-
// scrollPosition = window.scrollY;
|
|
378
|
-
// // document.body.style.overflow = 'hidden';
|
|
379
|
-
// // document.body.style.position = 'fixed';
|
|
380
|
-
// // document.body.style.top = `-${scrollPosition}px`;
|
|
381
|
-
// // document.body.style.width = '100%';
|
|
382
|
-
// } else {
|
|
383
|
-
// document.body.style.removeProperty('overflow');
|
|
384
|
-
// document.body.style.removeProperty('position');
|
|
385
|
-
// document.body.style.removeProperty('top');
|
|
386
|
-
// document.body.style.removeProperty('width');
|
|
387
|
-
// // Restore the scroll position
|
|
388
|
-
// window.scrollTo(0, scrollPosition);
|
|
389
|
-
// }
|
|
390
|
-
// }, [isOpen]);
|
|
391
|
-
if (!isOpen) {
|
|
392
|
-
return null;
|
|
393
|
-
}
|
|
394
|
-
return (_jsxs(_Fragment, { children: [_jsx("div", { style: {
|
|
395
|
-
position: 'fixed',
|
|
396
|
-
top: '0',
|
|
397
|
-
right: '0',
|
|
398
|
-
bottom: '0',
|
|
399
|
-
left: '0',
|
|
400
|
-
zIndex: '50',
|
|
401
|
-
backgroundColor: 'rgba(255, 255, 255, 0.8)',
|
|
402
|
-
backdropFilter: 'blur(5px)',
|
|
403
|
-
}, onClick: onClose }), _jsx("div", { style: {
|
|
404
|
-
// position: "absolute",
|
|
405
|
-
position: 'fixed',
|
|
406
|
-
left: '50%',
|
|
407
|
-
top: '50%',
|
|
408
|
-
zIndex: '50',
|
|
409
|
-
// width: "100%",
|
|
410
|
-
maxWidth: 1024,
|
|
411
|
-
maxHeight: '90vh',
|
|
412
|
-
display: 'flex',
|
|
413
|
-
justifyContent: 'center',
|
|
414
|
-
alignItems: 'center',
|
|
415
|
-
transform: 'translateX(-50%) translateY(-50%)',
|
|
416
|
-
background: 'white',
|
|
417
|
-
borderRadius: 8,
|
|
418
|
-
borderStyle: 'solid',
|
|
419
|
-
borderWidth: 1,
|
|
420
|
-
borderColor: '#e7e7e7',
|
|
421
|
-
overflow: 'hidden',
|
|
422
|
-
// zIndex: 1000,
|
|
423
|
-
}, children: _jsxs("div", { style: {
|
|
424
|
-
// width: "80%",
|
|
425
|
-
maxHeight: '90vh',
|
|
426
|
-
overflowY: 'scroll',
|
|
427
|
-
// maxWidth: "700px",
|
|
428
|
-
backgroundColor: '#ffffff',
|
|
429
|
-
// padding: "20px",
|
|
430
|
-
// borderRadius: "8px",
|
|
431
|
-
display: 'flex',
|
|
432
|
-
flexDirection: 'column',
|
|
433
|
-
alignItems: 'center',
|
|
434
|
-
}, children: [_jsx("h2", { style: {
|
|
435
|
-
marginLeft: 35,
|
|
436
|
-
marginTop: 25,
|
|
437
|
-
fontSize: 18,
|
|
438
|
-
fontWeight: '600',
|
|
439
|
-
width: '100%',
|
|
440
|
-
textAlign: 'left',
|
|
441
|
-
}, children: title }), children] }) })] }));
|
|
442
|
-
}
|
|
443
|
-
export function ChartForm({ data, fields, theme, saveVisualization, report, editChart, schema, query, organizationName, SelectComponent, TextInputComponent, client, ButtonComponent, SecondaryButtonComponent, formHeaderStyle, formLabelStyle, showTableFormatOptions, showDateFieldOptions, showAccessControlOptions, newFields, }) {
|
|
444
|
-
if (report) {
|
|
445
|
-
newFields = report.fields;
|
|
446
|
-
}
|
|
447
|
-
const fieldOptions = data?.length
|
|
448
|
-
? Object.keys(data[0]).map((field) => ({
|
|
449
|
-
value: field,
|
|
450
|
-
label: field,
|
|
451
|
-
}))
|
|
452
|
-
: fields.map((field) => ({
|
|
453
|
-
value: field.field,
|
|
454
|
-
label: field.field,
|
|
455
|
-
}));
|
|
456
|
-
const xAxisOptions = data?.length
|
|
457
|
-
? Object.keys(data[0])
|
|
458
|
-
.filter((option) => getPostgresBasicType(newFields.find((field) => field.name === option)) === 'date' ||
|
|
459
|
-
getPostgresBasicType(newFields.find((field) => field.name === option)) === 'string')
|
|
460
|
-
.map((field) => ({
|
|
461
|
-
value: field,
|
|
462
|
-
label: field,
|
|
463
|
-
}))
|
|
464
|
-
: fields
|
|
465
|
-
.filter((option) => {
|
|
466
|
-
return (getPostgresBasicType(newFields.find((field) => field.name === option.field)) === 'date' ||
|
|
467
|
-
getPostgresBasicType(newFields.find((field) => field.name === option.field)) === 'string');
|
|
468
|
-
})
|
|
469
|
-
.map((field) => ({
|
|
470
|
-
value: field.field,
|
|
471
|
-
label: field.field,
|
|
472
|
-
}));
|
|
473
|
-
const yAxisOptions = data?.length
|
|
474
|
-
? Object.keys(data[0])
|
|
475
|
-
.filter((option) => getPostgresBasicType(newFields.find((field) => field.name === option)) === 'number')
|
|
476
|
-
.map((field) => ({
|
|
477
|
-
value: field,
|
|
478
|
-
label: field,
|
|
479
|
-
}))
|
|
480
|
-
: fields
|
|
481
|
-
.filter((option) => {
|
|
482
|
-
return (getPostgresBasicType(newFields.find((field) => field.name === option.field)) === 'number');
|
|
483
|
-
})
|
|
484
|
-
.map((field) => ({
|
|
485
|
-
value: field.field,
|
|
486
|
-
label: field.field,
|
|
487
|
-
}));
|
|
488
|
-
const [dateFieldOptions, setDateFieldOptions] = useState([]);
|
|
489
|
-
const [formValues, setFormValues] = useState({});
|
|
490
|
-
useEffect(() => {
|
|
491
|
-
const fetchReferencedTables = async () => {
|
|
492
|
-
if (!query) {
|
|
493
|
-
return;
|
|
494
|
-
}
|
|
495
|
-
const result = await getReferencedTables(client, query, schema);
|
|
496
|
-
setDateFieldOptions(result);
|
|
497
|
-
};
|
|
498
|
-
fetchReferencedTables();
|
|
499
|
-
}, [query, schema]);
|
|
500
|
-
return (_jsx(FormikForm, { data: data, xAxisOptions: xAxisOptions, yAxisOptions: yAxisOptions, fieldOptions: fieldOptions, dateFieldOptions: dateFieldOptions, theme: theme, saveVisualization: saveVisualization, report: report, editChart: editChart, client: client, fields: fields, newFields: newFields, query: query, showTableFormatOptions: showTableFormatOptions, showDateFieldOptions: showDateFieldOptions, showAccessControlOptions: showAccessControlOptions, organizationName: organizationName, SelectComponent: SelectComponent
|
|
501
|
-
? ({ onChange, value, options, form, field, }) => {
|
|
502
|
-
const handleChange = async (option) => {
|
|
503
|
-
if (onChange) {
|
|
504
|
-
onChange(option);
|
|
505
|
-
return;
|
|
506
|
-
}
|
|
507
|
-
await form.setFieldValue(field.name, option);
|
|
508
|
-
form.setFieldTouched(field.name, true);
|
|
509
|
-
};
|
|
510
|
-
return (_jsx(SelectComponent, { onChange: (event) => handleChange(event.target.value), value: value, options: options }));
|
|
511
|
-
}
|
|
512
|
-
: MemoizedDefaultSelectComponent, TextInputComponent: TextInputComponent
|
|
513
|
-
? TextInputComponent
|
|
514
|
-
: MemoizedDefaultTextInputComponent, ButtonComponent: ButtonComponent
|
|
515
|
-
? ButtonComponent
|
|
516
|
-
: ({ onClick, label }) => {
|
|
517
|
-
return (_jsx("div", { style: {
|
|
518
|
-
height: 38,
|
|
519
|
-
background: theme.primaryButtonColor,
|
|
520
|
-
color: theme.backgroundColor,
|
|
521
|
-
display: 'flex',
|
|
522
|
-
borderRadius: 6,
|
|
523
|
-
alignItems: 'center',
|
|
524
|
-
justifyContent: 'center',
|
|
525
|
-
outline: 'none',
|
|
526
|
-
cursor: 'pointer',
|
|
527
|
-
fontFamily: theme.fontFamily,
|
|
528
|
-
fontWeight: theme.buttonFontWeight || 600,
|
|
529
|
-
border: 'none',
|
|
530
|
-
fontSize: 14,
|
|
531
|
-
}, onClick: onClick, children: label }));
|
|
532
|
-
}, SecondaryButtonComponent: ButtonComponent
|
|
533
|
-
? ButtonComponent
|
|
534
|
-
: ({ onClick, label }) => {
|
|
535
|
-
return (_jsx("div", { style: {
|
|
536
|
-
height: 38,
|
|
537
|
-
background: theme.backgroundColor,
|
|
538
|
-
borderWidth: theme.borderWidth,
|
|
539
|
-
borderColor: theme.borderColor,
|
|
540
|
-
color: theme.primaryTextColor,
|
|
541
|
-
display: 'flex',
|
|
542
|
-
borderRadius: 6,
|
|
543
|
-
alignItems: 'center',
|
|
544
|
-
justifyContent: 'center',
|
|
545
|
-
outline: 'none',
|
|
546
|
-
cursor: 'pointer',
|
|
547
|
-
fontFamily: theme.fontFamily,
|
|
548
|
-
fontWeight: theme.buttonFontWeight || 600,
|
|
549
|
-
fontSize: 14,
|
|
550
|
-
}, onClick: onClick, children: label }));
|
|
551
|
-
}, formHeaderStyle: formHeaderStyle, formLabelStyle: formLabelStyle }));
|
|
552
|
-
}
|
|
553
|
-
export function isValidDate(d) {
|
|
554
|
-
return d instanceof Date && !isNaN(d);
|
|
555
|
-
}
|
|
556
|
-
export const isArrayOfValidDates = (arr, field) => arr.every((d) => new Date(d[field]) instanceof Date && !isNaN(new Date(d[field])));
|
|
557
|
-
export function formatDateBuckets(startDate, endDate) {
|
|
558
|
-
// Calculate the distance in hours
|
|
559
|
-
const distanceInHours = Math.abs(differenceInHours(endDate, startDate));
|
|
560
|
-
// Check if the distance is less than or equal to one hour
|
|
561
|
-
if (distanceInHours <= 1) {
|
|
562
|
-
return {
|
|
563
|
-
unit: 'hour',
|
|
564
|
-
format: 'h a',
|
|
565
|
-
startOf: startOfHour,
|
|
566
|
-
};
|
|
567
|
-
}
|
|
568
|
-
// Calculate the distance in days
|
|
569
|
-
const distanceInDays = Math.abs(differenceInDays(endDate, startDate));
|
|
570
|
-
// Check if the distance is less than or equal to one day
|
|
571
|
-
if (distanceInDays <= 1) {
|
|
572
|
-
return {
|
|
573
|
-
unit: 'day',
|
|
574
|
-
format: 'MMM d',
|
|
575
|
-
startOf: startOfDay,
|
|
576
|
-
};
|
|
577
|
-
}
|
|
578
|
-
// Calculate the distance in months
|
|
579
|
-
const distanceInMonths = Math.abs(differenceInMonths(endDate, startDate));
|
|
580
|
-
// Check if the distance is less than or equal to one month
|
|
581
|
-
if (distanceInMonths <= 1) {
|
|
582
|
-
return {
|
|
583
|
-
unit: 'month',
|
|
584
|
-
format: 'MMM yyyy',
|
|
585
|
-
startOf: startOfMonth,
|
|
586
|
-
};
|
|
587
|
-
}
|
|
588
|
-
// Calculate the distance in years
|
|
589
|
-
const distanceInYears = Math.abs(differenceInYears(endDate, startDate));
|
|
590
|
-
// Check if the distance is less than or equal to one year
|
|
591
|
-
if (distanceInYears <= 1) {
|
|
592
|
-
return {
|
|
593
|
-
unit: 'year',
|
|
594
|
-
format: 'yyyy',
|
|
595
|
-
startOf: startOfYear,
|
|
596
|
-
};
|
|
597
|
-
}
|
|
598
|
-
// Otherwise, the distance is more than one year
|
|
599
|
-
return {
|
|
600
|
-
unit: 'year',
|
|
601
|
-
format: 'yyyy',
|
|
602
|
-
startOf: startOfYear,
|
|
603
|
-
};
|
|
604
|
-
}
|
|
605
|
-
const FormTextInput = ({ field, form, ...props }) => {
|
|
606
|
-
const { theme, wider } = props;
|
|
607
|
-
return (_jsx("input", { className: `px-[12px] text-sm h-[38px] py-1.5 shadow-sm w-[245px] border-[#E7E7E7] ${'text-[#212121]'} border-[1px] bg-[white] rounded-md`, type: "text", ...field, ...props }));
|
|
608
|
-
};
|
|
609
|
-
const POSTGRES_DATE_TYPES = [
|
|
610
|
-
'timestamp',
|
|
611
|
-
'date',
|
|
612
|
-
'timestamptz',
|
|
613
|
-
'time',
|
|
614
|
-
'timetz',
|
|
615
|
-
];
|
|
616
|
-
async function getReferencedTables(client, sqlQuery, dbTables) {
|
|
617
|
-
// const parser = new Parser();
|
|
618
|
-
const tables = [];
|
|
619
|
-
const withAliases = [];
|
|
620
|
-
const resp = await getDataFromCloud(client, `astify`, { query: sqlQuery });
|
|
621
|
-
let ast = resp.ast;
|
|
622
|
-
ast = ast.length ? ast[0] : ast;
|
|
623
|
-
if (ast.with && ast.with.length) {
|
|
624
|
-
for (let i = 0; i < ast.with.length; i++) {
|
|
625
|
-
withAliases.push(ast.with[i].name.value);
|
|
626
|
-
for (let j = 0; j < ast.with[i].stmt.from.length; j++)
|
|
627
|
-
tables.push(ast.with[i].stmt.from[j].table);
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
const tablesInQuery = [
|
|
631
|
-
...tables,
|
|
632
|
-
...ast.from.map((elem) => elem.table),
|
|
633
|
-
].filter((elem) => !withAliases.includes(elem));
|
|
634
|
-
return dbTables
|
|
635
|
-
.filter((table) => tablesInQuery.includes(table.displayName))
|
|
636
|
-
.map((table) => {
|
|
637
|
-
return {
|
|
638
|
-
name: table.displayName,
|
|
639
|
-
columns: table.columns.filter((column) => POSTGRES_DATE_TYPES.includes(column.fieldType)),
|
|
640
|
-
};
|
|
641
|
-
})
|
|
642
|
-
.filter((table) => table.columns.length > 0);
|
|
643
|
-
}
|
|
644
|
-
const X_FORMAT_OPTIONS = [
|
|
645
|
-
{ value: 'whole_number', label: 'whole number' },
|
|
646
|
-
{ value: 'one_decimal_place', label: 'one decimal place' },
|
|
647
|
-
{ value: 'two_decimal_places', label: 'two decimal places' },
|
|
648
|
-
{ value: 'dollar_amount', label: 'dollar amount' },
|
|
649
|
-
{ value: 'dollar_cents', label: 'dollar and cent amount' },
|
|
650
|
-
{ value: 'MMM_yyyy', label: 'month' },
|
|
651
|
-
{ value: 'MMM_dd-MMM_dd', label: 'week' },
|
|
652
|
-
{ value: 'MMM_dd_yyyy', label: 'day' },
|
|
653
|
-
{ value: 'MMM_dd_hh:mm_ap_pm', label: 'day and time' },
|
|
654
|
-
{ value: 'hh_ap_pm', label: 'hour' },
|
|
655
|
-
{ value: 'percent', label: 'percent' },
|
|
656
|
-
{ value: 'string', label: 'string' },
|
|
657
|
-
{ value: 'dynamic', label: 'dynamic' },
|
|
658
|
-
];
|
|
659
|
-
const Y_FORMAT_OPTIONS = [
|
|
660
|
-
{ value: 'whole_number', label: 'whole number' },
|
|
661
|
-
{ value: 'one_decimal_place', label: 'one decimal place' },
|
|
662
|
-
{ value: 'two_decimal_places', label: 'two decimal places' },
|
|
663
|
-
{ value: 'dollar_amount', label: 'dollar amount' },
|
|
664
|
-
{ value: 'dollar_cents', label: 'dollar and cent amount' },
|
|
665
|
-
{ value: 'MMM_yyyy', label: 'month' },
|
|
666
|
-
{ value: 'MMM_dd-MMM_dd', label: 'week' },
|
|
667
|
-
{ value: 'MMM_dd_yyyy', label: 'day' },
|
|
668
|
-
{ value: 'MMM_dd_hh:mm_ap_pm', label: 'day and time' },
|
|
669
|
-
{ value: 'hh_ap_pm', label: 'hour' },
|
|
670
|
-
{ value: 'percent', label: 'percent' },
|
|
671
|
-
{ value: 'string', label: 'string' },
|
|
672
|
-
];
|
|
673
|
-
const handleBucketData = (dashboardItem, bucketFields, dateFilter) => {
|
|
674
|
-
return aggregate(dashboardItem, bucketFields, dateFilter);
|
|
675
|
-
};
|
|
676
|
-
function FormikForm({ data, xAxisOptions, yAxisOptions, fieldOptions, dateFieldOptions, theme, report, editChart, fields, newFields, query, client, SelectComponent, TextInputComponent, ButtonComponent, SecondaryButtonComponent, organizationName, formHeaderStyle, formLabelStyle, showTableFormatOptions, showDateFieldOptions, showAccessControlOptions, }) {
|
|
677
|
-
// fieldOptions.sort((a, b) => {
|
|
678
|
-
// if (a.value === 'created_at') return -1;
|
|
679
|
-
// if (b.value === 'created_at') return 1;
|
|
680
|
-
// return 0;
|
|
681
|
-
// });
|
|
682
|
-
function postgresFormatMap(postgresType) {
|
|
683
|
-
if (postgresType === 'string')
|
|
684
|
-
return 'string';
|
|
685
|
-
if (postgresType === 'number')
|
|
686
|
-
return 'whole_number';
|
|
687
|
-
if (postgresType === 'date')
|
|
688
|
-
return 'dynamic';
|
|
689
|
-
}
|
|
690
|
-
X_FORMAT_OPTIONS.sort((a, b) => {
|
|
691
|
-
if (a.value === 'dynamic')
|
|
692
|
-
return -1;
|
|
693
|
-
if (b.value === 'dynamic')
|
|
694
|
-
return 1;
|
|
695
|
-
return 0;
|
|
696
|
-
});
|
|
697
|
-
const { dashboardFilters, dashboardFiltersDispatch } = useContext(DashboardFiltersContext);
|
|
698
|
-
const [rows, setRows] = useState(null);
|
|
699
|
-
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
700
|
-
const [xAxisField, setXAxisField] = useState(report?.xAxisField ||
|
|
701
|
-
(xAxisOptions && xAxisOptions.length && xAxisOptions[0].value) ||
|
|
702
|
-
'');
|
|
703
|
-
const [xAxisLabel, setXAxisLabel] = useState(report?.xAxisLabel || '');
|
|
704
|
-
const [xAxisFormat, setXAxisFormat] = useState(report?.xAxisFormat ||
|
|
705
|
-
(X_FORMAT_OPTIONS.length && X_FORMAT_OPTIONS[0].value) ||
|
|
706
|
-
'');
|
|
707
|
-
const [chartName, setChartName] = useState(report?.name || '');
|
|
708
|
-
const [chartType, setChartType] = useState(report?.chartType || 'column');
|
|
709
|
-
const [dateFieldTable, setDateFieldTable] = useState((dateFieldOptions.length && dateFieldOptions[0].name) || '');
|
|
710
|
-
const [dateField, setDateField] = useState((dateFieldOptions.length && dateFieldOptions[0].columns[0].name) || '');
|
|
711
|
-
const [template, setTemplate] = useState(report?.template || false);
|
|
712
|
-
const [chartConfig, setChartConfig] = useState({});
|
|
713
|
-
const { dateFilter, setDateFilter } = useContext(DateFilterContext);
|
|
714
|
-
const [yAxisFields, setYAxisFields] = useState(report
|
|
715
|
-
? report.yAxisFields
|
|
716
|
-
: [
|
|
717
|
-
{
|
|
718
|
-
field: yAxisOptions.length > 1
|
|
719
|
-
? yAxisOptions[1].value
|
|
720
|
-
: yAxisOptions[0].value,
|
|
721
|
-
label: '',
|
|
722
|
-
format: 'whole_number',
|
|
723
|
-
},
|
|
724
|
-
]);
|
|
725
|
-
const [bucketFields, setBucketFields] = useState((report && report.buckets) || []);
|
|
726
|
-
const [columns, setColumns] = useState(report && report.columns.length
|
|
727
|
-
? report.columns
|
|
728
|
-
: fields?.length
|
|
729
|
-
? fields.map((field) => convertPostgresColumn(field))
|
|
730
|
-
: []);
|
|
731
|
-
function removeQuotes(str) {
|
|
732
|
-
if (str.startsWith('"') && str.endsWith('"')) {
|
|
733
|
-
return str.slice(1, -1);
|
|
734
|
-
}
|
|
735
|
-
else {
|
|
736
|
-
return str;
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
const processFilter = (filter, value = null) => {
|
|
740
|
-
//for dateObjects only, since values are arrays for dateObjects
|
|
741
|
-
const { selectedValue: _, ...filterWithoutSelectedValue } = filter; // _ is a throwaway variable
|
|
742
|
-
let selectedValue;
|
|
743
|
-
let selectedElem;
|
|
744
|
-
if (filter.filterType === 'string') {
|
|
745
|
-
selectedElem = filter.options.find((elem) => elem[removeQuotes(filter.field)] === value);
|
|
746
|
-
if (selectedElem) {
|
|
747
|
-
selectedValue = selectedElem[removeQuotes(filter.field)];
|
|
748
|
-
}
|
|
749
|
-
return {
|
|
750
|
-
...filterWithoutSelectedValue,
|
|
751
|
-
...(selectedValue ? { selectedValue } : {}),
|
|
752
|
-
};
|
|
753
|
-
}
|
|
754
|
-
if (filter.filterType === 'date' || filter.filterType === 'date_range') {
|
|
755
|
-
if (value[2]) {
|
|
756
|
-
selectedElem = filter.options.find((elem) => {
|
|
757
|
-
return value[2] === elem[removeQuotes(filter.field)][2];
|
|
758
|
-
});
|
|
759
|
-
if (selectedElem) {
|
|
760
|
-
selectedValue = selectedElem[removeQuotes(filter.field)];
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
return {
|
|
764
|
-
startDate: value ? value[0] : filter.startDate,
|
|
765
|
-
endDate: value ? value[1] : filter.endDate,
|
|
766
|
-
filterType: 'date_range',
|
|
767
|
-
...(selectedValue ? { selectedValue } : {}),
|
|
768
|
-
field: 'date_range',
|
|
769
|
-
options: options,
|
|
770
|
-
label: 'Date',
|
|
771
|
-
};
|
|
772
|
-
}
|
|
773
|
-
};
|
|
774
|
-
const handleAddYAxisField = () => {
|
|
775
|
-
setYAxisFields([
|
|
776
|
-
...yAxisFields,
|
|
777
|
-
{ label: '', field: '', format: 'whole_number' },
|
|
778
|
-
]);
|
|
779
|
-
};
|
|
780
|
-
const handleAddBucket = () => {
|
|
781
|
-
const bucketPossibilities = xAxisOptions.filter((option) => getPostgresBasicType(newFields.find((field) => field.name === option.value)) === 'date');
|
|
782
|
-
if (!bucketPossibilities.length) {
|
|
783
|
-
alert('No possible buckets');
|
|
784
|
-
return;
|
|
785
|
-
}
|
|
786
|
-
setBucketFields([
|
|
787
|
-
...bucketFields,
|
|
788
|
-
{
|
|
789
|
-
field: bucketPossibilities[0].value,
|
|
790
|
-
},
|
|
791
|
-
]);
|
|
792
|
-
setXAxisField(bucketPossibilities[0].value);
|
|
793
|
-
if (bucketPossibilities[0].value === dateField) {
|
|
794
|
-
setXAxisFormat('dynamic');
|
|
795
|
-
}
|
|
796
|
-
else {
|
|
797
|
-
setXAxisFormat(postgresFormatMap(getPostgresBasicType(newFields.find((field) => field.name === bucketPossibilities[0].value))));
|
|
798
|
-
}
|
|
799
|
-
};
|
|
800
|
-
const [dashboardOptions, setDashboardOptions] = useState([]);
|
|
801
|
-
const [dashboardName, setDashboardName] = useState(report?.dashboardName || dashboardOptions[0]);
|
|
802
|
-
useEffect(() => {
|
|
803
|
-
if (!report && dashboardOptions && dashboardOptions.length) {
|
|
804
|
-
setDashboardName(dashboardOptions[0].value);
|
|
805
|
-
}
|
|
806
|
-
}, [dashboardOptions]);
|
|
807
|
-
const values = {
|
|
808
|
-
xAxisLabel,
|
|
809
|
-
chartName,
|
|
810
|
-
chartType,
|
|
811
|
-
xAxisField,
|
|
812
|
-
xAxisFormat,
|
|
813
|
-
dashboardName,
|
|
814
|
-
dateFieldTable,
|
|
815
|
-
dateField,
|
|
816
|
-
};
|
|
817
|
-
const [selectedTabIndex, setSelectedTabIndex] = useState(report && report.template ? 1 : 0);
|
|
818
|
-
React.useEffect(() => {
|
|
819
|
-
async function getDashboards() {
|
|
820
|
-
const { publicKey, customerId, queryEndpoint, databaseType } = client;
|
|
821
|
-
if (customerId || queryEndpoint) {
|
|
822
|
-
try {
|
|
823
|
-
let responseData;
|
|
824
|
-
// Add query parameters to the URL
|
|
825
|
-
const searchParams = new URLSearchParams({
|
|
826
|
-
publicKey: publicKey,
|
|
827
|
-
orgId: customerId,
|
|
828
|
-
name: name,
|
|
829
|
-
}).toString();
|
|
830
|
-
const hostedBody = {
|
|
831
|
-
metadata: customerId
|
|
832
|
-
? {
|
|
833
|
-
orgId: customerId,
|
|
834
|
-
clientId: publicKey,
|
|
835
|
-
name,
|
|
836
|
-
task: 'config',
|
|
837
|
-
databaseType: databaseType,
|
|
838
|
-
}
|
|
839
|
-
: {
|
|
840
|
-
name: dashboardName,
|
|
841
|
-
clientId: publicKey,
|
|
842
|
-
task: 'config',
|
|
843
|
-
databaseType: databaseType,
|
|
844
|
-
},
|
|
845
|
-
};
|
|
846
|
-
const resp = await getData(client, `dashconfig?${searchParams}`, 'omit', hostedBody, null, 'GET');
|
|
847
|
-
const bigFilterObj = {};
|
|
848
|
-
if (resp.dateFilter && Object.keys(resp.dateFilter).length) {
|
|
849
|
-
if (resp.dateFilter.initialRange === 'LAST_90_DAYS') {
|
|
850
|
-
const filter = {
|
|
851
|
-
startDate: sub(startOfToday(), { days: 90 }),
|
|
852
|
-
endDate: endOfToday(),
|
|
853
|
-
filterType: 'date_range',
|
|
854
|
-
selectedValue: [
|
|
855
|
-
sub(startOfToday(), { days: 90 }),
|
|
856
|
-
endOfToday(),
|
|
857
|
-
'90d',
|
|
858
|
-
],
|
|
859
|
-
field: 'date_range',
|
|
860
|
-
label: 'Date',
|
|
861
|
-
};
|
|
862
|
-
dashboardFiltersDispatch({
|
|
863
|
-
type: 'ADD_DASHBOARD_FILTER',
|
|
864
|
-
id: 'date_range',
|
|
865
|
-
data: {
|
|
866
|
-
...filter,
|
|
867
|
-
},
|
|
868
|
-
});
|
|
869
|
-
setDateFilter(filter);
|
|
870
|
-
bigFilterObj[filter.field] = filter;
|
|
871
|
-
}
|
|
872
|
-
else if (resp.dateFilter.initialRange === 'LAST_30_DAYS') {
|
|
873
|
-
const filter = {
|
|
874
|
-
startDate: sub(startOfToday(), { days: 30 }),
|
|
875
|
-
endDate: endOfToday(),
|
|
876
|
-
filterType: 'date_range',
|
|
877
|
-
selectedValue: [
|
|
878
|
-
sub(startOfToday(), { days: 30 }),
|
|
879
|
-
endOfToday(),
|
|
880
|
-
't',
|
|
881
|
-
],
|
|
882
|
-
options: options,
|
|
883
|
-
field: 'date_range',
|
|
884
|
-
label: 'Date',
|
|
885
|
-
};
|
|
886
|
-
dashboardFiltersDispatch({
|
|
887
|
-
type: 'ADD_DASHBOARD_FILTER',
|
|
888
|
-
id: 'date_range',
|
|
889
|
-
data: {
|
|
890
|
-
...filter,
|
|
891
|
-
},
|
|
892
|
-
});
|
|
893
|
-
setDateFilter(filter);
|
|
894
|
-
bigFilterObj[filter.field] = filter;
|
|
895
|
-
// return;
|
|
896
|
-
}
|
|
897
|
-
else if (resp.dateFilter.initialRange === 'CURRENT_MONTH') {
|
|
898
|
-
const filter = {
|
|
899
|
-
startDate: startOfMonth(new Date()),
|
|
900
|
-
endDate: endOfToday(),
|
|
901
|
-
filterType: 'date_range',
|
|
902
|
-
selectedValue: [startOfMonth(new Date()), endOfToday(), 'm'],
|
|
903
|
-
options: options,
|
|
904
|
-
field: 'date_range',
|
|
905
|
-
label: 'Date',
|
|
906
|
-
};
|
|
907
|
-
dashboardFiltersDispatch({
|
|
908
|
-
type: 'ADD_DASHBOARD_FILTER',
|
|
909
|
-
id: 'date_range',
|
|
910
|
-
data: {
|
|
911
|
-
...filter,
|
|
912
|
-
},
|
|
913
|
-
});
|
|
914
|
-
setDateFilter(filter);
|
|
915
|
-
bigFilterObj[filter.field] = filter;
|
|
916
|
-
}
|
|
917
|
-
else {
|
|
918
|
-
const filter = {
|
|
919
|
-
startDate: sub(startOfToday(), { days: 90 }),
|
|
920
|
-
endDate: endOfToday(),
|
|
921
|
-
filterType: 'date_range',
|
|
922
|
-
selectedValue: [
|
|
923
|
-
sub(startOfToday(), { days: 90 }),
|
|
924
|
-
endOfToday(),
|
|
925
|
-
'90d',
|
|
926
|
-
],
|
|
927
|
-
options: options,
|
|
928
|
-
field: 'date_range',
|
|
929
|
-
label: 'Date',
|
|
930
|
-
};
|
|
931
|
-
dashboardFiltersDispatch({
|
|
932
|
-
type: 'ADD_DASHBOARD_FILTER',
|
|
933
|
-
id: 'date_range',
|
|
934
|
-
data: {
|
|
935
|
-
...filter,
|
|
936
|
-
},
|
|
937
|
-
});
|
|
938
|
-
setDateFilter(filter);
|
|
939
|
-
bigFilterObj[filter.field] = filter;
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
if (resp.filters && resp.filters.length) {
|
|
943
|
-
Object.values(resp.filters)
|
|
944
|
-
.filter((filter) => filter.filterType !== 'date')
|
|
945
|
-
.forEach((filter) => {
|
|
946
|
-
// processFilter(filter);
|
|
947
|
-
bigFilterObj[filter.field] = processFilter(filter);
|
|
948
|
-
});
|
|
949
|
-
}
|
|
950
|
-
dashboardFiltersDispatch({
|
|
951
|
-
type: 'ADD_DASHBOARD_FILTERS',
|
|
952
|
-
id: 'tons',
|
|
953
|
-
data: bigFilterObj,
|
|
954
|
-
});
|
|
955
|
-
if (!resp.dateFilter) {
|
|
956
|
-
setDateFilter(null);
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
catch (error) {
|
|
960
|
-
console.error('Error fetching data:', error);
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
getDashboards();
|
|
965
|
-
}, [dashboardName, client]);
|
|
966
|
-
useEffect(() => {
|
|
967
|
-
async function getDashNames() {
|
|
968
|
-
const resp = await getDataFromCloud(client, `dashnames/${client.publicKey}/`, null, 'GET');
|
|
969
|
-
setDashboardOptions(resp.dashboardNames
|
|
970
|
-
.filter((elem) => elem !== null)
|
|
971
|
-
.map((key) => ({ label: key, value: key })));
|
|
972
|
-
}
|
|
973
|
-
getDashNames();
|
|
974
|
-
}, []);
|
|
975
|
-
useEffect(() => {
|
|
976
|
-
// if (!dateField) {
|
|
977
|
-
// return;
|
|
978
|
-
// }
|
|
979
|
-
// if (
|
|
980
|
-
// (!bucketFields.length && chartType === 'column') ||
|
|
981
|
-
// chartType === 'line'
|
|
982
|
-
// ) {
|
|
983
|
-
// handleAddBucket();
|
|
984
|
-
// return;
|
|
985
|
-
// }
|
|
986
|
-
if ((bucketFields.length && chartType === 'metric') ||
|
|
987
|
-
chartType === 'table' ||
|
|
988
|
-
chartType === 'pie') {
|
|
989
|
-
handleDeleteBucketField(0);
|
|
990
|
-
return;
|
|
991
|
-
}
|
|
992
|
-
}, [chartType, dateField]);
|
|
993
|
-
useEffect(() => {
|
|
994
|
-
if (dateFieldOptions.length) {
|
|
995
|
-
setDateFieldTable(dateFieldOptions[0].name);
|
|
996
|
-
setDateField(dateFieldOptions[0].columns[0].name);
|
|
997
|
-
}
|
|
998
|
-
}, [dateFieldOptions]);
|
|
999
|
-
const handleDeleteYAxisField = (index) => {
|
|
1000
|
-
setYAxisFields((yAxisFields) => yAxisFields.filter((_, i) => index !== i));
|
|
1001
|
-
};
|
|
1002
|
-
const handleDeleteBucketField = (index) => {
|
|
1003
|
-
setBucketFields((bucketFields) => bucketFields.filter((_, i) => index !== i));
|
|
1004
|
-
setXAxisField(xAxisOptions[0].value);
|
|
1005
|
-
setXAxisLabel('');
|
|
1006
|
-
};
|
|
1007
|
-
const handleBucketFieldChange = (index, value) => {
|
|
1008
|
-
if (!dateField) {
|
|
1009
|
-
return;
|
|
1010
|
-
}
|
|
1011
|
-
const newBucketFields = [...bucketFields];
|
|
1012
|
-
newBucketFields[index] = { ...newBucketFields[index], field: value };
|
|
1013
|
-
setBucketFields(newBucketFields);
|
|
1014
|
-
setXAxisField(value);
|
|
1015
|
-
if (value === dateField) {
|
|
1016
|
-
setXAxisFormat('dynamic');
|
|
1017
|
-
}
|
|
1018
|
-
else {
|
|
1019
|
-
setXAxisFormat(postgresFormatMap(getPostgresBasicType(newFields.find((field) => field.name === value))));
|
|
1020
|
-
}
|
|
1021
|
-
};
|
|
1022
|
-
const handleXAxisFieldChange = (value) => {
|
|
1023
|
-
if (!dateField) {
|
|
1024
|
-
return;
|
|
1025
|
-
}
|
|
1026
|
-
// const newXAxisField = {
|
|
1027
|
-
// format: xAxisFormat,
|
|
1028
|
-
// label: xAxisLabel,
|
|
1029
|
-
// field: value,
|
|
1030
|
-
// };
|
|
1031
|
-
setXAxisField(value);
|
|
1032
|
-
// TODO: MAKE DATE FIELD NOT HARD CODED
|
|
1033
|
-
if (value === dateField) {
|
|
1034
|
-
setXAxisFormat('dynamic');
|
|
1035
|
-
}
|
|
1036
|
-
else {
|
|
1037
|
-
setXAxisFormat(postgresFormatMap(getPostgresBasicType(newFields.find((field) => field.name === value))));
|
|
1038
|
-
}
|
|
1039
|
-
if (bucketFields.length > 0) {
|
|
1040
|
-
const newBucketFields = [...bucketFields];
|
|
1041
|
-
newBucketFields[0] = { ...newBucketFields[0], field: value };
|
|
1042
|
-
setBucketFields(newBucketFields);
|
|
1043
|
-
}
|
|
1044
|
-
};
|
|
1045
|
-
const handleYAxisFieldChange = (index, value) => {
|
|
1046
|
-
const newYAxisFields = [...yAxisFields];
|
|
1047
|
-
newYAxisFields[index] = {
|
|
1048
|
-
...newYAxisFields[index],
|
|
1049
|
-
field: value,
|
|
1050
|
-
format: postgresFormatMap(newFields.find((field) => field.name === value)),
|
|
1051
|
-
};
|
|
1052
|
-
setYAxisFields(newYAxisFields);
|
|
1053
|
-
};
|
|
1054
|
-
const handleYAxisFieldFormatChange = (index, value) => {
|
|
1055
|
-
const newYAxisFields = [...yAxisFields];
|
|
1056
|
-
newYAxisFields[index] = { ...newYAxisFields[index], format: value };
|
|
1057
|
-
setYAxisFields(newYAxisFields);
|
|
1058
|
-
};
|
|
1059
|
-
const handleYAxisLabelChange = (index, value) => {
|
|
1060
|
-
const newYAxisFields = [...yAxisFields];
|
|
1061
|
-
newYAxisFields[index] = { ...newYAxisFields[index], label: value };
|
|
1062
|
-
setYAxisFields(newYAxisFields);
|
|
1063
|
-
};
|
|
1064
|
-
const handleColumnFieldChange = (index, value) => {
|
|
1065
|
-
const newColumns = [...columns];
|
|
1066
|
-
newColumns[index] = { ...newColumns[index], field: value };
|
|
1067
|
-
setColumns(newColumns);
|
|
1068
|
-
};
|
|
1069
|
-
const handleColumnFormatChange = (index, value) => {
|
|
1070
|
-
const newColumns = [...columns];
|
|
1071
|
-
newColumns[index] = { ...newColumns[index], format: value };
|
|
1072
|
-
setColumns(newColumns);
|
|
1073
|
-
};
|
|
1074
|
-
const handleColumnLabelChange = (index, value) => {
|
|
1075
|
-
const newColumns = [...columns];
|
|
1076
|
-
newColumns[index] = { ...newColumns[index], label: value };
|
|
1077
|
-
setColumns(newColumns);
|
|
1078
|
-
};
|
|
1079
|
-
useEffect(() => {
|
|
1080
|
-
const now = new Date();
|
|
1081
|
-
if (!dateFilter ||
|
|
1082
|
-
(dateFilter && dateFilter.startDate && dateFilter.endDate)) {
|
|
1083
|
-
setChartConfig(handleBucketData({
|
|
1084
|
-
xAxisField,
|
|
1085
|
-
xAxisLabel,
|
|
1086
|
-
xAxisFormat,
|
|
1087
|
-
chartName,
|
|
1088
|
-
chartType,
|
|
1089
|
-
dashboardName,
|
|
1090
|
-
dateFieldTable,
|
|
1091
|
-
dateField,
|
|
1092
|
-
template,
|
|
1093
|
-
yAxisFields: yAxisFields,
|
|
1094
|
-
rows: data,
|
|
1095
|
-
fields: newFields,
|
|
1096
|
-
columns: columns,
|
|
1097
|
-
}, bucketFields, dateFilter));
|
|
1098
|
-
}
|
|
1099
|
-
}, [
|
|
1100
|
-
xAxisField,
|
|
1101
|
-
xAxisLabel,
|
|
1102
|
-
xAxisFormat,
|
|
1103
|
-
chartName,
|
|
1104
|
-
chartType,
|
|
1105
|
-
dashboardName,
|
|
1106
|
-
dateFieldTable,
|
|
1107
|
-
dateField,
|
|
1108
|
-
template,
|
|
1109
|
-
yAxisFields,
|
|
1110
|
-
bucketFields,
|
|
1111
|
-
columns,
|
|
1112
|
-
dateFilter,
|
|
1113
|
-
]);
|
|
1114
|
-
return (_jsx("div", { style: { display: 'inline-block' }, children: _jsxs("div", { style: {
|
|
1115
|
-
display: 'flex',
|
|
1116
|
-
flexDirection: 'column',
|
|
1117
|
-
paddingLeft: 25,
|
|
1118
|
-
paddingRight: chartConfig.chartType === 'pie' ? 25 : undefined,
|
|
1119
|
-
}, children: [_jsxs("div", { style: {
|
|
1120
|
-
display: 'flex',
|
|
1121
|
-
flexDirection: 'column',
|
|
1122
|
-
}, children: [_jsx("div", { style: { height: 20 } }), _jsx("div", { style: {
|
|
1123
|
-
marginRight: chartConfig.chartType === 'pie' ||
|
|
1124
|
-
chartConfig.chartType === 'table'
|
|
1125
|
-
? undefined
|
|
1126
|
-
: 25,
|
|
1127
|
-
marginLeft: chartConfig.chartType === 'pie' ||
|
|
1128
|
-
chartConfig.chartType === 'table'
|
|
1129
|
-
? undefined
|
|
1130
|
-
: -25,
|
|
1131
|
-
}, children: Object.keys(chartConfig).length > 0 && (_jsx(Chart, { config: chartConfig, colors: theme.chartColors, containerStyle: {
|
|
1132
|
-
width: chartConfig.chartType === 'table'
|
|
1133
|
-
? 640
|
|
1134
|
-
: 'calc(100% - 24px)',
|
|
1135
|
-
height: 300,
|
|
1136
|
-
} })) }), _jsx("div", { style: { height: 40 } }), showTableFormatOptions || showDateFieldOptions ? (_jsx(_Fragment, { children: _jsx("div", { style: formHeaderStyle || {
|
|
1137
|
-
fontFamily: theme.fontFamily,
|
|
1138
|
-
color: theme.primaryTextColor,
|
|
1139
|
-
fontSize: theme.fontSize + 2,
|
|
1140
|
-
fontWeight: 600,
|
|
1141
|
-
}, children: 'Chart' }) })) : null, _jsxs("div", { style: {
|
|
1142
|
-
display: 'flex',
|
|
1143
|
-
flexDirection: 'row',
|
|
1144
|
-
alignItems: 'center',
|
|
1145
|
-
}, children: [_jsxs("div", { style: { display: 'flex', flexDirection: 'column', marginTop: 8 }, children: [_jsx("div", { style: formLabelStyle || {
|
|
1146
|
-
color: theme.secondaryTextColor,
|
|
1147
|
-
fontFamily: theme?.fontFamily,
|
|
1148
|
-
fontSize: theme?.fontSize || '14px',
|
|
1149
|
-
fontWeight: theme.labelFontWeight || '600',
|
|
1150
|
-
}, children: "Name" }), _jsx("div", { style: { minWidth: 200, marginTop: 6 }, children: _jsx(TextInputComponent, { onChange: (e) => setChartName(e.target.value), value: chartName, theme: theme, placeholder: 'Enter a chart name' }) })] }), _jsx("div", { style: { width: 20 } }), _jsxs("div", { style: { display: 'flex', flexDirection: 'column', marginTop: 8 }, children: [_jsx("div", { style: formLabelStyle || {
|
|
1151
|
-
color: theme.secondaryTextColor,
|
|
1152
|
-
fontFamily: theme?.fontFamily,
|
|
1153
|
-
fontSize: theme?.fontSize || '14px',
|
|
1154
|
-
fontWeight: theme.labelFontWeight || '600',
|
|
1155
|
-
}, children: "Dashboard name" }), _jsx("div", { style: { minWidth: 200, marginTop: 6 }, children: _jsx(SelectComponent, { onChange: (value) => setDashboardName(value), value: dashboardName, theme: theme, options: dashboardOptions }) })] }), _jsx("div", { style: { width: 20 } }), _jsxs("div", { style: { display: 'flex', flexDirection: 'column', marginTop: 8 }, children: [_jsx("div", { style: formLabelStyle || {
|
|
1156
|
-
color: theme.secondaryTextColor,
|
|
1157
|
-
fontFamily: theme?.fontFamily,
|
|
1158
|
-
fontSize: theme?.fontSize || '14px',
|
|
1159
|
-
fontWeight: theme.labelFontWeight || '600',
|
|
1160
|
-
}, children: "Chart type" }), _jsx("div", { style: { minWidth: 200, marginTop: 6 }, children: _jsx(SelectComponent, { onChange: (e) => setChartType(e), value: chartType, options: [
|
|
1161
|
-
{ label: 'column', value: 'column' },
|
|
1162
|
-
{ label: 'bar', value: 'bar' },
|
|
1163
|
-
{ label: 'line', value: 'line' },
|
|
1164
|
-
{ label: 'pie', value: 'pie' },
|
|
1165
|
-
{ label: 'metric', value: 'metric' },
|
|
1166
|
-
{ label: 'table', value: 'table' },
|
|
1167
|
-
], theme: theme }) })] })] })] }), chartType !== 'table' &&
|
|
1168
|
-
chartType !== 'metric' &&
|
|
1169
|
-
chartType !== 'pie' && (_jsxs("div", { style: {
|
|
1170
|
-
display: 'flex',
|
|
1171
|
-
flexDirection: 'column',
|
|
1172
|
-
marginTop: 20,
|
|
1173
|
-
maxWidth: 200,
|
|
1174
|
-
}, children: [_jsx("div", { style: formLabelStyle || {
|
|
1175
|
-
color: theme.secondaryTextColor,
|
|
1176
|
-
fontFamily: theme?.fontFamily,
|
|
1177
|
-
fontSize: theme?.fontSize || '14px',
|
|
1178
|
-
fontWeight: theme.labelFontWeight || '600',
|
|
1179
|
-
}, children: "Buckets" }), _jsx("div", { style: {
|
|
1180
|
-
maxWidth: 200,
|
|
1181
|
-
// marginTop: 6,
|
|
1182
|
-
display: 'flex',
|
|
1183
|
-
flexDirection: 'column',
|
|
1184
|
-
}, children: bucketFields.map((bucketField, index) => (_jsxs("div", { style: {
|
|
1185
|
-
display: 'flex',
|
|
1186
|
-
flexDirection: 'row',
|
|
1187
|
-
alignItems: 'center',
|
|
1188
|
-
marginTop: index === 0 ? 6 : 10,
|
|
1189
|
-
}, children: [_jsx("div", { style: { minWidth: 200 }, children: _jsx(SelectComponent, { onChange: (option) => handleBucketFieldChange(index, option), value: bucketField.field,
|
|
1190
|
-
// TODO: PROB FILTER OUT NUMBERS LMAO (SO DATE AND STRING ONLY)
|
|
1191
|
-
options: xAxisOptions, theme: theme }) }), _jsx("div", { onClick: () => handleDeleteBucketField(index), style: {
|
|
1192
|
-
cursor: 'pointer',
|
|
1193
|
-
paddingLeft: 6,
|
|
1194
|
-
paddingTop: 9,
|
|
1195
|
-
paddingBottom: 9,
|
|
1196
|
-
paddingRight: 6,
|
|
1197
|
-
maxHeight: 38,
|
|
1198
|
-
display: 'flex',
|
|
1199
|
-
alignItems: 'center',
|
|
1200
|
-
justifyContent: 'center',
|
|
1201
|
-
}, children: _jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: theme?.secondaryTextColor, height: "20", width: "20", children: _jsx("path", { fillRule: "evenodd", d: "M5.47 5.47a.75.75 0 011.06 0L12 10.94l5.47-5.47a.75.75 0 111.06 1.06L13.06 12l5.47 5.47a.75.75 0 11-1.06 1.06L12 13.06l-5.47 5.47a.75.75 0 01-1.06-1.06L10.94 12 5.47 6.53a.75.75 0 010-1.06z", clipRule: "evenodd" }) }) })] }, `bucketField-${index}`))) }), !bucketFields.length && (_jsx("div", { style: { marginTop: 12 }, children: _jsx(SecondaryButtonComponent, { onClick: handleAddBucket, label: "Add bucket +" }) }))] })), _jsx("div", { style: {
|
|
1202
|
-
display: 'flex',
|
|
1203
|
-
flexDirection: 'row',
|
|
1204
|
-
alignItems: 'center',
|
|
1205
|
-
// justifyContent: 'space-between',
|
|
1206
|
-
marginTop: 20,
|
|
1207
|
-
}, children: chartType !== 'table' && (_jsxs("div", { style: { display: 'flex', flexDirection: 'column' }, children: [_jsx("div", { style: formLabelStyle || {
|
|
1208
|
-
color: theme.secondaryTextColor,
|
|
1209
|
-
fontFamily: theme?.fontFamily,
|
|
1210
|
-
fontSize: theme?.fontSize || '14px',
|
|
1211
|
-
fontWeight: theme.labelFontWeight || '600',
|
|
1212
|
-
}, children: chartType === 'pie' ? 'Category column' : 'x-axis column' }), _jsx("div", { style: { height: 6 } }), _jsxs("div", { style: {
|
|
1213
|
-
display: 'flex',
|
|
1214
|
-
flexDirection: 'row',
|
|
1215
|
-
alignItems: 'center',
|
|
1216
|
-
}, children: [_jsx("div", { style: { minWidth: 200 }, children: _jsx(SelectComponent, { onChange: (e) => handleXAxisFieldChange(e), value: xAxisField, options: xAxisOptions, theme: theme }) }), _jsx("div", { style: { width: 20 } }), _jsx("div", { style: { minWidth: 200 }, children: _jsx(TextInputComponent, { onChange: (e) => setXAxisLabel(e.target.value), value: xAxisLabel, theme: theme, placeholder: 'Enter a label' }) }), _jsx("div", { style: { width: 20 } }), _jsx("div", { style: { minWidth: 200 }, children: _jsx(SelectComponent, { onChange: (e) => setXAxisFormat(e), value: xAxisFormat, options: X_FORMAT_OPTIONS, theme: theme }) })] })] })) }), _jsxs("div", { style: {
|
|
1217
|
-
display: 'flex',
|
|
1218
|
-
flexDirection: 'row',
|
|
1219
|
-
alignItems: 'flex-start',
|
|
1220
|
-
// justifyContent: 'space-between',
|
|
1221
|
-
marginTop: 20,
|
|
1222
|
-
}, children: [_jsxs("div", { style: { display: 'flex', flexDirection: 'column' }, children: [_jsx("div", { style: formLabelStyle || {
|
|
1223
|
-
color: theme.secondaryTextColor,
|
|
1224
|
-
fontFamily: theme?.fontFamily,
|
|
1225
|
-
fontSize: theme?.fontSize || '14px',
|
|
1226
|
-
fontWeight: theme.labelFontWeight || '600',
|
|
1227
|
-
}, children: chartType === 'table'
|
|
1228
|
-
? 'Columns'
|
|
1229
|
-
: chartType === 'pie'
|
|
1230
|
-
? 'Quantity column'
|
|
1231
|
-
: 'y-axis columns' }), _jsxs("div", { style: {
|
|
1232
|
-
display: 'flex',
|
|
1233
|
-
flexDirection: 'column',
|
|
1234
|
-
}, children: [yAxisFields.map((yAxisField, index) => (_jsx("div", { style: {
|
|
1235
|
-
display: 'flex',
|
|
1236
|
-
flexDirection: 'row',
|
|
1237
|
-
alignItems: 'center',
|
|
1238
|
-
marginTop: index === 0 ? 6 : 10,
|
|
1239
|
-
}, children: _jsx("div", { style: { minWidth: 200 }, children: _jsx(SelectComponent, { onChange: (option) => handleYAxisFieldChange(index, option), value: yAxisField.field, options: chartType === 'table' ? fieldOptions : yAxisOptions, theme: theme }) }) }, `yAxisField-${index}`))), chartType !== 'pie' && (_jsx("div", { style: { marginTop: 12 }, children: _jsx(SecondaryButtonComponent, { onClick: handleAddYAxisField, label: "Add column +" }) })), _jsx("div", { style: { height: 10 } })] })] }), _jsx("div", { style: { width: 20 } }), _jsxs("div", { style: {
|
|
1240
|
-
display: 'flex',
|
|
1241
|
-
flexDirection: 'column',
|
|
1242
|
-
justifyContent: 'flex-start',
|
|
1243
|
-
}, children: [_jsx("div", { style: formLabelStyle || {
|
|
1244
|
-
color: 'transparent',
|
|
1245
|
-
fontFamily: theme?.fontFamily,
|
|
1246
|
-
fontSize: theme?.fontSize || '14px',
|
|
1247
|
-
fontWeight: theme.labelFontWeight || '600',
|
|
1248
|
-
}, children: "y-axis label" }), chartType !== 'pie' &&
|
|
1249
|
-
yAxisFields.map((yAxisField, index) => (_jsxs("div", { style: {
|
|
1250
|
-
display: 'flex',
|
|
1251
|
-
flexDirection: 'row',
|
|
1252
|
-
// alignItems: 'center',
|
|
1253
|
-
marginTop: index === 0 ? 6 : 10,
|
|
1254
|
-
}, children: [_jsx("div", { style: { minWidth: 200 }, children: _jsx(TextInputComponent, { value: yAxisFields[index].label, onChange: (e) => {
|
|
1255
|
-
handleYAxisLabelChange(index, e.target.value);
|
|
1256
|
-
}, theme: theme, placeholder: 'Enter a label' }) }), _jsx("div", { style: { width: 20 } }), _jsx("div", { style: { minWidth: 200 }, children: _jsx(SelectComponent, { onChange: (value) => handleYAxisFieldFormatChange(index, value), value: yAxisField.format, options: Y_FORMAT_OPTIONS, theme: theme }) }), _jsx("div", { onClick: () => index > 0 ? handleDeleteYAxisField(index) : undefined, style: {
|
|
1257
|
-
cursor: index > 0 ? 'pointer' : undefined,
|
|
1258
|
-
paddingLeft: 6,
|
|
1259
|
-
paddingTop: 12,
|
|
1260
|
-
paddingBottom: 12,
|
|
1261
|
-
paddingRight: 6,
|
|
1262
|
-
maxHeight: 38,
|
|
1263
|
-
display: 'flex',
|
|
1264
|
-
alignItems: 'center',
|
|
1265
|
-
justifyContent: 'center',
|
|
1266
|
-
}, children: _jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: index > 0 ? theme?.secondaryTextColor : 'rgba(0,0,0,0)', height: "20", width: "20", children: _jsx("path", { fillRule: "evenodd", d: "M5.47 5.47a.75.75 0 011.06 0L12 10.94l5.47-5.47a.75.75 0 111.06 1.06L13.06 12l5.47 5.47a.75.75 0 11-1.06 1.06L12 13.06l-5.47 5.47a.75.75 0 01-1.06-1.06L10.94 12 5.47 6.53a.75.75 0 010-1.06z", clipRule: "evenodd" }) }) })] }, `yAxisField-${index}`)))] })] }), _jsx("div", { style: { height: 20 } }), showTableFormatOptions && (_jsxs(_Fragment, { children: [_jsx("div", { style: formHeaderStyle || {
|
|
1267
|
-
fontFamily: theme.fontFamily,
|
|
1268
|
-
color: theme.primaryTextColor,
|
|
1269
|
-
fontSize: theme.fontSize + 2,
|
|
1270
|
-
fontWeight: 600,
|
|
1271
|
-
// marginTop: 20,
|
|
1272
|
-
}, children: 'Table' }), _jsx("div", { style: { height: 8 } })] })), showTableFormatOptions && chartType !== 'table' && (_jsx("div", { style: formLabelStyle || {
|
|
1273
|
-
color: theme.secondaryTextColor,
|
|
1274
|
-
fontFamily: theme?.fontFamily,
|
|
1275
|
-
fontSize: theme?.fontSize || '14px',
|
|
1276
|
-
fontWeight: theme.labelFontWeight || '600',
|
|
1277
|
-
}, children: 'Columns' })), showTableFormatOptions && chartType !== 'table' && (_jsxs("div", { style: {
|
|
1278
|
-
display: 'flex',
|
|
1279
|
-
flexDirection: 'row',
|
|
1280
|
-
alignItems: 'flex-start',
|
|
1281
|
-
marginTop: 6,
|
|
1282
|
-
// justifyContent: 'space-between',
|
|
1283
|
-
// marginTop: 8,
|
|
1284
|
-
}, children: [_jsx("div", { style: { display: 'flex', flexDirection: 'column' }, children: _jsxs("div", { style: {
|
|
1285
|
-
display: 'flex',
|
|
1286
|
-
flexDirection: 'column',
|
|
1287
|
-
}, children: [columns.map((yAxisField, index) => (_jsx("div", { style: {
|
|
1288
|
-
display: 'flex',
|
|
1289
|
-
flexDirection: 'row',
|
|
1290
|
-
alignItems: 'center',
|
|
1291
|
-
marginTop: index === 0 ? 6 : 10,
|
|
1292
|
-
}, children: _jsx("div", { style: { minWidth: 200 }, children: _jsx(SelectComponent, { value: yAxisField.field, onChange: (option) => {
|
|
1293
|
-
handleColumnFieldChange(index, option);
|
|
1294
|
-
}, options: fieldOptions, theme: theme }) }) }, `column-${index}`))), _jsx("div", { style: { height: 10 } })] }) }), _jsx("div", { style: { width: 20 } }), _jsx("div", { style: {
|
|
1295
|
-
display: 'flex',
|
|
1296
|
-
flexDirection: 'column',
|
|
1297
|
-
justifyContent: 'flex-start',
|
|
1298
|
-
}, children: columns.map((yAxisField, index) => (_jsxs("div", { style: {
|
|
1299
|
-
display: 'flex',
|
|
1300
|
-
flexDirection: 'row',
|
|
1301
|
-
alignItems: 'center',
|
|
1302
|
-
marginTop: index === 0 ? 6 : 10,
|
|
1303
|
-
}, children: [_jsx("div", { style: { minWidth: 200 }, children: _jsx(TextInputComponent, { theme: theme, placeholder: "Enter column label", value: yAxisField.label, onChange: (event) => handleColumnLabelChange(index, event.target.value) }) }), _jsx("div", { style: { width: 20 } }), _jsx("div", { style: { minWidth: 200 }, children: _jsx(SelectComponent, { value: yAxisField.format, onChange: (option) => handleColumnFormatChange(index, option), options: Y_FORMAT_OPTIONS, theme: theme }) })] }, `column-${index}`))) })] })), showDateFieldOptions && _jsx("div", { style: { height: 20 } }), showDateFieldOptions && (_jsxs(_Fragment, { children: [_jsx("div", { style: formHeaderStyle || {
|
|
1304
|
-
fontFamily: theme.fontFamily,
|
|
1305
|
-
color: theme.primaryTextColor,
|
|
1306
|
-
fontSize: theme.fontSize + 2,
|
|
1307
|
-
fontWeight: 600,
|
|
1308
|
-
// marginTop: 20,
|
|
1309
|
-
}, children: 'Filters' }), _jsx("div", { style: { height: 8 } })] })), showDateFieldOptions && (_jsxs("div", { style: {
|
|
1310
|
-
display: 'flex',
|
|
1311
|
-
flexDirection: 'row',
|
|
1312
|
-
alignItems: 'center',
|
|
1313
|
-
}, children: [_jsxs("div", { style: { display: 'flex', flexDirection: 'column' }, children: [_jsx("div", { style: formLabelStyle || {
|
|
1314
|
-
color: theme.secondaryTextColor,
|
|
1315
|
-
fontFamily: theme?.fontFamily,
|
|
1316
|
-
fontSize: theme?.fontSize || '14px',
|
|
1317
|
-
fontWeight: theme.labelFontWeight || '600',
|
|
1318
|
-
}, children: "Date field table" }), _jsx("div", { style: { minWidth: 200, marginTop: 6 }, children: _jsx(SelectComponent, { options: !dateFieldOptions.length
|
|
1319
|
-
? [{ label: '', value: '' }]
|
|
1320
|
-
: dateFieldOptions.map((elem) => {
|
|
1321
|
-
return { label: elem.name, value: elem.name };
|
|
1322
|
-
}), onChange: (e) => setDateFieldTable(e), value: dateFieldTable, theme: theme }) })] }), _jsx("div", { style: { width: 20 } }), _jsxs("div", { style: { display: 'flex', flexDirection: 'column' }, children: [_jsx("div", { style: formLabelStyle || {
|
|
1323
|
-
color: theme.secondaryTextColor,
|
|
1324
|
-
fontFamily: theme?.fontFamily,
|
|
1325
|
-
fontSize: theme?.fontSize || '14px',
|
|
1326
|
-
fontWeight: theme.labelFontWeight || '600',
|
|
1327
|
-
}, children: "Date field" }), _jsx("div", { style: { minWidth: 200, marginTop: 6 }, children: _jsx(SelectComponent, { options: !dateFieldOptions.length
|
|
1328
|
-
? [{ label: '', value: '' }]
|
|
1329
|
-
: dateFieldOptions.filter((elem) => elem.name === dateFieldTable).length
|
|
1330
|
-
? dateFieldOptions
|
|
1331
|
-
.filter((elem) => elem.name === dateFieldTable)[0]
|
|
1332
|
-
.columns.map((elem) => {
|
|
1333
|
-
return { label: elem.name, value: elem.name };
|
|
1334
|
-
})
|
|
1335
|
-
: [{ label: '', value: '' }], onChange: (value) => setDateField(value), value: dateField, theme: theme }) })] })] })), showAccessControlOptions && (_jsxs("div", { style: {
|
|
1336
|
-
display: 'flex',
|
|
1337
|
-
flexDirection: 'column',
|
|
1338
|
-
marginTop: 40,
|
|
1339
|
-
marginBottom: 40,
|
|
1340
|
-
}, children: [_jsx("div", { style: {
|
|
1341
|
-
fontFamily: theme.fontFamily,
|
|
1342
|
-
color: theme.primaryTextColor,
|
|
1343
|
-
fontSize: theme.fontSize + 2,
|
|
1344
|
-
fontWeight: 600,
|
|
1345
|
-
}, children: 'Access Control' }), _jsx("div", { style: { height: 12 } }), _jsxs("div", { style: {
|
|
1346
|
-
padding: '1px',
|
|
1347
|
-
display: 'flex',
|
|
1348
|
-
flexDirection: 'row',
|
|
1349
|
-
fontSize: '14px',
|
|
1350
|
-
fontWeight: '500',
|
|
1351
|
-
height: '32px',
|
|
1352
|
-
width: '640px',
|
|
1353
|
-
color: '#212121',
|
|
1354
|
-
backgroundColor: 'rgba(33, 33, 33, 0.03)',
|
|
1355
|
-
borderRadius: '6px',
|
|
1356
|
-
}, children: [_jsx("div", { onClick: () => {
|
|
1357
|
-
setSelectedTabIndex(0);
|
|
1358
|
-
setTemplate(false);
|
|
1359
|
-
}, style: {
|
|
1360
|
-
width: '100%',
|
|
1361
|
-
borderRadius: '6px', // Equivalent to rounded-md
|
|
1362
|
-
padding: '4px', // Equivalent to py-1
|
|
1363
|
-
fontSize: '14px', // Equivalent to text-sm
|
|
1364
|
-
fontWeight: '500', // Equivalent to font-medium
|
|
1365
|
-
display: 'flex',
|
|
1366
|
-
flexDirection: 'column',
|
|
1367
|
-
alignItems: 'center',
|
|
1368
|
-
justifyContent: 'center',
|
|
1369
|
-
cursor: 'pointer',
|
|
1370
|
-
borderColor: '#E7E7E7',
|
|
1371
|
-
borderWidth: selectedTabIndex === 0 ? 1 : 0,
|
|
1372
|
-
borderStyle: 'solid',
|
|
1373
|
-
color: selectedTabIndex === 0
|
|
1374
|
-
? '#212121'
|
|
1375
|
-
: 'rgba(33, 33, 33, 0.3)', // Color and its hover state
|
|
1376
|
-
backgroundColor: selectedTabIndex === 0
|
|
1377
|
-
? 'white'
|
|
1378
|
-
: 'rgba(255, 255, 255, 0.12)', // Background and its hover state
|
|
1379
|
-
boxShadow: selectedTabIndex === 0
|
|
1380
|
-
? '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)'
|
|
1381
|
-
: undefined, // Shadow when selected
|
|
1382
|
-
outline: 'none', // focus:outline-none
|
|
1383
|
-
}, children: `This Organization${organizationName ? ` (${organizationName})` : ``}` }), _jsx("div", { onClick: () => {
|
|
1384
|
-
setSelectedTabIndex(1);
|
|
1385
|
-
setTemplate(true);
|
|
1386
|
-
}, style: {
|
|
1387
|
-
width: '100%',
|
|
1388
|
-
borderRadius: '6px', // Equivalent to rounded-md
|
|
1389
|
-
padding: '4px', // Equivalent to py-1
|
|
1390
|
-
fontSize: '14px', // Equivalent to text-sm
|
|
1391
|
-
fontWeight: '500', // Equivalent to font-medium
|
|
1392
|
-
display: 'flex',
|
|
1393
|
-
flexDirection: 'column',
|
|
1394
|
-
alignItems: 'center',
|
|
1395
|
-
justifyContent: 'center',
|
|
1396
|
-
cursor: 'pointer',
|
|
1397
|
-
borderColor: '#E7E7E7',
|
|
1398
|
-
borderWidth: selectedTabIndex === 1 ? 1 : 0,
|
|
1399
|
-
borderStyle: 'solid',
|
|
1400
|
-
color: selectedTabIndex === 1
|
|
1401
|
-
? '#212121'
|
|
1402
|
-
: 'rgba(33, 33, 33, 0.3)', // Color and its hover state
|
|
1403
|
-
backgroundColor: selectedTabIndex === 1
|
|
1404
|
-
? 'white'
|
|
1405
|
-
: 'rgba(255, 255, 255, 0.12)', // Background and its hover state
|
|
1406
|
-
boxShadow: selectedTabIndex === 1
|
|
1407
|
-
? '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)'
|
|
1408
|
-
: undefined, // Shadow when selected
|
|
1409
|
-
outline: 'none', // focus:outline-none
|
|
1410
|
-
}, children: 'Global (All Organizations)' })] })] })), _jsx("div", { style: { paddingRight: 25 }, children: _jsx(ButtonComponent, { onClick: () => {
|
|
1411
|
-
const { xAxisField, xAxisLabel, xAxisFormat, chartName, chartType, dashboardName, dateFieldTable, dateField, template, } = chartConfig;
|
|
1412
|
-
if (isSubmitting === false) {
|
|
1413
|
-
editChart({
|
|
1414
|
-
setIsSubmitting,
|
|
1415
|
-
report,
|
|
1416
|
-
values: {
|
|
1417
|
-
xAxisField,
|
|
1418
|
-
xAxisLabel,
|
|
1419
|
-
xAxisFormat,
|
|
1420
|
-
chartName,
|
|
1421
|
-
chartType,
|
|
1422
|
-
dashboardName,
|
|
1423
|
-
dateFieldTable,
|
|
1424
|
-
dateField,
|
|
1425
|
-
template,
|
|
1426
|
-
},
|
|
1427
|
-
yAxisFields,
|
|
1428
|
-
columns,
|
|
1429
|
-
query,
|
|
1430
|
-
buckets: bucketFields,
|
|
1431
|
-
showTableFormatOptions,
|
|
1432
|
-
});
|
|
1433
|
-
}
|
|
1434
|
-
}, label: report ? 'Save changes' : 'Add to dashboard' }) }), _jsx("div", { style: { height: 20 } })] }) }));
|
|
1435
|
-
}
|