[v9.4.x] Alerting: Set YAML as default value for exporting alert rules (#62770)

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

Set YAML as default value for exporting alert rules

(cherry picked from commit 517e614661)

Co-authored-by: Sonia Aguilar <33540275+soniaAguilarPeiron@users.noreply.github.com>
This commit is contained in:
Grot (@grafanabot)
2023-02-02 13:42:44 +01:00
committed by GitHub
co-authored by Sonia Aguilar
parent 0413fea8d2
commit a03069fb08
@@ -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(
() => {