Files
supabase/apps/studio/components/interfaces/Connect/Connect.utils.ts
Jonathan Summers-Muir f650b5ae67 Feat/connection string revamp (#30572)
* add new page

* moar

* moar

* added icons

* improve icons

* moved connect dialog to main header

* update text

* smaller screen support

* moar

* add python and sqlalchemyString

* moar

* add IPv4 warning

* moar

* Delete pooler-icons-v2.tsx

* tidy

* Delete DatabaseSettings.tsx

* tidy

* tidy

* moar. Session pooler is de-prioritized

* Update DatabaseConnectionString.tsx

* type issue

* moar

* Update DatabaseConnectionString.tsx

* Spelling

* Clean up LayoutHeader

* Clean up ConnectionPanel

* Clean up ConnectionParameters

* Last batch of clean up

* Fix loading state padding

* Shift old Connect files to new Connect folder outside of Home

* Final clean up

* Smol fix

* FIX

* Fix button link

* Fixes

* Lint

---------

Co-authored-by: Terry Sutton <saltcod@gmail.com>
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2024-12-05 17:23:14 +08:00

46 lines
1.1 KiB
TypeScript

import { ConnectionType } from './Connect.constants'
export function getProjectRef(url: string): string | null {
const regex: RegExp = /https:\/\/([^\.]+)\./
const match: RegExpMatchArray | null = url.match(regex)
if (match) {
return match[1]
} else {
return null
}
}
export const getContentFilePath = ({
connectionObject,
selectedParent,
selectedChild,
selectedGrandchild,
}: {
selectedParent: string
selectedChild: string
selectedGrandchild: string
connectionObject: ConnectionType[]
}) => {
const parent = connectionObject.find((item) => item.key === selectedParent)
if (parent) {
const child = parent.children.find((child) => child.key === selectedChild)
// check grandchild first, then child, then parent as the fallback
if (child) {
const grandchild = child.children.find((grandchild) => grandchild.key === selectedGrandchild)
if (grandchild) {
return `${selectedParent}/${selectedChild}/${selectedGrandchild}`
} else {
return `${selectedParent}/${selectedChild}`
}
} else {
return selectedParent
}
}
return ''
}