@quillsql/react 2.1.4 → 2.1.6

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 && chartType !== 'table'
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 && chartType !== 'table'
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
- columns: showTableFormatOptions
348
+ columns: showTableFormatOptions && chartType !== 'table'
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,32 @@ 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 => (0, ReportBuilder_1.getPostgresBasicType)(newFields.find(field => field.name === option)) ===
589
+ 'number')
590
+ .map(field => ({
591
+ value: field,
592
+ label: field,
593
+ }));
396
594
  const [dateFieldOptions, setDateFieldOptions] = (0, react_1.useState)([]);
595
+ const [formValues, setFormValues] = (0, react_1.useState)({});
397
596
  (0, react_1.useEffect)(() => {
398
597
  const fetchReferencedTables = async () => {
399
598
  if (!query) {
@@ -404,115 +603,60 @@ SelectComponent, TextInputComponent, ButtonComponent, SecondaryButtonComponent,
404
603
  };
405
604
  fetchReferencedTables();
406
605
  }, [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 })) }));
606
+ 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
607
+ ? ({ onChange, value, options, form, field, }) => {
608
+ const handleChange = async (option) => {
609
+ if (onChange) {
610
+ onChange(option);
611
+ return;
612
+ }
613
+ await form.setFieldValue(field.name, option);
614
+ form.setFieldTouched(field.name, true);
615
+ };
616
+ return ((0, jsx_runtime_1.jsx)(SelectComponent, { onChange: event => handleChange(event.target.value), value: value, options: options }));
617
+ }
618
+ : MemoizedDefaultSelectComponent, TextInputComponent: TextInputComponent
619
+ ? TextInputComponent
620
+ : MemoizedDefaultTextInputComponent, ButtonComponent: ButtonComponent
621
+ ? ButtonComponent
622
+ : ({ onClick, label }) => {
623
+ return ((0, jsx_runtime_1.jsx)("div", { style: {
624
+ height: 38,
625
+ background: theme.primaryButtonColor,
626
+ color: theme.backgroundColor,
627
+ display: 'flex',
628
+ borderRadius: 6,
629
+ alignItems: 'center',
630
+ justifyContent: 'center',
631
+ outline: 'none',
632
+ cursor: 'pointer',
633
+ fontFamily: theme.fontFamily,
634
+ fontWeight: theme.buttonFontWeight || 600,
635
+ border: 'none',
636
+ fontSize: 14,
637
+ }, onClick: onClick, children: label }));
638
+ }, SecondaryButtonComponent: ButtonComponent
639
+ ? ButtonComponent
640
+ : ({ onClick, label }) => {
641
+ return ((0, jsx_runtime_1.jsx)("div", { style: {
642
+ height: 38,
643
+ background: theme.backgroundColor,
644
+ borderWidth: theme.borderWidth,
645
+ borderColor: theme.borderColor,
646
+ color: theme.primaryTextColor,
647
+ display: 'flex',
648
+ borderRadius: 6,
649
+ alignItems: 'center',
650
+ justifyContent: 'center',
651
+ outline: 'none',
652
+ cursor: 'pointer',
653
+ fontFamily: theme.fontFamily,
654
+ fontWeight: theme.buttonFontWeight || 600,
655
+ fontSize: 14,
656
+ }, onClick: onClick, children: label }));
657
+ }, formHeaderStyle: formHeaderStyle, formLabelStyle: formLabelStyle }));
515
658
  }
659
+ exports.ChartForm = ChartForm;
516
660
  function isValidDate(d) {
517
661
  return d instanceof Date && !isNaN(d);
518
662
  }
@@ -581,8 +725,8 @@ const POSTGRES_DATE_TYPES = [
581
725
  ];
582
726
  async function getReferencedTables(sqlQuery, databaseType, dbTables) {
583
727
  // const parser = new Parser();
584
- let tables = [];
585
- let withAliases = [];
728
+ const tables = [];
729
+ const withAliases = [];
586
730
  const response = await fetch('https://quill-344421.uc.r.appspot.com/astify', {
587
731
  method: 'POST',
588
732
  headers: {
@@ -611,10 +755,12 @@ async function getReferencedTables(sqlQuery, databaseType, dbTables) {
611
755
  })
612
756
  .filter(table => table.columns.length > 0);
613
757
  }
614
- const FORMAT_OPTIONS = [
758
+ const X_FORMAT_OPTIONS = [
615
759
  { value: 'whole_number', label: 'whole number' },
616
760
  { value: 'one_decimal_place', label: 'one decimal place' },
761
+ { value: 'two_decimal_places', label: 'two decimal places' },
617
762
  { value: 'dollar_amount', label: 'dollar amount' },
763
+ { value: 'dollar_cents', label: 'dollar and cent amount' },
618
764
  { value: 'MMM_yyyy', label: 'month' },
619
765
  { value: 'MMM_dd-MMM_dd', label: 'week' },
620
766
  { value: 'MMM_dd_yyyy', label: 'day' },
@@ -622,20 +768,64 @@ 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: 'two_decimal_places', label: 'two decimal places' },
777
+ { value: 'dollar_amount', label: 'dollar amount' },
778
+ { value: 'dollar_cents', label: 'dollar and cent amount' },
779
+ { value: 'MMM_yyyy', label: 'month' },
780
+ { value: 'MMM_dd-MMM_dd', label: 'week' },
781
+ { value: 'MMM_dd_yyyy', label: 'day' },
782
+ { value: 'MMM_dd_hh:mm_ap_pm', label: 'day and time' },
783
+ { value: 'hh_ap_pm', label: 'hour' },
784
+ { value: 'percent', label: 'percent' },
785
+ { value: 'string', label: 'string' },
786
+ ];
787
+ const handleBucketData = (dashboardItem, bucketFields, dateFilter) => {
788
+ const result = (0, aggregate_1.aggregate)(dashboardItem, bucketFields, dateFilter);
789
+ return (0, aggregate_1.aggregate)(dashboardItem, bucketFields, dateFilter);
790
+ };
791
+ function FormikForm({ data, xAxisOptions, yAxisOptions, fieldOptions, dateFieldOptions, theme, report, editChart, fields, newFields, query, client, SelectComponent, TextInputComponent, ButtonComponent, SecondaryButtonComponent, organizationName, formHeaderStyle, formLabelStyle, showTableFormatOptions, showDateFieldOptions, showAccessControlOptions, }) {
792
+ // fieldOptions.sort((a, b) => {
793
+ // if (a.value === 'created_at') return -1;
794
+ // if (b.value === 'created_at') return 1;
795
+ // return 0;
796
+ // });
797
+ X_FORMAT_OPTIONS.sort((a, b) => {
798
+ if (a.value === 'dynamic')
799
+ return -1;
800
+ if (b.value === 'dynamic')
801
+ return 1;
802
+ return 0;
803
+ });
804
+ const [rows, setRows] = (0, react_1.useState)(null);
805
+ const [isSubmitting, setIsSubmitting] = (0, react_1.useState)(false);
806
+ const { environment } = client;
807
+ const [xAxisField, setXAxisField] = (0, react_1.useState)(report?.xAxisField || xAxisOptions[0].value);
808
+ const [xAxisLabel, setXAxisLabel] = (0, react_1.useState)(report?.xAxisLabel || '');
809
+ const [xAxisFormat, setXAxisFormat] = (0, react_1.useState)(report?.xAxisFormat || X_FORMAT_OPTIONS[0].value);
810
+ const [chartName, setChartName] = (0, react_1.useState)(report?.name || '');
811
+ const [chartType, setChartType] = (0, react_1.useState)(report?.chartType || 'column');
812
+ const [dateFieldTable, setDateFieldTable] = (0, react_1.useState)((dateFieldOptions.length && dateFieldOptions[0].name) || '');
813
+ const [dateField, setDateField] = (0, react_1.useState)((dateFieldOptions.length && dateFieldOptions[0].columns[0].name) || '');
814
+ const [template, setTemplate] = (0, react_1.useState)(report?.template || false);
627
815
  const [chartConfig, setChartConfig] = (0, react_1.useState)({});
816
+ const { dateFilter } = (0, react_1.useContext)(Context_1.DateFilterContext);
628
817
  const [yAxisFields, setYAxisFields] = (0, react_1.useState)(report
629
818
  ? report.yAxisFields
630
819
  : [
631
820
  {
632
- field: fieldOptions.length > 1
633
- ? fieldOptions[1].value
634
- : fieldOptions[0].value,
821
+ field: yAxisOptions.length > 1
822
+ ? yAxisOptions[1].value
823
+ : yAxisOptions[0].value,
635
824
  label: '',
636
825
  format: 'whole_number',
637
826
  },
638
827
  ]);
828
+ const [bucketFields, setBucketFields] = (0, react_1.useState)((report && report.buckets) || []);
639
829
  const [columns, setColumns] = (0, react_1.useState)(report && report.columns.length
640
830
  ? report.columns
641
831
  : fields?.length
@@ -647,12 +837,146 @@ function FormikForm({ values, isSubmitting, data, fieldOptions, dateFieldOptions
647
837
  { label: '', field: '', format: 'whole_number' },
648
838
  ]);
649
839
  };
840
+ const handleAddBucket = () => {
841
+ const bucketPossibilities = xAxisOptions.filter(option =>
842
+ // whatIsProbablyTheType(data.slice(0, 10), option.value) === 'date'
843
+ (0, ReportBuilder_1.getPostgresBasicType)(newFields.find(field => field.name === option.value)) === 'date');
844
+ if (!bucketPossibilities.length) {
845
+ alert('No possible buckets');
846
+ return;
847
+ }
848
+ setBucketFields([
849
+ ...bucketFields,
850
+ {
851
+ field: bucketPossibilities[0].value,
852
+ },
853
+ ]);
854
+ setXAxisField(bucketPossibilities[0].value);
855
+ if (bucketPossibilities[0].value === dateField) {
856
+ setXAxisFormat('dynamic');
857
+ }
858
+ else {
859
+ setXAxisFormat(
860
+ // whatIsProbablyTheType(data.slice(0, 10), bucketPossibilities[0].value)
861
+ (0, ReportBuilder_1.getPostgresBasicType)(newFields.find(field => field.name === bucketPossibilities[0].value)));
862
+ }
863
+ };
864
+ const [dashboardOptions, setDashboardOptions] = (0, react_1.useState)([]);
865
+ const [dashboardName, setDashboardName] = (0, react_1.useState)(report?.dashboardName || dashboardOptions[0]);
866
+ const values = {
867
+ xAxisLabel,
868
+ chartName,
869
+ chartType,
870
+ xAxisField,
871
+ xAxisFormat,
872
+ dashboardName,
873
+ dateFieldTable,
874
+ dateField,
875
+ };
876
+ const [selectedTabIndex, setSelectedTabIndex] = (0, react_1.useState)(values.template ? 1 : 0);
877
+ (0, react_1.useEffect)(() => {
878
+ if (dashboardOptions.length) {
879
+ setDashboardName(dashboardOptions[0].value);
880
+ }
881
+ }, [dashboardOptions]);
882
+ (0, react_1.useEffect)(() => {
883
+ async function getDashNames() {
884
+ const response2 = await fetch(`https://quill-344421.uc.r.appspot.com/dashnames/${client.publicKey}/`, {
885
+ method: 'GET',
886
+ headers: {
887
+ Authorization: `Bearer `,
888
+ environment: environment,
889
+ },
890
+ });
891
+ const response2Data = await response2.json();
892
+ setDashboardOptions(response2Data.dashboardNames
893
+ .filter(elem => elem !== null)
894
+ .map(key => ({ label: key, value: key })));
895
+ }
896
+ getDashNames();
897
+ }, []);
898
+ (0, react_1.useEffect)(() => {
899
+ // if (!dateField) {
900
+ // return;
901
+ // }
902
+ // if (
903
+ // (!bucketFields.length && chartType === 'column') ||
904
+ // chartType === 'line'
905
+ // ) {
906
+ // handleAddBucket();
907
+ // return;
908
+ // }
909
+ if ((bucketFields.length && chartType === 'metric') ||
910
+ chartType === 'table' ||
911
+ chartType === 'pie') {
912
+ handleDeleteBucketField(0);
913
+ return;
914
+ }
915
+ }, [chartType, dateField]);
916
+ (0, react_1.useEffect)(() => {
917
+ if (dateFieldOptions.length) {
918
+ setDateFieldTable(dateFieldOptions[0].name);
919
+ setDateField(dateFieldOptions[0].columns[0].name);
920
+ }
921
+ }, [dateFieldOptions]);
650
922
  const handleDeleteYAxisField = index => {
651
923
  setYAxisFields(yAxisFields => yAxisFields.filter((_, i) => index !== i));
652
924
  };
925
+ const handleDeleteBucketField = index => {
926
+ setBucketFields(bucketFields => bucketFields.filter((_, i) => index !== i));
927
+ setXAxisField(xAxisOptions[0].value);
928
+ setXAxisLabel('');
929
+ };
930
+ const handleBucketFieldChange = (index, value) => {
931
+ if (!dateField) {
932
+ return;
933
+ }
934
+ const newBucketFields = [...bucketFields];
935
+ newBucketFields[index] = { ...newBucketFields[index], field: value };
936
+ setBucketFields(newBucketFields);
937
+ setXAxisField(value);
938
+ if (value === dateField) {
939
+ setXAxisFormat('dynamic');
940
+ }
941
+ else {
942
+ setXAxisFormat(
943
+ // whatIsProbablyTheType(data.slice(0, 10), value)
944
+ (0, ReportBuilder_1.getPostgresBasicType)(newFields.find(field => field.name === value)));
945
+ }
946
+ };
947
+ const handleXAxisFieldChange = value => {
948
+ if (!dateField) {
949
+ return;
950
+ }
951
+ // const newXAxisField = {
952
+ // format: xAxisFormat,
953
+ // label: xAxisLabel,
954
+ // field: value,
955
+ // };
956
+ setXAxisField(value);
957
+ // TODO: MAKE DATE FIELD NOT HARD CODED
958
+ if (value === dateField) {
959
+ setXAxisFormat('dynamic');
960
+ }
961
+ else {
962
+ setXAxisFormat(
963
+ // whatIsProbablyTheType(data.slice(0, 10), value)
964
+ (0, ReportBuilder_1.getPostgresBasicType)(newFields.find(field => field.name === value)));
965
+ }
966
+ if (bucketFields.length > 0) {
967
+ const newBucketFields = [...bucketFields];
968
+ newBucketFields[0] = { ...newBucketFields[0], field: value };
969
+ setBucketFields(newBucketFields);
970
+ }
971
+ };
653
972
  const handleYAxisFieldChange = (index, value) => {
654
973
  const newYAxisFields = [...yAxisFields];
655
- newYAxisFields[index] = { ...newYAxisFields[index], field: value };
974
+ newYAxisFields[index] = {
975
+ ...newYAxisFields[index],
976
+ field: value,
977
+ // format: whatIsProbablyTheType(data.slice(0, 10), value),
978
+ format: (0, ReportBuilder_1.getPostgresBasicType)(newFields.find(field => field.name === value)),
979
+ };
656
980
  setYAxisFields(newYAxisFields);
657
981
  };
658
982
  const handleYAxisFieldFormatChange = (index, value) => {
@@ -660,7 +984,7 @@ function FormikForm({ values, isSubmitting, data, fieldOptions, dateFieldOptions
660
984
  newYAxisFields[index] = { ...newYAxisFields[index], format: value };
661
985
  setYAxisFields(newYAxisFields);
662
986
  };
663
- const handleYAxisFieldLabelChange = (index, value) => {
987
+ const handleYAxisLabelChange = (index, value) => {
664
988
  const newYAxisFields = [...yAxisFields];
665
989
  newYAxisFields[index] = { ...newYAxisFields[index], label: value };
666
990
  setYAxisFields(newYAxisFields);
@@ -681,10 +1005,37 @@ function FormikForm({ values, isSubmitting, data, fieldOptions, dateFieldOptions
681
1005
  setColumns(newColumns);
682
1006
  };
683
1007
  (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: {
1008
+ const now = new Date();
1009
+ setChartConfig(handleBucketData({
1010
+ xAxisField,
1011
+ xAxisLabel,
1012
+ xAxisFormat,
1013
+ chartName,
1014
+ chartType,
1015
+ dashboardName,
1016
+ dateFieldTable,
1017
+ dateField,
1018
+ template,
1019
+ yAxisFields: yAxisFields,
1020
+ rows: data,
1021
+ fields: newFields,
1022
+ columns: columns,
1023
+ }, bucketFields, dateFilter));
1024
+ }, [
1025
+ xAxisField,
1026
+ xAxisLabel,
1027
+ xAxisFormat,
1028
+ chartName,
1029
+ chartType,
1030
+ dashboardName,
1031
+ dateFieldTable,
1032
+ dateField,
1033
+ template,
1034
+ yAxisFields,
1035
+ bucketFields,
1036
+ columns,
1037
+ ]);
1038
+ return ((0, jsx_runtime_1.jsx)("div", { style: { display: 'inline-block' }, children: (0, jsx_runtime_1.jsxs)("div", { style: {
688
1039
  display: 'flex',
689
1040
  flexDirection: 'column',
690
1041
  paddingLeft: 25,
@@ -693,76 +1044,114 @@ function FormikForm({ values, isSubmitting, data, fieldOptions, dateFieldOptions
693
1044
  display: 'flex',
694
1045
  flexDirection: 'column',
695
1046
  }, 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)',
1047
+ marginRight: chartConfig.chartType === 'pie' ||
1048
+ chartConfig.chartType === 'table'
1049
+ ? undefined
1050
+ : 25,
1051
+ marginLeft: chartConfig.chartType === 'pie' ||
1052
+ chartConfig.chartType === 'table'
1053
+ ? undefined
1054
+ : -25,
1055
+ }, children: Object.keys(chartConfig).length > 0 && ((0, jsx_runtime_1.jsx)(Chart_1.default, { config: chartConfig, colors: theme.chartColors, containerStyle: {
1056
+ width: chartConfig.chartType === 'table'
1057
+ ? 640
1058
+ : 'calc(100% - 24px)',
700
1059
  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: {
1060
+ } })) }), (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 || {
1061
+ fontFamily: theme.fontFamily,
1062
+ color: theme.primaryTextColor,
1063
+ fontSize: theme.fontSize + 2,
1064
+ fontWeight: 600,
1065
+ }, children: 'Chart' }) })) : null, (0, jsx_runtime_1.jsxs)("div", { style: {
708
1066
  display: 'flex',
709
1067
  flexDirection: 'row',
710
1068
  alignItems: 'center',
711
1069
  }, 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
1070
  color: theme.secondaryTextColor,
716
1071
  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,
1072
+ fontSize: theme?.fontSize || '14px',
1073
+ fontWeight: theme.labelFontWeight || '600',
1074
+ }, 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
1075
  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,
1076
+ fontFamily: theme?.fontFamily,
1077
+ fontSize: theme?.fontSize || '14px',
1078
+ fontWeight: theme.labelFontWeight || '600',
1079
+ }, 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 || {
1080
+ fontSize: '14px',
724
1081
  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: [
1082
+ fontFamily: theme?.fontFamily,
1083
+ fontSize: theme?.fontSize || '14px',
1084
+ fontWeight: theme.labelFontWeight || '600',
1085
+ }, 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
1086
  { label: 'column', value: 'column' },
729
1087
  { label: 'bar', value: 'bar' },
730
1088
  { label: 'line', value: 'line' },
731
1089
  { label: 'pie', value: 'pie' },
732
1090
  { label: 'metric', value: 'metric' },
733
1091
  { label: 'table', value: 'table' },
734
- ] }) })] })] })] }), (0, jsx_runtime_1.jsx)("div", { style: {
1092
+ ], theme: theme }) })] })] })] }), chartType !== 'table' &&
1093
+ chartType !== 'metric' &&
1094
+ chartType !== 'pie' && ((0, jsx_runtime_1.jsxs)("div", { style: {
1095
+ display: 'flex',
1096
+ flexDirection: 'column',
1097
+ marginTop: 20,
1098
+ maxWidth: 200,
1099
+ }, children: [(0, jsx_runtime_1.jsx)("div", { style: formLabelStyle || {
1100
+ color: theme.secondaryTextColor,
1101
+ fontFamily: theme?.fontFamily,
1102
+ fontSize: theme?.fontSize || '14px',
1103
+ fontWeight: theme.labelFontWeight || '600',
1104
+ }, children: "Buckets" }), (0, jsx_runtime_1.jsx)("div", { style: {
1105
+ maxWidth: 200,
1106
+ // marginTop: 6,
1107
+ display: 'flex',
1108
+ flexDirection: 'column',
1109
+ }, children: bucketFields.map((bucketField, index) => ((0, jsx_runtime_1.jsxs)("div", { style: {
1110
+ display: 'flex',
1111
+ flexDirection: 'row',
1112
+ alignItems: 'center',
1113
+ marginTop: index === 0 ? 6 : 10,
1114
+ }, 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,
1115
+ // TODO: PROB FILTER OUT NUMBERS LMAO (SO DATE AND STRING ONLY)
1116
+ options: xAxisOptions, theme: theme }) }), (0, jsx_runtime_1.jsx)("div", { onClick: () => handleDeleteBucketField(index), style: {
1117
+ cursor: 'pointer',
1118
+ paddingLeft: 6,
1119
+ paddingTop: 9,
1120
+ paddingBottom: 9,
1121
+ paddingRight: 6,
1122
+ maxHeight: 38,
1123
+ display: 'flex',
1124
+ alignItems: 'center',
1125
+ justifyContent: 'center',
1126
+ }, 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
1127
  display: 'flex',
736
1128
  flexDirection: 'row',
737
1129
  alignItems: 'center',
738
1130
  // justifyContent: 'space-between',
739
1131
  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,
1132
+ }, children: chartType !== 'table' && ((0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'column' }, children: [(0, jsx_runtime_1.jsx)("div", { style: formLabelStyle || {
742
1133
  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: {
1134
+ fontFamily: theme?.fontFamily,
1135
+ fontSize: theme?.fontSize || '14px',
1136
+ fontWeight: theme.labelFontWeight || '600',
1137
+ }, 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
1138
  display: 'flex',
749
1139
  flexDirection: 'row',
750
1140
  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: {
1141
+ }, 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
1142
  display: 'flex',
753
1143
  flexDirection: 'row',
754
1144
  alignItems: 'flex-start',
755
1145
  // justifyContent: 'space-between',
756
1146
  marginTop: 20,
757
1147
  }, 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
1148
  color: theme.secondaryTextColor,
760
- fontSize: theme.fontSize,
761
- fontWeight: theme.labelFontWeight,
762
- minWidth: 200,
763
- }, children: values.chartType === 'table'
1149
+ fontFamily: theme?.fontFamily,
1150
+ fontSize: theme?.fontSize || '14px',
1151
+ fontWeight: theme.labelFontWeight || '600',
1152
+ }, children: chartType === 'table'
764
1153
  ? 'Columns'
765
- : values.chartType === 'pie'
1154
+ : chartType === 'pie'
766
1155
  ? 'Quantity column'
767
1156
  : 'y-axis columns' }), (0, jsx_runtime_1.jsxs)("div", { style: {
768
1157
  display: 'flex',
@@ -772,24 +1161,24 @@ function FormikForm({ values, isSubmitting, data, fieldOptions, dateFieldOptions
772
1161
  flexDirection: 'row',
773
1162
  alignItems: 'center',
774
1163
  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: {
1164
+ }, 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
1165
  display: 'flex',
777
1166
  flexDirection: 'column',
778
1167
  justifyContent: 'flex-start',
779
1168
  }, children: [(0, jsx_runtime_1.jsx)("div", { style: formLabelStyle || {
780
- fontFamily: theme.fontFamily,
781
1169
  color: 'transparent',
782
- fontSize: theme.fontSize,
783
- fontWeight: theme.labelFontWeight,
784
- minWidth: 200,
785
- // marginBottom: 10,
786
- }, children: "y-axis label" }), values.chartType !== 'pie' &&
1170
+ fontFamily: theme?.fontFamily,
1171
+ fontSize: theme?.fontSize || '14px',
1172
+ fontWeight: theme.labelFontWeight || '600',
1173
+ }, children: "y-axis label" }), chartType !== 'pie' &&
787
1174
  yAxisFields.map((yAxisField, index) => ((0, jsx_runtime_1.jsxs)("div", { style: {
788
1175
  display: 'flex',
789
1176
  flexDirection: 'row',
790
- alignItems: 'center',
1177
+ // alignItems: 'center',
791
1178
  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: {
1179
+ }, children: [(0, jsx_runtime_1.jsx)("div", { style: { minWidth: 200 }, children: (0, jsx_runtime_1.jsx)(TextInputComponent, { value: yAxisFields[index].label, onChange: e => {
1180
+ handleYAxisLabelChange(index, e.target.value);
1181
+ }, 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
1182
  cursor: index > 0 ? 'pointer' : undefined,
794
1183
  paddingLeft: 6,
795
1184
  paddingTop: 12,
@@ -799,79 +1188,175 @@ function FormikForm({ values, isSubmitting, data, fieldOptions, dateFieldOptions
799
1188
  display: 'flex',
800
1189
  alignItems: 'center',
801
1190
  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: {
1191
+ }, 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 || {
1192
+ fontFamily: theme.fontFamily,
1193
+ color: theme.primaryTextColor,
1194
+ fontSize: theme.fontSize + 2,
1195
+ fontWeight: 600,
1196
+ // marginTop: 20,
1197
+ }, children: 'Table' }), (0, jsx_runtime_1.jsx)("div", { style: { height: 8 } })] })), showTableFormatOptions && chartType !== 'table' && ((0, jsx_runtime_1.jsx)("div", { style: formLabelStyle || {
1198
+ color: theme.secondaryTextColor,
1199
+ fontFamily: theme?.fontFamily,
1200
+ fontSize: theme?.fontSize || '14px',
1201
+ fontWeight: theme.labelFontWeight || '600',
1202
+ }, children: 'Columns' })), showTableFormatOptions && chartType !== 'table' && ((0, jsx_runtime_1.jsxs)("div", { style: {
808
1203
  display: 'flex',
809
1204
  flexDirection: 'row',
810
1205
  alignItems: 'flex-start',
811
1206
  marginTop: 6,
812
1207
  // justifyContent: 'space-between',
813
1208
  // 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: {
1209
+ }, children: [(0, jsx_runtime_1.jsx)("div", { style: { display: 'flex', flexDirection: 'column' }, children: (0, jsx_runtime_1.jsxs)("div", { style: {
1210
+ display: 'flex',
1211
+ flexDirection: 'column',
1212
+ }, children: [columns.map((yAxisField, index) => ((0, jsx_runtime_1.jsx)("div", { style: {
1213
+ display: 'flex',
1214
+ flexDirection: 'row',
1215
+ alignItems: 'center',
1216
+ marginTop: index === 0 ? 6 : 10,
1217
+ }, children: (0, jsx_runtime_1.jsx)("div", { style: { minWidth: 200 }, children: (0, jsx_runtime_1.jsx)(SelectComponent, { value: yAxisField.field, onChange: option => {
1218
+ handleColumnFieldChange(index, option);
1219
+ }, 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
1220
  display: 'flex',
829
1221
  flexDirection: 'column',
830
1222
  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: {
1223
+ }, children: columns.map((yAxisField, index) => ((0, jsx_runtime_1.jsxs)("div", { style: {
1224
+ display: 'flex',
1225
+ flexDirection: 'row',
1226
+ alignItems: 'center',
1227
+ marginTop: index === 0 ? 6 : 10,
1228
+ }, 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 || {
1229
+ fontFamily: theme.fontFamily,
1230
+ color: theme.primaryTextColor,
1231
+ fontSize: theme.fontSize + 2,
1232
+ fontWeight: 600,
1233
+ // marginTop: 20,
1234
+ }, children: 'Filters' }), (0, jsx_runtime_1.jsx)("div", { style: { height: 8 } })] })), showDateFieldOptions && ((0, jsx_runtime_1.jsxs)("div", { style: {
850
1235
  display: 'flex',
851
1236
  flexDirection: 'row',
852
1237
  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,
1238
+ }, children: [(0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'column' }, children: [(0, jsx_runtime_1.jsx)("div", { style: formLabelStyle || {
855
1239
  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
1240
+ fontFamily: theme?.fontFamily,
1241
+ fontSize: theme?.fontSize || '14px',
1242
+ fontWeight: theme.labelFontWeight || '600',
1243
+ }, 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
1244
  ? [{ label: '', value: '' }]
860
1245
  : dateFieldOptions.map(elem => {
861
1246
  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,
1247
+ }), 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
1248
  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
1249
+ fontFamily: theme?.fontFamily,
1250
+ fontSize: theme?.fontSize || '14px',
1251
+ fontWeight: theme.labelFontWeight || '600',
1252
+ }, 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
1253
  ? [{ label: '', value: '' }]
869
- : dateFieldOptions.filter(elem => elem.name === values.dateFieldTable).length
1254
+ : dateFieldOptions.filter(elem => elem.name === dateFieldTable // Replace `values.dateFieldTable` with your state variable or prop
1255
+ ).length
870
1256
  ? dateFieldOptions
871
- .filter(elem => elem.name === values.dateFieldTable)[0]
1257
+ .filter(elem => elem.name === dateFieldTable)[0]
872
1258
  .columns.map(elem => {
873
1259
  return { label: elem.name, value: elem.name };
874
1260
  })
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 } })] }) }));
1261
+ : [{ label: '', value: '' }], onChange: value => setDateField(value), value: dateField, theme: theme }) })] })] })), showAccessControlOptions && ((0, jsx_runtime_1.jsxs)("div", { style: {
1262
+ display: 'flex',
1263
+ flexDirection: 'column',
1264
+ marginTop: 40,
1265
+ marginBottom: 40,
1266
+ }, children: [(0, jsx_runtime_1.jsx)("div", { style: {
1267
+ fontFamily: theme.fontFamily,
1268
+ color: theme.primaryTextColor,
1269
+ fontSize: theme.fontSize + 2,
1270
+ fontWeight: 600,
1271
+ }, children: 'Access Control' }), (0, jsx_runtime_1.jsx)("div", { style: { height: 12 } }), (0, jsx_runtime_1.jsxs)("div", { style: {
1272
+ padding: '1px',
1273
+ display: 'flex',
1274
+ flexDirection: 'row',
1275
+ fontSize: '14px',
1276
+ fontWeight: '500',
1277
+ height: '32px',
1278
+ width: '640px',
1279
+ color: '#212121',
1280
+ backgroundColor: 'rgba(33, 33, 33, 0.03)',
1281
+ borderRadius: '6px',
1282
+ }, children: [(0, jsx_runtime_1.jsx)("div", { onClick: () => {
1283
+ setSelectedTabIndex(0);
1284
+ setTemplate(false);
1285
+ }, style: {
1286
+ width: '100%',
1287
+ borderRadius: '6px',
1288
+ padding: '4px',
1289
+ fontSize: '14px',
1290
+ fontWeight: '500',
1291
+ display: 'flex',
1292
+ flexDirection: 'column',
1293
+ alignItems: 'center',
1294
+ justifyContent: 'center',
1295
+ cursor: 'pointer',
1296
+ borderColor: '#E7E7E7',
1297
+ borderWidth: selectedTabIndex === 0 ? 1 : 0,
1298
+ borderStyle: 'solid',
1299
+ color: selectedTabIndex === 0
1300
+ ? '#212121'
1301
+ : 'rgba(33, 33, 33, 0.3)',
1302
+ backgroundColor: selectedTabIndex === 0
1303
+ ? 'white'
1304
+ : 'rgba(255, 255, 255, 0.12)',
1305
+ boxShadow: selectedTabIndex === 0
1306
+ ? '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)'
1307
+ : undefined,
1308
+ outline: 'none', // focus:outline-none
1309
+ }, children: `This Organization${organizationName ? ` (${organizationName})` : ``}` }), (0, jsx_runtime_1.jsx)("div", { onClick: () => {
1310
+ setSelectedTabIndex(1);
1311
+ setTemplate(true);
1312
+ }, style: {
1313
+ width: '100%',
1314
+ borderRadius: '6px',
1315
+ padding: '4px',
1316
+ fontSize: '14px',
1317
+ fontWeight: '500',
1318
+ display: 'flex',
1319
+ flexDirection: 'column',
1320
+ alignItems: 'center',
1321
+ justifyContent: 'center',
1322
+ cursor: 'pointer',
1323
+ borderColor: '#E7E7E7',
1324
+ borderWidth: selectedTabIndex === 1 ? 1 : 0,
1325
+ borderStyle: 'solid',
1326
+ color: selectedTabIndex === 1
1327
+ ? '#212121'
1328
+ : 'rgba(33, 33, 33, 0.3)',
1329
+ backgroundColor: selectedTabIndex === 1
1330
+ ? 'white'
1331
+ : 'rgba(255, 255, 255, 0.12)',
1332
+ boxShadow: selectedTabIndex === 1
1333
+ ? '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)'
1334
+ : undefined,
1335
+ outline: 'none', // focus:outline-none
1336
+ }, children: 'Global (All Organizations)' })] })] })), (0, jsx_runtime_1.jsx)("div", { style: { paddingRight: 25 }, children: (0, jsx_runtime_1.jsx)(ButtonComponent, { onClick: () => {
1337
+ const { xAxisField, xAxisLabel, xAxisFormat, chartName, chartType, dashboardName, dateFieldTable, dateField, template, } = chartConfig;
1338
+ if (isSubmitting === false) {
1339
+ editChart({
1340
+ setIsSubmitting,
1341
+ report,
1342
+ values: {
1343
+ xAxisField,
1344
+ xAxisLabel,
1345
+ xAxisFormat,
1346
+ chartName,
1347
+ chartType,
1348
+ dashboardName,
1349
+ dateFieldTable,
1350
+ dateField,
1351
+ template,
1352
+ },
1353
+ yAxisFields,
1354
+ columns,
1355
+ query,
1356
+ buckets: bucketFields,
1357
+ showTableFormatOptions,
1358
+ });
1359
+ }
1360
+ }, label: report ? 'Save changes' : 'Add to dashboard' }) }), (0, jsx_runtime_1.jsx)("div", { style: { height: 20 } })] }) }));
876
1361
  }
877
1362
  //# sourceMappingURL=AddToDashboardModal.js.map