Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exporter drawer when clicking export all Grafana managed alerts
- Loading branch information
1 parent
268e6aa
commit b7f910a
Showing
4 changed files
with
74 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} | ||
/> | ||
); | ||
} |