Skip to content

Commit 07c164d

Browse files
Add load kubeconfig when downloading
1 parent dbdaa92 commit 07c164d

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

frontend/kubecloud-v2/components/rows/DeploymentRow.vue

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
/>
2626

2727
<v-btn
28+
ref="downloader"
2829
variant="text"
2930
border
3031
prepend-icon="mdi-download-outline"
@@ -34,6 +35,9 @@
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
@@ -63,6 +67,7 @@
6367
</template>
6468

6569
<script setup lang="ts">
70+
import type { VBtn } from "vuetify/components"
6671
import type { ServicesClusterData } from "~/generated/api"
6772
6873
const props = defineProps<{ deployment: ServicesClusterData, disabled: boolean }>()
@@ -72,10 +77,10 @@ const createdAt = useDateFormat(() => props.deployment.created_at, DATE_FORMAT)
7277
7378
const 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
8186
const 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+
92107
const toast = useToast()
93108
const ctx = inject(DeploymentDialogCtxKey)!
94109

0 commit comments

Comments
 (0)