@cdc/markup-include 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.
@@ -1,10 +1,8 @@
1
- import React, { useState, useEffect, memo, useContext, useRef, useMemo, useReducer } from 'react'
1
+ import React, { useState, useEffect, useContext, useRef } from 'react'
2
2
 
3
- // Third Party
4
- import _ from 'lodash'
3
+ import { cloneConfig } from '@cdc/core/helpers/cloneConfig'
5
4
 
6
5
  // Context
7
- import { Variable } from '../types/Variable'
8
6
  import ConfigContext from '../ConfigContext'
9
7
 
10
8
  // Helpers
@@ -13,19 +11,16 @@ import { updateFieldFactory } from '@cdc/core/helpers/updateFieldFactory'
13
11
  // Components
14
12
  import InputCheckbox from '@cdc/core/components/inputs/InputCheckbox'
15
13
  import ErrorBoundary from '@cdc/core/components/ErrorBoundary'
16
- import Icon from '@cdc/core/components/ui/Icon'
17
14
  import InputText from '@cdc/core/components/inputs/InputText'
18
15
  import Layout from '@cdc/core/components/Layout'
19
- import Tooltip from '@cdc/core/components/ui/Tooltip'
20
16
  import Accordion from '@cdc/core/components/ui/Accordion'
17
+ import MarkupVariablesEditor from '@cdc/core/components/EditorPanel/components/MarkupVariablesEditor'
18
+ import FootnotesEditor from '@cdc/core/components/EditorPanel/FootnotesEditor'
19
+ import { Datasets } from '@cdc/core/types/DataSet'
21
20
 
22
21
  // styles
23
22
  import '@cdc/core/styles/v2/components/editor.scss'
24
23
  import './editorPanel.style.css'
25
- import VariableSection from './Variables'
26
- import { CheckBox } from '@cdc/core/components/EditorPanel/Inputs'
27
- import FootnotesEditor from '@cdc/core/components/EditorPanel/FootnotesEditor'
28
- import { Datasets } from '@cdc/core/types/DataSet'
29
24
 
30
25
  const headerColors = [
31
26
  'theme-blue',
@@ -48,12 +43,11 @@ type MarkupIncludeEditorPanelProps = {
48
43
  const EditorPanel: React.FC<MarkupIncludeEditorPanelProps> = ({ datasets }) => {
49
44
  const { config, data, isDashboard, loading, setParentConfig, updateConfig } = useContext(ConfigContext)
50
45
  const { contentEditor, theme, visual } = config
51
- const { inlineHTML, markupVariables, srcUrl, title, useInlineHTML, allowHideSection } = contentEditor
46
+ const { inlineHTML, srcUrl, title, useInlineHTML } = contentEditor
52
47
  const [displayPanel, setDisplayPanel] = useState(true)
53
48
  const updateField = updateFieldFactory(config, updateConfig, true)
54
- const hasData = data?.[0] !== undefined ?? false
55
49
 
56
- const openVariableControls = useState<boolean[]>([])
50
+ const textAreaInEditorContainer = useRef(null)
57
51
 
58
52
  useEffect(() => {
59
53
  // Pass up to Editor if needed
@@ -79,52 +73,25 @@ const EditorPanel: React.FC<MarkupIncludeEditorPanelProps> = ({ datasets }) => {
79
73
  }
80
74
 
81
75
  const convertStateToConfig = () => {
82
- const strippedState = _.cloneDeep(config)
76
+ const strippedState = cloneConfig(config)
83
77
  delete strippedState.newViz
84
78
  delete strippedState.runtime
85
79
 
86
80
  return strippedState
87
81
  }
88
82
 
89
- const [variableArray, setVariableArray] = useState<Variable[]>([...markupVariables])
90
- const [isCreatingVariable, setIsCreatingVariable] = useState(false)
91
-
92
- const textAreaInEditorContainer = useRef(null)
93
- const [controls, setControls] = openVariableControls
94
-
95
- const handleCreateNewVariableButtonClick = () => {
96
- const newVariableArray = [..._.cloneDeep(variableArray)]
97
- const newVariable = {
98
- columnName: '',
99
- conditions: [],
100
- name: '',
101
- tag: ''
102
- }
103
-
104
- setControls({ ...controls, [variableArray.length + 1]: true })
105
-
106
- newVariableArray.push(newVariable)
107
- setVariableArray(newVariableArray)
108
- setIsCreatingVariable(!isCreatingVariable)
109
- }
110
-
111
- const updateVariableArray = (newVariable: Variable, variableIndex: number) => {
112
- const newVariableArray = _.cloneDeep(variableArray)
113
- newVariableArray[variableIndex] = newVariable
114
- setVariableArray(newVariableArray)
115
- updateField('contentEditor', null, 'markupVariables', newVariableArray)
116
- return
83
+ const handleMarkupVariablesChange = (variables: any[]) => {
84
+ updateConfig({
85
+ ...config,
86
+ markupVariables: variables
87
+ })
117
88
  }
118
89
 
119
- const deleteVariable = (variableIndex: number) => {
120
- const newVariableArray = _.cloneDeep(variableArray)
121
- newVariableArray.splice(variableIndex, 1)
122
- setVariableArray(newVariableArray)
123
- updateField('contentEditor', null, 'markupVariables', newVariableArray)
124
-
125
- const newControls = _.cloneDeep(controls)
126
- delete newControls[variableIndex]
127
- setControls(newControls)
90
+ const handleToggleEnable = (enabled: boolean) => {
91
+ updateConfig({
92
+ ...config,
93
+ enableMarkupVariables: enabled
94
+ })
128
95
  }
129
96
 
130
97
  const editorContent = (
@@ -164,77 +131,7 @@ const EditorPanel: React.FC<MarkupIncludeEditorPanelProps> = ({ datasets }) => {
164
131
  rows={10}
165
132
  updateField={updateField}
166
133
  />
167
-
168
- <hr className='accordion__divider' />
169
134
  </div>
170
- {/* Create New Variable*/}
171
-
172
- {/* Variable Options List */}
173
- <fieldset>
174
- <label>
175
- <span className='edit-label'>
176
- Variables
177
- <Tooltip style={{ textTransform: 'none' }}>
178
- <Tooltip.Target>
179
- <Icon display='question' style={{ marginLeft: '0.5rem' }} />
180
- </Tooltip.Target>
181
- <Tooltip.Content>{`To use created variables wrap the variable name in curly brackets, e.g. {{some_variable}}, and place the variable directly in your Inline HTML`}</Tooltip.Content>
182
- </Tooltip>
183
- </span>
184
- </label>
185
- {hasData === false && (
186
- <span className='need-data-source-prompt'>To use variables, add data source.</span>
187
- )}
188
- {variableArray && variableArray.length > 0 && (
189
- <div className='section-border'>
190
- {variableArray?.map((variableObject, index) => {
191
- return (
192
- <VariableSection
193
- key={`${variableObject.name}-${index}`}
194
- controls={openVariableControls}
195
- data={data}
196
- deleteVariable={deleteVariable}
197
- updateVariableArray={updateVariableArray}
198
- variableConfig={variableObject}
199
- variableIndex={index}
200
- />
201
- )
202
- })}
203
- </div>
204
- )}
205
- <div className='pt-2'>
206
- <CheckBox
207
- value={allowHideSection}
208
- section='contentEditor'
209
- fieldName='allowHideSection'
210
- label='Hide Section on Null'
211
- updateField={updateField}
212
- tooltip={
213
- <Tooltip style={{ textTransform: 'none' }}>
214
- <Tooltip.Target>
215
- <Icon
216
- display='question'
217
- style={{ marginLeft: '0.5rem', display: 'inline-block', whiteSpace: 'nowrap' }}
218
- />
219
- </Tooltip.Target>
220
- <Tooltip.Content>
221
- <p>{`Hide this entire Markup Include section if any variable is null or blank.`}</p>
222
- </Tooltip.Content>
223
- </Tooltip>
224
- }
225
- />
226
- </div>
227
-
228
- <div className='mb-1 d-flex'>
229
- <button
230
- className={'btn btn-primary'}
231
- onClick={handleCreateNewVariableButtonClick}
232
- disabled={!hasData}
233
- >
234
- Create New Variable
235
- </button>
236
- </div>
237
- </fieldset>
238
135
  </>
239
136
  ) : (
240
137
  <InputText
@@ -307,6 +204,15 @@ const EditorPanel: React.FC<MarkupIncludeEditorPanelProps> = ({ datasets }) => {
307
204
  <FootnotesEditor config={config} updateField={updateField} datasets={datasets} />
308
205
  </Accordion.Section>
309
206
  )}
207
+ <Accordion.Section title='Markup Variables'>
208
+ <MarkupVariablesEditor
209
+ markupVariables={config.markupVariables || []}
210
+ data={data || []}
211
+ onChange={handleMarkupVariablesChange}
212
+ enableMarkupVariables={config.enableMarkupVariables || false}
213
+ onToggleEnable={handleToggleEnable}
214
+ />
215
+ </Accordion.Section>
310
216
  </Accordion>
311
217
  )
312
218
 
@@ -1,11 +1,12 @@
1
1
  export default {
2
2
  contentEditor: {
3
3
  inlineHTML: '<h2>Inline HTML</h2>',
4
- markupVariables: [],
5
4
  showHeader: true,
6
5
  srcUrl: '#example',
7
6
  title: 'Markup Include',
8
- useInlineHTML: false
7
+ useInlineHTML: false,
8
+ showNoDataMessage: false,
9
+ noDataMessageText: 'No Data Available'
9
10
  },
10
11
  data: [],
11
12
  legend: {},
@@ -19,5 +20,7 @@ export default {
19
20
  background: false,
20
21
  hideBackgroundColor: false,
21
22
  borderColorTheme: false
22
- }
23
+ },
24
+ markupVariables: [],
25
+ enableMarkupVariables: false
23
26
  }
package/src/index.jsx CHANGED
@@ -4,7 +4,6 @@ import ReactDOM from 'react-dom/client'
4
4
  import { GlobalContextProvider } from '@cdc/core/components/GlobalContext'
5
5
 
6
6
  import '@cdc/core/styles/cove-main.scss'
7
- import './coreStyles_markupinclude.scss'
8
7
 
9
8
  import CdcMarkupInclude from './CdcMarkupInclude'
10
9
 
@@ -15,7 +14,11 @@ let domContainer = document.getElementsByClassName('react-container')[0]
15
14
  ReactDOM.createRoot(domContainer).render(
16
15
  <React.StrictMode>
17
16
  <GlobalContextProvider>
18
- <CdcMarkupInclude configUrl={domContainer.attributes['data-config'].value} isEditor={isEditor} />
17
+ <CdcMarkupInclude
18
+ configUrl={domContainer.attributes['data-config'].value}
19
+ interactionLabel={domContainer.attributes['data-config'].value}
20
+ isEditor={isEditor}
21
+ />
19
22
  </GlobalContextProvider>
20
23
  </React.StrictMode>
21
24
  )
@@ -1,6 +1,11 @@
1
- // Placeholder test until we add them in.
1
+ import path from 'path'
2
+ import { testStandaloneBuild } from '@cdc/core/helpers/tests/testStandaloneBuild.ts'
3
+ import { describe, it, expect } from 'vitest'
4
+
2
5
  describe('Markup Include', () => {
3
- it('has a test.', async () => {
4
- return true
6
+ it('Can be built in isolation', async () => {
7
+ const pkgDir = path.join(__dirname, '..')
8
+ const result = testStandaloneBuild(pkgDir)
9
+ expect(result).toBe(true)
5
10
  })
6
11
  })
@@ -1,5 +1,5 @@
1
1
  export type Condition = {
2
2
  columnName: string
3
- isOrIsNotEqualTo: string
3
+ isOrIsNotEqualTo: 'is' | 'is not'
4
4
  value: string
5
5
  }
@@ -6,11 +6,12 @@ export type Config = {
6
6
  contentEditor: {
7
7
  // Changing the base config object creates an infinite loop, nesting it is a workaround
8
8
  inlineHTML: string
9
- markupVariables: Variable[]
10
9
  showHeader: boolean
11
10
  srcUrl: string
12
11
  title: string
13
12
  useInlineHTML: boolean
13
+ showNoDataMessage: boolean
14
+ noDataMessageText: string
14
15
  }
15
16
  data?: Object[]
16
17
  legend: {}
@@ -27,4 +28,6 @@ export type Config = {
27
28
  borderColorTheme: boolean
28
29
  }
29
30
  version: Version
31
+ markupVariables: Variable[]
32
+ enableMarkupVariables: boolean
30
33
  }
package/vite.config.js CHANGED
@@ -1,4 +1,4 @@
1
- import GenerateViteConfig from '../../generateViteConfig.js'
1
+ import GenerateViteConfig from '@cdc/core/generateViteConfig.js'
2
2
  import { moduleName } from './package.json'
3
3
 
4
4
  export default GenerateViteConfig(moduleName)
@@ -1 +0,0 @@
1
- @import '@cdc/core/styles/base';