@quillsql/react 2.3.1 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/AddToDashboardModal.js +249 -150
- package/lib/AddToDashboardModal.js.map +1 -1
- package/lib/Chart.js +11 -7
- package/lib/Chart.js.map +1 -1
- package/lib/Context.js +5 -1
- package/lib/Context.js.map +1 -1
- package/lib/Dashboard.js +1 -0
- package/lib/Dashboard.js.map +1 -1
- package/lib/hooks/useQuill.js +1 -1
- package/lib/hooks/useQuill.js.map +1 -1
- package/lib/utils/aggregate.js +4 -29
- package/lib/utils/aggregate.js.map +1 -1
- package/package.json +1 -1
|
@@ -30,8 +30,9 @@ exports.formatDateBuckets = exports.isArrayOfValidDates = exports.isValidDate =
|
|
|
30
30
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
31
31
|
// @ts-nocheck
|
|
32
32
|
const react_1 = __importStar(require("react"));
|
|
33
|
-
const Context_1 = require("./Context");
|
|
34
33
|
const date_fns_1 = require("date-fns");
|
|
34
|
+
const Context_1 = require("./Context");
|
|
35
|
+
const date_fns_2 = require("date-fns");
|
|
35
36
|
const Chart_1 = __importDefault(require("./Chart"));
|
|
36
37
|
const ReportBuilder_1 = require("./ReportBuilder");
|
|
37
38
|
const aggregate_1 = require("./utils/aggregate");
|
|
@@ -186,42 +187,6 @@ function AddToDashboardModal({ isOpen, setIsOpen, SelectComponent, TextInputComp
|
|
|
186
187
|
isSubscribed = false;
|
|
187
188
|
};
|
|
188
189
|
}, [schema]);
|
|
189
|
-
// useEffect(() => {
|
|
190
|
-
// let isSubscribed = true;
|
|
191
|
-
// async function getCustomers() {
|
|
192
|
-
// const response = await fetch(
|
|
193
|
-
// `https://quill-344421.uc.r.appspot.com/orgs/${publicKey}/`,
|
|
194
|
-
// {
|
|
195
|
-
// method: 'GET',
|
|
196
|
-
// headers: {
|
|
197
|
-
// Authorization: 'Bearer ',
|
|
198
|
-
// environment: environment,
|
|
199
|
-
// },
|
|
200
|
-
// }
|
|
201
|
-
// );
|
|
202
|
-
// if (!response.ok) {
|
|
203
|
-
// throw new Error('Network response was not ok');
|
|
204
|
-
// }
|
|
205
|
-
// const data = await response.json();
|
|
206
|
-
// if (environment === 'STAGING') {
|
|
207
|
-
// setOrganization(
|
|
208
|
-
// response.data.orgs.filter(
|
|
209
|
-
// org => org.id === client.stagingAdminCustomerId
|
|
210
|
-
// )[0]
|
|
211
|
-
// );
|
|
212
|
-
// } else {
|
|
213
|
-
// setOrganization(
|
|
214
|
-
// data.orgs.filter(org => org.id === client.adminCustomerId)[0]
|
|
215
|
-
// );
|
|
216
|
-
// }
|
|
217
|
-
// }
|
|
218
|
-
// if (isSubscribed && environment && client) {
|
|
219
|
-
// getCustomers();
|
|
220
|
-
// }
|
|
221
|
-
// return () => {
|
|
222
|
-
// isSubscribed = false;
|
|
223
|
-
// };
|
|
224
|
-
// }, [environment, client]);
|
|
225
190
|
const editChart = async ({ report, setIsSubmitting, values, yAxisFields, columns, query, buckets, showTableFormatOptions, }) => {
|
|
226
191
|
const { publicKey, customerId, authToken, queryEndpoint, queryHeaders, withCredentials, environment, } = client;
|
|
227
192
|
const { xAxisLabel, chartName, chartType, xAxisField, xAxisFormat, dashboardName, dateFieldTable, dateField, template, } = values;
|
|
@@ -248,18 +213,12 @@ function AddToDashboardModal({ isOpen, setIsOpen, SelectComponent, TextInputComp
|
|
|
248
213
|
return;
|
|
249
214
|
}
|
|
250
215
|
if (!columns.map((yAxisField, _) => yAxisField.label).every(Boolean) &&
|
|
251
|
-
showTableFormatOptions
|
|
216
|
+
showTableFormatOptions &&
|
|
217
|
+
chartType !== 'table') {
|
|
252
218
|
alert('Please enter a label for the table y-axis');
|
|
253
219
|
return;
|
|
254
220
|
}
|
|
255
221
|
setIsSubmitting(true);
|
|
256
|
-
// const newYAxisFields = updateLabels(yAxisFields, values);
|
|
257
|
-
// for (let i = 0; i < newYAxisFields.length; i++) {
|
|
258
|
-
// if (!newYAxisFields[i].label && chartType !== 'pie') {
|
|
259
|
-
// alert(`Please enter a label for column '${newYAxisFields[i].field}'`);
|
|
260
|
-
// return;
|
|
261
|
-
// }
|
|
262
|
-
// }
|
|
263
222
|
if (!client || !customerId) {
|
|
264
223
|
return;
|
|
265
224
|
}
|
|
@@ -273,26 +232,6 @@ function AddToDashboardModal({ isOpen, setIsOpen, SelectComponent, TextInputComp
|
|
|
273
232
|
}
|
|
274
233
|
let responseData;
|
|
275
234
|
if (queryEndpoint) {
|
|
276
|
-
// response = await axios.post(
|
|
277
|
-
// queryEndpoint,
|
|
278
|
-
// {
|
|
279
|
-
// metadata: {
|
|
280
|
-
// name: chartName,
|
|
281
|
-
// xAxisField,
|
|
282
|
-
// yAxisFields,
|
|
283
|
-
// xAxisLabel,
|
|
284
|
-
// xAxisFormat,
|
|
285
|
-
// yAxisLabel,
|
|
286
|
-
// chartType,
|
|
287
|
-
// dashboardName,
|
|
288
|
-
// columns,
|
|
289
|
-
// dateField: { table: dateFieldTable, field: dateField },
|
|
290
|
-
// query: query,
|
|
291
|
-
// task: 'create',
|
|
292
|
-
// },
|
|
293
|
-
// },
|
|
294
|
-
// { headers: queryHeaders, withCredentials }
|
|
295
|
-
// );
|
|
296
235
|
const url = queryEndpoint;
|
|
297
236
|
const headers = {
|
|
298
237
|
'Content-Type': 'application/json',
|
|
@@ -339,14 +278,7 @@ function AddToDashboardModal({ isOpen, setIsOpen, SelectComponent, TextInputComp
|
|
|
339
278
|
dashboardName,
|
|
340
279
|
columns: showTableFormatOptions && chartType !== 'table'
|
|
341
280
|
? columns
|
|
342
|
-
: [
|
|
343
|
-
...yAxisFields,
|
|
344
|
-
{
|
|
345
|
-
field: xAxisField,
|
|
346
|
-
label: xAxisLabel,
|
|
347
|
-
format: xAxisFormat,
|
|
348
|
-
},
|
|
349
|
-
],
|
|
281
|
+
: [...yAxisFields],
|
|
350
282
|
dateField: showDateFieldOptions
|
|
351
283
|
? { table: dateFieldTable, field: dateField }
|
|
352
284
|
: defaultDateField,
|
|
@@ -405,28 +337,6 @@ function AddToDashboardModal({ isOpen, setIsOpen, SelectComponent, TextInputComp
|
|
|
405
337
|
}
|
|
406
338
|
}
|
|
407
339
|
else {
|
|
408
|
-
// response = await axios.post(
|
|
409
|
-
// `https://quill-344421.uc.r.appspot.com/dashedit/${publicKey}/${orgId}/`,
|
|
410
|
-
// {
|
|
411
|
-
// name: chartName,
|
|
412
|
-
// xAxisField,
|
|
413
|
-
// yAxisFields,
|
|
414
|
-
// xAxisLabel,
|
|
415
|
-
// xAxisFormat,
|
|
416
|
-
// yAxisLabel,
|
|
417
|
-
// chartType,
|
|
418
|
-
// dashboardName,
|
|
419
|
-
// columns,
|
|
420
|
-
// dateField: { table: dateFieldTable, field: dateField },
|
|
421
|
-
// query: query,
|
|
422
|
-
// },
|
|
423
|
-
// {
|
|
424
|
-
// headers: {
|
|
425
|
-
// Authorization: `Bearer ${authToken}`,
|
|
426
|
-
// environment: environment || undefined,
|
|
427
|
-
// },
|
|
428
|
-
// }
|
|
429
|
-
// );
|
|
430
340
|
const url = `https://quill-344421.uc.r.appspot.com/dashedit/${publicKey}/${customerId}/`;
|
|
431
341
|
const headers = {
|
|
432
342
|
'Content-Type': 'application/json',
|
|
@@ -518,17 +428,7 @@ function AddToDashboardModal({ isOpen, setIsOpen, SelectComponent, TextInputComp
|
|
|
518
428
|
if (!responseData) {
|
|
519
429
|
return;
|
|
520
430
|
}
|
|
521
|
-
// setDashboard((dashboard) => {
|
|
522
|
-
// return {
|
|
523
|
-
// ...dashboard,
|
|
524
|
-
// [response.data._id]: { ...existingVisualization, ...response.data }
|
|
525
|
-
// }
|
|
526
|
-
// })
|
|
527
|
-
// setIsOpen(false);
|
|
528
|
-
// TODO: fire callback instead so user can customize action
|
|
529
|
-
// navigate("/dashboards");
|
|
530
431
|
};
|
|
531
|
-
// console.log('report', report);
|
|
532
432
|
return (
|
|
533
433
|
// <BigModal theme={theme} showModal={isOpen} setShowModal={setIsOpen}>
|
|
534
434
|
(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,
|
|
@@ -706,50 +606,50 @@ const isArrayOfValidDates = (arr, field) => arr.every(d => new Date(d[field]) in
|
|
|
706
606
|
exports.isArrayOfValidDates = isArrayOfValidDates;
|
|
707
607
|
function formatDateBuckets(startDate, endDate) {
|
|
708
608
|
// Calculate the distance in hours
|
|
709
|
-
const distanceInHours = Math.abs((0,
|
|
609
|
+
const distanceInHours = Math.abs((0, date_fns_2.differenceInHours)(endDate, startDate));
|
|
710
610
|
// Check if the distance is less than or equal to one hour
|
|
711
611
|
if (distanceInHours <= 1) {
|
|
712
612
|
return {
|
|
713
613
|
unit: 'hour',
|
|
714
614
|
format: 'h a',
|
|
715
|
-
startOf:
|
|
615
|
+
startOf: date_fns_2.startOfHour,
|
|
716
616
|
};
|
|
717
617
|
}
|
|
718
618
|
// Calculate the distance in days
|
|
719
|
-
const distanceInDays = Math.abs((0,
|
|
619
|
+
const distanceInDays = Math.abs((0, date_fns_2.differenceInDays)(endDate, startDate));
|
|
720
620
|
// Check if the distance is less than or equal to one day
|
|
721
621
|
if (distanceInDays <= 1) {
|
|
722
622
|
return {
|
|
723
623
|
unit: 'day',
|
|
724
624
|
format: 'MMM d',
|
|
725
|
-
startOf:
|
|
625
|
+
startOf: date_fns_2.startOfDay,
|
|
726
626
|
};
|
|
727
627
|
}
|
|
728
628
|
// Calculate the distance in months
|
|
729
|
-
const distanceInMonths = Math.abs((0,
|
|
629
|
+
const distanceInMonths = Math.abs((0, date_fns_2.differenceInMonths)(endDate, startDate));
|
|
730
630
|
// Check if the distance is less than or equal to one month
|
|
731
631
|
if (distanceInMonths <= 1) {
|
|
732
632
|
return {
|
|
733
633
|
unit: 'month',
|
|
734
634
|
format: 'MMM yyyy',
|
|
735
|
-
startOf:
|
|
635
|
+
startOf: date_fns_2.startOfMonth,
|
|
736
636
|
};
|
|
737
637
|
}
|
|
738
638
|
// Calculate the distance in years
|
|
739
|
-
const distanceInYears = Math.abs((0,
|
|
639
|
+
const distanceInYears = Math.abs((0, date_fns_2.differenceInYears)(endDate, startDate));
|
|
740
640
|
// Check if the distance is less than or equal to one year
|
|
741
641
|
if (distanceInYears <= 1) {
|
|
742
642
|
return {
|
|
743
643
|
unit: 'year',
|
|
744
644
|
format: 'yyyy',
|
|
745
|
-
startOf:
|
|
645
|
+
startOf: date_fns_2.startOfYear,
|
|
746
646
|
};
|
|
747
647
|
}
|
|
748
648
|
// Otherwise, the distance is more than one year
|
|
749
649
|
return {
|
|
750
650
|
unit: 'year',
|
|
751
651
|
format: 'yyyy',
|
|
752
|
-
startOf:
|
|
652
|
+
startOf: date_fns_2.startOfYear,
|
|
753
653
|
};
|
|
754
654
|
}
|
|
755
655
|
exports.formatDateBuckets = formatDateBuckets;
|
|
@@ -826,7 +726,6 @@ const Y_FORMAT_OPTIONS = [
|
|
|
826
726
|
{ value: 'string', label: 'string' },
|
|
827
727
|
];
|
|
828
728
|
const handleBucketData = (dashboardItem, bucketFields, dateFilter) => {
|
|
829
|
-
const result = (0, aggregate_1.aggregate)(dashboardItem, bucketFields, dateFilter);
|
|
830
729
|
return (0, aggregate_1.aggregate)(dashboardItem, bucketFields, dateFilter);
|
|
831
730
|
};
|
|
832
731
|
function FormikForm({ data, xAxisOptions, yAxisOptions, fieldOptions, dateFieldOptions, theme, report, editChart, fields, newFields, query, client, SelectComponent, TextInputComponent, ButtonComponent, SecondaryButtonComponent, organizationName, formHeaderStyle, formLabelStyle, showTableFormatOptions, showDateFieldOptions, showAccessControlOptions, }) {
|
|
@@ -835,6 +734,14 @@ function FormikForm({ data, xAxisOptions, yAxisOptions, fieldOptions, dateFieldO
|
|
|
835
734
|
// if (b.value === 'created_at') return 1;
|
|
836
735
|
// return 0;
|
|
837
736
|
// });
|
|
737
|
+
function postgresFormatMap(postgresType) {
|
|
738
|
+
if (postgresType === 'string')
|
|
739
|
+
return 'string';
|
|
740
|
+
if (postgresType === 'number')
|
|
741
|
+
return 'whole_number';
|
|
742
|
+
if (postgresType === 'date')
|
|
743
|
+
return 'dynamic';
|
|
744
|
+
}
|
|
838
745
|
X_FORMAT_OPTIONS.sort((a, b) => {
|
|
839
746
|
if (a.value === 'dynamic')
|
|
840
747
|
return -1;
|
|
@@ -842,6 +749,7 @@ function FormikForm({ data, xAxisOptions, yAxisOptions, fieldOptions, dateFieldO
|
|
|
842
749
|
return 1;
|
|
843
750
|
return 0;
|
|
844
751
|
});
|
|
752
|
+
const { dashboardFilters, dashboardFiltersDispatch } = (0, react_1.useContext)(Context_1.DashboardFiltersContext);
|
|
845
753
|
const [rows, setRows] = (0, react_1.useState)(null);
|
|
846
754
|
const [isSubmitting, setIsSubmitting] = (0, react_1.useState)(false);
|
|
847
755
|
const { environment } = client;
|
|
@@ -854,7 +762,7 @@ function FormikForm({ data, xAxisOptions, yAxisOptions, fieldOptions, dateFieldO
|
|
|
854
762
|
const [dateField, setDateField] = (0, react_1.useState)((dateFieldOptions.length && dateFieldOptions[0].columns[0].name) || '');
|
|
855
763
|
const [template, setTemplate] = (0, react_1.useState)(report?.template || false);
|
|
856
764
|
const [chartConfig, setChartConfig] = (0, react_1.useState)({});
|
|
857
|
-
const { dateFilter } = (0, react_1.useContext)(Context_1.DateFilterContext);
|
|
765
|
+
const { dateFilter, setDateFilter } = (0, react_1.useContext)(Context_1.DateFilterContext);
|
|
858
766
|
const [yAxisFields, setYAxisFields] = (0, react_1.useState)(report
|
|
859
767
|
? report.yAxisFields
|
|
860
768
|
: [
|
|
@@ -872,6 +780,49 @@ function FormikForm({ data, xAxisOptions, yAxisOptions, fieldOptions, dateFieldO
|
|
|
872
780
|
: fields?.length
|
|
873
781
|
? fields.map(field => convertPostgresColumn(field))
|
|
874
782
|
: []);
|
|
783
|
+
function removeQuotes(str) {
|
|
784
|
+
if (str.startsWith('"') && str.endsWith('"')) {
|
|
785
|
+
return str.slice(1, -1);
|
|
786
|
+
}
|
|
787
|
+
else {
|
|
788
|
+
return str;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
const processFilter = (filter, value = null) => {
|
|
792
|
+
//for dateObjects only, since values are arrays for dateObjects
|
|
793
|
+
const { selectedValue: _, ...filterWithoutSelectedValue } = filter; // _ is a throwaway variable
|
|
794
|
+
let selectedValue;
|
|
795
|
+
let selectedElem;
|
|
796
|
+
if (filter.filterType === 'string') {
|
|
797
|
+
selectedElem = filter.options.find(elem => elem[removeQuotes(filter.field)] === value);
|
|
798
|
+
if (selectedElem) {
|
|
799
|
+
selectedValue = selectedElem[removeQuotes(filter.field)];
|
|
800
|
+
}
|
|
801
|
+
return {
|
|
802
|
+
...filterWithoutSelectedValue,
|
|
803
|
+
...(selectedValue ? { selectedValue } : {}),
|
|
804
|
+
};
|
|
805
|
+
}
|
|
806
|
+
if (filter.filterType === 'date' || filter.filterType === 'date_range') {
|
|
807
|
+
if (value[2]) {
|
|
808
|
+
selectedElem = filter.options.find(elem => {
|
|
809
|
+
return value[2] === elem[removeQuotes(filter.field)][2];
|
|
810
|
+
});
|
|
811
|
+
if (selectedElem) {
|
|
812
|
+
selectedValue = selectedElem[removeQuotes(filter.field)];
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
return {
|
|
816
|
+
startDate: value ? value[0] : filter.startDate,
|
|
817
|
+
endDate: value ? value[1] : filter.endDate,
|
|
818
|
+
filterType: 'date_range',
|
|
819
|
+
...(selectedValue ? { selectedValue } : {}),
|
|
820
|
+
field: 'date_range',
|
|
821
|
+
options: options,
|
|
822
|
+
label: 'Date',
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
};
|
|
875
826
|
const handleAddYAxisField = () => {
|
|
876
827
|
setYAxisFields([
|
|
877
828
|
...yAxisFields,
|
|
@@ -879,9 +830,7 @@ function FormikForm({ data, xAxisOptions, yAxisOptions, fieldOptions, dateFieldO
|
|
|
879
830
|
]);
|
|
880
831
|
};
|
|
881
832
|
const handleAddBucket = () => {
|
|
882
|
-
const bucketPossibilities = xAxisOptions.filter(option =>
|
|
883
|
-
// whatIsProbablyTheType(data.slice(0, 10), option.value) === 'date'
|
|
884
|
-
(0, ReportBuilder_1.getPostgresBasicType)(newFields.find(field => field.name === option.value)) === 'date');
|
|
833
|
+
const bucketPossibilities = xAxisOptions.filter(option => (0, ReportBuilder_1.getPostgresBasicType)(newFields.find(field => field.name === option.value)) === 'date');
|
|
885
834
|
if (!bucketPossibilities.length) {
|
|
886
835
|
alert('No possible buckets');
|
|
887
836
|
return;
|
|
@@ -897,9 +846,7 @@ function FormikForm({ data, xAxisOptions, yAxisOptions, fieldOptions, dateFieldO
|
|
|
897
846
|
setXAxisFormat('dynamic');
|
|
898
847
|
}
|
|
899
848
|
else {
|
|
900
|
-
setXAxisFormat(
|
|
901
|
-
// whatIsProbablyTheType(data.slice(0, 10), bucketPossibilities[0].value)
|
|
902
|
-
(0, ReportBuilder_1.getPostgresBasicType)(newFields.find(field => field.name === bucketPossibilities[0].value)));
|
|
849
|
+
setXAxisFormat(postgresFormatMap((0, ReportBuilder_1.getPostgresBasicType)(newFields.find(field => field.name === bucketPossibilities[0].value))));
|
|
903
850
|
}
|
|
904
851
|
};
|
|
905
852
|
const [dashboardOptions, setDashboardOptions] = (0, react_1.useState)([]);
|
|
@@ -914,12 +861,165 @@ function FormikForm({ data, xAxisOptions, yAxisOptions, fieldOptions, dateFieldO
|
|
|
914
861
|
dateFieldTable,
|
|
915
862
|
dateField,
|
|
916
863
|
};
|
|
917
|
-
const [selectedTabIndex, setSelectedTabIndex] = (0, react_1.useState)(
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
864
|
+
const [selectedTabIndex, setSelectedTabIndex] = (0, react_1.useState)(report && report.template ? 1 : 0);
|
|
865
|
+
react_1.default.useEffect(() => {
|
|
866
|
+
async function getDashboards() {
|
|
867
|
+
const { publicKey, customerId, environment, queryEndpoint, queryHeaders, withCredentials, } = client;
|
|
868
|
+
if (customerId || queryEndpoint) {
|
|
869
|
+
try {
|
|
870
|
+
let responseData;
|
|
871
|
+
if (queryEndpoint) {
|
|
872
|
+
const response = await fetch(queryEndpoint, {
|
|
873
|
+
method: 'POST',
|
|
874
|
+
headers: {
|
|
875
|
+
...queryHeaders,
|
|
876
|
+
'Content-Type': 'application/json',
|
|
877
|
+
},
|
|
878
|
+
body: JSON.stringify({
|
|
879
|
+
metadata: customerId
|
|
880
|
+
? { orgId: customerId, name, task: 'config' }
|
|
881
|
+
: { name: dashboardName, task: 'config' },
|
|
882
|
+
}),
|
|
883
|
+
credentials: withCredentials ? 'include' : 'omit', // If withCredentials is true, set to 'include'. Otherwise, set to 'omit'.
|
|
884
|
+
});
|
|
885
|
+
responseData = await response.json(); // If the server returns JSON data
|
|
886
|
+
}
|
|
887
|
+
else {
|
|
888
|
+
const url = new URL('https://quill-344421.uc.r.appspot.com/dashconfig');
|
|
889
|
+
// Add query parameters to the URL
|
|
890
|
+
url.search = new URLSearchParams({
|
|
891
|
+
publicKey: publicKey,
|
|
892
|
+
orgId: customerId,
|
|
893
|
+
name: dashboardName,
|
|
894
|
+
}).toString();
|
|
895
|
+
const response = await fetch(url, {
|
|
896
|
+
method: 'GET',
|
|
897
|
+
headers: {
|
|
898
|
+
environment: environment || undefined,
|
|
899
|
+
},
|
|
900
|
+
});
|
|
901
|
+
responseData = await response.json();
|
|
902
|
+
}
|
|
903
|
+
const bigFilterObj = {};
|
|
904
|
+
if (responseData.dateFilter &&
|
|
905
|
+
Object.keys(responseData.dateFilter).length) {
|
|
906
|
+
if (responseData.dateFilter.initialRange === 'LAST_90_DAYS') {
|
|
907
|
+
const filter = {
|
|
908
|
+
startDate: (0, date_fns_1.sub)((0, date_fns_1.startOfToday)(), { days: 90 }),
|
|
909
|
+
endDate: new Date(),
|
|
910
|
+
filterType: 'date_range',
|
|
911
|
+
selectedValue: [
|
|
912
|
+
(0, date_fns_1.sub)((0, date_fns_1.startOfToday)(), { days: 90 }),
|
|
913
|
+
new Date(),
|
|
914
|
+
'90d',
|
|
915
|
+
],
|
|
916
|
+
field: 'date_range',
|
|
917
|
+
label: 'Date',
|
|
918
|
+
};
|
|
919
|
+
dashboardFiltersDispatch({
|
|
920
|
+
type: 'ADD_DASHBOARD_FILTER',
|
|
921
|
+
id: 'date_range',
|
|
922
|
+
data: {
|
|
923
|
+
...filter,
|
|
924
|
+
},
|
|
925
|
+
});
|
|
926
|
+
setDateFilter(filter);
|
|
927
|
+
bigFilterObj[filter.field] = filter;
|
|
928
|
+
}
|
|
929
|
+
else if (responseData.dateFilter.initialRange === 'LAST_30_DAYS') {
|
|
930
|
+
const filter = {
|
|
931
|
+
startDate: (0, date_fns_1.sub)((0, date_fns_1.startOfToday)(), { days: 30 }),
|
|
932
|
+
endDate: new Date(),
|
|
933
|
+
filterType: 'date_range',
|
|
934
|
+
selectedValue: [
|
|
935
|
+
(0, date_fns_1.sub)((0, date_fns_1.startOfToday)(), { days: 30 }),
|
|
936
|
+
new Date(),
|
|
937
|
+
't',
|
|
938
|
+
],
|
|
939
|
+
options: options,
|
|
940
|
+
field: 'date_range',
|
|
941
|
+
label: 'Date',
|
|
942
|
+
};
|
|
943
|
+
dashboardFiltersDispatch({
|
|
944
|
+
type: 'ADD_DASHBOARD_FILTER',
|
|
945
|
+
id: 'date_range',
|
|
946
|
+
data: {
|
|
947
|
+
...filter,
|
|
948
|
+
},
|
|
949
|
+
});
|
|
950
|
+
setDateFilter(filter);
|
|
951
|
+
bigFilterObj[filter.field] = filter;
|
|
952
|
+
// return;
|
|
953
|
+
}
|
|
954
|
+
else if (responseData.dateFilter.initialRange === 'CURRENT_MONTH') {
|
|
955
|
+
const filter = {
|
|
956
|
+
startDate: (0, date_fns_2.startOfMonth)(new Date()),
|
|
957
|
+
endDate: new Date(),
|
|
958
|
+
filterType: 'date_range',
|
|
959
|
+
selectedValue: [(0, date_fns_2.startOfMonth)(new Date()), new Date(), 'm'],
|
|
960
|
+
options: options,
|
|
961
|
+
field: 'date_range',
|
|
962
|
+
label: 'Date',
|
|
963
|
+
};
|
|
964
|
+
dashboardFiltersDispatch({
|
|
965
|
+
type: 'ADD_DASHBOARD_FILTER',
|
|
966
|
+
id: 'date_range',
|
|
967
|
+
data: {
|
|
968
|
+
...filter,
|
|
969
|
+
},
|
|
970
|
+
});
|
|
971
|
+
setDateFilter(filter);
|
|
972
|
+
bigFilterObj[filter.field] = filter;
|
|
973
|
+
}
|
|
974
|
+
else {
|
|
975
|
+
const filter = {
|
|
976
|
+
startDate: (0, date_fns_1.sub)((0, date_fns_1.startOfToday)(), { days: 90 }),
|
|
977
|
+
endDate: new Date(),
|
|
978
|
+
filterType: 'date_range',
|
|
979
|
+
selectedValue: [
|
|
980
|
+
(0, date_fns_1.sub)((0, date_fns_1.startOfToday)(), { days: 90 }),
|
|
981
|
+
new Date(),
|
|
982
|
+
'90d',
|
|
983
|
+
],
|
|
984
|
+
options: options,
|
|
985
|
+
field: 'date_range',
|
|
986
|
+
label: 'Date',
|
|
987
|
+
};
|
|
988
|
+
dashboardFiltersDispatch({
|
|
989
|
+
type: 'ADD_DASHBOARD_FILTER',
|
|
990
|
+
id: 'date_range',
|
|
991
|
+
data: {
|
|
992
|
+
...filter,
|
|
993
|
+
},
|
|
994
|
+
});
|
|
995
|
+
setDateFilter(filter);
|
|
996
|
+
bigFilterObj[filter.field] = filter;
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
if (responseData.filters && responseData.filters.length) {
|
|
1000
|
+
Object.values(responseData.filters)
|
|
1001
|
+
.filter(filter => filter.filterType !== 'date')
|
|
1002
|
+
.forEach(filter => {
|
|
1003
|
+
// processFilter(filter);
|
|
1004
|
+
bigFilterObj[filter.field] = processFilter(filter);
|
|
1005
|
+
});
|
|
1006
|
+
}
|
|
1007
|
+
dashboardFiltersDispatch({
|
|
1008
|
+
type: 'ADD_DASHBOARD_FILTERS',
|
|
1009
|
+
id: 'tons',
|
|
1010
|
+
data: bigFilterObj,
|
|
1011
|
+
});
|
|
1012
|
+
if (!responseData.dateFilter) {
|
|
1013
|
+
setDateFilter(null);
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
catch (error) {
|
|
1017
|
+
console.error('Error fetching data:', error);
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
921
1020
|
}
|
|
922
|
-
|
|
1021
|
+
getDashboards();
|
|
1022
|
+
}, [dashboardName, client]);
|
|
923
1023
|
(0, react_1.useEffect)(() => {
|
|
924
1024
|
async function getDashNames() {
|
|
925
1025
|
const response2 = await fetch(`https://quill-344421.uc.r.appspot.com/dashnames/${client.publicKey}/`, {
|
|
@@ -980,9 +1080,7 @@ function FormikForm({ data, xAxisOptions, yAxisOptions, fieldOptions, dateFieldO
|
|
|
980
1080
|
setXAxisFormat('dynamic');
|
|
981
1081
|
}
|
|
982
1082
|
else {
|
|
983
|
-
setXAxisFormat(
|
|
984
|
-
// whatIsProbablyTheType(data.slice(0, 10), value)
|
|
985
|
-
(0, ReportBuilder_1.getPostgresBasicType)(newFields.find(field => field.name === value)));
|
|
1083
|
+
setXAxisFormat(postgresFormatMap((0, ReportBuilder_1.getPostgresBasicType)(newFields.find(field => field.name === value))));
|
|
986
1084
|
}
|
|
987
1085
|
};
|
|
988
1086
|
const handleXAxisFieldChange = value => {
|
|
@@ -1000,9 +1098,7 @@ function FormikForm({ data, xAxisOptions, yAxisOptions, fieldOptions, dateFieldO
|
|
|
1000
1098
|
setXAxisFormat('dynamic');
|
|
1001
1099
|
}
|
|
1002
1100
|
else {
|
|
1003
|
-
setXAxisFormat(
|
|
1004
|
-
// whatIsProbablyTheType(data.slice(0, 10), value)
|
|
1005
|
-
(0, ReportBuilder_1.getPostgresBasicType)(newFields.find(field => field.name === value)));
|
|
1101
|
+
setXAxisFormat(postgresFormatMap((0, ReportBuilder_1.getPostgresBasicType)(newFields.find(field => field.name === value))));
|
|
1006
1102
|
}
|
|
1007
1103
|
if (bucketFields.length > 0) {
|
|
1008
1104
|
const newBucketFields = [...bucketFields];
|
|
@@ -1015,8 +1111,7 @@ function FormikForm({ data, xAxisOptions, yAxisOptions, fieldOptions, dateFieldO
|
|
|
1015
1111
|
newYAxisFields[index] = {
|
|
1016
1112
|
...newYAxisFields[index],
|
|
1017
1113
|
field: value,
|
|
1018
|
-
|
|
1019
|
-
format: (0, ReportBuilder_1.getPostgresBasicType)(newFields.find(field => field.name === value)),
|
|
1114
|
+
format: postgresFormatMap(newFields.find(field => field.name === value)),
|
|
1020
1115
|
};
|
|
1021
1116
|
setYAxisFields(newYAxisFields);
|
|
1022
1117
|
};
|
|
@@ -1047,21 +1142,24 @@ function FormikForm({ data, xAxisOptions, yAxisOptions, fieldOptions, dateFieldO
|
|
|
1047
1142
|
};
|
|
1048
1143
|
(0, react_1.useEffect)(() => {
|
|
1049
1144
|
const now = new Date();
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1145
|
+
if (!dateFilter ||
|
|
1146
|
+
(dateFilter && dateFilter.startDate && dateFilter.endDate)) {
|
|
1147
|
+
setChartConfig(handleBucketData({
|
|
1148
|
+
xAxisField,
|
|
1149
|
+
xAxisLabel,
|
|
1150
|
+
xAxisFormat,
|
|
1151
|
+
chartName,
|
|
1152
|
+
chartType,
|
|
1153
|
+
dashboardName,
|
|
1154
|
+
dateFieldTable,
|
|
1155
|
+
dateField,
|
|
1156
|
+
template,
|
|
1157
|
+
yAxisFields: yAxisFields,
|
|
1158
|
+
rows: data,
|
|
1159
|
+
fields: newFields,
|
|
1160
|
+
columns: columns,
|
|
1161
|
+
}, bucketFields, dateFilter));
|
|
1162
|
+
}
|
|
1065
1163
|
}, [
|
|
1066
1164
|
xAxisField,
|
|
1067
1165
|
xAxisLabel,
|
|
@@ -1075,6 +1173,7 @@ function FormikForm({ data, xAxisOptions, yAxisOptions, fieldOptions, dateFieldO
|
|
|
1075
1173
|
yAxisFields,
|
|
1076
1174
|
bucketFields,
|
|
1077
1175
|
columns,
|
|
1176
|
+
dateFilter,
|
|
1078
1177
|
]);
|
|
1079
1178
|
return ((0, jsx_runtime_1.jsx)("div", { style: { display: 'inline-block' }, children: (0, jsx_runtime_1.jsxs)("div", { style: {
|
|
1080
1179
|
display: 'flex',
|