@cdc/markup-include 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.
- package/dist/cdcmarkupinclude.js +9155 -13884
- package/index.html +7 -8
- package/package.json +5 -5
- package/src/CdcMarkupInclude.tsx +90 -7
- package/src/_stories/MarkupInclude.Editor.stories.tsx +10 -4
- package/src/components/EditorPanel/EditorPanel.styles.css +6 -0
- package/src/components/EditorPanel/EditorPanel.tsx +158 -0
- package/src/components/EditorPanel/index.tsx +3 -0
- package/src/data/initial-state.js +2 -1
- package/src/scss/main.scss +11 -12
- package/src/store/markupInclude.reducer.ts +1 -1
- package/src/test/CdcMarkupInclude.test.jsx +1 -1
- package/LICENSE +0 -201
- package/src/components/Conditions.tsx +0 -118
- package/src/components/EditorPanel.tsx +0 -235
- package/src/components/Variables.tsx +0 -218
- package/src/components/editorPanel.style.css +0 -17
- package/src/types/Config.ts +0 -33
- /package/src/{index.jsx → index.tsx} +0 -0
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
import { useMemo, useState } from 'react'
|
|
2
|
-
import Conditions from './Conditions'
|
|
3
|
-
import { Variable } from '../types/Variable'
|
|
4
|
-
import { Condition } from '../types/Condition'
|
|
5
|
-
import _ from 'lodash'
|
|
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'
|
|
9
|
-
|
|
10
|
-
type OpenControls = [boolean[], Function] // useState type
|
|
11
|
-
|
|
12
|
-
type VariableSectionProps = {
|
|
13
|
-
controls: OpenControls
|
|
14
|
-
data: Object[]
|
|
15
|
-
deleteVariable: Function
|
|
16
|
-
updateVariableArray: Function
|
|
17
|
-
variableConfig: Variable
|
|
18
|
-
variableIndex: number
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const VariableSection: React.FC<VariableSectionProps> = ({
|
|
22
|
-
controls,
|
|
23
|
-
data,
|
|
24
|
-
deleteVariable,
|
|
25
|
-
updateVariableArray,
|
|
26
|
-
variableConfig,
|
|
27
|
-
variableIndex
|
|
28
|
-
}) => {
|
|
29
|
-
const [openVariableControls, setOpenVariableControls] = controls
|
|
30
|
-
const show = openVariableControls[variableIndex]
|
|
31
|
-
const setShow = (key, value) => {
|
|
32
|
-
setOpenVariableControls({ openVariableControls, [key]: value })
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const openConditionControls = useState([])
|
|
36
|
-
|
|
37
|
-
const columnNames = Object.keys(data?.[0] || {})
|
|
38
|
-
const [selectedColumn, setNewVariableColumnName] = useState(variableConfig.columnName)
|
|
39
|
-
const [conditionsList, setConditionsList] = useState(variableConfig.conditions)
|
|
40
|
-
const [variableName, setVariableName] = useState(variableConfig.name)
|
|
41
|
-
const [addCommas, setAddCommas] = useState(variableConfig.addCommas)
|
|
42
|
-
|
|
43
|
-
const conditionLookup: Record<string, string[] | number[]> = useMemo(() => {
|
|
44
|
-
return columnNames.reduce((acc, column) => {
|
|
45
|
-
acc[column] = _.uniq(data.map(row => row[column]))
|
|
46
|
-
return acc
|
|
47
|
-
}, {})
|
|
48
|
-
}, [columnNames])
|
|
49
|
-
|
|
50
|
-
const handleUpdateAddCommas = () => {
|
|
51
|
-
setAddCommas(!addCommas)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const handleVariableColumnChange = (columnName: string) => {
|
|
55
|
-
setNewVariableColumnName(columnName)
|
|
56
|
-
setConditionsList([])
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const updateConditionsList = (conditionSettings: Condition, conditionIndex: number) => {
|
|
60
|
-
const { columnName, isOrIsNotEqualTo, value } = conditionSettings
|
|
61
|
-
const newConditionsList = _.cloneDeep(conditionsList)
|
|
62
|
-
newConditionsList[conditionIndex] = {
|
|
63
|
-
columnName: columnName,
|
|
64
|
-
isOrIsNotEqualTo: isOrIsNotEqualTo,
|
|
65
|
-
value: value
|
|
66
|
-
}
|
|
67
|
-
setConditionsList(newConditionsList)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const removeCondition = (conditionIndex: number) => {
|
|
71
|
-
const updatedConditionsList = _.cloneDeep(conditionsList)
|
|
72
|
-
updatedConditionsList.splice(conditionIndex, 1)
|
|
73
|
-
setConditionsList(updatedConditionsList)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const handleAddConditionClick = () => {
|
|
77
|
-
setConditionsList([
|
|
78
|
-
...conditionsList,
|
|
79
|
-
{
|
|
80
|
-
columnName: '',
|
|
81
|
-
isOrIsNotEqualTo: 'is',
|
|
82
|
-
value: ''
|
|
83
|
-
}
|
|
84
|
-
])
|
|
85
|
-
|
|
86
|
-
const [conditionControls, setConditionControls] = openConditionControls
|
|
87
|
-
|
|
88
|
-
const newConditionsControls = [...conditionControls]
|
|
89
|
-
newConditionsControls[conditionsList.length + 1] = true
|
|
90
|
-
setConditionControls(newConditionsControls)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const handleVariableDoneClick = () => {
|
|
94
|
-
const filteredConditionsList = conditionsList.filter(
|
|
95
|
-
condition => condition.columnName !== '' && condition.value !== ''
|
|
96
|
-
)
|
|
97
|
-
const newVariable = {
|
|
98
|
-
columnName: selectedColumn,
|
|
99
|
-
conditions: filteredConditionsList,
|
|
100
|
-
name: variableName,
|
|
101
|
-
tag: `{{${variableName}}}`,
|
|
102
|
-
addCommas
|
|
103
|
-
}
|
|
104
|
-
updateVariableArray(newVariable, variableIndex)
|
|
105
|
-
setShow(variableIndex, false)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const columnSelectDisabled = variableName === ''
|
|
109
|
-
const addConditionDisabled = columnSelectDisabled || selectedColumn === ''
|
|
110
|
-
|
|
111
|
-
return (
|
|
112
|
-
<>
|
|
113
|
-
{!show ? (
|
|
114
|
-
<>
|
|
115
|
-
<div className='mb-2'>
|
|
116
|
-
<button onClick={() => setShow(variableIndex, true)}>
|
|
117
|
-
<Icon display='caretDown' />
|
|
118
|
-
</button>
|
|
119
|
-
<span> {variableName ? `${variableName}` : 'New Variable'}</span>
|
|
120
|
-
</div>
|
|
121
|
-
</>
|
|
122
|
-
) : (
|
|
123
|
-
<fieldset className='edit-block mb-1' key={variableIndex}>
|
|
124
|
-
<div className='d-flex justify-content-between'>
|
|
125
|
-
<button onClick={handleVariableDoneClick} disabled={addConditionDisabled}>
|
|
126
|
-
<Icon display='caretUp' />
|
|
127
|
-
</button>
|
|
128
|
-
<button
|
|
129
|
-
className='btn btn-danger btn-sm mt-0 ms-2'
|
|
130
|
-
onClick={event => {
|
|
131
|
-
event.preventDefault()
|
|
132
|
-
deleteVariable(variableIndex)
|
|
133
|
-
}}
|
|
134
|
-
>
|
|
135
|
-
Delete
|
|
136
|
-
</button>
|
|
137
|
-
</div>
|
|
138
|
-
<label className='d-block'>
|
|
139
|
-
<span className='edit-label column-heading'>Variable Name:</span>
|
|
140
|
-
<input
|
|
141
|
-
className={`variable-${variableIndex} ms-1`}
|
|
142
|
-
type='text'
|
|
143
|
-
value={variableName}
|
|
144
|
-
onChange={e => setVariableName(e.target.value)}
|
|
145
|
-
/>
|
|
146
|
-
</label>
|
|
147
|
-
<div className='pt-2'>
|
|
148
|
-
<label className='d-block'>
|
|
149
|
-
<span className='edit-label column-heading'>Column:</span>
|
|
150
|
-
<select
|
|
151
|
-
className={`variable-${variableIndex} ms-1`}
|
|
152
|
-
onChange={e => handleVariableColumnChange(e.target.value)}
|
|
153
|
-
value={selectedColumn}
|
|
154
|
-
disabled={columnSelectDisabled}
|
|
155
|
-
>
|
|
156
|
-
<option value=''>Select</option>
|
|
157
|
-
{columnNames.map(columnName => (
|
|
158
|
-
<option key={columnName} value={columnName}>
|
|
159
|
-
{columnName}
|
|
160
|
-
</option>
|
|
161
|
-
))}
|
|
162
|
-
</select>
|
|
163
|
-
</label>
|
|
164
|
-
</div>
|
|
165
|
-
<div className='pt-2'>
|
|
166
|
-
<CheckBox
|
|
167
|
-
value={addCommas}
|
|
168
|
-
label='Add Commas to Number'
|
|
169
|
-
updateField={handleUpdateAddCommas}
|
|
170
|
-
tooltip={
|
|
171
|
-
<Tooltip style={{ textTransform: 'none' }}>
|
|
172
|
-
<Tooltip.Target>
|
|
173
|
-
<Icon
|
|
174
|
-
display='question'
|
|
175
|
-
style={{ marginLeft: '0.5rem', display: 'inline-block', whiteSpace: 'nowrap' }}
|
|
176
|
-
/>
|
|
177
|
-
</Tooltip.Target>
|
|
178
|
-
<Tooltip.Content>
|
|
179
|
-
<p>{`Selecting this option will add commas to the numeric value.`}</p>
|
|
180
|
-
</Tooltip.Content>
|
|
181
|
-
</Tooltip>
|
|
182
|
-
}
|
|
183
|
-
/>
|
|
184
|
-
</div>
|
|
185
|
-
<label className='d-block py-2'>
|
|
186
|
-
<span className='edit-label column-heading'>Conditions:</span>
|
|
187
|
-
{conditionsList.map((condition, index) => {
|
|
188
|
-
return (
|
|
189
|
-
<div className='condition-section mt-2'>
|
|
190
|
-
<Conditions
|
|
191
|
-
key={variableName + '-condition-' + index}
|
|
192
|
-
conditionControls={openConditionControls}
|
|
193
|
-
conditionLookup={conditionLookup}
|
|
194
|
-
conditionSettings={condition}
|
|
195
|
-
conditionIndex={index}
|
|
196
|
-
removeCondition={removeCondition}
|
|
197
|
-
selectedColumn={selectedColumn}
|
|
198
|
-
updateConditionsList={updateConditionsList}
|
|
199
|
-
/>
|
|
200
|
-
</div>
|
|
201
|
-
)
|
|
202
|
-
})}
|
|
203
|
-
</label>
|
|
204
|
-
<div className='mt-1'>
|
|
205
|
-
<button onClick={handleAddConditionClick} disabled={addConditionDisabled}>
|
|
206
|
-
Add Condition
|
|
207
|
-
</button>
|
|
208
|
-
<button className='ms-2' onClick={handleVariableDoneClick} disabled={addConditionDisabled}>
|
|
209
|
-
Done
|
|
210
|
-
</button>
|
|
211
|
-
</div>
|
|
212
|
-
</fieldset>
|
|
213
|
-
)}
|
|
214
|
-
</>
|
|
215
|
-
)
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
export default VariableSection
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
.cdc-open-viz-module.markup-include {
|
|
2
|
-
.editor-panel .condition-section :is(label) {
|
|
3
|
-
font-size: 1em;
|
|
4
|
-
}
|
|
5
|
-
:is(span).edit-label {
|
|
6
|
-
margin-bottom: 0.3em;
|
|
7
|
-
display: block;
|
|
8
|
-
}
|
|
9
|
-
.react-tooltip {
|
|
10
|
-
position: absolute;
|
|
11
|
-
width: 250px;
|
|
12
|
-
}
|
|
13
|
-
.need-data-source-prompt {
|
|
14
|
-
color: var(--gray);
|
|
15
|
-
font-size: 0.8rem;
|
|
16
|
-
}
|
|
17
|
-
}
|
package/src/types/Config.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Runtime } from '@cdc/core/types/Runtime'
|
|
2
|
-
import { Variable } from './Variable'
|
|
3
|
-
import { Version } from '@cdc/core/types/Version'
|
|
4
|
-
|
|
5
|
-
export type Config = {
|
|
6
|
-
contentEditor: {
|
|
7
|
-
// Changing the base config object creates an infinite loop, nesting it is a workaround
|
|
8
|
-
inlineHTML: string
|
|
9
|
-
showHeader: boolean
|
|
10
|
-
srcUrl: string
|
|
11
|
-
title: string
|
|
12
|
-
useInlineHTML: boolean
|
|
13
|
-
showNoDataMessage: boolean
|
|
14
|
-
noDataMessageText: string
|
|
15
|
-
}
|
|
16
|
-
data?: Object[]
|
|
17
|
-
legend: {}
|
|
18
|
-
newViz?: boolean
|
|
19
|
-
runtime?: Runtime
|
|
20
|
-
theme: any
|
|
21
|
-
type: string
|
|
22
|
-
showEditorPanel?: boolean
|
|
23
|
-
visual: {
|
|
24
|
-
border: boolean
|
|
25
|
-
accent: boolean
|
|
26
|
-
background: boolean
|
|
27
|
-
hideBackgroundColor: boolean
|
|
28
|
-
borderColorTheme: boolean
|
|
29
|
-
}
|
|
30
|
-
version: Version
|
|
31
|
-
markupVariables: Variable[]
|
|
32
|
-
enableMarkupVariables: boolean
|
|
33
|
-
}
|
|
File without changes
|