@cdc/editor 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/dist/cdceditor.js +70238 -67953
- package/example/valid-scatterplot.csv +17 -0
- package/package.json +16 -9
- package/src/CdcEditor.tsx +5 -4
- package/src/_stories/Editor.stories.tsx +35 -35
- package/src/components/ChooseTab.tsx +5 -5
- package/src/components/ConfigureTab.tsx +11 -5
- package/src/components/DataImport/components/DataImport.tsx +2 -2
- package/src/components/DataImport/components/data-import.scss +2 -1
- package/src/components/PreviewDataTable.tsx +17 -13
- package/src/components/Tabs.tsx +1 -1
- package/src/helpers/saveConfigToWindow.ts +13 -13
- package/src/index.jsx +0 -1
- package/vite.config.js +1 -1
- package/src/ConfigContext.ts +0 -15
- package/src/coreStyles_editor.scss +0 -2
- package/src/store/editor.actions.ts +0 -28
- package/src/store/editor.reducer.ts +0 -93
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
x,y1,y2,y3,y4
|
|
2
|
+
1,8,37,72,82
|
|
3
|
+
2,2,30,75,83
|
|
4
|
+
3,15,42,51,95
|
|
5
|
+
4,10,38,61,96
|
|
6
|
+
5,1,38,66,86
|
|
7
|
+
60,6,37,70,85
|
|
8
|
+
10,19,47,59,91
|
|
9
|
+
24,18,32,68,89
|
|
10
|
+
3,7,38,74,89
|
|
11
|
+
26,10,39,56,91
|
|
12
|
+
42,16,38,55,76
|
|
13
|
+
32,20,46,52,94
|
|
14
|
+
11,9,41,57,86
|
|
15
|
+
22,10,47,56,80
|
|
16
|
+
73,1,36,71,94
|
|
17
|
+
23,13,30,66,78
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cdc/editor",
|
|
3
|
-
"version": "4.25.
|
|
3
|
+
"version": "4.25.10",
|
|
4
4
|
"description": "React component for generating a new component entry",
|
|
5
5
|
"moduleName": "CdcEditor",
|
|
6
6
|
"main": "dist/cdceditor",
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
},
|
|
26
26
|
"license": "Apache-2.0",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@cdc/chart": "^4.25.
|
|
29
|
-
"@cdc/core": "^4.25.
|
|
30
|
-
"@cdc/dashboard": "^4.25.
|
|
31
|
-
"@cdc/data-bite": "^4.25.
|
|
32
|
-
"@cdc/map": "^4.25.
|
|
33
|
-
"@cdc/markup-include": "^4.25.
|
|
34
|
-
"@cdc/waffle-chart": "^4.25.
|
|
28
|
+
"@cdc/chart": "^4.25.10",
|
|
29
|
+
"@cdc/core": "^4.25.10",
|
|
30
|
+
"@cdc/dashboard": "^4.25.10",
|
|
31
|
+
"@cdc/data-bite": "^4.25.10",
|
|
32
|
+
"@cdc/map": "^4.25.10",
|
|
33
|
+
"@cdc/markup-include": "^4.25.10",
|
|
34
|
+
"@cdc/waffle-chart": "^4.25.10",
|
|
35
35
|
"axios": "^1.9.0",
|
|
36
36
|
"d3": "^7.9.0",
|
|
37
37
|
"react-dropzone": "^14.3.8",
|
|
@@ -41,5 +41,12 @@
|
|
|
41
41
|
"react": "^18.2.0",
|
|
42
42
|
"react-dom": "^18.2.0"
|
|
43
43
|
},
|
|
44
|
-
"
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@rollup/plugin-dsv": "^3.0.2",
|
|
46
|
+
"@vitejs/plugin-react": "^4.3.4",
|
|
47
|
+
"vite": "^4.4.11",
|
|
48
|
+
"vite-plugin-css-injected-by-js": "^2.4.0",
|
|
49
|
+
"vite-plugin-svgr": "^2.4.0"
|
|
50
|
+
},
|
|
51
|
+
"gitHead": "c2db758e74ab9b9ca1667a6f9cb41dd0dccf985d"
|
|
45
52
|
}
|
package/src/CdcEditor.tsx
CHANGED
|
@@ -7,7 +7,7 @@ import ResizeObserver from 'resize-observer-polyfill'
|
|
|
7
7
|
import getViewport from '@cdc/core/helpers/getViewport'
|
|
8
8
|
|
|
9
9
|
import { GlobalContextProvider } from '@cdc/core/components/GlobalContext'
|
|
10
|
-
import ConfigContext, { EditorDispatchContext } from '
|
|
10
|
+
import ConfigContext, { EditorDispatchContext } from '@cdc/core/contexts/EditorContext'
|
|
11
11
|
|
|
12
12
|
import OverlayFrame from '@cdc/core/components/ui/OverlayFrame'
|
|
13
13
|
|
|
@@ -16,13 +16,14 @@ import ChooseTab from './components/ChooseTab'
|
|
|
16
16
|
import ConfigureTab from './components/ConfigureTab'
|
|
17
17
|
import TabPane from './components/TabPane'
|
|
18
18
|
import { GlobalTabs as Tabs } from './components/Tabs'
|
|
19
|
-
import {
|
|
19
|
+
import { stripConfig } from '@cdc/dashboard/src/helpers/formatConfigBeforeSave'
|
|
20
20
|
import { saveConfigToWindow as updateVizConfig } from './helpers/saveConfigToWindow'
|
|
21
21
|
import { legacyConfigSupport } from './helpers/legacyConfigSupport'
|
|
22
22
|
|
|
23
23
|
import './scss/main.scss'
|
|
24
|
-
import editorReducer, { EditorState } from '
|
|
24
|
+
import editorReducer, { EditorState } from '@cdc/core/contexts/editor.reducer'
|
|
25
25
|
import _ from 'lodash'
|
|
26
|
+
import { cloneConfig } from '@cdc/core/helpers/cloneConfig'
|
|
26
27
|
import { WCMSProps } from '@cdc/core/types/WCMSProps'
|
|
27
28
|
import { devToolsStore } from '@cdc/core/helpers/withDevTools'
|
|
28
29
|
|
|
@@ -57,7 +58,7 @@ const CdcEditor: React.FC<WCMSProps> = ({ config: configObj, hostname, container
|
|
|
57
58
|
const [state, dispatch] = useReducer(editorReducer, initialState)
|
|
58
59
|
|
|
59
60
|
const setTempConfigAndUpdate = config => {
|
|
60
|
-
updateVizConfig(
|
|
61
|
+
updateVizConfig(cloneConfig(config))
|
|
61
62
|
dispatch({ type: 'EDITOR_TEMP_SAVE', payload: config })
|
|
62
63
|
}
|
|
63
64
|
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { Meta, StoryObj } from '@storybook/react'
|
|
2
|
-
import CdcEditor from '../CdcEditor'
|
|
3
|
-
import { within, userEvent } from '
|
|
4
|
-
|
|
5
|
-
const sleep = ms => {
|
|
6
|
-
return new Promise(r => setTimeout(r, ms))
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const meta: Meta<typeof CdcEditor> = {
|
|
10
|
-
title: 'Components/Pages/CdcEditor',
|
|
11
|
-
component: CdcEditor
|
|
12
|
-
}
|
|
13
|
-
export default meta
|
|
14
|
-
|
|
15
|
-
type Story = StoryObj<typeof CdcEditor>
|
|
16
|
-
|
|
17
|
-
export const DefaultEditor: Story = {
|
|
18
|
-
args: {
|
|
19
|
-
config: {}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const
|
|
24
|
-
args: {},
|
|
25
|
-
parameters: {},
|
|
26
|
-
play: async ({ canvasElement }) => {
|
|
27
|
-
const canvas = within(canvasElement)
|
|
28
|
-
const user = userEvent.setup()
|
|
29
|
-
await sleep(1000)
|
|
30
|
-
const mapButton = canvas.getByText('United States (State- or County-Level)')
|
|
31
|
-
await user.click(mapButton)
|
|
32
|
-
const sampleData = canvas.getByText('United States: County Sample Data')
|
|
33
|
-
await user.click(sampleData)
|
|
34
|
-
}
|
|
35
|
-
}
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react-vite'
|
|
2
|
+
import CdcEditor from '../CdcEditor'
|
|
3
|
+
import { within, userEvent } from 'storybook/test'
|
|
4
|
+
|
|
5
|
+
const sleep = ms => {
|
|
6
|
+
return new Promise(r => setTimeout(r, ms))
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const meta: Meta<typeof CdcEditor> = {
|
|
10
|
+
title: 'Components/Pages/CdcEditor',
|
|
11
|
+
component: CdcEditor
|
|
12
|
+
}
|
|
13
|
+
export default meta
|
|
14
|
+
|
|
15
|
+
type Story = StoryObj<typeof CdcEditor>
|
|
16
|
+
|
|
17
|
+
export const DefaultEditor: Story = {
|
|
18
|
+
args: {
|
|
19
|
+
config: {}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const PreviewTableTests: Story = {
|
|
24
|
+
args: {},
|
|
25
|
+
parameters: {},
|
|
26
|
+
play: async ({ canvasElement }) => {
|
|
27
|
+
const canvas = within(canvasElement)
|
|
28
|
+
const user = userEvent.setup()
|
|
29
|
+
await sleep(1000)
|
|
30
|
+
const mapButton = canvas.getByText('United States (State- or County-Level)')
|
|
31
|
+
await user.click(mapButton)
|
|
32
|
+
const sampleData = canvas.getByText('United States: County Sample Data')
|
|
33
|
+
await user.click(sampleData)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useContext, useState } from 'react'
|
|
2
2
|
import '../scss/choose-vis-tab.scss'
|
|
3
3
|
|
|
4
|
-
import ConfigContext, { EditorDispatchContext } from '
|
|
4
|
+
import ConfigContext, { EditorDispatchContext } from '@cdc/core/contexts/EditorContext'
|
|
5
5
|
import Tooltip from '@cdc/core/components/ui/Tooltip'
|
|
6
6
|
|
|
7
7
|
import DashboardIcon from '@cdc/core/assets/icon-dashboard.svg'
|
|
@@ -206,15 +206,15 @@ const ChooseTab: React.FC = (): JSX.Element => {
|
|
|
206
206
|
</div>
|
|
207
207
|
</a>
|
|
208
208
|
|
|
209
|
-
{rowLabels.map(label => {
|
|
209
|
+
{rowLabels.map((label, index) => {
|
|
210
210
|
return (
|
|
211
|
-
<React.Fragment>
|
|
211
|
+
<React.Fragment key={`row-label-${index}-${label}`}>
|
|
212
212
|
<div className='heading-2'>{label}</div>
|
|
213
213
|
<ul className={`visualization-grid category_${label.toLowerCase()}`}>
|
|
214
214
|
{buttons
|
|
215
215
|
.filter(button => button.category === label)
|
|
216
|
-
.map((button,
|
|
217
|
-
<li key={
|
|
216
|
+
.map((button, buttonIndex) => (
|
|
217
|
+
<li key={`${label}-button-${buttonIndex}`}>
|
|
218
218
|
<Tooltip position='right'>
|
|
219
219
|
<Tooltip.Target>
|
|
220
220
|
<VizButton {...button} />
|
|
@@ -7,12 +7,12 @@ import CdcWaffleChart from '@cdc/waffle-chart/src/CdcWaffleChart'
|
|
|
7
7
|
import CdcMarkupInclude from '@cdc/markup-include/src/CdcMarkupInclude'
|
|
8
8
|
|
|
9
9
|
import ErrorBoundary from '@cdc/core/components/ErrorBoundary'
|
|
10
|
-
import ConfigContext from '
|
|
10
|
+
import ConfigContext from '@cdc/core/contexts/EditorContext'
|
|
11
11
|
import MultiDashboardWrapper from '@cdc/dashboard/src/CdcDashboard'
|
|
12
|
-
import CdcDataTable from '
|
|
12
|
+
import CdcDataTable from '@cdc/data-table/src/CdcDataTable'
|
|
13
13
|
|
|
14
14
|
export default function ConfigureTab({ containerEl }) {
|
|
15
|
-
const { config, setTempConfig, isDebug } = useContext(ConfigContext)
|
|
15
|
+
const { config, setTempConfig, isDebug, configUrl } = useContext(ConfigContext)
|
|
16
16
|
|
|
17
17
|
let { type } = config
|
|
18
18
|
|
|
@@ -20,7 +20,13 @@ export default function ConfigureTab({ containerEl }) {
|
|
|
20
20
|
case 'map':
|
|
21
21
|
return (
|
|
22
22
|
<ErrorBoundary component='CdcMap'>
|
|
23
|
-
<CdcMap
|
|
23
|
+
<CdcMap
|
|
24
|
+
isEditor={true}
|
|
25
|
+
config={config}
|
|
26
|
+
containerEl={containerEl}
|
|
27
|
+
setConfig={setTempConfig}
|
|
28
|
+
configUrl={configUrl}
|
|
29
|
+
/>
|
|
24
30
|
</ErrorBoundary>
|
|
25
31
|
)
|
|
26
32
|
case 'waffle-chart':
|
|
@@ -41,7 +47,7 @@ export default function ConfigureTab({ containerEl }) {
|
|
|
41
47
|
case 'dashboard':
|
|
42
48
|
return (
|
|
43
49
|
<ErrorBoundary component='CdcDashboard'>
|
|
44
|
-
<MultiDashboardWrapper isEditor={true} isDebug={isDebug} />
|
|
50
|
+
<MultiDashboardWrapper isEditor={true} isDebug={isDebug} configUrl={configUrl} />
|
|
45
51
|
</ErrorBoundary>
|
|
46
52
|
)
|
|
47
53
|
case 'data-bite':
|
|
@@ -4,7 +4,7 @@ import axios from 'axios'
|
|
|
4
4
|
|
|
5
5
|
import { DataTransform } from '@cdc/core/helpers/DataTransform'
|
|
6
6
|
|
|
7
|
-
import ConfigContext, { EditorDispatchContext } from '
|
|
7
|
+
import ConfigContext, { EditorDispatchContext } from '@cdc/core/contexts/EditorContext'
|
|
8
8
|
|
|
9
9
|
import TabPane from '../../TabPane'
|
|
10
10
|
import Tabs from '../../Tabs'
|
|
@@ -21,7 +21,7 @@ import Tooltip from '@cdc/core/components/ui/Tooltip'
|
|
|
21
21
|
import Icon from '@cdc/core/components/ui/Icon'
|
|
22
22
|
import { isSolrCsv, isSolrJson } from '@cdc/core/helpers/isSolr'
|
|
23
23
|
import { type Visualization } from '@cdc/core/types/Visualization'
|
|
24
|
-
import { type DataSet } from '@cdc/
|
|
24
|
+
import { type DataSet } from '@cdc/core/types/DataSet'
|
|
25
25
|
|
|
26
26
|
import './data-import.scss'
|
|
27
27
|
import '@cdc/core/styles/v2/components/data-designer.scss'
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
@use 'sass:color';
|
|
1
2
|
@import './../../../scss/variables.scss';
|
|
2
3
|
|
|
3
4
|
.cdc-editor .data-designer {
|
|
@@ -114,7 +115,7 @@
|
|
|
114
115
|
}
|
|
115
116
|
.btn.active {
|
|
116
117
|
$primary: #005eaa;
|
|
117
|
-
background:
|
|
118
|
+
background: color.adjust($primary, $lightness: -15%);
|
|
118
119
|
}
|
|
119
120
|
.input-group {
|
|
120
121
|
display: flex;
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
useResizeColumns,
|
|
9
9
|
usePagination
|
|
10
10
|
} from 'react-table'
|
|
11
|
-
import ConfigContext, { EditorDispatchContext } from '
|
|
11
|
+
import ConfigContext, { EditorDispatchContext } from '@cdc/core/contexts/EditorContext'
|
|
12
12
|
import { useDebounce } from 'use-debounce'
|
|
13
13
|
import fetchRemoteData from '@cdc/core/helpers/fetchRemoteData'
|
|
14
14
|
import { MdNavigateNext } from 'react-icons/md'
|
|
@@ -17,7 +17,7 @@ import { GrFormPrevious } from 'react-icons/gr'
|
|
|
17
17
|
// Core
|
|
18
18
|
import validateFipsCodeLength from '@cdc/core/helpers/validateFipsCodeLength'
|
|
19
19
|
import { errorMessages } from '../helpers/errorMessages'
|
|
20
|
-
import { DataSet } from '@cdc/
|
|
20
|
+
import { DataSet } from '@cdc/core/types/DataSet'
|
|
21
21
|
import Icon from '@cdc/core/components/ui/Icon'
|
|
22
22
|
|
|
23
23
|
const TableFilter = memo(({ globalFilter, setGlobalFilter, disabled = false }: any) => {
|
|
@@ -262,17 +262,21 @@ const PreviewDataTable = () => {
|
|
|
262
262
|
<thead>
|
|
263
263
|
{headerGroups.map(headerGroup => (
|
|
264
264
|
<tr {...headerGroup.getHeaderGroupProps()}>
|
|
265
|
-
{headerGroup.headers.map(column =>
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
265
|
+
{headerGroup.headers.map(column => {
|
|
266
|
+
const { key, ...headerProps } = column.getHeaderProps(column.getSortByToggleProps())
|
|
267
|
+
return (
|
|
268
|
+
<th
|
|
269
|
+
key={key}
|
|
270
|
+
scope='col'
|
|
271
|
+
{...headerProps}
|
|
272
|
+
className={column.isSorted ? (column.isSortedDesc ? 'sort sort-desc' : 'sort sort-asc') : ''}
|
|
273
|
+
title={column.Header}
|
|
274
|
+
>
|
|
275
|
+
{column.render('Header')}
|
|
276
|
+
<div {...column.getResizerProps()} className='resizer' />
|
|
277
|
+
</th>
|
|
278
|
+
)
|
|
279
|
+
})}
|
|
276
280
|
</tr>
|
|
277
281
|
))}
|
|
278
282
|
</thead>
|
package/src/components/Tabs.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useContext, useState } from 'react'
|
|
2
|
-
import ConfigContext, { EditorDispatchContext } from '
|
|
2
|
+
import ConfigContext, { EditorDispatchContext } from '@cdc/core/contexts/EditorContext'
|
|
3
3
|
|
|
4
4
|
export const GlobalTabs = props => {
|
|
5
5
|
const { globalActive } = useContext(ConfigContext)
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export const saveConfigToWindow = newTempConfig => {
|
|
4
|
-
if (null !== newTempConfig) {
|
|
5
|
-
// Remove runtime/unnecessary items from config before saving to WCMS, performance optimization
|
|
6
|
-
let strippedConfig =
|
|
7
|
-
|
|
8
|
-
const parsedData = JSON.stringify(strippedConfig)
|
|
9
|
-
// Emit the data in a regular JS event so it can be consumed by anything.
|
|
10
|
-
const event = new CustomEvent('updateVizConfig', { detail: parsedData, bubbles: true })
|
|
11
|
-
window.dispatchEvent(event)
|
|
12
|
-
}
|
|
13
|
-
}
|
|
1
|
+
import { stripConfig } from '@cdc/dashboard/src/helpers/formatConfigBeforeSave'
|
|
2
|
+
|
|
3
|
+
export const saveConfigToWindow = newTempConfig => {
|
|
4
|
+
if (null !== newTempConfig) {
|
|
5
|
+
// Remove runtime/unnecessary items from config before saving to WCMS, performance optimization
|
|
6
|
+
let strippedConfig = stripConfig(newTempConfig)
|
|
7
|
+
|
|
8
|
+
const parsedData = JSON.stringify(strippedConfig)
|
|
9
|
+
// Emit the data in a regular JS event so it can be consumed by anything.
|
|
10
|
+
const event = new CustomEvent('updateVizConfig', { detail: parsedData, bubbles: true })
|
|
11
|
+
window.dispatchEvent(event)
|
|
12
|
+
}
|
|
13
|
+
}
|
package/src/index.jsx
CHANGED
package/vite.config.js
CHANGED
package/src/ConfigContext.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { WCMSProps } from '@cdc/core/types/WCMSProps'
|
|
2
|
-
import { Dispatch, createContext } from 'react'
|
|
3
|
-
import EditorActions from './store/editor.actions'
|
|
4
|
-
import { EditorState } from './store/editor.reducer'
|
|
5
|
-
|
|
6
|
-
export type EditorCTX = WCMSProps &
|
|
7
|
-
EditorState & {
|
|
8
|
-
displayName?: string
|
|
9
|
-
setTempConfig: Function
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const ConfigContext = createContext<EditorCTX>({ displayName: 'ConfigContext', setTempConfig: () => {} } as unknown as EditorCTX)
|
|
13
|
-
|
|
14
|
-
export default ConfigContext
|
|
15
|
-
export const EditorDispatchContext = createContext<Dispatch<EditorActions>>(() => {})
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { type Action } from '@cdc/core/types/Action'
|
|
2
|
-
import { type ViewPort } from '@cdc/core/types/ViewPort'
|
|
3
|
-
import { type Visualization } from '@cdc/core/types/Visualization'
|
|
4
|
-
import { DataSet } from '@cdc/dashboard/src/types/DataSet'
|
|
5
|
-
|
|
6
|
-
type EDITOR_SAVE = Action<'EDITOR_SAVE', Visualization>
|
|
7
|
-
type EDITOR_SET_CONFIG = Action<'EDITOR_SET_CONFIG', Visualization>
|
|
8
|
-
type EDITOR_TEMP_SAVE = Action<'EDITOR_TEMP_SAVE', Visualization>
|
|
9
|
-
type EDITOR_SET_ERRORS = Action<'EDITOR_SET_ERRORS', string[]>
|
|
10
|
-
type EDITOR_SET_VIEWPORT = Action<'EDITOR_SET_VIEWPORT', ViewPort>
|
|
11
|
-
type EDITOR_SET_GLOBALACTIVE = Action<'EDITOR_SET_GLOBALACTIVE', number>
|
|
12
|
-
type SET_DASHBOARD_DATASET = Action<
|
|
13
|
-
'SET_DASHBOARD_DATASET',
|
|
14
|
-
{ datasetKey: string; oldDatasetKey?: string; dataset: DataSet }
|
|
15
|
-
>
|
|
16
|
-
type DELETE_DATASET = Action<'DELETE_DASHBOARD_DATASET', { datasetKey: string }>
|
|
17
|
-
|
|
18
|
-
type actions =
|
|
19
|
-
| EDITOR_SAVE
|
|
20
|
-
| EDITOR_TEMP_SAVE
|
|
21
|
-
| EDITOR_SET_ERRORS
|
|
22
|
-
| EDITOR_SET_VIEWPORT
|
|
23
|
-
| EDITOR_SET_GLOBALACTIVE
|
|
24
|
-
| EDITOR_SET_CONFIG
|
|
25
|
-
| DELETE_DATASET
|
|
26
|
-
| SET_DASHBOARD_DATASET
|
|
27
|
-
|
|
28
|
-
export default actions
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import _ from 'lodash'
|
|
2
|
-
import EditorActions from './editor.actions'
|
|
3
|
-
import { Visualization } from '@cdc/core/types/Visualization'
|
|
4
|
-
import { devToolsWrapper } from '@cdc/core/helpers/withDevTools'
|
|
5
|
-
|
|
6
|
-
export type EditorState = {
|
|
7
|
-
config?: Visualization
|
|
8
|
-
tempConfig?: Visualization | null
|
|
9
|
-
errors: Record<string, string>
|
|
10
|
-
currentViewport: string
|
|
11
|
-
globalActive: number
|
|
12
|
-
newViz?: boolean
|
|
13
|
-
}
|
|
14
|
-
const reducer = (state: EditorState, action: EditorActions): EditorState => {
|
|
15
|
-
switch (action.type) {
|
|
16
|
-
case 'EDITOR_SAVE': {
|
|
17
|
-
return { ...state, config: action.payload, tempConfig: null }
|
|
18
|
-
}
|
|
19
|
-
case 'EDITOR_SET_CONFIG': {
|
|
20
|
-
return { ...state, config: action.payload }
|
|
21
|
-
}
|
|
22
|
-
case 'SET_DASHBOARD_DATASET': {
|
|
23
|
-
const { dataset, datasetKey, oldDatasetKey } = action.payload
|
|
24
|
-
const oldDataset = oldDatasetKey ? state.config?.datasets[oldDatasetKey] : {}
|
|
25
|
-
const config = _.cloneDeep(state.config)
|
|
26
|
-
if (oldDatasetKey) {
|
|
27
|
-
const changeDatasets = _config => {
|
|
28
|
-
_config.rows?.forEach(row => {
|
|
29
|
-
if (row.dataKey === oldDatasetKey) {
|
|
30
|
-
row.dataKey = datasetKey
|
|
31
|
-
}
|
|
32
|
-
})
|
|
33
|
-
Object.values(_config.visualizations || {}).forEach(viz => {
|
|
34
|
-
if (viz.dataKey === oldDatasetKey) {
|
|
35
|
-
viz.dataKey = datasetKey
|
|
36
|
-
}
|
|
37
|
-
})
|
|
38
|
-
}
|
|
39
|
-
applyMultiDashboards(config, changeDatasets)
|
|
40
|
-
delete config.datasets[oldDatasetKey]
|
|
41
|
-
}
|
|
42
|
-
Object.values(config.datasets).forEach(dataset => {
|
|
43
|
-
dataset.preview = false
|
|
44
|
-
})
|
|
45
|
-
config.datasets[datasetKey] = { ...oldDataset, ...dataset }
|
|
46
|
-
return { ...state, config }
|
|
47
|
-
}
|
|
48
|
-
case 'DELETE_DASHBOARD_DATASET': {
|
|
49
|
-
const { datasetKey } = action.payload
|
|
50
|
-
const deleteDatasetKeys = _config => {
|
|
51
|
-
_config.rows?.forEach(row => {
|
|
52
|
-
if (row.dataKey === datasetKey) {
|
|
53
|
-
delete row.dataKey
|
|
54
|
-
}
|
|
55
|
-
})
|
|
56
|
-
Object.values(_config.visualizations || {}).forEach(viz => {
|
|
57
|
-
if (viz.dataKey === datasetKey) {
|
|
58
|
-
delete viz.dataKey
|
|
59
|
-
}
|
|
60
|
-
})
|
|
61
|
-
}
|
|
62
|
-
const config = _.cloneDeep(state.config)
|
|
63
|
-
applyMultiDashboards(config, deleteDatasetKeys)
|
|
64
|
-
delete config.datasets[datasetKey]
|
|
65
|
-
return { ...state, config }
|
|
66
|
-
}
|
|
67
|
-
case 'EDITOR_TEMP_SAVE': {
|
|
68
|
-
return { ...state, tempConfig: action.payload }
|
|
69
|
-
}
|
|
70
|
-
case 'EDITOR_SET_ERRORS': {
|
|
71
|
-
return { ...state, errors: action.payload }
|
|
72
|
-
}
|
|
73
|
-
case 'EDITOR_SET_VIEWPORT': {
|
|
74
|
-
return { ...state, currentViewport: action.payload }
|
|
75
|
-
}
|
|
76
|
-
case 'EDITOR_SET_GLOBALACTIVE': {
|
|
77
|
-
return { ...state, globalActive: action.payload }
|
|
78
|
-
}
|
|
79
|
-
default:
|
|
80
|
-
return state
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const applyMultiDashboards = (config: Record<string, any>, mutationFunc: Function) => {
|
|
85
|
-
if (config.multiDashboards) {
|
|
86
|
-
config.multiDashboards.forEach(dashboard => {
|
|
87
|
-
mutationFunc(dashboard)
|
|
88
|
-
})
|
|
89
|
-
}
|
|
90
|
-
mutationFunc(config)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export default devToolsWrapper<EditorState, EditorActions>(reducer)
|