Skip to content

Commit

Permalink
OPG-483: Fix initialization of resource variable in PerformanceAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
synqotik committed Dec 12, 2024
1 parent a6294dd commit 7e619a8
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/datasources/perf-ds/PerformanceAttribute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -109,7 +109,19 @@ export const PerformanceAttribute: React.FC<PerformanceAttributesProps> = ({

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,
Expand Down

0 comments on commit 7e619a8

Please sign in to comment.