Skip to content

Commit 8ed6c19

Browse files
youngbeom-shin申永范-UX
andauthored
Csghub improve finetune iframe height handling (#1278)
* feat(finetune): improve iframe height handling * feat(finetune): improve iframe height handling --------- Co-authored-by: 申永范-UX <[email protected]>
1 parent c0db9fb commit 8ed6c19

File tree

1 file changed

+47
-14
lines changed

1 file changed

+47
-14
lines changed

frontend/src/components/finetune/FinetuneDetail.vue

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@
1919
class="mx-auto page-responsive-width mt-[-40px] md:px-0 relative"
2020
v-loading="dataLoading"
2121
>
22-
<el-button
22+
<CsgButton
2323
v-show="activeName == 'page' && repoDetailStore.endpoint"
24-
color="#3250BD"
25-
style="border-radius: var(--border-radius-md) !important"
26-
class="absolute top-0 right-0 z-10 cursor-pointer text-white"
24+
class="btn btn-primary btn-sm absolute top-0 right-0 z-10"
25+
:name="$t('finetune.detail.notebook')"
2726
@click="toNotebookPage"
28-
>{{ $t('finetune.detail.notebook') }}</el-button
29-
>
27+
/>
3028
<el-tabs
3129
v-model="activeName"
3230
class="demo-tabs finetune-repo-tabs"
@@ -37,32 +35,33 @@
3735
:label="$t('finetune.detail.tab1')"
3836
name="page"
3937
>
40-
<div v-if="activeName === 'page'" class="pt-[24px]">
38+
<div v-if="activeName === 'page'" class="pt-6 -mx-4">
4139
<iframe
4240
v-if="repoDetailStore.endpoint"
4341
:src="`${httpProtocal}://${repoDetailStore.proxyEndpoint}?jwt=${jwtToken}`"
4442
width="100%"
45-
height="700"
43+
:height="iframeHeight"
4644
frameborder="0"
4745
allowfullscreen
46+
class="block w-full"
4847
>
4948
</iframe>
5049
<div
5150
class="flex flex-col gap-6"
5251
v-else
5352
>
5453
<div
55-
class="flex items-center justify-start border border-gray-300 p-[16px] rounded-xl shadow-sm"
54+
class="flex items-center justify-start border border-gray-300 p-4 rounded-xl shadow-sm"
5655
>
57-
<div class="border border-gray-300 p-[10px] rounded-lg">
56+
<div class="border border-gray-300 p-2 rounded-lg">
5857
<SvgIcon
5958
name="finetune_tip"
6059
width="20"
6160
height="20"
6261
/>
6362
</div>
64-
<div class="ml-[16px]">
65-
<p class="text-gray-700 text-sm font-medium mb-[4px]">
63+
<div class="ml-4">
64+
<p class="text-gray-700 text-sm font-medium mb-1">
6665
{{ $t('finetune.detail.noDataTip1') }}
6766
</p>
6867
<p class="text-gray-600 text-sm font-light">
@@ -119,7 +118,7 @@
119118
</template>
120119

121120
<script setup>
122-
import { ref, inject, onBeforeMount, computed, provide, watch } from 'vue'
121+
import { ref, inject, onBeforeMount, computed, provide, watch, onMounted, onUnmounted } from 'vue'
123122
import RepoHeader from '../shared/RepoHeader.vue'
124123
import { useCookies } from 'vue3-cookies'
125124
import { fetchEventSource } from '@microsoft/fetch-event-source'
@@ -135,6 +134,7 @@
135134
import { useRepoTabStore } from '@/stores/RepoTabStore'
136135
import { useRoute, useRouter } from 'vue-router'
137136
import { validateTab } from '@/packs/utils'
137+
import CsgButton from '../shared/CsgButton.vue'
138138
139139
const props = defineProps({
140140
namespace: String,
@@ -155,6 +155,7 @@
155155
const dataLoading = ref(false)
156156
const finetuneResources = ref([])
157157
const finetuneResource = ref('')
158+
const iframeHeight = ref(700) // Default height
158159
const allStatus = [
159160
'Building',
160161
'Deploying',
@@ -173,6 +174,29 @@
173174
const csghubServer = inject('csghubServer')
174175
const httpProtocal = ENABLE_HTTPS === 'true' ? 'https' : 'http'
175176
177+
// Function to calculate iframe height
178+
const calculateIframeHeight = () => {
179+
// Get viewport height
180+
const viewportHeight = window.innerHeight
181+
182+
// Estimate fixed height parts to subtract
183+
// These values need to be adjusted based on actual page layout
184+
const headerHeight = 200 // RepoHeader approximate height
185+
const tabsHeight = 60 // Tabs navigation height
186+
const paddingAndMargin = 50 // Various padding and margin (reduced since iframe now fills container)
187+
188+
// Calculate the height iframe should have
189+
const calculatedHeight = viewportHeight - headerHeight - tabsHeight - paddingAndMargin
190+
191+
// Set minimum height to prevent being too small
192+
iframeHeight.value = Math.max(calculatedHeight, 700)
193+
}
194+
195+
// Recalculate height when window size changes
196+
const handleResize = () => {
197+
calculateIframeHeight()
198+
}
199+
176200
const isSameRepo = computed(() => {
177201
return (
178202
Number(props.finetuneId) === repoDetailStore.deployId &&
@@ -204,7 +228,7 @@
204228
return validTabs.value.includes(tab)
205229
}
206230
207-
// 监听路由变化,当用户使用浏览器前进/后退按钮时更新tab
231+
// Listen for route changes, update tab when user uses browser forward/back buttons
208232
watch(() => route.query.tab, (newTab) => {
209233
const validatedTab = validateTab(newTab)
210234
if (validatedTab && isValidTab(validatedTab) && validatedTab !== activeName.value) {
@@ -378,6 +402,15 @@
378402
})
379403
})
380404
405+
onMounted(() => {
406+
calculateIframeHeight()
407+
window.addEventListener('resize', handleResize)
408+
})
409+
410+
onUnmounted(() => {
411+
window.removeEventListener('resize', handleResize)
412+
})
413+
381414
provide('fetchRepoDetail', fetchRepoDetail)
382415
</script>
383416

0 commit comments

Comments
 (0)