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 React, { FC } from 'react'; |
||||||
import { GrafanaTheme } from '@grafana/data'; |
|
||||||
import { useStyles } from '@grafana/ui'; |
|
||||||
import { css } from '@emotion/css'; |
import { css } from '@emotion/css'; |
||||||
|
import { TagList, useStyles2 } from '@grafana/ui'; |
||||||
import { Matcher } from 'app/plugins/datasource/alertmanager/types'; |
import { Matcher } from 'app/plugins/datasource/alertmanager/types'; |
||||||
import { AlertLabel } from '../AlertLabel'; |
|
||||||
import { matcherToOperator } from '../../utils/alertmanager'; |
import { matcherToOperator } from '../../utils/alertmanager'; |
||||||
|
|
||||||
type MatchersProps = { matchers: Matcher[]; onRemoveLabel?(index: number): void }; |
type MatchersProps = { matchers: Matcher[] }; |
||||||
|
|
||||||
export const Matchers = ({ matchers, onRemoveLabel }: MatchersProps) => { |
|
||||||
const styles = useStyles(getStyles); |
|
||||||
|
|
||||||
const removeLabel = useCallback( |
|
||||||
(index: number) => { |
|
||||||
if (!!onRemoveLabel) { |
|
||||||
onRemoveLabel(index); |
|
||||||
} |
|
||||||
}, |
|
||||||
[onRemoveLabel] |
|
||||||
); |
|
||||||
|
|
||||||
|
export const Matchers: FC<MatchersProps> = ({ matchers }) => { |
||||||
|
const styles = useStyles2(getStyles); |
||||||
return ( |
return ( |
||||||
<div className={styles.wrapper}> |
<div> |
||||||
{matchers.map((matcher, index) => { |
<TagList |
||||||
const { name, value } = matcher; |
className={styles.tags} |
||||||
return ( |
tags={matchers.map((matcher) => `${matcher.name}${matcherToOperator(matcher)}${matcher.value}`)} |
||||||
<AlertLabel |
/> |
||||||
key={`${name}-${value}-${index}`} |
|
||||||
labelKey={name} |
|
||||||
value={value} |
|
||||||
operator={matcherToOperator(matcher)} |
|
||||||
onRemoveLabel={!!onRemoveLabel ? () => removeLabel(index) : undefined} |
|
||||||
/> |
|
||||||
); |
|
||||||
})} |
|
||||||
</div> |
</div> |
||||||
); |
); |
||||||
}; |
}; |
||||||
|
|
||||||
const getStyles = (theme: GrafanaTheme) => ({ |
const getStyles = () => ({ |
||||||
wrapper: css` |
tags: css` |
||||||
& > * { |
justify-content: flex-start; |
||||||
margin-top: ${theme.spacing.xs}; |
|
||||||
margin-right: ${theme.spacing.xs}; |
|
||||||
} |
|
||||||
padding-bottom: ${theme.spacing.xs}; |
|
||||||
`,
|
`,
|
||||||
}); |
}); |
||||||
|
Loading…
Reference in new issue