@cdc/filtered-text 4.25.10 → 4.26.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.
@@ -1,341 +0,0 @@
1
- import React, { memo, useState, useEffect, useContext } from 'react'
2
- import cloneConfig from '@cdc/core/helpers/cloneConfig'
3
- import _ from 'lodash'
4
- import ConfigContext from '../ConfigContext'
5
-
6
- import ErrorBoundary from '@cdc/core/components/ErrorBoundary'
7
- import Accordion from '@cdc/core/components/ui/Accordion'
8
- import InputText from '@cdc/core/components/inputs/InputText'
9
- import Button from '@cdc/core/components/elements/Button'
10
- import Icon from '@cdc/core/components/ui/Icon'
11
- import Tooltip from '@cdc/core/components/ui/Tooltip'
12
- import InputSelect from '@cdc/core/components/inputs/InputSelect'
13
- import InputCheckbox from '@cdc/core/components/inputs/InputCheckbox'
14
- import Layout from '@cdc/core/components/Layout'
15
- import { updateFieldFactory } from '@cdc/core/helpers/updateFieldFactory'
16
-
17
- import '@cdc/core/styles/v2/components/editor.scss'
18
-
19
- const headerColors = [
20
- 'theme-blue',
21
- 'theme-purple',
22
- 'theme-brown',
23
- 'theme-teal',
24
- 'theme-pink',
25
- 'theme-orange',
26
- 'theme-slate',
27
- 'theme-indigo',
28
- 'theme-cyan',
29
- 'theme-green',
30
- 'theme-amber'
31
- ]
32
-
33
- const EditorPanel = memo(props => {
34
- const { config, updateConfig, loading, stateData: data, setParentConfig, isDashboard } = useContext(ConfigContext)
35
-
36
- const [displayPanel, setDisplayPanel] = useState(true)
37
- const [showConfigConfirm, setShowConfigConfirm] = useState(false)
38
-
39
- const updateField = updateFieldFactory(config, updateConfig, true)
40
-
41
- const missingRequiredSections = () => {
42
- return false
43
- }
44
-
45
- // Filters -------------------------
46
- const removeFilter = index => {
47
- let filters = [...config.filters]
48
-
49
- filters.splice(index, 1)
50
-
51
- updateConfig({ ...config, filters })
52
- }
53
-
54
- const updateFilterProp = (name, index, value) => {
55
- let filters = [...config.filters]
56
-
57
- filters[index][name] = value
58
-
59
- updateConfig({ ...config, filters })
60
- }
61
-
62
- const addNewFilter = () => {
63
- let filters = config.filters ? [...config.filters] : []
64
-
65
- filters.push({ values: [] })
66
-
67
- updateConfig({ ...config, filters })
68
- }
69
-
70
- const getColumns = (filter = true) => {
71
- let columns = {}
72
- if (data.length) {
73
- data.map(row => {
74
- return Object.keys(row).forEach(columnName => (columns[columnName] = true))
75
- })
76
- }
77
-
78
- return Object.keys(columns)
79
- }
80
-
81
- const getFilterColumnValues = index => {
82
- let filterDataOptions = []
83
- const filterColumnName = config.filters[index].columnName
84
- if (data && filterColumnName) {
85
- data.forEach(function (row) {
86
- if (undefined !== row[filterColumnName] && -1 === filterDataOptions.indexOf(row[filterColumnName])) {
87
- filterDataOptions.push(row[filterColumnName])
88
- }
89
- })
90
- filterDataOptions.sort()
91
- }
92
- return filterDataOptions
93
- }
94
-
95
- useEffect(() => {
96
- // Pass up to Editor if needed
97
- if (setParentConfig) {
98
- const newConfig = convertStateToConfig()
99
- setParentConfig(newConfig)
100
- }
101
- }, [config])
102
-
103
- useEffect(() => {
104
- if (!showConfigConfirm) {
105
- let newConfig = { ...config }
106
- delete newConfig.newViz
107
- updateConfig(newConfig)
108
- }
109
- }, [])
110
-
111
- const onBackClick = () => {
112
- setDisplayPanel(!displayPanel)
113
- updateConfig({
114
- ...config,
115
- showEditorPanel: !displayPanel
116
- })
117
- }
118
-
119
- const Error = () => {
120
- return (
121
- <section className='waiting'>
122
- <section className='waiting-container'>
123
- <h3>Error With Configuration</h3>
124
- <p>{config.runtime.editorErrorMessage}</p>
125
- </section>
126
- </section>
127
- )
128
- }
129
-
130
- const Confirm = () => {
131
- const confirmDone = e => {
132
- e.preventDefault()
133
- let newConfig = { ...config }
134
- delete newConfig.newViz
135
- updateConfig(newConfig)
136
- }
137
-
138
- return (
139
- <section className='waiting'>
140
- <section className='waiting-container'>
141
- <h3>Finish Configuring</h3>
142
- <p>Set all required options to the left and confirm below to display a preview of the markup.</p>
143
- <button className='btn btn-primary' style={{ margin: '1em auto' }} onClick={confirmDone}>
144
- I'm Done
145
- </button>
146
- </section>
147
- </section>
148
- )
149
- }
150
- const convertStateToConfig = () => {
151
- let strippedState = cloneConfig(config)
152
- delete strippedState.newViz
153
- delete strippedState.runtime
154
-
155
- return strippedState
156
- }
157
- const editorContent = (
158
- <Accordion>
159
- <Accordion.Section title='General'>
160
- <InputText
161
- value={config.title}
162
- fieldName='title'
163
- label='Title'
164
- placeholder='Filterable Text Title'
165
- updateField={updateField}
166
- />
167
- </Accordion.Section>
168
- <Accordion.Section title='Data'>
169
- <div className='cove-accordion__panel-section'>
170
- <div className='cove-input-group'>
171
- <InputSelect
172
- value={config.textColumn || ''}
173
- fieldName='textColumn'
174
- label='Text Column'
175
- updateField={updateField}
176
- initial='Select'
177
- options={getColumns()}
178
- />
179
- </div>
180
- </div>
181
- <hr className='cove-accordion__divider' />
182
-
183
- <label style={{ marginBottom: '1rem' }}>
184
- <span className='edit-label'>Data Point Filters</span>
185
- <Tooltip style={{ textTransform: 'none' }}>
186
- <Tooltip.Target>
187
- <Icon display='question' style={{ marginLeft: '0.5rem' }} />
188
- </Tooltip.Target>
189
- <Tooltip.Content>
190
- <p>
191
- To refine the highlighted data point, specify one or more filters (e.g., "Male" and "Female" for a
192
- column called "Sex").
193
- </p>
194
- </Tooltip.Content>
195
- </Tooltip>
196
- </label>
197
- {config.filters && (
198
- <ul className='filters-list' style={{ paddingLeft: 0, marginBottom: '1rem' }}>
199
- {config.filters.map((filter, index) => (
200
- <fieldset className='edit-block' key={index}>
201
- <button
202
- type='button'
203
- className='remove-column'
204
- onClick={() => {
205
- removeFilter(index)
206
- }}
207
- >
208
- Remove
209
- </button>
210
- <label>
211
- <span className='edit-label column-heading'>Column</span>
212
- <select
213
- value={filter.columnName}
214
- onChange={e => {
215
- updateFilterProp('columnName', index, e.target.value)
216
- }}
217
- >
218
- <option value=''>- Select Option -</option>
219
- {getColumns().map((dataKey, index) => (
220
- <option value={dataKey} key={index}>
221
- {dataKey}
222
- </option>
223
- ))}
224
- </select>
225
- </label>
226
- <label>
227
- <span className='edit-label column-heading'>Column Value</span>
228
- <select
229
- value={filter.columnValue}
230
- onChange={e => {
231
- updateFilterProp('columnValue', index, e.target.value)
232
- }}
233
- >
234
- <option value=''>- Select Option -</option>
235
- {getFilterColumnValues(index).map((dataKey, index) => (
236
- <option value={dataKey} key={index}>
237
- {dataKey}
238
- </option>
239
- ))}
240
- </select>
241
- </label>
242
- </fieldset>
243
- ))}
244
- </ul>
245
- )}
246
- <Button onClick={addNewFilter} fluid>
247
- Add Filter
248
- </Button>
249
- </Accordion.Section>
250
- <Accordion.Section title='Visual'>
251
- <InputSelect
252
- value={config.fontSize}
253
- fieldName='fontSize'
254
- label='Font Size'
255
- updateField={updateField}
256
- options={['small', 'medium', 'large']}
257
- />
258
- <br />
259
- <label>
260
- <span className='edit-label'>Theme</span>
261
- <ul className='color-palette'>
262
- {headerColors.map(palette => (
263
- <li
264
- title={palette}
265
- key={palette}
266
- onClick={() => {
267
- updateConfig({ ...config, theme: palette })
268
- }}
269
- className={config.theme === palette ? 'selected ' + palette : palette}
270
- ></li>
271
- ))}
272
- </ul>
273
- </label>
274
-
275
- <div className='cove-accordion__panel-section checkbox-group'>
276
- <InputCheckbox
277
- inline
278
- size='small'
279
- value={config.visual.border}
280
- section='visual'
281
- fieldName='border'
282
- label='Display Border'
283
- updateField={updateField}
284
- />
285
- <InputCheckbox
286
- inline
287
- size='small'
288
- value={config.visual.borderColorTheme}
289
- section='visual'
290
- fieldName='borderColorTheme'
291
- label='Use theme border color'
292
- updateField={updateField}
293
- />
294
- <InputCheckbox
295
- size='small'
296
- value={config.visual.accent}
297
- section='visual'
298
- fieldName='accent'
299
- label='Use Accent Style'
300
- updateField={updateField}
301
- />
302
- <InputCheckbox
303
- size='small'
304
- value={config.visual.background}
305
- section='visual'
306
- fieldName='background'
307
- label='Use Theme Background Color'
308
- updateField={updateField}
309
- />
310
- <InputCheckbox
311
- size='small'
312
- value={config.visual.hideBackgroundColor}
313
- section='visual'
314
- fieldName='hideBackgroundColor'
315
- label='Hide Background Color'
316
- updateField={updateField}
317
- />
318
- </div>
319
- </Accordion.Section>
320
- </Accordion>
321
- )
322
-
323
- if (loading) return null
324
-
325
- return (
326
- <ErrorBoundary component='EditorPanel'>
327
- <Layout.Sidebar
328
- displayPanel={displayPanel}
329
- isDashboard={isDashboard}
330
- title={'Configure Filtered Text'}
331
- onBackClick={onBackClick}
332
- >
333
- {!config.newViz && config.runtime && config.runtime.editorErrorMessage && <Error />}
334
- {config.newViz && showConfigConfirm && <Confirm />}
335
- {editorContent}
336
- </Layout.Sidebar>
337
- </ErrorBoundary>
338
- )
339
- })
340
-
341
- export default EditorPanel