@@ -23,6 +23,7 @@ import {
2323 SelectTrigger ,
2424} from "@/components/ui/select" ;
2525import { useDashboardRouter } from "@/lib/DashboardRouter" ;
26+ import { cn } from "@/lib/utils" ;
2627import { LazyCreateAPIKeyDialog } from "components/settings/ApiKeys/Create/LazyCreateAPIKeyDialog" ;
2728import {
2829 ChevronDownIcon ,
@@ -33,22 +34,25 @@ import {
3334import Link from "next/link" ;
3435import { useMemo , useState } from "react" ;
3536
36- type SortById = "name" | "createdAt" | "totalConnections " ;
37+ type SortById = "name" | "createdAt" | "monthlyActiveUsers " ;
3738
38- type ProjectWithTotalConnections = Project & { totalConnections : number } ;
39+ export type ProjectWithAnalytics = Project & {
40+ monthlyActiveUsers : number ;
41+ } ;
3942
4043export function TeamProjectsPage ( props : {
41- projects : ProjectWithTotalConnections [ ] ;
44+ projects : ProjectWithAnalytics [ ] ;
4245 team : Team ;
4346} ) {
4447 const { projects } = props ;
4548 const [ searchTerm , setSearchTerm ] = useState ( "" ) ;
46- const [ sortBy , setSortBy ] = useState < SortById > ( "totalConnections " ) ;
49+ const [ sortBy , setSortBy ] = useState < SortById > ( "monthlyActiveUsers " ) ;
4750 const [ isCreateProjectDialogOpen , setIsCreateProjectDialogOpen ] =
4851 useState ( false ) ;
4952 const router = useDashboardRouter ( ) ;
53+ const [ isExpanded , setIsExpanded ] = useState ( false ) ;
5054
51- const projectsToShow = useMemo ( ( ) => {
55+ const filteredProjects = useMemo ( ( ) => {
5256 let _projectsToShow = ! searchTerm
5357 ? projects
5458 : projects . filter (
@@ -68,15 +72,23 @@ export function TeamProjectsPage(props: {
6872 ( a , b ) =>
6973 new Date ( b . createdAt ) . getTime ( ) - new Date ( a . createdAt ) . getTime ( ) ,
7074 ) ;
71- } else if ( sortBy === "totalConnections " ) {
75+ } else if ( sortBy === "monthlyActiveUsers " ) {
7276 _projectsToShow = _projectsToShow . sort (
73- ( a , b ) => b . totalConnections - a . totalConnections ,
77+ ( a , b ) => b . monthlyActiveUsers - a . monthlyActiveUsers ,
7478 ) ;
7579 }
7680
7781 return _projectsToShow ;
7882 } , [ searchTerm , sortBy , projects ] ) ;
7983
84+ const maxProjectsToShow = 8 ;
85+
86+ const projectsToShow = isExpanded
87+ ? filteredProjects
88+ : filteredProjects . slice ( 0 , maxProjectsToShow ) ;
89+
90+ const showExpandCollapseButton = filteredProjects . length > maxProjectsToShow ;
91+
8092 return (
8193 < div className = "flex grow flex-col" >
8294 { /* Filters + Add New */ }
@@ -132,6 +144,27 @@ export function TeamProjectsPage(props: {
132144 </ div >
133145 ) }
134146
147+ { showExpandCollapseButton && (
148+ < div className = "mt-4 flex items-center justify-end" >
149+ < Button
150+ size = "sm"
151+ variant = "ghost"
152+ className = "gap-2"
153+ onClick = { ( ) => {
154+ setIsExpanded ( ( v ) => ! v ) ;
155+ } }
156+ >
157+ < ChevronDownIcon
158+ className = { cn (
159+ "size-4 transition-transform" ,
160+ isExpanded && "rotate-180" ,
161+ ) }
162+ />
163+ { isExpanded ? "Show less" : "Show more" }
164+ </ Button >
165+ </ div >
166+ ) }
167+
135168 < LazyCreateAPIKeyDialog
136169 open = { isCreateProjectDialogOpen }
137170 onOpenChange = { setIsCreateProjectDialogOpen }
@@ -148,7 +181,7 @@ export function TeamProjectsPage(props: {
148181}
149182
150183function ProjectCard ( props : {
151- project : ProjectWithTotalConnections ;
184+ project : ProjectWithAnalytics ;
152185 team_slug : string ;
153186} ) {
154187 const { project, team_slug } = props ;
@@ -160,7 +193,7 @@ function ProjectCard(props: {
160193 { /* TODO - set image */ }
161194 < ProjectAvatar className = "size-10 rounded-full" src = "" />
162195
163- < div className = "flex-grow flex-col gap-1.5 " >
196+ < div className = "flex flex -grow flex-col gap-1" >
164197 < Link
165198 className = "group static before:absolute before:top-0 before:right-0 before:bottom-0 before:left-0 before:z-0"
166199 // remove /connect when we have overview page
@@ -170,8 +203,8 @@ function ProjectCard(props: {
170203 </ Link >
171204
172205 < p className = "flex items-center gap-1 text-muted-foreground text-sm" >
173- < span > { project . totalConnections } </ span >
174- Total Users
206+ < span > { project . monthlyActiveUsers } </ span >
207+ Monthly Active Users
175208 </ p >
176209 </ div >
177210
@@ -256,11 +289,11 @@ function SelectBy(props: {
256289 value : SortById ;
257290 onChange : ( value : SortById ) => void ;
258291} ) {
259- const values : SortById [ ] = [ "name" , "createdAt" , "totalConnections " ] ;
292+ const values : SortById [ ] = [ "name" , "createdAt" , "monthlyActiveUsers " ] ;
260293 const valueToLabel : Record < SortById , string > = {
261294 name : "Name" ,
262295 createdAt : "Creation Date" ,
263- totalConnections : "Total Users" ,
296+ monthlyActiveUsers : "Monthly Active Users" ,
264297 } ;
265298
266299 return (
0 commit comments