@cdc/dashboard 4.24.3 → 4.24.4

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 (34) hide show
  1. package/dist/cdcdashboard.js +119414 -103311
  2. package/examples/chart-data.json +5409 -0
  3. package/examples/full-dash-test.json +14643 -0
  4. package/examples/full-dashboard.json +10036 -0
  5. package/index.html +2 -2
  6. package/package.json +9 -9
  7. package/src/CdcDashboard.tsx +8 -3
  8. package/src/CdcDashboardComponent.tsx +232 -344
  9. package/src/_stories/Dashboard.stories.tsx +59 -38
  10. package/src/_stories/_mock/api-filter-chart.json +11 -35
  11. package/src/_stories/_mock/api-filter-map.json +17 -31
  12. package/src/_stories/_mock/dashboard-gallery.json +523 -534
  13. package/src/_stories/_mock/multi-viz.json +378 -0
  14. package/src/_stories/_mock/pivot-filter.json +0 -2
  15. package/src/components/DataDesignerModal.tsx +145 -0
  16. package/src/components/Grid.tsx +3 -1
  17. package/src/components/Header/FilterModal.tsx +49 -23
  18. package/src/components/Row.tsx +50 -25
  19. package/src/components/Toggle/Toggle.tsx +6 -7
  20. package/src/components/VisualizationRow.tsx +174 -0
  21. package/src/components/Widget.tsx +21 -103
  22. package/src/helpers/filterData.ts +16 -14
  23. package/src/helpers/getFilteredData.ts +39 -0
  24. package/src/helpers/getUpdateConfig.ts +15 -0
  25. package/src/helpers/getVizConfig.ts +31 -0
  26. package/src/helpers/getVizRowColumnLocator.ts +9 -0
  27. package/src/scss/grid.scss +9 -2
  28. package/src/scss/main.scss +5 -0
  29. package/src/store/dashboard.actions.ts +16 -1
  30. package/src/store/dashboard.reducer.ts +25 -2
  31. package/src/types/APIFilter.ts +4 -5
  32. package/src/types/ConfigRow.ts +12 -3
  33. package/src/types/DataSet.ts +11 -8
  34. package/src/types/SharedFilter.ts +1 -1
@@ -1,16 +1,19 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react'
2
+ import { faker } from '@faker-js/faker'
2
3
  import APIFiltersMapData from './_mock/api-filter-map.json'
3
4
  import APIFiltersChartData from './_mock/api-filter-chart.json'
4
5
  import ExampleConfig_1 from './_mock/dashboard-gallery.json'
5
6
  import ExampleConfig_2 from './_mock/dashboard-2.json'
6
7
  import ExampleConfig_3 from './_mock/dashboard_no_filter.json'
7
8
  import Dashboard_Filter from './_mock/dashboard-filter.json'
9
+ import MultiVizConfig from './_mock/multi-viz.json'
8
10
  import Dashboard from '../CdcDashboard'
9
11
  import StandaloneTable from './_mock/standalone-table.json'
10
12
  import PivotFitlerConfig from './_mock/pivot-filter.json'
11
13
  import { type DashboardConfig as Config } from '../types/DashboardConfig'
12
14
  import { userEvent, within } from '@storybook/testing-library'
13
15
  import ToggleExampleConfig from './_mock/toggle-example.json'
16
+ import _ from 'lodash'
14
17
 
15
18
  const meta: Meta<typeof Dashboard> = {
16
19
  title: 'Components/Pages/Dashboard',
@@ -21,44 +24,78 @@ type Story = StoryObj<typeof Dashboard>
21
24
 
22
25
  export const Example_1: Story = {
23
26
  args: {
24
- config: ExampleConfig_1
27
+ config: ExampleConfig_1,
28
+ isEditor: false
25
29
  }
26
30
  }
27
31
 
28
32
  export const Example_2: Story = {
29
33
  args: {
30
- config: ExampleConfig_2
34
+ config: ExampleConfig_2,
35
+ isEditor: false
31
36
  }
32
37
  }
33
38
 
34
39
  export const Example_3: Story = {
35
40
  args: {
36
- config: ExampleConfig_3
41
+ config: ExampleConfig_3,
42
+ isEditor: false
37
43
  }
38
44
  }
39
45
 
40
46
  export const Dashboard_Filters: Story = {
41
47
  args: {
42
- config: Dashboard_Filter
48
+ config: Dashboard_Filter,
49
+ isEditor: false
43
50
  }
44
51
  }
45
52
 
46
53
  export const StandAloneTable: Story = {
47
54
  args: {
48
- config: StandaloneTable
55
+ config: StandaloneTable,
56
+ isEditor: false
49
57
  }
50
58
  }
51
59
 
52
60
  export const ToggleExample: Story = {
53
61
  args: {
54
62
  config: ToggleExampleConfig,
55
- isEditor: true
63
+ isEditor: false
56
64
  }
57
65
  }
58
66
 
59
67
  export const PivotFilter: Story = {
60
68
  args: {
61
- config: PivotFitlerConfig
69
+ config: PivotFitlerConfig,
70
+ isEditor: false
71
+ }
72
+ }
73
+
74
+ faker.seed(123)
75
+
76
+ const countries = _.times(5, faker.location.country)
77
+ const categories = _.times(3, val => `category-${val + 1}`)
78
+
79
+ const data = []
80
+ countries.forEach((country, i) => {
81
+ categories.forEach((category, j) => {
82
+ if ((i + j) % 3 === 0) return
83
+ data.push({
84
+ Country: country,
85
+ 'Sample Categories': category,
86
+ Data: faker.number.int({ min: 5, max: 50 })
87
+ })
88
+ })
89
+ })
90
+
91
+ const multiVizData = {
92
+ 'valid-world-data.json': { data }
93
+ }
94
+
95
+ export const MultiVisualization: Story = {
96
+ args: {
97
+ config: { ...MultiVizConfig, datasets: multiVizData },
98
+ isEditor: false
62
99
  }
63
100
  }
64
101
 
@@ -88,35 +125,18 @@ const fetchMock = {
88
125
  body: [{ IndicatorID: 'indicatorID', Indicator: 'Some Indicator' }]
89
126
  }
90
127
  },
91
- {
92
- matcher: {
93
- name: 'filters',
94
- url: 'path:/api/POC/Filters'
95
- },
96
- response: {
97
- status: 200,
98
- body: {
99
- Years: [{ Year: 1999 }],
100
- DataValueTypes: [{ DataValueType: 'Some Data Value Type', DataValueTypeId: 'dataValueTypeId' }],
101
- StratificationCategories: [{ StratificationCategoryId: 'stratCategoryId', StratificationCategory: 'Some Strat Category' }]
128
+ ...['Year', 'DataValueType', 'StratificationCategory', 'Stratification'].map(filter => {
129
+ return {
130
+ matcher: {
131
+ name: 'filters' + filter,
132
+ url: 'path:/api/POC/Filters/' + filter
133
+ },
134
+ response: {
135
+ status: 200,
136
+ body: _.times(5, i => ({ [filter]: `Some ${filter} ${i}` }))
102
137
  }
103
138
  }
104
- },
105
- {
106
- matcher: {
107
- name: 'stratifications',
108
- url: 'path:/api/POC/stratifications'
109
- },
110
- response: {
111
- status: 200,
112
- body: [
113
- {
114
- StratificationId: 'stratId',
115
- Stratification: 'Some Strat'
116
- }
117
- ]
118
- }
119
- },
139
+ }),
120
140
  {
121
141
  matcher: {
122
142
  name: 'locations',
@@ -185,11 +205,11 @@ export const APIFiltersMap: Story = {
185
205
  const indicatorsFilter = canvas.getByLabelText('Indicator', { selector: 'select' })
186
206
  await user.selectOptions(indicatorsFilter, ['indicatorID'])
187
207
  const yearsFilter = canvas.getByLabelText('Year', { selector: 'select' })
188
- await user.selectOptions(yearsFilter, ['1999'])
208
+ await user.selectOptions(yearsFilter, ['Some Year 0'])
189
209
  const stratCategoryFilter = canvas.getByLabelText('View By', { selector: 'select' })
190
- await user.selectOptions(stratCategoryFilter, ['stratCategoryId'])
210
+ await user.selectOptions(stratCategoryFilter, ['Some StratificationCategory 0'])
191
211
  const stratFilter = canvas.getByLabelText('Stratification', { selector: 'select' })
192
- await user.selectOptions(stratFilter, ['stratId'])
212
+ await user.selectOptions(stratFilter, ['Some Stratification 0'])
193
213
  await user.click(canvas.getByText('GO!'))
194
214
  }
195
215
  }
@@ -215,8 +235,9 @@ export const APIFiltersChart: Story = {
215
235
  const indicatorsFilter = canvas.getByLabelText('Indicator', { selector: 'select' })
216
236
  await user.selectOptions(indicatorsFilter, ['indicatorID'])
217
237
  await user.click(canvas.getByText('GO!'))
238
+ await sleep(1000)
218
239
  const yearFilter = canvas.getByLabelText('Year', { selector: 'select' })
219
- await user.selectOptions(yearFilter, ['1999'])
240
+ await user.selectOptions(yearFilter, ['Some Year 1'])
220
241
  }
221
242
  }
222
243
 
@@ -4,9 +4,6 @@
4
4
  "sharedFilters": [
5
5
  {
6
6
  "key": "Location",
7
- "usedBy": [
8
- "chart1"
9
- ],
10
7
  "type": "urlfilter",
11
8
  "apiFilter": {
12
9
  "apiEndpoint": "http://test.gov/api/poc/locations",
@@ -19,9 +16,6 @@
19
16
  },
20
17
  {
21
18
  "key": "Category",
22
- "usedBy": [
23
- "chart1"
24
- ],
25
19
  "type": "urlfilter",
26
20
  "apiFilter": {
27
21
  "apiEndpoint": "http://test.gov/api/poc/topics",
@@ -34,9 +28,6 @@
34
28
  },
35
29
  {
36
30
  "key": "Indicator",
37
- "usedBy": [
38
- "chart1"
39
- ],
40
31
  "type": "urlfilter",
41
32
  "apiFilter": {
42
33
  "apiEndpoint": "http://test.gov/api/poc/indicators",
@@ -50,15 +41,11 @@
50
41
  },
51
42
  {
52
43
  "key": "Year",
53
- "usedBy": [
54
- "chart1"
55
- ],
56
44
  "type": "urlfilter",
57
45
  "apiFilter": {
58
- "apiEndpoint": "http://test.gov/api/POC/Filters",
46
+ "apiEndpoint": "http://test.gov/api/POC/Filters/Year",
59
47
  "valueSelector": "Year",
60
- "textSelector": "Year",
61
- "heirarchyLookup": "Years"
48
+ "textSelector": "Year"
62
49
  },
63
50
  "queryParameter": "year",
64
51
  "showDropdown": true,
@@ -66,15 +53,11 @@
66
53
  },
67
54
  {
68
55
  "key": "View By",
69
- "usedBy": [
70
- "chart1"
71
- ],
72
56
  "type": "urlfilter",
73
57
  "apiFilter": {
74
- "apiEndpoint": "http://test.gov/api/POC/Filters",
75
- "valueSelector": "StratificationCategoryId",
58
+ "apiEndpoint": "http://test.gov/api/POC/Filters/StratificationCategory",
59
+ "valueSelector": "StratificationCategory",
76
60
  "textSelector": "StratificationCategory",
77
- "heirarchyLookup": "StratificationCategories",
78
61
  "defaultValue": "AGE"
79
62
  },
80
63
  "queryParameter": "stratificationcategoryid",
@@ -83,16 +66,11 @@
83
66
  },
84
67
  {
85
68
  "key": "Data Type",
86
- "usedBy": [
87
- "chart1"
88
- ],
89
69
  "type": "urlfilter",
90
70
  "apiFilter": {
91
- "apiEndpoint": "http://test.gov/api/POC/Filters",
92
- "valueSelector": "DataValueTypeId",
93
- "textSelector": "DataValueType",
94
- "heirarchyLookup": "DataValueTypes"
95
-
71
+ "apiEndpoint": "http://test.gov/api/POC/Filters/DataValueType",
72
+ "valueSelector": "DataValueType",
73
+ "textSelector": "DataValueType"
96
74
  },
97
75
  "queryParameter": "datavaluetypeid",
98
76
  "showDropdown": true,
@@ -130,7 +108,7 @@
130
108
  "filters": {
131
109
  "type": "filter-dropdowns",
132
110
  "visualizationType": "filter-dropdowns",
133
- "hide": [ 3, 4, 5 ]
111
+ "hide": [3, 4, 5]
134
112
  },
135
113
  "header": {
136
114
  "type": "markup-include",
@@ -141,7 +119,7 @@
141
119
  "subfilters": {
142
120
  "type": "filter-dropdowns",
143
121
  "visualizationType": "filter-dropdowns",
144
- "hide": [ 0, 1, 2 ],
122
+ "hide": [0, 1, 2],
145
123
  "autoLoad": true
146
124
  },
147
125
  "chart1": {
@@ -341,9 +319,7 @@
341
319
  },
342
320
  "validated": 4.23,
343
321
  "dynamicMarginTop": 0,
344
- "regions": [
345
- {}
346
- ]
322
+ "regions": [{}]
347
323
  }
348
324
  },
349
325
  "type": "dashboard",
@@ -355,4 +331,4 @@
355
331
  "filterBehavior": "Apply Button",
356
332
  "runtime": {},
357
333
  "uuid": 1684783370106
358
- }
334
+ }
@@ -3,9 +3,7 @@
3
3
  "sharedFilters": [
4
4
  {
5
5
  "key": "Category",
6
- "usedBy": [
7
- "map1"
8
- ],
6
+ "usedBy": ["map1"],
9
7
  "type": "urlfilter",
10
8
  "apiFilter": {
11
9
  "apiEndpoint": "http://test.gov/api/poc/topics",
@@ -18,9 +16,7 @@
18
16
  },
19
17
  {
20
18
  "key": "Indicator",
21
- "usedBy": [
22
- "chart1"
23
- ],
19
+ "usedBy": ["chart1"],
24
20
  "type": "urlfilter",
25
21
  "apiFilter": {
26
22
  "apiEndpoint": "http://test.gov/api/poc/indicators",
@@ -34,15 +30,12 @@
34
30
  },
35
31
  {
36
32
  "key": "Year",
37
- "usedBy": [
38
- "map1"
39
- ],
33
+ "usedBy": ["map1"],
40
34
  "type": "urlfilter",
41
35
  "apiFilter": {
42
- "apiEndpoint": "http://test.gov/api/POC/Filters",
36
+ "apiEndpoint": "http://test.gov/api/POC/Filters/Year",
43
37
  "valueSelector": "Year",
44
- "textSelector": "Year",
45
- "heirarchyLookup": "Years"
38
+ "textSelector": "Year"
46
39
  },
47
40
  "queryParameter": "year",
48
41
  "resetLabel": "- Select -",
@@ -51,15 +44,12 @@
51
44
  },
52
45
  {
53
46
  "key": "View By",
54
- "usedBy": [
55
- "map1"
56
- ],
47
+ "usedBy": ["map1"],
57
48
  "type": "urlfilter",
58
49
  "apiFilter": {
59
- "apiEndpoint": "http://test.gov/api/POC/Filters",
60
- "valueSelector": "StratificationCategoryId",
61
- "textSelector": "StratificationCategory",
62
- "heirarchyLookup": "StratificationCategories"
50
+ "apiEndpoint": "http://test.gov/api/POC/Filters/StratificationCategory",
51
+ "valueSelector": "StratificationCategory",
52
+ "textSelector": "StratificationCategory"
63
53
  },
64
54
  "resetLabel": "- Select -",
65
55
  "queryParameter": "stratificationcategoryid",
@@ -68,13 +58,11 @@
68
58
  },
69
59
  {
70
60
  "key": "Stratification",
71
- "usedBy": [
72
- "map1"
73
- ],
61
+ "usedBy": ["map1"],
74
62
  "type": "urlfilter",
75
63
  "apiFilter": {
76
- "apiEndpoint": "http://test.gov/api/POC/stratifications",
77
- "valueSelector": "StratificationId",
64
+ "apiEndpoint": "http://test.gov/api/POC/Filters/Stratification",
65
+ "valueSelector": "Stratification",
78
66
  "textSelector": "Stratification"
79
67
  },
80
68
  "resetLabel": "- Select -",
@@ -149,8 +137,8 @@
149
137
  "suffix": "%",
150
138
  "name": "LowConfidenceLimit",
151
139
  "tooltip": true
152
- },
153
- "additionalColumn2": {
140
+ },
141
+ "additionalColumn2": {
154
142
  "label": "High Confidence Limit",
155
143
  "dataTable": true,
156
144
  "tooltips": false,
@@ -158,7 +146,7 @@
158
146
  "suffix": "%",
159
147
  "name": "HighConfidenceLimit",
160
148
  "tooltip": true
161
- },
149
+ },
162
150
  "navigate": {
163
151
  "name": "link",
164
152
  "tooltip": false,
@@ -173,9 +161,7 @@
173
161
  },
174
162
  "legend": {
175
163
  "descriptions": {},
176
- "specialClasses": [
177
- "NA"
178
- ],
164
+ "specialClasses": ["NA"],
179
165
  "unified": false,
180
166
  "singleColumn": false,
181
167
  "dynamicDescription": false,
@@ -196,4 +182,4 @@
196
182
  "filterBehavior": "Apply Button",
197
183
  "runtime": {},
198
184
  "uuid": 1684783370106
199
- }
185
+ }