@quillsql/react 2.10.17 → 2.10.19

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