mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Add and configure eslint-plugin-import * Fix the lint:ts npm command * Autofix + prettier all the files * Manually fix remaining files * Move jquery code in jest-setup to external file to safely reorder imports * Resolve issue caused by circular dependencies within Prometheus * Update .betterer.results * Fix missing // @ts-ignore * ignore iconBundle.ts * Fix missing // @ts-ignore
56 lines
1.7 KiB
TypeScript
56 lines
1.7 KiB
TypeScript
import React, { useEffect, useState } from 'react';
|
|
|
|
import { SelectableValue } from '@grafana/data';
|
|
import { Select } from '@grafana/ui';
|
|
|
|
import { QueryEditorRow } from '..';
|
|
import { SELECT_WIDTH } from '../../constants';
|
|
import CloudMonitoringDatasource from '../../datasource';
|
|
import { SLOQuery } from '../../types';
|
|
|
|
export interface Props {
|
|
refId: string;
|
|
onChange: (query: SLOQuery) => void;
|
|
query: SLOQuery;
|
|
templateVariableOptions: Array<SelectableValue<string>>;
|
|
datasource: CloudMonitoringDatasource;
|
|
}
|
|
|
|
export const Service: React.FC<Props> = ({ refId, query, templateVariableOptions, onChange, datasource }) => {
|
|
const [services, setServices] = useState<Array<SelectableValue<string>>>([]);
|
|
const { projectName } = query;
|
|
|
|
useEffect(() => {
|
|
if (!projectName) {
|
|
return;
|
|
}
|
|
|
|
datasource.getSLOServices(projectName).then((services: Array<SelectableValue<string>>) => {
|
|
setServices([
|
|
{
|
|
label: 'Template Variables',
|
|
options: templateVariableOptions,
|
|
},
|
|
...services,
|
|
]);
|
|
});
|
|
}, [datasource, projectName, templateVariableOptions]);
|
|
|
|
return (
|
|
<QueryEditorRow label="Service" htmlFor={`${refId}-slo-service`}>
|
|
<Select
|
|
menuShouldPortal
|
|
inputId={`${refId}-slo-service`}
|
|
width={SELECT_WIDTH}
|
|
allowCustomValue
|
|
value={query?.serviceId && { value: query?.serviceId, label: query?.serviceName || query?.serviceId }}
|
|
placeholder="Select service"
|
|
options={services}
|
|
onChange={({ value: serviceId = '', label: serviceName = '' }) =>
|
|
onChange({ ...query, serviceId, serviceName, sloId: '' })
|
|
}
|
|
/>
|
|
</QueryEditorRow>
|
|
);
|
|
};
|