@cdc/markup-include 4.25.8 → 4.25.11

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.
@@ -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 +0,0 @@
1
- @import '@cdc/core/styles/base';
@@ -1,32 +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
- markupVariables: Variable[]
10
- showHeader: boolean
11
- srcUrl: string
12
- title: string
13
- useInlineHTML: boolean
14
- showNoDataMessage: boolean
15
- noDataMessageText: string
16
- }
17
- data?: Object[]
18
- legend: {}
19
- newViz?: boolean
20
- runtime?: Runtime
21
- theme: any
22
- type: string
23
- showEditorPanel?: boolean
24
- visual: {
25
- border: boolean
26
- accent: boolean
27
- background: boolean
28
- hideBackgroundColor: boolean
29
- borderColorTheme: boolean
30
- }
31
- version: Version
32
- }