import React from 'react'; import { Segment, SegmentAsync } from '@grafana/ui'; import { SelectableValue } from '@grafana/data'; import { selectors } from '../constants'; import { Project, AlignmentPeriods, AliasBy, QueryInlineField } from '.'; import { SLOQuery } from '../types'; import StackdriverDatasource from '../datasource'; export interface Props { usedAlignmentPeriod: string; variableOptionGroup: SelectableValue; onChange: (query: SLOQuery) => void; onRunQuery: () => void; query: SLOQuery; datasource: StackdriverDatasource; } export const defaultQuery: SLOQuery = { projectName: '', alignmentPeriod: 'stackdriver-auto', aliasBy: '', selectorName: 'select_slo_health', serviceId: '', sloId: '', }; export function SLOQueryEditor({ query, datasource, onChange, variableOptionGroup, usedAlignmentPeriod, }: React.PropsWithChildren) { return ( <> onChange({ ...query, projectName })} /> datasource.getSLOServices(query.projectName).then(services => [ { label: 'Template Variables', options: variableOptionGroup.options, }, ...services, ]) } onChange={({ value: serviceId = '' }) => onChange({ ...query, serviceId, sloId: '' })} /> datasource.getServiceLevelObjectives(query.projectName, query.serviceId).then(sloIds => [ { label: 'Template Variables', options: variableOptionGroup.options, }, ...sloIds, ]) } onChange={async ({ value: sloId = '' }) => { const slos = await datasource.getServiceLevelObjectives(query.projectName, query.serviceId); const slo = slos.find(({ value }) => value === datasource.templateSrv.replace(sloId)); onChange({ ...query, sloId, goal: slo?.goal }); }} /> s.value === query?.selectorName ?? '')} options={[ { label: 'Template Variables', options: variableOptionGroup.options, }, ...selectors, ]} onChange={({ value: selectorName }) => onChange({ ...query, selectorName })} /> onChange({ ...query, alignmentPeriod })} /> onChange({ ...query, aliasBy })} /> ); }