mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: persist error dismissal to localstorage (#43406)
This commit is contained in:
@@ -1,16 +1,17 @@
|
|||||||
import { css } from '@emotion/css';
|
import { css } from '@emotion/css';
|
||||||
import { DataSourceInstanceSettings, GrafanaTheme2 } from '@grafana/data';
|
import { DataSourceInstanceSettings, GrafanaTheme2 } from '@grafana/data';
|
||||||
import { Alert, Button, useStyles2 } from '@grafana/ui';
|
import { Alert, Button, Tooltip, useStyles2 } from '@grafana/ui';
|
||||||
import { SerializedError } from '@reduxjs/toolkit';
|
import { SerializedError } from '@reduxjs/toolkit';
|
||||||
import pluralize from 'pluralize';
|
import pluralize from 'pluralize';
|
||||||
import React, { useMemo, ReactElement, useState } from 'react';
|
import React, { useMemo, ReactElement, useState, FC } from 'react';
|
||||||
|
import { useLocalStorage } from 'react-use';
|
||||||
import { useUnifiedAlertingSelector } from '../../hooks/useUnifiedAlertingSelector';
|
import { useUnifiedAlertingSelector } from '../../hooks/useUnifiedAlertingSelector';
|
||||||
import { getRulesDataSources, GRAFANA_RULES_SOURCE_NAME } from '../../utils/datasource';
|
import { getRulesDataSources, GRAFANA_RULES_SOURCE_NAME } from '../../utils/datasource';
|
||||||
import { isRulerNotSupportedResponse } from '../../utils/rules';
|
import { isRulerNotSupportedResponse } from '../../utils/rules';
|
||||||
|
|
||||||
export function RuleListErrors(): ReactElement {
|
export function RuleListErrors(): ReactElement {
|
||||||
const [expanded, setExpanded] = useState(false);
|
const [expanded, setExpanded] = useState(false);
|
||||||
const [closed, setClosed] = useState(false);
|
const [closed, setClosed] = useLocalStorage('grafana.unifiedalerting.hideErrors', false);
|
||||||
const promRuleRequests = useUnifiedAlertingSelector((state) => state.promRules);
|
const promRuleRequests = useUnifiedAlertingSelector((state) => state.promRules);
|
||||||
const rulerRuleRequests = useUnifiedAlertingSelector((state) => state.rulerRules);
|
const rulerRuleRequests = useUnifiedAlertingSelector((state) => state.rulerRules);
|
||||||
const styles = useStyles2(getStyles);
|
const styles = useStyles2(getStyles);
|
||||||
@@ -63,6 +64,9 @@ export function RuleListErrors(): ReactElement {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
{!!errors.length && closed && (
|
||||||
|
<ErrorSummaryButton count={errors.length} onClick={() => setClosed((closed) => !closed)} />
|
||||||
|
)}
|
||||||
{!!errors.length && !closed && (
|
{!!errors.length && !closed && (
|
||||||
<Alert
|
<Alert
|
||||||
data-testid="cloud-rulessource-errors"
|
data-testid="cloud-rulessource-errors"
|
||||||
@@ -93,8 +97,31 @@ export function RuleListErrors(): ReactElement {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface ErrorSummaryProps {
|
||||||
|
count: number;
|
||||||
|
onClick: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ErrorSummaryButton: FC<ErrorSummaryProps> = ({ count, onClick }) => {
|
||||||
|
const styles = useStyles2(getStyles);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.floatRight}>
|
||||||
|
<Tooltip content="Show all errors">
|
||||||
|
<Button fill="text" variant="destructive" icon="exclamation-triangle" onClick={onClick}>
|
||||||
|
{count > 1 ? <>{count} errors</> : <>1 error</>}
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
const getStyles = (theme: GrafanaTheme2) => ({
|
const getStyles = (theme: GrafanaTheme2) => ({
|
||||||
moreButton: css`
|
moreButton: css`
|
||||||
padding: 0;
|
padding: 0;
|
||||||
`,
|
`,
|
||||||
|
floatRight: css`
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
`,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user