From defae434bae6b97ac9b87f58690d7991b9d4db0b Mon Sep 17 00:00:00 2001 From: Rares Mardare Date: Mon, 13 Mar 2023 15:01:59 +0200 Subject: [PATCH] Prevent redirecting to Integrations if you navigated away to a different screen (#1449) # What this PR does A while ago we fixed a bug where each time you navigated to Integrations, moving to a different a screen would have redirected you back to the Integrations screen if the escalation chain didn't complete loading before you changed the screens. Added a check for `isMounted` which should prevent this bug to appear again in the future. --- CHANGELOG.md | 1 + .../src/pages/integrations/Integrations.tsx | 17 +++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c0a5bfb..1e7e23bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fix bug with override creation ([1515](https://github.com/grafana/oncall/pull/1515)) +- Fixed redirection issue on integrations screen ## v1.1.35 (2023-03-09) diff --git a/grafana-plugin/src/pages/integrations/Integrations.tsx b/grafana-plugin/src/pages/integrations/Integrations.tsx index 5c05fddc..26197e02 100644 --- a/grafana-plugin/src/pages/integrations/Integrations.tsx +++ b/grafana-plugin/src/pages/integrations/Integrations.tsx @@ -51,18 +51,23 @@ class Integrations extends React.Component errorData: initErrorDataState(), }; + private isMounted: boolean; private alertReceiveChanneltoPoll: { [key: string]: number } = {}; private alertReceiveChannelTimerId: ReturnType; async componentDidMount() { + this.isMounted = false; this.update().then(() => this.parseQueryParams(true)); } + componentWillUnmount() { + this.isMounted = false; + clearInterval(this.alertReceiveChannelTimerId); + } + componentDidUpdate(prevProps: Readonly): void { if (prevProps.match.params.id && !this.props.match.params.id) { - this.setState({ errorData: initErrorDataState() }, () => { - this.parseQueryParams(); - }); + this.parseQueryParams(); } } @@ -70,7 +75,7 @@ class Integrations extends React.Component const { store, history } = this.props; store.selectedAlertReceiveChannel = alertReceiveChannelId; - if (shouldRedirect) { + if (shouldRedirect && this.isMounted) { history.push(`${PLUGIN_ROOT}/integrations/${alertReceiveChannelId || ''}`); } }; @@ -123,10 +128,6 @@ class Integrations extends React.Component return store.alertReceiveChannelStore.updateItems(); }; - componentWillUnmount() { - clearInterval(this.alertReceiveChannelTimerId); - } - render() { const { store,