Skip to content

Commit

Permalink
feature dev-8490 dashboard filter refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
joshlacey committed Jul 11, 2024
1 parent 56d002e commit db33d6f
Show file tree
Hide file tree
Showing 35 changed files with 995 additions and 907 deletions.
2 changes: 1 addition & 1 deletion packages/core/components/EditorPanel/FieldSetWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type FieldSetProps = {
fieldType: string
controls: OpenControls
deleteField: Function
children: React.ReactElement[]
children: React.ReactNode
}

const FieldSet: React.FC<FieldSetProps> = ({ fieldName, fieldKey, fieldType, controls, deleteField, children }) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
// main visualization wrapper
import { ChartConfig } from '@cdc/chart/src/types/ChartConfig'
import React, { forwardRef, useRef } from 'react'
import React, { forwardRef } from 'react'
import { Config as DataBiteConfig } from '@cdc/data-bite/src/types/Config'
import './visualizations.scss'
import { Config as WaffleChartConfig } from '@cdc/waffle-chart/src/types/Config'
import { MarkupIncludeConfig } from '@cdc/core/types/MarkupInclude'
import { DashboardFilters } from '@cdc/dashboard/src/types/DashboardFilters'

type VisualizationWrapper = {
children: React.ReactNode
config: ChartConfig | DataBiteConfig | WaffleChartConfig | MarkupIncludeConfig
currentViewport: string
imageId: string
config: ChartConfig | DataBiteConfig | WaffleChartConfig | MarkupIncludeConfig | DashboardFilters
currentViewport?: string
imageId?: string
isEditor: boolean
showEditorPanel: boolean
showEditorPanel?: boolean
}

const Visualization: React.FC<VisualizationWrapper> = forwardRef((props, ref) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/components/ui/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const iconHash = {
plus: iconPlus,
minus: iconMinus,
'filtered-text': iconText,
'filter-dropdowns': iconDropdowns,
dashboardFilters: iconDropdowns,
table: iconTable,
sankey: iconSankey,
rotateLeft: iconRotateLeft,
Expand Down
99 changes: 71 additions & 28 deletions packages/core/helpers/ver/4.24.7.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,71 @@
import _ from 'lodash'

const mapUpdates = newConfig => {
// When switching between old version of equal number, and the revised equal number opt in, roundToPlace needs to be set.
// There wasn't an initial value set for this, and legends would return NaN if it wasn't set. ie. 0 - NAN instead of 0 - 1
const equalNumberRoundingPatch = newConfig => {
if (newConfig.type === 'map') {
if (newConfig.columns.primary.roundToPlace === undefined) {
newConfig.columns.primary.roundToPlace = 0
}
}
}

equalNumberRoundingPatch(newConfig)

return newConfig
}

const update_4_24_7 = config => {
const ver = '4.24.7'

const newConfig = _.cloneDeep(config)

mapUpdates(newConfig)
newConfig.version = ver
return newConfig
}
export default update_4_24_7
import _ from 'lodash'
import { DashboardFilters } from '@cdc/dashboard/src/types/DashboardFilters'
import { MultiDashboardConfig } from '@cdc/dashboard/src/types/MultiDashboard'

const dashboardFiltersMigrate = config => {
if (!config.dashboard) return config
const dashboardConfig = config as MultiDashboardConfig
const newVisualizations = {}
// autoload was removed from APIFilter type
const newSharedFilters = (dashboardConfig.dashboard.sharedFilters || []).map(sf => {
if (sf.apiFilter?.autoLoad !== undefined) {
delete sf.apiFilter.autoLoad
}
if (sf.apiFilter?.defaultValue !== undefined) {
delete sf.apiFilter.defaultValue
}
return sf
})
config.dashboard.sharedFilters = newSharedFilters

Object.keys(dashboardConfig.visualizations).forEach(vizKey => {
const viz = dashboardConfig.visualizations[vizKey] as DashboardFilters
// hide was removed from visualizations
if (viz.hide !== undefined) {
viz.sharedFilterIndexes = newSharedFilters.map((_sf, i) => i).filter(i => !viz.hide.includes(i))
viz.type = 'dashboardFilters'
if (viz.autoLoad) {
viz.filterBehavior = 'Filter Change'
} else {
viz.filterBehavior = 'Apply Button'
}

delete viz.hide
}
// 'filter-dropdowns' was renamed to 'dashboardFilters' for clarity
if (viz.type === 'filter-dropdowns') viz.type = 'dashboardFilters'
if (viz.visualizationType === 'filter-dropdowns') viz.visualizationType = 'dashboardFilters'
newVisualizations[vizKey] = viz
})
// if there's no dashboardFilters visualization but there are sharedFilters create a visualization and update rows.

config.visualizations = newVisualizations
}

const mapUpdates = newConfig => {
// When switching between old version of equal number, and the revised equal number opt in, roundToPlace needs to be set.
// There wasn't an initial value set for this, and legends would return NaN if it wasn't set. ie. 0 - NAN instead of 0 - 1
const equalNumberRoundingPatch = newConfig => {
if (newConfig.type === 'map') {
if (newConfig.columns.primary.roundToPlace === undefined) {
newConfig.columns.primary.roundToPlace = 0
}
}
}

equalNumberRoundingPatch(newConfig)

return newConfig
}

const update_4_24_7 = config => {
const ver = '4.24.7'

const newConfig = _.cloneDeep(config)

mapUpdates(newConfig)
dashboardFiltersMigrate(newConfig)
newConfig.version = ver
return newConfig
}
export default update_4_24_7
1 change: 0 additions & 1 deletion packages/core/types/BaseVisualizationType.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/core/types/General.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export type General = {
showMissingDataLabel: boolean
showSuppressedSymbol: boolean
showZeroValueDataLabel: boolean
title: string
}
35 changes: 27 additions & 8 deletions packages/core/types/Visualization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,28 @@ import { Column } from './Column'
import { Series } from './Series'
import { Table } from './Table'
import { ConfidenceInterval } from './ConfidenceInterval'
import { BaseVisualizationType } from './BaseVisualizationType'
import { ConfigureData } from './ConfigureData'
import { VizFilter } from './VizFilter'
import { FilterBehavior } from './FilterBehavior'
import { General } from './General'
import { Runtime } from './Runtime'
import { DashboardFilters } from '@cdc/dashboard/src/types/DashboardFilters'

export type Visualization = ConfigureData & {
autoLoad: boolean
// This was originally created as a catchall for the different types of visualizations.
// Currently it includes properties that ares specific to one Visualization type.
// We should avoid adding any new property to this type unless it is used by all visualizations.
// We should refactor it also to remove properties that are not used by all visualizations.
// See AnyVisualization type below...
type DeprecatedVisualizationType = {
columns: Record<string, Partial<Column>>
confidenceKeys: ConfidenceInterval
dataFileName: string
dataFileSourceType: string
dataFormat: any
datasets: Record<string, any>
editing: boolean
filterBehavior: FilterBehavior
filters: VizFilter[]
general: General
hide: number[]
legend: Legend
multiDashboards?: any[]
newViz: boolean
Expand All @@ -32,15 +34,32 @@ export type Visualization = ConfigureData & {
originalFormattedData: any
runtime?: Runtime
series: Series
showEditorPanel: boolean
table: Table
theme: string
title: string
type: BaseVisualizationType
uid: string // this is the actual key of the visualization object
type: 'dashboard' | 'chart' | 'footnotes' | 'map' | 'data-bite' | 'waffle-chart' | 'markup-include' | 'filtered-text' | 'table' | 'navigation'
usesSharedFilter: any
visualizationSubType: string
visualizationType: string
xAxis: Axis
preliminaryData: { type: 'effect' | 'suppression'; value: string }[]
}

type StatefulProperties = {
editing: boolean
newViz: boolean
}

export type CommonVisualizationProperties = Partial<StatefulProperties> & {
showEditorPanel?: boolean
uid?: string // this is the actual key of the visualization object
visualizationType?: string
} & Partial<ConfigureData>

export type Visualization = DeprecatedVisualizationType & CommonVisualizationProperties

// This type is used as a catchall for the different types of visualizations.
// We should create a specific type for each visualization type and add it to this list.
// We will remove Visualization from this list once we have all union types listed.
// All of the New types will extend CommonVisualizationProperties.
export type AnyVisualization = Visualization | DashboardFilters
2 changes: 1 addition & 1 deletion packages/core/types/VizFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export type GeneralFilter = FilterBase & {
export type MultiSelectFilter = {
active: string[]
selectLimit: number
} & GeneralFilter
} & Omit<GeneralFilter, 'active'>

export type VizFilter = GeneralFilter | MultiSelectFilter
Loading

0 comments on commit db33d6f

Please sign in to comment.