|
2 | 2 | /* eslint-disable @typescript-eslint/no-explicit-any */ |
3 | 3 | import { ref, computed, onMounted } from 'vue' |
4 | 4 | import { useI18n } from 'vue-i18n' |
| 5 | +import { useRoute } from 'vue-router' |
5 | 6 | import { Button } from '@/components/ui/button' |
6 | 7 | import { ProgressBars } from '@/components/ui/progress-bars' |
7 | 8 | import { Alert, AlertDescription } from '@/components/ui/alert' |
8 | 9 | import { Server, Settings, Cloud, Loader2 } from 'lucide-vue-next' |
9 | 10 | import { McpInstallationService } from '@/services/mcpInstallationService' |
10 | 11 | import { TeamService } from '@/services/teamService' |
| 12 | +import { McpCatalogService } from '@/services/mcpCatalogService' |
11 | 13 | import { useEventBus } from '@/composables/useEventBus' |
12 | 14 | import McpServerSelectionStep from './McpServerSelectionStep.vue' |
13 | 15 | import EnvironmentVariablesStep from './EnvironmentVariablesStep.vue' |
14 | 16 | import PlatformSelectionStep from './PlatformSelectionStep.vue' |
15 | 17 |
|
| 18 | +// Props |
| 19 | +interface Props { |
| 20 | + initialServerId?: string |
| 21 | + initialStep?: number |
| 22 | +} |
| 23 | +
|
| 24 | +withDefaults(defineProps<Props>(), { |
| 25 | + initialServerId: '', |
| 26 | + initialStep: 0 |
| 27 | +}) |
| 28 | +
|
16 | 29 | // Emits |
17 | 30 | const emit = defineEmits<{ |
18 | 31 | complete: [installationData: any] |
19 | 32 | cancel: [] |
20 | 33 | }>() |
21 | 34 |
|
22 | 35 | const { t } = useI18n() |
| 36 | +const route = useRoute() |
23 | 37 | const eventBus = useEventBus() |
24 | 38 |
|
25 | 39 | // Form data interface |
@@ -63,13 +77,13 @@ const steps = [ |
63 | 77 | const progressSteps = computed(() => { |
64 | 78 | return steps.map((step, index) => { |
65 | 79 | let status: 'completed' | 'current' | 'pending' = 'pending' |
66 | | - |
| 80 | +
|
67 | 81 | if (index < currentStep.value) { |
68 | 82 | status = 'completed' |
69 | 83 | } else if (index === currentStep.value) { |
70 | 84 | status = 'current' |
71 | 85 | } |
72 | | - |
| 86 | +
|
73 | 87 | return { |
74 | 88 | id: step.key, |
75 | 89 | label: step.label, |
@@ -157,7 +171,7 @@ const nextStep = () => { |
157 | 171 | const previousStep = () => { |
158 | 172 | if (canGoPrevious.value) { |
159 | 173 | currentStep.value-- |
160 | | - |
| 174 | +
|
161 | 175 | // Reset form data when going back to previous steps |
162 | 176 | if (currentStep.value === 0) { |
163 | 177 | // Going back to server selection - clear server data |
@@ -276,10 +290,51 @@ const handleValidationChange = (isValid: boolean, missingFields: string[]) => { |
276 | 290 | } |
277 | 291 | } |
278 | 292 |
|
| 293 | +// Handle query parameters for pre-selection |
| 294 | +const handleQueryParameters = async () => { |
| 295 | + const serverId = route.query.serverId as string |
| 296 | + const step = route.query.step as string |
| 297 | +
|
| 298 | + if (serverId) { |
| 299 | + try { |
| 300 | + // Fetch server data from API |
| 301 | + const serverData = await McpCatalogService.getServerById(serverId) |
| 302 | +
|
| 303 | + if (serverData) { |
| 304 | + // Pre-populate form data |
| 305 | + formData.value.server.server_id = serverId |
| 306 | + formData.value.server.server_data = serverData |
| 307 | +
|
| 308 | + // Pre-populate environment variables with default values |
| 309 | + if (serverData.environment_variables) { |
| 310 | + serverData.environment_variables.forEach((env: any) => { |
| 311 | + if (env.placeholder && env.placeholder !== `<insert-your-${env.name.toLowerCase()}-here>`) { |
| 312 | + formData.value.environment.user_environment_variables[env.name] = env.placeholder |
| 313 | + } else { |
| 314 | + formData.value.environment.user_environment_variables[env.name] = '' |
| 315 | + } |
| 316 | + }) |
| 317 | + } |
| 318 | +
|
| 319 | + // Set initial step if specified |
| 320 | + if (step === '2') { |
| 321 | + currentStep.value = 1 // Step 2 = index 1 |
| 322 | + } |
| 323 | + } |
| 324 | + } catch (error) { |
| 325 | + console.error('Error loading server from query parameters:', error) |
| 326 | + submitError.value = 'Failed to load the selected server. Please try again.' |
| 327 | + } |
| 328 | + } |
| 329 | +} |
| 330 | +
|
279 | 331 | onMounted(async () => { |
280 | 332 | // Initialize team context |
281 | 333 | await initializeTeamContext() |
282 | 334 |
|
| 335 | + // Handle query parameters for pre-selection |
| 336 | + await handleQueryParameters() |
| 337 | +
|
283 | 338 | // Listen for wizard reset events |
284 | 339 | eventBus.on('mcp-install-wizard-reset', () => { |
285 | 340 | currentStep.value = 0 |
|
0 commit comments