Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set schema dropdown if a table is selected #28560

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 2,7 @@ import { PermissionAction } from '@supabase/shared-types/out/constants'
import { partition } from 'lodash'
import { Filter, Plus } from 'lucide-react'
import { useRouter } from 'next/router'
import { useMemo, useState } from 'react'
import { useEffect, useMemo, useState } from 'react'

import { useParams } from 'common'
import { ProtectedSchemaModal } from 'components/interfaces/Database/ProtectedSchemaWarning'
Expand Down Expand Up @@ -38,6 38,7 @@ import {
} from 'ui-patterns/InnerSideMenu'
import { useProjectContext } from '../ProjectLayout/ProjectContext'
import EntityListItem from './EntityListItem'
import { useTableQuery } from 'data/tables/table-query'

const TableEditorMenu = () => {
const router = useRouter()
Expand All @@ -59,7 60,6 @@ const TableEditorMenu = () => {
isSuccess,
isError,
error,
refetch,
hasNextPage,
isFetchingNextPage,
fetchNextPage,
Expand Down Expand Up @@ -90,17 90,28 @@ const TableEditorMenu = () => {
const schema = schemas?.find((schema) => schema.name === snap.selectedSchemaName)
const canCreateTables = useCheckPermissions(PermissionAction.TENANT_SQL_ADMIN_WRITE, 'tables')

const refreshTables = async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks like it's been unused for a while

await refetch()
}

refreshTables
const [protectedSchemas] = partition(
(schemas ?? []).sort((a, b) => a.name.localeCompare(b.name)),
(schema) => EXCLUDED_SCHEMAS.includes(schema?.name ?? '')
)
const isLocked = protectedSchemas.some((s) => s.id === schema?.id)

const { data: selectedTable } = useTableQuery(
{
projectRef: project?.ref,
connectionString: project?.connectionString,
id: Number(id),
},
// only run if we have a selected table
{ enabled: Boolean(id) }
)

useEffect(() => {
if (selectedTable) {
snap.setSelectedSchemaName(selectedTable.schema)
}
}, [selectedTable])

return (
<>
<div
Expand Down