The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Support filtering projects by status, only either paused or active (#27818)
Joshen Lim5aa9c06f7bb2
diff --git a/apps/studio/components/interfaces/Home/ProjectList/ProjectList.tsx b/apps/studio/components/interfaces/Home/ProjectList/ProjectList.tsxindex d85fa8a5eab..602e8b32e43 100644--- a/apps/studio/components/interfaces/Home/ProjectList/ProjectList.tsx+++ b/apps/studio/components/interfaces/Home/ProjectList/ProjectList.tsx@@ -16,21 +16,30 @@ import { ResourceWarning, useResourceWarningsQuery } from 'data/usage/resource-wimport { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'import { IS_PLATFORM } from 'lib/constants'import { makeRandomString } from 'lib/helpers'+import { Plus } from 'lucide-react'import type { Organization, ResponseError } from 'types'-import { Button, IconPlus } from 'ui'+import { Button, cn } from 'ui'import ProjectCard from './ProjectCard'import ShimmeringCard from './ShimmeringCard'export interface ProjectListProps {rewriteHref?: (projectRef: string) => stringsearch: string+ filterStatus?: string[]+ resetFilterStatus?: () => void}-const ProjectList = ({ search, rewriteHref }: ProjectListProps) => {+const ProjectList = ({+ search,+ rewriteHref,+ filterStatus,+ resetFilterStatus,+}: ProjectListProps) => {const { data: organizations, isLoading, isSuccess } = useOrganizationsQuery()const {data: allProjects,isLoading: isLoadingProjects,+ isSuccess: isSuccessProjects,isError: isErrorProjects,error: projectsError,} = useProjectsQuery()@@ -43,15 +52,21 @@ const ProjectList = ({ search, rewriteHref }: ProjectListProps) => {const { data: allOverdueInvoices } = useOverdueInvoicesQuery({ enabled: IS_PLATFORM })const projectsByOrg = groupBy(allProjects, 'organization_id')const isLoadingPermissions = IS_PLATFORM ? _isLoadingPermissions : false- const noResults =++ const hasFilterStatusApplied = filterStatus !== undefined && filterStatus.length !== 2+ const noResultsFromSearch =search.length > 0 &&- allProjects !== undefined &&+ isSuccessProjects &&allProjects.filter((project) => {return (project.name.toLowerCase().includes(search.toLowerCase()) ||project.ref.includes(search.toLowerCase()))}).length === 0+ const noResultsFromStatusFilter =+ hasFilterStatusApplied &&+ isSuccessProjects &&+ allProjects.filter((project) => filterStatus.includes(project.status)).length === 0if (isLoading) {return (@@ -62,10 +77,35 @@ const ProjectList = ({ search, rewriteHref }: ProjectListProps) => {)}- if (noResults) {+ if (noResultsFromSearch) {return <NoSearchResults searchString={search} />}+ if (noResultsFromStatusFilter) {+ return (+ <div+ className={cn(+ 'bg-surface-100 border border-default px-6 py-4 rounded flex items-center justify-between'+ )}+ >+ <div className="space-y-1">+ {/* [Joshen] Just keeping it simple for now unless we decide to extend this to other statuses */}+ <p className="text-sm text-foreground">+ No projects found with status as {filterStatus[0] === 'INACTIVE' ? 'paused' : 'active'}+ </p>+ <p className="text-sm text-foreground-light">+ Your search for projects with the specified status did not return any results+ </p>+ </div>+ {resetFilterStatus !== undefined && (+ <Button type="default" onClick={() => resetFilterStatus()}>+ Reset filter+ </Button>+ )}+ </div>+ )+ }+return isSuccess && organizations && organizations?.length > 0 ? (<>{organizations?.map((organization) => {@@ -86,6 +126,7 @@ const ProjectList = ({ search, rewriteHref }: ProjectListProps) => {isErrorProjects={isErrorProjects}projectsError={projectsError}search={search}+ filterStatus={filterStatus}/>)})}@@ -110,6 +151,7 @@ type OrganizationProjectsProps = {projectsError: ResponseError | nullrewriteHref?: (projectRef: string) => stringsearch: string+ filterStatus?: string[]}const OrganizationProjects = ({@@ -125,6 +167,7 @@ const OrganizationProjects = ({projectsError,rewriteHref,search,+ filterStatus,}: OrganizationProjectsProps) => {const isEmpty = !projects || projects.length === 0const sortedProjects = [...(projects || [])].sort((a, b) => a.name.localeCompare(b.name))@@ -137,6 +180,10 @@ const OrganizationProjects = ({)}): sortedProjects+ const filteredProjectsByStatus =+ filterStatus !== undefined+ ? filteredProjects.filter((project) => filterStatus.includes(project.status))+ : filteredProjectsconst { data: integrations } = useOrgIntegrationsQuery({ orgSlug: organization?.slug })const { data: connections } = useGitHubConnectionsQuery({ organizationId: organization?.id })@@ -160,7 +207,11 @@ const OrganizationProjects = ({?.filter((integration) => integration.integration.name === 'Vercel').flatMap((integration) => integration.connections)- if (search.length > 0 && filteredProjects.length === 0) return null+ if (+ (search.length > 0 || (filterStatus !== undefined && filterStatus.length !== 2)) &&+ filteredProjectsByStatus.length === 0+ )+ return nullreturn (<div className="space-y-3" key={organization.slug}>@@ -221,7 +272,7 @@ const OrganizationProjects = ({) : isEmpty ? (<NoProjectsState slug={organization.slug} />) : (- filteredProjects?.map((project) => (+ filteredProjectsByStatus?.map((project) => (<ProjectCardkey={makeRandomString(5)}project={project}@@ -255,7 +306,7 @@ const NoProjectsState = ({ slug }: { slug: string }) => {</div>{projectCreationEnabled && (- <Button asChild icon={<IconPlus />}>+ <Button asChild icon={<Plus />}><Link href={`/new/${slug}`}>New Project</Link></Button>)}diff --git a/apps/studio/components/interfaces/HomePageActions.tsx b/apps/studio/components/interfaces/HomePageActions.tsxindex 05b2cb0d6af..b400ffa4060 100644--- a/apps/studio/components/interfaces/HomePageActions.tsx+++ b/apps/studio/components/interfaces/HomePageActions.tsx@@ -5,27 +5,36 @@ import { useRouter } from 'next/router'import { useOrganizationsQuery } from 'data/organizations/organizations-query'import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'import { EMPTY_ARR } from 'lib/void'+import { Filter, Search } from 'lucide-react'import {Button,+ Checkbox_Shadcn_,DropdownMenu,DropdownMenuContent,DropdownMenuItem,DropdownMenuLabel,DropdownMenuTrigger,- IconSearch,Input,+ Label_Shadcn_,+ PopoverContent_Shadcn_,+ PopoverTrigger_Shadcn_,+ Popover_Shadcn_,} from 'ui'interface HomePageActionsProps {organizations: { name: string; slug: string }[]search: string+ filterStatus: string[]setSearch: (value: string) => void+ setFilterStatus: (value: string[]) => void}const HomePageActions = ({organizations = EMPTY_ARR,search,+ filterStatus,setSearch,+ setFilterStatus,}: HomePageActionsProps) => {const router = useRouter()@@ -62,14 +71,65 @@ const HomePageActions = ({</Button>)}- <Input- size="tiny"- placeholder="Search for a project"- icon={<IconSearch size={16} />}- className="w-64 [&>div>div>div>input]:!pl-7 [&>div>div>div>div]:!pl-2"- value={search}- onChange={(event) => setSearch(event.target.value)}- />+ <div className="flex items-center gap-x-2">+ <Input+ size="tiny"+ placeholder="Search for a project"+ icon={<Search size={16} />}+ className="w-64 [&>div>div>div>input]:!pl-7 [&>div>div>div>div]:!pl-2"+ value={search}+ onChange={(event) => setSearch(event.target.value)}+ />++ <Popover_Shadcn_>+ <PopoverTrigger_Shadcn_ asChild>+ <Button+ type={filterStatus.length !== 2 ? 'secondary' : 'dashed'}+ className="h-[26px] w-[26px]"+ 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">Filter projects by status</p>+ <div className="flex flex-col">+ {[+ { key: 'ACTIVE_HEALTHY', label: 'Active' },+ { key: 'INACTIVE', label: 'Paused' },+ ].map(({ key, label }) => (+ <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={filterStatus.includes(key)}+ onCheckedChange={() => {+ if (filterStatus.includes(key)) {+ setFilterStatus(filterStatus.filter((y) => y !== key))+ } else {+ setFilterStatus(filterStatus.concat([key]))+ }+ }}+ />+ <Label_Shadcn_ htmlFor={key} className="capitalize text-xs">+ {label}+ </Label_Shadcn_>+ </div>+ <Button+ size="tiny"+ type="default"+ onClick={() => setFilterStatus([key])}+ 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_>+ </div></div>)}diff --git a/apps/studio/pages/projects.tsx b/apps/studio/pages/projects.tsxindex bd1a0923b26..0d89f430724 100644--- a/apps/studio/pages/projects.tsx+++ b/apps/studio/pages/projects.tsx@@ -16,6 +16,7 @@ import type { NextPageWithLayout } from 'types'const ProjectsPage: NextPageWithLayout = () => {const router = useRouter()const [search, setSearch] = useState('')+ const [filterStatus, setFilterStatus] = useState<string[]>(['ACTIVE_HEALTHY', 'INACTIVE'])const { data: organizations, isError, isSuccess } = useOrganizationsQuery()useAutoProjectsPrefetch()@@ -55,10 +56,20 @@ const ProjectsPage: NextPageWithLayout = () => {{!navLayoutV2 && (<div className="p-5">{IS_PLATFORM && projectCreationEnabled && isSuccess && (- <HomePageActions search={search} setSearch={setSearch} organizations={organizations} />+ <HomePageActions+ search={search}+ filterStatus={filterStatus}+ setSearch={setSearch}+ setFilterStatus={setFilterStatus}+ organizations={organizations}+ />)}<div className="my-6 space-y-8">- <ProjectList search={search} />+ <ProjectList+ search={search}+ filterStatus={filterStatus}+ resetFilterStatus={() => setFilterStatus(['ACTIVE_HEALTHY', 'INACTIVE'])}+ /></div></div>)}