Integrations.utils.ts 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * Builds the integrations page key from pathname segments.
  3. * e.g. /project/ref/integrations → 'integrations'
  4. * /project/ref/integrations/abc-123 → 'integrations/abc-123'
  5. * Returns empty string if path is too short.
  6. */
  7. export function getIntegrationsPageFromPathname(pathname: string): string {
  8. const segments = pathname.split('/').filter(Boolean)
  9. const projectIndex = segments.indexOf('project')
  10. if (projectIndex === -1 || segments.length <= projectIndex + 2) return ''
  11. const section = segments[projectIndex + 2]
  12. const subSection = segments[projectIndex + 3]
  13. if (!section) return ''
  14. return subSection ? `${section}/${subSection}` : section
  15. }
  16. /**
  17. * Extracts the 'category' query parameter from a full URL (asPath).
  18. * Returns null if not present or asPath is invalid.
  19. */
  20. export function getCategoryParamFromAsPath(asPath: string | undefined): string | null {
  21. if (!asPath || typeof asPath !== 'string') return null
  22. const queryPart = asPath.split('?')[1]
  23. if (!queryPart) return null
  24. const params = new URLSearchParams(queryPart)
  25. return params.get('category')
  26. }