Skip to content

Commit 6cb24de

Browse files
authored
Migrate layout files to Svelte 5 (#2937)
* Migrate layout files to Svelte 5 * Update FeedbackButton
1 parent a47970e commit 6cb24de

File tree

11 files changed

+159
-84
lines changed

11 files changed

+159
-84
lines changed
Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
<script lang="ts">
2-
import { page } from '$app/stores';
2+
import { page } from '$app/state';
33
4-
import Icon from '$lib/holocene/icon/icon.svelte';
4+
import Button from '$lib/holocene/button.svelte';
55
6-
const href =
7-
$page.data?.settings?.feedbackURL ||
8-
'https://github.com/temporalio/ui/issues/new/choose';
6+
const href = $derived(
7+
page.data?.settings?.feedbackURL ||
8+
'https://github.com/temporalio/ui/issues/new/choose',
9+
);
910
</script>
1011

11-
<a {href} target="_blank" data-testid="give-feedback" rel="noreferrer">
12-
<div class="feedback-button">
13-
<Icon class="mr-2 text-purple-200" name="feedback" height={12} width={12} />
14-
Give Feedback
15-
</div>
16-
</a>
17-
18-
<style lang="postcss">
19-
.feedback-button {
20-
@apply flex cursor-pointer items-center justify-between px-4 py-2 text-sm text-purple-200 shadow-md;
21-
}
22-
23-
.feedback-button:hover {
24-
@apply bg-slate-700;
25-
}
26-
</style>
12+
<Button
13+
size="sm"
14+
leadingIcon="feedback"
15+
variant="ghost"
16+
class="text-brand shadow-md"
17+
{href}
18+
target="_blank"
19+
data-testid="give-feedback"
20+
rel="noreferrer"
21+
>
22+
Give Feedback
23+
</Button>
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
<script lang="ts">
2-
import { page } from '$app/stores';
2+
import type { Snippet } from 'svelte';
33
4-
$: nexusEnabled = $page.data?.systemInfo?.capabilities?.nexus;
4+
import { page } from '$app/state';
5+
6+
interface Props {
7+
children: Snippet;
8+
fallback?: Snippet;
9+
}
10+
11+
let { children, fallback }: Props = $props();
12+
let nexusEnabled = $derived(page.data?.systemInfo?.capabilities?.nexus);
513
</script>
614

715
{#if nexusEnabled}
8-
<slot />
16+
{@render children()}
917
{:else}
10-
<slot name="fallback" />
18+
{@render fallback?.()}
1119
{/if}

src/routes/(app)/+layout.svelte

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<script lang="ts">
2+
import type { Snippet } from 'svelte';
3+
24
import { afterNavigate, goto } from '$app/navigation';
3-
import { page, updated } from '$app/stores';
5+
import { page, updated } from '$app/state';
46
57
import BottomNavigation from '$lib/components/bottom-nav.svelte';
68
import DataEncoderSettings from '$lib/components/data-encoder-settings.svelte';
@@ -36,27 +38,36 @@
3638
3739
import type { DescribeNamespaceResponse as Namespace } from '$types';
3840
39-
let namespaceList: NamespaceListItem[];
41+
interface Props {
42+
children: Snippet;
43+
}
4044
41-
$: isCloud = $page.data?.settings?.runtimeEnvironment?.isCloud;
42-
$: activeNamespaceName = $page.params?.namespace ?? $lastUsedNamespace;
43-
$: namespaceNames = isCloud
44-
? [$page.params.namespace]
45-
: $namespaces.map((namespace: Namespace) => namespace?.namespaceInfo?.name);
46-
$: namespaceList = namespaceNames.map((namespace: string) => {
47-
const getHref = (namespace: string) =>
48-
isCloud ? routeForWorkflows({ namespace }) : getCurrentHref(namespace);
49-
return {
50-
namespace,
51-
onClick: (namespace: string) => {
52-
$lastUsedNamespace = namespace;
53-
goto(getHref(namespace));
54-
},
55-
};
56-
});
45+
let { children }: Props = $props();
5746
58-
$: routes = getRoutes(activeNamespaceName);
59-
$: linkList = getLinkList(routes, !!$inProgressBatchOperation);
47+
let isCloud = $derived(page.data?.settings?.runtimeEnvironment?.isCloud);
48+
let activeNamespaceName = $derived(
49+
page.params?.namespace ?? $lastUsedNamespace,
50+
);
51+
let namespaceNames = $derived(
52+
isCloud
53+
? [page.params.namespace]
54+
: $namespaces.map(
55+
(namespace: Namespace) => namespace?.namespaceInfo?.name,
56+
),
57+
);
58+
let namespaceList: NamespaceListItem[] = $derived(
59+
namespaceNames.map((namespace: string) => {
60+
const getHref = (namespace: string) =>
61+
isCloud ? routeForWorkflows({ namespace }) : getCurrentHref(namespace);
62+
return {
63+
namespace,
64+
onClick: (namespace: string) => {
65+
$lastUsedNamespace = namespace;
66+
goto(getHref(namespace));
67+
},
68+
};
69+
}),
70+
);
6071
6172
const getRoutes = (namespace: string) => {
6273
return {
@@ -71,21 +82,6 @@
7182
};
7283
};
7384
74-
$: ({
75-
workflowsRoute,
76-
schedulesRoute,
77-
batchOperationsRoute,
78-
workerDeploymentsRoute,
79-
archivalRoute,
80-
} = routes);
81-
$: showNamespacePicker = [
82-
workflowsRoute,
83-
schedulesRoute,
84-
workerDeploymentsRoute,
85-
batchOperationsRoute,
86-
archivalRoute,
87-
].some((route) => $page.url.href.includes(route));
88-
8985
const getLinkList = (
9086
{
9187
workflowsRoute,
@@ -152,7 +148,7 @@
152148
href: nexusRoute,
153149
icon: 'nexus',
154150
label: translate('nexus.nexus'),
155-
hidden: !$page.data?.systemInfo?.capabilities?.nexus,
151+
hidden: !page.data?.systemInfo?.capabilities?.nexus,
156152
isActive: (path) => {
157153
const match = path.split('/').find((segment) => segment === 'nexus');
158154
return !!match;
@@ -180,6 +176,25 @@
180176
];
181177
};
182178
179+
let routes = $derived(getRoutes(activeNamespaceName));
180+
let linkList = $derived(getLinkList(routes, !!$inProgressBatchOperation));
181+
let {
182+
workflowsRoute,
183+
schedulesRoute,
184+
batchOperationsRoute,
185+
workerDeploymentsRoute,
186+
archivalRoute,
187+
} = $derived(routes);
188+
let showNamespacePicker = $derived(
189+
[
190+
workflowsRoute,
191+
schedulesRoute,
192+
workerDeploymentsRoute,
193+
batchOperationsRoute,
194+
archivalRoute,
195+
].some((route) => page.url.href.includes(route)),
196+
);
197+
183198
function getCurrentHref(namespace: string) {
184199
const namespacePages = [
185200
{
@@ -197,7 +212,7 @@
197212
];
198213
199214
for (const { subPath, fullRoute } of namespacePages) {
200-
if ($page.url.pathname.endsWith(subPath)) {
215+
if (page.url.pathname.endsWith(subPath)) {
201216
return fullRoute;
202217
}
203218
}
@@ -210,8 +225,8 @@
210225
goto(routeForLoginPage());
211226
};
212227
213-
updated.subscribe(async (value) => {
214-
if (value) {
228+
$effect(() => {
229+
if (updated.current) {
215230
// Hard refresh when version does not match
216231
window.location.reload();
217232
}
@@ -239,7 +254,7 @@
239254
<div class="sticky top-0 z-30 hidden h-screen w-auto md:block">
240255
<SideNavigation {linkList} {isCloud}>
241256
<NavigationItem
242-
link={$page.data?.settings?.feedbackURL ||
257+
link={page.data?.settings?.feedbackURL ||
243258
'https://github.com/temporalio/ui/issues/new/choose'}
244259
label={translate('common.feedback')}
245260
icon="feedback"
@@ -264,7 +279,7 @@
264279
class="flex h-[calc(100%-2.5rem)] w-full flex-col gap-4 p-4 md:p-8"
265280
>
266281
<ErrorBoundary>
267-
<slot />
282+
{@render children()}
268283
</ErrorBoundary>
269284
</div>
270285
<BottomNavigation
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
<script lang="ts">
2-
import { page } from '$app/stores';
2+
import type { Snippet } from 'svelte';
3+
4+
import { page } from '$app/state';
35
46
import PageTitle from '$lib/components/page-title.svelte';
7+
8+
interface Props {
9+
children: Snippet;
10+
}
11+
let { children }: Props = $props();
512
</script>
613

7-
<PageTitle title="Import Event History" url={$page.url.href} />
8-
<slot />
14+
<PageTitle title="Import Event History" url={page.url.href} />
15+
{@render children()}
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
<script lang="ts">
2+
import type { Snippet } from 'svelte';
3+
24
import ImportEventsView from '$lib/pages/import-events-view.svelte';
5+
6+
interface Props {
7+
children: Snippet;
8+
}
9+
let { children }: Props = $props();
310
</script>
411

512
<ImportEventsView>
6-
<slot />
13+
{@render children()}
714
</ImportEventsView>
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
<script>
1+
<script lang="ts">
2+
import type { Snippet } from 'svelte';
3+
24
import { translate } from '$lib/i18n/translate';
5+
interface Props {
6+
children: Snippet;
7+
}
8+
let { children }: Props = $props();
39
</script>
410

511
<p class="relative flex items-center gap-4" data-testid="task-queue-title">
612
{translate('common.task-queue')}
713
</p>
8-
<slot />
14+
{@render children()}
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
<script lang="ts">
2+
import type { Snippet } from 'svelte';
3+
24
import { viewDataEncoderSettings } from '$lib/components/data-encoder-settings.svelte';
5+
6+
interface Props {
7+
children: Snippet;
8+
}
9+
let { children }: Props = $props();
310
</script>
411

512
<div
@@ -8,5 +15,5 @@
815
: 'top-0'}
916
flex h-full flex-col"
1017
>
11-
<slot />
18+
{@render children()}
1219
</div>
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
<script lang="ts">
2-
import { onDestroy } from 'svelte';
2+
import { onDestroy, type Snippet } from 'svelte';
33
44
import WorkflowRunLayout from '$lib/layouts/workflow-run-layout.svelte';
55
import { clearPreviousEventParameters } from '$lib/stores/previous-events';
66
7+
interface Props {
8+
children: Snippet;
9+
}
10+
let { children }: Props = $props();
11+
712
onDestroy(() => {
813
clearPreviousEventParameters();
914
});
1015
</script>
1116

1217
<WorkflowRunLayout>
13-
<slot />
18+
{@render children()}
1419
</WorkflowRunLayout>
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
<script>
1+
<script lang="ts">
2+
import type { Snippet } from 'svelte';
3+
24
import NexusGuard from '$lib/components/nexus-guard.svelte';
5+
6+
interface Props {
7+
children: Snippet;
8+
}
9+
10+
let { children }: Props = $props();
311
</script>
412

513
<NexusGuard>
6-
<div slot="fallback">
14+
{#snippet fallback()}
715
<p>
816
Sorry, this feature is not available in this version of Temporal. Please
917
enable Nexus or upgrade to a newer version.
1018
</p>
11-
</div>
12-
<slot />
19+
{/snippet}
20+
{@render children()}
1321
</NexusGuard>
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
<script lang="ts">
2+
import type { Snippet } from 'svelte';
3+
24
import type { LayoutData } from './$types';
35
46
import Error from '$lib/holocene/error.svelte';
57
import { translate } from '$lib/i18n/translate';
68
7-
export let data: LayoutData;
8-
9-
$: ({ endpoint } = data);
9+
interface Props {
10+
data: LayoutData;
11+
children: Snippet;
12+
}
13+
let { data, children }: Props = $props();
14+
let { endpoint } = $derived(data);
1015
</script>
1116

1217
{#if !endpoint}
@@ -18,5 +23,5 @@
1823
status={404}
1924
/>
2025
{:else}
21-
<slot />
26+
{@render children()}
2227
{/if}

0 commit comments

Comments
 (0)