@@ -3,7 +3,11 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/vue-query"
33import { computed , ref } from " vue"
44import { useI18n } from " vue-i18n"
55
6- import { fetchModelMappings , saveModelMapping , deleteModelMapping } from " @/api/mappings"
6+ import {
7+ deleteModelMapping ,
8+ fetchModelMappings ,
9+ saveModelMapping ,
10+ } from " @/api/mappings"
711import { fetchAdminModels , fetchPremiumConfig } from " @/api/models"
812import { fetchAdminSettings } from " @/api/settings"
913import { adminQueryKeys } from " @/query/keys"
@@ -18,14 +22,17 @@ const mappingsQuery = useQuery({
1822 queryKey: adminQueryKeys .mappings ,
1923 queryFn: fetchModelMappings ,
2024})
25+
2126const modelsQuery = useQuery ({
2227 queryKey: adminQueryKeys .models ,
2328 queryFn: fetchAdminModels ,
2429})
30+
2531const premiumQuery = useQuery ({
2632 queryKey: adminQueryKeys .premiumConfig ,
2733 queryFn: fetchPremiumConfig ,
2834})
35+
2936const settingsQuery = useQuery ({
3037 queryKey: adminQueryKeys .settings ,
3138 queryFn: fetchAdminSettings ,
@@ -37,7 +44,8 @@ const targetModel = ref("")
3744
3845const availableModels = computed (() => {
3946 const hiddenModels = new Set (premiumQuery .data .value ?.hiddenModels ?? [])
40- const disableHiddenModels = settingsQuery .data .value ?.disableHiddenModels ?? false
47+ const disableHiddenModels =
48+ settingsQuery .data .value ?.disableHiddenModels ?? false
4149
4250 return (modelsQuery .data .value ?.data ?? []).filter ((model ) => {
4351 if (! disableHiddenModels ) {
@@ -48,6 +56,18 @@ const availableModels = computed(() => {
4856 })
4957})
5058
59+ const targetModelSelectDisabled = computed (() =>
60+ modelsQuery .isLoading .value
61+ || premiumQuery .isLoading .value
62+ || settingsQuery .isLoading .value ,
63+ )
64+
65+ const targetModelOptionText = computed (() =>
66+ targetModelSelectDisabled .value ?
67+ t (" mappings.loadingModels" )
68+ : t (" mappings.selectTarget" ),
69+ )
70+
5171const saveMutation = useMutation ({
5272 mutationFn : async () =>
5373 saveModelMapping (fromAlias .value .trim (), targetModel .value .trim ()),
@@ -113,12 +133,12 @@ function openMappingForm(): void {
113133
114134<template >
115135 <div id =" tab-model-mappings" class =" tab-content active" >
116- <div class =" card" >
117- <div class =" card-header" >
118- <span class =" card-title" >{{ t("mappings.title") }}</span >
119- <button type =" button" class =" btn btn-primary btn-sm" @click =" openMappingForm" >
120- {{ t("mappings.add") }}
121- </button >
136+ <div class =" card" >
137+ <div class =" card-header" >
138+ <span class =" card-title" >{{ t("mappings.title") }}</span >
139+ <button type =" button" class =" btn btn-primary btn-sm" @click =" openMappingForm" >
140+ {{ t("mappings.add") }}
141+ </button >
122142 </div >
123143
124144 <div class =" mapping-form" :class =" { active: formOpen }" >
@@ -128,9 +148,13 @@ function openMappingForm(): void {
128148 class =" select mapping-input-inline"
129149 :placeholder =" t('mappings.fromPlaceholder')"
130150 >
131- <span class =" mapping-arrow" >→</span >
132- <select v-model =" targetModel" class =" select mapping-input-inline" >
133- <option value =" " >{{ t("mappings.selectTarget") }}</option >
151+ <span class =" mapping-arrow" aria-hidden =" true" >&rarr ; </span >
152+ <select
153+ v-model =" targetModel"
154+ class =" select mapping-input-inline"
155+ :disabled =" targetModelSelectDisabled"
156+ >
157+ <option value =" " >{{ targetModelOptionText }}</option >
134158 <option v-for =" model in availableModels" :key =" model.id" :value =" model.id" >
135159 {{ model.id }}
136160 </option >
@@ -186,7 +210,11 @@ function openMappingForm(): void {
186210 <button type =" button" class =" btn btn-sm" @click =" copyMapping(from, to)" >
187211 {{ t("mappings.copy") }}
188212 </button >
189- <button type =" button" class =" btn btn-danger btn-sm" @click =" removeMapping(from)" >
213+ <button
214+ type =" button"
215+ class =" btn btn-danger btn-sm"
216+ @click =" removeMapping(from)"
217+ >
190218 {{ t("common.delete") }}
191219 </button >
192220 </div >
0 commit comments