Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix(cmdk): type errors

Greg Richardson7ee8a624dc12
diff --git a/packages/ui/src/components/Command/AiCommand.tsx b/packages/ui/src/components/Command/AiCommand.tsx
index 7d34e38f364..721fb2c5dbb 100644
--- a/packages/ui/src/components/Command/AiCommand.tsx
+++ b/packages/ui/src/components/Command/AiCommand.tsx
@@ -23,9 +23,14 @@ const questions = [
function getEdgeFunctionUrl() {
const supabaseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL?.replace(/\/$/, '')
- // if (IS_PLATFORM) {
- if (true) {
- // @ts-ignore
+ if (!supabaseUrl) {
+ throw new Error('Missing environment variable NEXT_PUBLIC_SUPABASE_URL')
+ }
+
+ // https://github.com/supabase/supabase-js/blob/10d3423506cbd56345f7f6ab2ec2093c8db629d4/src/SupabaseClient.ts#L96
+ const isPlatform = supabaseUrl.match(/(supabase\.co)|(supabase\.in)/)
+
+ if (isPlatform) {
const [schemeAndProjectId, domain, tld] = supabaseUrl.split('.')
return `${schemeAndProjectId}.functions.${domain}.${tld}`
} else {
diff --git a/packages/ui/src/components/Command/Command.utils.tsx b/packages/ui/src/components/Command/Command.utils.tsx
index 09397c85211..aeb016d1341 100644
--- a/packages/ui/src/components/Command/Command.utils.tsx
+++ b/packages/ui/src/components/Command/Command.utils.tsx
@@ -278,13 +278,15 @@ export interface TextHighlighterProps
}
export const TextHighlighter = ({ text, query, ...props }: TextHighlighterProps) => {
- const highlightMatches = (text) => {
+ const highlightMatches = (text?: string) => {
+ if (!text) {
+ return ''
+ }
+
if (!query) {
return text
}
- if (!text) return ''
-
const regex = new RegExp(query, 'gi')
return text.replace(regex, (match) => `<span class="font-bold text-scale-1200">${match}</span>`)
}
diff --git a/packages/ui/src/components/Command/CommandMenu.tsx b/packages/ui/src/components/Command/CommandMenu.tsx
index 34084d23021..18a9639045f 100644
--- a/packages/ui/src/components/Command/CommandMenu.tsx
+++ b/packages/ui/src/components/Command/CommandMenu.tsx
@@ -64,7 +64,7 @@ const SearchOnlyItem = ({ children, isSubItem, ...props }: any) => {
const CommandMenu = () => {
const router = useRouter()
- const commandInputRef = useRef<ElementRef<typeof CommandInput>>()
+ const commandInputRef = useRef<ElementRef<typeof CommandInput>>(null)
const { isOpen, setIsOpen, actions, search, setSearch, pages, setPages, currentPage } =
useCommandMenu()
@@ -122,7 +122,7 @@ const CommandMenu = () => {
commandInputRef.current?.focus()
}
- const showCommandInput = !CHAT_ROUTES.includes(currentPage)
+ const showCommandInput = !currentPage || !CHAT_ROUTES.includes(currentPage)
return (
<>
diff --git a/packages/ui/src/components/Command/DocsSearch.tsx b/packages/ui/src/components/Command/DocsSearch.tsx
index aa1514e0dee..faa0e0f7630 100644
--- a/packages/ui/src/components/Command/DocsSearch.tsx
+++ b/packages/ui/src/components/Command/DocsSearch.tsx
@@ -24,8 +24,30 @@ const questions = [
'How do I set up authentication?',
]
+export enum PageType {
+ Markdown = 'markdown',
+ Reference = 'reference',
+}
+
+export interface PageSection {
+ slug: string
+ heading: string
+}
+
+export interface PageMetadata {
+ title: string
+ description: string
+}
+
+export interface PageResult {
+ type: PageType
+ path: string
+ meta: PageMetadata
+ sections: PageSection[]
+}
+
const DocsSearch = () => {
- const [results, setResults] = useState<any[]>()
+ const [results, setResults] = useState<PageResult[]>()
const [hasSearchError, setHasSearchError] = useState(false)
const supabaseClient = useSupabaseClient()
const { isLoading, setIsLoading, search, setSearch } = useCommandMenu()
@@ -97,7 +119,9 @@ const DocsSearch = () => {
/>
)
- const IconContainer = (props) => (
+ const IconContainer = (
+ props: React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>
+ ) => (
<div
className="
transition
@@ -165,7 +189,7 @@ const DocsSearch = () => {
onSelect={() => {
// TODO: replace with Next.js router/Link when cross-project link logic solved
window.location.assign(
- `/docs/${page.path}${page.type === 'reference' ? '/' : '#'}${
+ `/docs/${page.path}${page.type === PageType.Reference ? '/' : '#'}${
section.slug
}`
)
diff --git a/packages/ui/src/components/Command/SearchButton.tsx b/packages/ui/src/components/Command/SearchButton.tsx
index 703d495b17a..fef19ceff21 100644
--- a/packages/ui/src/components/Command/SearchButton.tsx
+++ b/packages/ui/src/components/Command/SearchButton.tsx
@@ -8,7 +8,7 @@ const SearchButton = ({
}: PropsWithChildren<
DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>
>) => {
- const searchButtonRef = useRef<HTMLButtonElement>()
+ const searchButtonRef = useRef<HTMLButtonElement>(null)
const { setIsOpen } = useCommandMenu()
return (
diff --git a/packages/ui/src/types/sse.d.ts b/packages/ui/src/types/sse.d.ts
new file mode 100644
index 00000000000..dbf97ac0836
--- /dev/null
+++ b/packages/ui/src/types/sse.d.ts
@@ -0,0 +1,12 @@
+declare module 'sse.js' {
+ export type SSEOptions = EventSourceInit & {
+ headers?: Record<string, string>
+ payload?: string
+ method?: string
+ }
+
+ export class SSE extends EventSource {
+ constructor(url: string | URL, sseOptions?: SSEOptions)
+ stream(): void
+ }
+}
diff --git a/packages/ui/tsconfig.json b/packages/ui/tsconfig.json
new file mode 100644
index 00000000000..8637a0ecaf7
--- /dev/null
+++ b/packages/ui/tsconfig.json
@@ -0,0 +1,14 @@
+{
+ "extends": "tsconfig/react-library.json",
+ "compilerOptions": {
+ "resolveJsonModule": true
+ },
+ "include": [
+ "."
+ ],
+ "exclude": [
+ "dist",
+ "build",
+ "node_modules"
+ ]
+}
\ No newline at end of file