Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions app/components/RouteTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ export interface TabProps {
* able to link directly to the first sidebar tab, but we of course also want
* this tab to appear active for all the sidebar tabs. See instance metrics.
*/
toPrefix?: string
activePrefix?: string
children: ReactNode
}
export const Tab = ({ to, toPrefix, children }: TabProps) => {
const isActive = useIsActivePath({ to: toPrefix || to })
export const Tab = ({ to, activePrefix, children }: TabProps) => {
const isActive = useIsActivePath({ to: activePrefix || to })
return (
<Link
role="tab"
Expand Down
44 changes: 28 additions & 16 deletions app/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
* Copyright Oxide Computer Company
*/
import cn from 'classnames'
import { NavLink, useLocation } from 'react-router'
import { Link, useLocation } from 'react-router'

import { Action16Icon, Document16Icon } from '@oxide/design-system/icons/react'

import { useIsActivePath } from '~/hooks/use-is-active-path'
import { openQuickActions } from '~/hooks/use-quick-actions'
import { Button } from '~/ui/lib/Button'
import { Truncate } from '~/ui/lib/Truncate'
Expand Down Expand Up @@ -83,29 +84,40 @@ Sidebar.Nav = ({ children, heading }: SidebarNav) => (
</div>
)

export const NavLinkItem = (props: {
type NavLinkProps = {
to: string
children: React.ReactNode
end?: boolean
disabled?: boolean
}) => {
// Only for cases where we want to spoof the path and pretend 'isActive'
activePrefix?: string
}

export const NavLinkItem = ({
to,
children,
end,
disabled,
activePrefix,
}: NavLinkProps) => {
// If the current page is the create form for this NavLinkItem's resource, highlight the NavLink in the sidebar
const currentPathIsCreateForm = useLocation().pathname.startsWith(`${props.to}-new`)
const currentPathIsCreateForm = useLocation().pathname.startsWith(`${to}-new`)
// We aren't using NavLink, as we need to occasionally use an activePrefix to create an active state for matching root paths
// so we also recreate the isActive logic here
const isActive = useIsActivePath({ to: activePrefix || to, end })
return (
<li>
<NavLink
to={props.to}
className={({ isActive }) =>
cn(linkStyles, {
'text-accent !bg-accent-secondary hover:!bg-accent-secondary-hover [&>svg]:!text-accent-tertiary':
isActive || currentPathIsCreateForm,
'pointer-events-none text-disabled': props.disabled,
})
}
end={props.end}
<Link
to={to}
className={cn(linkStyles, {
'text-accent !bg-accent-secondary hover:!bg-accent-secondary-hover [&>svg]:!text-accent-tertiary':
isActive || currentPathIsCreateForm,
'pointer-events-none text-disabled': disabled,
})}
aria-current={isActive ? 'page' : undefined}
>
{props.children}
</NavLink>
{children}
</Link>
</li>
)
}
4 changes: 2 additions & 2 deletions app/layouts/SystemLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { TopBar } from '~/components/TopBar'
import { useCurrentUser } from '~/hooks/use-current-user'
import { useQuickActions } from '~/hooks/use-quick-actions'
import { Divider } from '~/ui/lib/Divider'
import { pb } from '~/util/path-builder'
import { inventoryBase, pb } from '~/util/path-builder'

import { ContentPane, PageContainer } from './helpers'

Expand Down Expand Up @@ -102,7 +102,7 @@ export default function SystemLayout() {
<NavLinkItem to={pb.systemUtilization()}>
<Metrics16Icon /> Utilization
</NavLinkItem>
<NavLinkItem to={pb.sledInventory()}>
<NavLinkItem to={pb.sledInventory()} activePrefix={inventoryBase()}>
<Servers16Icon /> Inventory
</NavLinkItem>
<NavLinkItem to={pb.ipPools()}>
Expand Down
2 changes: 1 addition & 1 deletion app/pages/project/instances/InstancePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export default function InstancePage() {
<Tab to={pb.instanceNetworking(instanceSelector)}>Networking</Tab>
<Tab
to={pb.instanceCpuMetrics(instanceSelector)}
toPrefix={instanceMetricsBase(instanceSelector)}
activePrefix={instanceMetricsBase(instanceSelector)}
>
Metrics
</Tab>
Expand Down
2 changes: 1 addition & 1 deletion app/pages/system/inventory/SledsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const handle = { crumb: 'Sleds' }
const colHelper = createColumnHelper<Sled>()
const staticCols = [
colHelper.accessor('id', {
cell: makeLinkCell((sledId) => pb.sled({ sledId })),
cell: makeLinkCell((sledId) => pb.sledInstances({ sledId })),
}),
// TODO: colHelper.accessor('baseboard.serviceAddress', { header: 'service address' }),
colHelper.group({
Expand Down
2 changes: 1 addition & 1 deletion app/pages/system/inventory/sled/SledPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function clientLoader({ params }: LoaderFunctionArgs) {
}
export const handle = makeCrumb(
(p) => truncate(p.sledId!, 12, 'middle'),
(p) => pb.sled({ sledId: p.sledId! })
(p) => pb.sledInstances({ sledId: p.sledId! })
)

export default function SledPage() {
Expand Down
18 changes: 0 additions & 18 deletions app/util/__snapshots__/path-builder.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -529,24 +529,6 @@ exports[`breadcrumbs 2`] = `
"path": "/system/silos",
},
],
"sled (/system/inventory/sleds/5c56b522-c9b8-49e4-9f9a-8d52a89ec3e0/instances)": [
{
"label": "Inventory",
"path": "/system/inventory",
},
{
"label": "Sleds",
"path": "/system/inventory/sleds",
},
{
"label": "5c56b…ec3e0",
"path": "/system/inventory/sleds/5c56b522-c9b8-49e4-9f9a-8d52a89ec3e0/instances",
},
{
"label": "Instances",
"path": "/system/inventory/sleds/5c56b522-c9b8-49e4-9f9a-8d52a89ec3e0/instances",
},
],
"sledInstances (/system/inventory/sleds/5c56b522-c9b8-49e4-9f9a-8d52a89ec3e0/instances)": [
{
"label": "Inventory",
Expand Down
1 change: 0 additions & 1 deletion app/util/path-builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ test('path builder', () => {
"siloUtilization": "/utilization",
"silos": "/system/silos",
"silosNew": "/system/silos-new",
"sled": "/system/inventory/sleds/5c56b522-c9b8-49e4-9f9a-8d52a89ec3e0/instances",
"sledInstances": "/system/inventory/sleds/5c56b522-c9b8-49e4-9f9a-8d52a89ec3e0/instances",
"sledInventory": "/system/inventory/sleds",
"snapshotImagesNew": "/projects/p/snapshots/sn/images-new",
Expand Down
10 changes: 5 additions & 5 deletions app/util/path-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ const instanceBase = ({ project, instance }: PP.Instance) =>
`${pb.instances({ project })}/${instance}`
const vpcBase = ({ project, vpc }: PP.Vpc) => `${pb.vpcs({ project })}/${vpc}`

/** Don't use this for links. only exported for use as toPrefix on metrics tab */
/** Don't use these for links. only exported for use with activePrefix */
export const instanceMetricsBase = ({ project, instance }: PP.Instance) =>
`${instanceBase({ project, instance })}/metrics`
export const inventoryBase = () => '/system/inventory'

export const pb = {
projects: () => `/projects`,
Expand Down Expand Up @@ -109,10 +110,9 @@ export const pb = {
ipPoolEdit: (params: PP.IpPool) => `${pb.ipPool(params)}/edit`,
ipPoolRangeAdd: (params: PP.IpPool) => `${pb.ipPool(params)}/ranges-add`,

sledInventory: () => '/system/inventory/sleds',
diskInventory: () => '/system/inventory/disks',
sled: ({ sledId }: PP.Sled) => `/system/inventory/sleds/${sledId}/instances`,
sledInstances: ({ sledId }: PP.Sled) => `/system/inventory/sleds/${sledId}/instances`,
sledInventory: () => `${inventoryBase()}/sleds`,
diskInventory: () => `${inventoryBase()}/disks`,
sledInstances: ({ sledId }: PP.Sled) => `${pb.sledInventory()}/${sledId}/instances`,

silos: () => '/system/silos',
silosNew: () => '/system/silos-new',
Expand Down
Loading