@cdc/dashboard 4.26.1 → 4.26.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.
Files changed (39) hide show
  1. package/dist/cdcdashboard-8NmHlKRI.es.js +15 -0
  2. package/dist/cdcdashboard-BPoPzKPz.es.js +6 -0
  3. package/dist/cdcdashboard-Cf9_fbQf.es.js +6 -0
  4. package/dist/{cdcdashboard-dgT_1dIT.es.js → cdcdashboard-DQ00cQCm.es.js} +1 -20
  5. package/dist/cdcdashboard-jiQQPkty.es.js +6 -0
  6. package/dist/cdcdashboard.js +59394 -65183
  7. package/examples/default.json +522 -133
  8. package/examples/nested-dropdown.json +6985 -0
  9. package/examples/private/abc.json +467 -0
  10. package/examples/private/dash.json +12696 -0
  11. package/examples/private/npcr.json +1 -0
  12. package/examples/private/test.json +125407 -0
  13. package/examples/private/timeline-data.json +4994 -0
  14. package/examples/private/timeline.json +1708 -0
  15. package/examples/test-api-filter-reset.json +8 -4
  16. package/examples/tp5-gauges.json +196 -0
  17. package/examples/tp5-test.json +266 -0
  18. package/index.html +1 -29
  19. package/package.json +38 -40
  20. package/src/CdcDashboardComponent.tsx +0 -3
  21. package/src/_stories/Dashboard.DataSetup.stories.tsx +2 -1
  22. package/src/_stories/Dashboard.stories.tsx +27 -5
  23. package/src/_stories/_mock/dashboard-line-chart-angles.json +1030 -0
  24. package/src/_stories/_mock/tp5-test.json +267 -0
  25. package/src/components/DashboardFilters/DashboardFiltersEditor/DashboardFiltersEditor.tsx +3 -0
  26. package/src/components/DashboardFilters/DashboardFiltersEditor/components/FilterEditor.tsx +5 -1
  27. package/src/components/DashboardFilters/DashboardFiltersEditor/components/NestedDropDownDashboard.tsx +5 -1
  28. package/src/components/VisualizationRow.tsx +30 -25
  29. package/src/components/VisualizationsPanel/VisualizationsPanel.tsx +0 -17
  30. package/src/helpers/addValuesToDashboardFilters.ts +17 -11
  31. package/src/helpers/apiFilterHelpers.ts +28 -32
  32. package/src/helpers/tests/addValuesToDashboardFilters.test.ts +141 -44
  33. package/src/helpers/tests/apiFilterHelpers.test.ts +523 -420
  34. package/src/scss/main.scss +8 -5
  35. package/vite.config.js +7 -1
  36. package/dist/cdcdashboard-BnB1QM5d.es.js +0 -361528
  37. package/dist/cdcdashboard-Ct2SB0vL.es.js +0 -231049
  38. package/dist/cdcdashboard-D6CG2-Hb.es.js +0 -39377
  39. package/dist/cdcdashboard-MXgURbdZ.es.js +0 -39194
@@ -1,44 +1,141 @@
1
- import { SharedFilter } from '../../types/SharedFilter'
2
- import { addValuesToDashboardFilters } from '../addValuesToDashboardFilters'
3
-
4
- describe('addValuesToDashboardFilters', () => {
5
- const colA = { columnName: 'colA', id: 11, active: 'apple', values: [], type: 'datafilter' } as SharedFilter
6
- const colB = { columnName: 'colB', id: 22, active: '1', values: [], type: 'datafilter' } as SharedFilter
7
- const colC = { columnName: 'colC', id: 33, values: [], setByQueryParameter: 'colC', type: 'datafilter' } as SharedFilter
8
-
9
- const data = {
10
- key: [
11
- { colA: 'apple', colB: 3, colC: 'abc' },
12
- { colA: 'apple', colB: 1, colC: 'bcd' },
13
- { colA: 'pear', colB: 4, colC: 'test' }
14
- ]
15
- }
16
- const filters = [colA, colC, colB]
17
- it('adds filter values', () => {
18
- const newFilters = addValuesToDashboardFilters(filters, data)
19
- expect(newFilters[0].values).toEqual(['apple', 'pear'])
20
- })
21
- it('converts to multiselect', () => {
22
- colA.multiSelect = true
23
- const newFilters = addValuesToDashboardFilters(filters, data)
24
- expect(newFilters[0].active).toEqual(['apple'])
25
- })
26
-
27
- it('sets active value by query string', () => {
28
- delete window.location
29
- window.location = new URL('https://www.example.com?colC=test')
30
- const newFilters = addValuesToDashboardFilters(filters, data)
31
- expect(newFilters[1].active).toEqual('test')
32
- })
33
- const colA2 = { apiFilter: { valueSelector: 'colA' }, id: 11, active: 'apple', values: [], type: 'urlfilter' } as SharedFilter
34
- const colB2 = { apiFilter: { valueSelector: 'colB' }, id: 22, active: '1', values: [], type: 'urlfilter' } as SharedFilter
35
- const colC2 = { apiFilter: { valueSelector: 'colC' }, id: 33, values: [], setByQueryParameter: 'colC', type: 'urlfilter' } as SharedFilter
36
- const filters2 = [colA2, colC2, colB2]
37
- it('skips urlfilters', () => {
38
- // urlfilter reloading happens in the dashboard in the loadAPIFilters function
39
- delete window.location
40
- window.location = new URL('https://www.example.com?colC=test')
41
- const newFilters = addValuesToDashboardFilters(filters2, data)
42
- expect(newFilters[1].active).toEqual(undefined)
43
- })
44
- })
1
+ import { SharedFilter } from '../../types/SharedFilter'
2
+ import { addValuesToDashboardFilters } from '../addValuesToDashboardFilters'
3
+
4
+ describe('addValuesToDashboardFilters', () => {
5
+ const colA = { columnName: 'colA', id: 11, active: 'apple', values: [], type: 'datafilter' } as SharedFilter
6
+ const colB = { columnName: 'colB', id: 22, active: '1', values: [], type: 'datafilter' } as SharedFilter
7
+ const colC = {
8
+ columnName: 'colC',
9
+ id: 33,
10
+ values: [],
11
+ setByQueryParameter: 'colC',
12
+ type: 'datafilter'
13
+ } as SharedFilter
14
+
15
+ const data = {
16
+ key: [
17
+ { colA: 'apple', colB: 3, colC: 'abc' },
18
+ { colA: 'apple', colB: 1, colC: 'bcd' },
19
+ { colA: 'pear', colB: 4, colC: 'test' }
20
+ ]
21
+ }
22
+ const filters = [colA, colC, colB]
23
+ it('adds filter values', () => {
24
+ const newFilters = addValuesToDashboardFilters(filters, data)
25
+ expect(newFilters[0].values).toEqual(['apple', 'pear'])
26
+ })
27
+ it('converts to multiselect', () => {
28
+ colA.multiSelect = true
29
+ const newFilters = addValuesToDashboardFilters(filters, data)
30
+ expect(newFilters[0].active).toEqual(['apple'])
31
+ })
32
+
33
+ it('sets active value by query string', () => {
34
+ delete window.location
35
+ window.location = new URL('https://www.example.com?colC=test')
36
+ const newFilters = addValuesToDashboardFilters(filters, data)
37
+ expect(newFilters[1].active).toEqual('test')
38
+ })
39
+ const colA2 = {
40
+ apiFilter: { valueSelector: 'colA' },
41
+ id: 11,
42
+ active: 'apple',
43
+ values: [],
44
+ type: 'urlfilter'
45
+ } as SharedFilter
46
+ const colB2 = {
47
+ apiFilter: { valueSelector: 'colB' },
48
+ id: 22,
49
+ active: '1',
50
+ values: [],
51
+ type: 'urlfilter'
52
+ } as SharedFilter
53
+ const colC2 = {
54
+ apiFilter: { valueSelector: 'colC' },
55
+ id: 33,
56
+ values: [],
57
+ setByQueryParameter: 'colC',
58
+ type: 'urlfilter'
59
+ } as SharedFilter
60
+ const filters2 = [colA2, colC2, colB2]
61
+ it('skips urlfilters', () => {
62
+ // urlfilter reloading happens in the dashboard in the loadAPIFilters function
63
+ delete window.location
64
+ window.location = new URL('https://www.example.com?colC=test')
65
+ const newFilters = addValuesToDashboardFilters(filters2, data)
66
+ expect(newFilters[1].active).toEqual(undefined)
67
+ })
68
+
69
+ it('respects nested dropdown default values for both group and subgroup', () => {
70
+ const nestedData = {
71
+ key: [
72
+ { year: '2022', quarter: 'Q1', region: 'North' },
73
+ { year: '2022', quarter: 'Q2', region: 'North' },
74
+ { year: '2023', quarter: 'Q1', region: 'North' },
75
+ { year: '2023', quarter: 'Q2', region: 'North' },
76
+ { year: '2023', quarter: 'Q3', region: 'North' },
77
+ { year: '2024', quarter: 'Q1', region: 'North' }
78
+ ]
79
+ }
80
+
81
+ const nestedFilter = {
82
+ columnName: 'year',
83
+ id: 1,
84
+ values: ['2022', '2023', '2024'],
85
+ type: 'datafilter',
86
+ filterStyle: 'nested-dropdown',
87
+ defaultValue: '2023',
88
+ subGrouping: {
89
+ columnName: 'quarter',
90
+ defaultValue: 'Q2',
91
+ valuesLookup: {
92
+ '2022': { values: ['Q1', 'Q2'] },
93
+ '2023': { values: ['Q1', 'Q2', 'Q3'] },
94
+ '2024': { values: ['Q1'] }
95
+ }
96
+ }
97
+ } as SharedFilter
98
+
99
+ const result = addValuesToDashboardFilters([nestedFilter], nestedData)
100
+
101
+ // Should use configured defaultValue for main group
102
+ expect(result[0].active).toBe('2023')
103
+
104
+ // Should use configured defaultValue for subgroup
105
+ expect(result[0].subGrouping.active).toBe('Q2')
106
+ })
107
+
108
+ it('uses first available subgroup value when defaultValue is not in current group', () => {
109
+ const nestedData = {
110
+ key: [
111
+ { year: '2022', quarter: 'Q1', region: 'North' },
112
+ { year: '2024', quarter: 'Q1', region: 'North' }
113
+ ]
114
+ }
115
+
116
+ const nestedFilter = {
117
+ columnName: 'year',
118
+ id: 1,
119
+ values: ['2022', '2024'],
120
+ type: 'datafilter',
121
+ filterStyle: 'nested-dropdown',
122
+ defaultValue: '2024',
123
+ subGrouping: {
124
+ columnName: 'quarter',
125
+ defaultValue: 'Q2', // Q2 doesn't exist for 2024
126
+ valuesLookup: {
127
+ '2022': { values: ['Q1'] },
128
+ '2024': { values: ['Q1'] }
129
+ }
130
+ }
131
+ } as SharedFilter
132
+
133
+ const result = addValuesToDashboardFilters([nestedFilter], nestedData)
134
+
135
+ // Should use configured defaultValue for main group
136
+ expect(result[0].active).toBe('2024')
137
+
138
+ // Should fall back to first available value since Q2 doesn't exist for 2024
139
+ expect(result[0].subGrouping.active).toBe('Q1')
140
+ })
141
+ })