@cdc/dashboard 4.24.7 → 4.24.9

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 (40) hide show
  1. package/dist/cdcdashboard.js +128394 -122305
  2. package/examples/single-state-dashboard-filters.json +421 -0
  3. package/examples/state-level.json +90136 -0
  4. package/examples/state-points.json +10474 -0
  5. package/examples/test-file.json +147 -0
  6. package/examples/testing.json +94456 -0
  7. package/index.html +18 -6
  8. package/package.json +9 -9
  9. package/src/CdcDashboardComponent.tsx +154 -90
  10. package/src/DashboardContext.tsx +7 -1
  11. package/src/_stories/Dashboard.stories.tsx +124 -10
  12. package/src/_stories/_mock/api-filter-map.json +1 -1
  13. package/src/_stories/_mock/bump-chart.json +3554 -0
  14. package/src/_stories/_mock/methodology.json +412 -0
  15. package/src/_stories/_mock/methodologyAPI.ts +90 -0
  16. package/src/_stories/_mock/multi-viz.json +1 -1
  17. package/src/_stories/_mock/single-state-dashboard-filters.json +390 -0
  18. package/src/components/DashboardFilters/DashboardFilters.tsx +39 -17
  19. package/src/components/DashboardFilters/DashboardFiltersEditor/DashboardFiltersEditor.tsx +2 -2
  20. package/src/components/DashboardFilters/DashboardFiltersEditor/components/FilterEditor.tsx +141 -31
  21. package/src/components/DashboardFilters/DashboardFiltersWrapper.tsx +66 -18
  22. package/src/components/Header/Header.tsx +0 -5
  23. package/src/components/MultiConfigTabs/MultiConfigTabs.tsx +20 -8
  24. package/src/components/Row.tsx +1 -1
  25. package/src/components/VisualizationRow.tsx +98 -17
  26. package/src/components/Widget.tsx +1 -0
  27. package/src/helpers/FilterBehavior.ts +4 -0
  28. package/src/helpers/addValuesToDashboardFilters.ts +49 -0
  29. package/src/helpers/apiFilterHelpers.ts +69 -18
  30. package/src/helpers/changeFilterActive.ts +16 -7
  31. package/src/helpers/getFilteredData.ts +4 -4
  32. package/src/helpers/iconHash.tsx +2 -0
  33. package/src/helpers/loadAPIFilters.ts +74 -0
  34. package/src/helpers/reloadURLHelpers.ts +13 -3
  35. package/src/helpers/tests/addValuesToDashboardFilters.test.ts +44 -0
  36. package/src/helpers/tests/apiFilterHelpers.test.ts +156 -0
  37. package/src/helpers/tests/getFilteredData.test.ts +86 -0
  38. package/src/helpers/tests/loadAPIFiltersWrapper.test.ts +176 -0
  39. package/src/helpers/tests/reloadURLHelpers.test.ts +195 -0
  40. package/src/types/SharedFilter.ts +2 -1
@@ -5,6 +5,7 @@ import APIFiltersChartData from './_mock/api-filter-chart.json'
5
5
  import ExampleConfig_1 from './_mock/dashboard-gallery.json'
6
6
  import ExampleConfig_2 from './_mock/dashboard-2.json'
7
7
  import ExampleConfig_3 from './_mock/dashboard_no_filter.json'
8
+ import SingleStateDashboardFilters from './_mock/single-state-dashboard-filters.json'
8
9
  import Dashboard_Filter from './_mock/dashboard-filter.json'
9
10
  import MultiVizConfig from './_mock/multi-viz.json'
10
11
  import MultiDashboardConfig from './_mock/multi-dashboards.json'
@@ -18,6 +19,9 @@ import _ from 'lodash'
18
19
  import { footnotesSymbols } from '@cdc/core/helpers/footnoteSymbols'
19
20
  import FootnotesConfig from '@cdc/core/types/Footnotes'
20
21
  import { ConfigRow } from '../types/ConfigRow'
22
+ import BumpChartConfig from './_mock/bump-chart.json'
23
+ import MethodologyConfig from './_mock/methodology.json'
24
+ import methodologyAPI from './_mock/methodologyAPI'
21
25
 
22
26
  const meta: Meta<typeof Dashboard> = {
23
27
  title: 'Components/Pages/Dashboard',
@@ -47,6 +51,13 @@ export const Example_3: Story = {
47
51
  }
48
52
  }
49
53
 
54
+ export const Bump_Chart_Dashboard: Story = {
55
+ args: {
56
+ config: BumpChartConfig,
57
+ isEditor: false
58
+ }
59
+ }
60
+
50
61
  export const Dashboard_Filters: Story = {
51
62
  args: {
52
63
  config: Dashboard_Filter,
@@ -75,6 +86,13 @@ export const PivotFilter: Story = {
75
86
  }
76
87
  }
77
88
 
89
+ export const SingleStateDashboardWithFilters: Story = {
90
+ args: {
91
+ config: SingleStateDashboardFilters,
92
+ isEditor: false
93
+ }
94
+ }
95
+
78
96
  faker.seed(123)
79
97
 
80
98
  const countries = _.times(5, faker.location.country)
@@ -101,13 +119,6 @@ const multiVizData = {
101
119
  'footnote-data.json': { data: footnoteData }
102
120
  }
103
121
 
104
- export const MultiVisualization: Story = {
105
- args: {
106
- config: { ...MultiVizConfig, datasets: multiVizData },
107
- isEditor: false
108
- }
109
- }
110
-
111
122
  export const MultiDashboard: Story = {
112
123
  args: {
113
124
  config: MultiDashboardConfig,
@@ -130,6 +141,7 @@ const sleep = ms => {
130
141
  }
131
142
 
132
143
  const fetchMock = {
144
+ debug: true,
133
145
  mocks: [
134
146
  {
135
147
  matcher: {
@@ -208,11 +220,55 @@ const fetchMock = {
208
220
  }
209
221
  ]
210
222
  }
211
- }
223
+ },
224
+ {
225
+ matcher: {
226
+ name: 'methodologyYear',
227
+ url: 'path:/methodology',
228
+ query: {
229
+ $select: 'distinct year'
230
+ }
231
+ },
232
+ response: {
233
+ status: 200,
234
+ body: methodologyAPI('distinct year')
235
+ }
236
+ },
237
+ ...['a', 'b'].map(methodology => {
238
+ return {
239
+ matcher: {
240
+ name: 'methodology' + methodology,
241
+ url: 'path:/methodology',
242
+ query: {
243
+ methodology: `"${methodology}"`
244
+ }
245
+ },
246
+ response: {
247
+ status: 200,
248
+ body: methodologyAPI('*', ['methodology', methodology])
249
+ }
250
+ }
251
+ }),
252
+ ...[1999, 2000, 2012, 2013].map(year => {
253
+ return {
254
+ matcher: {
255
+ name: 'methodology' + year,
256
+ url: 'path:/methodology',
257
+ query: {
258
+ $select: 'distinct methodology',
259
+ year
260
+ }
261
+ },
262
+ response: {
263
+ status: 200,
264
+ body: methodologyAPI('distinct methodology', ['year', year])
265
+ }
266
+ }
267
+ })
212
268
  ]
213
269
  }
214
270
 
215
- export const APIFiltersMap: Story = {
271
+ export const RegressionAPIFiltersMap: Story = {
216
272
  args: {
217
273
  config: APIFiltersMapData as unknown as Config,
218
274
  isEditor: false
@@ -241,7 +297,7 @@ export const APIFiltersMap: Story = {
241
297
  }
242
298
  }
243
299
 
244
- export const APIFiltersChart: Story = {
300
+ export const RegressionAPIFiltersChart: Story = {
245
301
  args: {
246
302
  config: APIFiltersChartData as unknown as Config,
247
303
  isEditor: false
@@ -269,4 +325,62 @@ export const APIFiltersChart: Story = {
269
325
  }
270
326
  }
271
327
 
328
+ export const RegressionHiddenFilter: Story = {
329
+ args: {
330
+ config: MethodologyConfig,
331
+ isEditor: false
332
+ },
333
+ parameters: {
334
+ fetchMock
335
+ },
336
+ play: async ({ canvasElement }) => {
337
+ const canvas = within(canvasElement)
338
+ const user = userEvent.setup()
339
+ // play is running before full rendering is complete so sleep function
340
+ // is needed to delay the execution.
341
+ // possible related bug: https://github.com/storybookjs/storybook/issues/18258
342
+ await sleep(1000)
343
+ const yearFilter = canvas.getByLabelText('Year', { selector: 'select' })
344
+ await user.selectOptions(yearFilter, ['1999'])
345
+ await user.click(canvas.getByText('GO!'))
346
+ await sleep(500)
347
+ canvas.getAllByText('alabama')
348
+ canvas.getAllByText('alaska')
349
+ canvas.getAllByText('arizona')
350
+ await user.selectOptions(yearFilter, ['2012'])
351
+ await user.click(canvas.getByText('GO!'))
352
+ await sleep(500)
353
+ canvas.getAllByText('new york')
354
+ canvas.getAllByText('new jersey')
355
+ canvas.getAllByText('new mexico')
356
+ }
357
+ }
358
+
359
+ export const RegressionMultiVisualization: Story = {
360
+ args: {
361
+ config: { ...MultiVizConfig, datasets: multiVizData },
362
+ isEditor: false
363
+ },
364
+ play: async ({ canvasElement }) => {
365
+ const canvas = within(canvasElement)
366
+ const user = userEvent.setup()
367
+ // play is running before full rendering is complete so sleep function
368
+ // is needed to delay the execution.
369
+ // possible related bug: https://github.com/storybookjs/storybook/issues/18258
370
+ await sleep(1000)
371
+ const categoryFilter = canvas.getByLabelText('Category', { selector: 'select' })
372
+ canvas.getAllByText('Paraguay')
373
+ canvas.getAllByText('Poland')
374
+ canvas.getAllByText('Iraq')
375
+ await user.selectOptions(categoryFilter, ['category-3'])
376
+ canvas.getAllByText('Paraguay')
377
+ canvas.getAllByText('Ethiopia')
378
+ canvas.getAllByText('Iraq')
379
+ await user.selectOptions(categoryFilter, ['category-1'])
380
+ canvas.getAllByText('Poland')
381
+ canvas.getAllByText('Ethiopia')
382
+ canvas.getAllByText('Curacao')
383
+ }
384
+ }
385
+
272
386
  export default meta
@@ -16,7 +16,7 @@
16
16
  },
17
17
  {
18
18
  "key": "Indicator",
19
- "usedBy": ["chart1"],
19
+ "usedBy": ["map1"],
20
20
  "type": "urlfilter",
21
21
  "apiFilter": {
22
22
  "apiEndpoint": "http://test.gov/api/poc/indicators",