@cdc/dashboard 4.24.5 → 4.24.9-1
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 +147572 -128223
- 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/examples/single-state-dashboard-filters.json +421 -0
- package/examples/state-level.json +90136 -0
- package/examples/state-points.json +10474 -0
- package/examples/test-file.json +147 -0
- package/examples/testing.json +94456 -0
- package/index.html +25 -4
- package/package.json +12 -11
- package/src/CdcDashboard.tsx +5 -1
- package/src/CdcDashboardComponent.tsx +250 -327
- package/src/DashboardContext.tsx +15 -1
- package/src/_stories/Dashboard.stories.tsx +158 -40
- package/src/_stories/_mock/api-filter-chart.json +11 -35
- package/src/_stories/_mock/api-filter-map.json +17 -31
- package/src/_stories/_mock/bump-chart.json +3554 -0
- package/src/_stories/_mock/methodology.json +412 -0
- package/src/_stories/_mock/methodologyAPI.ts +90 -0
- package/src/_stories/_mock/multi-viz.json +3 -4
- package/src/_stories/_mock/pivot-filter.json +14 -12
- package/src/_stories/_mock/single-state-dashboard-filters.json +390 -0
- package/src/components/CollapsibleVisualizationRow.tsx +44 -0
- package/src/components/Column.tsx +1 -1
- package/src/components/DashboardFilters/DashboardFilters.tsx +102 -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 +477 -0
- package/src/components/DashboardFilters/DashboardFiltersEditor/index.ts +1 -0
- package/src/components/DashboardFilters/DashboardFiltersWrapper.tsx +191 -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 -102
- package/src/components/MultiConfigTabs/MultiConfigTabs.tsx +24 -12
- package/src/components/Row.tsx +52 -19
- package/src/components/Toggle/Toggle.tsx +2 -4
- package/src/components/VisualizationRow.tsx +169 -30
- 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 +27 -90
- package/src/helpers/FilterBehavior.ts +4 -0
- package/src/helpers/addValuesToDashboardFilters.ts +49 -0
- package/src/helpers/apiFilterHelpers.ts +103 -0
- package/src/helpers/changeFilterActive.ts +39 -0
- package/src/helpers/filterData.ts +10 -48
- package/src/helpers/generateValuesForFilter.ts +1 -1
- package/src/helpers/getAutoLoadVisualization.ts +11 -0
- package/src/helpers/getFilteredData.ts +7 -5
- 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 +5 -3
- package/src/helpers/loadAPIFilters.ts +74 -0
- package/src/helpers/mapDataToConfig.ts +29 -0
- package/src/helpers/processData.ts +2 -3
- package/src/helpers/reloadURLHelpers.ts +102 -0
- package/src/helpers/tests/addValuesToDashboardFilters.test.ts +44 -0
- package/src/helpers/tests/apiFilterHelpers.test.ts +155 -0
- package/src/helpers/tests/filterData.test.ts +1 -93
- package/src/helpers/tests/getFilteredData.test.ts +86 -0
- package/src/helpers/tests/loadAPIFiltersWrapper.test.ts +220 -0
- package/src/helpers/tests/reloadURLHelpers.test.ts +232 -0
- 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 +12 -4
- package/src/store/dashboard.reducer.ts +30 -4
- package/src/types/APIFilter.ts +1 -5
- 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 +4 -6
- package/src/types/Tab.ts +1 -1
- package/src/components/Filters.tsx +0 -88
- package/src/components/Header/FilterModal.tsx +0 -510
- package/src/components/VisualizationsPanel.tsx +0 -95
- package/src/helpers/getApiFilterKey.ts +0 -5
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { Accordion, AccordionItem, AccordionItemButton, AccordionItemHeading, AccordionItemPanel } from 'react-accessible-accordion'
|
|
2
|
+
import { useContext, useMemo, useState } from 'react'
|
|
3
|
+
import { CheckBox, Select } from '@cdc/core/components/EditorPanel/Inputs'
|
|
4
|
+
import Tooltip from '@cdc/core/components/ui/Tooltip'
|
|
5
|
+
import Icon from '@cdc/core/components/ui/Icon'
|
|
6
|
+
import FieldSetWrapper from '@cdc/core/components/EditorPanel/FieldSetWrapper'
|
|
7
|
+
import FilterEditor from './components/FilterEditor'
|
|
8
|
+
import { AnyVisualization } from '@cdc/core/types/Visualization'
|
|
9
|
+
import { DashboardContext, DashboardDispatchContext } from '../../../DashboardContext'
|
|
10
|
+
import _ from 'lodash'
|
|
11
|
+
import { DashboardFilters } from '../../../types/DashboardFilters'
|
|
12
|
+
import { SharedFilter } from '../../../types/SharedFilter'
|
|
13
|
+
import { useGlobalContext } from '@cdc/core/components/GlobalContext'
|
|
14
|
+
import DeleteFilterModal from './components/DeleteFilterModal'
|
|
15
|
+
import { addValuesToDashboardFilters } from '../../../helpers/addValuesToDashboardFilters'
|
|
16
|
+
|
|
17
|
+
type DashboardFitlersEditorProps = {
|
|
18
|
+
vizConfig: DashboardFilters
|
|
19
|
+
updateConfig: Function
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const DashboardFiltersEditor: React.FC<DashboardFitlersEditorProps> = ({ vizConfig, updateConfig }) => {
|
|
23
|
+
const { config, loadAPIFilters, data } = useContext(DashboardContext)
|
|
24
|
+
const { overlay } = useGlobalContext()
|
|
25
|
+
const {
|
|
26
|
+
dashboard: { sharedFilters },
|
|
27
|
+
visualizations
|
|
28
|
+
} = config
|
|
29
|
+
const dispatch = useContext(DashboardDispatchContext)
|
|
30
|
+
|
|
31
|
+
const existingOptions = useMemo(() => {
|
|
32
|
+
const sharedFilterIndexes = (config.visualizations[vizConfig.uid] as DashboardFilters).sharedFilterIndexes.map(Number)
|
|
33
|
+
return config.dashboard.sharedFilters
|
|
34
|
+
.map<[number, string]>(({ key }, i) => [i, key])
|
|
35
|
+
.filter(([filterIndex]) => !sharedFilterIndexes.includes(filterIndex)) // filter out already added filters
|
|
36
|
+
.map(([filterIndex, filterName]) => <option key={filterIndex} value={filterIndex}>{`${filterIndex} - ${filterName}`}</option>)
|
|
37
|
+
}, [config.visualizations, vizConfig.uid])
|
|
38
|
+
|
|
39
|
+
const openControls = useState({})
|
|
40
|
+
const [canAddExisting, setCanAddExisting] = useState(false)
|
|
41
|
+
|
|
42
|
+
const updateFilterProp = (prop: string, index: number, value) => {
|
|
43
|
+
const newSharedFilters = _.cloneDeep(sharedFilters)
|
|
44
|
+
const oldEndpoint = sharedFilters[index].apiFilter?.apiEndpoint
|
|
45
|
+
const oldAPIValueSelector = sharedFilters[index].apiFilter?.valueSelector
|
|
46
|
+
const apiFilterChanged = value.apiEndpoint !== oldEndpoint || value.valueSelector !== oldAPIValueSelector
|
|
47
|
+
newSharedFilters[index][prop] = value
|
|
48
|
+
if (prop === 'columnName') {
|
|
49
|
+
// changing a data column and want to load the data into the preview options
|
|
50
|
+
const sharedFiltersWithValues = addValuesToDashboardFilters(newSharedFilters, data)
|
|
51
|
+
dispatch({ type: 'SET_SHARED_FILTERS', payload: sharedFiltersWithValues })
|
|
52
|
+
} else if (prop === 'apiFilter' && value.apiEndpoint && value.valueSelector && apiFilterChanged) {
|
|
53
|
+
// changing a api filter and want to load the api data into the preview.
|
|
54
|
+
// automatically dispatches SET_SHARED_FILTERS
|
|
55
|
+
loadAPIFilters(newSharedFilters, {})
|
|
56
|
+
} else {
|
|
57
|
+
dispatch({ type: 'SET_SHARED_FILTERS', payload: newSharedFilters })
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const removeFilter = index => {
|
|
62
|
+
const newSharedFilters = _.cloneDeep(sharedFilters)
|
|
63
|
+
|
|
64
|
+
newSharedFilters.splice(index, 1)
|
|
65
|
+
const shiftDownIndexes = Object.keys(sharedFilters).slice(index + 1)
|
|
66
|
+
const anyViz: Record<string, AnyVisualization> = visualizations
|
|
67
|
+
Object.keys(anyViz).forEach(vizKey => {
|
|
68
|
+
const viz = anyViz[vizKey]
|
|
69
|
+
if (viz.type === 'dashboardFilters') {
|
|
70
|
+
// shift the indexes down
|
|
71
|
+
const sharedFilterIndexes = viz.sharedFilterIndexes
|
|
72
|
+
.filter(filterIndex => filterIndex != index)
|
|
73
|
+
.map(filterIndex => {
|
|
74
|
+
if (shiftDownIndexes.includes(filterIndex.toString())) {
|
|
75
|
+
return filterIndex - 1
|
|
76
|
+
}
|
|
77
|
+
return filterIndex
|
|
78
|
+
})
|
|
79
|
+
dispatch({ type: 'UPDATE_VISUALIZATION', payload: { vizKey, configureData: { sharedFilterIndexes } } })
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
dispatch({ type: 'SET_SHARED_FILTERS', payload: newSharedFilters })
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const addNewFilter = () => {
|
|
86
|
+
const _sharedFilters = _.cloneDeep(sharedFilters) || []
|
|
87
|
+
const columnName = 'New Dashboard Filter ' + (_sharedFilters.length + 1)
|
|
88
|
+
const newFilter = { key: columnName, showDropdown: true, values: [] } as SharedFilter
|
|
89
|
+
dispatch({ type: 'SET_SHARED_FILTERS', payload: [..._sharedFilters, newFilter] })
|
|
90
|
+
updateConfig({ ...vizConfig, sharedFilterIndexes: [...vizConfig.sharedFilterIndexes, _sharedFilters.length] })
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<Accordion allowZeroExpanded={true}>
|
|
95
|
+
<AccordionItem>
|
|
96
|
+
<AccordionItemHeading>
|
|
97
|
+
<AccordionItemButton>General</AccordionItemButton>
|
|
98
|
+
</AccordionItemHeading>
|
|
99
|
+
<AccordionItemPanel>
|
|
100
|
+
<Select
|
|
101
|
+
value={vizConfig.filterBehavior}
|
|
102
|
+
label='Filter Behavior'
|
|
103
|
+
updateField={(_section, _subsection, _key, value) => {
|
|
104
|
+
updateConfig({ ...vizConfig, filterBehavior: value })
|
|
105
|
+
}}
|
|
106
|
+
options={['Apply Button', 'Filter Change']}
|
|
107
|
+
tooltip={
|
|
108
|
+
<Tooltip style={{ textTransform: 'none' }}>
|
|
109
|
+
<Tooltip.Target>
|
|
110
|
+
<Icon display='question' style={{ marginLeft: '0.5rem' }} />
|
|
111
|
+
</Tooltip.Target>
|
|
112
|
+
<Tooltip.Content>
|
|
113
|
+
<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>
|
|
114
|
+
</Tooltip.Content>
|
|
115
|
+
</Tooltip>
|
|
116
|
+
}
|
|
117
|
+
/>
|
|
118
|
+
{vizConfig.filterBehavior === 'Filter Change' && (
|
|
119
|
+
<CheckBox
|
|
120
|
+
label='Auto Load'
|
|
121
|
+
value={vizConfig.autoLoad}
|
|
122
|
+
updateField={(_section, _subsection, _key, value) => {
|
|
123
|
+
updateConfig({ ...vizConfig, autoLoad: value })
|
|
124
|
+
}}
|
|
125
|
+
tooltip={
|
|
126
|
+
<Tooltip style={{ textTransform: 'none' }}>
|
|
127
|
+
<Tooltip.Target>
|
|
128
|
+
<Icon display='question' style={{ marginLeft: '0.5rem' }} />
|
|
129
|
+
</Tooltip.Target>
|
|
130
|
+
<Tooltip.Content>
|
|
131
|
+
<p>Check if you would like for all URL filters to automatically select a value when a parent filter is changed.</p>
|
|
132
|
+
</Tooltip.Content>
|
|
133
|
+
</Tooltip>
|
|
134
|
+
}
|
|
135
|
+
/>
|
|
136
|
+
)}
|
|
137
|
+
</AccordionItemPanel>
|
|
138
|
+
</AccordionItem>
|
|
139
|
+
|
|
140
|
+
<AccordionItem>
|
|
141
|
+
<AccordionItemHeading>
|
|
142
|
+
<AccordionItemButton>Filters</AccordionItemButton>
|
|
143
|
+
</AccordionItemHeading>
|
|
144
|
+
<AccordionItemPanel>
|
|
145
|
+
{vizConfig.sharedFilterIndexes.map(index => {
|
|
146
|
+
const filter = sharedFilters[index]
|
|
147
|
+
return (
|
|
148
|
+
<FieldSetWrapper
|
|
149
|
+
key={filter.key + index}
|
|
150
|
+
fieldName={filter.key}
|
|
151
|
+
fieldKey={index}
|
|
152
|
+
fieldType='Dashboard Filter'
|
|
153
|
+
controls={openControls}
|
|
154
|
+
deleteField={() => {
|
|
155
|
+
overlay?.actions.openOverlay(
|
|
156
|
+
<DeleteFilterModal
|
|
157
|
+
removeFilterCompletely={removeFilter}
|
|
158
|
+
removeFilterFromViz={index => {
|
|
159
|
+
updateConfig({ ...vizConfig, sharedFilterIndexes: vizConfig.sharedFilterIndexes.filter(i => i !== index) })
|
|
160
|
+
}}
|
|
161
|
+
filterIndex={index}
|
|
162
|
+
/>
|
|
163
|
+
)
|
|
164
|
+
}}
|
|
165
|
+
>
|
|
166
|
+
<FilterEditor
|
|
167
|
+
filter={filter}
|
|
168
|
+
updateFilterProp={(name, value) => {
|
|
169
|
+
updateFilterProp(name, index, value)
|
|
170
|
+
}}
|
|
171
|
+
config={config}
|
|
172
|
+
/>
|
|
173
|
+
</FieldSetWrapper>
|
|
174
|
+
)
|
|
175
|
+
})}
|
|
176
|
+
<button onClick={addNewFilter} className='btn btn-primary full-width'>
|
|
177
|
+
Add Filter
|
|
178
|
+
</button>
|
|
179
|
+
{canAddExisting ? (
|
|
180
|
+
<label>
|
|
181
|
+
<span className='edit-label column-heading'>
|
|
182
|
+
Select Existing Dashboard Filter
|
|
183
|
+
<Tooltip style={{ textTransform: 'none' }}>
|
|
184
|
+
<Tooltip.Target>
|
|
185
|
+
<Icon display='question' style={{ marginLeft: '0.5rem' }} />
|
|
186
|
+
</Tooltip.Target>
|
|
187
|
+
<Tooltip.Content>
|
|
188
|
+
<p>This feature is indentended to support legacy functionality. Be advised that any change to the filter in this editor will reflect on the whole dashboard. </p>
|
|
189
|
+
</Tooltip.Content>
|
|
190
|
+
</Tooltip>
|
|
191
|
+
</span>
|
|
192
|
+
<select
|
|
193
|
+
value={''}
|
|
194
|
+
onChange={e => {
|
|
195
|
+
updateConfig({ ...vizConfig, sharedFilterIndexes: [...vizConfig.sharedFilterIndexes, e.target.value] })
|
|
196
|
+
setCanAddExisting(false)
|
|
197
|
+
}}
|
|
198
|
+
>
|
|
199
|
+
{[
|
|
200
|
+
<option key='select' value=''>
|
|
201
|
+
Select
|
|
202
|
+
</option>,
|
|
203
|
+
...existingOptions
|
|
204
|
+
]}
|
|
205
|
+
</select>
|
|
206
|
+
</label>
|
|
207
|
+
) : (
|
|
208
|
+
<button onClick={() => setCanAddExisting(true)} className='btn btn-primary full-width'>
|
|
209
|
+
Add Existing Dashboard Filter
|
|
210
|
+
</button>
|
|
211
|
+
)}
|
|
212
|
+
</AccordionItemPanel>
|
|
213
|
+
</AccordionItem>
|
|
214
|
+
</Accordion>
|
|
215
|
+
)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
export default DashboardFiltersEditor
|
package/src/components/DashboardFilters/DashboardFiltersEditor/components/DeleteFilterModal.tsx
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useGlobalContext } from '@cdc/core/components/GlobalContext'
|
|
2
|
+
import Modal from '@cdc/core/components/ui/Modal'
|
|
3
|
+
import { DashboardContext } from '../../../../DashboardContext'
|
|
4
|
+
import { useContext } from 'react'
|
|
5
|
+
import { DashboardFilters } from '../../../../types/DashboardFilters'
|
|
6
|
+
|
|
7
|
+
type DeleteFilterProps = {
|
|
8
|
+
removeFilterCompletely: (number) => void
|
|
9
|
+
removeFilterFromViz: (number) => void
|
|
10
|
+
filterIndex: number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const DeleteFilterModal: React.FC<DeleteFilterProps> = ({ removeFilterCompletely, removeFilterFromViz, filterIndex }) => {
|
|
14
|
+
const { overlay } = useGlobalContext()
|
|
15
|
+
const { config } = useContext(DashboardContext)
|
|
16
|
+
const filterUsedByMany = Object.values(config.visualizations).filter(viz => (viz as DashboardFilters).sharedFilterIndexes?.map(Number).includes(Number(filterIndex))).length > 1
|
|
17
|
+
|
|
18
|
+
const message = filterUsedByMany ? 'This filter is used by multiple visualizations. You can either delete the filter from this visualization only or you can delete the filter completely, which will also remove it from other visualizations.' : 'Are you sure you want to delete this filter?'
|
|
19
|
+
return (
|
|
20
|
+
<Modal showClose={true}>
|
|
21
|
+
<Modal.Content>
|
|
22
|
+
<p>{message}</p>
|
|
23
|
+
{filterUsedByMany && (
|
|
24
|
+
<button
|
|
25
|
+
className='btn btn-warning'
|
|
26
|
+
onClick={() => {
|
|
27
|
+
removeFilterFromViz(filterIndex)
|
|
28
|
+
overlay?.actions.toggleOverlay()
|
|
29
|
+
}}
|
|
30
|
+
>
|
|
31
|
+
Delete from Visualization
|
|
32
|
+
</button>
|
|
33
|
+
)}
|
|
34
|
+
<button
|
|
35
|
+
className='btn btn-danger'
|
|
36
|
+
onClick={() => {
|
|
37
|
+
removeFilterCompletely(filterIndex)
|
|
38
|
+
overlay?.actions.toggleOverlay()
|
|
39
|
+
}}
|
|
40
|
+
>
|
|
41
|
+
Delete{filterUsedByMany ? ' Completely' : ''}
|
|
42
|
+
</button>
|
|
43
|
+
</Modal.Content>
|
|
44
|
+
</Modal>
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default DeleteFilterModal
|