Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight active link in nav bar #2324

Merged
merged 3 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib/components/side-nav.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
tooltip={item?.tooltip || item.label}
external={item?.external}
animate={item?.animate}
isActive={item.isActive}
/>
{/if}
{/each}
Expand Down
11 changes: 10 additions & 1 deletion src/lib/holocene/navigation/navigation-item.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script lang="ts">
import { page } from '$app/stores';

import type { IconName } from '$lib/holocene/icon';
import { navOpen } from '$lib/stores/nav-open';

Expand All @@ -11,6 +13,7 @@
export let external = false;
export let animate = false;
export let disabled = false;
export let isActive: (path: string) => boolean = () => false;

$: rel = external ? 'noopener noreferrer' : '';
$: target = external ? '_blank' : '';
Expand All @@ -29,7 +32,8 @@
aria-disabled={disabled}
class:disabled
tabindex={disabled ? -1 : 0}
class="mb-1 flex items-center whitespace-nowrap rounded-lg p-1 pl-2 text-sm font-medium hover:bg-white hover:text-black group-[.surface-primary]:hover:bg-black group-[.surface-primary]:hover:text-white group-[.surface-primary]:dark:hover:bg-white group-[.surface-primary]:dark:hover:text-black"
class:active={isActive($page.url.href)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get a lot of errors for this lil guy

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whenever you change namespace in namespace switcher it errors and crashes UI

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a fix. Looks like isActive was still undefined despite setting () => false as the default initial value πŸ€”

class="mb-1 flex items-center whitespace-nowrap rounded-lg p-1 pl-2 text-sm font-medium"
class:text-disabled={disabled}
>
<div
Expand All @@ -53,4 +57,9 @@
a.disabled {
@apply pointer-events-none cursor-not-allowed opacity-50;
}

a:hover,
a.active {
@apply bg-white text-black group-[.surface-primary]:bg-black group-[.surface-primary]:text-white group-[.surface-primary]:dark:bg-white group-[.surface-primary]:dark:text-black;
}
</style>
1 change: 1 addition & 0 deletions src/lib/types/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,5 @@ export type NavLinkListItem = {
enabled?: boolean;
hidden?: boolean;
animate?: boolean;
isActive?: (path: string) => boolean;
};
36 changes: 29 additions & 7 deletions src/routes/(app)/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -56,45 +56,67 @@
namespace: string,
inProgressBatch: boolean,
): NavLinkListItem[] => {
const workflowsRoute = routeForWorkflows({ namespace });
const schedulesRoute = routeForSchedules({ namespace });
const batchOperationsRoute = routeForBatchOperations({ namespace });
const archivalRoute = routeForArchivalWorkfows({ namespace });
const namespacesRoute = routeForNamespaces();
const nexusRoute = routeForNexus();
const historyImportRoute = routeForEventHistoryImport();

Alex-Tideman marked this conversation as resolved.
Show resolved Hide resolved
return [
{
href: routeForWorkflows({ namespace }),
href: workflowsRoute,
icon: 'workflow',
label: translate('common.workflows'),
isActive: (path) => Boolean(path.includes(workflowsRoute)),
},
{
href: routeForSchedules({ namespace }),
href: schedulesRoute,
icon: 'schedules',
label: translate('common.schedules'),
isActive: (path) => Boolean(path.includes(schedulesRoute)),
},
{
href: routeForBatchOperations({ namespace }),
href: batchOperationsRoute,
icon: 'batch-operation',
label: translate('batch.nav-title'),
tooltip: translate('batch.list-page-title'),
animate: inProgressBatch,
isActive: (path) => Boolean(path.includes(batchOperationsRoute)),
},
{
href: routeForArchivalWorkfows({ namespace }),
href: archivalRoute,
icon: 'archives',
label: translate('common.archive'),
isActive: (path) => Boolean(path.includes(archivalRoute)),
},
{
href: routeForNamespaces(),
href: namespacesRoute,
icon: 'namespace',
label: translate('common.namespaces'),
divider: true,
isActive: (path) =>
Boolean(
path.includes(namespacesRoute) &&
!path.includes(workflowsRoute) &&
!path.includes(schedulesRoute) &&
!path.includes(batchOperationsRoute) &&
!path.includes(archivalRoute),
),
},
{
href: routeForNexus(),
href: nexusRoute,
icon: 'nexus',
label: translate('nexus.nexus'),
hidden: !$page.data?.systemInfo?.capabilities?.nexus,
isActive: (path) => Boolean(path.includes(nexusRoute)),
},
{
href: routeForEventHistoryImport(),
href: historyImportRoute,
icon: 'import',
label: translate('common.import'),
isActive: (path) => Boolean(path.includes(historyImportRoute)),
},
{
href: 'http://docs.temporal.io',
Expand Down
Loading