From a9223adbedf5aa43a56f30c72bf7efc188c631d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Thu, 19 Jul 2018 21:48:05 +0200 Subject: [PATCH] fix(ui): better rendering and life cycle for annotations --- .../Grid/AlertGrid/AlertGroup/Alert/index.js | 1 + .../AlertGrid/AlertGroup/Annotation/index.js | 46 ++++++++++++------- .../AlertGrid/AlertGroup/GroupFooter/index.js | 26 ++++++----- .../Grid/AlertGrid/AlertGroup/index.js | 1 + 4 files changed, 46 insertions(+), 28 deletions(-) diff --git a/ui/src/Components/Grid/AlertGrid/AlertGroup/Alert/index.js b/ui/src/Components/Grid/AlertGrid/AlertGroup/Alert/index.js index 5368f7182..809d433bd 100644 --- a/ui/src/Components/Grid/AlertGrid/AlertGroup/Alert/index.js +++ b/ui/src/Components/Grid/AlertGrid/AlertGroup/Alert/index.js @@ -50,6 +50,7 @@ const Alert = observer( key={a.name} name={a.name} value={a.value} + afterUpdate={afterUpdate} /> ))} diff --git a/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/index.js b/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/index.js index f534292fa..6e1fabc68 100644 --- a/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/index.js +++ b/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/index.js @@ -17,18 +17,21 @@ const RenderNonLinkAnnotation = inject("alertStore")( static propTypes = { alertStore: PropTypes.object.isRequired, name: PropTypes.string.isRequired, - value: PropTypes.string.isRequired + value: PropTypes.string.isRequired, + afterUpdate: PropTypes.func.isRequired }; // keep state of this annotation visibility, this is controlled by user toggle = observable( { visible: true, - show() { - this.visible = true; + show(e) { + // don't action link clicks inside Linkify + if (e.target.nodeName !== "A") this.visible = true; }, - hide() { - this.visible = false; + hide(e) { + // don't action link clicks inside Linkify + if (e.target.nodeName !== "A") this.visible = false; } }, { @@ -43,6 +46,12 @@ const RenderNonLinkAnnotation = inject("alertStore")( this.toggle.visible = this.isVisible(); } + componentDidUpdate() { + const { afterUpdate } = this.props; + + afterUpdate(); + } + // determinate if this annotation should be hidden by default or not isVisible() { const { alertStore, name } = this.props; @@ -74,28 +83,31 @@ const RenderNonLinkAnnotation = inject("alertStore")( render() { const { name, value } = this.props; + const className = + "mr-1 mb-1 p-1 bg-light cursor-pointer d-inline-block rounded"; + if (!this.toggle.visible) { return ( - +
{name} - +
); } return ( - +
{name}: - {value} - + + {value} + +
); } } diff --git a/ui/src/Components/Grid/AlertGrid/AlertGroup/GroupFooter/index.js b/ui/src/Components/Grid/AlertGrid/AlertGroup/GroupFooter/index.js index 057fc38b2..8fa48fef5 100644 --- a/ui/src/Components/Grid/AlertGrid/AlertGroup/GroupFooter/index.js +++ b/ui/src/Components/Grid/AlertGrid/AlertGroup/GroupFooter/index.js @@ -11,23 +11,27 @@ const GroupFooter = observer( class GroupFooter extends Component { static propTypes = { group: PropTypes.object.isRequired, - alertmanagers: PropTypes.arrayOf(PropTypes.string).isRequired + alertmanagers: PropTypes.arrayOf(PropTypes.string).isRequired, + afterUpdate: PropTypes.func.isRequired }; render() { - const { group, alertmanagers } = this.props; + const { group, alertmanagers, afterUpdate } = this.props; return (
- {group.shared.annotations - .filter(a => a.isLink === false) - .map(a => ( - - ))} +
+ {group.shared.annotations + .filter(a => a.isLink === false) + .map(a => ( + + ))} +
{Object.entries(group.shared.labels).map(([name, value]) => ( ))} diff --git a/ui/src/Components/Grid/AlertGrid/AlertGroup/index.js b/ui/src/Components/Grid/AlertGrid/AlertGroup/index.js index a95805e77..513781724 100644 --- a/ui/src/Components/Grid/AlertGrid/AlertGroup/index.js +++ b/ui/src/Components/Grid/AlertGrid/AlertGroup/index.js @@ -174,6 +174,7 @@ const AlertGroup = observer( ) : null}