The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Extract language picker
Terry Sutton393955b5d00f
diff --git a/studio/components/interfaces/Docs/Docs.types.ts b/studio/components/interfaces/Docs/Docs.types.tsnew file mode 100644index 00000000000..e6f3e8cb322--- /dev/null+++ b/studio/components/interfaces/Docs/Docs.types.ts@@ -0,0 +1,4 @@+export type showApiKey = {+ key: string+ name: string+}\ No newline at end of filediff --git a/studio/components/interfaces/Docs/ResourceContent.tsx b/studio/components/interfaces/Docs/ResourceContent.tsxindex 784b5018793..df8634208be 100644--- a/studio/components/interfaces/Docs/ResourceContent.tsx+++ b/studio/components/interfaces/Docs/ResourceContent.tsx@@ -30,7 +30,7 @@ const ResourceContent = ({return (<>- <h2 className="text-scale-1200 mt-0 flex items-center px-6 gap-2">+ <h2 className="doc-section__table-name text-scale-1200 mt-0 flex items-center px-6 gap-2"><span className="bg-slate-300 dark:bg-slate-400 p-2 rounded-lg"><IconTable size="small" /></span>@@ -54,7 +54,7 @@ const ResourceContent = ({<div>{properties.map((x) => (<div className="doc-section py-4" key={x.id}>- <article className="text">+ <div className="text"><Paramkey={x.id}name={x.id}@@ -68,8 +68,8 @@ const ResourceContent = ({}}onDesciptionUpdated={refreshDocs}/>- </article>- <article className="code">+ </div>+ <div className="code"><CodeSnippetselectedLang={selectedLang}snippet={Snippets.readColumns({@@ -80,7 +80,7 @@ const ResourceContent = ({columnName: x.id,})}/>- </article>+ </div></div>))}</div>diff --git a/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx b/studio/components/interfaces/TableGridEditor/TableGridEditor.tsxindex 1512a0446ae..b58d6f3375f 100644--- a/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx+++ b/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx@@ -11,13 +11,14 @@ import GridHeaderActions from './GridHeaderActions'import NotFoundState from './NotFoundState'import SidePanelEditor from './SidePanelEditor'import { Dictionary, parseSupaTable, SupabaseGrid, SupabaseGridRef } from 'components/grid'-import { SidePanel } from 'ui'+import { IconBookOpen, SidePanel } from 'ui'import ActionBar from './SidePanelEditor/ActionBar'import { GeneralContent, ResourceContent } from '../Docs'import { useProjectSettingsQuery } from 'data/config/project-settings-query'import { snakeToCamel } from 'lib/helpers'import useSWR from 'swr'import { get } from 'lib/common/fetch'+import LangSelector from 'components/to-be-cleaned/Docs/LangSelector'interface Props {/** Theme for the editor */@@ -78,9 +79,14 @@ const TableGridEditor: FC<Props> = ({settings?.autoApiService.endpoint ?? '-'}`,}- const [selectedLang, setSelectedLang] = useState<any>('js')+ const DEFAULT_KEY = { name: 'hide', key: 'SUPABASE_KEY' }+const [encryptedColumns, setEncryptedColumns] = useState([])const [apiPreviewPanelOpen, setApiPreviewPanelOpen] = useState(false)++ const [selectedLang, setSelectedLang] = useState<any>('js')+ const [showApiKey, setShowApiKey] = useState<any>(DEFAULT_KEY)+const isVaultEnabled = useFlag('vaultExtension')const getEncryptedColumns = async (table: any) => {@@ -263,7 +269,12 @@ const TableGridEditor: FC<Props> = ({size="xlarge"visible={apiPreviewPanelOpen}onCancel={() => console.log('cancel')}- header={<span>Connect to your table</span>}+ header={+ <span className="flex items-center gap-2">+ <IconBookOpen size="tiny" />+ API+ </span>+ }customFooter={<ActionBarbackButtonLabel="Back"@@ -273,14 +284,25 @@ const TableGridEditor: FC<Props> = ({/>}>- <div className="Docs">+ <div className="Docs Docs--table-editor"><SidePanel.Content>+ <div className="sticky top-0 bg-scale-200 z-10">+ <LangSelector+ selectedLang={selectedLang}+ setSelectedLang={setSelectedLang}+ showApiKey={showApiKey}+ setShowApiKey={setShowApiKey}+ apiKey={API_KEY}+ autoApiService={autoApiService}+ />+ </div><GeneralContentautoApiService={autoApiService}selectedLang={selectedLang}showApiKey={true}page={page}/>+{jsonSchema?.definitions && (<ResourceContentautoApiService={autoApiService}diff --git a/studio/components/to-be-cleaned/Docs/CodeSnippet.js b/studio/components/to-be-cleaned/Docs/CodeSnippet.jsindex 02bd93d5df3..4cf630d02b8 100644--- a/studio/components/to-be-cleaned/Docs/CodeSnippet.js+++ b/studio/components/to-be-cleaned/Docs/CodeSnippet.js@@ -1,6 +1,7 @@import SimpleCodeBlock from 'components/to-be-cleaned/SimpleCodeBlock'const CodeSnippet = ({ selectedLang, snippet }) => {+ console.log(snippet, 'snippet')if (!snippet[selectedLang]) return nullreturn (<>diff --git a/studio/components/to-be-cleaned/Docs/LangSelector.tsx b/studio/components/to-be-cleaned/Docs/LangSelector.tsxnew file mode 100644index 00000000000..2386ff91d3d--- /dev/null+++ b/studio/components/to-be-cleaned/Docs/LangSelector.tsx@@ -0,0 +1,110 @@+import { FC } from 'react'+import { Button, Dropdown, IconKey } from 'ui'+import { checkPermissions } from 'hooks'+import { PermissionAction } from '@supabase/shared-types/out/constants'++import { showApiKey } from 'components/interfaces/Docs/docs.types'++const DEFAULT_KEY = { name: 'hide', key: 'SUPABASE_KEY' }++interface Props {+ selectedLang: string+ setSelectedLang: (selectedLang: string) => void+ showApiKey: showApiKey+ setShowApiKey: (showApiKey: showApiKey) => void+ apiKey: string | undefined+ autoApiService: any+}++const LangSelector: FC<Props> = ({+ selectedLang,+ setSelectedLang,+ showApiKey,+ setShowApiKey,+ apiKey,+ autoApiService,+}) => {+ const canReadServiceKey = checkPermissions(+ PermissionAction.READ,+ 'service_api_keys.service_role_key'+ )++ return (+ <div className="bg-slate-200 dark:bg-scale-300 p-1 w-1/2 ml-auto">+ <div className="z-0 flex justify-end">+ <button+ type="button"+ onClick={() => setSelectedLang('js')}+ className={`${+ selectedLang == 'js'+ ? 'bg-scale-300 font-medium text-scale-1200 dark:bg-scale-200'+ : 'bg-scale-100 text-scale-900 dark:bg-scale-100'+ } relative inline-flex items-center border-r border-scale-200 p-1 px-2 text-sm transition hover:text-scale-1200 focus:outline-none`}+ >+ JavaScript+ </button>+ <button+ type="button"+ onClick={() => setSelectedLang('bash')}+ className={`${+ selectedLang == 'bash'+ ? 'bg-scale-300 font-medium text-scale-1200 dark:bg-scale-200'+ : 'bg-scale-100 text-scale-900 dark:bg-scale-100'+ } relative inline-flex items-center border-r border-scale-200 p-1 px-2 text-sm transition hover:text-scale-1200 focus:outline-none`}+ >+ Bash+ </button>+ {selectedLang == 'bash' && (+ <div className="flex">+ <div className="flex items-center gap-2 p-1 pl-2 text-xs text-scale-900">+ <IconKey size={12} strokeWidth={1.5} />+ <span>Project API key :</span>+ </div>+ <Dropdown+ align="end"+ side="bottom"+ className="cursor-pointer border-none bg-transparent p-0 pl-2 pr-8 text-sm text-scale-900"+ overlay={+ <>+ <Dropdown.Item key="hide" onClick={() => setShowApiKey(DEFAULT_KEY)}>+ hide+ </Dropdown.Item>+ {apiKey && (+ <Dropdown.Item+ key="anon"+ onClick={() =>+ setShowApiKey({+ key: apiKey,+ name: 'anon (public)',+ })+ }+ >+ anon (public)+ </Dropdown.Item>+ )}+ {canReadServiceKey && (+ <Dropdown.Item+ key="service"+ onClick={() =>+ setShowApiKey({+ key: autoApiService.serviceApiKey,+ name: 'service_role (secret)',+ })+ }+ >+ service_role (secret)+ </Dropdown.Item>+ )}+ </>+ }+ >+ <Button type="default">{showApiKey.name}</Button>+ </Dropdown>+ </div>+ )}+ </div>+ </div>+ )+}++export default LangSelectordiff --git a/studio/components/to-be-cleaned/Docs/Param.tsx b/studio/components/to-be-cleaned/Docs/Param.tsxindex 3ff95984a62..247cfd9d4c9 100644--- a/studio/components/to-be-cleaned/Docs/Param.tsx+++ b/studio/components/to-be-cleaned/Docs/Param.tsx@@ -51,7 +51,7 @@ const Param: FC<Props> = ({</label><div className="flex items-center gap-4">- <span className="font-bold text-lg text-scale-1100">{name}</span>+ <span className="text-lg text-scale-1100 pb-0.5">{name}</span></div></div></div>diff --git a/studio/pages/project/[ref]/api/index.tsx b/studio/pages/project/[ref]/api/index.tsxindex 4a793b45190..1ad4f4968f6 100644--- a/studio/pages/project/[ref]/api/index.tsx+++ b/studio/pages/project/[ref]/api/index.tsx@@ -12,6 +12,7 @@ import { DocsLayout } from 'components/layouts'import { GeneralContent, ResourceContent, RpcContent } from 'components/interfaces/Docs'import { PermissionAction } from '@supabase/shared-types/out/constants'import { useProjectSettingsQuery } from 'data/config/project-settings-query'+import LangSelector from 'components/to-be-cleaned/Docs/LangSelector'const PageContext = createContext(null)@@ -128,10 +129,18 @@ const DocView: FC<any> = observer(({}) => {const PAGE_KEY: any = resource || rpc || page || 'index'return (- <div className="Docs h-full w-full overflow-y-auto" key={PAGE_KEY}>+ <div className="Docs Docs--api-page h-full w-full overflow-y-auto" key={PAGE_KEY}><div className="Docs--inner-wrapper"><div className="sticky top-0 z-40 flex w-full flex-row-reverse ">- <div className="bg-scale-100 dark:bg-scale-300" style={{ width: '50%' }}>+ <LangSelector+ selectedLang={selectedLang}+ setSelectedLang={setSelectedLang}+ showApiKey={showApiKey}+ setShowApiKey={setShowApiKey}+ apiKey={API_KEY}+ autoApiService={autoApiService}+ />+ {/* <div className="bg-scale-100 dark:bg-scale-300" style={{ width: '50%' }}><div className="z-0 flex "><buttontype="button"@@ -202,7 +211,7 @@ const DocView: FC<any> = observer(({}) => {</div>)}</div>- </div>+ </div> */}</div><div className="">{resource ? (diff --git a/studio/styles/ui.scss b/studio/styles/ui.scssindex d4515a3f090..2fa8033d916 100644--- a/studio/styles/ui.scss+++ b/studio/styles/ui.scss@@ -234,6 +234,10 @@@apply prose prose-docs prose-sm max-w-none;}+ &.Docs--table-editor .doc-section__table-name {+ @apply mt-12;+ }+.text {@apply p-4 px-6 w-1/2;max-width: 50%;