mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Initial GCM schema work - Split types for convenience - Update conditionals where needed - Update type references * Add additional supporting types * Add some more accessory and legacy types * Add missing type * Rename backend folder * Add missing generated file * Review
56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
import React, { useEffect, useState } from 'react';
|
|
|
|
import { SelectableValue } from '@grafana/data';
|
|
import { EditorField } from '@grafana/experimental';
|
|
import { Select } from '@grafana/ui';
|
|
|
|
import CloudMonitoringDatasource from '../datasource';
|
|
import { SLOQuery } from '../types/query';
|
|
|
|
export interface Props {
|
|
refId: string;
|
|
onChange: (query: SLOQuery) => void;
|
|
query: SLOQuery;
|
|
templateVariableOptions: Array<SelectableValue<string>>;
|
|
datasource: CloudMonitoringDatasource;
|
|
}
|
|
|
|
export const SLO = ({ refId, query, templateVariableOptions, onChange, datasource }: Props) => {
|
|
const [slos, setSLOs] = useState<Array<SelectableValue<string>>>([]);
|
|
const { projectName, serviceId } = query;
|
|
|
|
useEffect(() => {
|
|
if (!projectName || !serviceId) {
|
|
return;
|
|
}
|
|
|
|
datasource.getServiceLevelObjectives(projectName, serviceId).then((sloIds: Array<SelectableValue<string>>) => {
|
|
setSLOs([
|
|
{
|
|
label: 'Template Variables',
|
|
options: templateVariableOptions,
|
|
},
|
|
...sloIds,
|
|
]);
|
|
});
|
|
}, [datasource, projectName, serviceId, templateVariableOptions]);
|
|
|
|
return (
|
|
<EditorField label="SLO">
|
|
<Select
|
|
inputId={`${refId}-slo`}
|
|
width="auto"
|
|
allowCustomValue
|
|
value={query?.sloId && { value: query?.sloId, label: query?.sloName || query?.sloId }}
|
|
placeholder="Select SLO"
|
|
options={slos}
|
|
onChange={async ({ value: sloId = '', label: sloName = '' }) => {
|
|
const slos = await datasource.getServiceLevelObjectives(projectName, serviceId);
|
|
const slo = slos.find(({ value }) => value === datasource.templateSrv.replace(sloId));
|
|
onChange({ ...query, sloId, sloName, goal: slo?.goal });
|
|
}}
|
|
/>
|
|
</EditorField>
|
|
);
|
|
};
|