@quillsql/react 2.1.2 → 2.1.5

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.
@@ -1,16 +1,40 @@
1
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
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.formatDateBuckets = exports.isArrayOfValidDates = exports.isValidDate = void 0;
29
+ exports.formatDateBuckets = exports.isArrayOfValidDates = exports.isValidDate = exports.ChartForm = void 0;
7
30
  const jsx_runtime_1 = require("react/jsx-runtime");
8
31
  // @ts-nocheck
9
- const react_1 = require("react");
32
+ const react_1 = __importStar(require("react"));
10
33
  const Context_1 = require("./Context");
11
- const formik_1 = require("formik");
12
34
  const date_fns_1 = require("date-fns");
13
35
  const Chart_1 = __importDefault(require("./Chart"));
36
+ const ReportBuilder_1 = require("./ReportBuilder");
37
+ const aggregate_1 = require("./utils/aggregate");
14
38
  function convertPostgresColumn(column) {
15
39
  let format;
16
40
  switch (column.dataTypeID) {
@@ -36,13 +60,13 @@ function convertPostgresColumn(column) {
36
60
  }
37
61
  return {
38
62
  label: column.name,
39
- field: column.name,
63
+ field: column.field,
40
64
  format: format,
41
65
  };
42
66
  }
43
67
  function updateLabels(yAxisFields, values) {
44
68
  return yAxisFields.map((item, index) => {
45
- let updatedItem = { ...item };
69
+ const updatedItem = { ...item };
46
70
  if (values[`yAxisLabel-${index}`]) {
47
71
  updatedItem.label = values[`yAxisLabel-${index}`];
48
72
  }
@@ -55,10 +79,63 @@ function updateLabels(yAxisFields, values) {
55
79
  return updatedItem;
56
80
  });
57
81
  }
58
- function AddToDashboardModal({ isOpen, setIsOpen, SelectComponent, TextInputComponent, ButtonComponent, SecondaryButtonComponent, rows, columns, query, ModalComponent, formHeaderStyle, formLabelStyle, showTableFormatOptions = false, showDateFieldOptions = false, onAddToDashboardComplete, }) {
82
+ const DefaultSelectComponent = function DefaultSelect({ onChange, value, options, form, field, theme, }) {
83
+ return ((0, jsx_runtime_1.jsx)("select", { onChange: event => onChange(event.target.value), value: value, id: 'reportbuilderdropdown', style: {
84
+ width: 200,
85
+ outline: 'none',
86
+ textAlign: 'left',
87
+ whiteSpace: 'nowrap',
88
+ overflow: 'hidden',
89
+ textOverflow: 'ellipsis',
90
+ borderRadius: 6,
91
+ paddingLeft: 12,
92
+ paddingRight: 12,
93
+ height: 38,
94
+ borderWidth: theme.borderWidth,
95
+ borderColor: theme.borderColor,
96
+ boxSizing: 'border-box',
97
+ background: theme.backgroundColor,
98
+ color: theme.primaryTextColor,
99
+ boxShadow: '0 1px 2px 0 rgba(0,0,0,.05)',
100
+ fontFamily: theme.fontFamily,
101
+ }, children: options.map((option, index) => ((0, jsx_runtime_1.jsx)("option", { value: option.value, children: option.label }, option.label + index))) }));
102
+ };
103
+ const MemoizedDefaultSelectComponent = react_1.default.memo(DefaultSelectComponent);
104
+ const DefaultTextInputComponent = function DefaultText({ onChange, value, id, theme, placeholder, }) {
105
+ return ((0, jsx_runtime_1.jsx)("input", { style: {
106
+ outline: 'none',
107
+ textAlign: 'left',
108
+ whiteSpace: 'nowrap',
109
+ overflow: 'hidden',
110
+ textOverflow: 'ellipsis',
111
+ borderRadius: 6,
112
+ paddingLeft: 12,
113
+ paddingRight: 12,
114
+ margin: 0,
115
+ paddingTop: 0,
116
+ paddingBottom: 0,
117
+ boxSizing: 'border-box',
118
+ width: 200,
119
+ height: 38,
120
+ borderWidth: theme.borderWidth,
121
+ borderColor: theme.borderColor,
122
+ borderStyle: 'solid',
123
+ background: theme.backgroundColor,
124
+ color: theme.primaryTextColor,
125
+ boxShadow: '0 1px 2px 0 rgba(0,0,0,.05)',
126
+ fontFamily: theme.fontFamily,
127
+ }, id: id, onChange: onChange, value: value, placeholder: placeholder }));
128
+ };
129
+ const MemoizedDefaultTextInputComponent = react_1.default.memo(DefaultTextInputComponent);
130
+ function AddToDashboardModal({ isOpen, setIsOpen, SelectComponent, TextInputComponent, ButtonComponent, SecondaryButtonComponent, rows, columns, query, report, ModalComponent, formHeaderStyle, formLabelStyle, showTableFormatOptions = false, showDateFieldOptions = false, showAccessControlOptions = false, onAddToDashboardComplete, fields, }) {
59
131
  const [theme] = (0, react_1.useContext)(Context_1.ThemeContext);
60
132
  const [client] = (0, react_1.useContext)(Context_1.ClientContext);
61
133
  const [schema, setSchema] = (0, react_1.useContext)(Context_1.SchemaContext);
134
+ const [organization, setOrganization] = (0, react_1.useState)([]);
135
+ const { publicKey, environment } = client;
136
+ // showTableFormatOptions = false;
137
+ // showDateFieldOptions = false;
138
+ // showAccessControlOptions = false;3
62
139
  (0, react_1.useEffect)(() => {
63
140
  let isSubscribed = true;
64
141
  async function getSchema() {
@@ -98,32 +175,72 @@ function AddToDashboardModal({ isOpen, setIsOpen, SelectComponent, TextInputComp
98
175
  isSubscribed = false;
99
176
  };
100
177
  }, [schema]);
101
- const editChart = async ({ report, values, yAxisFields, columns, query }) => {
178
+ (0, react_1.useEffect)(() => {
179
+ let isSubscribed = true;
180
+ async function getCustomers() {
181
+ const response = await fetch(`https://quill-344421.uc.r.appspot.com/orgs/${publicKey}/`, {
182
+ method: 'GET',
183
+ headers: {
184
+ Authorization: 'Bearer ',
185
+ environment: environment,
186
+ },
187
+ });
188
+ if (!response.ok) {
189
+ throw new Error('Network response was not ok');
190
+ }
191
+ const data = await response.json();
192
+ if (environment === 'STAGING') {
193
+ setOrganization(response.data.orgs.filter(org => org.id === client.stagingAdminCustomerId)[0]);
194
+ }
195
+ else {
196
+ setOrganization(data.orgs.filter(org => org.id === client.adminCustomerId)[0]);
197
+ }
198
+ }
199
+ if (isSubscribed && environment && client) {
200
+ getCustomers();
201
+ }
202
+ return () => {
203
+ isSubscribed = false;
204
+ };
205
+ }, [environment, client]);
206
+ const editChart = async ({ report, setIsSubmitting, values, yAxisFields, columns, query, buckets, showTableFormatOptions, }) => {
102
207
  const { publicKey, customerId, authToken, queryEndpoint, queryHeaders, withCredentials, environment, } = client;
103
- const { xAxisLabel, yAxisLabel, chartName, chartType, xAxisField, xAxisFormat, dashboardName, dateFieldTable, dateField, } = values;
208
+ const { xAxisLabel, chartName, chartType, xAxisField, xAxisFormat, dashboardName, dateFieldTable, dateField, template, } = values;
104
209
  if (!chartName) {
105
210
  alert('Please enter a chart name');
106
211
  return;
107
212
  }
108
- // if (!dashboardName) {
109
- // alert("Please choose a dashboard name");
110
- // return;
111
- // }
112
- // if (!xAxisLabel && chartType !== "pie" && chartType !== "table") {
113
- // alert("Please enter a label for the x-axis");
114
- // return;
115
- // }
116
- // if (!yAxisLabel && chartType !== "pie" && chartType !== "table") {
117
- // alert("Please enter a label for the y-axis");
118
- // return;
119
- // }
120
- const newYAxisFields = updateLabels(yAxisFields, values);
121
- for (let i = 0; i < newYAxisFields.length; i++) {
122
- if (!newYAxisFields[i].label && chartType !== 'pie') {
123
- alert(`Please enter a label for column '${newYAxisFields[i].field}'`);
124
- return;
125
- }
213
+ if (!dashboardName) {
214
+ alert('Please choose a dashboard name');
215
+ return;
216
+ }
217
+ if (!xAxisLabel && chartType !== 'pie' && chartType !== 'table') {
218
+ alert('Please enter a label for the x-axis');
219
+ return;
220
+ }
221
+ if (!xAxisField) {
222
+ alert('Please enter a label for the x-axis');
223
+ return;
224
+ }
225
+ if (!yAxisFields.map(field => field.label).every(Boolean) &&
226
+ chartType !== 'pie' &&
227
+ chartType !== 'table') {
228
+ alert('Please enter a label for the y-axis');
229
+ return;
230
+ }
231
+ if (!columns.map((yAxisField, _) => yAxisField.label).every(Boolean) &&
232
+ showTableFormatOptions) {
233
+ alert('Please enter a label for the table y-axis');
234
+ return;
126
235
  }
236
+ setIsSubmitting(true);
237
+ // const newYAxisFields = updateLabels(yAxisFields, values);
238
+ // for (let i = 0; i < newYAxisFields.length; i++) {
239
+ // if (!newYAxisFields[i].label && chartType !== 'pie') {
240
+ // alert(`Please enter a label for column '${newYAxisFields[i].field}'`);
241
+ // return;
242
+ // }
243
+ // }
127
244
  if (!client || !customerId) {
128
245
  return;
129
246
  }
@@ -164,38 +281,87 @@ function AddToDashboardModal({ isOpen, setIsOpen, SelectComponent, TextInputComp
164
281
  };
165
282
  const body = JSON.stringify({
166
283
  metadata: customerId
167
- ? {
168
- name: chartName,
169
- xAxisField,
170
- yAxisFields: newYAxisFields,
171
- xAxisLabel,
172
- xAxisFormat,
173
- yAxisLabel,
174
- chartType,
175
- dashboardName,
176
- columns: showTableFormatOptions ? columns : newYAxisFields,
177
- dateField: showDateFieldOptions
178
- ? { table: dateFieldTable, field: dateField }
179
- : defaultDateField,
180
- query: query,
181
- task: 'create',
182
- orgId: customerId,
183
- }
284
+ ? report
285
+ ? {
286
+ dashboardItemId: report._id,
287
+ name: chartName,
288
+ xAxisField,
289
+ yAxisFields,
290
+ xAxisLabel,
291
+ xAxisFormat,
292
+ chartType,
293
+ dashboardName,
294
+ columns: showTableFormatOptions
295
+ ? columns
296
+ : [
297
+ ...yAxisFields,
298
+ {
299
+ field: xAxisField,
300
+ label: xAxisLabel,
301
+ format: xAxisFormat,
302
+ },
303
+ ],
304
+ dateField: showDateFieldOptions
305
+ ? { table: dateFieldTable, field: dateField }
306
+ : defaultDateField,
307
+ query: query,
308
+ task: 'create',
309
+ orgId: customerId,
310
+ template: template,
311
+ buckets,
312
+ }
313
+ : {
314
+ name: chartName,
315
+ xAxisField,
316
+ yAxisFields,
317
+ xAxisLabel,
318
+ xAxisFormat,
319
+ chartType,
320
+ dashboardName,
321
+ columns: showTableFormatOptions
322
+ ? columns
323
+ : [
324
+ ...yAxisFields,
325
+ {
326
+ field: xAxisField,
327
+ label: xAxisLabel,
328
+ format: xAxisFormat,
329
+ },
330
+ ],
331
+ dateField: showDateFieldOptions
332
+ ? { table: dateFieldTable, field: dateField }
333
+ : defaultDateField,
334
+ query: query,
335
+ task: 'create',
336
+ orgId: customerId,
337
+ template: template,
338
+ buckets,
339
+ }
184
340
  : {
185
341
  name: chartName,
186
342
  xAxisField,
187
- yAxisFields: newYAxisFields,
343
+ yAxisFields,
188
344
  xAxisLabel,
189
345
  xAxisFormat,
190
- yAxisLabel,
191
346
  chartType,
192
347
  dashboardName,
193
- columns: showTableFormatOptions ? columns : newYAxisFields,
348
+ columns: showTableFormatOptions
349
+ ? columns
350
+ : [
351
+ ...yAxisFields,
352
+ {
353
+ field: xAxisField,
354
+ label: xAxisLabel,
355
+ format: xAxisFormat,
356
+ },
357
+ ],
194
358
  dateField: showDateFieldOptions
195
359
  ? { table: dateFieldTable, field: dateField }
196
360
  : defaultDateField,
197
361
  query: query,
198
362
  task: 'create',
363
+ template: template,
364
+ buckets,
199
365
  },
200
366
  });
201
367
  const response = await fetch(url, {
@@ -240,26 +406,67 @@ function AddToDashboardModal({ isOpen, setIsOpen, SelectComponent, TextInputComp
240
406
  if (environment) {
241
407
  headers['environment'] = environment;
242
408
  }
243
- const body = JSON.stringify({
244
- name: chartName,
245
- xAxisField,
246
- yAxisFields: newYAxisFields,
247
- xAxisLabel,
248
- xAxisFormat,
249
- yAxisLabel,
250
- chartType,
251
- dashboardName,
252
- columns: showTableFormatOptions ? columns : newYAxisFields,
253
- dateField: showDateFieldOptions
254
- ? { table: dateFieldTable, field: dateField }
255
- : defaultDateField,
256
- query: query,
257
- });
409
+ let body2;
410
+ if (report) {
411
+ body2 = JSON.stringify({
412
+ dashboardItemId: report._id,
413
+ name: chartName,
414
+ xAxisField,
415
+ yAxisFields,
416
+ xAxisLabel,
417
+ xAxisFormat,
418
+ chartType,
419
+ dashboardName,
420
+ columns: showTableFormatOptions
421
+ ? columns
422
+ : [
423
+ ...yAxisFields,
424
+ {
425
+ field: xAxisField,
426
+ label: xAxisLabel,
427
+ format: xAxisFormat,
428
+ },
429
+ ],
430
+ dateField: showDateFieldOptions
431
+ ? { table: dateFieldTable, field: dateField }
432
+ : defaultDateField,
433
+ query: query,
434
+ template: template,
435
+ buckets,
436
+ });
437
+ }
438
+ else {
439
+ body2 = JSON.stringify({
440
+ name: chartName,
441
+ xAxisField,
442
+ yAxisFields,
443
+ xAxisLabel,
444
+ xAxisFormat,
445
+ chartType,
446
+ dashboardName,
447
+ columns: showTableFormatOptions
448
+ ? columns
449
+ : [
450
+ ...yAxisFields,
451
+ {
452
+ field: xAxisField,
453
+ label: xAxisLabel,
454
+ format: xAxisFormat,
455
+ },
456
+ ],
457
+ dateField: showDateFieldOptions
458
+ ? { table: dateFieldTable, field: dateField }
459
+ : defaultDateField,
460
+ query: query,
461
+ template: template,
462
+ buckets,
463
+ });
464
+ }
258
465
  try {
259
466
  const response = await fetch(url, {
260
467
  method: 'POST',
261
468
  headers: headers,
262
- body: body,
469
+ body: body2,
263
470
  });
264
471
  responseData = await response.json();
265
472
  setIsOpen(false);
@@ -284,38 +491,30 @@ function AddToDashboardModal({ isOpen, setIsOpen, SelectComponent, TextInputComp
284
491
  // TODO: fire callback instead so user can customize action
285
492
  // navigate("/dashboards");
286
493
  };
494
+ // console.log('report', report);
287
495
  return (
288
496
  // <BigModal theme={theme} showModal={isOpen} setShowModal={setIsOpen}>
289
- (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,
290
- // leave null for now
291
- report: null, query: query,
292
- // organizationName={organization?.name}
293
- SelectComponent: SelectComponent, TextInputComponent: TextInputComponent, ButtonComponent: ButtonComponent, SecondaryButtonComponent: SecondaryButtonComponent, formHeaderStyle: formHeaderStyle, formLabelStyle: formLabelStyle, showTableFormatOptions: showTableFormatOptions, showDateFieldOptions: showDateFieldOptions }) })) : ((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,
294
- // leave null for now
295
- report: null, query: query,
296
- // organizationName={organization?.name}
297
- SelectComponent: SelectComponent, TextInputComponent: TextInputComponent, ButtonComponent: ButtonComponent, SecondaryButtonComponent: SecondaryButtonComponent, formHeaderStyle: formHeaderStyle, formLabelStyle: formLabelStyle, showTableFormatOptions: showTableFormatOptions, showDateFieldOptions: showDateFieldOptions }) })) }));
497
+ (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, organizationName: organization?.name, 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, organizationName: organization?.name, SelectComponent: SelectComponent, TextInputComponent: TextInputComponent, ButtonComponent: ButtonComponent, SecondaryButtonComponent: SecondaryButtonComponent, formHeaderStyle: formHeaderStyle, formLabelStyle: formLabelStyle, showTableFormatOptions: showTableFormatOptions, showDateFieldOptions: showDateFieldOptions, showAccessControlOptions: showAccessControlOptions, newFields: fields }) })) }));
298
498
  }
299
499
  exports.default = AddToDashboardModal;
300
500
  function QuillModal({ isOpen, setIsOpen, title, children }) {
301
- let scrollPosition = 0;
302
- (0, react_1.useEffect)(() => {
303
- if (isOpen) {
304
- scrollPosition = window.scrollY;
305
- document.body.style.overflow = 'hidden';
306
- document.body.style.position = 'fixed';
307
- document.body.style.top = `-${scrollPosition}px`;
308
- document.body.style.width = '100%';
309
- }
310
- else {
311
- document.body.style.removeProperty('overflow');
312
- document.body.style.removeProperty('position');
313
- document.body.style.removeProperty('top');
314
- document.body.style.removeProperty('width');
315
- // Restore the scroll position
316
- window.scrollTo(0, scrollPosition);
317
- }
318
- }, [isOpen]);
501
+ const scrollPosition = 0;
502
+ // useEffect(() => {
503
+ // if (isOpen) {
504
+ // scrollPosition = window.scrollY;
505
+ // // document.body.style.overflow = 'hidden';
506
+ // // document.body.style.position = 'fixed';
507
+ // // document.body.style.top = `-${scrollPosition}px`;
508
+ // // document.body.style.width = '100%';
509
+ // } else {
510
+ // document.body.style.removeProperty('overflow');
511
+ // document.body.style.removeProperty('position');
512
+ // document.body.style.removeProperty('top');
513
+ // document.body.style.removeProperty('width');
514
+ // // Restore the scroll position
515
+ // window.scrollTo(0, scrollPosition);
516
+ // }
517
+ // }, [isOpen]);
319
518
  if (!isOpen) {
320
519
  return null;
321
520
  }
@@ -368,14 +567,34 @@ function QuillModal({ isOpen, setIsOpen, title, children }) {
368
567
  textAlign: 'left',
369
568
  }, children: title }), children] }) })] }));
370
569
  }
371
- function ChartForm({ data, fields, theme, saveVisualization, report, editChart, schema, query,
372
- // organizationName,
373
- SelectComponent, TextInputComponent, ButtonComponent, SecondaryButtonComponent, formHeaderStyle, formLabelStyle, showTableFormatOptions, showDateFieldOptions, }) {
570
+ function ChartForm({ data, fields, theme, saveVisualization, report, editChart, schema, query, organizationName, SelectComponent, TextInputComponent, client, ButtonComponent, SecondaryButtonComponent, formHeaderStyle, formLabelStyle, showTableFormatOptions, showDateFieldOptions, showAccessControlOptions, newFields, }) {
571
+ if (report) {
572
+ newFields = report.fields;
573
+ }
374
574
  const fieldOptions = Object.keys(data[0]).map(field => ({
375
575
  value: field,
376
576
  label: field,
377
577
  }));
578
+ const xAxisOptions = Object.keys(data[0])
579
+ .filter(option => (0, ReportBuilder_1.getPostgresBasicType)(newFields.find(field => field.name === option)) ===
580
+ 'date' ||
581
+ (0, ReportBuilder_1.getPostgresBasicType)(newFields.find(field => field.name === option)) ===
582
+ 'string')
583
+ .map(field => ({
584
+ value: field,
585
+ label: field,
586
+ }));
587
+ const yAxisOptions = Object.keys(data[0])
588
+ .filter(option =>
589
+ // whatIsProbablyTheType([...data.slice(0, 10)], option) === 'number'
590
+ (0, ReportBuilder_1.getPostgresBasicType)(newFields.find(field => field.name === option)) ===
591
+ 'number')
592
+ .map(field => ({
593
+ value: field,
594
+ label: field,
595
+ }));
378
596
  const [dateFieldOptions, setDateFieldOptions] = (0, react_1.useState)([]);
597
+ const [formValues, setFormValues] = (0, react_1.useState)({});
379
598
  (0, react_1.useEffect)(() => {
380
599
  const fetchReferencedTables = async () => {
381
600
  if (!query) {
@@ -386,115 +605,60 @@ SelectComponent, TextInputComponent, ButtonComponent, SecondaryButtonComponent,
386
605
  };
387
606
  fetchReferencedTables();
388
607
  }, [query, schema]);
389
- return ((0, jsx_runtime_1.jsx)(formik_1.Formik, { initialValues: {
390
- xAxisField: report?.xAxisField || fieldOptions[0].value,
391
- xAxisLabel: report?.xAxisLabel || '',
392
- xAxisFormat: report?.xAxisFormat || FORMAT_OPTIONS[0].value,
393
- yAxisLabel: report?.yAxisLabel || '',
394
- 'yAxisLabel-0': '',
395
- 'yAxisLabel-1': '',
396
- 'yAxisLabel-2': '',
397
- 'yAxisLabel-3': '',
398
- 'yAxisFieldFormat-0': '',
399
- 'yAxisFieldFormat-1': '',
400
- 'yAxisFieldFormat-2': '',
401
- 'yAxisFieldFormat-3': '',
402
- 'yAxisField-0': '',
403
- 'yAxisField-1': '',
404
- 'yAxisField-2': '',
405
- 'yAxisField-3': '',
406
- chartName: report?.name || '',
407
- chartType: report?.chartType || 'column',
408
- xAxisFieldLabel: '',
409
- dashboardName: report?.dashboardName || '',
410
- dateFieldTable: (dateFieldOptions.length && dateFieldOptions[0].name) || '',
411
- dateField: (dateFieldOptions.length && dateFieldOptions[0].columns[0].name) ||
412
- '',
413
- template: report?.template || false,
414
- }, onSubmit: () => { }, children: ({ values, isSubmitting, setFieldValue }) => ((0, jsx_runtime_1.jsx)(FormikForm, { values: values, isSubmitting: isSubmitting, data: data, fieldOptions: fieldOptions, dateFieldOptions: dateFieldOptions, theme: theme, saveVisualization: saveVisualization, report: report, editChart: editChart, fields: fields, query: query, setFieldValue: setFieldValue, showTableFormatOptions: showTableFormatOptions, showDateFieldOptions: showDateFieldOptions, showAccessControlOptions: false,
415
- // organizationName={organizationName}
416
- SelectComponent: SelectComponent
417
- ? SelectComponent
418
- : ({ onChange, value, options }) => {
419
- return ((0, jsx_runtime_1.jsx)("select", { onChange: event => onChange(event.target.value), value: value, id: 'reportbuilderdropdown', style: {
420
- width: 200,
421
- outline: 'none',
422
- textAlign: 'left',
423
- whiteSpace: 'nowrap',
424
- overflow: 'hidden',
425
- textOverflow: 'ellipsis',
426
- borderRadius: 6,
427
- paddingLeft: 12,
428
- paddingRight: 12,
429
- height: 38,
430
- borderWidth: theme.borderWidth,
431
- borderColor: theme.borderColor,
432
- background: theme.backgroundColor,
433
- color: theme.primaryTextColor,
434
- boxShadow: '0 1px 2px 0 rgba(0,0,0,.05)',
435
- fontFamily: theme.fontFamily,
436
- }, children: options.map((option, index) => ((0, jsx_runtime_1.jsx)("option", { value: option.value, children: option.label }, option.label + index))) }));
437
- }, TextInputComponent: TextInputComponent
438
- ? TextInputComponent
439
- : ({ onChange, value, id }) => {
440
- return ((0, jsx_runtime_1.jsx)("input", { style: {
441
- outline: 'none',
442
- textAlign: 'left',
443
- whiteSpace: 'nowrap',
444
- overflow: 'hidden',
445
- textOverflow: 'ellipsis',
446
- borderRadius: 6,
447
- paddingLeft: 12,
448
- paddingRight: 12,
449
- width: 200,
450
- height: 38,
451
- borderWidth: theme.borderWidth,
452
- borderColor: theme.borderColor,
453
- borderStyle: 'solid',
454
- background: theme.backgroundColor,
455
- color: theme.primaryTextColor,
456
- boxShadow: '0 1px 2px 0 rgba(0,0,0,.05)',
457
- fontFamily: theme.fontFamily,
458
- }, id: id, onChange: onChange, value: value }));
459
- }, ButtonComponent: ButtonComponent
460
- ? ButtonComponent
461
- : ({ onClick, label }) => {
462
- return ((0, jsx_runtime_1.jsx)("div", { style: {
463
- height: 38,
464
- background: theme.primaryButtonColor,
465
- color: theme.backgroundColor,
466
- display: 'flex',
467
- borderRadius: 6,
468
- alignItems: 'center',
469
- justifyContent: 'center',
470
- outline: 'none',
471
- cursor: 'pointer',
472
- fontFamily: theme.fontFamily,
473
- fontWeight: theme.buttonFontWeight || 600,
474
- border: 'none',
475
- fontSize: 14,
476
- }, onClick: onClick, children: label }));
477
- }, SecondaryButtonComponent: ButtonComponent
478
- ? ButtonComponent
479
- : ({ onClick, label }) => {
480
- return ((0, jsx_runtime_1.jsx)("div", { style: {
481
- height: 38,
482
- background: theme.backgroundColor,
483
- borderWidth: theme.borderWidth,
484
- borderColor: theme.borderColor,
485
- color: theme.primaryTextColor,
486
- display: 'flex',
487
- borderRadius: 6,
488
- alignItems: 'center',
489
- justifyContent: 'center',
490
- outline: 'none',
491
- cursor: 'pointer',
492
- fontFamily: theme.fontFamily,
493
- fontWeight: theme.buttonFontWeight || 600,
494
- fontSize: 14,
495
- }, onClick: onClick, children: label }));
496
- }, formHeaderStyle: formHeaderStyle, formLabelStyle: formLabelStyle })) }));
608
+ 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
609
+ ? ({ onChange, value, options, form, field, }) => {
610
+ const handleChange = async (option) => {
611
+ if (onChange) {
612
+ onChange(option);
613
+ return;
614
+ }
615
+ await form.setFieldValue(field.name, option);
616
+ form.setFieldTouched(field.name, true);
617
+ };
618
+ return ((0, jsx_runtime_1.jsx)(SelectComponent, { onChange: event => handleChange(event.target.value), value: value, options: options }));
619
+ }
620
+ : MemoizedDefaultSelectComponent, TextInputComponent: TextInputComponent
621
+ ? TextInputComponent
622
+ : MemoizedDefaultTextInputComponent, ButtonComponent: ButtonComponent
623
+ ? ButtonComponent
624
+ : ({ onClick, label }) => {
625
+ return ((0, jsx_runtime_1.jsx)("div", { style: {
626
+ height: 38,
627
+ background: theme.primaryButtonColor,
628
+ color: theme.backgroundColor,
629
+ display: 'flex',
630
+ borderRadius: 6,
631
+ alignItems: 'center',
632
+ justifyContent: 'center',
633
+ outline: 'none',
634
+ cursor: 'pointer',
635
+ fontFamily: theme.fontFamily,
636
+ fontWeight: theme.buttonFontWeight || 600,
637
+ border: 'none',
638
+ fontSize: 14,
639
+ }, onClick: onClick, children: label }));
640
+ }, SecondaryButtonComponent: ButtonComponent
641
+ ? ButtonComponent
642
+ : ({ onClick, label }) => {
643
+ return ((0, jsx_runtime_1.jsx)("div", { style: {
644
+ height: 38,
645
+ background: theme.backgroundColor,
646
+ borderWidth: theme.borderWidth,
647
+ borderColor: theme.borderColor,
648
+ color: theme.primaryTextColor,
649
+ display: 'flex',
650
+ borderRadius: 6,
651
+ alignItems: 'center',
652
+ justifyContent: 'center',
653
+ outline: 'none',
654
+ cursor: 'pointer',
655
+ fontFamily: theme.fontFamily,
656
+ fontWeight: theme.buttonFontWeight || 600,
657
+ fontSize: 14,
658
+ }, onClick: onClick, children: label }));
659
+ }, formHeaderStyle: formHeaderStyle, formLabelStyle: formLabelStyle }));
497
660
  }
661
+ exports.ChartForm = ChartForm;
498
662
  function isValidDate(d) {
499
663
  return d instanceof Date && !isNaN(d);
500
664
  }
@@ -563,8 +727,8 @@ const POSTGRES_DATE_TYPES = [
563
727
  ];
564
728
  async function getReferencedTables(sqlQuery, databaseType, dbTables) {
565
729
  // const parser = new Parser();
566
- let tables = [];
567
- let withAliases = [];
730
+ const tables = [];
731
+ const withAliases = [];
568
732
  const response = await fetch('https://quill-344421.uc.r.appspot.com/astify', {
569
733
  method: 'POST',
570
734
  headers: {
@@ -593,7 +757,20 @@ async function getReferencedTables(sqlQuery, databaseType, dbTables) {
593
757
  })
594
758
  .filter(table => table.columns.length > 0);
595
759
  }
596
- const FORMAT_OPTIONS = [
760
+ const X_FORMAT_OPTIONS = [
761
+ { value: 'whole_number', label: 'whole number' },
762
+ { value: 'one_decimal_place', label: 'one decimal place' },
763
+ { value: 'dollar_amount', label: 'dollar amount' },
764
+ { value: 'MMM_yyyy', label: 'month' },
765
+ { value: 'MMM_dd-MMM_dd', label: 'week' },
766
+ { value: 'MMM_dd_yyyy', label: 'day' },
767
+ { value: 'MMM_dd_hh:mm_ap_pm', label: 'day and time' },
768
+ { value: 'hh_ap_pm', label: 'hour' },
769
+ { value: 'percent', label: 'percent' },
770
+ { value: 'string', label: 'string' },
771
+ { value: 'dynamic', label: 'dynamic' },
772
+ ];
773
+ const Y_FORMAT_OPTIONS = [
597
774
  { value: 'whole_number', label: 'whole number' },
598
775
  { value: 'one_decimal_place', label: 'one decimal place' },
599
776
  { value: 'dollar_amount', label: 'dollar amount' },
@@ -605,19 +782,48 @@ const FORMAT_OPTIONS = [
605
782
  { value: 'percent', label: 'percent' },
606
783
  { value: 'string', label: 'string' },
607
784
  ];
608
- function FormikForm({ values, isSubmitting, data, fieldOptions, dateFieldOptions, theme, report, editChart, fields, query, SelectComponent, TextInputComponent, ButtonComponent, SecondaryButtonComponent, setFieldValue, organizationName, formHeaderStyle, formLabelStyle, showTableFormatOptions, showDateFieldOptions, showAccessControlOptions, }) {
785
+ const handleBucketData = (dashboardItem, bucketFields, dateFilter) => {
786
+ const result = (0, aggregate_1.aggregate)(dashboardItem, bucketFields, dateFilter);
787
+ return (0, aggregate_1.aggregate)(dashboardItem, bucketFields, dateFilter);
788
+ };
789
+ function FormikForm({ data, xAxisOptions, yAxisOptions, fieldOptions, dateFieldOptions, theme, report, editChart, fields, newFields, query, client, SelectComponent, TextInputComponent, ButtonComponent, SecondaryButtonComponent, organizationName, formHeaderStyle, formLabelStyle, showTableFormatOptions, showDateFieldOptions, showAccessControlOptions, }) {
790
+ // fieldOptions.sort((a, b) => {
791
+ // if (a.value === 'created_at') return -1;
792
+ // if (b.value === 'created_at') return 1;
793
+ // return 0;
794
+ // });
795
+ X_FORMAT_OPTIONS.sort((a, b) => {
796
+ if (a.value === 'dynamic')
797
+ return -1;
798
+ if (b.value === 'dynamic')
799
+ return 1;
800
+ return 0;
801
+ });
802
+ const [rows, setRows] = (0, react_1.useState)(null);
803
+ const [isSubmitting, setIsSubmitting] = (0, react_1.useState)(false);
804
+ const { environment } = client;
805
+ const [xAxisField, setXAxisField] = (0, react_1.useState)(report?.xAxisField || xAxisOptions[0].value);
806
+ const [xAxisLabel, setXAxisLabel] = (0, react_1.useState)(report?.xAxisLabel || '');
807
+ const [xAxisFormat, setXAxisFormat] = (0, react_1.useState)(report?.xAxisFormat || X_FORMAT_OPTIONS[0].value);
808
+ const [chartName, setChartName] = (0, react_1.useState)(report?.name || '');
809
+ const [chartType, setChartType] = (0, react_1.useState)(report?.chartType || 'column');
810
+ const [dateFieldTable, setDateFieldTable] = (0, react_1.useState)((dateFieldOptions.length && dateFieldOptions[0].name) || '');
811
+ const [dateField, setDateField] = (0, react_1.useState)((dateFieldOptions.length && dateFieldOptions[0].columns[0].name) || '');
812
+ const [template, setTemplate] = (0, react_1.useState)(report?.template || false);
609
813
  const [chartConfig, setChartConfig] = (0, react_1.useState)({});
814
+ const { dateFilter } = (0, react_1.useContext)(Context_1.DateFilterContext);
610
815
  const [yAxisFields, setYAxisFields] = (0, react_1.useState)(report
611
816
  ? report.yAxisFields
612
817
  : [
613
818
  {
614
- field: fieldOptions.length > 1
615
- ? fieldOptions[1].value
616
- : fieldOptions[0].value,
819
+ field: yAxisOptions.length > 1
820
+ ? yAxisOptions[1].value
821
+ : yAxisOptions[0].value,
617
822
  label: '',
618
823
  format: 'whole_number',
619
824
  },
620
825
  ]);
826
+ const [bucketFields, setBucketFields] = (0, react_1.useState)((report && report.buckets) || []);
621
827
  const [columns, setColumns] = (0, react_1.useState)(report && report.columns.length
622
828
  ? report.columns
623
829
  : fields?.length
@@ -629,12 +835,146 @@ function FormikForm({ values, isSubmitting, data, fieldOptions, dateFieldOptions
629
835
  { label: '', field: '', format: 'whole_number' },
630
836
  ]);
631
837
  };
838
+ const handleAddBucket = () => {
839
+ const bucketPossibilities = xAxisOptions.filter(option =>
840
+ // whatIsProbablyTheType(data.slice(0, 10), option.value) === 'date'
841
+ (0, ReportBuilder_1.getPostgresBasicType)(newFields.find(field => field.name === option.value)) === 'date');
842
+ if (!bucketPossibilities.length) {
843
+ alert('No possible buckets');
844
+ return;
845
+ }
846
+ setBucketFields([
847
+ ...bucketFields,
848
+ {
849
+ field: bucketPossibilities[0].value,
850
+ },
851
+ ]);
852
+ setXAxisField(bucketPossibilities[0].value);
853
+ if (bucketPossibilities[0].value === dateField) {
854
+ setXAxisFormat('dynamic');
855
+ }
856
+ else {
857
+ setXAxisFormat(
858
+ // whatIsProbablyTheType(data.slice(0, 10), bucketPossibilities[0].value)
859
+ (0, ReportBuilder_1.getPostgresBasicType)(newFields.find(field => field.name === bucketPossibilities[0].value)));
860
+ }
861
+ };
862
+ const [dashboardOptions, setDashboardOptions] = (0, react_1.useState)([]);
863
+ const [dashboardName, setDashboardName] = (0, react_1.useState)(report?.dashboardName || dashboardOptions[0]);
864
+ const values = {
865
+ xAxisLabel,
866
+ chartName,
867
+ chartType,
868
+ xAxisField,
869
+ xAxisFormat,
870
+ dashboardName,
871
+ dateFieldTable,
872
+ dateField,
873
+ };
874
+ const [selectedTabIndex, setSelectedTabIndex] = (0, react_1.useState)(values.template ? 1 : 0);
875
+ (0, react_1.useEffect)(() => {
876
+ if (dashboardOptions.length) {
877
+ setDashboardName(dashboardOptions[0].value);
878
+ }
879
+ }, [dashboardOptions]);
880
+ (0, react_1.useEffect)(() => {
881
+ async function getDashNames() {
882
+ const response2 = await fetch(`https://quill-344421.uc.r.appspot.com/dashnames/${client.publicKey}/`, {
883
+ method: 'GET',
884
+ headers: {
885
+ Authorization: `Bearer `,
886
+ environment: environment,
887
+ },
888
+ });
889
+ const response2Data = await response2.json();
890
+ setDashboardOptions(response2Data.dashboardNames
891
+ .filter(elem => elem !== null)
892
+ .map(key => ({ label: key, value: key })));
893
+ }
894
+ getDashNames();
895
+ }, []);
896
+ (0, react_1.useEffect)(() => {
897
+ // if (!dateField) {
898
+ // return;
899
+ // }
900
+ // if (
901
+ // (!bucketFields.length && chartType === 'column') ||
902
+ // chartType === 'line'
903
+ // ) {
904
+ // handleAddBucket();
905
+ // return;
906
+ // }
907
+ if ((bucketFields.length && chartType === 'metric') ||
908
+ chartType === 'table' ||
909
+ chartType === 'pie') {
910
+ handleDeleteBucketField(0);
911
+ return;
912
+ }
913
+ }, [chartType, dateField]);
914
+ (0, react_1.useEffect)(() => {
915
+ if (dateFieldOptions.length) {
916
+ setDateFieldTable(dateFieldOptions[0].name);
917
+ setDateField(dateFieldOptions[0].columns[0].name);
918
+ }
919
+ }, [dateFieldOptions]);
632
920
  const handleDeleteYAxisField = index => {
633
921
  setYAxisFields(yAxisFields => yAxisFields.filter((_, i) => index !== i));
634
922
  };
923
+ const handleDeleteBucketField = index => {
924
+ setBucketFields(bucketFields => bucketFields.filter((_, i) => index !== i));
925
+ setXAxisField(xAxisOptions[0].value);
926
+ setXAxisLabel('');
927
+ };
928
+ const handleBucketFieldChange = (index, value) => {
929
+ if (!dateField) {
930
+ return;
931
+ }
932
+ const newBucketFields = [...bucketFields];
933
+ newBucketFields[index] = { ...newBucketFields[index], field: value };
934
+ setBucketFields(newBucketFields);
935
+ setXAxisField(value);
936
+ if (value === dateField) {
937
+ setXAxisFormat('dynamic');
938
+ }
939
+ else {
940
+ setXAxisFormat(
941
+ // whatIsProbablyTheType(data.slice(0, 10), value)
942
+ (0, ReportBuilder_1.getPostgresBasicType)(newFields.find(field => field.name === value)));
943
+ }
944
+ };
945
+ const handleXAxisFieldChange = value => {
946
+ if (!dateField) {
947
+ return;
948
+ }
949
+ // const newXAxisField = {
950
+ // format: xAxisFormat,
951
+ // label: xAxisLabel,
952
+ // field: value,
953
+ // };
954
+ setXAxisField(value);
955
+ // TODO: MAKE DATE FIELD NOT HARD CODED
956
+ if (value === dateField) {
957
+ setXAxisFormat('dynamic');
958
+ }
959
+ else {
960
+ setXAxisFormat(
961
+ // whatIsProbablyTheType(data.slice(0, 10), value)
962
+ (0, ReportBuilder_1.getPostgresBasicType)(newFields.find(field => field.name === value)));
963
+ }
964
+ if (bucketFields.length > 0) {
965
+ const newBucketFields = [...bucketFields];
966
+ newBucketFields[0] = { ...newBucketFields[0], field: value };
967
+ setBucketFields(newBucketFields);
968
+ }
969
+ };
635
970
  const handleYAxisFieldChange = (index, value) => {
636
971
  const newYAxisFields = [...yAxisFields];
637
- newYAxisFields[index] = { ...newYAxisFields[index], field: value };
972
+ newYAxisFields[index] = {
973
+ ...newYAxisFields[index],
974
+ field: value,
975
+ // format: whatIsProbablyTheType(data.slice(0, 10), value),
976
+ format: (0, ReportBuilder_1.getPostgresBasicType)(newFields.find(field => field.name === value)),
977
+ };
638
978
  setYAxisFields(newYAxisFields);
639
979
  };
640
980
  const handleYAxisFieldFormatChange = (index, value) => {
@@ -642,7 +982,7 @@ function FormikForm({ values, isSubmitting, data, fieldOptions, dateFieldOptions
642
982
  newYAxisFields[index] = { ...newYAxisFields[index], format: value };
643
983
  setYAxisFields(newYAxisFields);
644
984
  };
645
- const handleYAxisFieldLabelChange = (index, value) => {
985
+ const handleYAxisLabelChange = (index, value) => {
646
986
  const newYAxisFields = [...yAxisFields];
647
987
  newYAxisFields[index] = { ...newYAxisFields[index], label: value };
648
988
  setYAxisFields(newYAxisFields);
@@ -663,10 +1003,37 @@ function FormikForm({ values, isSubmitting, data, fieldOptions, dateFieldOptions
663
1003
  setColumns(newColumns);
664
1004
  };
665
1005
  (0, react_1.useEffect)(() => {
666
- setChartConfig({ ...values, yAxisFields: yAxisFields, rows: data });
667
- }, [values, yAxisFields]);
668
- // console.log('VIBE: ', { report, values, yAxisFields, columns, query });
669
- return ((0, jsx_runtime_1.jsx)(formik_1.Form, { style: { display: 'inline-block' }, children: (0, jsx_runtime_1.jsxs)("div", { style: {
1006
+ const now = new Date();
1007
+ setChartConfig(handleBucketData({
1008
+ xAxisField,
1009
+ xAxisLabel,
1010
+ xAxisFormat,
1011
+ chartName,
1012
+ chartType,
1013
+ dashboardName,
1014
+ dateFieldTable,
1015
+ dateField,
1016
+ template,
1017
+ yAxisFields: yAxisFields,
1018
+ rows: data,
1019
+ fields: newFields,
1020
+ columns: columns,
1021
+ }, bucketFields, dateFilter));
1022
+ }, [
1023
+ xAxisField,
1024
+ xAxisLabel,
1025
+ xAxisFormat,
1026
+ chartName,
1027
+ chartType,
1028
+ dashboardName,
1029
+ dateFieldTable,
1030
+ dateField,
1031
+ template,
1032
+ yAxisFields,
1033
+ bucketFields,
1034
+ columns,
1035
+ ]);
1036
+ return ((0, jsx_runtime_1.jsx)("div", { style: { display: 'inline-block' }, children: (0, jsx_runtime_1.jsxs)("div", { style: {
670
1037
  display: 'flex',
671
1038
  flexDirection: 'column',
672
1039
  paddingLeft: 25,
@@ -675,76 +1042,114 @@ function FormikForm({ values, isSubmitting, data, fieldOptions, dateFieldOptions
675
1042
  display: 'flex',
676
1043
  flexDirection: 'column',
677
1044
  }, children: [(0, jsx_runtime_1.jsx)("div", { style: { height: 20 } }), (0, jsx_runtime_1.jsx)("div", { style: {
678
- marginRight: chartConfig.chartType === 'pie' ? undefined : 25,
679
- marginLeft: chartConfig.chartType === 'pie' ? undefined : -25,
680
- }, children: Object.keys(chartConfig).length > 0 && ((0, jsx_runtime_1.jsx)(Chart_1.default, { chartId: "646e37a660feef000be67a93", config: chartConfig, colors: theme.chartColors, containerStyle: {
681
- width: 'calc(100% - 24px)',
1045
+ marginRight: chartConfig.chartType === 'pie' ||
1046
+ chartConfig.chartType === 'table'
1047
+ ? undefined
1048
+ : 25,
1049
+ marginLeft: chartConfig.chartType === 'pie' ||
1050
+ chartConfig.chartType === 'table'
1051
+ ? undefined
1052
+ : -25,
1053
+ }, children: Object.keys(chartConfig).length > 0 && ((0, jsx_runtime_1.jsx)(Chart_1.default, { config: chartConfig, colors: theme.chartColors, containerStyle: {
1054
+ width: chartConfig.chartType === 'table'
1055
+ ? 640
1056
+ : 'calc(100% - 24px)',
682
1057
  height: 300,
683
- } })) }), (0, jsx_runtime_1.jsx)("div", { style: { height: 40 } }), showTableFormatOptions || showDateFieldOptions ? ((0, jsx_runtime_1.jsx)("div", { style: formHeaderStyle || {
684
- fontFamily: theme.fontFamily,
685
- color: theme.primaryTextColor,
686
- fontSize: theme?.fontSize ? theme?.fontSize + 2 : 14,
687
- fontWeight: 600,
688
- // marginTop: 20,
689
- }, children: 'Chart' })) : null, (0, jsx_runtime_1.jsxs)("div", { style: {
1058
+ } })) }), (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 || {
1059
+ fontFamily: theme.fontFamily,
1060
+ color: theme.primaryTextColor,
1061
+ fontSize: theme.fontSize + 2,
1062
+ fontWeight: 600,
1063
+ }, children: 'Chart' }) })) : null, (0, jsx_runtime_1.jsxs)("div", { style: {
690
1064
  display: 'flex',
691
1065
  flexDirection: 'row',
692
1066
  alignItems: 'center',
693
1067
  }, children: [(0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'column', marginTop: 8 }, children: [(0, jsx_runtime_1.jsx)("div", { style: formLabelStyle || {
694
- fontSize: '14px',
695
- marginBottom: '6px',
696
- fontWeight: '600',
697
1068
  color: theme.secondaryTextColor,
698
1069
  fontFamily: theme?.fontFamily,
699
- }, children: "Name" }), (0, jsx_runtime_1.jsx)("div", { style: { minWidth: 200 }, children: (0, jsx_runtime_1.jsx)(formik_1.Field, { name: "chartName", component: TextInputComponent, theme: theme }) })] }), (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 || {
700
- fontFamily: theme.fontFamily,
1070
+ fontSize: theme?.fontSize || '14px',
1071
+ fontWeight: theme.labelFontWeight || '600',
1072
+ }, 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 || {
701
1073
  color: theme.secondaryTextColor,
702
- fontSize: theme?.fontSize,
703
- fontWeight: theme.labelFontWeight,
704
- }, children: "Dashboard name" }), (0, jsx_runtime_1.jsx)("div", { style: { minWidth: 200, marginTop: 6 }, children: (0, jsx_runtime_1.jsx)(formik_1.Field, { name: "dashboardName", component: TextInputComponent, theme: theme }) })] }), (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 || {
705
- fontFamily: theme.fontFamily,
1074
+ fontFamily: theme?.fontFamily,
1075
+ fontSize: theme?.fontSize || '14px',
1076
+ fontWeight: theme.labelFontWeight || '600',
1077
+ }, 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 || {
1078
+ fontSize: '14px',
706
1079
  color: theme.secondaryTextColor,
707
- fontSize: theme.fontSize,
708
- fontWeight: theme.labelFontWeight,
709
- }, children: "Chart type" }), (0, jsx_runtime_1.jsx)("div", { style: { minWidth: 200, marginTop: 6 }, children: (0, jsx_runtime_1.jsx)(formik_1.Field, { name: "chartType", component: SelectComponent, theme: theme, options: [
1080
+ fontFamily: theme?.fontFamily,
1081
+ fontSize: theme?.fontSize || '14px',
1082
+ fontWeight: theme.labelFontWeight || '600',
1083
+ }, 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: [
710
1084
  { label: 'column', value: 'column' },
711
1085
  { label: 'bar', value: 'bar' },
712
1086
  { label: 'line', value: 'line' },
713
1087
  { label: 'pie', value: 'pie' },
714
1088
  { label: 'metric', value: 'metric' },
715
1089
  { label: 'table', value: 'table' },
716
- ] }) })] })] })] }), (0, jsx_runtime_1.jsx)("div", { style: {
1090
+ ], theme: theme }) })] })] })] }), chartType !== 'table' &&
1091
+ chartType !== 'metric' &&
1092
+ chartType !== 'pie' && ((0, jsx_runtime_1.jsxs)("div", { style: {
1093
+ display: 'flex',
1094
+ flexDirection: 'column',
1095
+ marginTop: 20,
1096
+ maxWidth: 200,
1097
+ }, children: [(0, jsx_runtime_1.jsx)("div", { style: formLabelStyle || {
1098
+ color: theme.secondaryTextColor,
1099
+ fontFamily: theme?.fontFamily,
1100
+ fontSize: theme?.fontSize || '14px',
1101
+ fontWeight: theme.labelFontWeight || '600',
1102
+ }, children: "Buckets" }), (0, jsx_runtime_1.jsx)("div", { style: {
1103
+ maxWidth: 200,
1104
+ // marginTop: 6,
1105
+ display: 'flex',
1106
+ flexDirection: 'column',
1107
+ }, children: bucketFields.map((bucketField, index) => ((0, jsx_runtime_1.jsxs)("div", { style: {
1108
+ display: 'flex',
1109
+ flexDirection: 'row',
1110
+ alignItems: 'center',
1111
+ marginTop: index === 0 ? 6 : 10,
1112
+ }, 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,
1113
+ // TODO: PROB FILTER OUT NUMBERS LMAO (SO DATE AND STRING ONLY)
1114
+ options: xAxisOptions, theme: theme }) }), (0, jsx_runtime_1.jsx)("div", { onClick: () => handleDeleteBucketField(index), style: {
1115
+ cursor: 'pointer',
1116
+ paddingLeft: 6,
1117
+ paddingTop: 9,
1118
+ paddingBottom: 9,
1119
+ paddingRight: 6,
1120
+ maxHeight: 38,
1121
+ display: 'flex',
1122
+ alignItems: 'center',
1123
+ justifyContent: 'center',
1124
+ }, 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: {
717
1125
  display: 'flex',
718
1126
  flexDirection: 'row',
719
1127
  alignItems: 'center',
720
1128
  // justifyContent: 'space-between',
721
1129
  marginTop: 20,
722
- }, children: values.chartType !== 'table' && ((0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'column' }, children: [(0, jsx_runtime_1.jsx)("div", { style: formLabelStyle || {
723
- fontFamily: theme.fontFamily,
1130
+ }, children: chartType !== 'table' && ((0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'column' }, children: [(0, jsx_runtime_1.jsx)("div", { style: formLabelStyle || {
724
1131
  color: theme.secondaryTextColor,
725
- fontSize: theme.fontSize,
726
- fontWeight: theme.labelFontWeight,
727
- }, children: values.chartType === 'pie'
728
- ? 'Category column'
729
- : 'x-axis column' }), (0, jsx_runtime_1.jsx)("div", { style: { height: 6 } }), (0, jsx_runtime_1.jsxs)("div", { style: {
1132
+ fontFamily: theme?.fontFamily,
1133
+ fontSize: theme?.fontSize || '14px',
1134
+ fontWeight: theme.labelFontWeight || '600',
1135
+ }, children: chartType === 'pie' ? 'Category column' : 'x-axis column' }), (0, jsx_runtime_1.jsx)("div", { style: { height: 6 } }), (0, jsx_runtime_1.jsxs)("div", { style: {
730
1136
  display: 'flex',
731
1137
  flexDirection: 'row',
732
1138
  alignItems: 'center',
733
- }, children: [(0, jsx_runtime_1.jsx)("div", { style: { minWidth: 200 }, children: (0, jsx_runtime_1.jsx)(formik_1.Field, { name: "xAxisField", component: SelectComponent, theme: theme, options: fieldOptions }) }), (0, jsx_runtime_1.jsx)("div", { style: { width: 20 } }), (0, jsx_runtime_1.jsx)("div", { style: { minWidth: 200 }, children: (0, jsx_runtime_1.jsx)(formik_1.Field, { name: "xAxisLabel", component: TextInputComponent, 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)(formik_1.Field, { name: "xAxisFormat", component: SelectComponent, theme: theme, options: FORMAT_OPTIONS }) })] })] })) }), (0, jsx_runtime_1.jsxs)("div", { style: {
1139
+ }, 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: {
734
1140
  display: 'flex',
735
1141
  flexDirection: 'row',
736
1142
  alignItems: 'flex-start',
737
1143
  // justifyContent: 'space-between',
738
1144
  marginTop: 20,
739
1145
  }, children: [(0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'column' }, children: [(0, jsx_runtime_1.jsx)("div", { style: formLabelStyle || {
740
- fontFamily: theme.fontFamily,
741
1146
  color: theme.secondaryTextColor,
742
- fontSize: theme.fontSize,
743
- fontWeight: theme.labelFontWeight,
744
- minWidth: 200,
745
- }, children: values.chartType === 'table'
1147
+ fontFamily: theme?.fontFamily,
1148
+ fontSize: theme?.fontSize || '14px',
1149
+ fontWeight: theme.labelFontWeight || '600',
1150
+ }, children: chartType === 'table'
746
1151
  ? 'Columns'
747
- : values.chartType === 'pie'
1152
+ : chartType === 'pie'
748
1153
  ? 'Quantity column'
749
1154
  : 'y-axis columns' }), (0, jsx_runtime_1.jsxs)("div", { style: {
750
1155
  display: 'flex',
@@ -754,24 +1159,24 @@ function FormikForm({ values, isSubmitting, data, fieldOptions, dateFieldOptions
754
1159
  flexDirection: 'row',
755
1160
  alignItems: 'center',
756
1161
  marginTop: index === 0 ? 6 : 10,
757
- }, children: (0, jsx_runtime_1.jsx)("div", { style: { minWidth: 200 }, children: (0, jsx_runtime_1.jsx)(formik_1.Field, { name: `yAxisField-${index}`, component: SelectComponent, theme: theme, value: yAxisField.field, onChange: option => handleYAxisFieldChange(index, option), options: fieldOptions }) }) }, `yAxisField-${index}`))), values.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: {
1162
+ }, 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: 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: {
758
1163
  display: 'flex',
759
1164
  flexDirection: 'column',
760
1165
  justifyContent: 'flex-start',
761
1166
  }, children: [(0, jsx_runtime_1.jsx)("div", { style: formLabelStyle || {
762
- fontFamily: theme.fontFamily,
763
1167
  color: 'transparent',
764
- fontSize: theme.fontSize,
765
- fontWeight: theme.labelFontWeight,
766
- minWidth: 200,
767
- // marginBottom: 10,
768
- }, children: "y-axis label" }), values.chartType !== 'pie' &&
1168
+ fontFamily: theme?.fontFamily,
1169
+ fontSize: theme?.fontSize || '14px',
1170
+ fontWeight: theme.labelFontWeight || '600',
1171
+ }, children: "y-axis label" }), chartType !== 'pie' &&
769
1172
  yAxisFields.map((yAxisField, index) => ((0, jsx_runtime_1.jsxs)("div", { style: {
770
1173
  display: 'flex',
771
1174
  flexDirection: 'row',
772
- alignItems: 'center',
1175
+ // alignItems: 'center',
773
1176
  marginTop: index === 0 ? 6 : 10,
774
- }, children: [(0, jsx_runtime_1.jsx)("div", { style: { minWidth: 200 }, children: (0, jsx_runtime_1.jsx)(formik_1.Field, { name: `yAxisLabel-${index}`, component: TextInputComponent, theme: theme, placeholder: "Enter column 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)(formik_1.Field, { name: `yAxisFieldFormat-${index}`, component: SelectComponent, theme: theme, value: yAxisField.format, onChange: option => handleYAxisFieldFormatChange(index, option), options: FORMAT_OPTIONS }) }), (0, jsx_runtime_1.jsx)("div", { onClick: () => index > 0 ? handleDeleteYAxisField(index) : undefined, style: {
1177
+ }, children: [(0, jsx_runtime_1.jsx)("div", { style: { minWidth: 200 }, children: (0, jsx_runtime_1.jsx)(TextInputComponent, { value: yAxisFields[index].label, onChange: e => {
1178
+ handleYAxisLabelChange(index, e.target.value);
1179
+ }, 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: {
775
1180
  cursor: index > 0 ? 'pointer' : undefined,
776
1181
  paddingLeft: 6,
777
1182
  paddingTop: 12,
@@ -781,79 +1186,175 @@ function FormikForm({ values, isSubmitting, data, fieldOptions, dateFieldOptions
781
1186
  display: 'flex',
782
1187
  alignItems: 'center',
783
1188
  justifyContent: 'center',
784
- }, 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.jsx)("div", { style: formHeaderStyle || {
785
- fontFamily: theme.fontFamily,
786
- color: theme.primaryTextColor,
787
- fontSize: theme.fontSize + 2,
788
- fontWeight: 600,
789
- }, children: 'Table' })), showTableFormatOptions && ((0, jsx_runtime_1.jsxs)("div", { style: {
1189
+ }, 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 || {
1190
+ fontFamily: theme.fontFamily,
1191
+ color: theme.primaryTextColor,
1192
+ fontSize: theme.fontSize + 2,
1193
+ fontWeight: 600,
1194
+ // marginTop: 20,
1195
+ }, children: 'Table' }), (0, jsx_runtime_1.jsx)("div", { style: { height: 8 } })] })), showTableFormatOptions && ((0, jsx_runtime_1.jsx)("div", { style: formLabelStyle || {
1196
+ color: theme.secondaryTextColor,
1197
+ fontFamily: theme?.fontFamily,
1198
+ fontSize: theme?.fontSize || '14px',
1199
+ fontWeight: theme.labelFontWeight || '600',
1200
+ }, children: 'Columns' })), showTableFormatOptions && ((0, jsx_runtime_1.jsxs)("div", { style: {
790
1201
  display: 'flex',
791
1202
  flexDirection: 'row',
792
1203
  alignItems: 'flex-start',
793
1204
  marginTop: 6,
794
1205
  // justifyContent: 'space-between',
795
1206
  // marginTop: 8,
796
- }, children: [(0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'column' }, children: [(0, jsx_runtime_1.jsx)("div", { style: formLabelStyle || {
797
- fontFamily: theme.fontFamily,
798
- color: theme.secondaryTextColor,
799
- fontSize: theme.fontSize,
800
- fontWeight: theme.labelFontWeight,
801
- }, children: 'Columns' }), (0, jsx_runtime_1.jsxs)("div", { style: {
802
- display: 'flex',
803
- flexDirection: 'column',
804
- }, children: [columns.map((yAxisField, index) => ((0, jsx_runtime_1.jsx)("div", { style: {
805
- display: 'flex',
806
- flexDirection: 'row',
807
- alignItems: 'center',
808
- marginTop: index === 0 ? 6 : 10,
809
- }, children: (0, jsx_runtime_1.jsx)("div", { style: { minWidth: 200 }, children: (0, jsx_runtime_1.jsx)(formik_1.Field, { name: `column-${index}`, component: SelectComponent, theme: theme, value: yAxisField.field, onChange: option => handleColumnFieldChange(index, option), options: fieldOptions }) }) }, `column-${index}`))), (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: {
1207
+ }, children: [(0, jsx_runtime_1.jsx)("div", { style: { display: 'flex', flexDirection: 'column' }, children: (0, jsx_runtime_1.jsxs)("div", { style: {
1208
+ display: 'flex',
1209
+ flexDirection: 'column',
1210
+ }, children: [columns.map((yAxisField, index) => ((0, jsx_runtime_1.jsx)("div", { style: {
1211
+ display: 'flex',
1212
+ flexDirection: 'row',
1213
+ alignItems: 'center',
1214
+ marginTop: index === 0 ? 6 : 10,
1215
+ }, children: (0, jsx_runtime_1.jsx)("div", { style: { minWidth: 200 }, children: (0, jsx_runtime_1.jsx)(SelectComponent, { value: yAxisField.field, onChange: option => {
1216
+ handleColumnFieldChange(index, option);
1217
+ }, 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: {
810
1218
  display: 'flex',
811
1219
  flexDirection: 'column',
812
1220
  justifyContent: 'flex-start',
813
- }, children: [(0, jsx_runtime_1.jsx)("div", { style: formLabelStyle || {
814
- fontFamily: theme.fontFamily,
815
- color: 'transparent',
816
- fontSize: theme.fontSize,
817
- fontWeight: theme.labelFontWeight,
818
- minWidth: 200,
819
- // marginBottom: 10,
820
- }, children: "label" }), columns.map((yAxisField, index) => ((0, jsx_runtime_1.jsxs)("div", { style: {
821
- display: 'flex',
822
- flexDirection: 'row',
823
- alignItems: 'center',
824
- marginTop: index === 0 ? 6 : 10,
825
- }, children: [(0, jsx_runtime_1.jsx)("div", { style: { minWidth: 200 }, children: (0, jsx_runtime_1.jsx)(formik_1.Field, { name: `columnlabel-${index}`, component: 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)(formik_1.Field, { name: `columnFormat-${index}`, component: SelectComponent, theme: theme, value: yAxisField.format, onChange: option => handleColumnFormatChange(index, option), options: FORMAT_OPTIONS }) })] }, `column-${index}`)))] })] })), showDateFieldOptions && (0, jsx_runtime_1.jsx)("div", { style: { height: 20 } }), showDateFieldOptions && ((0, jsx_runtime_1.jsx)("div", { style: formHeaderStyle || {
826
- fontFamily: theme.fontFamily,
827
- color: theme.primaryTextColor,
828
- fontSize: theme.fontSize + 2,
829
- fontWeight: 600,
830
- // marginTop: 20,
831
- }, children: 'Filters' })), showDateFieldOptions && ((0, jsx_runtime_1.jsxs)("div", { style: {
1221
+ }, children: columns.map((yAxisField, index) => ((0, jsx_runtime_1.jsxs)("div", { style: {
1222
+ display: 'flex',
1223
+ flexDirection: 'row',
1224
+ alignItems: 'center',
1225
+ marginTop: index === 0 ? 6 : 10,
1226
+ }, 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 || {
1227
+ fontFamily: theme.fontFamily,
1228
+ color: theme.primaryTextColor,
1229
+ fontSize: theme.fontSize + 2,
1230
+ fontWeight: 600,
1231
+ // marginTop: 20,
1232
+ }, children: 'Filters' }), (0, jsx_runtime_1.jsx)("div", { style: { height: 8 } })] })), showDateFieldOptions && ((0, jsx_runtime_1.jsxs)("div", { style: {
832
1233
  display: 'flex',
833
1234
  flexDirection: 'row',
834
1235
  alignItems: 'center',
835
- }, children: [(0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'column', marginTop: 8 }, children: [(0, jsx_runtime_1.jsx)("div", { style: formLabelStyle || {
836
- fontFamily: theme.fontFamily,
1236
+ }, children: [(0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'column' }, children: [(0, jsx_runtime_1.jsx)("div", { style: formLabelStyle || {
837
1237
  color: theme.secondaryTextColor,
838
- fontSize: theme.fontSize,
839
- fontWeight: theme.labelFontWeight,
840
- }, children: "Date field table" }), (0, jsx_runtime_1.jsx)("div", { style: { minWidth: 200, marginTop: 6 }, children: (0, jsx_runtime_1.jsx)(formik_1.Field, { name: "dateFieldTable", component: SelectComponent, theme: theme, options: !dateFieldOptions.length
1238
+ fontFamily: theme?.fontFamily,
1239
+ fontSize: theme?.fontSize || '14px',
1240
+ fontWeight: theme.labelFontWeight || '600',
1241
+ }, 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
841
1242
  ? [{ label: '', value: '' }]
842
1243
  : dateFieldOptions.map(elem => {
843
1244
  return { label: elem.name, value: elem.name };
844
- }) }) })] }), (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 || {
845
- fontFamily: theme.fontFamily,
1245
+ }), 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 || {
846
1246
  color: theme.secondaryTextColor,
847
- fontSize: theme.fontSize,
848
- fontWeight: theme.labelFontWeight,
849
- }, children: "Date field" }), (0, jsx_runtime_1.jsx)("div", { style: { minWidth: 200, marginTop: 6 }, children: (0, jsx_runtime_1.jsx)(formik_1.Field, { name: "dateField", component: SelectComponent, theme: theme, options: !dateFieldOptions.length
1247
+ fontFamily: theme?.fontFamily,
1248
+ fontSize: theme?.fontSize || '14px',
1249
+ fontWeight: theme.labelFontWeight || '600',
1250
+ }, children: "Date field" }), (0, jsx_runtime_1.jsx)("div", { style: { minWidth: 200, marginTop: 6 }, children: (0, jsx_runtime_1.jsx)(SelectComponent, { options: !dateFieldOptions.length
850
1251
  ? [{ label: '', value: '' }]
851
- : dateFieldOptions.filter(elem => elem.name === values.dateFieldTable).length
1252
+ : dateFieldOptions.filter(elem => elem.name === dateFieldTable // Replace `values.dateFieldTable` with your state variable or prop
1253
+ ).length
852
1254
  ? dateFieldOptions
853
- .filter(elem => elem.name === values.dateFieldTable)[0]
1255
+ .filter(elem => elem.name === dateFieldTable)[0]
854
1256
  .columns.map(elem => {
855
1257
  return { label: elem.name, value: elem.name };
856
1258
  })
857
- : [{ label: '', value: '' }] }) })] })] })), (0, jsx_runtime_1.jsx)("div", { style: { paddingRight: 25 }, children: (0, jsx_runtime_1.jsx)(ButtonComponent, { onClick: () => editChart({ report, values, yAxisFields, columns, query }), label: report ? 'Save changes' : 'Add to dashboard' }) }), (0, jsx_runtime_1.jsx)("div", { style: { height: 20 } })] }) }));
1259
+ : [{ label: '', value: '' }], onChange: value => setDateField(value), value: dateField, theme: theme }) })] })] })), showAccessControlOptions && ((0, jsx_runtime_1.jsxs)("div", { style: {
1260
+ display: 'flex',
1261
+ flexDirection: 'column',
1262
+ marginTop: 40,
1263
+ marginBottom: 40,
1264
+ }, children: [(0, jsx_runtime_1.jsx)("div", { style: {
1265
+ fontFamily: theme.fontFamily,
1266
+ color: theme.primaryTextColor,
1267
+ fontSize: theme.fontSize + 2,
1268
+ fontWeight: 600,
1269
+ }, children: 'Access Control' }), (0, jsx_runtime_1.jsx)("div", { style: { height: 12 } }), (0, jsx_runtime_1.jsxs)("div", { style: {
1270
+ padding: '1px',
1271
+ display: 'flex',
1272
+ flexDirection: 'row',
1273
+ fontSize: '14px',
1274
+ fontWeight: '500',
1275
+ height: '32px',
1276
+ width: '640px',
1277
+ color: '#212121',
1278
+ backgroundColor: 'rgba(33, 33, 33, 0.03)',
1279
+ borderRadius: '6px',
1280
+ }, children: [(0, jsx_runtime_1.jsx)("div", { onClick: () => {
1281
+ setSelectedTabIndex(0);
1282
+ setTemplate(false);
1283
+ }, style: {
1284
+ width: '100%',
1285
+ borderRadius: '6px',
1286
+ padding: '4px',
1287
+ fontSize: '14px',
1288
+ fontWeight: '500',
1289
+ display: 'flex',
1290
+ flexDirection: 'column',
1291
+ alignItems: 'center',
1292
+ justifyContent: 'center',
1293
+ cursor: 'pointer',
1294
+ borderColor: '#E7E7E7',
1295
+ borderWidth: selectedTabIndex === 0 ? 1 : 0,
1296
+ borderStyle: 'solid',
1297
+ color: selectedTabIndex === 0
1298
+ ? '#212121'
1299
+ : 'rgba(33, 33, 33, 0.3)',
1300
+ backgroundColor: selectedTabIndex === 0
1301
+ ? 'white'
1302
+ : 'rgba(255, 255, 255, 0.12)',
1303
+ boxShadow: selectedTabIndex === 0
1304
+ ? '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)'
1305
+ : undefined,
1306
+ outline: 'none', // focus:outline-none
1307
+ }, children: `This Organization${organizationName ? ` (${organizationName})` : ``}` }), (0, jsx_runtime_1.jsx)("div", { onClick: () => {
1308
+ setSelectedTabIndex(1);
1309
+ setTemplate(true);
1310
+ }, style: {
1311
+ width: '100%',
1312
+ borderRadius: '6px',
1313
+ padding: '4px',
1314
+ fontSize: '14px',
1315
+ fontWeight: '500',
1316
+ display: 'flex',
1317
+ flexDirection: 'column',
1318
+ alignItems: 'center',
1319
+ justifyContent: 'center',
1320
+ cursor: 'pointer',
1321
+ borderColor: '#E7E7E7',
1322
+ borderWidth: selectedTabIndex === 1 ? 1 : 0,
1323
+ borderStyle: 'solid',
1324
+ color: selectedTabIndex === 1
1325
+ ? '#212121'
1326
+ : 'rgba(33, 33, 33, 0.3)',
1327
+ backgroundColor: selectedTabIndex === 1
1328
+ ? 'white'
1329
+ : 'rgba(255, 255, 255, 0.12)',
1330
+ boxShadow: selectedTabIndex === 1
1331
+ ? '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)'
1332
+ : undefined,
1333
+ outline: 'none', // focus:outline-none
1334
+ }, children: 'Global (All Organizations)' })] })] })), (0, jsx_runtime_1.jsx)("div", { style: { paddingRight: 25 }, children: (0, jsx_runtime_1.jsx)(ButtonComponent, { onClick: () => {
1335
+ const { xAxisField, xAxisLabel, xAxisFormat, chartName, chartType, dashboardName, dateFieldTable, dateField, template, } = chartConfig;
1336
+ if (isSubmitting === false) {
1337
+ editChart({
1338
+ setIsSubmitting,
1339
+ report,
1340
+ values: {
1341
+ xAxisField,
1342
+ xAxisLabel,
1343
+ xAxisFormat,
1344
+ chartName,
1345
+ chartType,
1346
+ dashboardName,
1347
+ dateFieldTable,
1348
+ dateField,
1349
+ template,
1350
+ },
1351
+ yAxisFields,
1352
+ columns,
1353
+ query,
1354
+ buckets: bucketFields,
1355
+ showTableFormatOptions,
1356
+ });
1357
+ }
1358
+ }, label: report ? 'Save changes' : 'Add to dashboard' }) }), (0, jsx_runtime_1.jsx)("div", { style: { height: 20 } })] }) }));
858
1359
  }
859
1360
  //# sourceMappingURL=AddToDashboardModal.js.map