mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 09:55:06 +03:00
Remove duplicated types-query, use enumerated-types-query instead (#21632)
* Remove duplicated types-query, use enumerated-types-query instead * Fix type
This commit is contained in:
1 parent
aa27290181
commit
0ddd1b4711
9 files changed
+27
-86
No files matched your search
+2
-2
@@ -1,7 +1,7 @@
|
||||
import type { PostgresType } from '@supabase/postgres-meta'
|
||||
import { noop } from 'lodash'
|
||||
import { Select } from 'ui'
|
||||
|
||||
import { EnumeratedType } from 'data/enumerated-types/enumerated-types-query'
|
||||
import { POSTGRES_DATA_TYPES } from '../SidePanelEditor.constants'
|
||||
import { ColumnField } from '../SidePanelEditor.types'
|
||||
import { typeExpressionSuggestions } from './ColumnEditor.constants'
|
||||
@@ -10,7 +10,7 @@ import InputWithSuggestions from './InputWithSuggestions'
|
||||
|
||||
interface ColumnDefaultValueProps {
|
||||
columnFields: ColumnField
|
||||
enumTypes: PostgresType[]
|
||||
enumTypes: EnumeratedType[]
|
||||
onUpdateField: (changes: Partial<ColumnField>) => void
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -20,8 +20,13 @@ import {
|
||||
|
||||
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
|
||||
import { FormSection, FormSectionContent, FormSectionLabel } from 'components/ui/Forms'
|
||||
import {
|
||||
CONSTRAINT_TYPE,
|
||||
Constraint,
|
||||
useTableConstraintsQuery,
|
||||
} from 'data/database/constraints-query'
|
||||
import { useForeignKeyConstraintsQuery } from 'data/database/foreign-key-constraints-query'
|
||||
import { usePostgresTypesQuery } from 'data/database/types-query'
|
||||
import { useEnumeratedTypesQuery } from 'data/enumerated-types/enumerated-types-query'
|
||||
import { EXCLUDED_SCHEMAS_WITHOUT_EXTENSIONS } from 'lib/constants/schemas'
|
||||
import { Dictionary } from 'types'
|
||||
import ActionBar from '../ActionBar'
|
||||
@@ -40,11 +45,6 @@ import {
|
||||
import ColumnForeignKey from './ColumnForeignKey'
|
||||
import ColumnType from './ColumnType'
|
||||
import HeaderTitle from './HeaderTitle'
|
||||
import {
|
||||
CONSTRAINT_TYPE,
|
||||
Constraint,
|
||||
useTableConstraintsQuery,
|
||||
} from 'data/database/constraints-query'
|
||||
|
||||
export interface ColumnEditorProps {
|
||||
column?: PostgresColumn
|
||||
@@ -78,7 +78,7 @@ const ColumnEditor = ({
|
||||
const [columnFields, setColumnFields] = useState<ColumnField>()
|
||||
const [fkRelations, setFkRelations] = useState<ForeignKey[]>([])
|
||||
|
||||
const { data: types } = usePostgresTypesQuery({
|
||||
const { data: types } = useEnumeratedTypesQuery({
|
||||
projectRef: project?.ref,
|
||||
connectionString: project?.connectionString,
|
||||
})
|
||||
|
||||
+2
-2
@@ -1,5 +1,4 @@
|
||||
import * as Tooltip from '@radix-ui/react-tooltip'
|
||||
import type { PostgresType } from '@supabase/postgres-meta'
|
||||
import { noop } from 'lodash'
|
||||
import Link from 'next/link'
|
||||
import { ReactNode } from 'react'
|
||||
@@ -23,10 +22,11 @@ import {
|
||||
} from '../SidePanelEditor.constants'
|
||||
import { PostgresDataTypeOption } from '../SidePanelEditor.types'
|
||||
import { ListPlus } from 'lucide-react'
|
||||
import { EnumeratedType } from 'data/enumerated-types/enumerated-types-query'
|
||||
|
||||
interface ColumnTypeProps {
|
||||
value: string
|
||||
enumTypes: PostgresType[]
|
||||
enumTypes: EnumeratedType[]
|
||||
size?: 'tiny' | 'small' | 'medium' | 'large' | 'xlarge'
|
||||
layout?: 'vertical' | 'horizontal'
|
||||
className?: string
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
import type { PostgresType } from '@supabase/postgres-meta'
|
||||
import { noop } from 'lodash'
|
||||
import { Checkbox, IconMenu, IconSettings, IconX, Input, Popover } from 'ui'
|
||||
|
||||
import { EnumeratedType } from 'data/enumerated-types/enumerated-types-query'
|
||||
import { EMPTY_ARR, EMPTY_OBJ } from 'lib/void'
|
||||
import { typeExpressionSuggestions } from '../ColumnEditor/ColumnEditor.constants'
|
||||
import { Suggestion } from '../ColumnEditor/ColumnEditor.types'
|
||||
@@ -29,7 +29,7 @@ import { ColumnField } from '../SidePanelEditor.types'
|
||||
|
||||
interface ColumnProps {
|
||||
column: ColumnField
|
||||
enumTypes: PostgresType[]
|
||||
enumTypes: EnumeratedType[]
|
||||
isNewRecord: boolean
|
||||
hasForeignKeys: boolean
|
||||
hasImportContent: boolean
|
||||
@@ -40,7 +40,7 @@ interface ColumnProps {
|
||||
|
||||
const Column = ({
|
||||
column = EMPTY_OBJ as ColumnField,
|
||||
enumTypes = EMPTY_ARR as PostgresType[],
|
||||
enumTypes = EMPTY_ARR as EnumeratedType[],
|
||||
isNewRecord = false,
|
||||
hasForeignKeys = false,
|
||||
hasImportContent = false,
|
||||
|
||||
+2
-2
@@ -1,5 +1,4 @@
|
||||
import * as Tooltip from '@radix-ui/react-tooltip'
|
||||
import type { PostgresType } from '@supabase/postgres-meta'
|
||||
import { isEmpty, noop, partition } from 'lodash'
|
||||
import {
|
||||
DragDropContext,
|
||||
@@ -11,6 +10,7 @@ import {
|
||||
import { Alert, Button, IconEdit, IconExternalLink, IconHelpCircle, IconKey, IconTrash } from 'ui'
|
||||
|
||||
import InformationBox from 'components/ui/InformationBox'
|
||||
import { EnumeratedType } from 'data/enumerated-types/enumerated-types-query'
|
||||
import { generateColumnField } from '../ColumnEditor/ColumnEditor.utils'
|
||||
import { ForeignKey } from '../ForeignKeySelector/ForeignKeySelector.types'
|
||||
import { TEXT_TYPES } from '../SidePanelEditor.constants'
|
||||
@@ -21,7 +21,7 @@ import { ImportContent } from './TableEditor.types'
|
||||
interface ColumnManagementProps {
|
||||
columns?: ColumnField[]
|
||||
relations: ForeignKey[]
|
||||
enumTypes: PostgresType[]
|
||||
enumTypes: EnumeratedType[]
|
||||
importContent?: ImportContent
|
||||
isNewRecord: boolean
|
||||
onColumnsUpdated: (columns: ColumnField[]) => void
|
||||
|
||||
+7
-7
@@ -7,11 +7,16 @@ import { Alert, Badge, Button, Checkbox, IconBookOpen, Input, Modal, SidePanel }
|
||||
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
|
||||
import ConfirmationModal from 'components/ui/ConfirmationModal'
|
||||
import { useDatabasePublicationsQuery } from 'data/database-publications/database-publications-query'
|
||||
import {
|
||||
CONSTRAINT_TYPE,
|
||||
Constraint,
|
||||
useTableConstraintsQuery,
|
||||
} from 'data/database/constraints-query'
|
||||
import {
|
||||
ForeignKeyConstraint,
|
||||
useForeignKeyConstraintsQuery,
|
||||
} from 'data/database/foreign-key-constraints-query'
|
||||
import { usePostgresTypesQuery } from 'data/database/types-query'
|
||||
import { useEnumeratedTypesQuery } from 'data/enumerated-types/enumerated-types-query'
|
||||
import { useIsFeatureEnabled, useStore } from 'hooks'
|
||||
import { EXCLUDED_SCHEMAS_WITHOUT_EXTENSIONS } from 'lib/constants/schemas'
|
||||
import { useTableEditorStateSnapshot } from 'state/table-editor'
|
||||
@@ -32,11 +37,6 @@ import {
|
||||
generateTableFieldFromPostgresTable,
|
||||
validateFields,
|
||||
} from './TableEditor.utils'
|
||||
import {
|
||||
CONSTRAINT_TYPE,
|
||||
Constraint,
|
||||
useTableConstraintsQuery,
|
||||
} from 'data/database/constraints-query'
|
||||
|
||||
export interface TableEditorProps {
|
||||
table?: PostgresTable
|
||||
@@ -80,7 +80,7 @@ const TableEditor = ({
|
||||
const isNewRecord = isUndefined(table)
|
||||
const realtimeEnabled = useIsFeatureEnabled('realtime:all')
|
||||
|
||||
const { data: types } = usePostgresTypesQuery({
|
||||
const { data: types } = useEnumeratedTypesQuery({
|
||||
projectRef: project?.ref,
|
||||
connectionString: project?.connectionString,
|
||||
})
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
export const databaseKeys = {
|
||||
schemaList: (projectRef: string | undefined) => ['projects', projectRef, 'schemas'] as const,
|
||||
postgresTypes: (projectRef: string | undefined) => ['projects', projectRef, 'types'] as const,
|
||||
backups: (projectRef: string | undefined) => [projectRef, 'database', 'backups'] as const,
|
||||
poolingConfiguration: (projectRef: string | undefined) =>
|
||||
[projectRef, 'database', 'pooling-configuration'] as const,
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
import { PostgresType } from '@supabase/postgres-meta'
|
||||
import { QueryClient, useQuery, UseQueryOptions } from '@tanstack/react-query'
|
||||
|
||||
import { get } from 'data/fetchers'
|
||||
import { ResponseError } from 'types'
|
||||
import { databaseKeys } from './keys'
|
||||
|
||||
export type PostgresTypesVariables = {
|
||||
projectRef?: string
|
||||
connectionString?: string
|
||||
}
|
||||
|
||||
export async function getPostgresTypes(
|
||||
{ projectRef, connectionString }: PostgresTypesVariables,
|
||||
signal?: AbortSignal
|
||||
) {
|
||||
if (!projectRef) {
|
||||
throw new Error('projectRef is required')
|
||||
}
|
||||
|
||||
let headers = new Headers()
|
||||
if (connectionString) headers.set('x-connection-encrypted', connectionString)
|
||||
|
||||
const { data, error } = await get('/platform/pg-meta/{ref}/types', {
|
||||
// @ts-ignore [Joshen] query param is not required
|
||||
params: {
|
||||
header: {
|
||||
'x-connection-encrypted': connectionString!,
|
||||
},
|
||||
path: {
|
||||
ref: projectRef,
|
||||
},
|
||||
},
|
||||
headers: Object.fromEntries(headers),
|
||||
signal,
|
||||
})
|
||||
|
||||
if (error) throw error
|
||||
return data as PostgresType[]
|
||||
}
|
||||
|
||||
export type PostgresTypesData = Awaited<ReturnType<typeof getPostgresTypes>>
|
||||
export type PostgresTypesError = ResponseError
|
||||
|
||||
export const usePostgresTypesQuery = <TData = PostgresTypesData>(
|
||||
{ projectRef, connectionString }: PostgresTypesVariables,
|
||||
{ enabled = true, ...options }: UseQueryOptions<PostgresTypesData, PostgresTypesError, TData> = {}
|
||||
) =>
|
||||
useQuery<PostgresTypesData, PostgresTypesError, TData>(
|
||||
databaseKeys.postgresTypes(projectRef),
|
||||
({ signal }) => getPostgresTypes({ projectRef, connectionString }, signal),
|
||||
{ enabled: enabled && typeof projectRef !== 'undefined', ...options }
|
||||
)
|
||||
|
||||
export function invalidatePostgresTypesQuery(client: QueryClient, projectRef: string | undefined) {
|
||||
return client.invalidateQueries(databaseKeys.postgresTypes(projectRef))
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
import { useQuery, useQueryClient, UseQueryOptions } from '@tanstack/react-query'
|
||||
import { useCallback } from 'react'
|
||||
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
||||
|
||||
import { get } from 'data/fetchers'
|
||||
import { components } from 'data/api'
|
||||
import { get, handleError } from 'data/fetchers'
|
||||
import { ResponseError } from 'types'
|
||||
import { enumeratedTypesKeys } from './keys'
|
||||
import { components } from 'data/api'
|
||||
|
||||
export type EnumeratedTypesVariables = {
|
||||
projectRef?: string
|
||||
@@ -32,7 +31,7 @@ export async function getEnumeratedTypes(
|
||||
signal,
|
||||
})
|
||||
|
||||
if (error) throw error
|
||||
if (error) handleError(error)
|
||||
const enumeratedTypes = data.filter((type) => type.enums.length > 0)
|
||||
return enumeratedTypes
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user