2525 />
2626
2727 <v-btn
28+ ref =" downloader"
2829 variant =" text"
2930 border
3031 prepend-icon =" mdi-download-outline"
3435 :href =" binary"
3536 :download =" `${deployment.cluster?.name}-kubeconfig.yaml`"
3637 :disabled =" disabled"
38+ v-bind =" {
39+ onClick: isKubeConfigReady ? undefined : downloadKubeConfig,
40+ }"
3741 />
3842
3943 <v-btn
6367</template >
6468
6569<script setup lang="ts">
70+ import type { VBtn } from " vuetify/components"
6671import type { ServicesClusterData } from " ~/generated/api"
6772
6873const props = defineProps <{ deployment: ServicesClusterData , disabled: boolean }>()
@@ -72,10 +77,10 @@ const createdAt = useDateFormat(() => props.deployment.created_at, DATE_FORMAT)
7277
7378const api = useApi ()
7479
75- const { state : kubeconfig, isLoading : downloading } = useAsyncState (
76- () => api .helpers .getKubeconfig (props .deployment .cluster ?.name ?? " " ),
80+ const { state : kubeconfig, execute : loadKubeConfig, isLoading : downloading, isReady : isKubeConfigReady } = useAsyncState (
81+ async () => api .helpers .getKubeconfig (props .deployment .cluster ?.name ?? " " ),
7782 " " ,
78- { immediate: $meta . client },
83+ { immediate: false },
7984)
8085
8186const binary = computed (() => {
@@ -89,6 +94,16 @@ const binary = computed(() => {
8994 return URL .createObjectURL (blob )
9095})
9196
97+ const downloader = ref <VBtn | null >(null )
98+ async function downloadKubeConfig(e : Event ) {
99+ if (! isKubeConfigReady .value ) {
100+ e .preventDefault ()
101+ await loadKubeConfig ()
102+ await nextTick ()
103+ downloader .value ?.$el ?.click ()
104+ }
105+ }
106+
92107const toast = useToast ()
93108const ctx = inject (DeploymentDialogCtxKey )!
94109
0 commit comments