diff --git a/ui/src/Components/OverviewModal/index.js b/ui/src/Components/OverviewModal/index.js index 28a97b11a..d274d7526 100644 --- a/ui/src/Components/OverviewModal/index.js +++ b/ui/src/Components/OverviewModal/index.js @@ -1,8 +1,7 @@ -import React, { Component } from "react"; +import React from "react"; import PropTypes from "prop-types"; -import { observer } from "mobx-react"; -import { observable, action } from "mobx"; +import { observer, useLocalStore } from "mobx-react"; import Flash from "react-reveal/Flash"; @@ -20,65 +19,51 @@ const OverviewModalContent = React.lazy(() => })) ); -const OverviewModal = observer( - class OverviewModal extends Component { - static propTypes = { - alertStore: PropTypes.instanceOf(AlertStore).isRequired, - }; +const OverviewModal = observer(({ alertStore }) => { + const toggle = useLocalStore(() => ({ + show: false, + toggle() { + this.show = !this.show; + }, + hide() { + this.show = false; + }, + })); - toggle = observable( - { - show: false, - toggle() { - this.show = !this.show; - }, - hide() { - this.show = false; - }, - }, - { toggle: action.bound, hide: action.bound } - ); - - render() { - const { alertStore } = this.props; - - return ( - - - - - {alertStore.info.totalAlerts} - - - - + + + - - - - } - > - - - - - ); - } - } -); + {alertStore.info.totalAlerts} + + + + + + + + } + > + + + + + ); +}); +OverviewModal.propTypes = { + alertStore: PropTypes.instanceOf(AlertStore).isRequired, +}; export { OverviewModal }; diff --git a/ui/src/Components/OverviewModal/index.test.js b/ui/src/Components/OverviewModal/index.test.js index 14c3228ca..7fc6b8294 100644 --- a/ui/src/Components/OverviewModal/index.test.js +++ b/ui/src/Components/OverviewModal/index.test.js @@ -57,15 +57,14 @@ describe("", () => { expect(tree.find(".modal-title")).toHaveLength(0); }); - it("hides the modal when hide() is called", () => { + it("hides the modal when button.close is clicked", () => { const tree = MountedOverviewModal(); const toggle = tree.find("div.navbar-brand"); toggle.simulate("click"); expect(tree.find(".modal-title").text()).toBe("Overview"); - const instance = tree.instance(); - instance.toggle.hide(); + tree.find("button.close").simulate("click"); jest.runOnlyPendingTimers(); tree.update(); expect(tree.find("OverviewModalContent")).toHaveLength(0);