From a03069fb089bdf6d5a01f9350f5bb90013aafd29 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Thu, 2 Feb 2023 07:42:44 -0500 Subject: [PATCH] [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 517e6146613fe91fb8b4f8ae8f572aaa4179ce81) Co-authored-by: Sonia Aguilar <33540275+soniaAguilarPeiron@users.noreply.github.com> --- .../app/features/alerting/unified/RuleList.tsx | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/public/app/features/alerting/unified/RuleList.tsx b/public/app/features/alerting/unified/RuleList.tsx index 5f0eed1cbf1..7dfc10724fc 100644 --- a/public/app/features/alerting/unified/RuleList.tsx +++ b/public/app/features/alerting/unified/RuleList.tsx @@ -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( () => {