From dd77596447960a181dafaefb8062ff9f52bf6a36 Mon Sep 17 00:00:00 2001 From: Rares Mardare Date: Fri, 16 Sep 2022 17:43:31 +0300 Subject: [PATCH] handle page refresh when switching teams --- grafana-plugin/src/GrafanaPluginRootPage.tsx | 2 +- .../src/components/PluginLink/PluginLink.tsx | 2 +- .../GrafanaTeamSelect/GrafanaTeamSelect.tsx | 11 +++++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/grafana-plugin/src/GrafanaPluginRootPage.tsx b/grafana-plugin/src/GrafanaPluginRootPage.tsx index 870c1cae..05742afd 100644 --- a/grafana-plugin/src/GrafanaPluginRootPage.tsx +++ b/grafana-plugin/src/GrafanaPluginRootPage.tsx @@ -135,7 +135,7 @@ export const Root = observer((props: AppRootProps) => { return ( - + ); diff --git a/grafana-plugin/src/components/PluginLink/PluginLink.tsx b/grafana-plugin/src/components/PluginLink/PluginLink.tsx index eef5374e..3a218c2e 100644 --- a/grafana-plugin/src/components/PluginLink/PluginLink.tsx +++ b/grafana-plugin/src/components/PluginLink/PluginLink.tsx @@ -11,7 +11,7 @@ interface PluginLinkProps extends LocationUpdate { disabled?: boolean; className?: string; wrap?: boolean; - children: any + children: any; } const cx = cn.bind(styles); diff --git a/grafana-plugin/src/containers/GrafanaTeamSelect/GrafanaTeamSelect.tsx b/grafana-plugin/src/containers/GrafanaTeamSelect/GrafanaTeamSelect.tsx index 1ca31a27..de290790 100644 --- a/grafana-plugin/src/containers/GrafanaTeamSelect/GrafanaTeamSelect.tsx +++ b/grafana-plugin/src/containers/GrafanaTeamSelect/GrafanaTeamSelect.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { SelectableValue } from '@grafana/data'; +import { getLocationSrv } from '@grafana/runtime'; import { HorizontalGroup, Icon, IconButton, Label, Tooltip } from '@grafana/ui'; import cn from 'classnames/bind'; import { observer } from 'mobx-react'; @@ -18,11 +19,14 @@ import styles from './GrafanaTeamSelect.module.css'; const cx = cn.bind(styles); -interface GrafanaTeamSelectProps {} +interface GrafanaTeamSelectProps { + currentPage: string; +} const GrafanaTeamSelect = observer((props: GrafanaTeamSelectProps) => { const store = useStore(); + const { currentPage } = props; const { userStore, grafanaTeamStore } = store; const grafanaTeams = grafanaTeamStore.getSearchResult(); const user = userStore.currentUser; @@ -33,7 +37,10 @@ const GrafanaTeamSelect = observer((props: GrafanaTeamSelectProps) => { const onTeamChange = async (teamId: GrafanaTeam['id']) => { await userStore.updateCurrentUser({ current_team: teamId }); - window.location.reload(); + + const queryParams = new URLSearchParams(); + queryParams.set('page', currentPage); + window.location.search = queryParams.toString(); }; return document.getElementsByClassName('page-header__inner')[0]