Skip to content

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

Fix database replications page tables not toggling realtime properly

Joshen Lim21dcaa5bf474
diff --git a/studio/components/interfaces/Database/Publications/PublicationsList.tsx b/studio/components/interfaces/Database/Publications/PublicationsList.tsx
index 1d374ada6e7..600e3d36851 100644
--- a/studio/components/interfaces/Database/Publications/PublicationsList.tsx
+++ b/studio/components/interfaces/Database/Publications/PublicationsList.tsx
@@ -7,7 +7,7 @@ import { confirmAlert } from 'components/to-be-cleaned/ModalsDeprecated/ConfirmM
import Table from 'components/to-be-cleaned/Table'
interface Props {
- onSelectPublication: (publication: any) => void
+ onSelectPublication: (id: number) => void
}
const PublicationsList: FC<Props> = ({ onSelectPublication = () => {} }) => {
@@ -48,7 +48,7 @@ const PublicationsList: FC<Props> = ({ onSelectPublication = () => {} }) => {
return (
<>
<div className="mb-4">
- <div className="flex justify-between items-center">
+ <div className="flex items-center justify-between">
<div className="flex items-center">
<div>
<Input
@@ -63,7 +63,7 @@ const PublicationsList: FC<Props> = ({ onSelectPublication = () => {} }) => {
<div className=""></div>
</div>
</div>
- <div className="rounded overflow-hidden">
+ <div className="overflow-hidden rounded">
<Table
head={[
<Table.th key="header.name">Name</Table.th>,
@@ -131,11 +131,11 @@ const PublicationsList: FC<Props> = ({ onSelectPublication = () => {} }) => {
</div>
</Table.td>
<Table.td className="px-4 py-3 pr-2">
- <div className="flex gap-2 justify-end">
+ <div className="flex justify-end gap-2">
<Button
type="default"
style={{ paddingTop: 3, paddingBottom: 3 }}
- onClick={() => onSelectPublication(x)}
+ onClick={() => onSelectPublication(x.id)}
>
{x.tables == null
? 'All tables'
diff --git a/studio/components/interfaces/Database/Publications/PublicationsTableItem.tsx b/studio/components/interfaces/Database/Publications/PublicationsTableItem.tsx
index 2fa4a01b8eb..2c362f3fdaa 100644
--- a/studio/components/interfaces/Database/Publications/PublicationsTableItem.tsx
+++ b/studio/components/interfaces/Database/Publications/PublicationsTableItem.tsx
@@ -1,42 +1,46 @@
import { FC, useState } from 'react'
import { observer } from 'mobx-react-lite'
import { Badge, Toggle } from '@supabase/ui'
+import { PostgresPublication, PostgresTable } from '@supabase/postgres-meta'
import { useStore } from 'hooks'
import Table from 'components/to-be-cleaned/Table'
interface Props {
- table: any
- selectedPublication: any
+ table: PostgresTable
+ selectedPublication: PostgresPublication
}
const PublicationsTableItem: FC<Props> = ({ table, selectedPublication }) => {
const { ui, meta } = useStore()
+ const enabledForAllTables = selectedPublication.tables == null
- const publication = selectedPublication
- const enabledForAllTables = publication.tables == null
const [loading, setLoading] = useState(false)
const [checked, setChecked] = useState(
- publication.tables?.find((x: any) => x.id == table.id) != undefined
+ selectedPublication.tables?.find((x: any) => x.id == table.id) != undefined
)
- const toggleReplicationForTable = async (table: any, publication: any) => {
+ const toggleReplicationForTable = async (
+ table: PostgresTable,
+ publication: PostgresPublication
+ ) => {
const originalChecked = checked
setChecked(!checked)
setLoading(true)
- let exists = publication.tables.some((x: any) => x.id == table.id)
- let tables = !exists
+ const publicationTables = publication?.tables ?? []
+ const exists = publicationTables.some((x: any) => x.id == table.id)
+ const tables = !exists
? [`${table.schema}.${table.name}`].concat(
- publication.tables.map((t: any) => `${t.schema}.${t.name}`)
+ publicationTables.map((t: any) => `${t.schema}.${t.name}`)
)
- : publication.tables
+ : publicationTables
.filter((x: any) => x.id != table.id)
.map((x: any) => `${x.schema}.${x.name}`)
try {
const id = publication.id
- let payload = { tables, id }
+ const payload = { tables, id }
const { error } = await meta.publications.update(id, payload)
if (error) throw error
setLoading(false)
@@ -60,12 +64,7 @@ const PublicationsTableItem: FC<Props> = ({ table, selectedPublication }) => {
<Table.td className="px-4 py-3 pr-2">
<div className="flex justify-end gap-2">
{enabledForAllTables ? (
- // @ts-ignore
- <Badge
- color="scale"
- // className="hover:border-gray-500"
- // style={{ paddingTop: 3, paddingBottom: 3 }}
- >
+ <Badge color="scale">
<span>Enabled</span>
<span className="hidden lg:inline-block">&nbsp;for all tables</span>
</Badge>
@@ -76,7 +75,7 @@ const PublicationsTableItem: FC<Props> = ({ table, selectedPublication }) => {
disabled={loading}
className="m-0 ml-2 mt-1 -mb-1 p-0"
checked={checked}
- onChange={() => toggleReplicationForTable(table, publication)}
+ onChange={() => toggleReplicationForTable(table, selectedPublication)}
/>
)}
</div>
diff --git a/studio/components/interfaces/Database/Publications/PublicationsTables.tsx b/studio/components/interfaces/Database/Publications/PublicationsTables.tsx
index 03c5a66e319..1ad2eaa2818 100644
--- a/studio/components/interfaces/Database/Publications/PublicationsTables.tsx
+++ b/studio/components/interfaces/Database/Publications/PublicationsTables.tsx
@@ -1,27 +1,19 @@
import { FC, useState } from 'react'
import { observer } from 'mobx-react-lite'
-import { Button, Toggle, Input, IconChevronLeft, IconSearch } from '@supabase/ui'
+import { Button, Input, IconChevronLeft, IconSearch } from '@supabase/ui'
+import { PostgresPublication } from '@supabase/postgres-meta'
import { useStore } from 'hooks'
import PublicationsTableItem from './PublicationsTableItem'
import Table from 'components/to-be-cleaned/Table'
-// import { confirmAlert } from 'components/to-be-cleaned/ModalsDeprecated/ConfirmModal'
interface Props {
- selectedPublication: any
+ selectedPublication: PostgresPublication
onSelectBack: () => void
- onPublicationUpdated: (publication: any) => void
}
-const PublicationsTables: FC<Props> = ({
- selectedPublication,
- onSelectBack,
- // onPublicationUpdated,
-}) => {
- const {
- // ui,
- meta,
- } = useStore()
+const PublicationsTables: FC<Props> = ({ selectedPublication, onSelectBack }) => {
+ const { meta } = useStore()
const [filterString, setFilterString] = useState<string>('')
const tables =
@@ -62,7 +54,7 @@ const PublicationsTables: FC<Props> = ({
return (
<>
<div className="mb-4">
- <div className="flex justify-between items-center">
+ <div className="flex items-center justify-between">
<div className="flex items-center space-x-3">
<Button
type="outline"
@@ -88,7 +80,7 @@ const PublicationsTables: FC<Props> = ({
head={[
<Table.th key="header-name">Name</Table.th>,
<Table.th key="header-schema">Schema</Table.th>,
- <Table.th key="header-desc" className="text-left hidden lg:table-cell">
+ <Table.th key="header-desc" className="hidden text-left lg:table-cell">
Description
</Table.th>,
<Table.th key="header-all">
diff --git a/studio/pages/project/[ref]/database/replication.tsx b/studio/pages/project/[ref]/database/replication.tsx
index 661f42a4731..e938cea3443 100644
--- a/studio/pages/project/[ref]/database/replication.tsx
+++ b/studio/pages/project/[ref]/database/replication.tsx
@@ -1,23 +1,31 @@
import { useState } from 'react'
-import { isUndefined } from 'lodash'
import { observer } from 'mobx-react-lite'
+import { useStore } from 'hooks'
+import { NextPageWithLayout } from 'types'
import { DatabaseLayout } from 'components/layouts'
import { PublicationsList, PublicationsTables } from 'components/interfaces/Database'
-import { NextPageWithLayout } from 'types'
+
+// [Joshen] Technically, best that we have these as separate URLs
+// makes it easier to manage state, but foresee that this page might
+// be consolidated somewhere else eventually for better UX
const DatabaseReplication: NextPageWithLayout = () => {
- const [selectedPublication, setSelectedPublication] = useState<any>()
+ const { meta } = useStore()
+ const publications = meta.publications.list()
+
+ const [selectedPublicationId, setSelectedPublicationId] = useState<number>()
+ const selectedPublication = publications.find((pub) => pub.id === selectedPublicationId)
return (
<div className="p-4">
- {isUndefined(selectedPublication) ? (
- <PublicationsList onSelectPublication={setSelectedPublication} />
+ {selectedPublicationId === undefined ? (
+ <PublicationsList onSelectPublication={setSelectedPublicationId} />
) : (
<PublicationsTables
selectedPublication={selectedPublication}
- onSelectBack={() => setSelectedPublication(undefined)}
- onPublicationUpdated={setSelectedPublication}
+ onSelectBack={() => setSelectedPublicationId(undefined)}
+ // onPublicationUpdated={setSelectedPublication}
/>
)}
</div>