mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Misc tidy up
This commit is contained in:
parent
21a3f4817a
commit
df5c62b8ad
@ -195,7 +195,7 @@ export const SilencesEditor = ({ silenceId, alertManagerSourceName }: Props) =>
|
|||||||
return (
|
return (
|
||||||
<FormProvider {...formAPI}>
|
<FormProvider {...formAPI}>
|
||||||
<form onSubmit={handleSubmit(onSubmit)}>
|
<form onSubmit={handleSubmit(onSubmit)}>
|
||||||
<FieldSet label={`${silenceId ? 'Recreate silence' : 'Create silence'}`}>
|
<FieldSet label={silenceId ? 'Recreate silence' : 'Create silence'}>
|
||||||
<div className={cx(styles.flexRow, styles.silencePeriod)}>
|
<div className={cx(styles.flexRow, styles.silencePeriod)}>
|
||||||
<SilencePeriod />
|
<SilencePeriod />
|
||||||
<Field
|
<Field
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { css } from '@emotion/css';
|
import { css } from '@emotion/css';
|
||||||
import React, { useEffect, useMemo } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
|
|
||||||
import { dateMath, GrafanaTheme2 } from '@grafana/data';
|
import { dateMath, GrafanaTheme2 } from '@grafana/data';
|
||||||
import { CollapsableSection, Icon, Link, LinkButton, useStyles2, Stack, Alert } from '@grafana/ui';
|
import { CollapsableSection, Icon, Link, LinkButton, useStyles2, Stack, Alert } from '@grafana/ui';
|
||||||
@ -36,11 +36,22 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const SilencesTable = ({ alertManagerSourceName }: Props) => {
|
const SilencesTable = ({ alertManagerSourceName }: Props) => {
|
||||||
const [getAmAlerts, { data: alertManagerAlerts, isLoading: amAlertsIsLoading }] =
|
const { data: alertManagerAlerts, isLoading: amAlertsIsLoading } =
|
||||||
alertmanagerApi.endpoints.getAlertmanagerAlerts.useLazyQuery({ pollingInterval: SILENCES_POLL_INTERVAL_MS });
|
alertmanagerApi.endpoints.getAlertmanagerAlerts.useQuery(
|
||||||
const [getSilences, { data: silences = [], isLoading, error }] = alertSilencesApi.endpoints.getSilences.useLazyQuery({
|
{ amSourceName: alertManagerSourceName, filter: { silenced: true, active: true, inhibited: true } },
|
||||||
pollingInterval: SILENCES_POLL_INTERVAL_MS,
|
{ pollingInterval: SILENCES_POLL_INTERVAL_MS }
|
||||||
});
|
);
|
||||||
|
|
||||||
|
const {
|
||||||
|
data: silences = [],
|
||||||
|
isLoading,
|
||||||
|
error,
|
||||||
|
} = alertSilencesApi.endpoints.getSilences.useQuery(
|
||||||
|
{ datasourceUid: getDatasourceAPIUid(alertManagerSourceName) },
|
||||||
|
{
|
||||||
|
pollingInterval: SILENCES_POLL_INTERVAL_MS,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const { currentData: amFeatures } = featureDiscoveryApi.useDiscoverAmFeaturesQuery(
|
const { currentData: amFeatures } = featureDiscoveryApi.useDiscoverAmFeaturesQuery(
|
||||||
{ amSourceName: alertManagerSourceName ?? '' },
|
{ amSourceName: alertManagerSourceName ?? '' },
|
||||||
@ -51,11 +62,6 @@ const SilencesTable = ({ alertManagerSourceName }: Props) => {
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
(error as any)?.message?.includes('the Alertmanager is not configured') && amFeatures?.lazyConfigInit;
|
(error as any)?.message?.includes('the Alertmanager is not configured') && amFeatures?.lazyConfigInit;
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
getSilences({ datasourceUid: getDatasourceAPIUid(alertManagerSourceName) });
|
|
||||||
getAmAlerts({ amSourceName: alertManagerSourceName });
|
|
||||||
}, [alertManagerSourceName, getAmAlerts, getSilences]);
|
|
||||||
|
|
||||||
const styles = useStyles2(getStyles);
|
const styles = useStyles2(getStyles);
|
||||||
const [queryParams] = useQueryParams();
|
const [queryParams] = useQueryParams();
|
||||||
const filteredSilencesNotExpired = useFilteredSilences(silences, false);
|
const filteredSilencesNotExpired = useFilteredSilences(silences, false);
|
||||||
@ -119,11 +125,11 @@ const SilencesTable = ({ alertManagerSourceName }: Props) => {
|
|||||||
<Stack direction="column">
|
<Stack direction="column">
|
||||||
<SilencesFilter />
|
<SilencesFilter />
|
||||||
<Authorize actions={[AlertmanagerAction.CreateSilence]}>
|
<Authorize actions={[AlertmanagerAction.CreateSilence]}>
|
||||||
<div className={styles.topButtonContainer}>
|
<Stack justifyContent="end">
|
||||||
<LinkButton href={makeAMLink('/alerting/silence/new', alertManagerSourceName)} icon="plus">
|
<LinkButton href={makeAMLink('/alerting/silence/new', alertManagerSourceName)} icon="plus">
|
||||||
Add Silence
|
Add Silence
|
||||||
</LinkButton>
|
</LinkButton>
|
||||||
</div>
|
</Stack>
|
||||||
</Authorize>
|
</Authorize>
|
||||||
<SilenceList
|
<SilenceList
|
||||||
items={itemsNotExpired}
|
items={itemsNotExpired}
|
||||||
@ -213,11 +219,6 @@ const useFilteredSilences = (silences: Silence[], expired = false) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getStyles = (theme: GrafanaTheme2) => ({
|
const getStyles = (theme: GrafanaTheme2) => ({
|
||||||
topButtonContainer: css({
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'row',
|
|
||||||
justifyContent: 'flex-end',
|
|
||||||
}),
|
|
||||||
addNewSilence: css({
|
addNewSilence: css({
|
||||||
margin: theme.spacing(2, 0),
|
margin: theme.spacing(2, 0),
|
||||||
}),
|
}),
|
||||||
@ -237,13 +238,9 @@ const getStyles = (theme: GrafanaTheme2) => ({
|
|||||||
calloutIcon: css({
|
calloutIcon: css({
|
||||||
color: theme.colors.info.text,
|
color: theme.colors.info.text,
|
||||||
}),
|
}),
|
||||||
editButton: css({
|
|
||||||
marginLeft: theme.spacing(0.5),
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function useColumns(alertManagerSourceName: string) {
|
function useColumns(alertManagerSourceName: string) {
|
||||||
const styles = useStyles2(getStyles);
|
|
||||||
const [updateSupported, updateAllowed] = useAlertmanagerAbility(AlertmanagerAction.UpdateSilence);
|
const [updateSupported, updateAllowed] = useAlertmanagerAbility(AlertmanagerAction.UpdateSilence);
|
||||||
const [expireSilence] = alertSilencesApi.endpoints.expireSilence.useMutation();
|
const [expireSilence] = alertSilencesApi.endpoints.expireSilence.useMutation();
|
||||||
|
|
||||||
@ -312,10 +309,9 @@ function useColumns(alertManagerSourceName: string) {
|
|||||||
)}
|
)}
|
||||||
{silence.status.state !== 'expired' && (
|
{silence.status.state !== 'expired' && (
|
||||||
<ActionIcon
|
<ActionIcon
|
||||||
className={styles.editButton}
|
|
||||||
to={makeAMLink(`/alerting/silence/${silence.id}/edit`, alertManagerSourceName)}
|
to={makeAMLink(`/alerting/silence/${silence.id}/edit`, alertManagerSourceName)}
|
||||||
icon="pen"
|
icon="pen"
|
||||||
tooltip="edit"
|
tooltip="Edit"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
@ -325,6 +321,6 @@ function useColumns(alertManagerSourceName: string) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
return columns;
|
return columns;
|
||||||
}, [alertManagerSourceName, expireSilence, styles.editButton, updateAllowed, updateSupported]);
|
}, [alertManagerSourceName, expireSilence, updateAllowed, updateSupported]);
|
||||||
}
|
}
|
||||||
export default SilencesTable;
|
export default SilencesTable;
|
||||||
|
Loading…
Reference in New Issue
Block a user