Skip to content

Commit d17d9c2

Browse files
author
Lasim
committed
refactor: update installation form data structure and integrate team context initialization
1 parent b24c75f commit d17d9c2

3 files changed

Lines changed: 70 additions & 32 deletions

File tree

services/frontend/src/components/mcp-server/wizard/McpServerInstallWizard.vue

Lines changed: 66 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
import { Alert, AlertDescription } from '@/components/ui/alert'
1515
import { Server, Settings, Cloud, Loader2 } from 'lucide-vue-next'
1616
import { McpInstallationService } from '@/services/mcpInstallationService'
17+
import { TeamService } from '@/services/teamService'
1718
import { useEventBus } from '@/composables/useEventBus'
1819
import McpServerSelectionStep from './McpServerSelectionStep.vue'
1920
import EnvironmentVariablesStep from './EnvironmentVariablesStep.vue'
@@ -31,14 +32,14 @@ const eventBus = useEventBus()
3132
// Form data interface
3233
interface InstallationFormData {
3334
server: {
34-
mcp_server_id: string
35+
server_id: string
3536
server_data?: any
3637
}
3738
environment: {
38-
environment_variables: Record<string, string>
39+
user_environment_variables: Record<string, string>
3940
}
4041
platform: {
41-
platform: string
42+
installation_type: string
4243
platform_config?: any
4344
}
4445
}
@@ -74,17 +75,18 @@ const environmentValidation = ref({
7475
missingFields: [] as string[]
7576
})
7677
const environmentStepTouched = ref(false)
78+
const currentTeamId = ref<string | null>(null)
7779
7880
// Form data with proper initialization
7981
const formData = ref<InstallationFormData>({
8082
server: {
81-
mcp_server_id: ''
83+
server_id: ''
8284
},
8385
environment: {
84-
environment_variables: {}
86+
user_environment_variables: {}
8587
},
8688
platform: {
87-
platform: 'local'
89+
installation_type: 'local'
8890
}
8991
})
9092
@@ -95,7 +97,7 @@ const canGoNext = computed(() => !isLastStep.value)
9597
const canGoPrevious = computed(() => !isFirstStep.value)
9698
9799
const canProceedFromServer = computed(() => {
98-
return formData.value.server.mcp_server_id !== ''
100+
return formData.value.server.server_id !== ''
99101
})
100102
101103
const canProceedFromEnvironment = computed(() => {
@@ -104,8 +106,8 @@ const canProceedFromEnvironment = computed(() => {
104106
})
105107
106108
const canSubmit = computed(() => {
107-
return formData.value.server.mcp_server_id &&
108-
formData.value.platform.platform &&
109+
return formData.value.server.server_id &&
110+
formData.value.platform.installation_type &&
109111
canProceedFromEnvironment.value
110112
})
111113
@@ -137,23 +139,58 @@ const handleCancel = () => {
137139
emit('cancel')
138140
}
139141
142+
// Initialize team context from event bus storage
143+
const initializeTeamContext = async () => {
144+
try {
145+
const userTeams = await TeamService.getUserTeams()
146+
if (userTeams.length > 0) {
147+
const storedTeamId = eventBus.getState<string>('selected_team_id')
148+
149+
if (storedTeamId) {
150+
// Try to find the stored team in available teams
151+
const storedTeam = userTeams.find(team => team.id === storedTeamId)
152+
if (storedTeam) {
153+
currentTeamId.value = storedTeam.id
154+
} else {
155+
// Stored team not found, fallback to default team
156+
const defaultTeam = userTeams.find(team => team.is_default) || userTeams[0]
157+
currentTeamId.value = defaultTeam.id
158+
eventBus.setState('selected_team_id', defaultTeam.id)
159+
}
160+
} else {
161+
// No stored team, use default team
162+
const defaultTeam = userTeams.find(team => team.is_default) || userTeams[0]
163+
currentTeamId.value = defaultTeam.id
164+
eventBus.setState('selected_team_id', defaultTeam.id)
165+
}
166+
}
167+
} catch (error) {
168+
console.error('Error initializing team context:', error)
169+
submitError.value = 'Failed to initialize team context. Please refresh the page.'
170+
}
171+
}
172+
140173
// Form submission
141174
const submitInstallation = async () => {
142175
try {
143176
isSubmitting.value = true
144177
submitError.value = null
145178
146-
// Prepare installation data
179+
// Ensure we have a team ID
180+
if (!currentTeamId.value) {
181+
throw new Error('No team selected. Please refresh the page and try again.')
182+
}
183+
184+
// Prepare installation data aligned with backend API
147185
const installationData = {
148-
mcp_server_id: formData.value.server.mcp_server_id,
149-
platform: formData.value.platform.platform,
150-
environment_variables: formData.value.environment.environment_variables,
151-
status: 'pending',
186+
server_id: formData.value.server.server_id,
187+
installation_type: formData.value.platform.installation_type,
188+
user_environment_variables: formData.value.environment.user_environment_variables,
152189
installation_name: formData.value.server.server_data?.name || 'Unknown Server'
153190
}
154191
155-
// Call backend API to create installation
156-
const response = await McpInstallationService.createInstallation(installationData)
192+
// Call backend API to create installation with real team ID
193+
const response = await McpInstallationService.createInstallation(currentTeamId.value, installationData)
157194
158195
if (response.success) {
159196
emit('complete', {
@@ -176,7 +213,7 @@ const handleServerSelected = (serverData: any) => {
176213
formData.value.server.server_data = serverData
177214
178215
// Reset environment variables when server changes
179-
formData.value.environment.environment_variables = {}
216+
formData.value.environment.user_environment_variables = {}
180217
181218
// Reset touched state when server changes
182219
environmentStepTouched.value = false
@@ -185,9 +222,9 @@ const handleServerSelected = (serverData: any) => {
185222
if (serverData.environment_variables) {
186223
serverData.environment_variables.forEach((env: any) => {
187224
if (env.placeholder && env.placeholder !== `<insert-your-${env.name.toLowerCase()}-here>`) {
188-
formData.value.environment.environment_variables[env.name] = env.placeholder
225+
formData.value.environment.user_environment_variables[env.name] = env.placeholder
189226
} else {
190-
formData.value.environment.environment_variables[env.name] = ''
227+
formData.value.environment.user_environment_variables[env.name] = ''
191228
}
192229
})
193230
}
@@ -201,14 +238,17 @@ const handleValidationChange = (isValid: boolean, missingFields: string[]) => {
201238
}
202239
}
203240
204-
onMounted(() => {
241+
onMounted(async () => {
242+
// Initialize team context
243+
await initializeTeamContext()
244+
205245
// Listen for wizard reset events
206246
eventBus.on('mcp-install-wizard-reset', () => {
207247
currentStep.value = 0
208248
formData.value = {
209-
server: { mcp_server_id: '' },
210-
environment: { environment_variables: {} },
211-
platform: { platform: 'local' }
249+
server: { server_id: '' },
250+
environment: { user_environment_variables: {} },
251+
platform: { installation_type: 'local' }
212252
}
213253
submitError.value = null
214254
})
@@ -270,22 +310,22 @@ onMounted(() => {
270310
<!-- Server Selection Step -->
271311
<McpServerSelectionStep
272312
v-if="currentStep === 0"
273-
v-model="formData.server.mcp_server_id"
313+
v-model="formData.server.server_id"
274314
@server-selected="handleServerSelected"
275315
/>
276316

277317
<!-- Environment Variables Step -->
278318
<EnvironmentVariablesStep
279319
v-else-if="currentStep === 1"
280-
v-model="formData.environment.environment_variables"
320+
v-model="formData.environment.user_environment_variables"
281321
:server-data="formData.server.server_data"
282322
@validation-change="handleValidationChange"
283323
/>
284324

285325
<!-- Platform Selection Step -->
286326
<PlatformSelectionStep
287327
v-else-if="currentStep === 2"
288-
v-model="formData.platform.platform"
328+
v-model="formData.platform.installation_type"
289329
/>
290330
</div>
291331

services/frontend/src/components/mcp-server/wizard/McpServerSelectionStep.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ onMounted(() => {
152152
<!-- Loading State -->
153153
<div v-if="isLoading" class="flex items-center justify-center py-8">
154154
<Loader2 class="h-6 w-6 animate-spin mr-2 text-gray-400" />
155-
<span class="text-gray-600">{{ t('common.messages.loading') }}</span>
155+
<span class="text-gray-600">{{ t('messages.loading') }}</span>
156156
</div>
157157

158158
<!-- Server List (only show when there's a search query) -->

services/frontend/src/services/mcpInstallationService.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,12 @@ export class McpInstallationService {
4848
}
4949

5050
/**
51-
* Create MCP server installation (alias for installServer)
51+
* Create MCP server installation with proper team context
5252
*/
5353
// eslint-disable-next-line @typescript-eslint/no-explicit-any
54-
static async createInstallation(installData: any): Promise<{ success: boolean; data: any; message?: string }> {
54+
static async createInstallation(teamId: string, installData: any): Promise<{ success: boolean; data: any; message?: string }> {
5555
try {
56-
// For now, we'll use a mock team ID - this should be replaced with actual team context
57-
const mockTeamId = 'team-123'
58-
const result = await this.installServer(mockTeamId, installData)
56+
const result = await this.installServer(teamId, installData)
5957
return {
6058
success: true,
6159
data: result

0 commit comments

Comments
 (0)