forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Alerting: Add View YAML button for Grafana/provisioned rules (grafana…
…#71983) * Add View YAML button for grafana/provisioned rules * Address PR comments
- Loading branch information
Showing
5 changed files
with
138 additions
and
27 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
74 changes: 74 additions & 0 deletions
74
public/app/features/alerting/unified/components/rule-editor/GrafanaRuleInspector.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,74 @@ | ||
import { dump } from 'js-yaml'; | ||
import React, { useMemo, useState } from 'react'; | ||
import AutoSizer from 'react-virtualized-auto-sizer'; | ||
|
||
import { CodeEditor, Drawer, useStyles2 } from '@grafana/ui'; | ||
|
||
import { alertRuleApi } from '../../api/alertRuleApi'; | ||
|
||
import { drawerStyles, RuleInspectorSubtitle, yamlTabStyle } from './RuleInspector'; | ||
|
||
interface Props { | ||
onClose: () => void; | ||
alertUid: string; | ||
} | ||
|
||
export const GrafanaRuleInspector = ({ onClose, alertUid }: Props) => { | ||
const [activeTab, setActiveTab] = useState('yaml'); | ||
|
||
const styles = useStyles2(drawerStyles); | ||
|
||
return ( | ||
<Drawer | ||
title="Inspect Alert rule" | ||
subtitle={ | ||
<div className={styles.subtitle}> | ||
<RuleInspectorSubtitle setActiveTab={setActiveTab} activeTab={activeTab} /> | ||
</div> | ||
} | ||
onClose={onClose} | ||
> | ||
{activeTab === 'yaml' && <GrafanaInspectorYamlTab alertUid={alertUid} />} | ||
</Drawer> | ||
); | ||
}; | ||
|
||
const { useExportRuleQuery } = alertRuleApi; | ||
|
||
interface YamlTabProps { | ||
alertUid: string; | ||
} | ||
|
||
const GrafanaInspectorYamlTab = ({ alertUid }: YamlTabProps) => { | ||
const styles = useStyles2(yamlTabStyle); | ||
|
||
const { currentData: ruleYamlConfig, isLoading } = useExportRuleQuery({ uid: alertUid, format: 'yaml' }); | ||
|
||
const yamlRule = useMemo(() => dump(ruleYamlConfig), [ruleYamlConfig]); | ||
|
||
if (isLoading) { | ||
return <div>Loading...</div>; | ||
} | ||
|
||
return ( | ||
<> | ||
<div className={styles.content}> | ||
<AutoSizer disableWidth> | ||
{({ height }) => ( | ||
<CodeEditor | ||
width="100%" | ||
height={height} | ||
language="yaml" | ||
value={yamlRule} | ||
monacoOptions={{ | ||
minimap: { | ||
enabled: false, | ||
}, | ||
}} | ||
/> | ||
)} | ||
</AutoSizer> | ||
</div> | ||
</> | ||
); | ||
}; |
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