Skip to content

Commit f1bf102

Browse files
committed
feat: auth required view for terminal
1 parent 7af61bb commit f1bf102

File tree

2 files changed

+69
-61
lines changed

2 files changed

+69
-61
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<script setup lang="ts">
2+
const terminals = useTerminals()
3+
const route = useRoute()
4+
const router = useRouter()
5+
6+
const selected = computed(() => {
7+
const id = route.query.id as string
8+
return terminals.value?.find(t => t.id === id)
9+
})
10+
11+
function remove(id: string) {
12+
rpc.runTerminalAction(id, 'remove')
13+
router.replace('/modules/terminals')
14+
}
15+
16+
watchEffect(() => {
17+
if (!route.query.id && terminals.value?.length)
18+
router.replace(`/modules/terminals?id=${encodeURIComponent(terminals.value[0].id)}`)
19+
})
20+
</script>
21+
22+
<template>
23+
<div v-if="terminals?.length" h-full w-full of-hidden grid="~ rows-[max-content_1fr_max-content]">
24+
<!-- TODO: Refactor to have general component -->
25+
<div flex="~" border="b base" flex-1 items-center navbar-glass>
26+
<NuxtLink
27+
v-for="t of terminals"
28+
:key="t.id" border="r base"
29+
flex="~ gap-2" items-center px3 py2
30+
:class="t.id === selected?.id ? 'bg-active' : ''"
31+
:to="`/modules/terminals?id=${encodeURIComponent(t.id)}` "
32+
>
33+
<NIcon v-if="t.icon " :icon="t.icon" />
34+
<span :class="t.id === selected?.id ? '' : 'op50'">
35+
{{ t.name }}{{ t.isTerminated ? ' (terminated)' : '' }}
36+
</span>
37+
<NIconButton
38+
v-if="t.isTerminated"
39+
icon="carbon-close" mx--2
40+
@click.stop="remove(t.id)"
41+
/>
42+
</NuxtLink>
43+
</div>
44+
45+
<template v-if="selected">
46+
<TerminalView :id="selected.id" :key="selected.id" />
47+
</template>
48+
<template v-else>
49+
<div p10>
50+
Terminal <code>{{ route.query.id }}</code> not found
51+
</div>
52+
</template>
53+
</div>
54+
<div v-else h-full flex items-center justify-center>
55+
<em op50>No terminal attached</em>
56+
</div>
57+
</template>
58+
59+
<style>
60+
.xterm {
61+
padding-left: 1rem;
62+
padding-right: 1rem;
63+
}
64+
</style>

packages/devtools/client/pages/modules/terminals.vue

Lines changed: 5 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -8,70 +8,14 @@ definePageMeta({
88
return () => !!terminals.value?.length
99
},
1010
badge() {
11-
return useTerminals().value?.filter(i => !i.isTerminated).length
11+
const terminals = useTerminals()
12+
return () => terminals.value?.filter(i => !i.isTerminated).length
1213
},
1314
})
14-
15-
const terminals = useTerminals()
16-
const route = useRoute()
17-
const router = useRouter()
18-
19-
const selected = computed(() => {
20-
const id = route.query.id as string
21-
return terminals.value?.find(t => t.id === id)
22-
})
23-
24-
function remove(id: string) {
25-
rpc.runTerminalAction(id, 'remove')
26-
router.replace('/modules/terminals')
27-
}
28-
29-
watchEffect(() => {
30-
if (!route.query.id && terminals.value?.length)
31-
router.replace(`/modules/terminals?id=${encodeURIComponent(terminals.value[0].id)}`)
32-
})
3315
</script>
3416

3517
<template>
36-
<div v-if="terminals?.length" h-full w-full of-hidden grid="~ rows-[max-content_1fr_max-content]">
37-
<!-- TODO: Refactor to have general component -->
38-
<div flex="~" border="b base" flex-1 items-center navbar-glass>
39-
<NuxtLink
40-
v-for="t of terminals"
41-
:key="t.id" border="r base"
42-
flex="~ gap-2" items-center px3 py2
43-
:class="t.id === selected?.id ? 'bg-active' : ''"
44-
:to="`/modules/terminals?id=${encodeURIComponent(t.id)}` "
45-
>
46-
<NIcon v-if="t.icon " :icon="t.icon" />
47-
<span :class="t.id === selected?.id ? '' : 'op50'">
48-
{{ t.name }}{{ t.isTerminated ? ' (terminated)' : '' }}
49-
</span>
50-
<NIconButton
51-
v-if="t.isTerminated"
52-
icon="carbon-close" mx--2
53-
@click.stop="remove(t.id)"
54-
/>
55-
</NuxtLink>
56-
</div>
57-
58-
<template v-if="selected">
59-
<TerminalView :id="selected.id" :key="selected.id" />
60-
</template>
61-
<template v-else>
62-
<div p10>
63-
Terminal <code>{{ route.query.id }}</code> not found
64-
</div>
65-
</template>
66-
</div>
67-
<div v-else h-full flex items-center justify-center>
68-
<em op50>No terminal attached</em>
69-
</div>
18+
<AuthRequiredPanel>
19+
<TerminalsPage />
20+
</AuthRequiredPanel>
7021
</template>
71-
72-
<style>
73-
.xterm {
74-
padding-left: 1rem;
75-
padding-right: 1rem;
76-
}
77-
</style>

0 commit comments

Comments
 (0)