@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
@@ -0,0 +1,31 @@
1
+ import _ from 'lodash'
2
+ import { MultiDashboardConfig } from '../types/MultiDashboard'
3
+ import DataTransform from '@cdc/core/helpers/DataTransform'
4
+
5
+ const transform = new DataTransform()
6
+
7
+ export const getVizConfig = (visualizationKey: string, rowNumber: number, config: MultiDashboardConfig, data: Object, filteredData?: Object) => {
8
+ const visualizationConfig = _.cloneDeep(config.visualizations[visualizationKey])
9
+ const rowData = config.rows[rowNumber]
10
+ if (rowData?.dataKey) {
11
+ // data configured on the row
12
+ Object.assign(visualizationConfig, _.pick(rowData, ['dataKey', 'dataDescription', 'formattedData', 'data']))
13
+ }
14
+
15
+ if (visualizationConfig.formattedData) visualizationConfig.originalFormattedData = visualizationConfig.formattedData
16
+ const filteredVizData = filteredData?.[rowNumber] ?? filteredData?.[visualizationKey]
17
+
18
+ if (filteredVizData) {
19
+ visualizationConfig.data = filteredVizData
20
+ if (visualizationConfig.formattedData) {
21
+ visualizationConfig.formattedData = visualizationConfig.data
22
+ }
23
+ } else {
24
+ const dataKey = visualizationConfig.dataKey || 'backwards-compatibility'
25
+ visualizationConfig.data = data[dataKey]
26
+ if (visualizationConfig.formattedData) {
27
+ visualizationConfig.formattedData = transform.developerStandardize(visualizationConfig.data, visualizationConfig.dataDescription) || visualizationConfig.data
28
+ }
29
+ }
30
+ return visualizationConfig
31
+ }
@@ -0,0 +1,9 @@
1
+ import { ConfigRow } from '../types/ConfigRow'
2
+
3
+ export const getVizRowColumnLocator = (rows: ConfigRow[]) =>
4
+ rows.reduce((acc, curr, index) => {
5
+ curr.columns?.forEach((column, columnIndex) => {
6
+ if (column.widget !== undefined) acc[column.widget] = { row: index, column: columnIndex }
7
+ })
8
+ return acc
9
+ }, {})
@@ -35,8 +35,7 @@ $red: #f74242;
35
35
  flex-flow: row;
36
36
  width: 100%;
37
37
  position: relative;
38
- top: 0;
39
- padding: 1em;
38
+ padding: 2em 1em 1em;
40
39
  border: 1px solid #c2c2c2;
41
40
  transition: border 300ms cubic-bezier(0.16, 1, 0.3, 1);
42
41
  background-color: #f2f2f2;
@@ -330,6 +329,14 @@ $red: #f74242;
330
329
  .builder-row {
331
330
  position: relative;
332
331
 
332
+ .btn-configure-row {
333
+ background: none;
334
+ display: block;
335
+ position: absolute;
336
+ right: 1em;
337
+ top: 0;
338
+ }
339
+
333
340
  .widget__content {
334
341
  padding: 0 2em;
335
342
 
@@ -10,6 +10,11 @@
10
10
  margin-top: 20%;
11
11
  }
12
12
 
13
+ > .cove-editor__content {
14
+ width: 100% !important;
15
+ left: 0px;
16
+ }
17
+
13
18
  .editor-heading {
14
19
  background-color: #ddd;
15
20
  border-bottom: #c7c7c7 1px solid;
@@ -1,8 +1,14 @@
1
1
  import type { DashboardConfig as Config } from '../types/DashboardConfig'
2
2
  import { type Action } from '@cdc/core/types/Action'
3
3
  import { Tab } from '../types/Tab'
4
+ <<<<<<< HEAD
5
+ import { ConfigureData } from '@cdc/core/types/ConfigureData'
6
+ import { ConfigRow } from '../types/ConfigRow'
7
+ =======
8
+ import { SharedFilter } from '../types/SharedFilter'
9
+ >>>>>>> 35436844 (fixed api dropdowns)
4
10
 
5
- type SET_CONFIG = Action<'SET_CONFIG', Config>
11
+ type SET_CONFIG = Action<'SET_CONFIG', Partial<Config>>
6
12
  type UPDATE_CONFIG = Action<'UPDATE_CONFIG', [Config, Object?]>
7
13
  type SET_DATA = Action<'SET_DATA', Object>
8
14
  type SET_LOADING = Action<'SET_LOADING', boolean>
@@ -17,6 +23,12 @@ type ADD_NEW_DASHBOARD = Action<'ADD_NEW_DASHBOARD', undefined>
17
23
  type SAVE_CURRENT_CHANGES = Action<'SAVE_CURRENT_CHANGES', undefined>
18
24
  type SWITCH_CONFIG = Action<'SWITCH_CONFIG', number>
19
25
  type TOGGLE_ROW = Action<'TOGGLE_ROW', { rowIndex: number; colIndex: number }>
26
+ <<<<<<< HEAD
27
+ type UPDATE_VISUALIZATION = Action<'UPDATE_VISUALIZATION', { vizKey: string; configureData: Partial<ConfigureData> }>
28
+ type UPDATE_ROW = Action<'UPDATE_ROW', { rowIndex: number; rowData: Partial<ConfigRow> }>
29
+ =======
30
+ type SET_SHARED_FILTERS = Action<'SET_SHARED_FILTERS', SharedFilter[]>
31
+ >>>>>>> 35436844 (fixed api dropdowns)
20
32
 
21
33
  type DashboardActions =
22
34
  | ADD_NEW_DASHBOARD
@@ -30,8 +42,11 @@ type DashboardActions =
30
42
  | SET_LOADING
31
43
  | SET_PREVIEW
32
44
  | SET_FILTERED_DATA
45
+ | SET_SHARED_FILTERS
33
46
  | SET_TAB_SELECTED
34
47
  | SWITCH_CONFIG
35
48
  | INITIALIZE_MULTIDASHBOARDS
36
49
  | TOGGLE_ROW
50
+ | UPDATE_VISUALIZATION
51
+ | UPDATE_ROW
37
52
  export default DashboardActions
@@ -41,7 +41,7 @@ const reducer = (state: DashboardState, action: DashboardActions): DashboardStat
41
41
  return { ...state, config, filteredData }
42
42
  }
43
43
  case 'SET_CONFIG': {
44
- return { ...state, config: action.payload }
44
+ return { ...state, config: { ...state.config, ...action.payload } }
45
45
  }
46
46
  case 'SET_DATA': {
47
47
  return { ...state, data: action.payload }
@@ -92,6 +92,11 @@ const reducer = (state: DashboardState, action: DashboardActions): DashboardStat
92
92
  newMultiDashboards[saveSlot] = { ...toSave, label }
93
93
  return applyMultiDashboards(state, newMultiDashboards)
94
94
  }
95
+ case 'SET_SHARED_FILTERS': {
96
+ const newSharedFilters = action.payload
97
+ const newDashboardConfig = { ...state.config.dashboard, sharedFilters: newSharedFilters }
98
+ return { ...state, config: { ...state.config, dashboard: newDashboardConfig } }
99
+ }
95
100
  case 'INITIALIZE_MULTIDASHBOARDS': {
96
101
  const label = 'New Dashboard 1'
97
102
  const toSave = _.pick(state.config, ['dashboard', 'visualizations', 'rows'])
@@ -107,7 +112,25 @@ const reducer = (state: DashboardState, action: DashboardActions): DashboardStat
107
112
  case 'TOGGLE_ROW': {
108
113
  const { rowIndex, colIndex } = action.payload
109
114
  const newRows = state.config.rows.map((row, index) => {
110
- return index === rowIndex ? row.map((col, i) => ({ ...col, hide: i !== colIndex })) : row
115
+ if (index === rowIndex) {
116
+ const newColumns = row.columns.map((col, i) => ({ ...col, hide: i === colIndex }))
117
+ return { ...row, columns: newColumns }
118
+ }
119
+ return row
120
+ })
121
+ return { ...state, config: { ...state.config, rows: newRows } }
122
+ }
123
+ case 'UPDATE_VISUALIZATION': {
124
+ const { vizKey, configureData } = action.payload
125
+ return { ...state, config: { ...state.config, visualizations: { ...state.config.visualizations, [vizKey]: { ...state.config.visualizations[vizKey], ...configureData } } } }
126
+ }
127
+ case 'UPDATE_ROW': {
128
+ const { rowIndex, rowData } = action.payload
129
+ const newRows = state.config.rows.map((row, index) => {
130
+ if (index === rowIndex) {
131
+ return { ...row, ...rowData }
132
+ }
133
+ return row
111
134
  })
112
135
  return { ...state, config: { ...state.config, rows: newRows } }
113
136
  }
@@ -1,5 +1,4 @@
1
- export type APIFilter = Record<'apiEndpoint'|'valueSelector'|'textSelector', string> & {
2
- heirarchyLookup?: string
3
- autoLoad?: boolean
4
- defaultValue?: string
5
- }
1
+ export type APIFilter = Record<'apiEndpoint' | 'valueSelector' | 'textSelector', string> & {
2
+ autoLoad?: boolean
3
+ defaultValue?: string
4
+ }
@@ -1,8 +1,17 @@
1
- export type ConfigRow = {
1
+ import { ConfigureData } from '@cdc/core/types/ConfigureData'
2
+
3
+ type Col = {
2
4
  equalHeight?: boolean
3
5
  width: number | null
4
- toggle?: boolean
5
6
  hide?: boolean
6
7
  widget?: string
7
8
  uuid?: string | number
8
- }[] & { uuid?: string | number }
9
+ }
10
+
11
+ export type ConfigRow = {
12
+ columns: Col[]
13
+ uuid?: string | number
14
+ toggle?: boolean
15
+ equalHeight?: boolean
16
+ multiVizColumn?: string
17
+ } & ConfigureData
@@ -1,8 +1,11 @@
1
- export type DataSet = {
2
- data: Object[]
3
- dataDescription: {}
4
- dataUrl: string
5
- runtimeDataUrl: string
6
- dataFileSourceType: string
7
- formattedData: Object[]
8
- }
1
+ import { ConfigureData } from '@cdc/core/types/ConfigureData'
2
+
3
+ export type DataSet = ConfigureData & {
4
+ dataFileFormat?: string
5
+ dataFileName?: string
6
+ dataFileSize?: number
7
+ preview?: boolean
8
+ dataUrl: string
9
+ runtimeDataUrl: string
10
+ dataFileSourceType: string
11
+ }
@@ -7,7 +7,7 @@ export type SharedFilter = {
7
7
  setByQueryParameter?: string
8
8
  active?: string | string[]
9
9
  queuedActive?: string
10
- usedBy?: string[]
10
+ usedBy?: (string | number)[] // if number used by whole row, else used by specific viz
11
11
  parents?: string[]
12
12
  pivot?: string
13
13
  setBy?: string