@quillsql/react 2.1.4 → 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;
126
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;
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,45 +281,74 @@ 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
177
- ? columns
178
- : [
179
- ...newYAxisFields,
180
- {
181
- field: xAxisField,
182
- label: xAxisLabel,
183
- format: xAxisFormat,
184
- },
185
- ],
186
- dateField: showDateFieldOptions
187
- ? { table: dateFieldTable, field: dateField }
188
- : defaultDateField,
189
- query: query,
190
- task: 'create',
191
- orgId: customerId,
192
- }
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
+ }
193
340
  : {
194
341
  name: chartName,
195
342
  xAxisField,
196
- yAxisFields: newYAxisFields,
343
+ yAxisFields,
197
344
  xAxisLabel,
198
345
  xAxisFormat,
199
- yAxisLabel,
200
346
  chartType,
201
347
  dashboardName,
202
348
  columns: showTableFormatOptions
203
349
  ? columns
204
350
  : [
205
- ...newYAxisFields,
351
+ ...yAxisFields,
206
352
  {
207
353
  field: xAxisField,
208
354
  label: xAxisLabel,
@@ -214,6 +360,8 @@ function AddToDashboardModal({ isOpen, setIsOpen, SelectComponent, TextInputComp
214
360
  : defaultDateField,
215
361
  query: query,
216
362
  task: 'create',
363
+ template: template,
364
+ buckets,
217
365
  },
218
366
  });
219
367
  const response = await fetch(url, {
@@ -258,26 +406,67 @@ function AddToDashboardModal({ isOpen, setIsOpen, SelectComponent, TextInputComp
258
406
  if (environment) {
259
407
  headers['environment'] = environment;
260
408
  }
261
- const body = JSON.stringify({
262
- name: chartName,
263
- xAxisField,
264
- yAxisFields: newYAxisFields,
265
- xAxisLabel,
266
- xAxisFormat,
267
- yAxisLabel,
268
- chartType,
269
- dashboardName,
270
- columns: showTableFormatOptions ? columns : newYAxisFields,
271
- dateField: showDateFieldOptions
272
- ? { table: dateFieldTable, field: dateField }
273
- : defaultDateField,
274
- query: query,
275
- });
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
+ }
276
465
  try {
277
466
  const response = await fetch(url, {
278
467
  method: 'POST',
279
468
  headers: headers,
280
- body: body,
469
+ body: body2,
281
470
  });
282
471
  responseData = await response.json();
283
472
  setIsOpen(false);
@@ -302,38 +491,30 @@ function AddToDashboardModal({ isOpen, setIsOpen, SelectComponent, TextInputComp
302
491
  // TODO: fire callback instead so user can customize action
303
492
  // navigate("/dashboards");
304
493
  };
494
+ // console.log('report', report);
305
495
  return (
306
496
  // <BigModal theme={theme} showModal={isOpen} setShowModal={setIsOpen}>
307
- (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,
308
- // leave null for now
309
- report: null, query: query,
310
- // organizationName={organization?.name}
311
- 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,
312
- // leave null for now
313
- report: null, query: query,
314
- // organizationName={organization?.name}
315
- 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 }) })) }));
316
498
  }
317
499
  exports.default = AddToDashboardModal;
318
500
  function QuillModal({ isOpen, setIsOpen, title, children }) {
319
- let scrollPosition = 0;
320
- (0, react_1.useEffect)(() => {
321
- if (isOpen) {
322
- scrollPosition = window.scrollY;
323
- document.body.style.overflow = 'hidden';
324
- document.body.style.position = 'fixed';
325
- document.body.style.top = `-${scrollPosition}px`;
326
- document.body.style.width = '100%';
327
- }
328
- else {
329
- document.body.style.removeProperty('overflow');
330
- document.body.style.removeProperty('position');
331
- document.body.style.removeProperty('top');
332
- document.body.style.removeProperty('width');
333
- // Restore the scroll position
334
- window.scrollTo(0, scrollPosition);
335
- }
336
- }, [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]);
337
518
  if (!isOpen) {
338
519
  return null;
339
520
  }
@@ -386,14 +567,34 @@ function QuillModal({ isOpen, setIsOpen, title, children }) {
386
567
  textAlign: 'left',
387
568
  }, children: title }), children] }) })] }));
388
569
  }
389
- function ChartForm({ data, fields, theme, saveVisualization, report, editChart, schema, query,
390
- // organizationName,
391
- 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
+ }
392
574
  const fieldOptions = Object.keys(data[0]).map(field => ({
393
575
  value: field,
394
576
  label: field,
395
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
+ }));
396
596
  const [dateFieldOptions, setDateFieldOptions] = (0, react_1.useState)([]);
597
+ const [formValues, setFormValues] = (0, react_1.useState)({});
397
598
  (0, react_1.useEffect)(() => {
398
599
  const fetchReferencedTables = async () => {
399
600
  if (!query) {
@@ -404,115 +605,60 @@ SelectComponent, TextInputComponent, ButtonComponent, SecondaryButtonComponent,
404
605
  };
405
606
  fetchReferencedTables();
406
607
  }, [query, schema]);
407
- return ((0, jsx_runtime_1.jsx)(formik_1.Formik, { initialValues: {
408
- xAxisField: report?.xAxisField || fieldOptions[0].value,
409
- xAxisLabel: report?.xAxisLabel || '',
410
- xAxisFormat: report?.xAxisFormat || FORMAT_OPTIONS[0].value,
411
- yAxisLabel: report?.yAxisLabel || '',
412
- 'yAxisLabel-0': '',
413
- 'yAxisLabel-1': '',
414
- 'yAxisLabel-2': '',
415
- 'yAxisLabel-3': '',
416
- 'yAxisFieldFormat-0': '',
417
- 'yAxisFieldFormat-1': '',
418
- 'yAxisFieldFormat-2': '',
419
- 'yAxisFieldFormat-3': '',
420
- 'yAxisField-0': '',
421
- 'yAxisField-1': '',
422
- 'yAxisField-2': '',
423
- 'yAxisField-3': '',
424
- chartName: report?.name || '',
425
- chartType: report?.chartType || 'column',
426
- xAxisFieldLabel: '',
427
- dashboardName: report?.dashboardName || '',
428
- dateFieldTable: (dateFieldOptions.length && dateFieldOptions[0].name) || '',
429
- dateField: (dateFieldOptions.length && dateFieldOptions[0].columns[0].name) ||
430
- '',
431
- template: report?.template || false,
432
- }, 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,
433
- // organizationName={organizationName}
434
- SelectComponent: SelectComponent
435
- ? SelectComponent
436
- : ({ onChange, value, options }) => {
437
- return ((0, jsx_runtime_1.jsx)("select", { onChange: event => onChange(event.target.value), value: value, id: 'reportbuilderdropdown', style: {
438
- width: 200,
439
- outline: 'none',
440
- textAlign: 'left',
441
- whiteSpace: 'nowrap',
442
- overflow: 'hidden',
443
- textOverflow: 'ellipsis',
444
- borderRadius: 6,
445
- paddingLeft: 12,
446
- paddingRight: 12,
447
- height: 38,
448
- borderWidth: theme.borderWidth,
449
- borderColor: theme.borderColor,
450
- background: theme.backgroundColor,
451
- color: theme.primaryTextColor,
452
- boxShadow: '0 1px 2px 0 rgba(0,0,0,.05)',
453
- fontFamily: theme.fontFamily,
454
- }, children: options.map((option, index) => ((0, jsx_runtime_1.jsx)("option", { value: option.value, children: option.label }, option.label + index))) }));
455
- }, TextInputComponent: TextInputComponent
456
- ? TextInputComponent
457
- : ({ onChange, value, id }) => {
458
- return ((0, jsx_runtime_1.jsx)("input", { style: {
459
- outline: 'none',
460
- textAlign: 'left',
461
- whiteSpace: 'nowrap',
462
- overflow: 'hidden',
463
- textOverflow: 'ellipsis',
464
- borderRadius: 6,
465
- paddingLeft: 12,
466
- paddingRight: 12,
467
- width: 200,
468
- height: 38,
469
- borderWidth: theme.borderWidth,
470
- borderColor: theme.borderColor,
471
- borderStyle: 'solid',
472
- background: theme.backgroundColor,
473
- color: theme.primaryTextColor,
474
- boxShadow: '0 1px 2px 0 rgba(0,0,0,.05)',
475
- fontFamily: theme.fontFamily,
476
- }, id: id, onChange: onChange, value: value }));
477
- }, ButtonComponent: ButtonComponent
478
- ? ButtonComponent
479
- : ({ onClick, label }) => {
480
- return ((0, jsx_runtime_1.jsx)("div", { style: {
481
- height: 38,
482
- background: theme.primaryButtonColor,
483
- color: theme.backgroundColor,
484
- display: 'flex',
485
- borderRadius: 6,
486
- alignItems: 'center',
487
- justifyContent: 'center',
488
- outline: 'none',
489
- cursor: 'pointer',
490
- fontFamily: theme.fontFamily,
491
- fontWeight: theme.buttonFontWeight || 600,
492
- border: 'none',
493
- fontSize: 14,
494
- }, onClick: onClick, children: label }));
495
- }, SecondaryButtonComponent: ButtonComponent
496
- ? ButtonComponent
497
- : ({ onClick, label }) => {
498
- return ((0, jsx_runtime_1.jsx)("div", { style: {
499
- height: 38,
500
- background: theme.backgroundColor,
501
- borderWidth: theme.borderWidth,
502
- borderColor: theme.borderColor,
503
- color: theme.primaryTextColor,
504
- display: 'flex',
505
- borderRadius: 6,
506
- alignItems: 'center',
507
- justifyContent: 'center',
508
- outline: 'none',
509
- cursor: 'pointer',
510
- fontFamily: theme.fontFamily,
511
- fontWeight: theme.buttonFontWeight || 600,
512
- fontSize: 14,
513
- }, onClick: onClick, children: label }));
514
- }, 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 }));
515
660
  }
661
+ exports.ChartForm = ChartForm;
516
662
  function isValidDate(d) {
517
663
  return d instanceof Date && !isNaN(d);
518
664
  }
@@ -581,8 +727,8 @@ const POSTGRES_DATE_TYPES = [
581
727
  ];
582
728
  async function getReferencedTables(sqlQuery, databaseType, dbTables) {
583
729
  // const parser = new Parser();
584
- let tables = [];
585
- let withAliases = [];
730
+ const tables = [];
731
+ const withAliases = [];
586
732
  const response = await fetch('https://quill-344421.uc.r.appspot.com/astify', {
587
733
  method: 'POST',
588
734
  headers: {
@@ -611,7 +757,7 @@ async function getReferencedTables(sqlQuery, databaseType, dbTables) {
611
757
  })
612
758
  .filter(table => table.columns.length > 0);
613
759
  }
614
- const FORMAT_OPTIONS = [
760
+ const X_FORMAT_OPTIONS = [
615
761
  { value: 'whole_number', label: 'whole number' },
616
762
  { value: 'one_decimal_place', label: 'one decimal place' },
617
763
  { value: 'dollar_amount', label: 'dollar amount' },
@@ -622,20 +768,62 @@ const FORMAT_OPTIONS = [
622
768
  { value: 'hh_ap_pm', label: 'hour' },
623
769
  { value: 'percent', label: 'percent' },
624
770
  { value: 'string', label: 'string' },
771
+ { value: 'dynamic', label: 'dynamic' },
625
772
  ];
626
- function FormikForm({ values, isSubmitting, data, fieldOptions, dateFieldOptions, theme, report, editChart, fields, query, SelectComponent, TextInputComponent, ButtonComponent, SecondaryButtonComponent, setFieldValue, organizationName, formHeaderStyle, formLabelStyle, showTableFormatOptions, showDateFieldOptions, showAccessControlOptions, }) {
773
+ const Y_FORMAT_OPTIONS = [
774
+ { value: 'whole_number', label: 'whole number' },
775
+ { value: 'one_decimal_place', label: 'one decimal place' },
776
+ { value: 'dollar_amount', label: 'dollar amount' },
777
+ { value: 'MMM_yyyy', label: 'month' },
778
+ { value: 'MMM_dd-MMM_dd', label: 'week' },
779
+ { value: 'MMM_dd_yyyy', label: 'day' },
780
+ { value: 'MMM_dd_hh:mm_ap_pm', label: 'day and time' },
781
+ { value: 'hh_ap_pm', label: 'hour' },
782
+ { value: 'percent', label: 'percent' },
783
+ { value: 'string', label: 'string' },
784
+ ];
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);
627
813
  const [chartConfig, setChartConfig] = (0, react_1.useState)({});
814
+ const { dateFilter } = (0, react_1.useContext)(Context_1.DateFilterContext);
628
815
  const [yAxisFields, setYAxisFields] = (0, react_1.useState)(report
629
816
  ? report.yAxisFields
630
817
  : [
631
818
  {
632
- field: fieldOptions.length > 1
633
- ? fieldOptions[1].value
634
- : fieldOptions[0].value,
819
+ field: yAxisOptions.length > 1
820
+ ? yAxisOptions[1].value
821
+ : yAxisOptions[0].value,
635
822
  label: '',
636
823
  format: 'whole_number',
637
824
  },
638
825
  ]);
826
+ const [bucketFields, setBucketFields] = (0, react_1.useState)((report && report.buckets) || []);
639
827
  const [columns, setColumns] = (0, react_1.useState)(report && report.columns.length
640
828
  ? report.columns
641
829
  : fields?.length
@@ -647,12 +835,146 @@ function FormikForm({ values, isSubmitting, data, fieldOptions, dateFieldOptions
647
835
  { label: '', field: '', format: 'whole_number' },
648
836
  ]);
649
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]);
650
920
  const handleDeleteYAxisField = index => {
651
921
  setYAxisFields(yAxisFields => yAxisFields.filter((_, i) => index !== i));
652
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
+ };
653
970
  const handleYAxisFieldChange = (index, value) => {
654
971
  const newYAxisFields = [...yAxisFields];
655
- 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
+ };
656
978
  setYAxisFields(newYAxisFields);
657
979
  };
658
980
  const handleYAxisFieldFormatChange = (index, value) => {
@@ -660,7 +982,7 @@ function FormikForm({ values, isSubmitting, data, fieldOptions, dateFieldOptions
660
982
  newYAxisFields[index] = { ...newYAxisFields[index], format: value };
661
983
  setYAxisFields(newYAxisFields);
662
984
  };
663
- const handleYAxisFieldLabelChange = (index, value) => {
985
+ const handleYAxisLabelChange = (index, value) => {
664
986
  const newYAxisFields = [...yAxisFields];
665
987
  newYAxisFields[index] = { ...newYAxisFields[index], label: value };
666
988
  setYAxisFields(newYAxisFields);
@@ -681,10 +1003,37 @@ function FormikForm({ values, isSubmitting, data, fieldOptions, dateFieldOptions
681
1003
  setColumns(newColumns);
682
1004
  };
683
1005
  (0, react_1.useEffect)(() => {
684
- setChartConfig({ ...values, yAxisFields: yAxisFields, rows: data });
685
- }, [values, yAxisFields]);
686
- // console.log('VIBE: ', { report, values, yAxisFields, columns, query });
687
- 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: {
688
1037
  display: 'flex',
689
1038
  flexDirection: 'column',
690
1039
  paddingLeft: 25,
@@ -693,76 +1042,114 @@ function FormikForm({ values, isSubmitting, data, fieldOptions, dateFieldOptions
693
1042
  display: 'flex',
694
1043
  flexDirection: 'column',
695
1044
  }, children: [(0, jsx_runtime_1.jsx)("div", { style: { height: 20 } }), (0, jsx_runtime_1.jsx)("div", { style: {
696
- marginRight: chartConfig.chartType === 'pie' ? undefined : 25,
697
- marginLeft: chartConfig.chartType === 'pie' ? undefined : -25,
698
- }, children: Object.keys(chartConfig).length > 0 && ((0, jsx_runtime_1.jsx)(Chart_1.default, { chartId: "646e37a660feef000be67a93", config: chartConfig, colors: theme.chartColors, containerStyle: {
699
- 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)',
700
1057
  height: 300,
701
- } })) }), (0, jsx_runtime_1.jsx)("div", { style: { height: 40 } }), showTableFormatOptions || showDateFieldOptions ? ((0, jsx_runtime_1.jsx)("div", { style: formHeaderStyle || {
702
- fontFamily: theme.fontFamily,
703
- color: theme.primaryTextColor,
704
- fontSize: theme?.fontSize ? theme?.fontSize + 2 : 14,
705
- fontWeight: 600,
706
- // marginTop: 20,
707
- }, 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: {
708
1064
  display: 'flex',
709
1065
  flexDirection: 'row',
710
1066
  alignItems: 'center',
711
1067
  }, children: [(0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'column', marginTop: 8 }, children: [(0, jsx_runtime_1.jsx)("div", { style: formLabelStyle || {
712
- fontSize: '14px',
713
- marginBottom: '6px',
714
- fontWeight: '600',
715
1068
  color: theme.secondaryTextColor,
716
1069
  fontFamily: theme?.fontFamily,
717
- }, 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 || {
718
- 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 || {
719
1073
  color: theme.secondaryTextColor,
720
- fontSize: theme?.fontSize,
721
- fontWeight: theme.labelFontWeight,
722
- }, 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 || {
723
- 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',
724
1079
  color: theme.secondaryTextColor,
725
- fontSize: theme.fontSize,
726
- fontWeight: theme.labelFontWeight,
727
- }, 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: [
728
1084
  { label: 'column', value: 'column' },
729
1085
  { label: 'bar', value: 'bar' },
730
1086
  { label: 'line', value: 'line' },
731
1087
  { label: 'pie', value: 'pie' },
732
1088
  { label: 'metric', value: 'metric' },
733
1089
  { label: 'table', value: 'table' },
734
- ] }) })] })] })] }), (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: {
735
1125
  display: 'flex',
736
1126
  flexDirection: 'row',
737
1127
  alignItems: 'center',
738
1128
  // justifyContent: 'space-between',
739
1129
  marginTop: 20,
740
- }, children: values.chartType !== 'table' && ((0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'column' }, children: [(0, jsx_runtime_1.jsx)("div", { style: formLabelStyle || {
741
- 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 || {
742
1131
  color: theme.secondaryTextColor,
743
- fontSize: theme.fontSize,
744
- fontWeight: theme.labelFontWeight,
745
- }, children: values.chartType === 'pie'
746
- ? 'Category column'
747
- : '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: {
748
1136
  display: 'flex',
749
1137
  flexDirection: 'row',
750
1138
  alignItems: 'center',
751
- }, 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: {
752
1140
  display: 'flex',
753
1141
  flexDirection: 'row',
754
1142
  alignItems: 'flex-start',
755
1143
  // justifyContent: 'space-between',
756
1144
  marginTop: 20,
757
1145
  }, children: [(0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'column' }, children: [(0, jsx_runtime_1.jsx)("div", { style: formLabelStyle || {
758
- fontFamily: theme.fontFamily,
759
1146
  color: theme.secondaryTextColor,
760
- fontSize: theme.fontSize,
761
- fontWeight: theme.labelFontWeight,
762
- minWidth: 200,
763
- }, children: values.chartType === 'table'
1147
+ fontFamily: theme?.fontFamily,
1148
+ fontSize: theme?.fontSize || '14px',
1149
+ fontWeight: theme.labelFontWeight || '600',
1150
+ }, children: chartType === 'table'
764
1151
  ? 'Columns'
765
- : values.chartType === 'pie'
1152
+ : chartType === 'pie'
766
1153
  ? 'Quantity column'
767
1154
  : 'y-axis columns' }), (0, jsx_runtime_1.jsxs)("div", { style: {
768
1155
  display: 'flex',
@@ -772,24 +1159,24 @@ function FormikForm({ values, isSubmitting, data, fieldOptions, dateFieldOptions
772
1159
  flexDirection: 'row',
773
1160
  alignItems: 'center',
774
1161
  marginTop: index === 0 ? 6 : 10,
775
- }, 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: {
776
1163
  display: 'flex',
777
1164
  flexDirection: 'column',
778
1165
  justifyContent: 'flex-start',
779
1166
  }, children: [(0, jsx_runtime_1.jsx)("div", { style: formLabelStyle || {
780
- fontFamily: theme.fontFamily,
781
1167
  color: 'transparent',
782
- fontSize: theme.fontSize,
783
- fontWeight: theme.labelFontWeight,
784
- minWidth: 200,
785
- // marginBottom: 10,
786
- }, 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' &&
787
1172
  yAxisFields.map((yAxisField, index) => ((0, jsx_runtime_1.jsxs)("div", { style: {
788
1173
  display: 'flex',
789
1174
  flexDirection: 'row',
790
- alignItems: 'center',
1175
+ // alignItems: 'center',
791
1176
  marginTop: index === 0 ? 6 : 10,
792
- }, 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: {
793
1180
  cursor: index > 0 ? 'pointer' : undefined,
794
1181
  paddingLeft: 6,
795
1182
  paddingTop: 12,
@@ -799,79 +1186,175 @@ function FormikForm({ values, isSubmitting, data, fieldOptions, dateFieldOptions
799
1186
  display: 'flex',
800
1187
  alignItems: 'center',
801
1188
  justifyContent: 'center',
802
- }, 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 || {
803
- fontFamily: theme.fontFamily,
804
- color: theme.primaryTextColor,
805
- fontSize: theme.fontSize + 2,
806
- fontWeight: 600,
807
- }, 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: {
808
1201
  display: 'flex',
809
1202
  flexDirection: 'row',
810
1203
  alignItems: 'flex-start',
811
1204
  marginTop: 6,
812
1205
  // justifyContent: 'space-between',
813
1206
  // marginTop: 8,
814
- }, children: [(0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'column' }, children: [(0, jsx_runtime_1.jsx)("div", { style: formLabelStyle || {
815
- fontFamily: theme.fontFamily,
816
- color: theme.secondaryTextColor,
817
- fontSize: theme.fontSize,
818
- fontWeight: theme.labelFontWeight,
819
- }, children: 'Columns' }), (0, jsx_runtime_1.jsxs)("div", { style: {
820
- display: 'flex',
821
- flexDirection: 'column',
822
- }, children: [columns.map((yAxisField, index) => ((0, jsx_runtime_1.jsx)("div", { style: {
823
- display: 'flex',
824
- flexDirection: 'row',
825
- alignItems: 'center',
826
- marginTop: index === 0 ? 6 : 10,
827
- }, 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: {
828
1218
  display: 'flex',
829
1219
  flexDirection: 'column',
830
1220
  justifyContent: 'flex-start',
831
- }, children: [(0, jsx_runtime_1.jsx)("div", { style: formLabelStyle || {
832
- fontFamily: theme.fontFamily,
833
- color: 'transparent',
834
- fontSize: theme.fontSize,
835
- fontWeight: theme.labelFontWeight,
836
- minWidth: 200,
837
- // marginBottom: 10,
838
- }, children: "label" }), columns.map((yAxisField, index) => ((0, jsx_runtime_1.jsxs)("div", { style: {
839
- display: 'flex',
840
- flexDirection: 'row',
841
- alignItems: 'center',
842
- marginTop: index === 0 ? 6 : 10,
843
- }, 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 || {
844
- fontFamily: theme.fontFamily,
845
- color: theme.primaryTextColor,
846
- fontSize: theme.fontSize + 2,
847
- fontWeight: 600,
848
- // marginTop: 20,
849
- }, 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: {
850
1233
  display: 'flex',
851
1234
  flexDirection: 'row',
852
1235
  alignItems: 'center',
853
- }, children: [(0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'column', marginTop: 8 }, children: [(0, jsx_runtime_1.jsx)("div", { style: formLabelStyle || {
854
- 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 || {
855
1237
  color: theme.secondaryTextColor,
856
- fontSize: theme.fontSize,
857
- fontWeight: theme.labelFontWeight,
858
- }, 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
859
1242
  ? [{ label: '', value: '' }]
860
1243
  : dateFieldOptions.map(elem => {
861
1244
  return { label: elem.name, value: elem.name };
862
- }) }) })] }), (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 || {
863
- 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 || {
864
1246
  color: theme.secondaryTextColor,
865
- fontSize: theme.fontSize,
866
- fontWeight: theme.labelFontWeight,
867
- }, 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
868
1251
  ? [{ label: '', value: '' }]
869
- : 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
870
1254
  ? dateFieldOptions
871
- .filter(elem => elem.name === values.dateFieldTable)[0]
1255
+ .filter(elem => elem.name === dateFieldTable)[0]
872
1256
  .columns.map(elem => {
873
1257
  return { label: elem.name, value: elem.name };
874
1258
  })
875
- : [{ 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 } })] }) }));
876
1359
  }
877
1360
  //# sourceMappingURL=AddToDashboardModal.js.map