From 7e619a83a7a993b0f3d369a90e647122b840519b Mon Sep 17 00:00:00 2001 From: Scott Theleman Date: Tue, 10 Dec 2024 16:46:52 -0500 Subject: [PATCH] OPG-483: Fix initialization of resource variable in PerformanceAttribute --- src/datasources/perf-ds/PerformanceAttribute.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/datasources/perf-ds/PerformanceAttribute.tsx b/src/datasources/perf-ds/PerformanceAttribute.tsx index 6eb770e1..c877bd43 100644 --- a/src/datasources/perf-ds/PerformanceAttribute.tsx +++ b/src/datasources/perf-ds/PerformanceAttribute.tsx @@ -3,7 +3,7 @@ import { SelectableValue } from '@grafana/data' import { Segment, SegmentAsync, SegmentInput } from '@grafana/ui' import { SegmentSectionWithIcon } from 'components/SegmentSectionWithIcon' import { ValueOverrideSwitch } from 'components/ValueOverrideSwitch' -import { getTemplateVariables } from 'lib/variableHelpers' +import { getTemplateVariables, isTemplateVariable } from 'lib/variableHelpers' import { OnmsResourceDto } from '../../lib/api_types' import { PerformanceAttributeItemState, PerformanceAttributeState } from './types' @@ -109,7 +109,19 @@ export const PerformanceAttribute: React.FC = ({ const resourceOptions: OnmsResourceDto[] = await loadResourcesByNode(node.id || node.label) const existingLabel = performanceState?.resource?.label - const resource = (existingLabel && resourceOptions && resourceOptions.filter(r => r.label === existingLabel)?.[0]) || {} + + let resource = performanceState?.resource ?? {} + + if (!isTemplateVariable(resource)) { + const resourceOption = (existingLabel && resourceOptions && resourceOptions.filter(r => r.label === existingLabel)?.[0]) || null + + if (resourceOption?.id && resourceOption?.label) { + resource = { + id: resourceOption.id ?? '', + label: resourceOption.label ?? '' + } + } + } const state = { ...performanceState,