|
1 | 1 | <script lang="ts"> |
| 2 | + import type { Snippet } from 'svelte'; |
| 3 | +
|
2 | 4 | import { afterNavigate, goto } from '$app/navigation'; |
3 | | - import { page, updated } from '$app/stores'; |
| 5 | + import { page, updated } from '$app/state'; |
4 | 6 |
|
5 | 7 | import BottomNavigation from '$lib/components/bottom-nav.svelte'; |
6 | 8 | import DataEncoderSettings from '$lib/components/data-encoder-settings.svelte'; |
|
36 | 38 |
|
37 | 39 | import type { DescribeNamespaceResponse as Namespace } from '$types'; |
38 | 40 |
|
39 | | - let namespaceList: NamespaceListItem[]; |
| 41 | + interface Props { |
| 42 | + children: Snippet; |
| 43 | + } |
40 | 44 |
|
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(); |
57 | 46 |
|
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 | + ); |
60 | 71 |
|
61 | 72 | const getRoutes = (namespace: string) => { |
62 | 73 | return { |
|
71 | 82 | }; |
72 | 83 | }; |
73 | 84 |
|
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 | | -
|
89 | 85 | const getLinkList = ( |
90 | 86 | { |
91 | 87 | workflowsRoute, |
|
152 | 148 | href: nexusRoute, |
153 | 149 | icon: 'nexus', |
154 | 150 | label: translate('nexus.nexus'), |
155 | | - hidden: !$page.data?.systemInfo?.capabilities?.nexus, |
| 151 | + hidden: !page.data?.systemInfo?.capabilities?.nexus, |
156 | 152 | isActive: (path) => { |
157 | 153 | const match = path.split('/').find((segment) => segment === 'nexus'); |
158 | 154 | return !!match; |
|
180 | 176 | ]; |
181 | 177 | }; |
182 | 178 |
|
| 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 | +
|
183 | 198 | function getCurrentHref(namespace: string) { |
184 | 199 | const namespacePages = [ |
185 | 200 | { |
|
197 | 212 | ]; |
198 | 213 |
|
199 | 214 | for (const { subPath, fullRoute } of namespacePages) { |
200 | | - if ($page.url.pathname.endsWith(subPath)) { |
| 215 | + if (page.url.pathname.endsWith(subPath)) { |
201 | 216 | return fullRoute; |
202 | 217 | } |
203 | 218 | } |
|
210 | 225 | goto(routeForLoginPage()); |
211 | 226 | }; |
212 | 227 |
|
213 | | - updated.subscribe(async (value) => { |
214 | | - if (value) { |
| 228 | + $effect(() => { |
| 229 | + if (updated.current) { |
215 | 230 | // Hard refresh when version does not match |
216 | 231 | window.location.reload(); |
217 | 232 | } |
|
239 | 254 | <div class="sticky top-0 z-30 hidden h-screen w-auto md:block"> |
240 | 255 | <SideNavigation {linkList} {isCloud}> |
241 | 256 | <NavigationItem |
242 | | - link={$page.data?.settings?.feedbackURL || |
| 257 | + link={page.data?.settings?.feedbackURL || |
243 | 258 | 'https://github.com/temporalio/ui/issues/new/choose'} |
244 | 259 | label={translate('common.feedback')} |
245 | 260 | icon="feedback" |
|
264 | 279 | class="flex h-[calc(100%-2.5rem)] w-full flex-col gap-4 p-4 md:p-8" |
265 | 280 | > |
266 | 281 | <ErrorBoundary> |
267 | | - <slot /> |
| 282 | + {@render children()} |
268 | 283 | </ErrorBoundary> |
269 | 284 | </div> |
270 | 285 | <BottomNavigation |
|
0 commit comments