-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Alerting: Add export drawer when exporting all Grafana managed alerts (…
…#74846) * Add export formats drawer when exporting contact points * Add 'export by format' drawer in policies (root policy) * Add test for showing export policies button * Add tests for Policy.tsx * Add tests for export functionality in receivers * Add exporter drawer for receivers * Fix prettier warnings * Allow HCL only for alert rules exports * Add tests for Policies * Fix tests * Refactor: Update ExportProviders types for limiting the avaliable export formats when using GrafanaExportDrawer * Delete unused shouldShowExportOption method and tests * Add exporter drawer when clicking export all Grafana managed alerts * Fix test * fix prettier * lint --------- Co-authored-by: Gilles De Mey <gilles.de.mey@gmail.com>
- Loading branch information
1 parent
39dbd98
commit 942c477
Showing
4 changed files
with
69 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
public/app/features/alerting/unified/components/export/GrafanaRulesExporter.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React, { useState } from 'react'; | ||
|
||
import { LoadingPlaceholder } from '@grafana/ui'; | ||
|
||
import { alertRuleApi } from '../../api/alertRuleApi'; | ||
|
||
import { FileExportPreview } from './FileExportPreview'; | ||
import { GrafanaExportDrawer } from './GrafanaExportDrawer'; | ||
import { allGrafanaExportProviders, ExportFormats } from './providers'; | ||
|
||
interface GrafanaRulesExporterProps { | ||
onClose: () => void; | ||
} | ||
|
||
export function GrafanaRulesExporter({ onClose }: GrafanaRulesExporterProps) { | ||
const [activeTab, setActiveTab] = useState<ExportFormats>('yaml'); | ||
|
||
return ( | ||
<GrafanaExportDrawer | ||
activeTab={activeTab} | ||
onTabChange={setActiveTab} | ||
onClose={onClose} | ||
formatProviders={Object.values(allGrafanaExportProviders)} | ||
> | ||
<GrafanaRulesExportPreview exportFormat={activeTab} onClose={onClose} /> | ||
</GrafanaExportDrawer> | ||
); | ||
} | ||
|
||
interface GrafanaRulesExportPreviewProps { | ||
exportFormat: ExportFormats; | ||
onClose: () => void; | ||
} | ||
|
||
function GrafanaRulesExportPreview({ exportFormat, onClose }: GrafanaRulesExportPreviewProps) { | ||
const { currentData: rulesDefinition = '', isFetching } = alertRuleApi.useExportRulesQuery({ | ||
format: exportFormat, | ||
}); | ||
|
||
const downloadFileName = `alert-rules-${new Date().getTime()}`; | ||
|
||
if (isFetching) { | ||
return <LoadingPlaceholder text="Loading...." />; | ||
} | ||
|
||
return ( | ||
<FileExportPreview | ||
format={exportFormat} | ||
textDefinition={rulesDefinition} | ||
downloadFileName={downloadFileName} | ||
onClose={onClose} | ||
/> | ||
); | ||
} |