Skip to content

Commit e31d0b8

Browse files
committed
[dashboard] add pagination to user search
1 parent 746638b commit e31d0b8

File tree

4 files changed

+61
-8
lines changed

4 files changed

+61
-8
lines changed

components/dashboard/src/admin/ProjectsSearch.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import ProjectDetail from "./ProjectDetail";
1313
import { getGitpodService } from "../service/service";
1414
import { AdminGetListResult, Project } from "@gitpod/gitpod-protocol";
1515
import { PageWithAdminSubMenu } from "./PageWithAdminSubMenu";
16+
import Pagination from "../Pagination/Pagination";
1617

1718
export default function ProjectsSearchPage() {
1819
return (
@@ -24,6 +25,8 @@ export default function ProjectsSearchPage() {
2425

2526
export function ProjectsSearch() {
2627
const location = useLocation();
28+
const pageLength = 50;
29+
const [currentPage, setCurrentPage] = useState(0);
2730
const [searchTerm, setSearchTerm] = useState("");
2831
const [searching, setSearching] = useState(false);
2932
const [searchResult, setSearchResult] = useState<AdminGetListResult<Project>>({ total: 0, rows: [] });
@@ -75,9 +78,9 @@ export function ProjectsSearch() {
7578
try {
7679
const result = await getGitpodService().server.adminGetProjectsBySearchTerm({
7780
searchTerm,
78-
limit: 50,
81+
limit: pageLength,
7982
orderBy: "creationTime",
80-
offset: 0,
83+
offset: currentPage * pageLength,
8184
orderDir: "desc",
8285
});
8386
setSearchResult(result);
@@ -86,6 +89,11 @@ export function ProjectsSearch() {
8689
}
8790
};
8891

92+
const updatePage = (page: number) => {
93+
setCurrentPage(page);
94+
search();
95+
};
96+
8997
return (
9098
<>
9199
<div className="pt-8 flex">
@@ -131,6 +139,11 @@ export function ProjectsSearch() {
131139
<ProjectResultItem project={project} />
132140
))}
133141
</div>
142+
<Pagination
143+
currentPage={currentPage}
144+
setPage={updatePage}
145+
totalNumberOfPages={searchResult.total / pageLength}
146+
/>
134147
</>
135148
);
136149

components/dashboard/src/admin/TeamsSearch.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { getGitpodService } from "../service/service";
1414
import { AdminGetListResult, Team } from "@gitpod/gitpod-protocol";
1515
import Label from "./Label";
1616
import { PageWithAdminSubMenu } from "./PageWithAdminSubMenu";
17+
import Pagination from "../Pagination/Pagination";
1718

1819
export default function TeamsSearchPage() {
1920
return (
@@ -25,6 +26,8 @@ export default function TeamsSearchPage() {
2526

2627
export function TeamsSearch() {
2728
const location = useLocation();
29+
const pageLength = 50;
30+
const [currentPage, setCurrentPage] = useState(0);
2831
const [searching, setSearching] = useState(false);
2932
const [searchTerm, setSearchTerm] = useState("");
3033
const [currentTeam, setCurrentTeam] = useState<Team | undefined>(undefined);
@@ -56,16 +59,21 @@ export function TeamsSearch() {
5659
try {
5760
const result = await getGitpodService().server.adminGetTeams({
5861
searchTerm,
59-
limit: 100,
62+
limit: pageLength,
6063
orderBy: "creationTime",
61-
offset: 0,
64+
offset: currentPage * pageLength,
6265
orderDir: "desc",
6366
});
6467
setSearchResult(result);
6568
} finally {
6669
setSearching(false);
6770
}
6871
};
72+
73+
const updatePage = (page: number) => {
74+
setCurrentPage(page);
75+
search();
76+
};
6977
return (
7078
<>
7179
<div className="pt-8 flex">
@@ -120,6 +128,11 @@ export function TeamsSearch() {
120128
<TeamResultItem team={team} />
121129
))}
122130
</div>
131+
<Pagination
132+
currentPage={currentPage}
133+
setPage={updatePage}
134+
totalNumberOfPages={searchResult.total / pageLength}
135+
/>
123136
</>
124137
);
125138

components/dashboard/src/admin/UserSearch.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ import moment from "moment";
99
import { useEffect, useState } from "react";
1010
import { useLocation } from "react-router";
1111
import { Link } from "react-router-dom";
12+
import Pagination from "../Pagination/Pagination";
1213
import { getGitpodService } from "../service/service";
1314
import { PageWithAdminSubMenu } from "./PageWithAdminSubMenu";
1415
import UserDetail from "./UserDetail";
1516

1617
export default function UserSearch() {
1718
const location = useLocation();
19+
const pageLength = 50;
20+
const [currentPage, setCurrentPage] = useState(0);
1821
const [searchResult, setSearchResult] = useState<AdminGetListResult<User>>({ rows: [], total: 0 });
1922
const [searchTerm, setSearchTerm] = useState("");
2023
const [searching, setSearching] = useState(false);
@@ -46,16 +49,21 @@ export default function UserSearch() {
4649
try {
4750
const result = await getGitpodService().server.adminGetUsers({
4851
searchTerm,
49-
limit: 50,
52+
limit: pageLength,
5053
orderBy: "creationDate",
51-
offset: 0,
54+
offset: currentPage * pageLength,
5255
orderDir: "desc",
5356
});
5457
setSearchResult(result);
5558
} finally {
5659
setSearching(false);
5760
}
5861
};
62+
63+
const updatePage = (page: number) => {
64+
setCurrentPage(page);
65+
search();
66+
};
5967
return (
6068
<PageWithAdminSubMenu title="Users" subtitle="Search and manage all users.">
6169
<div className="pt-8 flex">
@@ -103,6 +111,11 @@ export default function UserSearch() {
103111
<UserEntry user={u} />
104112
))}
105113
</div>
114+
<Pagination
115+
currentPage={currentPage}
116+
setPage={updatePage}
117+
totalNumberOfPages={searchResult.total / pageLength}
118+
/>
106119
</PageWithAdminSubMenu>
107120
);
108121
}

components/dashboard/src/admin/WorkspacesSearch.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import moment from "moment";
1919
import { useEffect, useState } from "react";
2020
import { useLocation } from "react-router";
2121
import { Link } from "react-router-dom";
22+
import Pagination from "../Pagination/Pagination";
2223
import { getGitpodService } from "../service/service";
2324
import { getProject, WorkspaceStatusIndicator } from "../workspaces/WorkspaceEntry";
2425
import WorkspaceDetail from "./WorkspaceDetail";
@@ -39,6 +40,8 @@ export default function WorkspaceSearchPage() {
3940

4041
export function WorkspaceSearch(props: Props) {
4142
const location = useLocation();
43+
const pageLength = 50;
44+
const [currentPage, setCurrentPage] = useState(0);
4245
const [searchResult, setSearchResult] = useState<AdminGetListResult<WorkspaceAndInstance>>({ rows: [], total: 0 });
4346
const [queryTerm, setQueryTerm] = useState("");
4447
const [searching, setSearching] = useState(false);
@@ -92,9 +95,9 @@ export function WorkspaceSearch(props: Props) {
9295
}
9396

9497
const result = await getGitpodService().server.adminGetWorkspaces({
95-
limit: 100,
98+
limit: pageLength,
9699
orderBy: "instanceCreationTime",
97-
offset: 0,
100+
offset: currentPage * pageLength,
98101
orderDir: "desc",
99102
...query,
100103
});
@@ -103,6 +106,12 @@ export function WorkspaceSearch(props: Props) {
103106
setSearching(false);
104107
}
105108
};
109+
110+
const updatePage = (page: number) => {
111+
setCurrentPage(page);
112+
search();
113+
};
114+
106115
return (
107116
<>
108117
<div className="pt-8 flex">
@@ -152,6 +161,11 @@ export function WorkspaceSearch(props: Props) {
152161
<WorkspaceEntry ws={ws} />
153162
))}
154163
</div>
164+
<Pagination
165+
currentPage={currentPage}
166+
setPage={updatePage}
167+
totalNumberOfPages={searchResult.total / pageLength}
168+
/>
155169
</>
156170
);
157171
}

0 commit comments

Comments
 (0)