Skip to content

Commit

Permalink
Add type for state.controls.defaults
Browse files Browse the repository at this point in the history
Partial<ControlsState> previously worked but has the side effect of
marking all keys as optional, which is not accurate and prone to cause
future type errors.
  • Loading branch information
victorlin committed Oct 8, 2024
1 parent 4b45f15 commit cb3ce63
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/reducers/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { doesColorByHaveConfidence } from "../actions/recomputeReduxState";
import { hasMultipleGridPanels } from "../actions/panelDisplay";

export interface BasicControlsState {
defaults: Defaults
panelsAvailable: string[]
panelsToDisplay: string[]
showTreeToo: boolean
Expand All @@ -36,11 +37,24 @@ export interface MeasurementsControlState {

export interface ControlsState extends BasicControlsState, MeasurementsControlState {}

interface Defaults {
distanceMeasure: string
layout: string
geoResolution: string
filters: Record<string, any>
filtersInFooter: any[]
colorBy: string
selectedBranchLabel: string
tipLabelKey: typeof strainSymbol
showTransmissionLines: boolean
sidebarOpen?: boolean
}

/* defaultState is a fn so that we can re-create it
at any time, e.g. if we want to revert things (e.g. on dataset change)
*/
export const getDefaultControlsState = () => {
const defaults: Partial<ControlsState> = {
const defaults: Defaults = {
distanceMeasure: defaultDistanceMeasure,
layout: defaultLayout,
geoResolution: defaultGeoResolution,
Expand Down

0 comments on commit cb3ce63

Please sign in to comment.