From 4975b86f34d2332eb7612e4d79dd8f57f23773f3 Mon Sep 17 00:00:00 2001 From: Georg Bremer Date: Fri, 28 Feb 2025 16:00:23 +0100 Subject: [PATCH] chore(Mattermost Plugin): Default to linked teams on new channels --- .../components/Sidepanel/SidePanel.tsx | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/packages/mattermost-plugin/components/Sidepanel/SidePanel.tsx b/packages/mattermost-plugin/components/Sidepanel/SidePanel.tsx index 3e752b80843..6519c7311ea 100644 --- a/packages/mattermost-plugin/components/Sidepanel/SidePanel.tsx +++ b/packages/mattermost-plugin/components/Sidepanel/SidePanel.tsx @@ -1,6 +1,10 @@ -import {useState} from 'react' +import graphql from 'babel-plugin-relay/macro' +import {useEffect, useState} from 'react' import {useDispatch} from 'react-redux' +import {useLazyLoadQuery} from 'react-relay' import ReactSelect from 'react-select' +import {SidePanelQuery} from '../../__generated__/SidePanelQuery.graphql' +import {useCurrentChannel} from '../../hooks/useCurrentChannel' import {openLinkTeamModal, openStartActivityModal} from '../../reducers' import ActiveMeetings from './ActiveMeetings' import LinkedTeams from './LinkedTeams' @@ -21,7 +25,26 @@ const panels = { } as const const SidePanel = () => { - const [activePanel, setActivePanel] = useState('teams') + const channel = useCurrentChannel() + const data = useLazyLoadQuery( + graphql` + query SidePanelQuery($channel: ID!) { + linkedTeamIds(channel: $channel) + } + `, + { + channel: channel?.id ?? '' + } + ) + const {linkedTeamIds} = data + + const [activePanel, setActivePanel] = useState('meetings') + useEffect(() => { + if (linkedTeamIds && linkedTeamIds.length === 0) { + setActivePanel('teams') + } + }, [linkedTeamIds]) + const dispatch = useDispatch() const handleClick = () => {