@quillsql/react 2.12.53 → 2.13.1

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 (97) hide show
  1. package/dist/cjs/ChartBuilder.d.ts.map +1 -1
  2. package/dist/cjs/ChartBuilder.js +4 -4
  3. package/dist/cjs/ChartEditor.d.ts.map +1 -1
  4. package/dist/cjs/ChartEditor.js +10 -10
  5. package/dist/cjs/Context.d.ts +13 -1
  6. package/dist/cjs/Context.d.ts.map +1 -1
  7. package/dist/cjs/Context.js +114 -17
  8. package/dist/cjs/Dashboard.d.ts.map +1 -1
  9. package/dist/cjs/Dashboard.js +107 -313
  10. package/dist/cjs/DateRangePicker/QuillDateRangePicker.d.ts.map +1 -1
  11. package/dist/cjs/DateRangePicker/QuillDateRangePicker.js +14 -6
  12. package/dist/cjs/ReportBuilder.d.ts.map +1 -1
  13. package/dist/cjs/ReportBuilder.js +13 -7
  14. package/dist/cjs/SQLEditor.d.ts.map +1 -1
  15. package/dist/cjs/SQLEditor.js +6 -5
  16. package/dist/cjs/components/Dashboard/DashboardFilter.d.ts +2 -1
  17. package/dist/cjs/components/Dashboard/DashboardFilter.d.ts.map +1 -1
  18. package/dist/cjs/components/Dashboard/DashboardFilter.js +7 -7
  19. package/dist/cjs/components/Dashboard/DataLoader.d.ts.map +1 -1
  20. package/dist/cjs/components/Dashboard/DataLoader.js +36 -3
  21. package/dist/cjs/components/QuillMultiSelect.js +1 -1
  22. package/dist/cjs/components/QuillMultiSelectWithCombo.js +1 -1
  23. package/dist/cjs/components/QuillSelect.d.ts +1 -1
  24. package/dist/cjs/components/QuillSelect.d.ts.map +1 -1
  25. package/dist/cjs/components/QuillSelect.js +3 -3
  26. package/dist/cjs/components/QuillSelectWithCombo.d.ts +1 -1
  27. package/dist/cjs/components/QuillSelectWithCombo.d.ts.map +1 -1
  28. package/dist/cjs/components/QuillSelectWithCombo.js +3 -3
  29. package/dist/cjs/components/QuillTable.d.ts.map +1 -1
  30. package/dist/cjs/components/QuillTable.js +10 -3
  31. package/dist/cjs/components/UiComponents.d.ts +1 -0
  32. package/dist/cjs/components/UiComponents.d.ts.map +1 -1
  33. package/dist/cjs/hooks/useDashboard.d.ts +4 -1
  34. package/dist/cjs/hooks/useDashboard.d.ts.map +1 -1
  35. package/dist/cjs/hooks/useDashboard.js +122 -53
  36. package/dist/cjs/hooks/useExport.d.ts.map +1 -1
  37. package/dist/cjs/hooks/useExport.js +8 -2
  38. package/dist/cjs/hooks/useQuill.d.ts.map +1 -1
  39. package/dist/cjs/hooks/useQuill.js +11 -13
  40. package/dist/cjs/models/Client.d.ts +6 -0
  41. package/dist/cjs/models/Client.d.ts.map +1 -1
  42. package/dist/cjs/models/Filter.d.ts +4 -3
  43. package/dist/cjs/models/Filter.d.ts.map +1 -1
  44. package/dist/cjs/models/Filter.js +38 -1
  45. package/dist/cjs/utils/paginationProcessing.js +1 -1
  46. package/dist/cjs/utils/report.js +2 -2
  47. package/dist/cjs/utils/tableProcessing.d.ts +2 -2
  48. package/dist/cjs/utils/tableProcessing.d.ts.map +1 -1
  49. package/dist/esm/ChartBuilder.d.ts.map +1 -1
  50. package/dist/esm/ChartBuilder.js +4 -4
  51. package/dist/esm/ChartEditor.d.ts.map +1 -1
  52. package/dist/esm/ChartEditor.js +10 -10
  53. package/dist/esm/Context.d.ts +13 -1
  54. package/dist/esm/Context.d.ts.map +1 -1
  55. package/dist/esm/Context.js +114 -17
  56. package/dist/esm/Dashboard.d.ts.map +1 -1
  57. package/dist/esm/Dashboard.js +107 -313
  58. package/dist/esm/DateRangePicker/QuillDateRangePicker.d.ts.map +1 -1
  59. package/dist/esm/DateRangePicker/QuillDateRangePicker.js +15 -7
  60. package/dist/esm/ReportBuilder.d.ts.map +1 -1
  61. package/dist/esm/ReportBuilder.js +14 -8
  62. package/dist/esm/SQLEditor.d.ts.map +1 -1
  63. package/dist/esm/SQLEditor.js +6 -5
  64. package/dist/esm/components/Dashboard/DashboardFilter.d.ts +2 -1
  65. package/dist/esm/components/Dashboard/DashboardFilter.d.ts.map +1 -1
  66. package/dist/esm/components/Dashboard/DashboardFilter.js +7 -7
  67. package/dist/esm/components/Dashboard/DataLoader.d.ts.map +1 -1
  68. package/dist/esm/components/Dashboard/DataLoader.js +37 -4
  69. package/dist/esm/components/QuillMultiSelect.js +1 -1
  70. package/dist/esm/components/QuillMultiSelectWithCombo.js +1 -1
  71. package/dist/esm/components/QuillSelect.d.ts +1 -1
  72. package/dist/esm/components/QuillSelect.d.ts.map +1 -1
  73. package/dist/esm/components/QuillSelect.js +3 -3
  74. package/dist/esm/components/QuillSelectWithCombo.d.ts +1 -1
  75. package/dist/esm/components/QuillSelectWithCombo.d.ts.map +1 -1
  76. package/dist/esm/components/QuillSelectWithCombo.js +3 -3
  77. package/dist/esm/components/QuillTable.d.ts.map +1 -1
  78. package/dist/esm/components/QuillTable.js +10 -3
  79. package/dist/esm/components/UiComponents.d.ts +1 -0
  80. package/dist/esm/components/UiComponents.d.ts.map +1 -1
  81. package/dist/esm/hooks/useDashboard.d.ts +4 -1
  82. package/dist/esm/hooks/useDashboard.d.ts.map +1 -1
  83. package/dist/esm/hooks/useDashboard.js +121 -55
  84. package/dist/esm/hooks/useExport.d.ts.map +1 -1
  85. package/dist/esm/hooks/useExport.js +9 -3
  86. package/dist/esm/hooks/useQuill.d.ts.map +1 -1
  87. package/dist/esm/hooks/useQuill.js +12 -14
  88. package/dist/esm/models/Client.d.ts +6 -0
  89. package/dist/esm/models/Client.d.ts.map +1 -1
  90. package/dist/esm/models/Filter.d.ts +4 -3
  91. package/dist/esm/models/Filter.d.ts.map +1 -1
  92. package/dist/esm/models/Filter.js +36 -0
  93. package/dist/esm/utils/paginationProcessing.js +1 -1
  94. package/dist/esm/utils/report.js +2 -2
  95. package/dist/esm/utils/tableProcessing.d.ts +2 -2
  96. package/dist/esm/utils/tableProcessing.d.ts.map +1 -1
  97. package/package.json +1 -1
@@ -27,7 +27,6 @@ import QuillTemplateMetricComponent from './components/Dashboard/TemplateMetricC
27
27
  import QuillTemplateTableComponent from './components/Dashboard/TemplateTableComponent';
28
28
  import QuillDashboardTemplate from './components/Dashboard/DashboardTemplate';
29
29
  import { DashboardFilterType, } from './models/Filter';
30
- import equal from 'fast-deep-equal';
31
30
  const defaultChartContainerStyles = {
32
31
  display: 'flex',
33
32
  width: '100%',
@@ -43,6 +42,15 @@ const charts = (sections, section, sortByOrdering) => sections[section]
43
42
  const tables = (sections, section, sortByOrdering) => sections[section]
44
43
  .filter(({ chartType }) => chartType === 'table')
45
44
  .sort(sortByOrdering);
45
+ const sortByOrdering = (a, b) => {
46
+ if (a.order === undefined && b.order === undefined)
47
+ return 0;
48
+ if (a.order === undefined)
49
+ return 1;
50
+ if (b.order === undefined)
51
+ return -1;
52
+ return a.order - b.order;
53
+ };
46
54
  /**
47
55
  * ### Quill Dashboard
48
56
  *
@@ -75,13 +83,11 @@ const tables = (sections, section, sortByOrdering) => sections[section]
75
83
  * @see https://docs.quillsql.com/components/dashboard
76
84
  */
77
85
  export default function Dashboard({ name, hidden = false, SelectComponent = QuillSelectComponentWithCombo, MultiSelectComponent = QuillMultiSelectComponentWithCombo, ModalComponent = QuillModalComponent, ButtonComponent = MemoizedButton, SecondaryButtonComponent = MemoizedSecondaryButton, FilterTagComponent = QuillFilterPopover, PopoverComponent = MemoizedPopover, TextInputComponent = QuillTextInput, EmptyDashboardComponent = QuillEmptyDashboardComponent, DateRangePickerComponent = QuillDateRangePicker, MetricComponent = QuillMetricComponent, ChartComponent = QuillChartComponent, TableComponent = QuillTableComponent, TemplateMetricComponent = QuillTemplateMetricComponent, TemplateChartComponent = QuillTemplateChartComponent, TemplateTableComponent = QuillTemplateTableComponent, DashboardSectionComponent = DashboardSection, DashboardSectionContainerComponent = DashboardSectionContainer, FilterContainerComponent = QuillFilterContainerComponent, DashboardLoadingComponent = QuillLoadingDashboardComponent, ErrorComponent = QuillChartErrorWithAction, onClickReport, hoverActions, onChangeLoading, hideFilters, hideXAxis = false, hideYAxis = false, hideCartesianGrid = false, comparisonLineStyle = 'solid', containerStyle, className, chartContainerStyle = defaultChartContainerStyles, filters, onClickChartElement, dateBucket, additionalProcessing, hideAdminErrors = true, templateDashboardName, }) {
78
- const { isLoading, data, isDashboardFiltersLoading, dashboardFilters: populatedDashboardFilters, reload, } = useDashboard(name);
79
- const [presetFilters, setPresetFilters] = useState(null);
86
+ const { isLoading, data, isDashboardFilterLoading, dashboardFilters: populatedDashboardFilters, reload, } = useDashboard(name);
80
87
  const [client, isClientLoading] = useContext(ClientContext);
81
88
  const [theme] = useContext(ThemeContext);
82
89
  const [initialLoad, setInitialLoad] = useState(true);
83
- const [appliedFilters, setAppliedFilters] = useState(null);
84
- const { dashboardFilters, dashboardFiltersDispatch } = useContext(DashboardFiltersContext);
90
+ const { dispatch: dashboardFiltersDispatch } = useContext(DashboardFiltersContext);
85
91
  const [schemaData] = useContext(SchemaDataContext);
86
92
  const [filterSchemaIsLoaded, setFilterSchemaIsLoaded] = useState(false);
87
93
  const [filterSchema, setFilterSchema] = useState({ columns: [] }); // Schema to be passed into FilterModal
@@ -91,20 +97,37 @@ export default function Dashboard({ name, hidden = false, SelectComponent = Quil
91
97
  const [addFilterPopoverIsOpen, setAddFilterPopoverIsOpen] = useState(false);
92
98
  const [filterListIsOpen, setFilterListIsOpen] = useState(false);
93
99
  const [filterListAddFilterPopoverIsOpen, setFilterListAddFilterPopoverIsOpen,] = useState(false);
94
- const [uniqueCounter, setUniqueCounter] = useState(0);
95
- const userFilters = useMemo(() => {
96
- return (appliedFilters
97
- ?.map((filter, index) => {
98
- return { filter, index };
99
- })
100
- .filter((filter) => filter.filter.isUserFilter) ?? []);
101
- }, [appliedFilters]);
102
- const adminFilters = useMemo(() => {
103
- return appliedFilters?.filter((filter) => !filter.isUserFilter) ?? [];
104
- }, [appliedFilters]);
100
+ const presetOptions = useMemo(() => {
101
+ return populatedDashboardFilters?.[0]?.filterType === 'date_range'
102
+ ? populatedDashboardFilters[0].presetRanges?.map((elem) => {
103
+ if (!elem.isStatic) {
104
+ return {
105
+ label: elem.label,
106
+ value: elem.value,
107
+ startDate: PRIMARY_RANGE[elem.value].start,
108
+ endDate: PRIMARY_RANGE[elem.value].end,
109
+ };
110
+ }
111
+ return {
112
+ label: elem.label,
113
+ value: elem.value,
114
+ startDate: new Date(elem.startDate),
115
+ endDate: new Date(elem.endDate),
116
+ };
117
+ }) ?? defaultOptionsV2
118
+ : defaultOptionsV2;
119
+ }, [populatedDashboardFilters]);
120
+ const [userFilters, setUserFilters] = useState({});
121
+ // A filter value can either be a string, an array of strings for a multiselect, or a date range (that could have a comparison range)
122
+ const [filterValues, setFilterValues] = useState({});
105
123
  useEffect(() => {
124
+ setFilterValues({});
106
125
  reload(name, true);
107
- }, [name, client?.organizationId]);
126
+ }, [client?.organizationId]);
127
+ useEffect(() => {
128
+ setFilterValues({});
129
+ reload(name, false);
130
+ }, [name]);
108
131
  const customOperatorOptions = {
109
132
  [FieldTypes.Number]: [
110
133
  NumberOperator.EqualTo,
@@ -137,23 +160,6 @@ export default function Dashboard({ name, hidden = false, SelectComponent = Quil
137
160
  return;
138
161
  onDashboardDataChange(data, schemaData.schema);
139
162
  }, [data, filters, schemaData.schema]);
140
- useEffect(() => {
141
- if (isDashboardFiltersLoading)
142
- return;
143
- if (populatedDashboardFilters) {
144
- const newApplied = appliedFilters?.map((filter) => {
145
- if ((filter.options && filter.options.length) ||
146
- filter.isUserFilter) {
147
- return filter;
148
- }
149
- const equivalent = populatedDashboardFilters.find((populatedFilter) => populatedFilter._id === filter._id);
150
- return { ...filter, options: equivalent?.options ?? filter.options };
151
- }) ?? populatedDashboardFilters;
152
- if (!equal(appliedFilters, newApplied)) {
153
- setAppliedFilters(newApplied);
154
- }
155
- }
156
- }, [isDashboardFiltersLoading, populatedDashboardFilters]);
157
163
  // Go through all columns in the referenced tables and get the unique values to use in fieldValuesMap
158
164
  useEffect(() => {
159
165
  const fetchData = async () => {
@@ -174,7 +180,9 @@ export default function Dashboard({ name, hidden = false, SelectComponent = Quil
174
180
  setFieldValuesMap(newFieldValues);
175
181
  setFieldValuesIsLoaded(true);
176
182
  };
177
- fetchData();
183
+ if (data?.customFiltersEnabled) {
184
+ fetchData();
185
+ }
178
186
  }, [referencedTables]);
179
187
  // Get the relevant information from the dashboard and schema to pass to FilterModal
180
188
  const updateFilterSchema = (sections, schema) => {
@@ -225,107 +233,6 @@ export default function Dashboard({ name, hidden = false, SelectComponent = Quil
225
233
  const onDashboardDataChange = (resp, schema) => {
226
234
  // setDashboardSections(resp.sections ?? {});
227
235
  updateFilterSchema(resp.sections, schema);
228
- const filterArray = [];
229
- if (resp.dateFilter && Object.keys(resp.dateFilter).length) {
230
- let presetsOptions = defaultOptionsV2;
231
- if (resp.dateFilter.presetRanges) {
232
- presetsOptions = resp.dateFilter.presetRanges.map((elem) => {
233
- if (!elem.isStatic) {
234
- return {
235
- label: elem.label,
236
- value: elem.value,
237
- startDate: PRIMARY_RANGE[elem.value].start,
238
- endDate: PRIMARY_RANGE[elem.value].end,
239
- };
240
- }
241
- return {
242
- label: elem.label,
243
- value: elem.value,
244
- startDate: new Date(elem.startDate),
245
- endDate: new Date(elem.endDate),
246
- };
247
- });
248
- }
249
- setPresetFilters(presetsOptions);
250
- // Attempt to find a date filter in the current applied filters
251
- const currentDateFilter = appliedFilters?.find((filter) => filter.filterType === 'date_range');
252
- const key = currentDateFilter?.preset?.value ||
253
- resp.dateFilter?.primaryRange?.value ||
254
- 'LAST_6_MONTHS';
255
- const primaryPreset = presetsOptions.find((option) => {
256
- return option.value === key;
257
- });
258
- const filter = {
259
- startDate: primaryPreset.startDate,
260
- endDate: primaryPreset.endDate,
261
- filterType: 'date_range',
262
- options: presetsOptions.map((elem) => {
263
- return {
264
- label: elem.label,
265
- value: elem.value,
266
- };
267
- }),
268
- field: 'date_range',
269
- label: resp.dateFilter.label,
270
- preset: {
271
- label: primaryPreset.label,
272
- value: primaryPreset.value,
273
- },
274
- dashboardName: name,
275
- };
276
- if (resp.dateFilter.comparison) {
277
- filter.comparison = true;
278
- const compKey = resp.dateFilter.defaultComparisonRange ?? 'PREV_PERIOD';
279
- const range = { start: filter.startDate, end: filter.endDate };
280
- filter.comparisonRange = {
281
- startDate: COMPARISON_RANGE[compKey](range)?.start,
282
- endDate: COMPARISON_RANGE[compKey](range)?.end,
283
- value: compKey,
284
- };
285
- }
286
- else {
287
- filter.comparison = false;
288
- }
289
- filterArray.push(filter);
290
- }
291
- // Add string filters to filterArray
292
- if (resp.filters && resp.filters.length) {
293
- Object.values(resp.filters)
294
- .filter((filter) => filter.filterType !== 'date_range')
295
- .forEach((filter) => {
296
- let processedFilter = processFilter(filter);
297
- if (populatedDashboardFilters) {
298
- const equivalent = populatedDashboardFilters.find((populatedFilter) => populatedFilter._id === filter._id);
299
- processedFilter = {
300
- ...processedFilter,
301
- options: equivalent?.options ?? filter.options,
302
- };
303
- }
304
- filterArray.push(processedFilter);
305
- });
306
- }
307
- // Add custom filter to filterArray
308
- if (filters) {
309
- filters.forEach((filter) => {
310
- filterArray.push({
311
- ...filter,
312
- dashboardName: name,
313
- isUserFilter: true,
314
- });
315
- });
316
- }
317
- // remove all that are already present in dashboardSpecificFilters
318
- const dashboardSpecificFilters = dashboardFilters.filter((f) => f.dashboardName === name);
319
- if (!equal(dashboardSpecificFilters, filterArray)) {
320
- dashboardFiltersDispatch({
321
- type: 'CLEAR_AND_ADD_DASHBOARD_FILTERS',
322
- data: filterArray,
323
- dashboardName: name,
324
- });
325
- }
326
- if (!equal(appliedFilters, filterArray)) {
327
- setAppliedFilters(filterArray);
328
- }
329
236
  setInitialLoad(false);
330
237
  };
331
238
  const handleOnClickDashboardItem = (elem) => {
@@ -333,174 +240,87 @@ export default function Dashboard({ name, hidden = false, SelectComponent = Quil
333
240
  onClickReport({ ...elem, _id: elem.id });
334
241
  }
335
242
  };
336
- function removeQuotes(str) {
337
- if (str.startsWith('"') && str.endsWith('"')) {
338
- return str.slice(1, -1);
339
- }
340
- else {
341
- return str;
342
- }
343
- }
344
- const processFilter = (filter, value = null) => {
345
- //for dateObjects only, since values are arrays for dateObjects
346
- const { ...filterWithoutSelectedValue } = filter; // _ is a throwaway variable
347
- let selectedValue;
348
- let selectedElem;
349
- if (filter.filterType === 'string') {
350
- if (filter.options) {
351
- selectedElem = filter.options.find((elem) => elem[removeQuotes(filter.field)] === value);
352
- }
353
- if (selectedElem) {
354
- selectedValue = selectedElem[removeQuotes(filter.field)];
355
- }
356
- return {
357
- ...filterWithoutSelectedValue,
358
- ...(selectedValue ? { selectedValue } : {}),
359
- dashboardName: name,
360
- };
361
- }
362
- if (filter.filterType === 'date' || filter.filterType === 'date_range') {
363
- return {
364
- startDate: value ? value[0] : filter.startDate,
365
- endDate: value ? value[1] : filter.endDate,
366
- filterType: 'date_range',
367
- label: 'Date',
368
- field: 'date_range',
369
- options: filter.options,
370
- dashboardName: name,
371
- };
372
- }
373
- };
374
243
  const updateFilter = (filter, value = null, comparison = null) => {
375
- if (!appliedFilters) {
244
+ if (!populatedDashboardFilters)
376
245
  return;
377
- }
378
- //for dateObjects only, since values are arrays for dateObjects
379
- const { ...filterWithoutSelectedValue } = filter; // _ is a throwaway variable
246
+ let filterValue = {};
380
247
  if (filter.filterType === 'string') {
381
- let selectedValue = {};
382
248
  if (filter.stringFilterType === 'multiselect') {
383
249
  if ((value?.length ?? 0) === 0) {
384
- selectedValue = { values: [] };
250
+ filterValue = { values: undefined, operator: undefined };
385
251
  }
386
252
  else {
387
- selectedValue = { values: value, operator: 'IN' };
253
+ filterValue = { values: value, operator: 'IN' };
388
254
  }
389
255
  }
390
256
  else {
391
- selectedValue = { selectedValue: value };
257
+ filterValue = { selectedValue: value };
392
258
  }
393
- const newFilter = {
394
- ...filterWithoutSelectedValue,
395
- ...selectedValue,
396
- dashboardName: name,
397
- stringFilterType: filter.stringFilterType,
398
- table: filter.table,
399
- labelField: filter.labelField,
400
- label: filter.label,
401
- field: filter.field,
402
- filterType: DashboardFilterType.String,
403
- };
404
- dashboardFiltersDispatch({
405
- type: 'UPDATE_DASHBOARD_FILTER',
406
- id: filter.field,
407
- data: newFilter,
408
- });
409
- const index = appliedFilters.findIndex((filter) => filter.field === newFilter.field &&
410
- filter.dashboardName === newFilter.dashboardName);
411
- if (index !== -1) {
412
- setAppliedFilters([
413
- ...appliedFilters.slice(0, index),
414
- newFilter,
415
- ...appliedFilters.slice(index + 1),
416
- ]);
417
- }
418
- return;
259
+ setFilterValues((filterValues) => ({
260
+ ...filterValues,
261
+ [filter.label]: filterValue,
262
+ }));
419
263
  }
420
- if (filter.filterType === DashboardFilterType.Date) {
264
+ else if (filter.filterType === DashboardFilterType.Date) {
421
265
  if (comparison ||
422
- (filter.comparison && filter.comparisonRange.value !== 'NO_COMPARISON')) {
266
+ (filter.comparison &&
267
+ (filter.comparisonRange?.value ?? 'NO_COMPARISON') !==
268
+ 'NO_COMPARISON')) {
423
269
  let preset = '';
424
270
  if (comparison) {
425
- preset = filter.preset.label;
271
+ preset = filter.preset.value;
426
272
  }
427
- const key = comparison?.value || filter.comparisonRange.value;
273
+ const key = comparison?.value ||
274
+ (filter.comparisonRange?.value ?? 'NO_COMPARISON');
428
275
  let primaryRange = {
429
276
  start: value ? value.startDate : filter.startDate,
430
277
  end: value ? value.endDate : filter.endDate,
431
278
  };
432
279
  if (value && value.preset) {
433
280
  preset = value.preset;
434
- primaryRange = getRangeFromPresetOptions(value.preset, presetFilters);
281
+ primaryRange = getRangeFromPresetOptions(value.preset, presetOptions);
435
282
  }
436
- const newFilter = {
283
+ filterValue = {
437
284
  startDate: primaryRange.start,
438
285
  endDate: primaryRange.end,
439
- filterType: DashboardFilterType.Date,
440
- label: filter.label,
441
- field: 'date_range',
442
- preset: { label: preset, value: preset },
443
- options: filter.options,
444
- comparison: true,
286
+ preset: {
287
+ label: presetOptions.find((o) => o.value === preset)?.label ?? preset,
288
+ value: preset,
289
+ },
445
290
  comparisonRange: {
446
291
  startDate: COMPARISON_RANGE[key](primaryRange)?.start,
447
292
  endDate: COMPARISON_RANGE[key](primaryRange)?.end,
448
293
  value: key,
449
294
  },
450
- defaultComparisonRange: filter.defaultComparisonRange,
451
- primaryRange: filter.primaryRange,
452
- dashboardName: name,
453
295
  };
454
- dashboardFiltersDispatch({
455
- type: 'UPDATE_DASHBOARD_FILTER',
456
- id: 'date_range',
457
- data: newFilter,
458
- });
459
- const index = appliedFilters.findIndex((filter) => filter.field === newFilter.field &&
460
- filter.dashboardName === newFilter.dashboardName);
461
- if (index !== -1) {
462
- setAppliedFilters([
463
- ...appliedFilters.slice(0, index),
464
- newFilter,
465
- ...appliedFilters.slice(index + 1),
466
- ]);
467
- }
296
+ setFilterValues((filterValues) => ({
297
+ ...filterValues,
298
+ [filter.label]: filterValue,
299
+ }));
468
300
  }
469
301
  else {
470
302
  const primaryRange = value && value.preset
471
- ? getRangeFromPresetOptions(value.preset, presetFilters)
303
+ ? getRangeFromPresetOptions(value.preset, presetOptions)
472
304
  : {
473
305
  start: value?.startDate || filter.startDate,
474
306
  end: value?.endDate || filter.endDate,
475
307
  };
476
308
  const preset = value?.preset ? value.preset : '';
477
- const newFilter = {
478
- ...filter,
479
- preset: { label: preset, value: preset },
309
+ filterValue = {
480
310
  startDate: primaryRange.start,
481
311
  endDate: primaryRange.end,
482
- filterType: DashboardFilterType.Date,
483
- field: 'date_range',
484
- options: filter.options,
485
- label: filter.label,
486
- dashboardName: name,
312
+ preset: { label: preset, value: preset },
487
313
  };
488
- dashboardFiltersDispatch({
489
- type: 'UPDATE_DASHBOARD_FILTER',
490
- id: 'date_range',
491
- data: newFilter,
492
- });
493
- const index = appliedFilters.findIndex((filter) => filter.field === newFilter.field &&
494
- filter.dashboardName === newFilter.dashboardName);
495
- if (index !== -1) {
496
- setAppliedFilters([
497
- ...appliedFilters.slice(0, index),
498
- newFilter,
499
- ...appliedFilters.slice(index + 1),
500
- ]);
501
- }
314
+ setFilterValues((filterValues) => ({
315
+ ...filterValues,
316
+ [filter.label]: filterValue,
317
+ }));
502
318
  }
503
319
  }
320
+ reload(name, false, undefined, {
321
+ filters: populatedDashboardFilters.map((f) => filter.label === f.label ? { ...f, ...filterValue } : f),
322
+ editedFilterLabel: filter.label,
323
+ });
504
324
  };
505
325
  // generate the correct filter structure
506
326
  const getUserFilter = (filter, id, existingFilter) => {
@@ -525,34 +345,20 @@ export default function Dashboard({ name, hidden = false, SelectComponent = Quil
525
345
  return userFilter;
526
346
  };
527
347
  // new update filter function for user added filters
528
- const updateUserFilter = (filter, id) => {
529
- if (!appliedFilters) {
530
- return;
531
- }
532
- const newFilter = getUserFilter(filter, id);
533
- dashboardFiltersDispatch({
534
- type: 'ADD_DASHBOARD_FILTER',
535
- data: newFilter,
536
- });
537
- setAppliedFilters([...appliedFilters, newFilter]);
348
+ const updateUserFilter = (filter) => {
349
+ setUserFilters((userFilters) => ({
350
+ ...userFilters,
351
+ [filter.field]: filter,
352
+ }));
538
353
  };
539
354
  useEffect(() => {
540
355
  if (onChangeLoading) {
541
356
  onChangeLoading(isLoading || initialLoad);
542
357
  }
543
358
  }, [isLoading, initialLoad, onChangeLoading]);
544
- const sortByOrdering = (a, b) => {
545
- if (a.order === undefined && b.order === undefined)
546
- return 0;
547
- if (a.order === undefined)
548
- return 1;
549
- if (b.order === undefined)
550
- return -1;
551
- return a.order - b.order;
552
- };
553
359
  if (!isLoading &&
554
360
  (Object.keys(data?.sections ?? {}).length === 0 ||
555
- data?.sections?.['']?.length === 0)) {
361
+ Object.values(data?.sections ?? {})[0]?.length === 0)) {
556
362
  return _jsx(EmptyDashboardComponent, {});
557
363
  }
558
364
  if (hidden || isLoading || isClientLoading || !data?.sections) {
@@ -566,7 +372,13 @@ export default function Dashboard({ name, hidden = false, SelectComponent = Quil
566
372
  data &&
567
373
  data.customFiltersEnabled &&
568
374
  filterSchema &&
569
- filterSchema.columns.length === 0 && (_jsx("div", { style: { marginBottom: 10 }, children: _jsx(QuillErrorMessageComponent, { errorMessage: "Warning: No custom filter options because there are no common views among the charts in the dashboard" }) })), _jsxs("div", { style: { display: 'flex', flexDirection: 'row', alignItems: 'center' }, children: [!hideFilters && (_jsxs(FilterContainerComponent, { children: [adminFilters.map((filter, index) => (_jsx(DashboardFilter, { filter: filter, onChangeFilter: updateFilter, theme: theme, SelectComponent: SelectComponent, MultiSelectComponent: MultiSelectComponent, DateRangePickerComponent: DateRangePickerComponent, isLoading: isDashboardFiltersLoading }, filter._id ?? index))), _jsxs("div", { style: {
375
+ filterSchema.columns.length === 0 && (_jsx("div", { style: { marginBottom: 10 }, children: _jsx(QuillErrorMessageComponent, { errorMessage: "Warning: No custom filter options because there are no common views among the charts in the dashboard" }) })), _jsxs("div", { style: { display: 'flex', flexDirection: 'row', alignItems: 'center' }, children: [!hideFilters && (_jsxs(FilterContainerComponent, { children: [(populatedDashboardFilters ?? []).map((filter) => (_jsx(DashboardFilter, { filter: {
376
+ ...filter,
377
+ ...(filter.filterType === 'date_range' && {
378
+ options: presetOptions,
379
+ }),
380
+ ...filterValues[filter.label],
381
+ }, onChangeFilter: updateFilter, theme: theme, SelectComponent: SelectComponent, MultiSelectComponent: MultiSelectComponent, DateRangePickerComponent: DateRangePickerComponent, isLoading: isDashboardFilterLoading(filter.label) }, filter.label + name))), _jsxs("div", { style: {
570
382
  display: 'flex',
571
383
  flexDirection: 'column',
572
384
  }, children: [data && data.customFiltersEnabled && (_jsx(SecondaryButtonComponent, { onClick: () => {
@@ -576,14 +388,12 @@ export default function Dashboard({ name, hidden = false, SelectComponent = Quil
576
388
  }
577
389
  }, label: `Add Filter` })), _jsx(PopoverComponent, { isOpen: addFilterPopoverIsOpen, setIsOpen: setAddFilterPopoverIsOpen, popoverTitle: "Add Filter", popoverChildren: _jsx(FilterModal, { schema: filterSchema, fieldValuesMap: fieldValuesMap, onSubmitFilter: (filter) => {
578
390
  setAddFilterPopoverIsOpen(false);
579
- if (appliedFilters) {
580
- updateUserFilter(filter, appliedFilters.length);
581
- }
582
- }, onDeleteFilter: () => { }, ButtonComponent: ButtonComponent, SelectComponent: SelectComponent, MultiSelectComponent: MultiSelectComponent, TextInputComponent: TextInputComponent }), containerStyle: { position: 'relative', top: 10 } })] }), userFilters.length > 0 && (_jsx(ModalComponent, { triggerLabel: `Filters${userFilters.length > 0 ? ` (${userFilters.length})` : ''}`, isOpen: filterListIsOpen, setIsOpen: setFilterListIsOpen, title: "Filters", children: _jsxs("div", { style: {
391
+ updateUserFilter(filter);
392
+ }, onDeleteFilter: () => { }, ButtonComponent: ButtonComponent, SelectComponent: SelectComponent, MultiSelectComponent: MultiSelectComponent, TextInputComponent: TextInputComponent }), containerStyle: { position: 'relative', top: 10 } })] }), Object.values(userFilters).length > 0 && (_jsx(ModalComponent, { triggerLabel: `Filters${Object.values(userFilters).length > 0 ? ` (${Object.values(userFilters).length})` : ''}`, isOpen: filterListIsOpen, setIsOpen: setFilterListIsOpen, title: "Filters", children: _jsxs("div", { style: {
583
393
  display: 'flex',
584
394
  flexDirection: 'column',
585
395
  alignItems: 'start',
586
- }, children: [userFilters.map(({ filter, index }) => (_jsx(FilterPopoverWrapper, { schema: filterSchema, filter: {
396
+ }, children: [Object.values(userFilters).map((filter, index) => (_jsx(FilterPopoverWrapper, { schema: filterSchema, filter: {
587
397
  filterType: filter.filterType,
588
398
  fieldType: filter.fieldType,
589
399
  field: filter.field,
@@ -591,31 +401,17 @@ export default function Dashboard({ name, hidden = false, SelectComponent = Quil
591
401
  value: filter.value,
592
402
  }, filterLabel: filter ? filterSentence(filter) : '', index: index, fieldValuesMap: fieldValuesMap, customOperatorOptions: customOperatorOptions, FilterTagComponent: FilterTagComponent, FilterModal: FilterModal, ButtonComponent: ButtonComponent, SecondaryButtonComponent: SecondaryButtonComponent, SelectComponent: SelectComponent, TextInputComponent: TextInputComponent, MultiSelectComponent: MultiSelectComponent, handleFilterSave: (newFilter) => {
593
403
  const updatedFilter = getUserFilter(newFilter, filter._id, filter);
594
- if (!appliedFilters) {
595
- return;
596
- }
597
404
  dashboardFiltersDispatch({
598
405
  type: 'UPDATE_DASHBOARD_FILTER',
599
406
  id: updatedFilter._id,
600
407
  data: updateFilter,
601
408
  });
602
- setAppliedFilters([
603
- ...appliedFilters.slice(0, index),
604
- updatedFilter,
605
- ...appliedFilters.slice(index + 1),
606
- ]);
607
409
  }, handleFilterDelete: () => {
608
- if (!appliedFilters) {
609
- return;
610
- }
611
- dashboardFiltersDispatch({
612
- type: 'DELETE_DASHBOARD_FILTER',
613
- id: appliedFilters[index]._id,
410
+ setUserFilters((userFilters) => {
411
+ const updatedFilters = { ...userFilters };
412
+ delete updatedFilters[filter.field];
413
+ return updatedFilters;
614
414
  });
615
- setAppliedFilters([
616
- ...appliedFilters.slice(0, index),
617
- ...appliedFilters.slice(index + 1),
618
- ]);
619
415
  }, containerStyle: { width: 300, marginBottom: 10 } }, `userFilter_${index}_${filter ? filterSentence(filter) : ''}`))), _jsxs("div", { style: {
620
416
  display: 'flex',
621
417
  flexDirection: 'column',
@@ -626,10 +422,8 @@ export default function Dashboard({ name, hidden = false, SelectComponent = Quil
626
422
  }, label: `Add Filter` }), _jsx(PopoverComponent, { isOpen: filterListAddFilterPopoverIsOpen, setIsOpen: setFilterListAddFilterPopoverIsOpen, popoverTitle: "Add Filter", popoverChildren: _jsx(FilterModal, { schema: filterSchema, fieldValuesMap: fieldValuesMap, onSubmitFilter: (filter) => {
627
423
  setFilterListAddFilterPopoverIsOpen(false);
628
424
  setFilterListIsOpen(false);
629
- const id = uniqueCounter;
630
- setUniqueCounter(uniqueCounter + 1);
631
- updateUserFilter(filter, id);
632
- }, onDeleteFilter: () => { }, ButtonComponent: ButtonComponent, SelectComponent: SelectComponent, MultiSelectComponent: MultiSelectComponent, TextInputComponent: TextInputComponent }), containerStyle: { position: 'relative', top: 10 } })] })] }) }))] })), templateDashboardName && (_jsx(QuillDashboardTemplate, { name: templateDashboardName, originDashboard: name, client: client, appliedFilters: appliedFilters, ModalComponent: ModalComponent, TemplateChartComponent: TemplateChartComponent, TemplateMetricComponent: TemplateMetricComponent, TemplateTableComponent: TemplateTableComponent, ButtonComponent: SecondaryButtonComponent }))] }), Object.keys(data.sections)
425
+ updateUserFilter(filter);
426
+ }, onDeleteFilter: () => { }, ButtonComponent: ButtonComponent, SelectComponent: SelectComponent, MultiSelectComponent: MultiSelectComponent, TextInputComponent: TextInputComponent }), containerStyle: { position: 'relative', top: 10 } })] })] }) }))] })), templateDashboardName && (_jsx(QuillDashboardTemplate, { name: templateDashboardName, originDashboard: name, client: client, appliedFilters: populatedDashboardFilters, ModalComponent: ModalComponent, TemplateChartComponent: TemplateChartComponent, TemplateMetricComponent: TemplateMetricComponent, TemplateTableComponent: TemplateTableComponent, ButtonComponent: SecondaryButtonComponent }))] }), Object.keys(data.sections)
633
427
  .sort(function (a, b) {
634
428
  return a.length - b.length;
635
429
  })
@@ -643,13 +437,13 @@ export default function Dashboard({ name, hidden = false, SelectComponent = Quil
643
437
  textAlign: 'left',
644
438
  marginTop: 12,
645
439
  }, children: section })] })), metrics(data.sections, section, sortByOrdering).length > 0 && (_jsx(DashboardSectionComponent, { section: "metrics", children: metrics(data.sections, section, sortByOrdering).map((item, index) => {
646
- return (_jsx(DataLoader, { item: item, filters: appliedFilters, children: ({ isLoading, error, data, }) => (_jsx(MetricComponent, { error: error, isLoading: isLoading, report: data, onClick: !isLoading && onClickReport
440
+ return (_jsx(DataLoader, { item: item, filters: populatedDashboardFilters, children: ({ isLoading, error, data, }) => (_jsx(MetricComponent, { error: error, isLoading: isLoading, report: data, onClick: !isLoading && onClickReport
647
441
  ? () => handleOnClickDashboardItem({
648
442
  ...item,
649
443
  ...data,
650
444
  })
651
- : () => { }, hoverActions: hoverActions }, item.name + '' + index)) }, `${item._id}${index}`));
652
- }) })), charts(data.sections, section, sortByOrdering).length > 0 && (_jsx(DashboardSectionComponent, { section: "charts", children: charts(data.sections, section, sortByOrdering).map((item, index) => (_jsx(ChartDataLoader, { item: item, dateBucket: dateBucket, additionalProcessing: additionalProcessing, filters: appliedFilters, children: ({ isLoading, data, error, dateBucket, }) => (_jsx(ChartComponent, { report: data, error: error, onClick: () => {
445
+ : () => { }, hoverActions: hoverActions }, item.name + '' + index)) }, `metric${index}`));
446
+ }) })), charts(data.sections, section, sortByOrdering).length > 0 && (_jsx(DashboardSectionComponent, { section: "charts", children: charts(data.sections, section, sortByOrdering).map((item, index) => (_jsx(ChartDataLoader, { item: item, dateBucket: dateBucket, additionalProcessing: additionalProcessing, filters: populatedDashboardFilters, children: ({ isLoading, data, error, dateBucket, }) => (_jsx(ChartComponent, { report: data, error: error, onClick: () => {
653
447
  if (!isLoading && onClickReport) {
654
448
  handleOnClickDashboardItem({
655
449
  ...item,
@@ -661,7 +455,7 @@ export default function Dashboard({ name, hidden = false, SelectComponent = Quil
661
455
  height: 300,
662
456
  } })) : (_jsx(ChartDisplay, { reportId: data.id, config: data, loading: isLoading, containerStyle: chartContainerStyle, colors: theme.chartColors?.length
663
457
  ? theme.chartColors
664
- : undefined, scrollable: false, hideXAxis: hideXAxis, hideYAxis: hideYAxis, hideCartesianGrid: hideCartesianGrid, comparisonLineStyle: comparisonLineStyle, onClickChartElement: onClickChartElement })) }, item.name + '' + index)) }, `${item._id}${index}`))) })), tables(data.sections, section, sortByOrdering).length > 0 && (_jsx(DashboardSectionComponent, { section: "tables", children: tables(data.sections, section, sortByOrdering).map((item, index) => (_jsx(DataLoader, { item: item, filters: appliedFilters, children: ({ isLoading, error, onPageChange, onSortChange, data, rowCount, rowCountIsLoading, }) => (_jsx(TableComponent, { report: data, isLoading: isLoading, error: error, onClick: !isLoading && onClickReport
458
+ : undefined, scrollable: false, hideXAxis: hideXAxis, hideYAxis: hideYAxis, hideCartesianGrid: hideCartesianGrid, comparisonLineStyle: comparisonLineStyle, onClickChartElement: onClickChartElement })) }, item.name + '' + index)) }, `chart${index}`))) })), tables(data.sections, section, sortByOrdering).length > 0 && (_jsx(DashboardSectionComponent, { section: "tables", children: tables(data.sections, section, sortByOrdering).map((item, index) => (_jsx(DataLoader, { item: item, filters: populatedDashboardFilters, children: ({ isLoading, error, onPageChange, onSortChange, data, rowCount, rowCountIsLoading, }) => (_jsx(TableComponent, { report: data, isLoading: isLoading, error: error, onClick: !isLoading && onClickReport
665
459
  ? () => handleOnClickDashboardItem({
666
460
  ...item,
667
461
  ...data,
@@ -669,6 +463,6 @@ export default function Dashboard({ name, hidden = false, SelectComponent = Quil
669
463
  : undefined, hoverActions: hoverActions, rowCount: rowCount ??
670
464
  data?.rowCount ??
671
465
  data?.rows?.length ??
672
- 0, rowCountIsLoading: rowCountIsLoading, onPageChange: (page) => onPageChange(page), onSortChange: (sort) => onSortChange(sort) })) }, `${item._id}${index}`))) }))] }, section + '' + sectionIndex));
466
+ 0, rowCountIsLoading: rowCountIsLoading, onPageChange: (page) => onPageChange(page), onSortChange: (sort) => onSortChange(sort) })) }, `${name}${index}`))) }))] }, section + '' + sectionIndex));
673
467
  })] }));
674
468
  }
@@ -1 +1 @@
1
- {"version":3,"file":"QuillDateRangePicker.d.ts","sourceRoot":"","sources":["../../../src/DateRangePicker/QuillDateRangePicker.tsx"],"names":[],"mappings":"AAAA,OAAc,EACZ,WAAW,EAKZ,MAAM,OAAO,CAAC;AAmBf,MAAM,WAAW,6BAA6B;IAC5C,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE;QAAE,SAAS,EAAE,IAAI,CAAC;QAAC,OAAO,EAAE,IAAI,CAAA;KAAE,CAAC;IAC9C,aAAa,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAClD,iBAAiB,EAAE,CAAC,EAClB,SAAS,EACT,OAAO,GACR,EAAE;QACD,SAAS,EAAE,IAAI,CAAC;QAChB,OAAO,EAAE,IAAI,CAAC;KACf,KAAK,IAAI,CAAC;IACX,cAAc,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAC;IAChE,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,EAAE,IAAI,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,MAAM,EACN,KAAK,EACL,WAAW,EACX,UAAU,GACX,EAAE,6BAA6B,2CAgI/B"}
1
+ {"version":3,"file":"QuillDateRangePicker.d.ts","sourceRoot":"","sources":["../../../src/DateRangePicker/QuillDateRangePicker.tsx"],"names":[],"mappings":"AAAA,OAAc,EACZ,WAAW,EAKZ,MAAM,OAAO,CAAC;AAmBf,MAAM,WAAW,6BAA6B;IAC5C,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE;QAAE,SAAS,EAAE,IAAI,CAAC;QAAC,OAAO,EAAE,IAAI,CAAA;KAAE,CAAC;IAC9C,aAAa,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAClD,iBAAiB,EAAE,CAAC,EAClB,SAAS,EACT,OAAO,GACR,EAAE;QACD,SAAS,EAAE,IAAI,CAAC;QAChB,OAAO,EAAE,IAAI,CAAC;KACf,KAAK,IAAI,CAAC;IACX,cAAc,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAC;IAChE,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,MAAM,SAAS,GAAG;IACtB,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,EAAE,IAAI,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,OAAO,CAAC,EAAE,IAAI,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,EACnC,SAAS,EACT,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,MAAM,EACN,KAAK,EACL,WAAW,EACX,UAAU,GACX,EAAE,6BAA6B,2CA2I/B"}