datatrails: handle "single" layout when switching to "all" labels (#85373)

* fix: handle "single" layout when switching to "all" labels
pull/85488/head
Darren Janeczek 1 year ago committed by GitHub
parent 63a941472e
commit 18f3c7188b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 14
      public/app/features/trails/ActionTabs/LayoutSwitcher.tsx

@ -20,22 +20,30 @@ export class LayoutSwitcher extends SceneObjectBase<LayoutSwitcherState> {
public Selector({ model }: { model: LayoutSwitcher }) {
const { options } = model.useState();
const { layout } = model.getMetricScene().useState();
const activeLayout = model.useActiveLayout();
return (
<Field label="View">
<RadioButtonGroup options={options} value={layout} onChange={model.onLayoutChange} />
<RadioButtonGroup options={options} value={activeLayout} onChange={model.onLayoutChange} />
</Field>
);
}
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<LayoutSwitcher>) => {
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) {

Loading…
Cancel
Save