mirror of https://github.com/grafana/grafana
Alerting: Add export drawer with yaml and json formats, in policies and contact points view. (#74613)
* 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 * Use useAlertmanagerAbility hook to check if canReadSecrets * Update snapshot for useAbilities test * Fix prettier * Convert decrypt to boolean * Fix prettier * Rename CanReadSecrets action to DecryptSecrets * Update the string value for DecryptSecrets * Fix snapshor for useAbilities after renaming the can-read-secretspull/74846/head
parent
40c12c17bf
commit
5484e0a2d5
@ -0,0 +1,53 @@ |
||||
import React, { useState } from 'react'; |
||||
|
||||
import { LoadingPlaceholder } from '@grafana/ui'; |
||||
|
||||
import { alertRuleApi } from '../../api/alertRuleApi'; |
||||
|
||||
import { FileExportPreview } from './FileExportPreview'; |
||||
import { GrafanaExportDrawer } from './GrafanaExportDrawer'; |
||||
import { ExportFormats, jsonAndYamlGrafanaExportProviders } from './providers'; |
||||
interface GrafanaPoliciesPreviewProps { |
||||
exportFormat: ExportFormats; |
||||
onClose: () => void; |
||||
} |
||||
|
||||
const GrafanaPoliciesExporterPreview = ({ exportFormat, onClose }: GrafanaPoliciesPreviewProps) => { |
||||
const { currentData: policiesDefinition = '', isFetching } = alertRuleApi.useExportPoliciesQuery({ |
||||
format: exportFormat, |
||||
}); |
||||
|
||||
const downloadFileName = `policies-${new Date().getTime()}`; |
||||
|
||||
if (isFetching) { |
||||
return <LoadingPlaceholder text="Loading...." />; |
||||
} |
||||
|
||||
return ( |
||||
<FileExportPreview |
||||
format={exportFormat} |
||||
textDefinition={policiesDefinition} |
||||
downloadFileName={downloadFileName} |
||||
onClose={onClose} |
||||
/> |
||||
); |
||||
}; |
||||
|
||||
interface GrafanaPoliciesExporterProps { |
||||
onClose: () => void; |
||||
} |
||||
|
||||
export const GrafanaPoliciesExporter = ({ onClose }: GrafanaPoliciesExporterProps) => { |
||||
const [activeTab, setActiveTab] = useState<ExportFormats>('yaml'); |
||||
|
||||
return ( |
||||
<GrafanaExportDrawer |
||||
activeTab={activeTab} |
||||
onTabChange={setActiveTab} |
||||
onClose={onClose} |
||||
formatProviders={jsonAndYamlGrafanaExportProviders} |
||||
> |
||||
<GrafanaPoliciesExporterPreview exportFormat={activeTab} onClose={onClose} /> |
||||
</GrafanaExportDrawer> |
||||
); |
||||
}; |
||||
@ -0,0 +1,70 @@ |
||||
import React, { useState } from 'react'; |
||||
|
||||
import { LoadingPlaceholder } from '@grafana/ui'; |
||||
|
||||
import { alertRuleApi } from '../../api/alertRuleApi'; |
||||
|
||||
import { FileExportPreview } from './FileExportPreview'; |
||||
import { GrafanaExportDrawer } from './GrafanaExportDrawer'; |
||||
import { ExportFormats, jsonAndYamlGrafanaExportProviders } from './providers'; |
||||
|
||||
interface GrafanaReceiverExportPreviewProps { |
||||
exportFormat: ExportFormats; |
||||
onClose: () => void; |
||||
receiverName: string; |
||||
decrypt: boolean; |
||||
} |
||||
|
||||
const GrafanaReceiverExportPreview = ({ |
||||
receiverName, |
||||
decrypt, |
||||
exportFormat, |
||||
onClose, |
||||
}: GrafanaReceiverExportPreviewProps) => { |
||||
const { currentData: receiverDefinition = '', isFetching } = alertRuleApi.useExportReceiverQuery({ |
||||
receiverName: receiverName, |
||||
decrypt: decrypt, |
||||
format: exportFormat, |
||||
}); |
||||
|
||||
const downloadFileName = `cp-${receiverName}-${new Date().getTime()}`; |
||||
|
||||
if (isFetching) { |
||||
return <LoadingPlaceholder text="Loading...." />; |
||||
} |
||||
|
||||
return ( |
||||
<FileExportPreview |
||||
format={exportFormat} |
||||
textDefinition={receiverDefinition} |
||||
downloadFileName={downloadFileName} |
||||
onClose={onClose} |
||||
/> |
||||
); |
||||
}; |
||||
|
||||
interface GrafanaReceiverExporterProps { |
||||
onClose: () => void; |
||||
receiverName: string; |
||||
decrypt: boolean; |
||||
} |
||||
|
||||
export const GrafanaReceiverExporter = ({ onClose, receiverName, decrypt }: GrafanaReceiverExporterProps) => { |
||||
const [activeTab, setActiveTab] = useState<ExportFormats>('yaml'); |
||||
|
||||
return ( |
||||
<GrafanaExportDrawer |
||||
activeTab={activeTab} |
||||
onTabChange={setActiveTab} |
||||
onClose={onClose} |
||||
formatProviders={jsonAndYamlGrafanaExportProviders} |
||||
> |
||||
<GrafanaReceiverExportPreview |
||||
receiverName={receiverName} |
||||
decrypt={decrypt} |
||||
exportFormat={activeTab} |
||||
onClose={onClose} |
||||
/> |
||||
</GrafanaExportDrawer> |
||||
); |
||||
}; |
||||
@ -0,0 +1,57 @@ |
||||
import React, { useState } from 'react'; |
||||
|
||||
import { LoadingPlaceholder } from '@grafana/ui'; |
||||
|
||||
import { alertRuleApi } from '../../api/alertRuleApi'; |
||||
|
||||
import { FileExportPreview } from './FileExportPreview'; |
||||
import { GrafanaExportDrawer } from './GrafanaExportDrawer'; |
||||
import { ExportFormats, jsonAndYamlGrafanaExportProviders } from './providers'; |
||||
|
||||
interface GrafanaReceiversExportPreviewProps { |
||||
exportFormat: ExportFormats; |
||||
onClose: () => void; |
||||
decrypt: boolean; |
||||
} |
||||
|
||||
const GrafanaReceiversExportPreview = ({ decrypt, exportFormat, onClose }: GrafanaReceiversExportPreviewProps) => { |
||||
const { currentData: receiverDefinition = '', isFetching } = alertRuleApi.useExportReceiversQuery({ |
||||
decrypt: decrypt, |
||||
format: exportFormat, |
||||
}); |
||||
|
||||
const downloadFileName = `contact-points-${new Date().getTime()}`; |
||||
|
||||
if (isFetching) { |
||||
return <LoadingPlaceholder text="Loading...." />; |
||||
} |
||||
|
||||
return ( |
||||
<FileExportPreview |
||||
format={exportFormat} |
||||
textDefinition={receiverDefinition} |
||||
downloadFileName={downloadFileName} |
||||
onClose={onClose} |
||||
/> |
||||
); |
||||
}; |
||||
|
||||
interface GrafanaReceiversExporterProps { |
||||
onClose: () => void; |
||||
decrypt: boolean; |
||||
} |
||||
|
||||
export const GrafanaReceiversExporter = ({ onClose, decrypt }: GrafanaReceiversExporterProps) => { |
||||
const [activeTab, setActiveTab] = useState<ExportFormats>('yaml'); |
||||
|
||||
return ( |
||||
<GrafanaExportDrawer |
||||
activeTab={activeTab} |
||||
onTabChange={setActiveTab} |
||||
onClose={onClose} |
||||
formatProviders={jsonAndYamlGrafanaExportProviders} |
||||
> |
||||
<GrafanaReceiversExportPreview decrypt={decrypt} exportFormat={activeTab} onClose={onClose} /> |
||||
</GrafanaExportDrawer> |
||||
); |
||||
}; |
||||
Loading…
Reference in new issue