From a91923585ea8c0d87af5343369495a5de03386a9 Mon Sep 17 00:00:00 2001 From: Christian Swinehart Date: Tue, 5 Sep 2023 23:46:03 -0400 Subject: [PATCH] :bug: work around the 2 types for `manager.selection` - grapher provides a SelectionArray but a bunch of ad-hoc managers define `selection` as a string[] of entity names --- .../grapher/src/controls/Controls.tsx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/@ourworldindata/grapher/src/controls/Controls.tsx b/packages/@ourworldindata/grapher/src/controls/Controls.tsx index 1de260b0892..9c94b83f0ea 100644 --- a/packages/@ourworldindata/grapher/src/controls/Controls.tsx +++ b/packages/@ourworldindata/grapher/src/controls/Controls.tsx @@ -162,12 +162,18 @@ export class SettingsMenu extends React.Component<{ } @computed get showZoomToggle(): boolean { - return ( - !this.manager.hideZoomToggle && this.manager.type === ScatterPlot - // TODO: make this work around the definition that `selection` - // might just be an array of stringsā€¦ - // && this.manager.selection.hasSelection - ) + // TODO: + // grapher passes a SelectionArray instance but programmatically defined + // managers treat `selection` as a string[] of entity names. do we need both? + const { selection, type, hideZoomToggle } = this.manager, + entities = + selection instanceof SelectionArray + ? selection.selectedEntityNames + : Array.isArray(selection) + ? selection + : [] + + return !hideZoomToggle && type === ScatterPlot && entities.length > 0 } @computed get showNoDataAreaToggle(): boolean {