fix: [SIG-567]: prevented stage-&-run API on legend change (#4720)

* fix: prevented stage-&-run API on legend change

* fix: code refactor

---------

Co-authored-by: Sagar Rajput <sagarrajput@192.168.1.2>
This commit is contained in:
SagarRajput-7 2024-03-21 16:31:59 +05:30 committed by GitHub
parent 63f0ae1c7c
commit 0df86454ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 6 deletions

View File

@ -133,6 +133,7 @@ function WidgetGraph({
softMax,
softMin,
panelType: selectedGraph,
currentQuery,
}),
[
widgetId,
@ -148,6 +149,7 @@ function WidgetGraph({
softMax,
softMin,
selectedGraph,
currentQuery,
],
);

View File

@ -12,6 +12,7 @@ import { Dimensions } from 'hooks/useDimensions';
import { convertValue } from 'lib/getConvertedValue';
import _noop from 'lodash-es/noop';
import { MetricRangePayloadProps } from 'types/api/metrics/getQueryRange';
import { Query } from 'types/api/queryBuilder/queryBuilderData';
import uPlot from 'uplot';
import onClickPlugin, { OnClickPluginOpts } from './plugins/onClickPlugin';
@ -40,6 +41,7 @@ export interface GetUPlotChartOptions {
maxTimeScale?: number;
softMin: number | null;
softMax: number | null;
currentQuery?: Query;
}
export const getUPlotChartOptions = ({
@ -59,6 +61,7 @@ export const getUPlotChartOptions = ({
softMax,
softMin,
panelType,
currentQuery,
}: GetUPlotChartOptions): uPlot.Options => {
const timeScaleProps = getXAxisScale(minTimeScale, maxTimeScale);
@ -223,6 +226,7 @@ export const getUPlotChartOptions = ({
widgetMetaData: apiResponse?.data.result,
graphsVisibilityStates,
panelType,
currentQuery,
}),
axes: getAxes(isDarkMode, yAxisUnit),
};

View File

@ -3,6 +3,7 @@ import { PANEL_TYPES } from 'constants/queryBuilder';
import { themeColors } from 'constants/theme';
import getLabelName from 'lib/getLabelName';
import { MetricRangePayloadProps } from 'types/api/metrics/getQueryRange';
import { Query } from 'types/api/queryBuilder/queryBuilderData';
import { QueryData } from 'types/api/widgets/getQuery';
import { drawStyles, lineInterpolations } from './constants';
@ -31,6 +32,7 @@ const getSeries = ({
widgetMetaData,
graphsVisibilityStates,
panelType,
currentQuery,
}: GetSeriesProps): uPlot.Options['series'] => {
const configurations: uPlot.Series[] = [
{ label: 'Timestamp', stroke: 'purple' },
@ -40,13 +42,15 @@ const getSeries = ({
const newGraphVisibilityStates = graphsVisibilityStates?.slice(1);
for (let i = 0; i < seriesList?.length; i += 1) {
const { metric = {}, queryName = '', legend = '' } = widgetMetaData[i] || {};
const { metric = {}, queryName = '', legend: lgd } = widgetMetaData[i] || {};
const label = getLabelName(
metric,
queryName || '', // query
legend || '',
);
const newLegend =
currentQuery?.builder.queryData.find((item) => item.queryName === queryName)
?.legend || '';
const legend = newLegend || lgd || '';
const label = getLabelName(metric, queryName || '', legend);
const color = generateColor(label, themeColors.chartcolors);
@ -87,6 +91,7 @@ export type GetSeriesProps = {
widgetMetaData: QueryData[];
graphsVisibilityStates?: boolean[];
panelType?: PANEL_TYPES;
currentQuery?: Query;
};
export default getSeries;