From 18f3c7188be5389421379dac345338d4680adc91 Mon Sep 17 00:00:00 2001 From: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Date: Thu, 28 Mar 2024 12:13:43 -0400 Subject: [PATCH] datatrails: handle "single" layout when switching to "all" labels (#85373) * fix: handle "single" layout when switching to "all" labels --- .../features/trails/ActionTabs/LayoutSwitcher.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/public/app/features/trails/ActionTabs/LayoutSwitcher.tsx b/public/app/features/trails/ActionTabs/LayoutSwitcher.tsx index 4e5a2e11a8e..f2f1ae206d4 100644 --- a/public/app/features/trails/ActionTabs/LayoutSwitcher.tsx +++ b/public/app/features/trails/ActionTabs/LayoutSwitcher.tsx @@ -20,22 +20,30 @@ export class LayoutSwitcher extends SceneObjectBase { public Selector({ model }: { model: LayoutSwitcher }) { const { options } = model.useState(); - const { layout } = model.getMetricScene().useState(); + const activeLayout = model.useActiveLayout(); return ( - + ); } + private useActiveLayout() { + const { options } = this.useState(); + const { layout } = this.getMetricScene().useState(); + + const activeLayout = options.map((option) => option.value).includes(layout) ? layout : options[0].value; + return activeLayout; + } + public onLayoutChange = (active: LayoutType) => { this.getMetricScene().setState({ layout: active }); }; public static Component = ({ model }: SceneComponentProps) => { const { layouts, options } = model.useState(); - const { layout: activeLayout } = model.getMetricScene().useState(); + const activeLayout = model.useActiveLayout(); const index = options.findIndex((o) => o.value === activeLayout); if (index === -1) {