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

fix url query breaking active tab #25953

Merged
merged 4 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 3 additions & 1 deletion apps/studio/components/layouts/OrganizationLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import { ScaffoldContainer, ScaffoldDivider, ScaffoldHeader, ScaffoldTitle } fro
import SettingsLayout from './SettingsLayout/SettingsLayout'
import Link from 'next/link'
import { useOrgSubscriptionQuery } from '../../data/subscriptions/org-subscription-query'
import { useCurrentPath } from 'hooks/misc/useCurrentPath'

const OrganizationLayout = ({ children }: PropsWithChildren<{}>) => {
const selectedOrganization = useSelectedOrganization()
const router = useRouter()
const currentPath = useCurrentPath()
const { slug } = useParams()

const invoicesEnabledOnProfileLevel = useIsFeatureEnabled('billing:invoices')
Expand Down Expand Up @@ -80,7 +82,7 @@ const OrganizationLayout = ({ children }: PropsWithChildren<{}>) => {
<ScaffoldContainer>
<NavMenu className="border-none" aria-label="Organization menu navigation">
{filteredNavMenuItems.map((item) => (
<NavMenuItem key={item.label} active={item.href === router.asPath}>
<NavMenuItem key={item.label} active={currentPath === item.href}>
<Link href={item.href}>{item.label}</Link>
</NavMenuItem>
))}
Expand Down
17 changes: 17 additions & 0 deletions apps/studio/hooks/misc/useCurrentPath.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { useRouter } from 'next/router'

type UseCurrentPathOptions = {
withQuery: boolean
}
export const useCurrentPath = (options?: UseCurrentPathOptions) => {
jordienr marked this conversation as resolved.
Show resolved Hide resolved
const router = useRouter()

if (!router.isReady) {
return ''
}

const pathWithQuery = router.asPath
const currentPath = pathWithQuery.split('?')[0]

return currentPath
}
Loading