Alerting: Pass yaml as a query param in export request (#62751)

* Set YAML as default value for exporting alert rules

* use YAML format for rule list export

Co-authored-by: Sonia Aguilar <33540275+soniaAguilarPeiron@users.noreply.github.com>

* lint

* Add new format query param to swagger+docs

* Fix broken test

---------

Co-authored-by: Gilles De Mey <gilles.de.mey@gmail.com>
Co-authored-by: Matt Jacobson <matthew.jacobson@grafana.com>
This commit is contained in:
Sonia Aguilar
2023-02-02 17:10:02 +01:00
committed by GitHub
parent 99a16d27c1
commit 753c84f825
8 changed files with 173 additions and 40 deletions

View File

@@ -5,7 +5,7 @@ import { useAsyncFn, useInterval } from 'react-use';
import { GrafanaTheme2, urlUtil } from '@grafana/data';
import { Stack } from '@grafana/experimental';
import { BackendSrvRequest, getBackendSrv, logInfo } from '@grafana/runtime';
import { 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,20 +33,7 @@ const VIEWS = {
state: RuleListStateView,
};
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 onExport = () => window.open('/api/v1/provisioning/alert-rules/export?download=true&format=yaml');
const RuleList = withErrorBoundary(
() => {