Skip to content

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

Support filtering by entity types in table editor (#27555)

Joshen Lim3530c022ec40
diff --git a/apps/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx b/apps/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx
index 061d1306273..24ebd09141b 100644
--- a/apps/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx
+++ b/apps/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx
@@ -1,7 +1,7 @@
import * as Tooltip from '@radix-ui/react-tooltip'
import { PermissionAction } from '@supabase/shared-types/out/constants'
import { partition } from 'lodash'
-import { Plus } from 'lucide-react'
+import { Filter, Plus } from 'lucide-react'
import { useRouter } from 'next/router'
import { useMemo, useState } from 'react'
@@ -15,7 +15,17 @@ import { useEntityTypesQuery } from 'data/entity-types/entity-types-infinite-que
import { useCheckPermissions, useLocalStorage } from 'hooks'
import { EXCLUDED_SCHEMAS } from 'lib/constants/schemas'
import { useTableEditorStateSnapshot } from 'state/table-editor'
-import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, Button } from 'ui'
+import {
+ AlertDescription_Shadcn_,
+ AlertTitle_Shadcn_,
+ Alert_Shadcn_,
+ Button,
+ Checkbox_Shadcn_,
+ Label_Shadcn_,
+ PopoverContent_Shadcn_,
+ PopoverTrigger_Shadcn_,
+ Popover_Shadcn_,
+} from 'ui'
import {
InnerSideBarEmptyPanel,
InnerSideBarFilterSearchInput,
@@ -26,6 +36,7 @@ import {
} from 'ui-patterns/InnerSideMenu'
import { useProjectContext } from '../ProjectLayout/ProjectContext'
import EntityListItem from './EntityListItem'
+import { ENTITY_TYPE } from 'data/entity-types/entity-type-constants'
const TableEditorMenu = () => {
const router = useRouter()
@@ -34,6 +45,7 @@ const TableEditorMenu = () => {
const [showModal, setShowModal] = useState(false)
const [searchText, setSearchText] = useState<string>('')
+ const [visibleTypes, setVisibleTypes] = useState<string[]>(Object.values(ENTITY_TYPE))
const [sort, setSort] = useLocalStorage<'alphabetical' | 'grouped-alphabetical'>(
'table-editor-sort',
'alphabetical'
@@ -57,6 +69,7 @@ const TableEditorMenu = () => {
schema: snap.selectedSchemaName,
search: searchText || undefined,
sort,
+ filterTypes: visibleTypes,
},
{
keepPreviousData: Boolean(searchText),
@@ -188,6 +201,51 @@ const TableEditorMenu = () => {
</InnerSideBarFilterSortDropdownItem>
</InnerSideBarFilterSortDropdown>
</InnerSideBarFilterSearchInput>
+ <Popover_Shadcn_>
+ <PopoverTrigger_Shadcn_ asChild>
+ <Button
+ type={visibleTypes.length !== 5 ? 'default' : 'dashed'}
+ className="h-[28px] px-1.5"
+ icon={<Filter />}
+ />
+ </PopoverTrigger_Shadcn_>
+ <PopoverContent_Shadcn_ className="p-0 w-56" side="bottom" align="center">
+ <div className="px-3 pt-3 pb-2 flex flex-col gap-y-2">
+ <p className="text-xs">Show entity types</p>
+ <div className="flex flex-col">
+ {Object.entries(ENTITY_TYPE).map(([key, value]) => (
+ <div key={key} className="group flex items-center justify-between py-0.5">
+ <div className="flex items-center gap-x-2">
+ <Checkbox_Shadcn_
+ id={key}
+ name={key}
+ checked={visibleTypes.includes(value)}
+ onCheckedChange={() => {
+ if (visibleTypes.includes(value)) {
+ setVisibleTypes(visibleTypes.filter((y) => y !== value))
+ } else {
+ setVisibleTypes(visibleTypes.concat([value]))
+ }
+ }}
+ />
+ <Label_Shadcn_ htmlFor={key} className="capitalize text-xs">
+ {key.toLowerCase().replace('_', ' ')}
+ </Label_Shadcn_>
+ </div>
+ <Button
+ size="tiny"
+ type="default"
+ onClick={() => setVisibleTypes([value])}
+ className="transition opacity-0 group-hover:opacity-100 h-auto px-1 py-0.5"
+ >
+ Select only
+ </Button>
+ </div>
+ ))}
+ </div>
+ </div>
+ </PopoverContent_Shadcn_>
+ </Popover_Shadcn_>
</InnerSideBarFilters>
{isLoading && <InnerSideBarShimmeringLoaders />}
diff --git a/apps/studio/data/entity-types/entity-types-infinite-query.ts b/apps/studio/data/entity-types/entity-types-infinite-query.ts
index f24f0bf96d1..470bd56933b 100644
--- a/apps/studio/data/entity-types/entity-types-infinite-query.ts
+++ b/apps/studio/data/entity-types/entity-types-infinite-query.ts
@@ -10,6 +10,7 @@ export type EntityTypesVariables = {
limit?: number
page?: number
sort?: 'alphabetical' | 'grouped-alphabetical'
+ filterTypes?: string[]
} & Pick<ExecuteSqlVariables, 'connectionString'>
export type EntityTypesResponse = {
@@ -28,6 +29,7 @@ export async function getEntityTypes(
limit = 100,
page = 0,
sort = 'alphabetical',
+ filterTypes,
}: EntityTypesVariables,
signal?: AbortSignal
) {
@@ -55,7 +57,7 @@ export async function getEntityTypes(
pg_namespace nc
join pg_class c on nc.oid = c.relnamespace
where
- c.relkind in ('r', 'v', 'm', 'f', 'p')
+ c.relkind in (${filterTypes === undefined ? `'r', 'v', 'm', 'f', 'p'` : filterTypes.map((x) => `'${x}'`).join(', ')})
and not pg_is_other_temp_schema(nc.oid)
and (
pg_has_role(c.relowner, 'USAGE')
@@ -113,6 +115,7 @@ export const useEntityTypesQuery = <TData = EntityTypesData>(
search,
limit = 100,
sort,
+ filterTypes,
}: Omit<EntityTypesVariables, 'page'>,
{
enabled = true,
@@ -120,10 +123,10 @@ export const useEntityTypesQuery = <TData = EntityTypesData>(
}: UseInfiniteQueryOptions<EntityTypesData, EntityTypesError, TData> = {}
) =>
useInfiniteQuery<EntityTypesData, EntityTypesError, TData>(
- entityTypeKeys.list(projectRef, { schema, search, sort, limit }),
+ entityTypeKeys.list(projectRef, { schema, search, sort, limit, filterTypes }),
({ signal, pageParam }) =>
getEntityTypes(
- { projectRef, connectionString, schema, search, limit, page: pageParam, sort },
+ { projectRef, connectionString, schema, search, limit, page: pageParam, sort, filterTypes },
signal
),
{
diff --git a/apps/studio/data/entity-types/keys.ts b/apps/studio/data/entity-types/keys.ts
index d56b82cb4ba..c04fc7dbd12 100644
--- a/apps/studio/data/entity-types/keys.ts
+++ b/apps/studio/data/entity-types/keys.ts
@@ -6,6 +6,7 @@ export const entityTypeKeys = {
search?: string
sort?: 'alphabetical' | 'grouped-alphabetical'
limit?: number
+ filterTypes?: string[]
}
) => ['projects', projectRef, 'entity-types', ...(params ? [params] : [])] as const,
}