From bd0a32ec8abebadec66e9139431ad35cdb9afb1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Wed, 13 Mar 2019 18:06:15 +0000 Subject: [PATCH] chore(ui): hide annotation details only when clicking on the - icon This changes handling of annotation hide/show clicks. Right now annotation details are toggled when anything inside the annotation div is clicked. With this change showing annotation details stays the same (click anywhere), but hiding those details only works when clicking the minus icon. A tooltip was added and cursor changes to pointer only when hoovering over clickable elements. Fixes #518 --- .../Alert/__snapshots__/index.test.js.snap | 178 ++++++++++------- .../__snapshots__/index.test.js.snap | 80 ++++---- .../AlertGrid/AlertGroup/Annotation/index.js | 49 +++-- .../AlertGroup/Annotation/index.test.js | 15 +- .../__snapshots__/index.test.js.snap | 186 ++++++++++-------- 5 files changed, 289 insertions(+), 219 deletions(-) diff --git a/ui/src/Components/Grid/AlertGrid/AlertGroup/Alert/__snapshots__/index.test.js.snap b/ui/src/Components/Grid/AlertGrid/AlertGroup/Alert/__snapshots__/index.test.js.snap index 464c2d83b..b86ba39b4 100644 --- a/ui/src/Components/Grid/AlertGrid/AlertGroup/Alert/__snapshots__/index.test.js.snap +++ b/ui/src/Components/Grid/AlertGrid/AlertGroup/Alert/__snapshots__/index.test.js.snap @@ -4,44 +4,58 @@ exports[` matches snapshot when inhibited 1`] = ` "
  • -
    - - +
    + - - - - help: - - - some long text - + + + + + help: + + + some long text + +
    -
    - - +
    + - - - hidden + + + + hidden +
    matches snapshot when inhibited 1`] = `
    @@ -92,7 +106,7 @@ exports[` matches snapshot when inhibited 1`] = `
    @@ -107,7 +121,7 @@ exports[` matches snapshot when inhibited 1`] = `
    @@ -148,44 +162,58 @@ exports[` matches snapshot with showAlertmanagers=false showReceiver=fa "
  • -
    - - +
    + - - - - help: - - - some long text - + + + + + help: + + + some long text + +
    -
    - - +
    + - - - hidden + + + + hidden +
    matches snapshot with showAlertmanagers=false showReceiver=fa
    @@ -228,7 +256,7 @@ exports[` matches snapshot with showAlertmanagers=false showReceiver=fa
    diff --git a/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/__snapshots__/index.test.js.snap b/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/__snapshots__/index.test.js.snap index f16c8350f..4f4798608 100644 --- a/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/__snapshots__/index.test.js.snap +++ b/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/__snapshots__/index.test.js.snap @@ -28,49 +28,59 @@ exports[` matches snapshot 1`] = ` exports[` matches snapshot when visible=false 1`] = ` " -
    - - +
    + - - - foo + + + + foo +
    " `; exports[` matches snapshot when visible=true 1`] = ` " -
    - - +
    + - - - - foo: - - - some long text - + + + + + foo: + + + some long text + +
    " `; diff --git a/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/index.js b/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/index.js index aa297d949..88fa805a9 100644 --- a/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/index.js +++ b/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/index.js @@ -12,6 +12,7 @@ import { faSearchPlus } from "@fortawesome/free-solid-svg-icons/faSearchPlus"; import { faSearchMinus } from "@fortawesome/free-solid-svg-icons/faSearchMinus"; import { AlertStore } from "Stores/AlertStore"; +import { TooltipWrapper } from "Components/TooltipWrapper"; import "./index.css"; @@ -36,8 +37,7 @@ const RenderNonLinkAnnotation = inject("alertStore")( this.visible = true; }, hide(e) { - // don't action link clicks inside Linkify - if (e.target.nodeName !== "A") this.visible = false; + this.visible = false; } }, { @@ -62,30 +62,41 @@ const RenderNonLinkAnnotation = inject("alertStore")( const { name, value } = this.props; const className = - "mr-1 mb-1 p-1 bg-light cursor-pointer d-inline-block rounded components-grid-annotation text-break"; + "mr-1 mb-1 p-1 bg-light d-inline-block rounded components-grid-annotation text-break"; if (!this.toggle.visible) { return ( -
    - - {name} -
    + +
    + + {name} +
    +
    ); } return ( -
    - - {name}: - - {value} - -
    + +
    + + {name}: + + {value} + +
    +
    ); } } diff --git a/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/index.test.js b/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/index.test.js index cddd63457..098ad0fcb 100644 --- a/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/index.test.js +++ b/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/index.test.js @@ -98,27 +98,20 @@ describe("", () => { expect(link.text()).toBe("http://example.com"); }); - it("clicking on + icon hides the value", () => { + it("clicking on - icon hides the value", () => { const tree = MountedNonLinkAnnotation(true); expect(tree.html()).toMatch(/fa-search-minus/); expect(tree.html()).toMatch(/some long text/); - tree.find("div").simulate("click"); + tree.find(".fa-search-minus").simulate("click"); expect(tree.html()).toMatch(/fa-search-plus/); expect(tree.html()).not.toMatch(/some long text/); }); - it("clicking on a link inside annotation doesn't hide the value", () => { - const tree = MountedNonLinkAnnotationContainingLink(true); - expect(tree.html()).toMatch(/fa-search-minus/); - tree.find("a").simulate("click"); - expect(tree.html()).toMatch(/fa-search-minus/); - }); - - it("clicking on - icon shows the value", () => { + it("clicking on + icon shows the value", () => { const tree = MountedNonLinkAnnotation(false); expect(tree.html()).toMatch(/fa-search-plus/); expect(tree.html()).not.toMatch(/some long text/); - tree.find("div").simulate("click"); + tree.find(".components-grid-annotation").simulate("click"); expect(tree.html()).toMatch(/fa-search-minus/); expect(tree.html()).toMatch(/some long text/); }); diff --git a/ui/src/Components/Grid/AlertGrid/AlertGroup/GroupFooter/__snapshots__/index.test.js.snap b/ui/src/Components/Grid/AlertGrid/AlertGroup/GroupFooter/__snapshots__/index.test.js.snap index eb12ad65a..f1b578125 100644 --- a/ui/src/Components/Grid/AlertGrid/AlertGroup/GroupFooter/__snapshots__/index.test.js.snap +++ b/ui/src/Components/Grid/AlertGrid/AlertGroup/GroupFooter/__snapshots__/index.test.js.snap @@ -4,50 +4,64 @@ exports[` matches snapshot 1`] = ` "