From 7653da1870961dcf986fec81a75381045b24eea2 Mon Sep 17 00:00:00 2001 From: Darren Janeczek <38694490+darrenjaneczek@users.noreply.github.com> Date: Wed, 20 Mar 2024 21:51:47 -0400 Subject: [PATCH] datatrails: add ability to deselect currently metric (#84586) * feat: ability to deselect currently metric --- .../app/features/trails/DataTrailsHistory.tsx | 59 +++++++++++-------- public/app/features/trails/MetricScene.tsx | 8 +++ public/app/features/trails/shared.ts | 2 +- 3 files changed, 43 insertions(+), 26 deletions(-) diff --git a/public/app/features/trails/DataTrailsHistory.tsx b/public/app/features/trails/DataTrailsHistory.tsx index c562b85cd30..c0c4fd2f6d6 100644 --- a/public/app/features/trails/DataTrailsHistory.tsx +++ b/public/app/features/trails/DataTrailsHistory.tsx @@ -69,7 +69,7 @@ export class DataTrailHistory extends SceneObjectBase { this.state.steps[0].trailState = sceneUtils.cloneSceneObjectState(oldState, { history: this }); } - if (newState.metric) { + if (newState.metric || oldState.metric) { this.addTrailStep(trail, 'metric'); } } @@ -131,7 +131,7 @@ export class DataTrailHistory extends SceneObjectBase { return (
{step.type}
- {step.type === 'metric' &&
{step.trailState.metric}
} + {step.type === 'metric' &&
{step.trailState.metric || 'Select new metric'}
}
); } @@ -163,29 +163,38 @@ export class DataTrailHistory extends SceneObjectBase { return (
History
- {steps.map((step, index) => ( - model.renderStepTooltip(step)} key={index}> - - - ))} + {steps.map((step, index) => { + let stepType = step.type; + + if (stepType === 'metric' && step.trailState.metric === undefined) { + // If we're resetting the metric, we want it to look like a start node + stepType = 'start'; + } + + return ( + model.renderStepTooltip(step)} key={index}> + + + ); + })}
); }; diff --git a/public/app/features/trails/MetricScene.tsx b/public/app/features/trails/MetricScene.tsx index 29971855954..0ffd8f7ad63 100644 --- a/public/app/features/trails/MetricScene.tsx +++ b/public/app/features/trails/MetricScene.tsx @@ -29,6 +29,7 @@ import { ActionViewType, getVariablesWithMetricConstant, MakeOptional, + MetricSelectedEvent, trailDS, VAR_GROUP_BY, VAR_METRIC_EXPR, @@ -155,6 +156,13 @@ export class MetricActionBar extends SceneObjectBase {
+ trail.publishEvent(new MetricSelectedEvent(undefined))} + > + Select new metric + { +export class MetricSelectedEvent extends BusEventWithPayload { public static type = 'metric-selected-event'; }