diff --git a/ui/src/App.tsx b/ui/src/App.tsx index f3e7abd5f..2f50957d0 100644 --- a/ui/src/App.tsx +++ b/ui/src/App.tsx @@ -1,7 +1,5 @@ import React, { Component } from "react"; -import { Provider } from "mobx-react"; - import { AlertStore, DecodeLocationSearch } from "Stores/AlertStore"; import { Settings } from "Stores/Settings"; import { SilenceFormStore } from "Stores/SilenceFormStore"; @@ -92,13 +90,11 @@ class App extends Component { settingsStore={this.settingsStore} silenceFormStore={this.silenceFormStore} /> - - - + { const MountedFetchPauser = () => { return mount( - - -
- - + +
+ ); }; diff --git a/ui/src/Components/Grid/AlertGrid/AlertGroup/Alert/AlertMenu.js b/ui/src/Components/Grid/AlertGrid/AlertGroup/Alert/AlertMenu.js index 3c9965c78..54ff70107 100644 --- a/ui/src/Components/Grid/AlertGrid/AlertGroup/Alert/AlertMenu.js +++ b/ui/src/Components/Grid/AlertGrid/AlertGroup/Alert/AlertMenu.js @@ -45,7 +45,7 @@ const MenuContent = onClickOutside( silenceFormStore }) => { return ( - +
{ return mount( - - - - ).find("AlertMenu"); + + ); }; describe("", () => { @@ -65,18 +61,16 @@ describe("", () => { const MountedMenuContent = group => { return mount( - - - + ); }; diff --git a/ui/src/Components/Grid/AlertGrid/AlertGroup/Alert/index.js b/ui/src/Components/Grid/AlertGrid/AlertGroup/Alert/index.js index cd8e45c11..a9f71693c 100644 --- a/ui/src/Components/Grid/AlertGrid/AlertGroup/Alert/index.js +++ b/ui/src/Components/Grid/AlertGrid/AlertGroup/Alert/index.js @@ -86,6 +86,7 @@ const Alert = observer( value={a.value} visible={a.visible} afterUpdate={afterUpdate} + alertStore={alertStore} /> ))}
@@ -106,7 +107,12 @@ const Alert = observer( ) : null} {Object.entries(alert.labels).map(([name, value]) => ( - + ))} {showAlertmanagers ? alert.alertmanager.map(am => ( @@ -114,6 +120,7 @@ const Alert = observer( key={am.name} name={StaticLabels.AlertManager} value={am.name} + alertStore={alertStore} /> )) : null} @@ -121,6 +128,7 @@ const Alert = observer( ) : null} {alert.annotations diff --git a/ui/src/Components/Grid/AlertGrid/AlertGroup/Alert/index.test.js b/ui/src/Components/Grid/AlertGrid/AlertGroup/Alert/index.test.js index 9e107b427..65256e2b6 100644 --- a/ui/src/Components/Grid/AlertGrid/AlertGroup/Alert/index.test.js +++ b/ui/src/Components/Grid/AlertGrid/AlertGroup/Alert/index.test.js @@ -1,7 +1,5 @@ import React from "react"; -import { Provider } from "mobx-react"; - import { mount } from "enzyme"; import { advanceTo, clear } from "jest-date-mock"; @@ -53,18 +51,16 @@ const MockedAlert = () => { const MountedAlert = (alert, group, showAlertmanagers, showReceiver) => { return mount( - - - + ); }; diff --git a/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/index.js b/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/index.js index 841cec469..361b0db8a 100644 --- a/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/index.js +++ b/ui/src/Components/Grid/AlertGrid/AlertGroup/Annotation/index.js @@ -2,7 +2,7 @@ import React, { Component } from "react"; import PropTypes from "prop-types"; import { observable, action } from "mobx"; -import { observer, inject } from "mobx-react"; +import { observer } from "mobx-react"; import Linkify from "react-linkify"; @@ -18,93 +18,91 @@ import { TooltipWrapper } from "Components/TooltipWrapper"; import "./index.css"; -const RenderNonLinkAnnotation = inject("alertStore")( - observer( - class RenderNonLinkAnnotation extends Component { - static propTypes = { - alertStore: PropTypes.instanceOf(AlertStore).isRequired, - name: PropTypes.string.isRequired, - value: PropTypes.string.isRequired, - visible: PropTypes.bool.isRequired, - afterUpdate: PropTypes.func.isRequired - }; +const RenderNonLinkAnnotation = observer( + class RenderNonLinkAnnotation extends Component { + static propTypes = { + alertStore: PropTypes.instanceOf(AlertStore).isRequired, + name: PropTypes.string.isRequired, + value: PropTypes.string.isRequired, + visible: PropTypes.bool.isRequired, + afterUpdate: PropTypes.func.isRequired + }; - // keep state of this annotation visibility, this is controlled by user - toggle = observable( - { - visible: true, - show(e) { - // Linkify only handles value, no need to check for links of - // collapsed annotation - this.visible = true; - }, - hide(e) { - this.visible = false; - } + // keep state of this annotation visibility, this is controlled by user + toggle = observable( + { + visible: true, + show(e) { + // Linkify only handles value, no need to check for links of + // collapsed annotation + this.visible = true; }, - { - show: action.bound, - hide: action.bound + hide(e) { + this.visible = false; } - ); - - constructor(props) { - super(props); - - this.toggle.visible = props.visible; + }, + { + show: action.bound, + hide: action.bound } + ); - componentDidUpdate() { - const { afterUpdate } = this.props; + constructor(props) { + super(props); - afterUpdate(); - } + this.toggle.visible = props.visible; + } - render() { - const { name, value } = this.props; + componentDidUpdate() { + const { afterUpdate } = this.props; - const className = - "mr-1 mb-1 p-1 bg-light d-inline-block rounded components-grid-annotation text-break mw-100"; + afterUpdate(); + } - if (!this.toggle.visible) { - return ( - -
- - {name} -
-
- ); - } + render() { + const { name, value } = this.props; + const className = + "mr-1 mb-1 p-1 bg-light d-inline-block rounded components-grid-annotation text-break mw-100"; + + if (!this.toggle.visible) { return ( - -
- - {name}: - - - {value} - - + +
+ + {name}
); } + + return ( + +
+ + {name}: + + + {value} + + +
+
+ ); } - ) + } ); const RenderLinkAnnotation = ({ name, value }) => { diff --git a/ui/src/Components/Grid/AlertGrid/AlertGroup/GroupFooter/index.js b/ui/src/Components/Grid/AlertGrid/AlertGroup/GroupFooter/index.js index 62288f65b..47a7a9ae9 100644 --- a/ui/src/Components/Grid/AlertGrid/AlertGroup/GroupFooter/index.js +++ b/ui/src/Components/Grid/AlertGrid/AlertGroup/GroupFooter/index.js @@ -44,20 +44,31 @@ const GroupFooter = observer( value={a.value} visible={a.visible} afterUpdate={afterUpdate} + alertStore={alertStore} /> ))}
{Object.entries(group.shared.labels).map(([name, value]) => ( - + ))} {alertmanagers.map(am => ( ))} - + {group.shared.annotations .filter(a => a.isLink === true) .map(a => ( diff --git a/ui/src/Components/Grid/AlertGrid/AlertGroup/GroupFooter/index.test.js b/ui/src/Components/Grid/AlertGrid/AlertGroup/GroupFooter/index.test.js index 8da6f29e3..38d749e07 100644 --- a/ui/src/Components/Grid/AlertGrid/AlertGroup/GroupFooter/index.test.js +++ b/ui/src/Components/Grid/AlertGrid/AlertGroup/GroupFooter/index.test.js @@ -1,7 +1,5 @@ import React from "react"; -import { Provider } from "mobx-react"; - import { mount } from "enzyme"; import toDiffableHtml from "diffable-html"; @@ -59,15 +57,13 @@ afterEach(() => { const MountedGroupFooter = () => { return mount( - - - + ); }; diff --git a/ui/src/Components/Grid/AlertGrid/AlertGroup/GroupHeader/GroupMenu.js b/ui/src/Components/Grid/AlertGrid/AlertGroup/GroupHeader/GroupMenu.js index 6d7ebe3bc..f27c9a63c 100644 --- a/ui/src/Components/Grid/AlertGrid/AlertGroup/GroupHeader/GroupMenu.js +++ b/ui/src/Components/Grid/AlertGrid/AlertGroup/GroupHeader/GroupMenu.js @@ -57,7 +57,7 @@ const MenuContent = onClickOutside( const groupLink = `${baseURL}?${FormatAlertsQ(groupFilters)}`; return ( - +
{ return mount( - - - + ).find("GroupMenu"); }; @@ -67,17 +63,15 @@ describe("", () => { const MountedMenuContent = group => { return mount( - - - + ); }; diff --git a/ui/src/Components/Grid/AlertGrid/AlertGroup/GroupHeader/index.js b/ui/src/Components/Grid/AlertGrid/AlertGroup/GroupHeader/index.js index caa3a0520..a95b676df 100644 --- a/ui/src/Components/Grid/AlertGrid/AlertGroup/GroupHeader/index.js +++ b/ui/src/Components/Grid/AlertGrid/AlertGroup/GroupHeader/index.js @@ -60,6 +60,7 @@ const GroupHeader = observer( key={name} name={name} value={group.labels[name]} + alertStore={alertStore} /> ))} @@ -69,18 +70,21 @@ const GroupHeader = observer( value="unprocessed" counter={group.stateCount.unprocessed} themed={themedCounters} + alertStore={alertStore} /> { const MountedAlertGroup = (afterUpdate, showAlertmanagers) => { return mount( - - - + ); }; diff --git a/ui/src/Components/Grid/index.stories.js b/ui/src/Components/Grid/index.stories.js index e5d488106..84e7eaf8f 100644 --- a/ui/src/Components/Grid/index.stories.js +++ b/ui/src/Components/Grid/index.stories.js @@ -2,8 +2,6 @@ import React from "react"; import { storiesOf } from "@storybook/react"; -import { Provider } from "mobx-react"; - import moment from "moment"; import { MockAlert, MockAlertGroup } from "__mocks__/Alerts.js"; @@ -173,12 +171,10 @@ storiesOf("Grid", module) alertStore.data.groups = groups; return ( - - - + ); }); diff --git a/ui/src/Components/Labels/FilteringCounterBadge/index.js b/ui/src/Components/Labels/FilteringCounterBadge/index.js index af4d9524a..200b11582 100644 --- a/ui/src/Components/Labels/FilteringCounterBadge/index.js +++ b/ui/src/Components/Labels/FilteringCounterBadge/index.js @@ -1,7 +1,7 @@ import React from "react"; import PropTypes from "prop-types"; -import { inject, observer } from "mobx-react"; +import { observer } from "mobx-react"; import Flash from "react-reveal/Flash"; @@ -12,53 +12,51 @@ import { BaseLabel } from "Components/Labels/BaseLabel"; // Same as FilteringLabel but for labels that are counters (usually @state) // and only renders a pill badge with the counter, it doesn't render anything // if the counter is 0 -const FilteringCounterBadge = inject("alertStore")( - observer( - class FilteringCounterBadge extends BaseLabel { - static propTypes = { - alertStore: PropTypes.instanceOf(AlertStore).isRequired, - name: PropTypes.string.isRequired, - value: PropTypes.string.isRequired, - counter: PropTypes.number.isRequired, - themed: PropTypes.bool.isRequired - }; +const FilteringCounterBadge = observer( + class FilteringCounterBadge extends BaseLabel { + static propTypes = { + alertStore: PropTypes.instanceOf(AlertStore).isRequired, + name: PropTypes.string.isRequired, + value: PropTypes.string.isRequired, + counter: PropTypes.number.isRequired, + themed: PropTypes.bool.isRequired + }; - render() { - const { name, value, counter, themed } = this.props; + render() { + const { name, value, counter, themed } = this.props; - if (counter === 0) return null; + if (counter === 0) return null; - const cs = this.getClassAndStyle( - name, - value, - "badge-pill components-label-with-hover" - ); + const cs = this.getClassAndStyle( + name, + value, + "badge-pill components-label-with-hover" + ); - return ( - - - this.handleClick(e)} - > - {counter} - - - - ); - } + return ( + + + this.handleClick(e)} + > + {counter} + + + + ); } - ) + } ); export { FilteringCounterBadge }; diff --git a/ui/src/Components/Labels/FilteringLabel/index.js b/ui/src/Components/Labels/FilteringLabel/index.js index 0ff595df0..724cb16e5 100644 --- a/ui/src/Components/Labels/FilteringLabel/index.js +++ b/ui/src/Components/Labels/FilteringLabel/index.js @@ -1,38 +1,36 @@ import React from "react"; -import { inject, observer } from "mobx-react"; +import { observer } from "mobx-react"; import { TooltipWrapper } from "Components/TooltipWrapper"; import { BaseLabel } from "Components/Labels/BaseLabel"; // Renders a label element that after clicking adds current label as a filter -const FilteringLabel = inject("alertStore")( - observer( - class FilteringLabel extends BaseLabel { - render() { - const { name, value } = this.props; +const FilteringLabel = observer( + class FilteringLabel extends BaseLabel { + render() { + const { name, value } = this.props; - let cs = this.getClassAndStyle( - name, - value, - "components-label-with-hover" - ); + let cs = this.getClassAndStyle( + name, + value, + "components-label-with-hover" + ); - return ( - - this.handleClick(e)} - > - {name}:{" "} - {value} - - - ); - } + return ( + + this.handleClick(e)} + > + {name}:{" "} + {value} + + + ); } - ) + } ); export { FilteringLabel }; diff --git a/ui/src/Components/Labels/LabelWithPercent/index.js b/ui/src/Components/Labels/LabelWithPercent/index.js index a5e1f5430..f072a3b5b 100644 --- a/ui/src/Components/Labels/LabelWithPercent/index.js +++ b/ui/src/Components/Labels/LabelWithPercent/index.js @@ -1,7 +1,7 @@ import React from "react"; import PropTypes from "prop-types"; -import { inject, observer } from "mobx-react"; +import { observer } from "mobx-react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faTimes } from "@fortawesome/free-solid-svg-icons/faTimes"; @@ -12,86 +12,80 @@ import { BaseLabel } from "Components/Labels/BaseLabel"; import "./index.scss"; -const LabelWithPercent = inject("alertStore")( - observer( - class LabelWithPercent 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, - offset: PropTypes.number.isRequired, - isActive: PropTypes.bool.isRequired - }; +const LabelWithPercent = observer( + class LabelWithPercent 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, + offset: PropTypes.number.isRequired, + isActive: PropTypes.bool.isRequired + }; - removeFromFilters = () => { - const { alertStore, name, value } = this.props; - alertStore.filters.removeFilter( - FormatQuery(name, QueryOperators.Equal, value) - ); - }; + removeFromFilters = () => { + const { alertStore, name, value } = this.props; + alertStore.filters.removeFilter( + FormatQuery(name, QueryOperators.Equal, value) + ); + }; - render() { - const { name, value, hits, percent, offset, isActive } = this.props; + render() { + const { name, value, hits, percent, offset, isActive } = this.props; - let cs = this.getClassAndStyle( - name, - value, - "components-label-with-hover mb-0 pl-0 text-left" - ); + let cs = this.getClassAndStyle( + name, + value, + "components-label-with-hover mb-0 pl-0 text-left" + ); - const progressBarBg = - percent > 66 - ? "bg-danger" - : percent > 33 - ? "bg-warning" - : "bg-success"; + const progressBarBg = + percent > 66 ? "bg-danger" : percent > 33 ? "bg-warning" : "bg-success"; - return ( -
- - - {hits} - - this.handleClick(e)}> - {name}:{" "} - {value} - - {isActive ? ( - - ) : null} + return ( +
+ + + {hits} -
- {offset === 0 ? null : ( -
- )} + this.handleClick(e)}> + {name}:{" "} + {value} + + {isActive ? ( + + ) : null} + +
+ {offset === 0 ? null : (
-
+ )} +
- ); - } +
+ ); } - ) + } ); export { LabelWithPercent }; diff --git a/ui/src/Components/Labels/StaticLabel/index.js b/ui/src/Components/Labels/StaticLabel/index.js index 91f9a6bd4..76ee9aab4 100644 --- a/ui/src/Components/Labels/StaticLabel/index.js +++ b/ui/src/Components/Labels/StaticLabel/index.js @@ -1,27 +1,25 @@ import React from "react"; -import { inject, observer } from "mobx-react"; +import { observer } from "mobx-react"; import { BaseLabel } from "Components/Labels/BaseLabel"; // Renders a static label element, no click actions, no hover -const StaticLabel = inject("alertStore")( - observer( - class FilteringLabel extends BaseLabel { - render() { - const { name, value } = this.props; +const StaticLabel = observer( + class FilteringLabel extends BaseLabel { + render() { + const { name, value } = this.props; - let cs = this.getClassAndStyle(name, value); + let cs = this.getClassAndStyle(name, value); - return ( - - {name}:{" "} - {value} - - ); - } + return ( + + {name}:{" "} + {value} + + ); } - ) + } ); export { StaticLabel }; diff --git a/ui/src/Components/OverviewModal/OverviewModalContent.js b/ui/src/Components/OverviewModal/OverviewModalContent.js index f27239f75..ace404127 100644 --- a/ui/src/Components/OverviewModal/OverviewModalContent.js +++ b/ui/src/Components/OverviewModal/OverviewModalContent.js @@ -26,6 +26,7 @@ const TableRows = observer(({ alertStore, nameStats }) => {nameStats.values.slice(0, 9).map((valueStats, i) => ( // https://github.com/airbnb/enzyme/issues/1213 mount( - - - + ); diff --git a/ui/src/Components/OverviewModal/index.js b/ui/src/Components/OverviewModal/index.js index 2263870e2..f7737babe 100644 --- a/ui/src/Components/OverviewModal/index.js +++ b/ui/src/Components/OverviewModal/index.js @@ -1,7 +1,7 @@ import React, { Component } from "react"; import PropTypes from "prop-types"; -import { observer, Provider } from "mobx-react"; +import { observer } from "mobx-react"; import { observable, action } from "mobx"; import Flash from "react-reveal/Flash"; @@ -70,13 +70,11 @@ const OverviewModal = observer( } > - - - + diff --git a/ui/src/Components/SilenceModal/Browser/index.js b/ui/src/Components/SilenceModal/Browser/index.js index 0dfbb7c58..2183aa207 100644 --- a/ui/src/Components/SilenceModal/Browser/index.js +++ b/ui/src/Components/SilenceModal/Browser/index.js @@ -2,7 +2,7 @@ import React, { Component } from "react"; import PropTypes from "prop-types"; import { observable, action } from "mobx"; -import { observer, Provider } from "mobx-react"; +import { observer } from "mobx-react"; import { debounce } from "lodash"; @@ -232,23 +232,21 @@ const Browser = observer( ) : ( - - {this.dataSource.silences - .slice( - (this.pagination.activePage - 1) * this.maxPerPage, - this.pagination.activePage * this.maxPerPage - ) - .map(silence => ( - - ))} - + {this.dataSource.silences + .slice( + (this.pagination.activePage - 1) * this.maxPerPage, + this.pagination.activePage * this.maxPerPage + ) + .map(silence => ( + + ))} {this.dataSource.silences.length > this.maxPerPage ? (