Alerting: Set YAML as default value for exporting alert rules (#62760)

Set YAML as default value for exporting alert rules
This commit is contained in:
Sonia Aguilar 2023-02-02 12:38:27 +01:00 committed by GitHub
parent 312ea59e6d
commit 517e614661
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,7 +5,7 @@ import { useAsyncFn, useInterval } from 'react-use';
import { GrafanaTheme2, urlUtil } from '@grafana/data';
import { Stack } from '@grafana/experimental';
import { logInfo } from '@grafana/runtime';
import { BackendSrvRequest, getBackendSrv, logInfo } from '@grafana/runtime';
import { Button, LinkButton, useStyles2, withErrorBoundary } from '@grafana/ui';
import { useQueryParams } from 'app/core/hooks/useQueryParams';
import { useDispatch } from 'app/types';
@ -33,7 +33,20 @@ const VIEWS = {
state: RuleListStateView,
};
const onExport = () => window.open(`/api/v1/provisioning/alert-rules/export?download=true`);
const onExport = async () => {
const exportURL = `/api/v1/provisioning/alert-rules/export?download=true`;
const options: BackendSrvRequest = {
url: exportURL,
headers: { Accept: 'yaml' },
responseType: 'blob',
};
const blob = await getBackendSrv().get(exportURL, undefined, undefined, options);
const fileUrl = window.URL.createObjectURL(blob);
const downloadLink = document.createElement('a');
downloadLink.href = fileUrl;
downloadLink.download = 'export.yaml';
downloadLink.click();
};
const RuleList = withErrorBoundary(
() => {