@cdc/editor 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.
Files changed (29) hide show
  1. package/dist/{cdceditor-fce76882.es.js → cdceditor-BnB1QM5d.es.js} +6 -13
  2. package/dist/{cdceditor-c55ac1ea.es.js → cdceditor-D6CG2-Hb.es.js} +5 -12
  3. package/dist/{cdceditor-31a33da1.es.js → cdceditor-MXgURbdZ.es.js} +6 -13
  4. package/dist/{cdceditor-1a1724a1.es.js → cdceditor-dgT_1dIT.es.js} +136 -151
  5. package/dist/cdceditor.js +74915 -72367
  6. package/example/private/markup-footer/burden_toolkit_mortality_diabetes_attributable_deaths_data.csv +14041 -0
  7. package/example/private/markup-footer/burden_toolkit_mortality_diabetes_attributable_deaths_per_100000_data.csv +14041 -0
  8. package/example/private/markup-footer/burden_toolkit_mortality_qaly_data.csv +18721 -0
  9. package/example/private/markup-footer/burden_toolkit_mortality_yll_data.csv +18721 -0
  10. package/example/private/markup-footer/mortality-deaths-footnotes-age.csv +3 -0
  11. package/example/valid-scatterplot.csv +17 -0
  12. package/package.json +15 -9
  13. package/src/CdcEditor.tsx +5 -4
  14. package/src/_stories/Editor.stories.tsx +35 -35
  15. package/src/components/ChooseTab.tsx +5 -5
  16. package/src/components/ConfigureTab.tsx +2 -2
  17. package/src/components/DataImport/components/DataImport.tsx +2 -2
  18. package/src/components/DataImport/components/data-import.scss +2 -1
  19. package/src/components/DataImport/components/samples/valid-boxplot.csv +37 -17
  20. package/src/components/PreviewDataTable.tsx +17 -13
  21. package/src/components/Tabs.tsx +1 -1
  22. package/src/helpers/saveConfigToWindow.ts +13 -13
  23. package/src/index.jsx +0 -1
  24. package/vite.config.js +1 -1
  25. package/src/ConfigContext.ts +0 -15
  26. package/src/coreStyles_editor.scss +0 -2
  27. package/src/store/editor.actions.ts +0 -28
  28. package/src/store/editor.reducer.ts +0 -93
  29. /package/dist/{cdceditor-548642e6.es.js → cdceditor-Ct2SB0vL.es.js} +0 -0
@@ -0,0 +1,3 @@
1
+ M_short_indicator_text,M_footnote_text_to_define_short_text,M_datasource_footnotetext,M_footnote_context1,M_footnote_context2,M_footnote_context3
2
+ Cause-specific Deaths,ATD = Attributable to Diabetes,"Data Sources: Centers for Disease Control and Prevention, National Center for Health Statistics. Multiple Cause of Death 1999-2013 from CDC WONDER Online Database, 2013 United States Renal Data System.","All Causes of Death (Estimated): Reports the estimated number of deaths from all causes attributable to diabetes as a rate (per 100,000 persons age 15+). ","Cardiovascular Disease (Estimated): Reports the estimated number of deaths from cardiovascular disease attributable to diabetes as a rate (per 100,000 persons age 15+). ","End-stage Renal Disease: Reports the number of deaths from end-stage renal disease attributable to diabetes as a rate (per 100,000 persons age 15+). "
3
+ Diabetes Cause of Death,,"Data Sources: Centers for Disease Control and Prevention, National Center for Health Statistics. Multiple Cause of Death 2021 from CDC WONDER Online Database.",Number of Deaths: Reports the number of deaths with diabetes as the underlying cause of death.,,
@@ -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.8",
3
+ "version": "4.25.11",
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.8",
29
- "@cdc/core": "^4.25.8",
30
- "@cdc/dashboard": "^4.25.8",
31
- "@cdc/data-bite": "^4.25.8",
32
- "@cdc/map": "^4.25.8",
33
- "@cdc/markup-include": "^4.25.8",
34
- "@cdc/waffle-chart": "^4.25.8",
28
+ "@cdc/chart": "^4.25.11",
29
+ "@cdc/core": "^4.25.11",
30
+ "@cdc/dashboard": "^4.25.11",
31
+ "@cdc/data-bite": "^4.25.11",
32
+ "@cdc/map": "^4.25.11",
33
+ "@cdc/markup-include": "^4.25.11",
34
+ "@cdc/waffle-chart": "^4.25.11",
35
35
  "axios": "^1.9.0",
36
36
  "d3": "^7.9.0",
37
37
  "react-dropzone": "^14.3.8",
@@ -41,5 +41,11 @@
41
41
  "react": "^18.2.0",
42
42
  "react-dom": "^18.2.0"
43
43
  },
44
- "gitHead": "e369994230b5e3facff224e1d89d5937528ac5a0"
44
+ "devDependencies": {
45
+ "@vitejs/plugin-react": "^4.3.4",
46
+ "vite": "^4.4.11",
47
+ "vite-plugin-css-injected-by-js": "^2.4.0",
48
+ "vite-plugin-svgr": "^2.4.0"
49
+ },
50
+ "gitHead": "5f09a137c22f454111ab5f4cd7fdf1d2d58e31bd"
45
51
  }
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 './ConfigContext'
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 { formatConfigBeforeSave as stripConfig } from '@cdc/core/helpers/formatConfigBeforeSave'
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 './store/editor.reducer'
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(_.cloneDeep(config))
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 '@storybook/testing-library'
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 PreviewTable: 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
+ 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 '../ConfigContext'
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, index) => (
217
- <li key={index}>
216
+ .map((button, buttonIndex) => (
217
+ <li key={`${label}-button-${buttonIndex}`}>
218
218
  <Tooltip position='right'>
219
219
  <Tooltip.Target>
220
220
  <VizButton {...button} />
@@ -7,9 +7,9 @@ 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 '../ConfigContext'
10
+ import ConfigContext from '@cdc/core/contexts/EditorContext'
11
11
  import MultiDashboardWrapper from '@cdc/dashboard/src/CdcDashboard'
12
- import CdcDataTable from '../../../data-table/src/CdcDataTable'
12
+ import CdcDataTable from '@cdc/data-table/src/CdcDataTable'
13
13
 
14
14
  export default function ConfigureTab({ containerEl }) {
15
15
  const { config, setTempConfig, isDebug, configUrl } = useContext(ConfigContext)
@@ -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 '../../../ConfigContext'
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/dashboard/src/types/DataSet'
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: darken($primary, 15%);
118
+ background: color.adjust($primary, $lightness: -15%);
118
119
  }
119
120
  .input-group {
120
121
  display: flex;
@@ -1,17 +1,37 @@
1
- Group_Category,Value
2
- category one,21
3
- category one,19
4
- category one,23
5
- category one,24
6
- category two,18
7
- category two,10
8
- category two,12
9
- category two,19
10
- category three,30
11
- category three,35
12
- category three,36
13
- category three,40
14
- category four,50
15
- category four,54
16
- category four,42
17
- category four,159
1
+ Group,Score
2
+ Group A,8
3
+ Group A,24
4
+ Group A,32
5
+ Group A,40
6
+ Group A,43
7
+ Group A,72
8
+ Group A,83
9
+ Group A,90
10
+ Group A,92
11
+ Group A,96
12
+ Group A,112
13
+ Group A,278
14
+ Group B,5
15
+ Group B,10
16
+ Group B,15
17
+ Group B,20
18
+ Group B,25
19
+ Group B,30
20
+ Group B,35
21
+ Group B,40
22
+ Group B,45
23
+ Group B,50
24
+ Group B,55
25
+ Group B,60
26
+ Group C,12
27
+ Group C,44
28
+ Group C,46
29
+ Group C,63
30
+ Group C,76
31
+ Group C,88
32
+ Group C,94
33
+ Group C,99
34
+ Group C,112
35
+ Group C,118
36
+ Group C,240
37
+ Group C,256
@@ -8,7 +8,7 @@ import {
8
8
  useResizeColumns,
9
9
  usePagination
10
10
  } from 'react-table'
11
- import ConfigContext, { EditorDispatchContext } from '../ConfigContext'
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/dashboard/src/types/DataSet'
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
- <th
267
- scope='col'
268
- {...column.getHeaderProps(column.getSortByToggleProps())}
269
- className={column.isSorted ? (column.isSortedDesc ? 'sort sort-desc' : 'sort sort-asc') : ''}
270
- title={column.Header}
271
- >
272
- {column.render('Header')}
273
- <div {...column.getResizerProps()} className='resizer' />
274
- </th>
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>
@@ -1,5 +1,5 @@
1
1
  import { useContext, useState } from 'react'
2
- import ConfigContext, { EditorDispatchContext } from '../ConfigContext'
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 { formatConfigBeforeSave } from '@cdc/core/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 = formatConfigBeforeSave(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
- }
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
@@ -2,7 +2,6 @@ import React from 'react'
2
2
  import ReactDOM from 'react-dom/client'
3
3
 
4
4
  import '@cdc/core/styles/cove-main.scss'
5
- import './coreStyles_editor.scss'
6
5
 
7
6
  import CdcEditor from './CdcEditor'
8
7
 
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,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,2 +0,0 @@
1
- @import '@cdc/core/styles/base';
2
- @import '@cdc/core/styles/variables';
@@ -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)