@cdc/filtered-text 4.26.2 → 4.26.3
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/LICENSE +201 -0
- package/dist/cdcfilteredtext.js +5994 -5386
- package/examples/default.json +7 -1
- package/package.json +3 -3
- package/src/CdcFilteredText.jsx +28 -41
- package/src/components/EditorPanel/EditorPanel.tsx +58 -3
- package/src/scss/main.scss +8 -15
- package/src/test/CdcFilteredText.test.jsx +2 -2
package/examples/default.json
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cdc/filtered-text",
|
|
3
|
-
"version": "4.26.
|
|
3
|
+
"version": "4.26.3",
|
|
4
4
|
"description": "React component for adding filtered text on dashboards.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Adam Doe <rsq2@cdc.gov>",
|
|
7
7
|
"bugs": "https://github.com/CDCgov/cdc-open-viz/issues",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@cdc/core": "^4.26.
|
|
9
|
+
"@cdc/core": "^4.26.3",
|
|
10
10
|
"html-react-parser": "^5.2.3",
|
|
11
11
|
"lodash": "^4.17.23"
|
|
12
12
|
},
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"vite-plugin-css-injected-by-js": "^2.4.0",
|
|
18
18
|
"vite-plugin-svgr": "^4.2.0"
|
|
19
19
|
},
|
|
20
|
-
"gitHead": "
|
|
20
|
+
"gitHead": "d50e45a074fbefa56cac904917e707d57f237737",
|
|
21
21
|
"homepage": "https://github.com/CDCgov/cdc-open-viz#readme",
|
|
22
22
|
"main": "dist/cdcfilteredtext",
|
|
23
23
|
"moduleName": "CdcFilteredText",
|
package/src/CdcFilteredText.jsx
CHANGED
|
@@ -12,9 +12,10 @@ import EditorPanel from './components/EditorPanel'
|
|
|
12
12
|
|
|
13
13
|
// helpers
|
|
14
14
|
import DataTransform from '@cdc/core/helpers/DataTransform'
|
|
15
|
+
import fetchRemoteData from '@cdc/core/helpers/fetchRemoteData'
|
|
15
16
|
import useDataVizClasses from '@cdc/core/helpers/useDataVizClasses'
|
|
16
17
|
import coveUpdateWorker from '@cdc/core/helpers/coveUpdateWorker'
|
|
17
|
-
import
|
|
18
|
+
import { VisualizationContainer, VisualizationContent } from '@cdc/core/components/Layout'
|
|
18
19
|
|
|
19
20
|
// external
|
|
20
21
|
import parse from 'html-react-parser'
|
|
@@ -38,10 +39,6 @@ const CdcFilteredText = ({
|
|
|
38
39
|
let { title, filters } = config
|
|
39
40
|
|
|
40
41
|
const { contentClasses, innerContainerClasses } = useDataVizClasses(config)
|
|
41
|
-
const { visual } = config
|
|
42
|
-
|
|
43
|
-
const shouldApplyTopPadding = visual?.border || visual?.background || (config.title && config.titleStyle === 'legacy')
|
|
44
|
-
const shouldApplySidePadding = visual?.border || visual?.accent || visual?.background
|
|
45
42
|
|
|
46
43
|
// Default Functions
|
|
47
44
|
|
|
@@ -51,9 +48,9 @@ const CdcFilteredText = ({
|
|
|
51
48
|
let data = response.formattedData || response.data || {}
|
|
52
49
|
|
|
53
50
|
if (response.dataUrl) {
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
const { data: fetchedData, dataMetadata } = await fetchRemoteData(response.dataUrl)
|
|
52
|
+
data = fetchedData
|
|
53
|
+
response.dataMetadata = dataMetadata
|
|
57
54
|
if (response.dataDescription) {
|
|
58
55
|
data = transform.autoStandardize(data)
|
|
59
56
|
data = transform.developerStandardize(data, response.dataDescription)
|
|
@@ -122,39 +119,29 @@ const CdcFilteredText = ({
|
|
|
122
119
|
let content = <Loading />
|
|
123
120
|
|
|
124
121
|
if (loading === false) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
))}
|
|
146
|
-
</div>
|
|
147
|
-
</div>
|
|
148
|
-
</Layout.Responsive>
|
|
149
|
-
</>
|
|
122
|
+
const body = (
|
|
123
|
+
<VisualizationContent
|
|
124
|
+
innerClassName={innerContainerClasses.join(' ')}
|
|
125
|
+
bodyClassName={contentClasses.join(' ')}
|
|
126
|
+
header={
|
|
127
|
+
<Title
|
|
128
|
+
classes={[`${config.theme}`, 'mb-0']}
|
|
129
|
+
title={title}
|
|
130
|
+
titleStyle={config.titleStyle}
|
|
131
|
+
config={config}
|
|
132
|
+
noContent={!config.textColumn}
|
|
133
|
+
/>
|
|
134
|
+
}
|
|
135
|
+
>
|
|
136
|
+
{filterByTextColumn()
|
|
137
|
+
.slice(0, 1)
|
|
138
|
+
.map((el, i) => (
|
|
139
|
+
<p key={i}> {parse(el[config.textColumn] || '')} </p>
|
|
140
|
+
))}
|
|
141
|
+
</VisualizationContent>
|
|
150
142
|
)
|
|
151
143
|
|
|
152
|
-
content =
|
|
153
|
-
<>
|
|
154
|
-
{isEditor && <EditorPanel />}
|
|
155
|
-
{body}
|
|
156
|
-
</>
|
|
157
|
-
)
|
|
144
|
+
content = body
|
|
158
145
|
}
|
|
159
146
|
const values = {
|
|
160
147
|
config,
|
|
@@ -169,9 +156,9 @@ const CdcFilteredText = ({
|
|
|
169
156
|
return (
|
|
170
157
|
<ErrorBoundary component='CdcFilteredText'>
|
|
171
158
|
<ConfigContext.Provider value={values}>
|
|
172
|
-
<
|
|
159
|
+
<VisualizationContainer config={config} isEditor={isEditor} editorPanel={<EditorPanel />}>
|
|
173
160
|
{content}
|
|
174
|
-
</
|
|
161
|
+
</VisualizationContainer>
|
|
175
162
|
</ConfigContext.Provider>
|
|
176
163
|
</ErrorBoundary>
|
|
177
164
|
)
|
|
@@ -10,12 +10,13 @@ import { useDataColumns } from '@cdc/core/hooks/useDataColumns'
|
|
|
10
10
|
|
|
11
11
|
// Components
|
|
12
12
|
import { EditorPanel as BaseEditorPanel } from '@cdc/core/components/EditorPanel/EditorPanel'
|
|
13
|
-
import { TextField, Select
|
|
13
|
+
import { TextField, Select } from '@cdc/core/components/EditorPanel/Inputs'
|
|
14
14
|
import Button from '@cdc/core/components/elements/Button'
|
|
15
15
|
import Icon from '@cdc/core/components/ui/Icon'
|
|
16
16
|
import Tooltip from '@cdc/core/components/ui/Tooltip'
|
|
17
17
|
import Accordion from '@cdc/core/components/ui/Accordion'
|
|
18
|
-
import
|
|
18
|
+
import StyleTreatmentSection from '@cdc/core/components/EditorPanel/sections/StyleTreatmentSection'
|
|
19
|
+
import { HeaderThemeSelector } from '@cdc/core/components/HeaderThemeSelector'
|
|
19
20
|
|
|
20
21
|
type FilteredTextEditorPanelProps = {
|
|
21
22
|
// Add any props if needed
|
|
@@ -24,6 +25,21 @@ type FilteredTextEditorPanelProps = {
|
|
|
24
25
|
const EditorPanel: React.FC<FilteredTextEditorPanelProps> = () => {
|
|
25
26
|
const { config, updateConfig, loading, stateData: data, setParentConfig, isDashboard } = useContext(ConfigContext)
|
|
26
27
|
const updateField = updateFieldFactory(config, updateConfig, true)
|
|
28
|
+
const styleTreatment = config?.visual?.tp5Treatment ? 'tp5' : 'legacy'
|
|
29
|
+
|
|
30
|
+
const handleStyleTreatmentChange = (value: string) => {
|
|
31
|
+
const useTp5Treatment = value === 'tp5'
|
|
32
|
+
updateConfig({
|
|
33
|
+
...config,
|
|
34
|
+
visual: {
|
|
35
|
+
...config.visual,
|
|
36
|
+
tp5Treatment: useTp5Treatment,
|
|
37
|
+
border: useTp5Treatment ? false : config.visual?.border,
|
|
38
|
+
borderColorTheme: useTp5Treatment ? false : config.visual?.borderColorTheme,
|
|
39
|
+
accent: useTp5Treatment ? false : config.visual?.accent
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
}
|
|
27
43
|
|
|
28
44
|
// Filters -------------------------
|
|
29
45
|
const { addNewFilter, removeFilter, updateFilterProp, getFilterColumnValues } = useFilterManagement(
|
|
@@ -78,6 +94,29 @@ const EditorPanel: React.FC<FilteredTextEditorPanelProps> = () => {
|
|
|
78
94
|
</Tooltip>
|
|
79
95
|
}
|
|
80
96
|
/>
|
|
97
|
+
<Select
|
|
98
|
+
value={config.locale}
|
|
99
|
+
fieldName='locale'
|
|
100
|
+
label='Language for dates and numbers'
|
|
101
|
+
updateField={updateField}
|
|
102
|
+
options={[
|
|
103
|
+
{ value: 'en-US', label: 'English (en-US)' },
|
|
104
|
+
{ value: 'es-MX', label: 'Spanish (es-MX)' }
|
|
105
|
+
]}
|
|
106
|
+
tooltip={
|
|
107
|
+
<Tooltip style={{ textTransform: 'none' }}>
|
|
108
|
+
<Tooltip.Target>
|
|
109
|
+
<Icon display='question' style={{ marginLeft: '0.5rem' }} />
|
|
110
|
+
</Tooltip.Target>
|
|
111
|
+
<Tooltip.Content>
|
|
112
|
+
<p>
|
|
113
|
+
Change the language (locale) for this visualization to alter the way dates and numbers are
|
|
114
|
+
formatted.
|
|
115
|
+
</p>
|
|
116
|
+
</Tooltip.Content>
|
|
117
|
+
</Tooltip>
|
|
118
|
+
}
|
|
119
|
+
/>
|
|
81
120
|
</Accordion.Section>
|
|
82
121
|
<Accordion.Section title='Data'>
|
|
83
122
|
<Select
|
|
@@ -149,7 +188,23 @@ const EditorPanel: React.FC<FilteredTextEditorPanelProps> = () => {
|
|
|
149
188
|
</Button>
|
|
150
189
|
</Accordion.Section>
|
|
151
190
|
<Accordion.Section title='Visual'>
|
|
152
|
-
<
|
|
191
|
+
<HeaderThemeSelector
|
|
192
|
+
selectedTheme={config.theme}
|
|
193
|
+
onThemeSelect={theme => updateConfig({ ...config, theme })}
|
|
194
|
+
/>
|
|
195
|
+
<StyleTreatmentSection
|
|
196
|
+
styleTreatment={styleTreatment}
|
|
197
|
+
onStyleTreatmentChange={handleStyleTreatmentChange}
|
|
198
|
+
showStyleTreatment={false}
|
|
199
|
+
border={config.visual?.border}
|
|
200
|
+
borderColorTheme={config.visual?.borderColorTheme}
|
|
201
|
+
accent={config.visual?.accent}
|
|
202
|
+
background={config.visual?.background}
|
|
203
|
+
hideBackgroundColor={config.visual?.hideBackgroundColor}
|
|
204
|
+
showBackground
|
|
205
|
+
showHideBackgroundColor
|
|
206
|
+
updateField={updateField}
|
|
207
|
+
/>
|
|
153
208
|
</Accordion.Section>
|
|
154
209
|
</Accordion>
|
|
155
210
|
)}
|
package/src/scss/main.scss
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
@import '@cdc/core/styles/layout/wrapper-padding';
|
|
2
|
+
|
|
3
|
+
.cove-visualization.is-editor {
|
|
2
4
|
background: transparent;
|
|
3
5
|
}
|
|
4
6
|
|
|
@@ -12,23 +14,14 @@
|
|
|
12
14
|
}
|
|
13
15
|
}
|
|
14
16
|
|
|
15
|
-
.
|
|
17
|
+
.cove-visualization.type-filtered-text {
|
|
18
|
+
.cove-visualization__body {
|
|
19
|
+
@include cove-visualization-body-padding;
|
|
20
|
+
}
|
|
21
|
+
|
|
16
22
|
.cove-accordion__panel-section .cove-input__checkbox--small {
|
|
17
23
|
// float: initial;
|
|
18
24
|
// display: initial;
|
|
19
25
|
float: none;
|
|
20
26
|
}
|
|
21
|
-
.cove-component__content.body:not(:empty) {
|
|
22
|
-
padding: 0;
|
|
23
|
-
|
|
24
|
-
&.has-top-padding {
|
|
25
|
-
padding-top: 1rem;
|
|
26
|
-
padding-bottom: 1rem;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
&.has-side-padding {
|
|
30
|
-
padding-left: 1rem;
|
|
31
|
-
padding-right: 1rem;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
27
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import path from 'path'
|
|
1
|
+
import path from 'node:path'
|
|
2
2
|
import { testStandaloneBuild } from '@cdc/core/helpers/tests/testStandaloneBuild.ts'
|
|
3
3
|
import { describe, it, expect } from 'vitest'
|
|
4
4
|
|
|
5
5
|
describe('Filtered Text', () => {
|
|
6
6
|
it('Can be built in isolation', async () => {
|
|
7
7
|
const pkgDir = path.join(__dirname, '..')
|
|
8
|
-
const result = testStandaloneBuild(pkgDir)
|
|
8
|
+
const result = await testStandaloneBuild(pkgDir)
|
|
9
9
|
expect(result).toBe(true)
|
|
10
10
|
}, 300000)
|
|
11
11
|
})
|