mirror of https://github.com/grafana/grafana
Alerting: Colorize labels and matchers (#46678)
* Replace AlertLabel with TagsList * left align labels * restart dronepull/47139/head
parent
54b1d88c44
commit
32ad1199e1
@ -1,49 +1,25 @@ |
||||
import React, { useCallback } from 'react'; |
||||
import { GrafanaTheme } from '@grafana/data'; |
||||
import { useStyles } from '@grafana/ui'; |
||||
import React, { FC } from 'react'; |
||||
import { css } from '@emotion/css'; |
||||
import { TagList, useStyles2 } from '@grafana/ui'; |
||||
import { Matcher } from 'app/plugins/datasource/alertmanager/types'; |
||||
import { AlertLabel } from '../AlertLabel'; |
||||
import { matcherToOperator } from '../../utils/alertmanager'; |
||||
|
||||
type MatchersProps = { matchers: Matcher[]; onRemoveLabel?(index: number): void }; |
||||
|
||||
export const Matchers = ({ matchers, onRemoveLabel }: MatchersProps) => { |
||||
const styles = useStyles(getStyles); |
||||
|
||||
const removeLabel = useCallback( |
||||
(index: number) => { |
||||
if (!!onRemoveLabel) { |
||||
onRemoveLabel(index); |
||||
} |
||||
}, |
||||
[onRemoveLabel] |
||||
); |
||||
type MatchersProps = { matchers: Matcher[] }; |
||||
|
||||
export const Matchers: FC<MatchersProps> = ({ matchers }) => { |
||||
const styles = useStyles2(getStyles); |
||||
return ( |
||||
<div className={styles.wrapper}> |
||||
{matchers.map((matcher, index) => { |
||||
const { name, value } = matcher; |
||||
return ( |
||||
<AlertLabel |
||||
key={`${name}-${value}-${index}`} |
||||
labelKey={name} |
||||
value={value} |
||||
operator={matcherToOperator(matcher)} |
||||
onRemoveLabel={!!onRemoveLabel ? () => removeLabel(index) : undefined} |
||||
/> |
||||
); |
||||
})} |
||||
<div> |
||||
<TagList |
||||
className={styles.tags} |
||||
tags={matchers.map((matcher) => `${matcher.name}${matcherToOperator(matcher)}${matcher.value}`)} |
||||
/> |
||||
</div> |
||||
); |
||||
}; |
||||
|
||||
const getStyles = (theme: GrafanaTheme) => ({ |
||||
wrapper: css` |
||||
& > * { |
||||
margin-top: ${theme.spacing.xs}; |
||||
margin-right: ${theme.spacing.xs}; |
||||
} |
||||
padding-bottom: ${theme.spacing.xs}; |
||||
const getStyles = () => ({ |
||||
tags: css` |
||||
justify-content: flex-start; |
||||
`,
|
||||
}); |
||||
|
Loading…
Reference in new issue