From 70e69fda093478b69f3b74e87e9beff4ff3f0a89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Tue, 9 Jul 2019 22:08:31 +0100 Subject: [PATCH] feat(ui): add a modal with labels overview Fixes #766 --- demo/karma.yaml | 2 +- .../__snapshots__/index.test.js.snap | 34 ++++ .../Labels/LabelWithPercent/index.js | 69 ++++++++ .../Labels/LabelWithPercent/index.scss | 4 + .../Labels/LabelWithPercent/index.test.js | 63 +++++++ ui/src/Components/NavBar/index.js | 11 +- ui/src/Components/NavBar/index.test.js | 2 +- .../OverviewModal/OverviewModalContent.js | 81 +++++++++ .../OverviewModalContent.test.js | 66 ++++++++ .../OverviewModalContent.test.js.snap | 154 ++++++++++++++++++ ui/src/Components/OverviewModal/index.js | 84 ++++++++++ ui/src/Components/OverviewModal/index.scss | 10 ++ ui/src/Components/OverviewModal/index.test.js | 96 +++++++++++ ui/src/Stores/AlertStore.js | 2 +- 14 files changed, 667 insertions(+), 11 deletions(-) create mode 100644 ui/src/Components/Labels/LabelWithPercent/__snapshots__/index.test.js.snap create mode 100644 ui/src/Components/Labels/LabelWithPercent/index.js create mode 100644 ui/src/Components/Labels/LabelWithPercent/index.scss create mode 100644 ui/src/Components/Labels/LabelWithPercent/index.test.js create mode 100644 ui/src/Components/OverviewModal/OverviewModalContent.js create mode 100644 ui/src/Components/OverviewModal/OverviewModalContent.test.js create mode 100644 ui/src/Components/OverviewModal/__snapshots__/OverviewModalContent.test.js.snap create mode 100644 ui/src/Components/OverviewModal/index.js create mode 100644 ui/src/Components/OverviewModal/index.scss create mode 100644 ui/src/Components/OverviewModal/index.test.js diff --git a/demo/karma.yaml b/demo/karma.yaml index 1f69348a7..2edca4575 100644 --- a/demo/karma.yaml +++ b/demo/karma.yaml @@ -53,7 +53,7 @@ labels: color: "#ff220c" log: config: false - level: warning + level: debug sentry: private: https://84a9ef37a6ed4fdb80e9ea2310d1ed26:8c6ee6f0ab02406482ff4b4e824e2c27@sentry.io/1279017 public: https://84a9ef37a6ed4fdb80e9ea2310d1ed26@sentry.io/1279017 diff --git a/ui/src/Components/Labels/LabelWithPercent/__snapshots__/index.test.js.snap b/ui/src/Components/Labels/LabelWithPercent/__snapshots__/index.test.js.snap new file mode 100644 index 000000000..d87242fe6 --- /dev/null +++ b/ui/src/Components/Labels/LabelWithPercent/__snapshots__/index.test.js.snap @@ -0,0 +1,34 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` matches snapshot 1`] = ` +" +
+ + + 25 + + + foo: + + + bar + + +
+
+
+
+
+" +`; diff --git a/ui/src/Components/Labels/LabelWithPercent/index.js b/ui/src/Components/Labels/LabelWithPercent/index.js new file mode 100644 index 000000000..c4f135e95 --- /dev/null +++ b/ui/src/Components/Labels/LabelWithPercent/index.js @@ -0,0 +1,69 @@ +import React from "react"; +import PropTypes from "prop-types"; + +import { inject, observer } from "mobx-react"; + +import { AlertStore } from "Stores/AlertStore"; +import { TooltipWrapper } from "Components/TooltipWrapper"; +import { BaseLabel } from "Components/Labels/BaseLabel"; + +import "./index.scss"; + +const LabelWithPercent = inject("alertStore")( + observer( + class FilteringLabel extends BaseLabel { + static propTypes = { + alertStore: PropTypes.instanceOf(AlertStore).isRequired, + name: PropTypes.string.isRequired, + value: PropTypes.string.isRequired, + hits: PropTypes.number.isRequired, + percent: PropTypes.number.isRequired + }; + + render() { + const { name, value, hits, percent } = this.props; + + let cs = this.getClassAndStyle( + name, + value, + "components-label-with-hover mb-0 pl-0 text-left" + ); + + const progressBarBg = + percent > 66 + ? "bg-danger" + : percent > 66 + ? "bg-warning" + : "bg-success"; + + return ( + + this.handleClick(e)} + > + + {hits} + + {name}:{" "} + {value} + +
+
+
+ + ); + } + } + ) +); + +export { LabelWithPercent }; diff --git a/ui/src/Components/Labels/LabelWithPercent/index.scss b/ui/src/Components/Labels/LabelWithPercent/index.scss new file mode 100644 index 000000000..c6589aa4d --- /dev/null +++ b/ui/src/Components/Labels/LabelWithPercent/index.scss @@ -0,0 +1,4 @@ +.components-labelWithPercent-percent { + padding-top: 0.25rem; + padding-bottom: 0.25rem; +} diff --git a/ui/src/Components/Labels/LabelWithPercent/index.test.js b/ui/src/Components/Labels/LabelWithPercent/index.test.js new file mode 100644 index 000000000..8d2a8e18f --- /dev/null +++ b/ui/src/Components/Labels/LabelWithPercent/index.test.js @@ -0,0 +1,63 @@ +import React from "react"; + +import { mount } from "enzyme"; + +import toDiffableHtml from "diffable-html"; + +import { AlertStore, NewUnappliedFilter } from "Stores/AlertStore"; + +import { LabelWithPercent } from "."; + +let alertStore; + +beforeEach(() => { + alertStore = new AlertStore([]); +}); + +const MountedLabelWithPercent = (name, value) => { + return mount( + + ).find(".components-label"); +}; + +const RenderAndClick = (name, value, clickOptions) => { + const tree = MountedLabelWithPercent(name, value); + tree.find(".components-label").simulate("click", clickOptions || {}); +}; + +describe("", () => { + it("matches snapshot", () => { + const tree = mount( + + ); + expect(toDiffableHtml(tree.html())).toMatchSnapshot(); + }); + + it("calling onClick() adds a new filter 'foo=bar'", () => { + RenderAndClick("foo", "bar"); + expect(alertStore.filters.values).toHaveLength(1); + expect(alertStore.filters.values).toContainEqual( + NewUnappliedFilter("foo=bar") + ); + }); + + it("calling onClick() while holding Alt key adds a new filter 'foo!=bar'", () => { + RenderAndClick("foo", "bar", { altKey: true }); + expect(alertStore.filters.values).toHaveLength(1); + expect(alertStore.filters.values).toContainEqual( + NewUnappliedFilter("foo!=bar") + ); + }); +}); diff --git a/ui/src/Components/NavBar/index.js b/ui/src/Components/NavBar/index.js index 5d7a05a20..d6d50daf8 100644 --- a/ui/src/Components/NavBar/index.js +++ b/ui/src/Components/NavBar/index.js @@ -8,13 +8,12 @@ import ReactResizeDetector from "react-resize-detector"; import IdleTimer from "react-idle-timer"; -import Flash from "react-reveal/Flash"; - import { AlertStore } from "Stores/AlertStore"; import { Settings } from "Stores/Settings"; import { SilenceFormStore } from "Stores/SilenceFormStore"; import { IsMobile } from "Common/Device"; import { NavBarSlide } from "Components/Animations/NavBarSlide"; +import { OverviewModal } from "Components/OverviewModal"; import { MainModal } from "Components/MainModal"; import { SilenceModal } from "Components/SilenceModal"; import { FetchIndicator } from "./FetchIndicator"; @@ -141,12 +140,8 @@ const NavBar = observer( >