mirror of
https://github.com/supabase/supabase.git
synced 2026-05-09 18:30:12 -04:00
b997b7fb13
- add new [OrgSelector](https://github.com/supabase/supabase/pull/43238/changes#diff-214b339101a9c06864ea2755ac7246eb4c971ce74c5d3169b1385a28ee1d4227) and [ProjectBranchSelector](https://github.com/supabase/supabase/pull/43238/changes#diff-82d25c128c306b61bea7481026f58f670a229874f23ca3a1a1d78ddeabde21e0) components to the mobile navigation, replacing the previous which took up a lot of horizontal space - org/project/branch dropdowns now open up in the bottom MobileSheetNav for a better mobile ux - desktop nav remains unchanged
25 lines
1.0 KiB
TypeScript
25 lines
1.0 KiB
TypeScript
import type { ParsedUrlQuery } from 'querystring'
|
|
|
|
/**
|
|
* Sanitizes a route for project navigation (e.g. when building href for project switch).
|
|
* Truncates to avoid carrying project-specific dynamic path segments.
|
|
* Uses route segments (not query params) to determine truncation, so non-path query keys
|
|
* (e.g. sort, filter) do not incorrectly trigger or affect truncation.
|
|
*/
|
|
export function sanitizeRoute(_route: string, _routerQueries: ParsedUrlQuery): string {
|
|
const routeSegments = _route.split('/')
|
|
|
|
const hasStorageBucketSegment = routeSegments.includes('[bucketId]')
|
|
const hasSecurityAdvisorSegment = routeSegments.includes('[preset]')
|
|
const hasOtherDynamicSegment = routeSegments.some(
|
|
(s) => s.startsWith('[') && s.endsWith(']') && s !== '[ref]'
|
|
)
|
|
|
|
const needsTruncation =
|
|
hasStorageBucketSegment || hasSecurityAdvisorSegment || hasOtherDynamicSegment
|
|
if (!needsTruncation) return _route
|
|
|
|
const sliceLength = hasStorageBucketSegment || hasSecurityAdvisorSegment ? 5 : 4
|
|
return routeSegments.slice(0, sliceLength).join('/')
|
|
}
|