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

fix; Fix all links to the table editor to include schema #34

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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 @@ -6,7 +6,6 @@ import type { RenderCellProps } from 'react-data-grid'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import { useTableQuery } from 'data/tables/table-query'
import { useTablesQuery } from 'data/tables/tables-query'
import { useQuerySchemaState } from 'hooks/misc/useSchemaQueryState'
import { Button, Tooltip_Shadcn_, TooltipContent_Shadcn_, TooltipTrigger_Shadcn_ } from 'ui'
import type { SupaRow } from '../../types'
import { NullValue } from '../common/NullValue'
Expand All @@ -18,7 +17,6 @@ interface Props extends PropsWithChildren<RenderCellProps<SupaRow, unknown>> {

export const ForeignKeyFormatter = (props: Props) => {
const { project } = useProjectContext()
const { selectedSchema } = useQuerySchemaState()

const { projectRef, tableId, row, column } = props
const id = tableId ? Number(tableId) : undefined
Expand Down Expand Up @@ -63,7 +61,7 @@ export const ForeignKeyFormatter = (props: Props) => {
style={{ padding: '3px' }}
>
<Link
href={`/project/${projectRef}/editor/${targetTable?.id}?schema=${selectedSchema}&filter=${relationship?.target_column_name}%3Aeq%3A${value}`}
href={`/project/${projectRef}/editor/${targetTable?.id}?schema=${targetTable.schema}&filter=${relationship?.target_column_name}%3Aeq%3A${value}`}
>
<ArrowRight size={14} />
</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const PolicyTableRowHeader = ({
return (
<div id={table.id.toString()} className="flex w-full items-center justify-between">
<div className="flex gap-x-4 text-left">
<Link href={`/project/${ref}/editor/${table.id}`} className="flex items-center gap-x-2">
<Link href={`/project/${ref}/editor/${table.id}?schema=${table.schema}`}> className="flex items-center gap-x-2">
{table.rls_enabled ? (
<div className="flex items-center gap-x-1 text-xs">
<Lock size={14} strokeWidth={2} className="text-brand" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,9 @@ const TableList = ({
<DropdownMenuItem
className="flex items-center space-x-2"
onClick={() =>
router.push(`/project/${project?.ref}/editor/${x.id}`)
router.push(
`/project/${project?.ref}/editor/${x.id}?schema=${x.schema}`
)
}
>
<Eye size={12} />
Expand Down
25 changes: 20 additions & 5 deletions apps/studio/components/interfaces/Database/Tables/Tables.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ import { PostgresMaterializedView, PostgresTable, PostgresView } from '@supabase
import { PostgresForeignTable } from '@supabase/postgres-meta/dist/lib/types'
import { ENTITY_TYPE } from 'data/entity-types/entity-type-constants'

type Entity = {
type: ENTITY_TYPE
id: number
name: string
comment: string | null
rows: number | undefined
size: string | undefined
columns: unknown[]
schema: string
}

// [Joshen] We just need name, description, rows, size, and the number of columns
// Just missing partitioned tables as missing pg-meta support
export const formatAllEntities = ({
Expand All @@ -14,17 +25,18 @@ export const formatAllEntities = ({
views?: PostgresView[]
materializedViews?: PostgresMaterializedView[]
foreignTables?: PostgresForeignTable[]
}) => {
const formattedTables = tables.map((x) => {
}): Entity[] => {
const formattedTables: Entity[] = tables.map((x) => {
return {
...x,
type: ENTITY_TYPE.TABLE,
rows: x.live_rows_estimate,
columns: x.columns ?? [],
schema: x.schema,
}
})

const formattedViews = views.map((x) => {
const formattedViews: Entity[] = views.map((x) => {
return {
type: ENTITY_TYPE.VIEW,
id: x.id,
Expand All @@ -33,10 +45,11 @@ export const formatAllEntities = ({
rows: undefined,
size: undefined,
columns: x.columns ?? [],
schema: x.schema,
}
})

const formattedMaterializedViews = materializedViews.map((x) => {
const formattedMaterializedViews: Entity[] = materializedViews.map((x) => {
return {
type: ENTITY_TYPE.MATERIALIZED_VIEW,
id: x.id,
Expand All @@ -45,10 +58,11 @@ export const formatAllEntities = ({
rows: undefined,
size: undefined,
columns: x.columns ?? [],
schema: x.schema,
}
})

const formattedForeignTables = foreignTables.map((x) => {
const formattedForeignTables: Entity[] = foreignTables.map((x) => {
return {
type: ENTITY_TYPE.FOREIGN_TABLE,
id: x.id,
Expand All @@ -57,6 +71,7 @@ export const formatAllEntities = ({
rows: undefined,
size: undefined,
columns: x.columns ?? [],
schema: x.schema,
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,11 @@ const WrapperRow = ({
</p>
<div className="flex flex-wrap gap-2">
{wrapper.tables ? (
wrapper.tables.map((table: any) => (
<Link key={table.id} href={`/project/${ref}/editor/${table.id}`}>
wrapper.tables.map((table) => (
<Link
key={table.id}
href={`/project/${ref}/editor/${table.id}?schema=${table.schema}`}
>
<div className="text-sm border rounded px-2 py-1 transition bg-surface-200 hover:bg-overlay-hover">
{table.name}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import clsx from 'clsx'
import { useParams } from 'common'
import { ArrowRight } from 'lucide-react'
import Link from 'next/link'
import SVG from 'react-inlinesvg'
import { Badge, Button, cn } from 'ui'
import { ArrowRight } from 'lucide-react'

import { BASE_PATH } from 'lib/constants'
import { Badge, Button, cn } from 'ui'
import type { ForeignKey } from '../../ForeignKeySelector/ForeignKeySelector.types'

interface ForeignKeyProps {
Expand Down Expand Up @@ -78,7 +78,7 @@ export const ForeignKeyRow = ({
}
>
<Link
href={`/project/${ref}/editor/${foreignKey.tableId}`}
href={`/project/${ref}/editor/${foreignKey.tableId}?schema=${foreignKey.schema}`}
onClick={() => closePanel()}
>
{foreignKey.schema}.{foreignKey.table}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ const TableGridEditor = ({
const gridKey = `${selectedTable.schema}_${selectedTable.name}`

const onTableCreated = (table: PostgresTable) => {
router.push(`/project/${projectRef}/editor/${table.id}`)
router.push(`/project/${projectRef}/editor/${table.id}?schema=${table.schema}`)
}

// columns must be accessed via columnsRef.current as these two functions immediately become
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
MAX_EXPORT_ROW_COUNT_MESSAGE,
} from 'components/grid/components/header/Header'
import { parseSupaTable } from 'components/grid/SupabaseGrid.utils'
import { Markdown } from 'components/interfaces/Markdown'
import {
formatTableRowsToSQL,
getEntityLintDetails,
Expand All @@ -45,7 +46,6 @@ import {
DropdownMenuTrigger,
} from 'ui'
import { useProjectContext } from '../ProjectLayout/ProjectContext'
import { Markdown } from 'components/interfaces/Markdown'

export interface EntityListItemProps {
id: number
Expand Down Expand Up @@ -279,7 +279,7 @@ const EntityListItem: ItemRenderer<Entity, EntityListItemProps> = ({
return (
<Link
title={entity.name}
href={`/project/${projectRef}/editor/${entity.id}?schema=${selectedSchema}`}
href={`/project/${projectRef}/editor/${entity.id}?schema=${entity.schema}`}
role="button"
aria-label={`View ${entity.name}`}
className={cn(
Expand Down
2 changes: 1 addition & 1 deletion apps/studio/pages/project/[ref]/editor/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const TableEditorPage: NextPageWithLayout = () => {
onAfterDeleteTable={(tables) => {
// For simplicity for now, we just open the first table within the same schema
if (tables.length > 0) {
router.push(`/project/${projectRef}/editor/${tables[0].id}`)
router.push(`/project/${projectRef}/editor/${tables[0].id}?schema=${tables[0].schema}`)
} else {
router.push(`/project/${projectRef}/editor/`)
}
Expand Down
2 changes: 1 addition & 1 deletion apps/studio/pages/project/[ref]/editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const TableEditorPage: NextPageWithLayout = () => {
const router = useRouter()

const onTableCreated = (table: Table) => {
router.push(`/project/${projectRef}/editor/${table.id}`)
router.push(`/project/${projectRef}/editor/${table.id}?schema=${table.schema}`)
}

return (
Expand Down