From acfae1a663eeb24fd8710d70031f238c3b650afc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Thu, 14 May 2020 11:21:29 +0100 Subject: [PATCH] fix(ui): fix menu close on trigger click --- .../AlertGrid/AlertGroup/Alert/AlertMenu.js | 96 +++++++++---------- .../Alert/__snapshots__/index.test.js.snap | 80 ++++++++-------- .../AlertGroup/GroupHeader/GroupMenu.js | 92 +++++++++--------- .../Components/NavBar/FilterInput/History.js | 91 +++++++++--------- .../__snapshots__/index.test.js.snap | 40 ++++---- 5 files changed, 201 insertions(+), 198 deletions(-) diff --git a/ui/src/Components/Grid/AlertGrid/AlertGroup/Alert/AlertMenu.js b/ui/src/Components/Grid/AlertGrid/AlertGroup/Alert/AlertMenu.js index 58665f272..dd4b013ea 100644 --- a/ui/src/Components/Grid/AlertGrid/AlertGroup/Alert/AlertMenu.js +++ b/ui/src/Components/Grid/AlertGrid/AlertGroup/Alert/AlertMenu.js @@ -1,4 +1,4 @@ -import React, { useRef, useEffect } from "react"; +import React, { useRef } from "react"; import PropTypes from "prop-types"; import { useObserver, useLocalStore } from "mobx-react"; @@ -40,18 +40,11 @@ const MenuContent = ({ alertStore, silenceFormStore, }) => { - const ref = useRef(null); - useOnClickOutside(ref, afterClick); - - useEffect(() => { - popperRef(ref.current); - }, [popperRef]); - return (
@@ -117,48 +110,53 @@ const AlertMenu = ({ }, })); + const ref = useRef(null); + useOnClickOutside(ref, collapse.hide); + return useObserver(() => ( - - - {({ ref }) => ( - - - {alert.startsAt} - - )} - - - - {({ placement, ref, style }) => ( - + + + + {({ ref }) => ( + + + {alert.startsAt} + )} - - - + + + + {({ placement, ref, style }) => ( + + )} + + + + )); }; AlertMenu.propTypes = { 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 1afe7d473..78cdf0f09 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 @@ -56,27 +56,29 @@ exports[` matches snapshot when inhibited 1`] = `
- - + - - - - + + + + +
matches snapshot with showAlertmanagers=false showReceiver=fa
- - + - - - - + + + + +
{ - const ref = useRef(null); - useOnClickOutside(ref, afterClick); - - useEffect(() => { - popperRef(ref.current); - }, [popperRef]); - let groupFilters = Object.keys(group.labels).map((name) => FormatQuery(name, QueryOperators.Equal, group.labels[name]) ); @@ -65,7 +58,7 @@ const MenuContent = ({
@@ -123,46 +116,51 @@ const GroupMenu = ({ }, })); + const ref = useRef(null); + useOnClickOutside(ref, collapse.hide); + return useObserver(() => ( - - - {({ ref }) => ( - - - - )} - - - - {({ placement, ref, style }) => ( - + + + + {({ ref }) => ( + + + )} - - - + + + + {({ placement, ref, style }) => ( + + )} + + + + )); }; GroupMenu.propTypes = { diff --git a/ui/src/Components/NavBar/FilterInput/History.js b/ui/src/Components/NavBar/FilterInput/History.js index 4672515ab..77d18ed1f 100644 --- a/ui/src/Components/NavBar/FilterInput/History.js +++ b/ui/src/Components/NavBar/FilterInput/History.js @@ -62,17 +62,10 @@ const HistoryMenu = ({ afterClick, onClear, }) => { - const ref = useRef(null); - useOnClickOutside(ref, afterClick); - - useEffect(() => { - popperRef(ref.current); - }, [popperRef]); - return (
@@ -201,51 +194,59 @@ const History = ({ alertStore, settingsStore }) => { } }); + const ref = useRef(null); + useOnClickOutside(ref, collapse.hide); + return useObserver(() => ( // data-filters is there to register filters for observation in mobx // it needs to be using full filter object to notice changes to // name & value but ignore hits // using it this way will force re-render on every change, which is // needed to keep track of all filter changes - ReduceFilter(f)) - .join(" ")} + - - {({ ref }) => ( - - )} - - - - {({ placement, ref, style }) => ( - { - history.filters = []; - }} - alertStore={alertStore} - settingsStore={settingsStore} - afterClick={collapse.hide} - /> + ReduceFilter(f)) + .join(" ")} + > + + {({ ref }) => ( + )} - - - + + + + {({ placement, ref, style }) => ( + { + history.filters = []; + }} + alertStore={alertStore} + settingsStore={settingsStore} + afterClick={collapse.hide} + /> + )} + + + + )); }; History.propTypes = { diff --git a/ui/src/Components/NavBar/FilterInput/__snapshots__/index.test.js.snap b/ui/src/Components/NavBar/FilterInput/__snapshots__/index.test.js.snap index 047783663..6e179bd11 100644 --- a/ui/src/Components/NavBar/FilterInput/__snapshots__/index.test.js.snap +++ b/ui/src/Components/NavBar/FilterInput/__snapshots__/index.test.js.snap @@ -45,27 +45,29 @@ exports[` matches snapshot on default render 1`] = `
- + + + + +
"