Skip to content

Commit 260eef9

Browse files
Copilotserhalp
andauthored
feat: prefill URL input with run's URL on permalink pages (#87)
* Initial plan * Initial exploration and plan setup Co-authored-by: serhalp <[email protected]> * Implement URL pre-filling for run page permalinks Co-authored-by: serhalp <[email protected]> * Fix loading state and remove package-lock.json per feedback Co-authored-by: serhalp <[email protected]> * Simplify loading condition and runUrl logic per code review Co-authored-by: serhalp <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: serhalp <[email protected]>
1 parent 2ad9c18 commit 260eef9

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

app/components/RequestForm.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,19 @@ describe('RequestForm', () => {
4343
await wrapper.find('button').trigger('click')
4444
expect(wrapper.emitted('submit')).toBeFalsy()
4545
})
46+
47+
it('uses default URL when no initialUrl prop is provided', () => {
48+
const wrapper = mount(RequestForm)
49+
const input = wrapper.find('input')
50+
expect(input.element.value).toBe('https://nextjs-netlify-durable-cache-demo.netlify.app/isr-page')
51+
})
52+
53+
it('uses initialUrl prop when provided', () => {
54+
const customUrl = 'https://example.com/test-page'
55+
const wrapper = mount(RequestForm, {
56+
props: { initialUrl: customUrl },
57+
})
58+
const input = wrapper.find('input')
59+
expect(input.element.value).toBe(customUrl)
60+
})
4661
})

app/components/RequestForm.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<script setup lang="ts">
2-
const inputUrl = ref(
3-
'https://nextjs-netlify-durable-cache-demo.netlify.app/isr-page',
4-
)
5-
62
const props = defineProps<{
73
loading?: boolean
4+
initialUrl?: string
85
}>()
96
7+
const inputUrl = ref(
8+
props.initialUrl ?? 'https://nextjs-netlify-durable-cache-demo.netlify.app/isr-page',
9+
)
10+
1011
const emit = defineEmits(['submit'])
1112
1213
const handleSubmit = () => {

app/pages/run/[runId].vue

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { runs, error, loading, handleRequestFormSubmit, handleClickClear, getRunF
33
44
const route = useRoute()
55
6-
const { data: initialRuns, pending: _pending, error: preloadedRunsError } = await useAsyncData('preloadedRuns', async () => {
6+
const { data: initialRuns, pending: initialLoading, error: preloadedRunsError } = await useAsyncData('preloadedRuns', async () => {
77
const { runId } = route.params
88
if (typeof runId === 'string') {
99
const responseBody = await $fetch(`/api/runs/${runId}`)
@@ -18,15 +18,31 @@ if (preloadedRunsError.value) {
1818
if (initialRuns.value) {
1919
setRuns(initialRuns.value)
2020
}
21+
22+
// Get the URL from the loaded run - we know it exists since we successfully loaded the run
23+
const runUrl = computed(() => {
24+
return initialRuns.value?.[0]?.url
25+
})
2126
</script>
2227

2328
<template>
2429
<main>
30+
<!-- Only render RequestForm when we have loaded the initial run -->
2531
<RequestForm
32+
v-if="!initialLoading"
2633
:loading="loading"
34+
:initial-url="runUrl"
2735
@submit="handleRequestFormSubmit"
2836
/>
2937

38+
<!-- Show loading state while initial run is loading -->
39+
<div
40+
v-else-if="initialLoading"
41+
class="loading-state"
42+
>
43+
Loading run...
44+
</div>
45+
3046
<RunDisplay
3147
:runs="runs"
3248
:error="error"
@@ -37,4 +53,9 @@ if (initialRuns.value) {
3753
</template>
3854

3955
<style scoped>
56+
.loading-state {
57+
padding: 1em;
58+
text-align: center;
59+
color: #666;
60+
}
4061
</style>

0 commit comments

Comments
 (0)