@cdc/dashboard 4.24.4 → 4.24.7
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.
- package/dist/cdcdashboard.js +179228 -141419
- package/examples/custom/css/respiratory.css +236 -0
- package/examples/custom/js/respiratory.js +242 -0
- package/examples/default-multi-dataset-shared-filter.json +1729 -0
- package/examples/ed-visits-county-file.json +618 -0
- package/examples/filtered-dash.json +6 -21
- package/index.html +12 -3
- package/package.json +12 -11
- package/src/CdcDashboard.tsx +5 -1
- package/src/CdcDashboardComponent.tsx +156 -334
- package/src/DashboardContext.tsx +9 -1
- package/src/_stories/Dashboard.stories.tsx +31 -3
- package/src/_stories/_mock/dashboard-gallery.json +534 -523
- package/src/_stories/_mock/markup-include.json +78 -0
- package/src/_stories/_mock/multi-dashboards.json +914 -0
- package/src/_stories/_mock/multi-viz.json +2 -3
- package/src/_stories/_mock/pivot-filter.json +15 -11
- package/src/_stories/_mock/standalone-table.json +2 -0
- package/src/components/CollapsibleVisualizationRow.tsx +44 -0
- package/src/components/Column.tsx +1 -1
- package/src/components/DashboardFilters/DashboardFilters.tsx +80 -0
- package/src/components/DashboardFilters/DashboardFiltersEditor/DashboardFiltersEditor.tsx +218 -0
- package/src/components/DashboardFilters/DashboardFiltersEditor/components/DeleteFilterModal.tsx +48 -0
- package/src/components/DashboardFilters/DashboardFiltersEditor/components/FilterEditor.tsx +367 -0
- package/src/components/DashboardFilters/DashboardFiltersEditor/index.ts +1 -0
- package/src/components/DashboardFilters/DashboardFiltersWrapper.tsx +143 -0
- package/src/components/DashboardFilters/index.ts +3 -0
- package/src/components/DataDesignerModal.tsx +9 -9
- package/src/components/ExpandCollapseButtons.tsx +20 -0
- package/src/components/Header/Header.tsx +1 -97
- package/src/components/MultiConfigTabs/MultiConfigTabs.tsx +4 -4
- package/src/components/MultiConfigTabs/MultiTabs.tsx +3 -2
- package/src/components/Row.tsx +52 -19
- package/src/components/Toggle/Toggle.tsx +2 -4
- package/src/components/VisualizationRow.tsx +96 -29
- package/src/components/VisualizationsPanel/VisualizationsPanel.tsx +116 -0
- package/src/components/VisualizationsPanel/index.ts +1 -0
- package/src/components/VisualizationsPanel/visualizations-panel-styles.css +12 -0
- package/src/components/Widget.tsx +26 -90
- package/src/helpers/apiFilterHelpers.ts +51 -0
- package/src/helpers/changeFilterActive.ts +30 -0
- package/src/helpers/filterData.ts +16 -56
- package/src/helpers/generateValuesForFilter.ts +1 -1
- package/src/helpers/getAutoLoadVisualization.ts +11 -0
- package/src/helpers/getFilteredData.ts +4 -2
- package/src/helpers/getVizConfig.ts +23 -2
- package/src/helpers/getVizRowColumnLocator.ts +2 -1
- package/src/helpers/hasDashboardApplyBehavior.ts +5 -0
- package/src/helpers/iconHash.tsx +3 -3
- package/src/helpers/mapDataToConfig.ts +29 -0
- package/src/helpers/processData.ts +2 -3
- package/src/helpers/reloadURLHelpers.ts +68 -0
- package/src/helpers/tests/filterData.test.ts +1 -93
- package/src/scss/editor-panel.scss +1 -1
- package/src/scss/grid.scss +34 -27
- package/src/scss/main.scss +41 -3
- package/src/scss/variables.scss +4 -0
- package/src/store/dashboard.actions.ts +9 -10
- package/src/store/dashboard.reducer.ts +41 -13
- package/src/types/APIFilter.ts +1 -4
- package/src/types/ConfigRow.ts +2 -0
- package/src/types/Dashboard.ts +1 -1
- package/src/types/DashboardConfig.ts +2 -4
- package/src/types/DashboardFilters.ts +7 -0
- package/src/types/InitialState.ts +1 -1
- package/src/types/MultiDashboard.ts +2 -2
- package/src/types/SharedFilter.ts +2 -5
- package/src/types/Tab.ts +1 -1
- package/LICENSE +0 -201
- package/src/components/EditorWrapper/EditorWrapper.tsx +0 -52
- package/src/components/EditorWrapper/editor-wrapper.style.css +0 -13
- package/src/components/Filters.tsx +0 -88
- package/src/components/Header/FilterModal.tsx +0 -506
- package/src/components/VisualizationsPanel.tsx +0 -72
- package/src/helpers/getApiFilterKey.ts +0 -5
|
@@ -2,19 +2,9 @@ import { useEffect, useContext } from 'react'
|
|
|
2
2
|
|
|
3
3
|
import { DashboardContext, DashboardDispatchContext } from '../../DashboardContext'
|
|
4
4
|
|
|
5
|
-
// types
|
|
6
|
-
import { type SharedFilter } from '../../types/SharedFilter'
|
|
7
|
-
import { type DashboardConfig as Config } from '../../types/DashboardConfig'
|
|
8
|
-
import { useGlobalContext } from '@cdc/core/components/GlobalContext'
|
|
9
|
-
|
|
10
|
-
import Tooltip from '@cdc/core/components/ui/Tooltip'
|
|
11
|
-
import Icon from '@cdc/core/components/ui/Icon'
|
|
12
|
-
import Select from '@cdc/core/components/ui/Select'
|
|
13
|
-
|
|
14
5
|
import './index.scss'
|
|
15
6
|
import MultiConfigTabs from '../MultiConfigTabs'
|
|
16
7
|
import { Tab } from '../../types/Tab'
|
|
17
|
-
import FilterModal from './FilterModal'
|
|
18
8
|
import _ from 'lodash'
|
|
19
9
|
|
|
20
10
|
type HeaderProps = {
|
|
@@ -29,7 +19,7 @@ export const FilterBehavior = {
|
|
|
29
19
|
}
|
|
30
20
|
|
|
31
21
|
const Header = (props: HeaderProps) => {
|
|
32
|
-
const tabs: Tab[] = ['Dashboard Description', '
|
|
22
|
+
const tabs: Tab[] = ['Dashboard Description', 'Data Table Settings', 'Dashboard Preview']
|
|
33
23
|
const { visualizationKey, subEditor } = props
|
|
34
24
|
const { config, setParentConfig, tabSelected } = useContext(DashboardContext)
|
|
35
25
|
if (!config) return null
|
|
@@ -41,8 +31,6 @@ const Header = (props: HeaderProps) => {
|
|
|
41
31
|
dispatch({ type: 'SET_CONFIG', payload: newConfig })
|
|
42
32
|
}
|
|
43
33
|
|
|
44
|
-
const { overlay } = useGlobalContext()
|
|
45
|
-
|
|
46
34
|
const changeConfigValue = (parentObj, key, value) => {
|
|
47
35
|
let newConfig = { ...config }
|
|
48
36
|
if (!newConfig[parentObj]) newConfig[parentObj] = {}
|
|
@@ -50,48 +38,6 @@ const Header = (props: HeaderProps) => {
|
|
|
50
38
|
dispatch({ type: 'UPDATE_CONFIG', payload: [newConfig] })
|
|
51
39
|
}
|
|
52
40
|
|
|
53
|
-
const addNewFilter = () => {
|
|
54
|
-
let dashboardConfig = { ...config.dashboard }
|
|
55
|
-
|
|
56
|
-
dashboardConfig.sharedFilters = dashboardConfig.sharedFilters || []
|
|
57
|
-
const newFilter: SharedFilter = { key: 'Dashboard Filter ' + (dashboardConfig.sharedFilters.length + 1) }
|
|
58
|
-
dashboardConfig.sharedFilters.push(newFilter)
|
|
59
|
-
|
|
60
|
-
dispatch({ type: 'UPDATE_CONFIG', payload: [{ ...config, dashboard: dashboardConfig }] })
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const removeFilter = index => {
|
|
64
|
-
let dashboardConfig = { ...config.dashboard }
|
|
65
|
-
let visualizations = { ...config.visualizations }
|
|
66
|
-
|
|
67
|
-
dashboardConfig.sharedFilters?.splice(index, 1)
|
|
68
|
-
|
|
69
|
-
Object.keys(visualizations).forEach(vizKey => {
|
|
70
|
-
if (visualizations[vizKey].visualizationType === 'filter-dropdowns' && visualizations[vizKey].hide && visualizations[vizKey].hide.length > 0) {
|
|
71
|
-
if (visualizations[vizKey].hide.indexOf(index) !== -1) {
|
|
72
|
-
visualizations[vizKey].hide.splice(visualizations[vizKey].hide.indexOf(index), 1)
|
|
73
|
-
}
|
|
74
|
-
visualizations[vizKey].hide.forEach((hideIndex, i) => {
|
|
75
|
-
if (hideIndex > index) {
|
|
76
|
-
visualizations[vizKey].hide[i] = hideIndex - 1
|
|
77
|
-
}
|
|
78
|
-
})
|
|
79
|
-
}
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
// Ensures URL filters refresh after filter removal
|
|
83
|
-
if (dashboardConfig.datasets) {
|
|
84
|
-
Object.keys(dashboardConfig.datasets).forEach(datasetKey => {
|
|
85
|
-
dashboardConfig.datasets![datasetKey].runtimeDataUrl = ''
|
|
86
|
-
})
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const newConfig = { ...config, visualizations, dashboard: dashboardConfig }
|
|
90
|
-
dispatch({ type: 'UPDATE_CONFIG', payload: [newConfig] })
|
|
91
|
-
|
|
92
|
-
overlay?.actions.toggleOverlay()
|
|
93
|
-
}
|
|
94
|
-
|
|
95
41
|
const convertStateToConfig = (type = 'JSON') => {
|
|
96
42
|
let strippedState = JSON.parse(JSON.stringify(config))
|
|
97
43
|
delete strippedState.newViz
|
|
@@ -166,48 +112,6 @@ const Header = (props: HeaderProps) => {
|
|
|
166
112
|
</ul>
|
|
167
113
|
<div className='heading-body'>
|
|
168
114
|
{tabSelected === 'Dashboard Description' && <input type='text' className='description-input' placeholder='Type a dashboard description here.' defaultValue={config.dashboard?.description} onChange={e => changeConfigValue('dashboard', 'description', e.target.value)} />}
|
|
169
|
-
{tabSelected === 'Dashboard Filters' && (
|
|
170
|
-
<>
|
|
171
|
-
{config.dashboard.sharedFilters &&
|
|
172
|
-
config.dashboard.sharedFilters.map((sharedFilter, index) => (
|
|
173
|
-
<span className='shared-filter-button' key={`shared-filter-${sharedFilter.key}`}>
|
|
174
|
-
<a
|
|
175
|
-
href='#'
|
|
176
|
-
onClick={e => {
|
|
177
|
-
e.preventDefault()
|
|
178
|
-
overlay?.actions.openOverlay(<FilterModal index={index} config={config} filterState={sharedFilter} removeFilter={removeFilter} />)
|
|
179
|
-
}}
|
|
180
|
-
>
|
|
181
|
-
{sharedFilter.key}
|
|
182
|
-
</a>
|
|
183
|
-
<button onClick={() => removeFilter(index)}>X</button>
|
|
184
|
-
</span>
|
|
185
|
-
))}
|
|
186
|
-
<button onClick={addNewFilter}>Add New Filter</button>
|
|
187
|
-
|
|
188
|
-
<Select
|
|
189
|
-
value={config.filterBehavior}
|
|
190
|
-
fieldName='filterBehavior'
|
|
191
|
-
label='Filter Behavior'
|
|
192
|
-
initial='- Select Option -'
|
|
193
|
-
onchange={e => {
|
|
194
|
-
const newConfig = { ...config, filterBehavior: e.target.value }
|
|
195
|
-
dispatch({ type: 'UPDATE_CONFIG', payload: [newConfig] })
|
|
196
|
-
}}
|
|
197
|
-
options={Object.values(FilterBehavior)}
|
|
198
|
-
tooltip={
|
|
199
|
-
<Tooltip style={{ textTransform: 'none' }}>
|
|
200
|
-
<Tooltip.Target>
|
|
201
|
-
<Icon display='question' color='' style={{ marginLeft: '0.5rem' }} />
|
|
202
|
-
</Tooltip.Target>
|
|
203
|
-
<Tooltip.Content>
|
|
204
|
-
<p>The Apply Button option changes the visualization when the user clicks "apply". The Filter Change option immediately changes the visualization when the selection is changed.</p>
|
|
205
|
-
</Tooltip.Content>
|
|
206
|
-
</Tooltip>
|
|
207
|
-
}
|
|
208
|
-
/>
|
|
209
|
-
</>
|
|
210
|
-
)}
|
|
211
115
|
{tabSelected === 'Data Table Settings' && (
|
|
212
116
|
<>
|
|
213
117
|
<div className='wrap'>
|
|
@@ -65,14 +65,14 @@ const Tab = ({ name, handleClick, tabs, index, active }) => {
|
|
|
65
65
|
|
|
66
66
|
return (
|
|
67
67
|
<li className='nav-item'>
|
|
68
|
-
<
|
|
68
|
+
<div className={`edit nav-link${active ? ' active' : ''}`} aria-current={active ? 'page' : null} onClick={onClick}>
|
|
69
69
|
{canMoveLeft && <button onClick={() => handleReorder(index, -1)}>{'<'}</button>}
|
|
70
70
|
{editing ? <input type='text' defaultValue={name} onBlur={onBlur} ref={inputRef} /> : <>{name}</>}
|
|
71
71
|
{canMoveRight && <button onClick={() => handleReorder(index, 1)}>{'>'}</button>}
|
|
72
72
|
<button className='remove' onClick={handleRemove}>
|
|
73
73
|
X
|
|
74
74
|
</button>
|
|
75
|
-
</
|
|
75
|
+
</div>
|
|
76
76
|
</li>
|
|
77
77
|
)
|
|
78
78
|
}
|
|
@@ -95,9 +95,9 @@ const MultiConfigTabs = () => {
|
|
|
95
95
|
<Tab key={tab + index} name={tab} tabs={tabs} index={index} handleClick={() => saveAndLoad(index)} active={index === activeTab} />
|
|
96
96
|
))}
|
|
97
97
|
<li className='nav-item'>
|
|
98
|
-
<
|
|
98
|
+
<button className='nav-link add' onClick={() => dispatch({ type: 'ADD_NEW_DASHBOARD' })}>
|
|
99
99
|
+
|
|
100
|
-
</
|
|
100
|
+
</button>
|
|
101
101
|
</li>
|
|
102
102
|
</ul>
|
|
103
103
|
)
|
|
@@ -9,7 +9,8 @@ const MultiTabs = () => {
|
|
|
9
9
|
const tabs = useMemo<string[]>(() => (config.multiDashboards || []).map(({ label }) => label), [config.multiDashboards])
|
|
10
10
|
const activeTab = useMemo<number>(() => config.activeDashboard, [config.activeDashboard])
|
|
11
11
|
|
|
12
|
-
const load = (indexToSwitchTo: number) => {
|
|
12
|
+
const load = (indexToSwitchTo: number, e) => {
|
|
13
|
+
e.preventDefault() // some form wrapper is causing this to act as a submit button
|
|
13
14
|
dispatch({ type: 'SWITCH_CONFIG', payload: indexToSwitchTo })
|
|
14
15
|
}
|
|
15
16
|
|
|
@@ -18,7 +19,7 @@ const MultiTabs = () => {
|
|
|
18
19
|
<ul className='nav nav-tabs multi-config-tabs'>
|
|
19
20
|
{tabs.map((tab, index) => (
|
|
20
21
|
<li className='nav-item'>
|
|
21
|
-
<a className={`nav-link${activeTab === index ? ' active' : ''}`} aria-current={activeTab === index ? 'page' : null} href='#' onClick={
|
|
22
|
+
<a className={`nav-link${activeTab === index ? ' active' : ''}`} aria-current={activeTab === index ? 'page' : null} href='#' onClick={e => load(index, e)}>
|
|
22
23
|
{tab}
|
|
23
24
|
</a>
|
|
24
25
|
</li>
|
package/src/components/Row.tsx
CHANGED
|
@@ -17,6 +17,7 @@ import { DataDesignerModal } from './DataDesignerModal'
|
|
|
17
17
|
import { useGlobalContext } from '@cdc/core/components/GlobalContext'
|
|
18
18
|
import { iconHash } from '../helpers/iconHash'
|
|
19
19
|
import _ from 'lodash'
|
|
20
|
+
import { Visualization } from '@cdc/core/types/Visualization'
|
|
20
21
|
|
|
21
22
|
type RowMenuProps = {
|
|
22
23
|
rowIdx: number
|
|
@@ -104,9 +105,20 @@ const RowMenu: React.FC<RowMenuProps> = ({ rowIdx }) => {
|
|
|
104
105
|
}
|
|
105
106
|
|
|
106
107
|
const deleteRow = () => {
|
|
107
|
-
|
|
108
|
+
let newVisualizations = { ...config.visualizations }
|
|
109
|
+
|
|
110
|
+
//delete the instantiated widgets
|
|
111
|
+
if (rows[rowIdx] && rows[rowIdx].columns && rows[rowIdx].columns.length && config.visualizations) {
|
|
112
|
+
rows[rowIdx].columns.forEach(column => {
|
|
113
|
+
if (column.widget) {
|
|
114
|
+
delete newVisualizations[column.widget]
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
}
|
|
108
118
|
|
|
109
|
-
|
|
119
|
+
rows.splice(rowIdx, 1) // delete the row
|
|
120
|
+
|
|
121
|
+
updateConfig({ ...config, rows, visualizations: newVisualizations })
|
|
110
122
|
}
|
|
111
123
|
|
|
112
124
|
const layoutList = [
|
|
@@ -149,31 +161,52 @@ const RowMenu: React.FC<RowMenuProps> = ({ rowIdx }) => {
|
|
|
149
161
|
)
|
|
150
162
|
}
|
|
151
163
|
|
|
152
|
-
|
|
164
|
+
type RowProps = { row: ConfigRow; idx: number; uuid: number | string }
|
|
165
|
+
|
|
166
|
+
const Row: React.FC<RowProps> = ({ row, idx: rowIdx, uuid }) => {
|
|
153
167
|
const { overlay } = useGlobalContext()
|
|
154
|
-
|
|
155
|
-
<div className='builder-row' data-row-id={rowIdx}>
|
|
156
|
-
<RowMenu rowIdx={rowIdx} />
|
|
157
|
-
<div className='column-container'>
|
|
158
|
-
<>
|
|
159
|
-
<button
|
|
160
|
-
title='Configure Data'
|
|
161
|
-
className='btn btn-configure-row'
|
|
162
|
-
onClick={() => {
|
|
163
|
-
overlay?.actions.openOverlay(<DataDesignerModal rowIndex={rowIdx} />)
|
|
164
|
-
}}
|
|
165
|
-
>
|
|
166
|
-
{iconHash['gear']}
|
|
167
|
-
</button>
|
|
168
|
+
const dispatch = useContext(DashboardDispatchContext)
|
|
168
169
|
|
|
170
|
+
const configureFootnotes = () => {
|
|
171
|
+
if (!row.footnotesId) {
|
|
172
|
+
const type = 'footnotes'
|
|
173
|
+
const uid = type + Date.now()
|
|
174
|
+
const newVisualizationConfig = {
|
|
175
|
+
uid,
|
|
176
|
+
type,
|
|
177
|
+
visualizationType: type,
|
|
178
|
+
editing: true
|
|
179
|
+
}
|
|
180
|
+
dispatch({ type: 'ADD_FOOTNOTE', payload: { id: uid, rowIndex: rowIdx, config: newVisualizationConfig as Visualization } })
|
|
181
|
+
} else {
|
|
182
|
+
dispatch({ type: 'UPDATE_VISUALIZATION', payload: { vizKey: row.footnotesId, configureData: { editing: true } } })
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return (
|
|
186
|
+
<>
|
|
187
|
+
<div className='builder-row' data-row-id={rowIdx}>
|
|
188
|
+
<RowMenu rowIdx={rowIdx} />
|
|
189
|
+
<button
|
|
190
|
+
title='Configure Data'
|
|
191
|
+
className='btn btn-configure-row'
|
|
192
|
+
onClick={() => {
|
|
193
|
+
overlay?.actions.openOverlay(<DataDesignerModal rowIndex={rowIdx} />)
|
|
194
|
+
}}
|
|
195
|
+
>
|
|
196
|
+
{iconHash['gear']}
|
|
197
|
+
</button>
|
|
198
|
+
<div className='column-container'>
|
|
169
199
|
{row.columns
|
|
170
200
|
.filter(column => column.width)
|
|
171
201
|
.map((column, colIdx) => (
|
|
172
202
|
<Column data={column} key={`row-${uuid}-col-${colIdx}`} rowIdx={rowIdx} colIdx={colIdx} />
|
|
173
203
|
))}
|
|
174
|
-
|
|
204
|
+
</div>
|
|
205
|
+
<button className='btn btn-primary footnotes' onClick={configureFootnotes}>
|
|
206
|
+
{row.footnotesId ? 'Edit' : 'Add'} Footnotes
|
|
207
|
+
</button>
|
|
175
208
|
</div>
|
|
176
|
-
|
|
209
|
+
</>
|
|
177
210
|
)
|
|
178
211
|
}
|
|
179
212
|
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { useContext } from 'react'
|
|
2
|
-
import { DashboardDispatchContext } from '../../DashboardContext'
|
|
3
1
|
import { ConfigRow } from '../../types/ConfigRow'
|
|
4
|
-
import {
|
|
2
|
+
import { AnyVisualization } from '@cdc/core/types/Visualization'
|
|
5
3
|
import { getIcon } from '../../helpers/iconHash'
|
|
6
4
|
import './toggle-style.css'
|
|
7
5
|
import _ from 'lodash'
|
|
@@ -9,7 +7,7 @@ import _ from 'lodash'
|
|
|
9
7
|
type ToggleProps = {
|
|
10
8
|
active: number
|
|
11
9
|
row: ConfigRow
|
|
12
|
-
visualizations: Record<string,
|
|
10
|
+
visualizations: Record<string, AnyVisualization>
|
|
13
11
|
setToggled: (colIndex: number) => void
|
|
14
12
|
}
|
|
15
13
|
const Toggle: React.FC<ToggleProps> = ({ active, row, visualizations, setToggled }) => {
|
|
@@ -1,57 +1,104 @@
|
|
|
1
1
|
import DataTableStandAlone from '@cdc/core/components/DataTable/DataTableStandAlone'
|
|
2
|
-
import React, {
|
|
2
|
+
import React, { useContext, useMemo } from 'react'
|
|
3
3
|
import Toggle from './Toggle'
|
|
4
4
|
import _ from 'lodash'
|
|
5
|
-
import { DashboardConfig } from '../types/DashboardConfig'
|
|
6
5
|
import { ConfigRow } from '../types/ConfigRow'
|
|
7
|
-
import DataTransform from '@cdc/core/helpers/DataTransform'
|
|
8
|
-
import CdcMap from '@cdc/map'
|
|
9
6
|
import CdcChart from '@cdc/chart'
|
|
10
7
|
import CdcDataBite from '@cdc/data-bite'
|
|
8
|
+
import CdcMap from '@cdc/map'
|
|
11
9
|
import CdcWaffleChart from '@cdc/waffle-chart'
|
|
12
10
|
import CdcMarkupInclude from '@cdc/markup-include'
|
|
13
11
|
import CdcFilteredText from '@cdc/filtered-text'
|
|
14
|
-
import
|
|
15
|
-
import { FilterBehavior } from './Header/Header'
|
|
12
|
+
import DashboardSharedFilters, { APIFilterDropdowns } from './DashboardFilters'
|
|
16
13
|
import { DashboardContext } from '../DashboardContext'
|
|
17
14
|
import { ViewPort } from '@cdc/core/types/ViewPort'
|
|
18
|
-
import { getVizConfig } from '../helpers/getVizConfig'
|
|
15
|
+
import { getFootnotesVizConfig, getVizConfig } from '../helpers/getVizConfig'
|
|
16
|
+
import { TableConfig } from '@cdc/core/components/DataTable/types/TableConfig'
|
|
17
|
+
import FootnotesStandAlone from '@cdc/core/components/Footnotes/FootnotesStandAlone'
|
|
18
|
+
import CollapsibleVisualizationRow from './CollapsibleVisualizationRow'
|
|
19
|
+
import { DashboardFilters } from '../types/DashboardFilters'
|
|
20
|
+
import { hasDashboardApplyBehavior } from '../helpers/hasDashboardApplyBehavior'
|
|
21
|
+
|
|
22
|
+
type VisualizationWrapperProps = {
|
|
23
|
+
allExpanded: boolean
|
|
24
|
+
children: React.ReactNode
|
|
25
|
+
currentViewport: ViewPort
|
|
26
|
+
groupName: string
|
|
27
|
+
row: ConfigRow
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const VisualizationWrapper: React.FC<VisualizationWrapperProps> = ({ allExpanded, currentViewport, groupName, row, children }) => {
|
|
31
|
+
return row.expandCollapseAllButtons ? (
|
|
32
|
+
<div className='collapsable-multiviz-container'>
|
|
33
|
+
<CollapsibleVisualizationRow allExpanded={allExpanded} fontSize={'26px'} groupName={groupName} currentViewport={currentViewport}>
|
|
34
|
+
{children}
|
|
35
|
+
</CollapsibleVisualizationRow>
|
|
36
|
+
</div>
|
|
37
|
+
) : (
|
|
38
|
+
<>
|
|
39
|
+
<h3>{groupName}</h3>
|
|
40
|
+
{children}
|
|
41
|
+
</>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
19
44
|
|
|
20
45
|
type VizRowProps = {
|
|
46
|
+
allExpanded: boolean
|
|
21
47
|
filteredDataOverride?: Object[]
|
|
48
|
+
groupName: string
|
|
22
49
|
row: ConfigRow
|
|
23
50
|
rowIndex: number
|
|
24
51
|
setSharedFilter: Function
|
|
25
52
|
updateChildConfig: Function
|
|
26
|
-
applyFilters: MouseEventHandler<HTMLButtonElement>
|
|
27
53
|
apiFilterDropdowns: APIFilterDropdowns
|
|
28
|
-
handleOnChange: Function
|
|
29
54
|
currentViewport: ViewPort
|
|
30
55
|
}
|
|
31
56
|
|
|
32
|
-
const VisualizationRow: React.FC<VizRowProps> = ({ filteredDataOverride, row, rowIndex: index, setSharedFilter, updateChildConfig, applyFilters, apiFilterDropdowns, handleOnChange, currentViewport }) => {
|
|
57
|
+
const VisualizationRow: React.FC<VizRowProps> = ({ allExpanded, filteredDataOverride, groupName, row, rowIndex: index, setSharedFilter, updateChildConfig, applyFilters, apiFilterDropdowns, handleOnChange, currentViewport }) => {
|
|
33
58
|
const { config, filteredData: dashboardFilteredData, data: rawData } = useContext(DashboardContext)
|
|
34
59
|
const [show, setShow] = React.useState(row.columns.map((col, i) => i === 0))
|
|
35
60
|
const setToggled = (colIndex: number) => {
|
|
36
61
|
setShow(show.map((_, i) => i === colIndex))
|
|
37
62
|
}
|
|
38
63
|
const inNoDataState = useMemo(() => {
|
|
39
|
-
const vals = Object.values(rawData)
|
|
64
|
+
const vals = Object.values(rawData).flatMap(val => val)
|
|
40
65
|
if (!vals.length) return true
|
|
41
66
|
return vals.some(val => val === undefined)
|
|
42
67
|
}, [rawData])
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
68
|
+
|
|
69
|
+
const footnotesConfig = useMemo(() => {
|
|
70
|
+
if (row.footnotesId) {
|
|
71
|
+
const footnoteConfig = getFootnotesVizConfig(row.footnotesId, index, config)
|
|
72
|
+
if (row.multiVizColumn && filteredDataOverride) {
|
|
73
|
+
const vizCategory = filteredDataOverride[0][row.multiVizColumn]
|
|
74
|
+
// the multiViz filtering filtering is applied after the dashboard filters
|
|
75
|
+
const categoryFootnote = footnoteConfig.formattedData.filter(d => d[row.multiVizColumn] === vizCategory)
|
|
76
|
+
footnoteConfig.formattedData = categoryFootnote
|
|
77
|
+
}
|
|
78
|
+
return footnoteConfig
|
|
46
79
|
}
|
|
47
80
|
return null
|
|
81
|
+
}, [config, row, rawData, dashboardFilteredData])
|
|
82
|
+
|
|
83
|
+
const applyButtonNotClicked = (vizConfig: DashboardFilters): boolean => {
|
|
84
|
+
const dashboardFilters = Object.values(config.visualizations).filter(v => v.type === 'dashboardFilters') as DashboardFilters[]
|
|
85
|
+
const applyFilters = dashboardFilters.filter(v => !v.autoLoad).flatMap(v => v.sharedFilterIndexes)
|
|
86
|
+
if (hasDashboardApplyBehavior(config.visualizations) && vizConfig.autoLoad) {
|
|
87
|
+
return applyFilters.some(index => {
|
|
88
|
+
const { queuedActive, active } = config.dashboard.sharedFilters[index]
|
|
89
|
+
if (!active && !queuedActive) return true
|
|
90
|
+
if (!queuedActive) return false
|
|
91
|
+
return queuedActive !== active
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
return false
|
|
48
95
|
}
|
|
49
96
|
return (
|
|
50
|
-
<div className={`
|
|
97
|
+
<div className={`row mb-5 ${row.equalHeight ? 'equal-height' : ''} ${row.toggle ? 'toggle' : ''}`} key={`row__${index}`}>
|
|
51
98
|
{row.toggle && <Toggle row={row} visualizations={config.visualizations} active={show.indexOf(true)} setToggled={setToggled} />}
|
|
52
99
|
{row.columns.map((col, colIndex) => {
|
|
53
100
|
if (col.width) {
|
|
54
|
-
if (!col.widget) return <div key={`row__${index}__col__${colIndex}`} className={`
|
|
101
|
+
if (!col.widget) return <div key={`row__${index}__col__${colIndex}`} className={`col-md-${col.width}`}></div>
|
|
55
102
|
|
|
56
103
|
const visualizationConfig = getVizConfig(col.widget, index, config, rawData, dashboardFilteredData)
|
|
57
104
|
if (filteredDataOverride) {
|
|
@@ -68,12 +115,15 @@ const VisualizationRow: React.FC<VizRowProps> = ({ filteredDataOverride, row, ro
|
|
|
68
115
|
{visualizationConfig.dataKey} (Go to Table)
|
|
69
116
|
</a>
|
|
70
117
|
)
|
|
71
|
-
const hideFilter = visualizationConfig.
|
|
118
|
+
const hideFilter = inNoDataState && visualizationConfig.type === 'dashboardFilters' && applyButtonNotClicked(visualizationConfig)
|
|
72
119
|
|
|
73
120
|
const shouldShow = row.toggle === undefined || (row.toggle && show[colIndex])
|
|
121
|
+
|
|
122
|
+
const body = <></>
|
|
123
|
+
|
|
74
124
|
return (
|
|
75
|
-
<
|
|
76
|
-
<
|
|
125
|
+
<div key={`vis__${index}__${colIndex}`} className={`col-${col.width} ${!shouldShow ? 'd-none' : ''}`}>
|
|
126
|
+
<VisualizationWrapper allExpanded={allExpanded} currentViewport={currentViewport} groupName={groupName} row={row}>
|
|
77
127
|
{visualizationConfig.type === 'chart' && (
|
|
78
128
|
<CdcChart
|
|
79
129
|
key={col.widget}
|
|
@@ -134,12 +184,12 @@ const VisualizationRow: React.FC<VizRowProps> = ({ filteredDataOverride, row, ro
|
|
|
134
184
|
<CdcMarkupInclude
|
|
135
185
|
key={col.widget}
|
|
136
186
|
config={visualizationConfig}
|
|
187
|
+
configUrl={undefined}
|
|
188
|
+
isDashboard={true}
|
|
137
189
|
isEditor={false}
|
|
138
190
|
setConfig={newConfig => {
|
|
139
191
|
updateChildConfig(col.widget, newConfig)
|
|
140
192
|
}}
|
|
141
|
-
isDashboard={true}
|
|
142
|
-
configUrl={undefined}
|
|
143
193
|
/>
|
|
144
194
|
)}
|
|
145
195
|
{visualizationConfig.type === 'filtered-text' && (
|
|
@@ -154,19 +204,36 @@ const VisualizationRow: React.FC<VizRowProps> = ({ filteredDataOverride, row, ro
|
|
|
154
204
|
configUrl={undefined}
|
|
155
205
|
/>
|
|
156
206
|
)}
|
|
157
|
-
{visualizationConfig.type === '
|
|
158
|
-
<
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
207
|
+
{visualizationConfig.type === 'dashboardFilters' && !hideFilter && (
|
|
208
|
+
<DashboardSharedFilters
|
|
209
|
+
setConfig={newConfig => {
|
|
210
|
+
updateChildConfig(col.widget, newConfig)
|
|
211
|
+
}}
|
|
212
|
+
key={col.widget}
|
|
213
|
+
visualizationConfig={visualizationConfig as DashboardFilters}
|
|
214
|
+
apiFilterDropdowns={apiFilterDropdowns}
|
|
215
|
+
currentViewport={currentViewport}
|
|
216
|
+
/>
|
|
217
|
+
)}
|
|
218
|
+
{visualizationConfig.type === 'table' && (
|
|
219
|
+
<DataTableStandAlone
|
|
220
|
+
key={col.widget}
|
|
221
|
+
updateConfig={newConfig => {
|
|
222
|
+
updateChildConfig(col.widget, newConfig)
|
|
223
|
+
}}
|
|
224
|
+
visualizationKey={col.widget}
|
|
225
|
+
config={visualizationConfig as TableConfig}
|
|
226
|
+
viewport={currentViewport}
|
|
227
|
+
/>
|
|
162
228
|
)}
|
|
163
|
-
{visualizationConfig.type === '
|
|
164
|
-
</
|
|
165
|
-
</
|
|
229
|
+
{visualizationConfig.type === 'footnotes' && <FootnotesStandAlone key={col.widget} visualizationKey={col.widget} config={visualizationConfig} viewport={currentViewport} />}
|
|
230
|
+
</VisualizationWrapper>
|
|
231
|
+
</div>
|
|
166
232
|
)
|
|
167
233
|
}
|
|
168
234
|
return <React.Fragment key={`vis__${index}__${colIndex}`}></React.Fragment>
|
|
169
235
|
})}
|
|
236
|
+
{row.footnotesId ? <FootnotesStandAlone isEditor={false} visualizationKey={row.footnotesId} config={footnotesConfig} viewport={currentViewport} /> : null}
|
|
170
237
|
</div>
|
|
171
238
|
)
|
|
172
239
|
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { useContext, useState } from 'react'
|
|
2
|
+
import type { AnyVisualization } from '@cdc/core/types/Visualization'
|
|
3
|
+
import Widget from '../Widget'
|
|
4
|
+
import AdvancedEditor from '@cdc/core/components/AdvancedEditor'
|
|
5
|
+
import { Table } from '@cdc/core/types/Table'
|
|
6
|
+
import { DashboardContext, DashboardDispatchContext } from '../../DashboardContext'
|
|
7
|
+
import { mapDataToConfig } from '../../helpers/mapDataToConfig'
|
|
8
|
+
import './visualizations-panel-styles.css'
|
|
9
|
+
|
|
10
|
+
const addVisualization = (type, subType) => {
|
|
11
|
+
const modalWillOpen = type !== 'markup-include'
|
|
12
|
+
const newVisualizationConfig: Partial<AnyVisualization> = {
|
|
13
|
+
filters: [],
|
|
14
|
+
filterBehavior: 'Filter Change',
|
|
15
|
+
newViz: type !== 'table',
|
|
16
|
+
openModal: modalWillOpen,
|
|
17
|
+
uid: type + Date.now(),
|
|
18
|
+
type
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
switch (type) {
|
|
22
|
+
case 'chart':
|
|
23
|
+
newVisualizationConfig.visualizationType = subType
|
|
24
|
+
break
|
|
25
|
+
case 'map':
|
|
26
|
+
newVisualizationConfig.general = {}
|
|
27
|
+
newVisualizationConfig.general.geoType = subType
|
|
28
|
+
break
|
|
29
|
+
case 'data-bite' || 'waffle-chart' || 'filtered-text':
|
|
30
|
+
newVisualizationConfig.visualizationType = type
|
|
31
|
+
break
|
|
32
|
+
case 'table':
|
|
33
|
+
const tableConfig: Table = { label: 'Data Table', show: true, showDownloadUrl: false, showVertical: true, expanded: true, collapsible: true }
|
|
34
|
+
newVisualizationConfig.table = tableConfig
|
|
35
|
+
newVisualizationConfig.columns = {}
|
|
36
|
+
newVisualizationConfig.dataFormat = {}
|
|
37
|
+
newVisualizationConfig.visualizationType = type
|
|
38
|
+
break
|
|
39
|
+
case 'markup-include':
|
|
40
|
+
newVisualizationConfig.contentEditor = {
|
|
41
|
+
inlineHTML: '<h2>Inline HTML</h2>',
|
|
42
|
+
markupVariables: [],
|
|
43
|
+
showHeader: true,
|
|
44
|
+
srcUrl: '#example',
|
|
45
|
+
title: 'Markup Include',
|
|
46
|
+
useInlineHTML: true
|
|
47
|
+
}
|
|
48
|
+
newVisualizationConfig.theme = 'theme-blue'
|
|
49
|
+
newVisualizationConfig.visual = {
|
|
50
|
+
border: false,
|
|
51
|
+
accent: false,
|
|
52
|
+
background: false,
|
|
53
|
+
hideBackgroundColor: false,
|
|
54
|
+
borderColorTheme: false
|
|
55
|
+
}
|
|
56
|
+
newVisualizationConfig.showEditorPanel = true
|
|
57
|
+
newVisualizationConfig.visualizationType = type
|
|
58
|
+
|
|
59
|
+
break
|
|
60
|
+
case 'dashboardFilters': {
|
|
61
|
+
newVisualizationConfig.sharedFilterIndexes = []
|
|
62
|
+
newVisualizationConfig.visualizationType = type
|
|
63
|
+
break
|
|
64
|
+
}
|
|
65
|
+
default:
|
|
66
|
+
newVisualizationConfig.visualizationType = type
|
|
67
|
+
break
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return newVisualizationConfig
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const VisualizationsPanel = () => {
|
|
74
|
+
const [advancedEditing, setAdvancedEditing] = useState(false)
|
|
75
|
+
const { config } = useContext(DashboardContext)
|
|
76
|
+
const dispatch = useContext(DashboardDispatchContext)
|
|
77
|
+
const loadConfig = newConfig => dispatch({ type: 'APPLY_CONFIG', payload: [mapDataToConfig(newConfig)] })
|
|
78
|
+
return (
|
|
79
|
+
<div className={`visualizations-panel${advancedEditing ? ' advanced-editor' : ''}`}>
|
|
80
|
+
<p style={{ fontSize: '14px' }}>Click and drag an item onto the grid to add it to your dashboard.</p>
|
|
81
|
+
<span className='subheading-3'>Chart</span>
|
|
82
|
+
<div className='drag-grid'>
|
|
83
|
+
<Widget addVisualization={() => addVisualization('chart', 'Bar')} type='Bar' />
|
|
84
|
+
<Widget addVisualization={() => addVisualization('chart', 'Line')} type='Line' />
|
|
85
|
+
<Widget addVisualization={() => addVisualization('chart', 'Pie')} type='Pie' />
|
|
86
|
+
<Widget addVisualization={() => addVisualization('chart', 'Sankey')} type='Sankey' />
|
|
87
|
+
</div>
|
|
88
|
+
<span className='subheading-3'>Map</span>
|
|
89
|
+
<div className='drag-grid'>
|
|
90
|
+
<Widget addVisualization={() => addVisualization('map', 'us')} type='us' />
|
|
91
|
+
<Widget addVisualization={() => addVisualization('map', 'world')} type='world' />
|
|
92
|
+
<Widget addVisualization={() => addVisualization('map', 'single-state')} type='single-state' />
|
|
93
|
+
</div>
|
|
94
|
+
<span className='subheading-3'>Misc.</span>
|
|
95
|
+
<div className='drag-grid'>
|
|
96
|
+
<Widget addVisualization={() => addVisualization('data-bite', '')} type='data-bite' />
|
|
97
|
+
<Widget addVisualization={() => addVisualization('waffle-chart', '')} type='waffle-chart' />
|
|
98
|
+
<Widget addVisualization={() => addVisualization('markup-include', '')} type='markup-include' />
|
|
99
|
+
<Widget addVisualization={() => addVisualization('filtered-text', '')} type='filtered-text' />
|
|
100
|
+
<Widget addVisualization={() => addVisualization('dashboardFilters', '')} type='dashboardFilters' />
|
|
101
|
+
<Widget addVisualization={() => addVisualization('table', '')} type='table' />
|
|
102
|
+
</div>
|
|
103
|
+
<span className='subheading-3'>Advanced</span>
|
|
104
|
+
<AdvancedEditor
|
|
105
|
+
loadConfig={loadConfig}
|
|
106
|
+
config={config}
|
|
107
|
+
convertStateToConfig={() => undefined}
|
|
108
|
+
onExpandCollapse={() => {
|
|
109
|
+
setAdvancedEditing(!advancedEditing)
|
|
110
|
+
}}
|
|
111
|
+
/>
|
|
112
|
+
</div>
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export default VisualizationsPanel
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './VisualizationsPanel'
|