@cdc/data-bite 4.25.7 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdc/data-bite",
3
- "version": "4.25.7",
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.7",
31
- "chroma": "0.0.1",
32
- "react-accessible-accordion": "^3.3.4"
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
- "gitHead": "9062881d50c824ee6cdd71868bafd016a5e5694d"
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
  }
@@ -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'
@@ -53,6 +56,7 @@ type CdcDataBiteProps = {
53
56
  isEditor: boolean
54
57
  setConfig: () => {}
55
58
  link: any
59
+ interactionLabel: string
56
60
  }
57
61
 
58
62
  const CdcDataBite = (props: CdcDataBiteProps) => {
@@ -62,7 +66,8 @@ const CdcDataBite = (props: CdcDataBiteProps) => {
62
66
  isDashboard = false,
63
67
  isEditor = false,
64
68
  setConfig: setParentConfig,
65
- link
69
+ link,
70
+ interactionLabel = ''
66
71
  } = props
67
72
 
68
73
  const initialState = {
@@ -87,7 +92,9 @@ const CdcDataBite = (props: CdcDataBiteProps) => {
87
92
  dataFormat,
88
93
  biteStyle,
89
94
  filters,
90
- subtext
95
+ subtext,
96
+ markupVariables,
97
+ enableMarkupVariables
91
98
  } = config
92
99
 
93
100
  const { innerContainerClasses, contentClasses } = useDataVizClasses(config)
@@ -121,7 +128,25 @@ const CdcDataBite = (props: CdcDataBiteProps) => {
121
128
 
122
129
  //@ts-ignore
123
130
  const loadConfig = async () => {
124
- let response = configObj || (await (await fetch(configUrl)).json())
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
+ }
125
150
 
126
151
  // If data is included through a URL, fetch that and store
127
152
  let responseData = response.data ?? []
@@ -148,6 +173,22 @@ const CdcDataBite = (props: CdcDataBiteProps) => {
148
173
  dispatch({ type: 'SET_LOADING', payload: false })
149
174
  }
150
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
+
151
192
  const calculateDataBite = (includePrefixSuffix = true) => {
152
193
  //If either the column or function aren't set, do not calculate
153
194
  if (!dataColumn || !dataFunction) {
@@ -562,7 +603,7 @@ const CdcDataBite = (props: CdcDataBiteProps) => {
562
603
  <Title
563
604
  showTitle={config.visual?.showTitle}
564
605
  config={config}
565
- title={title}
606
+ title={processContentWithMarkup(title)}
566
607
  isDashboard={isDashboard}
567
608
  classes={['bite-header', `${config.theme}`]}
568
609
  />
@@ -596,14 +637,16 @@ const CdcDataBite = (props: CdcDataBiteProps) => {
596
637
  {calculateDataBite()}
597
638
  </span>
598
639
  )}
599
- {parse(biteBody)}
640
+ {parse(processContentWithMarkup(biteBody))}
600
641
  </p>
601
642
  {showBite && 'end' === biteStyle && (
602
643
  <span className='bite-value data-bite-body' style={{ fontSize: biteFontSize + 'px' }}>
603
644
  {calculateDataBite()}
604
645
  </span>
605
646
  )}
606
- {subtext && !config.general.isCompactStyle && <p className='bite-subtext'>{parse(subtext)}</p>}
647
+ {subtext && !config.general.isCompactStyle && (
648
+ <p className='bite-subtext'>{parse(processContentWithMarkup(subtext))}</p>
649
+ )}
607
650
  </div>
608
651
  </Fragment>
609
652
  </div>
@@ -626,7 +669,9 @@ const CdcDataBite = (props: CdcDataBiteProps) => {
626
669
  }
627
670
 
628
671
  return (
629
- <Context.Provider value={{ config, updateConfig, loading, data: config.data, setParentConfig, isDashboard }}>
672
+ <Context.Provider
673
+ value={{ config, updateConfig, loading, data: config.data, setParentConfig, isDashboard, isEditor }}
674
+ >
630
675
  {biteStyle !== 'gradient' && (
631
676
  <Layout.VisualizationWrapper
632
677
  ref={outerContainerRef}