Files
Alaister YoungandKevin Grüneberg 70da0f1d1d chore: cleanup packages (#27770)
* chore: cleanup packages

- Avoid circular imports
- Export API-types as types
- pg-format without depending on Node internal Buffer (not browser-compatible)
- Avoid importing from barrel files in ui dir

* chore: avoid barrel file imports in studio (#27771)

* chore: avoid barrel file imports

- Removes some unused imports
- Avoids barrel file import for faster builds + less memory

* add eslint rule

* type fixes

* delete layouts barrel

* delete components/grid barrel file

* delete components/grid/utils barrel file

* delete components/grid/components/common barrel file

* delete components/grid/components/editor barrel file

* delete components/grid/components/formatter barrel file

* delete components/grid/components/grid barrel file

* delete components/grid/components/header/filter barrel file

* remote components/grid/store barrel file

* remove components/interfaces/Auth/Policies barrel file

* delete components/interfaces/Settings/Logs barrel file

* delete components/ui/CodeEditor barrel file

* delete components/ui/Forms barrel file

* delete components/ui/Shimmers barrel file

* delete data/analytics barrel file

* delete hooks barrel file

* cleanup lib/common/fetch barrel file

* final * barral files cleanup

* global react-data-grid styles

* remove console.log

---------

Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com>

* fix build

---------

Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com>
2024-07-04 14:48:10 +08:00

62 lines
2.4 KiB
TypeScript

import { PermissionAction } from '@supabase/shared-types/out/constants'
import { useState } from 'react'
import { PublicationsList, PublicationsTables } from 'components/interfaces/Database'
import DatabaseLayout from 'components/layouts/DatabaseLayout/DatabaseLayout'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import { ScaffoldContainer, ScaffoldSection } from 'components/layouts/Scaffold'
import { FormHeader } from 'components/ui/Forms/FormHeader'
import NoPermission from 'components/ui/NoPermission'
import { useDatabasePublicationsQuery } from 'data/database-publications/database-publications-query'
import { useCheckPermissions, usePermissionsLoaded } from 'hooks/misc/useCheckPermissions'
import type { 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 DatabasePublications: NextPageWithLayout = () => {
const { project } = useProjectContext()
const { data } = useDatabasePublicationsQuery({
projectRef: project?.ref,
connectionString: project?.connectionString,
})
const publications = data ?? []
const canViewPublications = useCheckPermissions(
PermissionAction.TENANT_SQL_ADMIN_READ,
'publications'
)
const isPermissionsLoaded = usePermissionsLoaded()
const [selectedPublicationId, setSelectedPublicationId] = useState<number>()
const selectedPublication = publications.find((pub) => pub.id === selectedPublicationId)
if (isPermissionsLoaded && !canViewPublications) {
return <NoPermission isFullPage resourceText="view database publications" />
}
return (
<ScaffoldContainer>
<ScaffoldSection>
<div className="col-span-12">
<FormHeader title="Database Publications" />
{selectedPublication === undefined ? (
<PublicationsList onSelectPublication={setSelectedPublicationId} />
) : (
<PublicationsTables
selectedPublication={selectedPublication}
onSelectBack={() => setSelectedPublicationId(undefined)}
/>
)}
</div>
</ScaffoldSection>
</ScaffoldContainer>
)
}
DatabasePublications.getLayout = (page) => <DatabaseLayout title="Database">{page}</DatabaseLayout>
export default DatabasePublications