@@ -11,7 +11,7 @@ import { useEventBus } from '@/composables/useEventBus'
1111import McpInstallationsCard from ' @/components/mcp-server/McpInstallationsCard.vue'
1212import type { McpInstallation } from ' @/types/mcp-installations'
1313import { McpInstallationService } from ' @/services/mcpInstallationService'
14- import { TeamService } from ' @/services/teamService'
14+ import { TeamService , type Team } from ' @/services/teamService'
1515
1616const { t } = useI18n ()
1717const router = useRouter ()
@@ -23,32 +23,71 @@ const isLoading = ref(true)
2323const error = ref <string | null >(null )
2424const successMessage = ref <string | null >(null )
2525
26+ // Team context using event bus storage
27+ const selectedTeam = ref <Team | null >(null )
28+
2629// Computed
2730const hasInstallations = computed (() => installations .value .length > 0 )
2831
29- // Methods
30- const fetchInstallations = async (): Promise < void > => {
32+ // Initialize selected team from storage
33+ const initializeSelectedTeam = async () => {
3134 try {
32- isLoading .value = true
33- error .value = null
35+ const userTeams = await TeamService .getUserTeams ()
36+ if (userTeams .length > 0 ) {
37+ const storedTeamId = eventBus .getState <string >(' selected_team_id' )
38+
39+ if (storedTeamId ) {
40+ // Try to find the stored team in available teams
41+ const storedTeam = userTeams .find (team => team .id === storedTeamId )
42+ if (storedTeam ) {
43+ selectedTeam .value = storedTeam
44+ } else {
45+ // Stored team not found, fallback to default team
46+ const defaultTeam = userTeams .find (team => team .is_default ) || userTeams [0 ]
47+ selectedTeam .value = defaultTeam
48+ eventBus .setState (' selected_team_id' , defaultTeam .id )
49+ }
50+ } else {
51+ // No stored team, use default team
52+ const defaultTeam = userTeams .find (team => team .is_default ) || userTeams [0 ]
53+ selectedTeam .value = defaultTeam
54+ eventBus .setState (' selected_team_id' , defaultTeam .id )
55+ }
56+ }
57+ } catch (error ) {
58+ console .error (' Error initializing selected team:' , error )
59+ }
60+ }
3461
35- // Get user's teams
62+ // Handle team selection from sidebar
63+ const handleTeamSelected = async (data : { teamId: string ; teamName: string }) => {
64+ // Find the full team object with role information
65+ try {
3666 const userTeams = await TeamService .getUserTeams ()
67+ const fullTeam = userTeams .find (t => t .id === data .teamId )
68+ if (fullTeam ) {
69+ selectedTeam .value = fullTeam
70+ } else {
71+ selectedTeam .value = { id: data .teamId , name: data .teamName } as Team
72+ }
3773
38- // Fetch installations from all teams
39- const allInstallations: McpInstallation [] = []
74+ fetchInstallations () // Reload installations for new team
75+ } catch (error ) {
76+ console .error (' Error handling team selection:' , error )
77+ selectedTeam .value = { id: data .teamId , name: data .teamName } as Team
78+ fetchInstallations ()
79+ }
80+ }
4081
41- for (const team of userTeams ) {
42- try {
43- const teamInstallations = await McpInstallationService .getTeamInstallations (team .id )
44- allInstallations .push (... teamInstallations )
45- } catch {
46- // Continue with other teams if one fails
47- continue
48- }
49- }
82+ // Methods
83+ const fetchInstallations = async (): Promise <void > => {
84+ if (! selectedTeam .value ) return
5085
51- installations .value = allInstallations
86+ try {
87+ isLoading .value = true
88+ error .value = null
89+
90+ installations .value = await McpInstallationService .getTeamInstallations (selectedTeam .value .id )
5291 } catch (err ) {
5392 error .value = err instanceof Error ? err .message : ' An unknown error occurred'
5493 installations .value = []
@@ -95,14 +134,24 @@ const handleInstallationsUpdate = () => {
95134
96135// Lifecycle
97136onMounted (async () => {
98- await fetchInstallations ()
137+ // Initialize team context first
138+ await initializeSelectedTeam ()
139+
140+ // Initial fetch after team is set
141+ if (selectedTeam .value ) {
142+ await fetchInstallations ()
143+ }
144+
145+ // Listen for team selection events from sidebar
146+ eventBus .on (' team-selected' , handleTeamSelected )
99147
100148 // Listen for installation updates
101149 eventBus .on (' mcp-installations-updated' , handleInstallationsUpdate )
102150})
103151
104152onUnmounted (() => {
105- // Clean up event listeners
153+ // Clean up event listeners to prevent memory leaks
154+ eventBus .off (' team-selected' , handleTeamSelected )
106155 eventBus .off (' mcp-installations-updated' , handleInstallationsUpdate )
107156})
108157 </script >
@@ -116,6 +165,7 @@ onUnmounted(() => {
116165 <p class =" text-muted-foreground" >{{ t('mcpInstallations.description') }}</p >
117166 </div >
118167 <Button
168+ v-if =" selectedTeam"
119169 @click =" handleInstallServer"
120170 class =" flex items-center gap-2"
121171 >
@@ -130,8 +180,13 @@ onUnmounted(() => {
130180 <AlertDescription >{{ successMessage }}</AlertDescription >
131181 </Alert >
132182
183+ <!-- No team selected state -->
184+ <div v-if =" !selectedTeam" class =" text-center py-12" >
185+ <p class =" text-muted-foreground" >{{ t('mcpInstallations.teamContext.noTeamSelected') }}</p >
186+ </div >
187+
133188 <!-- Loading State -->
134- <div v-if =" isLoading" class =" text-muted-foreground" >
189+ <div v-else- if =" isLoading" class =" text-muted-foreground" >
135190 {{ t('mcpInstallations.table.loading') }}
136191 </div >
137192
0 commit comments