diff --git a/grafana-plugin/src/components/NotFoundInTeam/WrongTeamStub.tsx b/grafana-plugin/src/components/NotFoundInTeam/WrongTeamStub.tsx index c28d8eb8..269c07a8 100644 --- a/grafana-plugin/src/components/NotFoundInTeam/WrongTeamStub.tsx +++ b/grafana-plugin/src/components/NotFoundInTeam/WrongTeamStub.tsx @@ -17,14 +17,17 @@ export interface WrongTeamStubProps { className?: string; objectName: string; pageName: string; - currentTeam?: string; switchToTeam?: { name: string; id: string }; wrongTeamNoPermissions?: boolean; } const WrongTeamStub: FC = (props) => { const store = useStore(); - const { objectName, pageName, currentTeam, switchToTeam, className, wrongTeamNoPermissions } = props; + + const currentTeamId = store.userStore.currentUser?.current_team; + const currentTeam = store.grafanaTeamStore.items[currentTeamId]?.name; + + const { objectName, pageName, switchToTeam, wrongTeamNoPermissions } = props; const onTeamChange = async (teamId: GrafanaTeam['id']) => { await store.userStore.updateCurrentUser({ current_team: teamId }); diff --git a/grafana-plugin/src/models/alert_receive_channel/alert_receive_channel.ts b/grafana-plugin/src/models/alert_receive_channel/alert_receive_channel.ts index 57b6f332..ab8808cf 100644 --- a/grafana-plugin/src/models/alert_receive_channel/alert_receive_channel.ts +++ b/grafana-plugin/src/models/alert_receive_channel/alert_receive_channel.ts @@ -71,7 +71,7 @@ export class AlertReceiveChannelStore extends BaseStore { } @action - async loadItem(id: AlertReceiveChannel['id'], skipErrorHandling: boolean = false): Promise { + async loadItem(id: AlertReceiveChannel['id'], skipErrorHandling = false): Promise { const alertReceiveChannel = await this.getById(id, skipErrorHandling); this.items = { diff --git a/grafana-plugin/src/models/base_store.ts b/grafana-plugin/src/models/base_store.ts index 90e6a76e..56cebb15 100644 --- a/grafana-plugin/src/models/base_store.ts +++ b/grafana-plugin/src/models/base_store.ts @@ -13,8 +13,8 @@ export default class BaseStore { this.rootStore = rootStore; } - onApiError(error: any, skipErrorHandling: boolean = false) { - if (skipErrorHandling) throw error + onApiError(error: any, skipErrorHandling = false) { + if (skipErrorHandling) {throw error} if (error.response.status >= 400 && error.response.status < 500) { const payload = error.response.data; @@ -39,7 +39,7 @@ export default class BaseStore { } @action - async getById(id: string, skipErrorHandling: boolean = false) { + async getById(id: string, skipErrorHandling = false) { return await makeRequest(`${this.path}${id}/`, { method: 'GET', }).catch((error) => this.onApiError(error, skipErrorHandling)); diff --git a/grafana-plugin/src/models/escalation_chain/escalation_chain.ts b/grafana-plugin/src/models/escalation_chain/escalation_chain.ts index dde0b3b4..a64ed47b 100644 --- a/grafana-plugin/src/models/escalation_chain/escalation_chain.ts +++ b/grafana-plugin/src/models/escalation_chain/escalation_chain.ts @@ -23,7 +23,7 @@ export class EscalationChainStore extends BaseStore { } @action - async loadItem(id: EscalationChain['id'], skipErrorHandling: boolean = false): Promise { + async loadItem(id: EscalationChain['id'], skipErrorHandling = false): Promise { const escalationChain = await this.getById(id, skipErrorHandling); this.items = { diff --git a/grafana-plugin/src/models/outgoing_webhook/outgoing_webhook.ts b/grafana-plugin/src/models/outgoing_webhook/outgoing_webhook.ts index a5e70b59..d064fa38 100644 --- a/grafana-plugin/src/models/outgoing_webhook/outgoing_webhook.ts +++ b/grafana-plugin/src/models/outgoing_webhook/outgoing_webhook.ts @@ -20,7 +20,7 @@ export class OutgoingWebhookStore extends BaseStore { } @action - async loadItem(id: OutgoingWebhook['id'], skipErrorHandling: boolean = false): Promise { + async loadItem(id: OutgoingWebhook['id'], skipErrorHandling = false): Promise { const outgoingWebhook = await this.getById(id, skipErrorHandling); this.items = { diff --git a/grafana-plugin/src/models/schedule/schedule.ts b/grafana-plugin/src/models/schedule/schedule.ts index c424882a..a2b66973 100644 --- a/grafana-plugin/src/models/schedule/schedule.ts +++ b/grafana-plugin/src/models/schedule/schedule.ts @@ -26,7 +26,7 @@ export class ScheduleStore extends BaseStore { } @action - async loadItem(id: Schedule['id'], skipErrorHandling: boolean = false): Promise { + async loadItem(id: Schedule['id'], skipErrorHandling = false): Promise { const schedule = await this.getById(id, skipErrorHandling); this.items = { diff --git a/grafana-plugin/src/models/user/user.ts b/grafana-plugin/src/models/user/user.ts index c1961844..22dbd1f7 100644 --- a/grafana-plugin/src/models/user/user.ts +++ b/grafana-plugin/src/models/user/user.ts @@ -60,7 +60,7 @@ export class UserStore extends BaseStore { } @action - async loadUser(userPk: User['pk'], skipErrorHandling: boolean = false) { + async loadUser(userPk: User['pk'], skipErrorHandling = false) { const user = await this.getById(userPk, skipErrorHandling); this.items = { diff --git a/grafana-plugin/src/pages/escalation-chains/EscalationChains.tsx b/grafana-plugin/src/pages/escalation-chains/EscalationChains.tsx index 375d810c..d9cd7458 100644 --- a/grafana-plugin/src/pages/escalation-chains/EscalationChains.tsx +++ b/grafana-plugin/src/pages/escalation-chains/EscalationChains.tsx @@ -12,6 +12,7 @@ import EscalationsFilters from 'components/EscalationsFilters/EscalationsFilters import Block from 'components/GBlock/Block'; import GList from 'components/GList/GList'; import { getWrongTeamResponseInfo } from 'components/NotFoundInTeam/WrongTeam.helpers'; +import WrongTeamStub from 'components/NotFoundInTeam/WrongTeamStub'; import PluginLink from 'components/PluginLink/PluginLink'; import Text from 'components/Text/Text'; import Tutorial from 'components/Tutorial/Tutorial'; @@ -28,7 +29,6 @@ import { withMobXProviderContext } from 'state/withStore'; import { openWarningNotification } from 'utils'; import styles from './EscalationChains.module.css'; -import WrongTeamStub from 'components/NotFoundInTeam/WrongTeamStub'; const cx = cn.bind(styles); @@ -80,7 +80,7 @@ class EscalationChainsPage extends React.Component this.setState({ ...getWrongTeamResponseInfo(error) })); - if (!escalationChain) return; + if (!escalationChain) {return;} escalationChain = escalationChainStore.items[query.id]; if (escalationChain) { @@ -131,14 +131,10 @@ class EscalationChainsPage extends React.Component diff --git a/grafana-plugin/src/pages/incident/Incident.tsx b/grafana-plugin/src/pages/incident/Incident.tsx index ae8c3574..407c6004 100644 --- a/grafana-plugin/src/pages/incident/Incident.tsx +++ b/grafana-plugin/src/pages/incident/Incident.tsx @@ -26,8 +26,8 @@ import reactStringReplace from 'react-string-replace'; import Collapse from 'components/Collapse/Collapse'; import Block from 'components/GBlock/Block'; import IntegrationLogo from 'components/IntegrationLogo/IntegrationLogo'; -import WrongTeamStub from 'components/NotFoundInTeam/WrongTeamStub'; import { getWrongTeamResponseInfo } from 'components/NotFoundInTeam/WrongTeam.helpers'; +import WrongTeamStub from 'components/NotFoundInTeam/WrongTeamStub'; import PluginLink from 'components/PluginLink/PluginLink'; import SourceCode from 'components/SourceCode/SourceCode'; import Text from 'components/Text/Text'; @@ -122,8 +122,7 @@ class IncidentPage extends React.Component const { alerts } = store.alertGroupStore; const incident = alerts.get(id); - const currentTeamId = store.userStore.currentUser?.current_team; - const currentTeamName = store.grafanaTeamStore.items[currentTeamId]?.name; + if (notFound) { return (
@@ -147,7 +146,6 @@ class IncidentPage extends React.Component diff --git a/grafana-plugin/src/pages/integrations/Integrations.tsx b/grafana-plugin/src/pages/integrations/Integrations.tsx index 7d46c7c1..08d069d9 100644 --- a/grafana-plugin/src/pages/integrations/Integrations.tsx +++ b/grafana-plugin/src/pages/integrations/Integrations.tsx @@ -7,9 +7,10 @@ import cn from 'classnames/bind'; import { debounce } from 'lodash-es'; import { observer } from 'mobx-react'; -import WrongTeamStub from 'components/NotFoundInTeam/WrongTeamStub'; import GList from 'components/GList/GList'; import IntegrationsFilters, { Filters } from 'components/IntegrationsFilters/IntegrationsFilters'; +import { getWrongTeamResponseInfo } from 'components/NotFoundInTeam/WrongTeam.helpers'; +import WrongTeamStub from 'components/NotFoundInTeam/WrongTeamStub'; import Text from 'components/Text/Text'; import Tutorial from 'components/Tutorial/Tutorial'; import { TutorialStep } from 'components/Tutorial/Tutorial.types'; @@ -25,7 +26,6 @@ import { WithStoreProps } from 'state/types'; import { UserAction } from 'state/userAction'; import { withMobXProviderContext } from 'state/withStore'; import { openWarningNotification } from 'utils'; -import { getWrongTeamResponseInfo } from 'components/NotFoundInTeam/WrongTeam.helpers'; import styles from './Integrations.module.css'; @@ -80,7 +80,7 @@ class Integrations extends React.Component let alertReceiveChannel = await alertReceiveChannelStore .loadItem(query.id, true) .catch((error) => this.setState({ ...getWrongTeamResponseInfo(error) })); - if (!alertReceiveChannel) return; + if (!alertReceiveChannel) {return;} if (alertReceiveChannel.id) { selectedAlertReceiveChannel = alertReceiveChannel.id; @@ -132,14 +132,10 @@ class Integrations extends React.Component } = this.state; if (wrongTeamError) { - const currentTeamId = store.userStore.currentUser?.current_team; - const currentTeamName = store.grafanaTeamStore.items[currentTeamId]?.name; - return ( diff --git a/grafana-plugin/src/pages/outgoing_webhooks/OutgoingWebhooks.tsx b/grafana-plugin/src/pages/outgoing_webhooks/OutgoingWebhooks.tsx index 0c427e75..061f5074 100644 --- a/grafana-plugin/src/pages/outgoing_webhooks/OutgoingWebhooks.tsx +++ b/grafana-plugin/src/pages/outgoing_webhooks/OutgoingWebhooks.tsx @@ -7,6 +7,8 @@ import cn from 'classnames/bind'; import { observer } from 'mobx-react'; import GTable from 'components/GTable/GTable'; +import { getWrongTeamResponseInfo } from 'components/NotFoundInTeam/WrongTeam.helpers'; +import WrongTeamStub from 'components/NotFoundInTeam/WrongTeamStub'; import PluginLink from 'components/PluginLink/PluginLink'; import Text from 'components/Text/Text'; import WithConfirm from 'components/WithConfirm/WithConfirm'; @@ -21,8 +23,6 @@ import { UserAction } from 'state/userAction'; import { withMobXProviderContext } from 'state/withStore'; import styles from './OutgoingWebhooks.module.css'; -import { getWrongTeamResponseInfo } from 'components/NotFoundInTeam/WrongTeam.helpers'; -import WrongTeamStub from 'components/NotFoundInTeam/WrongTeamStub'; const cx = cn.bind(styles); @@ -79,14 +79,10 @@ class OutgoingWebhooks extends React.Component diff --git a/grafana-plugin/src/pages/schedules/Schedules.tsx b/grafana-plugin/src/pages/schedules/Schedules.tsx index 57ff9511..62e3dfef 100644 --- a/grafana-plugin/src/pages/schedules/Schedules.tsx +++ b/grafana-plugin/src/pages/schedules/Schedules.tsx @@ -22,6 +22,8 @@ import moment, { Moment } from 'moment-timezone'; import instructionsImage from 'assets/img/events_instructions.png'; import Avatar from 'components/Avatar/Avatar'; import GTable from 'components/GTable/GTable'; +import { getWrongTeamResponseInfo } from 'components/NotFoundInTeam/WrongTeam.helpers'; +import WrongTeamStub from 'components/NotFoundInTeam/WrongTeamStub'; import PluginLink from 'components/PluginLink/PluginLink'; import SchedulesFilters from 'components/SchedulesFilters/SchedulesFilters'; import { SchedulesFiltersType } from 'components/SchedulesFilters/SchedulesFilters.types'; @@ -43,8 +45,6 @@ import { openErrorNotification } from 'utils'; import { getDatesString } from './Schedules.helpers'; import styles from './Schedules.module.css'; -import { getWrongTeamResponseInfo } from 'components/NotFoundInTeam/WrongTeam.helpers'; -import WrongTeamStub from 'components/NotFoundInTeam/WrongTeamStub'; const cx = cn.bind(styles); @@ -93,7 +93,7 @@ class SchedulesPage extends React.Component this.setState({ ...getWrongTeamResponseInfo(error) })); - if (!schedule) return; + if (!schedule) {return;} const schedules = store.scheduleStore.getSearchResult(); const scheduleId = schedules && schedules.find((res) => res.id === id)?.id; @@ -119,14 +119,10 @@ class SchedulesPage extends React.Component diff --git a/grafana-plugin/src/pages/users/Users.tsx b/grafana-plugin/src/pages/users/Users.tsx index 01a8a6d9..6c9b961f 100644 --- a/grafana-plugin/src/pages/users/Users.tsx +++ b/grafana-plugin/src/pages/users/Users.tsx @@ -9,6 +9,8 @@ import { observer } from 'mobx-react'; import Avatar from 'components/Avatar/Avatar'; import GTable from 'components/GTable/GTable'; +import { getWrongTeamResponseInfo } from 'components/NotFoundInTeam/WrongTeam.helpers'; +import WrongTeamStub from 'components/NotFoundInTeam/WrongTeamStub'; import PluginLink from 'components/PluginLink/PluginLink'; import Text from 'components/Text/Text'; import UsersFilters from 'components/UsersFilters/UsersFilters'; @@ -23,8 +25,6 @@ import { withMobXProviderContext } from 'state/withStore'; import { getRealFilters, getUserRowClassNameFn } from './Users.helpers'; import styles from './Users.module.css'; -import { getWrongTeamResponseInfo } from 'components/NotFoundInTeam/WrongTeam.helpers'; -import WrongTeamStub from 'components/NotFoundInTeam/WrongTeamStub'; const cx = cn.bind(styles); @@ -172,14 +172,10 @@ class Users extends React.Component { const { count, results } = userStore.getSearchResult(); if (wrongTeamError) { - const currentTeamId = store.userStore.currentUser?.current_team; - const currentTeamName = store.grafanaTeamStore.items[currentTeamId]?.name; - return (