@quillsql/react 2.10.17 → 2.10.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/cjs/ChartEditor.d.ts.map +1 -1
  2. package/dist/cjs/Dashboard.d.ts +24 -16
  3. package/dist/cjs/Dashboard.d.ts.map +1 -1
  4. package/dist/cjs/Dashboard.js +88 -478
  5. package/dist/cjs/DateRangePicker/QuillDateRangePicker.d.ts +3 -0
  6. package/dist/cjs/DateRangePicker/QuillDateRangePicker.d.ts.map +1 -0
  7. package/dist/cjs/DateRangePicker/QuillDateRangePicker.js +260 -0
  8. package/dist/cjs/DateRangePicker/dateRangePickerUtils.d.ts +20 -1
  9. package/dist/cjs/DateRangePicker/dateRangePickerUtils.d.ts.map +1 -1
  10. package/dist/cjs/DateRangePicker/dateRangePickerUtils.js +93 -4
  11. package/dist/cjs/QuillProvider.d.ts +1 -0
  12. package/dist/cjs/QuillProvider.d.ts.map +1 -1
  13. package/dist/cjs/QuillProvider.js +1 -0
  14. package/dist/cjs/ReportBuilder.d.ts.map +1 -1
  15. package/dist/cjs/ReportBuilder.js +1 -2
  16. package/dist/cjs/components/Dashboard/ChartComponent.js +1 -1
  17. package/dist/cjs/components/Dashboard/DashboardSection.js +1 -1
  18. package/dist/cjs/components/Dashboard/MetricComponent.js +1 -1
  19. package/dist/cjs/components/Dashboard/TableComponent.js +1 -1
  20. package/dist/cjs/components/QuillSelect.d.ts +3 -0
  21. package/dist/cjs/components/QuillSelect.d.ts.map +1 -0
  22. package/dist/cjs/components/QuillSelect.js +128 -0
  23. package/dist/cjs/components/UiComponents.d.ts +1 -0
  24. package/dist/cjs/components/UiComponents.d.ts.map +1 -1
  25. package/dist/cjs/index.d.ts +0 -1
  26. package/dist/cjs/index.d.ts.map +1 -1
  27. package/dist/cjs/index.js +1 -3
  28. package/dist/cjs/internals/ReportBuilder/PivotModal.d.ts.map +1 -1
  29. package/dist/cjs/internals/ReportBuilder/PivotModal.js +9 -0
  30. package/dist/cjs/utils/aggregate.js +2 -2
  31. package/dist/esm/ChartEditor.d.ts.map +1 -1
  32. package/dist/esm/Dashboard.d.ts +24 -16
  33. package/dist/esm/Dashboard.d.ts.map +1 -1
  34. package/dist/esm/Dashboard.js +86 -475
  35. package/dist/esm/DateRangePicker/QuillDateRangePicker.d.ts +3 -0
  36. package/dist/esm/DateRangePicker/QuillDateRangePicker.d.ts.map +1 -0
  37. package/dist/esm/DateRangePicker/QuillDateRangePicker.js +256 -0
  38. package/dist/esm/DateRangePicker/dateRangePickerUtils.d.ts +20 -1
  39. package/dist/esm/DateRangePicker/dateRangePickerUtils.d.ts.map +1 -1
  40. package/dist/esm/DateRangePicker/dateRangePickerUtils.js +91 -3
  41. package/dist/esm/QuillProvider.d.ts +1 -0
  42. package/dist/esm/QuillProvider.d.ts.map +1 -1
  43. package/dist/esm/QuillProvider.js +1 -0
  44. package/dist/esm/ReportBuilder.d.ts.map +1 -1
  45. package/dist/esm/ReportBuilder.js +0 -1
  46. package/dist/esm/components/Dashboard/ChartComponent.js +1 -1
  47. package/dist/esm/components/Dashboard/DashboardSection.js +1 -1
  48. package/dist/esm/components/Dashboard/MetricComponent.js +1 -1
  49. package/dist/esm/components/Dashboard/TableComponent.js +1 -1
  50. package/dist/esm/components/QuillSelect.d.ts +3 -0
  51. package/dist/esm/components/QuillSelect.d.ts.map +1 -0
  52. package/dist/esm/components/QuillSelect.js +124 -0
  53. package/dist/esm/components/UiComponents.d.ts +1 -0
  54. package/dist/esm/components/UiComponents.d.ts.map +1 -1
  55. package/dist/esm/index.d.ts +0 -1
  56. package/dist/esm/index.d.ts.map +1 -1
  57. package/dist/esm/index.js +0 -1
  58. package/dist/esm/internals/ReportBuilder/PivotModal.d.ts.map +1 -1
  59. package/dist/esm/internals/ReportBuilder/PivotModal.js +10 -1
  60. package/dist/esm/utils/aggregate.js +1 -1
  61. package/package.json +1 -1
  62. package/dist/cjs/AddToDashboardModal.d.ts +0 -82
  63. package/dist/cjs/AddToDashboardModal.d.ts.map +0 -1
  64. package/dist/cjs/AddToDashboardModal.js +0 -1469
  65. package/dist/esm/AddToDashboardModal.d.ts +0 -82
  66. package/dist/esm/AddToDashboardModal.d.ts.map +0 -1
  67. package/dist/esm/AddToDashboardModal.js +0 -1435
@@ -1,12 +1,9 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useContext, useEffect, useState, useRef, useCallback, memo, } from 'react';
2
+ import { useContext, useEffect, useState, useCallback, memo, } from 'react';
3
3
  import Chart from './Chart';
4
- import { capitalize, defaultOptions, getWeekdays, getRangeFromPreset, PRIMARY_RANGE, COMPARISON_RANGE, PRIMARY_CODES, } from './DateRangePicker/dateRangePickerUtils';
4
+ import { PRIMARY_RANGE, COMPARISON_RANGE, defaultOptionsV2, COMPARISON_OPTIONS, getRangeFromPresetOptions, } from './DateRangePicker/dateRangePickerUtils';
5
5
  import { ClientContext, DashboardContext, ThemeContext, DashboardFiltersContext, DateFilterContext, useComparisonRange, useDateFilter, } from './Context';
6
- import { addDays, eachDayOfInterval, endOfMonth, format, isAfter, isBefore, isEqual, isSaturday, isSunday, nextSaturday, previousSunday, startOfMonth, startOfToday, startOfWeek, startOfYear, sub, subDays, } from 'date-fns';
7
- import { ArrowDownHeadIcon, ArrowLeftHeadIcon, ArrowRightHeadIcon, CalendarNormalIcon, } from './assets';
8
- import { useOnClickOutside } from './hooks';
9
- import { enUS } from 'date-fns/locale';
6
+ import { ArrowDownHeadIcon } from './assets';
10
7
  import { useDashboard } from './hooks/useDashboard';
11
8
  import { hashCode } from './utils/crypto';
12
9
  import DashboardSectionContainer from './components/Dashboard/DashboardSectionContainer';
@@ -16,69 +13,19 @@ import QuillChartComponent from './components/Dashboard/ChartComponent';
16
13
  import DashboardSection from './components/Dashboard/DashboardSection';
17
14
  import { styleToProps } from './utils/styles';
18
15
  import { cleanDashboardItem } from './utils/dashboard';
16
+ import { QuillDateRangePicker } from './DateRangePicker/QuillDateRangePicker';
19
17
  import DataLoader from './components/Dashboard/DataLoader';
20
- export const COMPARISON_OPTIONS = [
21
- {
22
- value: 'PREV_PERIOD',
23
- text: 'Previous Period',
24
- },
25
- {
26
- value: 'PREV_7_DAYS',
27
- text: 'Previous 7 days',
28
- },
29
- {
30
- value: 'PREV_30_DAYS',
31
- text: 'Previous 30 days',
32
- },
33
- {
34
- value: 'PREV_90_DAYS',
35
- text: 'Previous 90 days',
36
- },
37
- {
38
- value: 'NO_COMPARISON',
39
- text: 'No comparison',
40
- },
41
- ];
42
- export const PRIMARY_OPTIONS = [
43
- { value: 'THIS_WEEK', text: 'This Week' },
44
- { value: 'THIS_MONTH', text: 'This Month' },
45
- { value: 'THIS_YEAR', text: 'This year' },
46
- { value: 'LAST_7_DAYS', text: 'Last 7 days' },
47
- { value: 'LAST_30_DAYS', text: 'Last 30 days' },
48
- { value: 'LAST_90_DAYS', text: 'Last 90 days' },
49
- { value: 'LAST_6_MONTHS', text: 'Last 6 months' },
50
- { value: 'ALL_TIME', text: 'All time' },
51
- ];
52
- const FILTER_CODE_MAP = {
53
- wk: 'This week',
54
- m: 'This month',
55
- y: 'This year',
56
- w: 'Last 7 days',
57
- t: 'Last 30 days',
58
- '90d': 'Last 90 days',
59
- '6m': 'Last 6 months',
60
- at: 'All time',
61
- };
18
+ import { QuillSelectComponent } from './components/QuillSelect';
62
19
  export function DashboardFilter({ filter, onChangeFilter, SelectComponent, DateRangePickerComponent, theme, }) {
63
20
  const { comparisonRange, setComparisonRange } = useComparisonRange();
64
21
  const { setDateFilter } = useDateFilter();
65
22
  const [filterValue, setFilterValue] = useState(null);
66
23
  useEffect(() => {
67
- if (filter.filterType === 'date_range' &&
68
- !filter.selectedValue &&
69
- !filterValue) {
70
- setFilterValue([filter.startDate, filter.endDate, null]);
71
- }
72
- else if (filter.filterType === 'date_range' && !filterValue) {
73
- setFilterValue(filter.selectedValue);
74
- }
75
- else if (filter.filterType === 'string') {
24
+ if (filter.filterType === 'string') {
76
25
  setFilterValue(filter.selectedValue);
77
26
  }
78
27
  if (filter.filterType == 'date_range') {
79
- setDateFilter(filter.selectedValue
80
- ? FILTER_CODE_MAP[filter.selectedValue[2]]
81
- : null);
28
+ setDateFilter(filter.preset.label);
82
29
  if (filter?.comparisonRange?.value) {
83
30
  const newComparisonRange = COMPARISON_OPTIONS.find((option) => {
84
31
  return option.value === filter.comparisonRange.value;
@@ -91,7 +38,7 @@ export function DashboardFilter({ filter, onChangeFilter, SelectComponent, DateR
91
38
  }
92
39
  }, [filter]);
93
40
  if (filter.filterType === 'string') {
94
- return (_jsx(SelectComponent, { label: filter.label, value: filterValue, onChange: (e) => {
41
+ return (_jsx(QuillSelectComponent, { theme: theme, label: filter.label, value: filterValue, onChange: (e) => {
95
42
  onChangeFilter(filter, e);
96
43
  }, options: [
97
44
  ...filter.options.map((elem) => {
@@ -107,31 +54,16 @@ export function DashboardFilter({ filter, onChangeFilter, SelectComponent, DateR
107
54
  display: 'flex',
108
55
  flexDirection: 'row',
109
56
  alignItems: 'flex-end',
110
- }, children: [_jsx(DateRangePickerComponent, { dateRange: filterValue ? [filterValue[0], filterValue[1]] : [null, null], label: filter.label,
111
- // value={filterValue}
112
- onChangeDateRange: (dateRange) => {
113
- onChangeFilter(filter, [dateRange[0], dateRange[1], null]);
114
- setFilterValue([dateRange[0], dateRange[1], null]);
115
- }, preset: filterValue && filterValue.length === 3 && filterValue[2] !== null
116
- ? filterValue[2]
117
- : '', onChangePreset: (preset) => {
118
- if (typeof preset === 'string') {
119
- const fullPreset = getRangeFromPreset(preset);
120
- onChangeFilter(filter, fullPreset);
121
- setFilterValue(fullPreset);
122
- return;
123
- }
124
- onChangeFilter(filter, [
125
- preset?.startDate || null,
126
- new Date(),
127
- preset?.value || '',
128
- ]);
129
- setFilterValue([
130
- preset?.startDate || null,
131
- new Date(),
132
- preset?.value || '',
133
- ]);
134
- }, presetOptions: defaultOptions }), comparisonRange && (_jsx("div", { children: _jsxs("div", { style: {
57
+ }, children: [_jsx(DateRangePickerComponent, { label: filter.label, dateRange: { startDate: filter.startDate, endDate: filter.endDate }, preset: filter.preset.label, onChangeDateRange: (value) => {
58
+ onChangeFilter(filter, {
59
+ startDate: value.startDate,
60
+ endDate: value.endDate,
61
+ });
62
+ }, onChangePreset: (value) => {
63
+ onChangeFilter(filter, { preset: value });
64
+ }, presetOptions: filter.options.map((option) => {
65
+ return { label: option.label, value: option.label };
66
+ }) }), comparisonRange && (_jsx("div", { children: _jsxs("div", { style: {
135
67
  display: 'flex',
136
68
  flexDirection: 'row',
137
69
  alignItems: 'center',
@@ -140,7 +72,8 @@ export function DashboardFilter({ filter, onChangeFilter, SelectComponent, DateR
140
72
  paddingRight: 12,
141
73
  color: theme?.secondaryTextColor,
142
74
  fontFamily: theme?.fontFamily,
143
- }, children: "compared to" }), _jsx(SelectComponent, { value: comparisonRange.value, onChange: (e) => {
75
+ fontSize: 14,
76
+ }, children: "compared to" }), _jsx(QuillSelectComponent, { theme: theme, value: comparisonRange.value, onChange: (e) => {
144
77
  onChangeFilter(filter, null, COMPARISON_OPTIONS.find((option) => {
145
78
  return option.value === e;
146
79
  }));
@@ -153,32 +86,6 @@ export function DashboardFilter({ filter, onChangeFilter, SelectComponent, DateR
153
86
  }
154
87
  return null;
155
88
  }
156
- const options = [
157
- {
158
- date_range: [startOfWeek(startOfToday()), startOfToday(), 'wk'],
159
- },
160
- {
161
- date_range: [sub(startOfToday(), { days: 90 }), startOfToday(), '90d'],
162
- },
163
- {
164
- date_range: [sub(startOfToday(), { days: 30 }), startOfToday(), 't'],
165
- },
166
- {
167
- date_range: [sub(startOfToday(), { years: 100 }), startOfToday(), 'at'],
168
- },
169
- {
170
- date_range: [startOfYear(startOfToday()), startOfToday(), 'y'],
171
- },
172
- {
173
- date_range: [startOfMonth(startOfToday()), startOfToday(), 'm'],
174
- },
175
- {
176
- date_range: [sub(startOfToday(), { days: 7 }), startOfToday(), 'w'],
177
- },
178
- {
179
- date_range: [sub(startOfToday(), { months: 6 }), startOfToday(), '6m'],
180
- },
181
- ];
182
89
  const QuillDropdownComponent = ({ onChange, value, label, options, }) => {
183
90
  const [theme] = useContext(ThemeContext);
184
91
  const handleOnChange = useCallback((event) => {
@@ -224,317 +131,12 @@ const QuillDropdownComponent = ({ onChange, value, label, options, }) => {
224
131
  color: theme?.secondaryTextColor,
225
132
  }, "aria-hidden": "true" })] })] }));
226
133
  };
227
- const isBetween = (date, startDate, endDate) => {
228
- return isAfter(date, startDate) && isBefore(date, endDate);
229
- };
230
- function Calendar({ anchorDate, onClickDate, theme, localStartDate, localEndDate, }) {
231
- const firstDayOfDisplayedMonth = startOfMonth(anchorDate);
232
- const lastDayOfDisplayedMonth = endOfMonth(anchorDate);
233
- const weekdays = getWeekdays(enUS).map((dayName) => capitalize(dayName, enUS));
234
- const displayedDates = eachDayOfInterval({
235
- start: isSunday(firstDayOfDisplayedMonth)
236
- ? firstDayOfDisplayedMonth
237
- : previousSunday(firstDayOfDisplayedMonth),
238
- end: isSaturday(lastDayOfDisplayedMonth)
239
- ? lastDayOfDisplayedMonth
240
- : nextSaturday(lastDayOfDisplayedMonth),
241
- });
242
- const displayedTitle = capitalize(format(firstDayOfDisplayedMonth, 'MMMM yyyy', { locale: enUS }), enUS);
243
- return (_jsxs("div", { style: {
244
- display: 'flex',
245
- flexDirection: 'column',
246
- flex: 1,
247
- // alignItems: 'center',
248
- }, children: [_jsx("h2", { style: {
249
- color: theme?.textColor || '#364153',
250
- fontSize: '13px',
251
- fontFamily: theme?.fontFamily,
252
- fontWeight: '700',
253
- width: '100%',
254
- textAlign: 'center',
255
- height: 36,
256
- display: 'flex',
257
- flexDirection: 'row',
258
- alignItems: 'center',
259
- justifyContent: 'center',
260
- marginBottom: 3,
261
- marginTop: 6,
262
- }, children: displayedTitle }), _jsx("div", { style: {
263
- color: theme?.primaryTextColor || '#364153',
264
- textAlign: 'center',
265
- fontSize: 12,
266
- fontWeight: '500',
267
- display: 'grid',
268
- gridTemplateColumns: 'repeat(7, minmax(0, 1fr))',
269
- paddingTop: 6,
270
- }, children: weekdays.map((dayName) => (_jsx("div", { style: { width: '100%', display: 'flex', justifyContent: 'center' }, children: _jsx("div", { style: {
271
- display: 'flex',
272
- alignItems: 'center',
273
- justifyContent: 'center',
274
- width: '100%',
275
- // height: '2.25rem',
276
- fontFamily: theme?.fontFamily,
277
- color: theme.secondaryTextColor,
278
- paddingBottom: 4,
279
- }, children: dayName }) }, dayName))) }), _jsx("div", { style: {
280
- display: 'grid',
281
- gridTemplateColumns: 'repeat(7, minmax(0, 1fr))',
282
- borderRadius: 3,
283
- overflow: 'hidden',
284
- rowGap: 6,
285
- }, children: displayedDates.map((date, index) => {
286
- return (_jsx("div", { style: { width: '100%' }, children: _jsx("button", { style: {
287
- border: 'none',
288
- height: '34px',
289
- display: 'flex',
290
- width: '100%',
291
- alignItems: 'center',
292
- justifyContent: 'center',
293
- fontFamily: theme?.fontFamily,
294
- fontSize: 13,
295
- background: isEqual(localStartDate, date) || isEqual(localEndDate, date)
296
- ? theme.primaryTextColor
297
- : isBetween(date, localStartDate, localEndDate)
298
- ? '#F4F4F5'
299
- : 'transparent',
300
- color: isEqual(localStartDate, date) || isEqual(localEndDate, date)
301
- ? theme.backgroundColor
302
- : theme.primaryTextColor,
303
- borderRadius: isEqual(localStartDate, date) || isEqual(localEndDate, date)
304
- ? 3
305
- : 0,
306
- ...isBeginningOrEndOfWeek(index),
307
- }, type: "button", onClick: () => {
308
- onClickDate(date);
309
- }, children: _jsx("time", { dateTime: format(date, 'yyyy-MM-dd', { locale: enUS }), children: format(date, 'd', { locale: enUS }) }) }) }, date.toString()));
310
- }) }), _jsx("div", { style: { height: 8 } })] }));
311
- }
312
- function isBeginningOrEndOfWeek(num) {
313
- // Check if the number is 0
314
- if (num === 0)
315
- return { borderTopLeftRadius: 3, borderBottomLeftRadius: 3 };
316
- // Check if the number is divisible by 7
317
- if (num % 7 === 0)
318
- return { borderTopLeftRadius: 3, borderBottomLeftRadius: 3 };
319
- // Check if the number is one less than a multiple of 7
320
- if ((num + 1) % 7 === 0)
321
- return { borderTopRightRadius: 3, borderBottomRightRadius: 3 };
322
- // If none of the conditions are met, return false
323
- return {};
324
- }
325
- const formatDateText = (dateRange, localStartDate, localEndDate) => {
326
- if (dateRange.length && dateRange[0] && dateRange[1]) {
327
- return (format(dateRange[0], 'MMM dd, yyyy') +
328
- ' - ' +
329
- format(dateRange[1], 'MMM dd, yyyy'));
330
- }
331
- if (localStartDate && localEndDate) {
332
- return (format(localStartDate, 'MMM dd, yyyy') +
333
- ' - ' +
334
- format(localEndDate, 'MMM dd, yyyy'));
335
- }
336
- return '';
337
- };
338
- function CalendarDropdown({ onChangeDateRange, dateRange }) {
339
- const [theme] = useContext(ThemeContext);
340
- const [showModal, setShowModal] = useState(false);
341
- const modalRef = useRef(null);
342
- const parentRef = useRef(null);
343
- const [anchorDate, setAnchorDate] = useState(null);
344
- const [localStartDate, setLocalStartDate] = useState(null);
345
- const [localEndDate, setLocalEndDate] = useState(null);
346
- const prevMonthAnchor = subDays(startOfMonth(anchorDate), 1);
347
- const onClickDate = (date) => {
348
- if (localStartDate && isBefore(date, localStartDate)) {
349
- setLocalStartDate(date);
350
- return;
351
- }
352
- if (localEndDate && isAfter(date, localEndDate)) {
353
- setLocalEndDate(date);
354
- return;
355
- }
356
- if (localEndDate && isBefore(date, localEndDate)) {
357
- setLocalEndDate(date);
358
- return;
359
- }
360
- if (isEqual(localStartDate, date) || isEqual(localEndDate, date)) {
361
- setLocalStartDate(null);
362
- setLocalEndDate(null);
363
- }
364
- if (!localStartDate) {
365
- setLocalStartDate(date);
366
- return;
367
- }
368
- if (!localEndDate) {
369
- setLocalEndDate(date);
370
- return;
371
- }
372
- };
373
- useEffect(() => {
374
- if (localEndDate &&
375
- localStartDate &&
376
- isBefore(localStartDate, localEndDate)) {
377
- onChangeDateRange([localStartDate, localEndDate]);
378
- }
379
- }, [localEndDate, localStartDate]);
380
- useEffect(() => {
381
- if (dateRange.length && !anchorDate) {
382
- setAnchorDate(dateRange[1]);
383
- }
384
- }, [dateRange, anchorDate]);
385
- useOnClickOutside(modalRef, (e) => {
386
- // Exclude click on trigger button (e.g. Dropdown Button) from outside click handler
387
- const isTriggerElem = parentRef
388
- ? parentRef.current?.contains(e.target)
389
- : false;
390
- if (!isTriggerElem) {
391
- setShowModal(false);
392
- }
393
- });
394
- return (_jsxs("div", { ref: parentRef, style: { position: 'relative', height: 38 }, children: [_jsx("button", {
395
- // onChange={handleOnChange}
396
- // value={value}
397
- onClick: () => setShowModal((showModal) => !showModal), id: 'reportbuilderdropdown', defaultValue: "Select", style: {
398
- width: '100%',
399
- WebkitAppearance: 'none',
400
- minWidth: 275,
401
- maxWidth: 275,
402
- outline: 'none',
403
- textAlign: 'left',
404
- whiteSpace: 'nowrap',
405
- overflow: 'hidden',
406
- textOverflow: 'ellipsis',
407
- borderRadius: 6,
408
- // paddingLeft: 12,
409
- paddingRight: 12,
410
- height: 38,
411
- borderStyle: 'solid',
412
- borderWidth: theme.borderWidth,
413
- borderColor: theme.borderColor,
414
- background: theme.backgroundColor,
415
- color: theme.primaryTextColor,
416
- boxShadow: '0 1px 2px 0 rgba(0,0,0,.05)',
417
- fontFamily: theme.fontFamily,
418
- fontSize: 14,
419
- fontWeight: 500,
420
- minHeight: 38,
421
- marginBottom: 0,
422
- paddingLeft: 14 + 15 + 3,
423
- }, children: formatDateText(dateRange, localStartDate, localEndDate) }), _jsx(CalendarNormalIcon, { style: {
424
- height: '15px',
425
- width: '15px',
426
- flex: 'none',
427
- position: 'absolute',
428
- left: 12,
429
- top: 11,
430
- color: theme?.primaryTextColor,
431
- } }), showModal && (_jsxs("div", { ref: modalRef, style: {
432
- position: 'absolute',
433
- zIndex: 1,
434
- overflowY: 'auto',
435
- top: 38 + 8,
436
- width: 230 + 245 + 12,
437
- // left: getAbsoluteSpacing(),
438
- // right: getAbsoluteSpacing(),
439
- // height: 230 + 10,
440
- backgroundColor: theme?.backgroundColor || 'white',
441
- borderColor: theme?.borderColor || '#E5E7EB',
442
- borderTopStyle: 'solid',
443
- borderBottomStyle: 'solid',
444
- borderLeftStyle: 'solid',
445
- borderRightStyle: 'solid',
446
- borderTopWidth: 1,
447
- borderBottomWidth: 1,
448
- borderLeftWidth: 1,
449
- borderRightWidth: 1,
450
- marginTop: 0,
451
- // marginTop: '6px',
452
- borderRadius: 5,
453
- display: 'flex',
454
- flexDirection: 'row',
455
- alignItems: 'flex-start',
456
- boxShadow: '0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)',
457
- gap: 12,
458
- paddingLeft: 8,
459
- paddingRight: 8,
460
- paddingBottom: 1,
461
- }, children: [_jsx("button", { style: {
462
- height: 32,
463
- width: 32,
464
- position: 'absolute',
465
- borderColor: theme?.borderColor || '#E5E7EB',
466
- borderTopStyle: 'solid',
467
- borderBottomStyle: 'solid',
468
- borderLeftStyle: 'solid',
469
- borderRightStyle: 'solid',
470
- borderTopWidth: 1,
471
- borderBottomWidth: 1,
472
- borderLeftWidth: 1,
473
- borderRightWidth: 1,
474
- top: 8,
475
- left: 8,
476
- borderRadius: 3,
477
- display: 'flex',
478
- alignItems: 'center',
479
- justifyContent: 'center',
480
- background: 'transparent',
481
- }, onClick: () => setAnchorDate((date) => subDays(startOfMonth(date), 1)), children: _jsx(ArrowLeftHeadIcon, { style: {
482
- height: '20px',
483
- width: '20px',
484
- color: theme?.secondaryTextColor,
485
- }, "aria-hidden": "true" }) }), _jsx("button", { style: {
486
- height: 32,
487
- width: 32,
488
- borderColor: theme?.borderColor || '#E5E7EB',
489
- borderTopStyle: 'solid',
490
- borderBottomStyle: 'solid',
491
- borderLeftStyle: 'solid',
492
- borderRightStyle: 'solid',
493
- borderTopWidth: 1,
494
- borderBottomWidth: 1,
495
- borderLeftWidth: 1,
496
- borderRightWidth: 1,
497
- position: 'absolute',
498
- top: 8,
499
- right: 8,
500
- borderRadius: 3,
501
- display: 'flex',
502
- alignItems: 'center',
503
- justifyContent: 'center',
504
- background: 'transparent',
505
- }, onClick: () => setAnchorDate((date) => addDays(endOfMonth(date), 1)), children: _jsx(ArrowRightHeadIcon, { style: {
506
- height: '20px',
507
- width: '20px',
508
- color: theme?.secondaryTextColor,
509
- }, "aria-hidden": "true" }) }), anchorDate && (_jsx(Calendar, { anchorDate: prevMonthAnchor, dateRange: dateRange, theme: theme, onClickDate: onClickDate, localStartDate: localStartDate, localEndDate: localEndDate })), anchorDate && (_jsx(Calendar, { anchorDate: anchorDate, dateRange: dateRange, theme: theme, onClickDate: onClickDate, localStartDate: localStartDate, localEndDate: localEndDate }))] }))] }));
510
- }
511
- export const QuillDateRangePicker = ({ label, dateRange, onChangeDateRange, presetOptions, preset, onChangePreset, }) => {
512
- const [theme] = useContext(ThemeContext);
513
- return (_jsxs("div", { children: [label !== '' && (_jsx("div", { style: {
514
- marginBottom: 6,
515
- fontWeight: theme.labelFontWeight || '600',
516
- color: theme.secondaryTextColor,
517
- fontFamily: theme.fontFamily,
518
- fontSize: 14,
519
- }, children: label })), _jsxs("div", { style: {
520
- display: 'flex',
521
- flexDirection: 'row',
522
- alignItems: 'center',
523
- gap: 12,
524
- }, children: [_jsx(MemoizedCalendarDropdown, { dateRange: dateRange, onChangeDateRange: onChangeDateRange, theme: theme }), _jsx(MemoizedDropdown, { options: presetOptions.map((option) => ({
525
- label: option.text,
526
- value: option.value,
527
- })), onChange: onChangePreset, value: preset })] })] }));
528
- };
529
- const MemoizedCalendarDropdown = memo(CalendarDropdown);
530
134
  const MemoizedDropdown = memo(QuillDropdownComponent);
531
135
  const areEqual = (prevProps, nextProps) => {
532
136
  // This function returns true if passing nextProps to render would return
533
137
  // the same result as passing prevProps to render, otherwise it returns false
534
- // You can replace 'someProperty' with the actual prop you want to compare
535
- return (prevProps.dateRange.length === nextProps.dateRange.length &&
536
- prevProps.dateRange[0] === nextProps.dateRange[0] &&
537
- prevProps.dateRange[1] === nextProps.dateRange[1]);
138
+ return (prevProps.dateRange.startDate === nextProps.dateRange.startDate &&
139
+ prevProps.dateRange.endDate === nextProps.dateRange.endDate);
538
140
  };
539
141
  const MemoizedDateRangePicker = memo(QuillDateRangePicker, areEqual);
540
142
  const QuillEmptyDashboardComponent = () => _jsx("div", {});
@@ -552,6 +154,7 @@ export default function Dashboard({ name, containerStyle, chartContainerStyle =
552
154
  const { dispatch } = useContext(DashboardContext);
553
155
  const { isLoading: isDataLoading, data, reload, } = useDashboard(name);
554
156
  const [dashboardSections, setDashboardSections] = useState(null);
157
+ const [presetFilters, setPresetFilters] = useState(null);
555
158
  const { dashboard } = useContext(DashboardContext);
556
159
  const [client] = useContext(ClientContext);
557
160
  const [isLoading, setIsLoading] = useState(isDataLoading);
@@ -573,19 +176,45 @@ export default function Dashboard({ name, containerStyle, chartContainerStyle =
573
176
  setDashboardSections(resp.sections);
574
177
  const bigFilterObj = {};
575
178
  if (resp.dateFilter && Object.keys(resp.dateFilter).length) {
576
- const key = resp.dateFilter.defaultPrimaryRange ?? 'LAST_6_MONTHS';
179
+ let presetsOptions = defaultOptionsV2;
180
+ if (resp.dateFilter.presetRanges) {
181
+ presetsOptions = resp.dateFilter.presetRanges.map((elem) => {
182
+ if (!elem.isStatic) {
183
+ return {
184
+ label: elem.label,
185
+ value: elem.value,
186
+ startDate: PRIMARY_RANGE[elem.value].start,
187
+ endDate: PRIMARY_RANGE[elem.value].end,
188
+ };
189
+ }
190
+ return {
191
+ label: elem.label,
192
+ value: elem.value,
193
+ startDate: new Date(elem.startDate),
194
+ endDate: new Date(elem.endDate),
195
+ };
196
+ });
197
+ }
198
+ setPresetFilters(presetsOptions);
199
+ const key = resp.dateFilter?.primaryRange?.value || 'LAST_6_MONTHS';
200
+ const primaryPreset = presetsOptions.find((option) => {
201
+ return option.value === key;
202
+ });
577
203
  const filter = {
578
- startDate: PRIMARY_RANGE[key]?.start,
579
- endDate: PRIMARY_RANGE[key]?.end,
204
+ startDate: primaryPreset.startDate,
205
+ endDate: primaryPreset.endDate,
580
206
  filterType: 'date_range',
581
- selectedValue: [
582
- PRIMARY_RANGE[key]?.start,
583
- PRIMARY_RANGE[key]?.end,
584
- PRIMARY_CODES[key],
585
- ],
586
- options: options,
207
+ options: presetsOptions.map((elem) => {
208
+ return {
209
+ label: elem.label,
210
+ value: elem.value,
211
+ };
212
+ }),
587
213
  field: 'date_range',
588
214
  label: 'Date',
215
+ preset: {
216
+ label: primaryPreset.label,
217
+ },
589
218
  };
590
219
  if (resp.dateFilter.comparison) {
591
220
  filter.comparison = true;
@@ -609,13 +238,12 @@ export default function Dashboard({ name, containerStyle, chartContainerStyle =
609
238
  });
610
239
  }
611
240
  bigFilterObj[filter.field] = filter;
612
- setDateFilter(PRIMARY_OPTIONS.find((opt) => opt.value === resp.dateFilter.defaultPrimaryRange)?.text ?? null);
241
+ setDateFilter(presetsOptions.find((opt) => opt.value === resp.dateFilter.defaultPrimaryRange)?.label ?? null);
613
242
  }
614
243
  if (resp.filters && resp.filters.length) {
615
244
  Object.values(resp.filters)
616
245
  .filter((filter) => filter.filterType !== 'date')
617
246
  .forEach((filter) => {
618
- // processFilter(filter);
619
247
  bigFilterObj[filter.field] = processFilter(filter);
620
248
  });
621
249
  }
@@ -647,18 +275,6 @@ export default function Dashboard({ name, containerStyle, chartContainerStyle =
647
275
  });
648
276
  }
649
277
  };
650
- const onChangeDateFilter = (dateFilter) => {
651
- // setGlobalDateFilter(dateFilter[0], dateFilter[1]);
652
- dashboardFiltersDispatch({
653
- type: 'ADD_DASHBOARD_FILTER',
654
- id: 'date_range',
655
- data: {
656
- startDate: dateFilter[0],
657
- endDate: dateFilter[1],
658
- filterType: 'date_range',
659
- },
660
- });
661
- };
662
278
  function removeQuotes(str) {
663
279
  if (str.startsWith('"') && str.endsWith('"')) {
664
280
  return str.slice(1, -1);
@@ -683,22 +299,13 @@ export default function Dashboard({ name, containerStyle, chartContainerStyle =
683
299
  };
684
300
  }
685
301
  if (filter.filterType === 'date' || filter.filterType === 'date_range') {
686
- if (value[2]) {
687
- selectedElem = filter.options.find((elem) => {
688
- return value[2] === elem[removeQuotes(filter.field)][2];
689
- });
690
- if (selectedElem) {
691
- selectedValue = selectedElem[removeQuotes(filter.field)];
692
- }
693
- }
694
302
  return {
695
303
  startDate: value ? value[0] : filter.startDate,
696
304
  endDate: value ? value[1] : filter.endDate,
697
305
  filterType: 'date_range',
698
306
  label: 'Date',
699
- ...(selectedValue ? { selectedValue } : {}),
700
307
  field: 'date_range',
701
- options: options,
308
+ options: filter.options,
702
309
  };
703
310
  }
704
311
  };
@@ -723,35 +330,32 @@ export default function Dashboard({ name, containerStyle, chartContainerStyle =
723
330
  return;
724
331
  }
725
332
  if (filter.filterType === 'date' || filter.filterType === 'date_range') {
726
- if (value && value[2]) {
727
- selectedElem = filter.options.find((elem) => {
728
- return value[2] === elem[removeQuotes(filter.field)][2];
729
- });
730
- if (selectedElem) {
731
- selectedValue = selectedElem[removeQuotes(filter.field)];
732
- }
733
- }
734
333
  if (comparison ||
735
334
  (filter.comparison && filter.comparisonRange.value !== 'NO_COMPARISON')) {
335
+ let preset = '';
736
336
  if (comparison) {
737
- selectedValue = filter.selectedValue;
337
+ preset = filter.preset.label;
738
338
  }
739
339
  const key = comparison?.value || filter.comparisonRange.value;
740
- const primaryRange = {
741
- start: value ? value[0] : filter.startDate,
742
- end: value ? value[1] : filter.endDate,
340
+ let primaryRange = {
341
+ start: value ? value.startDate : filter.startDate,
342
+ end: value ? value.endDate : filter.endDate,
743
343
  };
344
+ if (value && value.preset) {
345
+ preset = value.preset;
346
+ primaryRange = getRangeFromPresetOptions(value.preset, presetFilters);
347
+ }
744
348
  dashboardFiltersDispatch({
745
349
  type: 'ADD_DASHBOARD_FILTER',
746
350
  id: 'date_range',
747
351
  data: {
748
- startDate: value ? value[0] : filter.startDate,
749
- endDate: value ? value[1] : filter.endDate,
352
+ startDate: primaryRange.start,
353
+ endDate: primaryRange.end,
750
354
  filterType: 'date_range',
751
355
  label: 'Date',
752
- ...(selectedValue ? { selectedValue } : {}),
753
356
  field: 'date_range',
754
- options: options,
357
+ preset: { label: preset },
358
+ options: filter.options,
755
359
  comparison: true,
756
360
  comparisonRange: {
757
361
  startDate: COMPARISON_RANGE[key](primaryRange)
@@ -763,17 +367,24 @@ export default function Dashboard({ name, containerStyle, chartContainerStyle =
763
367
  });
764
368
  }
765
369
  else {
370
+ const primaryRange = value.preset
371
+ ? getRangeFromPresetOptions(value.preset, presetFilters)
372
+ : {
373
+ start: value.startDate || filter.startDate,
374
+ end: value.endDate || filter.endDate,
375
+ };
376
+ const preset = value.preset ? value.preset : '';
766
377
  dashboardFiltersDispatch({
767
378
  type: 'ADD_DASHBOARD_FILTER',
768
379
  id: 'date_range',
769
380
  data: {
770
381
  ...filter,
771
- startDate: value ? value[0] : filter.startDate,
772
- endDate: value ? value[1] : filter.endDate,
382
+ preset: { label: preset },
383
+ startDate: primaryRange.start,
384
+ endDate: primaryRange.end,
773
385
  filterType: 'date_range',
774
- ...(selectedValue ? { selectedValue } : {}),
775
386
  field: 'date_range',
776
- options: options,
387
+ options: filter.options,
777
388
  label: 'Date',
778
389
  },
779
390
  });
@@ -831,7 +442,7 @@ export default function Dashboard({ name, containerStyle, chartContainerStyle =
831
442
  flexDirection: 'row',
832
443
  alignItems: 'center',
833
444
  gap: 12,
834
- }, children: sortedFilters.map((filter, index) => (_jsx(DashboardFilter, { filter: filter, onChangeFilter: updateFilter, theme: theme, filterValue: dashboardFilters, SelectComponent: SelectComponent ? SelectComponent : MemoizedDropdown, DateRangePickerComponent: DateRangePickerComponent
445
+ }, children: sortedFilters.map((filter, index) => (_jsx(DashboardFilter, { filter: filter, onChangeFilter: updateFilter, theme: theme, SelectComponent: SelectComponent ? SelectComponent : MemoizedDropdown, DateRangePickerComponent: DateRangePickerComponent
835
446
  ? DateRangePickerComponent
836
447
  : MemoizedDateRangePicker }, index))) }) })), Object.keys(dashboardSections)
837
448
  .sort(function (a, b) {
@@ -874,6 +485,6 @@ export default function Dashboard({ name, containerStyle, chartContainerStyle =
874
485
  height: '400px',
875
486
  }, chartId: item._id, colors: theme.chartColors?.length
876
487
  ? theme.chartColors
877
- : undefined, hideXAxis: hideXAxis, hideYAxis: hideYAxis, hideCartesianGrid: hideCartesianGrid }) }, `${item.name}${index}`)) }))) }))] }, section + '' + sectionIndex));
488
+ : undefined, hideXAxis: hideXAxis, hideYAxis: hideYAxis, hideCartesianGrid: hideCartesianGrid }) })) }, `${item.name}${index}`))) }))] }, section + '' + sectionIndex));
878
489
  })] }));
879
490
  }