|
| 1 | +<script setup lang="ts"> |
| 2 | +import { ref, computed, onMounted, watch } from 'vue' |
| 3 | +import { useI18n } from 'vue-i18n' |
| 4 | +import { Button } from '@/components/ui/button' |
| 5 | +import { Progress } from '@/components/ui/progress' |
| 6 | +import { Alert, AlertDescription } from '@/components/ui/alert' |
| 7 | +import { |
| 8 | + Loader2, |
| 9 | + AlertTriangle, |
| 10 | + Server, |
| 11 | + RefreshCw, |
| 12 | + HardDrive, |
| 13 | + Globe |
| 14 | +} from 'lucide-vue-next' |
| 15 | +import { TeamService, type Team, type TeamUsageData } from '@/services/teamService' |
| 16 | +
|
| 17 | +const { t } = useI18n() |
| 18 | +
|
| 19 | +interface Props { |
| 20 | + team: Team |
| 21 | +} |
| 22 | +
|
| 23 | +const props = defineProps<Props>() |
| 24 | +
|
| 25 | +// State |
| 26 | +const usageData = ref<TeamUsageData | null>(null) |
| 27 | +const isLoading = ref(true) |
| 28 | +const error = ref<string | null>(null) |
| 29 | +
|
| 30 | +// Computed properties |
| 31 | +const totalMcpPercentage = computed(() => { |
| 32 | + if (!usageData.value) return 0 |
| 33 | + const { total_installed_mcp_servers, limits } = usageData.value |
| 34 | + if (limits.mcp_server_limit === 0) return 0 |
| 35 | + return Math.min(100, (total_installed_mcp_servers / limits.mcp_server_limit) * 100) |
| 36 | +}) |
| 37 | +
|
| 38 | +const nonHttpMcpPercentage = computed(() => { |
| 39 | + if (!usageData.value) return 0 |
| 40 | + const { non_http_mcp_servers, limits } = usageData.value |
| 41 | + if (limits.non_http_mcp_limit === 0) return 0 |
| 42 | + return Math.min(100, (non_http_mcp_servers / limits.non_http_mcp_limit) * 100) |
| 43 | +}) |
| 44 | +
|
| 45 | +const isAtTotalLimit = computed(() => { |
| 46 | + if (!usageData.value) return false |
| 47 | + return usageData.value.total_installed_mcp_servers >= usageData.value.limits.mcp_server_limit |
| 48 | +}) |
| 49 | +
|
| 50 | +const isAtNonHttpLimit = computed(() => { |
| 51 | + if (!usageData.value) return false |
| 52 | + return usageData.value.non_http_mcp_servers >= usageData.value.limits.non_http_mcp_limit |
| 53 | +}) |
| 54 | +
|
| 55 | +// Load usage data |
| 56 | +const loadUsageData = async () => { |
| 57 | + try { |
| 58 | + isLoading.value = true |
| 59 | + error.value = null |
| 60 | + usageData.value = await TeamService.getTeamUsage(props.team.id) |
| 61 | + } catch (err) { |
| 62 | + error.value = err instanceof Error ? err.message : 'Failed to load usage data' |
| 63 | + console.error('Error loading team usage:', err) |
| 64 | + } finally { |
| 65 | + isLoading.value = false |
| 66 | + } |
| 67 | +} |
| 68 | +
|
| 69 | +// Watch for team changes and reload data |
| 70 | +watch(() => props.team.id, () => { |
| 71 | + loadUsageData() |
| 72 | +}, { immediate: false }) |
| 73 | +
|
| 74 | +onMounted(() => { |
| 75 | + loadUsageData() |
| 76 | +}) |
| 77 | +</script> |
| 78 | + |
| 79 | +<template> |
| 80 | + <div class="space-y-6"> |
| 81 | + <!-- Loading State --> |
| 82 | + <div v-if="isLoading" class="flex items-center justify-center py-12"> |
| 83 | + <div class="flex items-center gap-3 text-muted-foreground"> |
| 84 | + <Loader2 class="h-5 w-5 animate-spin" /> |
| 85 | + {{ t('teams.manage.usage.loading') }} |
| 86 | + </div> |
| 87 | + </div> |
| 88 | + |
| 89 | + <!-- Error State --> |
| 90 | + <Alert v-else-if="error" variant="destructive"> |
| 91 | + <AlertTriangle class="h-4 w-4" /> |
| 92 | + <AlertDescription> |
| 93 | + {{ error }} |
| 94 | + </AlertDescription> |
| 95 | + <div class="mt-4"> |
| 96 | + <Button |
| 97 | + variant="outline" |
| 98 | + size="sm" |
| 99 | + @click="loadUsageData" |
| 100 | + > |
| 101 | + <RefreshCw class="h-4 w-4 mr-2" /> |
| 102 | + {{ t('teams.manage.usage.retry') }} |
| 103 | + </Button> |
| 104 | + </div> |
| 105 | + </Alert> |
| 106 | + |
| 107 | + <!-- Usage Content --> |
| 108 | + <div v-else-if="usageData"> |
| 109 | + <div class="px-4 sm:px-0"> |
| 110 | + <h3 class="text-base/7 font-semibold text-gray-900">{{ t('teams.manage.usage.title') }}</h3> |
| 111 | + <p class="mt-1 max-w-2xl text-sm/6 text-gray-500">{{ t('teams.manage.usage.description') }}</p> |
| 112 | + </div> |
| 113 | + |
| 114 | + <div class="mt-6 border-t border-gray-100"> |
| 115 | + <dl class="divide-y divide-gray-100"> |
| 116 | + <!-- Total MCP Servers --> |
| 117 | + <div class="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0"> |
| 118 | + <dt class="text-sm/6 font-medium text-gray-900 flex items-center gap-2"> |
| 119 | + <Server class="h-4 w-4 text-muted-foreground" /> |
| 120 | + {{ t('teams.manage.usage.totalMcpServers') }} |
| 121 | + </dt> |
| 122 | + <dd class="mt-1 text-sm/6 text-gray-700 sm:col-span-2 sm:mt-0"> |
| 123 | + <div class="space-y-2 max-w-md"> |
| 124 | + <div class="flex justify-between text-sm"> |
| 125 | + <span>{{ usageData.total_installed_mcp_servers }} / {{ usageData.limits.mcp_server_limit }}</span> |
| 126 | + <span :class="isAtTotalLimit ? 'text-destructive font-medium' : 'text-muted-foreground'"> |
| 127 | + {{ Math.round(totalMcpPercentage) }}% |
| 128 | + </span> |
| 129 | + </div> |
| 130 | + <Progress |
| 131 | + :model-value="totalMcpPercentage" |
| 132 | + :class="isAtTotalLimit ? '[&>div]:bg-destructive' : ''" |
| 133 | + /> |
| 134 | + <p v-if="isAtTotalLimit" class="text-xs text-destructive"> |
| 135 | + {{ t('teams.manage.usage.limitReached') }} |
| 136 | + </p> |
| 137 | + </div> |
| 138 | + </dd> |
| 139 | + </div> |
| 140 | + |
| 141 | + <!-- Non-HTTP MCP Servers --> |
| 142 | + <div class="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0"> |
| 143 | + <dt class="text-sm/6 font-medium text-gray-900 flex items-center gap-2"> |
| 144 | + <HardDrive class="h-4 w-4 text-muted-foreground" /> |
| 145 | + {{ t('teams.manage.usage.nonHttpMcpServers') }} |
| 146 | + </dt> |
| 147 | + <dd class="mt-1 text-sm/6 text-gray-700 sm:col-span-2 sm:mt-0"> |
| 148 | + <div class="space-y-2 max-w-md"> |
| 149 | + <div class="flex justify-between text-sm"> |
| 150 | + <span>{{ usageData.non_http_mcp_servers }} / {{ usageData.limits.non_http_mcp_limit }}</span> |
| 151 | + <span :class="isAtNonHttpLimit ? 'text-destructive font-medium' : 'text-muted-foreground'"> |
| 152 | + {{ Math.round(nonHttpMcpPercentage) }}% |
| 153 | + </span> |
| 154 | + </div> |
| 155 | + <Progress |
| 156 | + :model-value="nonHttpMcpPercentage" |
| 157 | + :class="isAtNonHttpLimit ? '[&>div]:bg-destructive' : ''" |
| 158 | + /> |
| 159 | + <p v-if="isAtNonHttpLimit" class="text-xs text-destructive"> |
| 160 | + {{ t('teams.manage.usage.limitReached') }} |
| 161 | + </p> |
| 162 | + <p class="text-xs text-muted-foreground"> |
| 163 | + {{ t('teams.manage.usage.nonHttpDescription') }} |
| 164 | + </p> |
| 165 | + </div> |
| 166 | + </dd> |
| 167 | + </div> |
| 168 | + |
| 169 | + <!-- HTTP MCP Servers (info only) --> |
| 170 | + <div class="px-4 py-6 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-0"> |
| 171 | + <dt class="text-sm/6 font-medium text-gray-900 flex items-center gap-2"> |
| 172 | + <Globe class="h-4 w-4 text-muted-foreground" /> |
| 173 | + {{ t('teams.manage.usage.httpMcpServers') }} |
| 174 | + </dt> |
| 175 | + <dd class="mt-1 text-sm/6 text-gray-700 sm:col-span-2 sm:mt-0"> |
| 176 | + <div class="space-y-1"> |
| 177 | + <span class="font-medium">{{ usageData.http_mcp_servers }}</span> |
| 178 | + <p class="text-xs text-muted-foreground"> |
| 179 | + {{ t('teams.manage.usage.httpDescription') }} |
| 180 | + </p> |
| 181 | + </div> |
| 182 | + </dd> |
| 183 | + </div> |
| 184 | + </dl> |
| 185 | + </div> |
| 186 | + |
| 187 | + <!-- Refresh Button --> |
| 188 | + <div class="flex items-center justify-end pt-4 border-t"> |
| 189 | + <Button |
| 190 | + variant="outline" |
| 191 | + @click="loadUsageData" |
| 192 | + :disabled="isLoading" |
| 193 | + class="gap-2" |
| 194 | + > |
| 195 | + <RefreshCw class="h-4 w-4" :class="isLoading ? 'animate-spin' : ''" /> |
| 196 | + {{ t('teams.manage.usage.refresh') }} |
| 197 | + </Button> |
| 198 | + </div> |
| 199 | + </div> |
| 200 | + </div> |
| 201 | +</template> |
0 commit comments