@cdc/markup-include 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/cdcmarkupinclude.js +6059 -5587
- package/package.json +6 -5
- package/src/CdcMarkupInclude.tsx +36 -13
- package/src/components/EditorPanel.tsx +1 -1
- package/src/components/Variables.tsx +26 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cdc/markup-include",
|
|
3
|
-
"version": "4.24.
|
|
3
|
+
"version": "4.24.9-1",
|
|
4
4
|
"description": "React component for displaying HTML content from an outside link",
|
|
5
5
|
"moduleName": "CdcMarkupInclude",
|
|
6
6
|
"main": "dist/cdcmarkupinclude",
|
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
"preview": "vite preview",
|
|
12
12
|
"graph": "nx graph",
|
|
13
13
|
"prepublishOnly": "lerna run --scope @cdc/markup-include build",
|
|
14
|
-
"test": "vitest
|
|
15
|
-
"test
|
|
14
|
+
"test": "vitest run --reporter verbose",
|
|
15
|
+
"test-watch": "vitest watch --reporter verbose",
|
|
16
|
+
"test-watch:ui": "vitest --ui"
|
|
16
17
|
},
|
|
17
18
|
"repository": {
|
|
18
19
|
"type": "git",
|
|
@@ -26,7 +27,7 @@
|
|
|
26
27
|
"license": "Apache-2.0",
|
|
27
28
|
"homepage": "https://github.com/CDCgov/cdc-open-viz#readme",
|
|
28
29
|
"dependencies": {
|
|
29
|
-
"@cdc/core": "^4.24.
|
|
30
|
+
"@cdc/core": "^4.24.9-1",
|
|
30
31
|
"axios": "^1.6.0",
|
|
31
32
|
"chroma": "0.0.1",
|
|
32
33
|
"chroma-js": "^2.1.0",
|
|
@@ -38,5 +39,5 @@
|
|
|
38
39
|
"react": "^18.2.0",
|
|
39
40
|
"react-dom": "^18.2.0"
|
|
40
41
|
},
|
|
41
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "4a77c2fa79c8fa6074da3b6dfee3d8e32f0b2586"
|
|
42
43
|
}
|
package/src/CdcMarkupInclude.tsx
CHANGED
|
@@ -31,8 +31,21 @@ type CdcMarkupIncludeProps = {
|
|
|
31
31
|
|
|
32
32
|
import Title from '@cdc/core/components/ui/Title'
|
|
33
33
|
|
|
34
|
-
const CdcMarkupInclude: React.FC<CdcMarkupIncludeProps> = ({
|
|
35
|
-
|
|
34
|
+
const CdcMarkupInclude: React.FC<CdcMarkupIncludeProps> = ({
|
|
35
|
+
configUrl,
|
|
36
|
+
config: configObj,
|
|
37
|
+
isDashboard = true,
|
|
38
|
+
isEditor = false,
|
|
39
|
+
setConfig: setParentConfig
|
|
40
|
+
}) => {
|
|
41
|
+
const initialState = {
|
|
42
|
+
config: configObj,
|
|
43
|
+
loading: true,
|
|
44
|
+
urlMarkup: '',
|
|
45
|
+
markupError: null,
|
|
46
|
+
errorMessage: null,
|
|
47
|
+
coveLoadedHasRan: false
|
|
48
|
+
}
|
|
36
49
|
|
|
37
50
|
const [state, dispatch] = useReducer(markupIncludeReducer, initialState)
|
|
38
51
|
|
|
@@ -72,7 +85,7 @@ const CdcMarkupInclude: React.FC<CdcMarkupIncludeProps> = ({ configUrl, config:
|
|
|
72
85
|
}
|
|
73
86
|
|
|
74
87
|
response.data = responseData
|
|
75
|
-
const processedConfig = { ...
|
|
88
|
+
const processedConfig = { ...coveUpdateWorker(response) }
|
|
76
89
|
|
|
77
90
|
updateConfig({ ...configObj, ...processedConfig })
|
|
78
91
|
dispatch({ type: 'SET_LOADING', payload: false })
|
|
@@ -92,7 +105,8 @@ const CdcMarkupInclude: React.FC<CdcMarkupIncludeProps> = ({ configUrl, config:
|
|
|
92
105
|
let errorList = {
|
|
93
106
|
200: 'This is likely due to a CORS restriction policy from the remote origin address.',
|
|
94
107
|
404: 'The requested source URL cannot be found. Please verify the link address provided.',
|
|
95
|
-
proto:
|
|
108
|
+
proto:
|
|
109
|
+
'Provided source URL must include https:// or http:// before the address (depending on the source content type).'
|
|
96
110
|
}
|
|
97
111
|
|
|
98
112
|
message += errorList[errorCode]
|
|
@@ -138,7 +152,10 @@ const CdcMarkupInclude: React.FC<CdcMarkupIncludeProps> = ({ configUrl, config:
|
|
|
138
152
|
const filterOutConditions = (workingData, conditionList) => {
|
|
139
153
|
const { columnName, isOrIsNotEqualTo, value } = conditionList[0]
|
|
140
154
|
|
|
141
|
-
const newWorkingData =
|
|
155
|
+
const newWorkingData =
|
|
156
|
+
isOrIsNotEqualTo === 'is'
|
|
157
|
+
? workingData.filter(dataObject => dataObject[columnName] === value)
|
|
158
|
+
: workingData.filter(dataObject => dataObject[columnName] !== value)
|
|
142
159
|
|
|
143
160
|
conditionList.shift()
|
|
144
161
|
return conditionList.length === 0 ? newWorkingData : filterOutConditions(newWorkingData, conditionList)
|
|
@@ -150,7 +167,10 @@ const CdcMarkupInclude: React.FC<CdcMarkupIncludeProps> = ({ configUrl, config:
|
|
|
150
167
|
const convertedInlineMarkup = inlineMarkup.replace(variableRegexPattern, variableTag => {
|
|
151
168
|
const workingVariable = markupVariables.filter(variable => variable.tag === variableTag)[0]
|
|
152
169
|
if (workingVariable === undefined) return [variableTag]
|
|
153
|
-
const workingData =
|
|
170
|
+
const workingData =
|
|
171
|
+
workingVariable && workingVariable.conditions.length === 0
|
|
172
|
+
? data
|
|
173
|
+
: filterOutConditions(data, [...workingVariable.conditions])
|
|
154
174
|
|
|
155
175
|
const variableValues: string[] = _.uniq(workingData?.map(dataObject => dataObject[workingVariable.columnName]))
|
|
156
176
|
const variableDisplay = []
|
|
@@ -166,9 +186,17 @@ const CdcMarkupInclude: React.FC<CdcMarkupIncludeProps> = ({ configUrl, config:
|
|
|
166
186
|
}
|
|
167
187
|
variableDisplay.push(variableValues.join(', '))
|
|
168
188
|
|
|
169
|
-
|
|
189
|
+
let finalDisplay = variableDisplay[0]
|
|
190
|
+
|
|
191
|
+
if (workingVariable.addCommas && !isNaN(parseFloat(finalDisplay))) {
|
|
192
|
+
finalDisplay = parseFloat(finalDisplay)
|
|
193
|
+
finalDisplay = finalDisplay.toLocaleString('en-US', { useGrouping: true })
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const displayInfoMessage =
|
|
197
|
+
'<span class="font-weight-bold display-Info-message">One or more of the following values will appear in the place of this variable placeholder:</span>'
|
|
170
198
|
|
|
171
|
-
const newReplacementForVariable = `<span class="cove-tooltip-variable">${variableTag}<span class="cove-tooltip-value">${displayInfoMessage}<br/>${
|
|
199
|
+
const newReplacementForVariable = `<span class="cove-tooltip-variable">${variableTag}<span class="cove-tooltip-value">${displayInfoMessage}<br/>${finalDisplay}</span></span><span class="cove-markup-include-variable-value">${finalDisplay}</span>`
|
|
172
200
|
|
|
173
201
|
return newReplacementForVariable
|
|
174
202
|
})
|
|
@@ -203,11 +231,6 @@ const CdcMarkupInclude: React.FC<CdcMarkupIncludeProps> = ({ configUrl, config:
|
|
|
203
231
|
}
|
|
204
232
|
}, [config, container])
|
|
205
233
|
|
|
206
|
-
//Reload config if config object provided/updated
|
|
207
|
-
useEffect(() => {
|
|
208
|
-
loadConfig().catch(err => console.log(err))
|
|
209
|
-
}, [configObj?.data])
|
|
210
|
-
|
|
211
234
|
//Reload any functions when config is updated
|
|
212
235
|
useEffect(() => {
|
|
213
236
|
loadConfigMarkupData().catch(err => console.log(err))
|
|
@@ -4,6 +4,8 @@ import { Variable } from '../types/Variable'
|
|
|
4
4
|
import { Condition } from '../types/Condition'
|
|
5
5
|
import _ from 'lodash'
|
|
6
6
|
import Icon from '@cdc/core/components/ui/Icon'
|
|
7
|
+
import { CheckBox } from '@cdc/core/components/EditorPanel/Inputs'
|
|
8
|
+
import Tooltip from '@cdc/core/components/ui/Tooltip'
|
|
7
9
|
|
|
8
10
|
type OpenControls = [boolean[], Function] // useState type
|
|
9
11
|
|
|
@@ -29,6 +31,7 @@ const VariableSection: React.FC<VariableSectionProps> = ({ controls, data, delet
|
|
|
29
31
|
const [selectedColumn, setNewVariableColumnName] = useState(variableConfig.columnName)
|
|
30
32
|
const [conditionsList, setConditionsList] = useState(variableConfig.conditions)
|
|
31
33
|
const [variableName, setVariableName] = useState(variableConfig.name)
|
|
34
|
+
const [addCommas, setAddCommas] = useState(variableConfig.addCommas)
|
|
32
35
|
|
|
33
36
|
const conditionLookup: Record<string, string[] | number[]> = useMemo(() => {
|
|
34
37
|
return columnNames.reduce((acc, column) => {
|
|
@@ -37,6 +40,10 @@ const VariableSection: React.FC<VariableSectionProps> = ({ controls, data, delet
|
|
|
37
40
|
}, {})
|
|
38
41
|
}, [columnNames])
|
|
39
42
|
|
|
43
|
+
const handleUpdateAddCommas = () => {
|
|
44
|
+
setAddCommas(!addCommas)
|
|
45
|
+
}
|
|
46
|
+
|
|
40
47
|
const handleVariableColumnChange = (columnName: string) => {
|
|
41
48
|
setNewVariableColumnName(columnName)
|
|
42
49
|
setConditionsList([])
|
|
@@ -82,7 +89,8 @@ const VariableSection: React.FC<VariableSectionProps> = ({ controls, data, delet
|
|
|
82
89
|
columnName: selectedColumn,
|
|
83
90
|
conditions: filteredConditionsList,
|
|
84
91
|
name: variableName,
|
|
85
|
-
tag: `{{${variableName}}}
|
|
92
|
+
tag: `{{${variableName}}}`,
|
|
93
|
+
addCommas
|
|
86
94
|
}
|
|
87
95
|
updateVariableArray(newVariable, variableIndex)
|
|
88
96
|
setShow(variableIndex, false)
|
|
@@ -135,6 +143,23 @@ const VariableSection: React.FC<VariableSectionProps> = ({ controls, data, delet
|
|
|
135
143
|
</select>
|
|
136
144
|
</label>
|
|
137
145
|
</div>
|
|
146
|
+
<div className='pt-2'>
|
|
147
|
+
<CheckBox
|
|
148
|
+
value={addCommas}
|
|
149
|
+
label='Add Commas to Number'
|
|
150
|
+
updateField={handleUpdateAddCommas}
|
|
151
|
+
tooltip={
|
|
152
|
+
<Tooltip style={{ textTransform: 'none' }}>
|
|
153
|
+
<Tooltip.Target>
|
|
154
|
+
<Icon display='question' style={{ marginLeft: '0.5rem', display: 'inline-block', whiteSpace: 'nowrap' }} />
|
|
155
|
+
</Tooltip.Target>
|
|
156
|
+
<Tooltip.Content>
|
|
157
|
+
<p>{`Selecting this option will add commas to the numeric value.`}</p>
|
|
158
|
+
</Tooltip.Content>
|
|
159
|
+
</Tooltip>
|
|
160
|
+
}
|
|
161
|
+
/>
|
|
162
|
+
</div>
|
|
138
163
|
<label className='d-block py-2'>
|
|
139
164
|
<span className='edit-label column-heading'>Conditions:</span>
|
|
140
165
|
{conditionsList.map((condition, index) => {
|