@cdc/data-bite 4.25.8 → 4.25.10
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/cdcdatabite.js +7905 -7239
- package/package.json +15 -5
- package/src/CdcDataBite.tsx +49 -8
- package/src/_stories/DataBite.Editor.stories.tsx +862 -0
- package/src/_stories/DataBite.stories.tsx +59 -35
- package/src/components/EditorPanel.jsx +23 -3
- package/src/data/initial-state.js +3 -1
- package/src/index.jsx +0 -1
- package/src/test/CdcDataBite.test.jsx +8 -3
- package/src/types/Config.ts +4 -2
- package/tests/fixtures/example-data.json +833 -0
- package/tests/fixtures/test-config.json +26 -0
- package/vite.config.js +1 -1
- package/vitest.config.ts +16 -0
- package/src/coreStyles_databite.scss +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cdc/data-bite",
|
|
3
|
-
"version": "4.25.
|
|
3
|
+
"version": "4.25.10",
|
|
4
4
|
"description": "React component for displaying a single piece of data in a card module",
|
|
5
5
|
"moduleName": "CdcDataBite",
|
|
6
6
|
"main": "dist/cdcdatabite",
|
|
@@ -27,13 +27,23 @@
|
|
|
27
27
|
"license": "Apache-2.0",
|
|
28
28
|
"homepage": "https://github.com/CDCgov/cdc-open-viz#readme",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@cdc/core": "^4.25.
|
|
31
|
-
"chroma": "
|
|
32
|
-
"react-
|
|
30
|
+
"@cdc/core": "^4.25.10",
|
|
31
|
+
"chroma-js": "3.1.2",
|
|
32
|
+
"html-react-parser": "5.2.3",
|
|
33
|
+
"lodash": "^4.17.21",
|
|
34
|
+
"react-accessible-accordion": "^5.0.1",
|
|
35
|
+
"resize-observer-polyfill": "^1.5.1"
|
|
33
36
|
},
|
|
34
37
|
"peerDependencies": {
|
|
35
38
|
"react": "^18.2.0",
|
|
36
39
|
"react-dom": "^18.2.0"
|
|
37
40
|
},
|
|
38
|
-
"
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@rollup/plugin-dsv": "^3.0.2",
|
|
43
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
44
|
+
"vite": "^4.4.11",
|
|
45
|
+
"vite-plugin-css-injected-by-js": "^2.4.0",
|
|
46
|
+
"vite-plugin-svgr": "^2.4.0"
|
|
47
|
+
},
|
|
48
|
+
"gitHead": "c2db758e74ab9b9ca1667a6f9cb41dd0dccf985d"
|
|
39
49
|
}
|
package/src/CdcDataBite.tsx
CHANGED
|
@@ -17,6 +17,9 @@ import Layout from '@cdc/core/components/Layout'
|
|
|
17
17
|
import ResizeObserver from 'resize-observer-polyfill'
|
|
18
18
|
import parse from 'html-react-parser'
|
|
19
19
|
|
|
20
|
+
// markup processing
|
|
21
|
+
import { processMarkupVariables } from '@cdc/core/helpers/markupProcessor'
|
|
22
|
+
|
|
20
23
|
// helpers
|
|
21
24
|
import getViewport from '@cdc/core/helpers/getViewport'
|
|
22
25
|
import { DataTransform } from '@cdc/core/helpers/DataTransform'
|
|
@@ -45,7 +48,6 @@ import {
|
|
|
45
48
|
|
|
46
49
|
// styles
|
|
47
50
|
import './scss/main.scss'
|
|
48
|
-
import { publishAnalyticsEvent } from '@cdc/core/helpers/metrics/helpers'
|
|
49
51
|
|
|
50
52
|
type CdcDataBiteProps = {
|
|
51
53
|
config: Config
|
|
@@ -90,7 +92,9 @@ const CdcDataBite = (props: CdcDataBiteProps) => {
|
|
|
90
92
|
dataFormat,
|
|
91
93
|
biteStyle,
|
|
92
94
|
filters,
|
|
93
|
-
subtext
|
|
95
|
+
subtext,
|
|
96
|
+
markupVariables,
|
|
97
|
+
enableMarkupVariables
|
|
94
98
|
} = config
|
|
95
99
|
|
|
96
100
|
const { innerContainerClasses, contentClasses } = useDataVizClasses(config)
|
|
@@ -124,7 +128,25 @@ const CdcDataBite = (props: CdcDataBiteProps) => {
|
|
|
124
128
|
|
|
125
129
|
//@ts-ignore
|
|
126
130
|
const loadConfig = async () => {
|
|
127
|
-
let response = configObj
|
|
131
|
+
let response = configObj
|
|
132
|
+
|
|
133
|
+
if (!response && configUrl) {
|
|
134
|
+
try {
|
|
135
|
+
const fetchResponse = await fetch(configUrl)
|
|
136
|
+
if (fetchResponse.ok) {
|
|
137
|
+
const text = await fetchResponse.text()
|
|
138
|
+
response = text ? JSON.parse(text) : {}
|
|
139
|
+
} else {
|
|
140
|
+
console.warn(`Failed to fetch config from ${configUrl}: ${fetchResponse.status}`)
|
|
141
|
+
response = {}
|
|
142
|
+
}
|
|
143
|
+
} catch (error) {
|
|
144
|
+
console.warn(`Error loading config from ${configUrl}:`, error)
|
|
145
|
+
response = {}
|
|
146
|
+
}
|
|
147
|
+
} else if (!response) {
|
|
148
|
+
response = {}
|
|
149
|
+
}
|
|
128
150
|
|
|
129
151
|
// If data is included through a URL, fetch that and store
|
|
130
152
|
let responseData = response.data ?? []
|
|
@@ -148,10 +170,25 @@ const CdcDataBite = (props: CdcDataBiteProps) => {
|
|
|
148
170
|
const processedConfig = { ...coveUpdateWorker(response) }
|
|
149
171
|
|
|
150
172
|
updateConfig({ ...defaults, ...processedConfig })
|
|
151
|
-
publishAnalyticsEvent('data-bite_loaded', 'load', interactionLabel, 'data-bite')
|
|
152
173
|
dispatch({ type: 'SET_LOADING', payload: false })
|
|
153
174
|
}
|
|
154
175
|
|
|
176
|
+
// Process markup variables in content
|
|
177
|
+
const processContentWithMarkup = (content: string) => {
|
|
178
|
+
if (!enableMarkupVariables || !markupVariables || markupVariables.length === 0) {
|
|
179
|
+
return content
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const result = processMarkupVariables(content, config.data, markupVariables, {
|
|
183
|
+
isEditor,
|
|
184
|
+
showNoDataMessage: false,
|
|
185
|
+
allowHideSection: false,
|
|
186
|
+
filters: config.filters || []
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
return result.processedContent
|
|
190
|
+
}
|
|
191
|
+
|
|
155
192
|
const calculateDataBite = (includePrefixSuffix = true) => {
|
|
156
193
|
//If either the column or function aren't set, do not calculate
|
|
157
194
|
if (!dataColumn || !dataFunction) {
|
|
@@ -566,7 +603,7 @@ const CdcDataBite = (props: CdcDataBiteProps) => {
|
|
|
566
603
|
<Title
|
|
567
604
|
showTitle={config.visual?.showTitle}
|
|
568
605
|
config={config}
|
|
569
|
-
title={title}
|
|
606
|
+
title={processContentWithMarkup(title)}
|
|
570
607
|
isDashboard={isDashboard}
|
|
571
608
|
classes={['bite-header', `${config.theme}`]}
|
|
572
609
|
/>
|
|
@@ -600,14 +637,16 @@ const CdcDataBite = (props: CdcDataBiteProps) => {
|
|
|
600
637
|
{calculateDataBite()}
|
|
601
638
|
</span>
|
|
602
639
|
)}
|
|
603
|
-
{parse(biteBody)}
|
|
640
|
+
{parse(processContentWithMarkup(biteBody))}
|
|
604
641
|
</p>
|
|
605
642
|
{showBite && 'end' === biteStyle && (
|
|
606
643
|
<span className='bite-value data-bite-body' style={{ fontSize: biteFontSize + 'px' }}>
|
|
607
644
|
{calculateDataBite()}
|
|
608
645
|
</span>
|
|
609
646
|
)}
|
|
610
|
-
{subtext && !config.general.isCompactStyle &&
|
|
647
|
+
{subtext && !config.general.isCompactStyle && (
|
|
648
|
+
<p className='bite-subtext'>{parse(processContentWithMarkup(subtext))}</p>
|
|
649
|
+
)}
|
|
611
650
|
</div>
|
|
612
651
|
</Fragment>
|
|
613
652
|
</div>
|
|
@@ -630,7 +669,9 @@ const CdcDataBite = (props: CdcDataBiteProps) => {
|
|
|
630
669
|
}
|
|
631
670
|
|
|
632
671
|
return (
|
|
633
|
-
<Context.Provider
|
|
672
|
+
<Context.Provider
|
|
673
|
+
value={{ config, updateConfig, loading, data: config.data, setParentConfig, isDashboard, isEditor }}
|
|
674
|
+
>
|
|
634
675
|
{biteStyle !== 'gradient' && (
|
|
635
676
|
<Layout.VisualizationWrapper
|
|
636
677
|
ref={outerContainerRef}
|