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
11 changes: 9 additions & 2 deletions app/components/RouteTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,24 @@ export function RouteTabs({

export interface TabProps {
to: string
/**
* Used in rare cases when a tab has sidebar tabs underneath and we want to be
* 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
children: ReactNode
}
export const Tab = ({ to, children }: TabProps) => {
const isActive = useIsActivePath({ to })
export const Tab = ({ to, toPrefix, children }: TabProps) => {
const isActive = useIsActivePath({ to: toPrefix || to })
return (
<Link
role="tab"
to={to}
className={cn('ox-tab', { 'is-selected': isActive })}
tabIndex={isActive ? 0 : -1}
aria-selected={isActive}
data-state={isActive ? 'active' : 'inactive'}
>
<div>{children}</div>
</Link>
Expand Down
9 changes: 7 additions & 2 deletions app/pages/project/instances/InstancePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import { PropertiesTable } from '~/ui/lib/PropertiesTable'
import { Spinner } from '~/ui/lib/Spinner'
import { Tooltip } from '~/ui/lib/Tooltip'
import { truncate } from '~/ui/lib/Truncate'
import { pb } from '~/util/path-builder'
import { instanceMetricsBase, pb } from '~/util/path-builder'
import { pluralize } from '~/util/str'
import { GiB } from '~/util/units'

Expand Down Expand Up @@ -256,7 +256,12 @@ export default function InstancePage() {
<RouteTabs fullWidth>
<Tab to={pb.instanceStorage(instanceSelector)}>Storage</Tab>
<Tab to={pb.instanceNetworking(instanceSelector)}>Networking</Tab>
<Tab to={pb.instanceCpuMetrics(instanceSelector)}>Metrics</Tab>
<Tab
to={pb.instanceCpuMetrics(instanceSelector)}
toPrefix={instanceMetricsBase(instanceSelector)}
>
Metrics
</Tab>
<Tab to={pb.instanceConnect(instanceSelector)}>Connect</Tab>
<Tab to={pb.instanceSettings(instanceSelector)}>Settings</Tab>
</RouteTabs>
Expand Down
20 changes: 12 additions & 8 deletions app/ui/styles/components/Tabs.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,25 @@
}

/* Active states */
.ox-tab.is-selected {
.ox-tab[data-state='active'] {
@apply text-accent border-accent;
}

.ox-tab.is-selected:hover > * {
@apply !bg-accent-secondary;
.ox-tabs-list .ox-tab[data-state='active']:hover > * {
@apply bg-accent-secondary;
}

/* Badge styles */
.ox-tab > .ox-badge {
@apply -mt-1 select-none text-current;
}

.ox-tab:not(.is-selected) > .ox-badge {
.ox-tab[data-state='inactive'] > .ox-badge {
@apply bg-disabled;
}

.ox-tab.is-selected > .ox-badge {
@apply bg-accent-secondary;
.ox-tab[data-state='active'] > .ox-badge {
@apply bg-accent-secondary-hover;
}

/* Full width variants */
Expand All @@ -81,7 +81,7 @@
border-bottom: none;
}

.ox-side-tabs .ox-tab.is-selected {
.ox-side-tabs-list .ox-tab[data-state='active'] {
@apply text-accent bg-accent-secondary;
border: none;
}
Expand All @@ -90,6 +90,10 @@
@apply mx-0 ml-4;
}

.ox-side-tabs-list .ox-tab:not(.is-selected):hover {
.ox-side-tabs-list .ox-tab[data-state='active']:hover {
@apply bg-accent-secondary-hover;
}

.ox-side-tabs-list .ox-tab:not([data-state='active']):hover {
@apply text-default bg-hover;
}
4 changes: 3 additions & 1 deletion app/util/path-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const projectBase = ({ project }: PP.Project) => `${pb.projects()}/${project}`
const instanceBase = ({ project, instance }: PP.Instance) =>
`${pb.instances({ project })}/${instance}`
const vpcBase = ({ project, vpc }: PP.Vpc) => `${pb.vpcs({ project })}/${vpc}`
const instanceMetricsBase = ({ project, instance }: PP.Instance) =>

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

export const pb = {
Expand Down
Loading