Skip to content

Commit 1508e56

Browse files
committed
binding config service api to server
1 parent 9e5879e commit 1508e56

File tree

5 files changed

+73
-10
lines changed

5 files changed

+73
-10
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Copyright (c) 2023 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License.AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { useQuery } from "@tanstack/react-query";
8+
import { useCurrentOrg } from "../organizations/orgs-query";
9+
import { configurationClient } from "../../service/public-api";
10+
11+
const BASE_KEY = "configurations";
12+
13+
type ListConfigurationsQueryArgs = {
14+
searchTerm?: string;
15+
page: number;
16+
pageSize: number;
17+
};
18+
19+
export const useListConfigurationsQuery = ({ searchTerm = "", page, pageSize }: ListConfigurationsQueryArgs) => {
20+
const { data: org } = useCurrentOrg();
21+
22+
return useQuery(
23+
getListConfigurationsQueryKey(org?.id || "", { searchTerm, page, pageSize }),
24+
async () => {
25+
if (!org) {
26+
throw new Error("No org currently selected");
27+
}
28+
29+
const response = await configurationClient.listConfigurations({
30+
organizationId: org.id,
31+
searchTerm,
32+
pagination: { page, pageSize },
33+
});
34+
35+
return response;
36+
},
37+
{
38+
enabled: !!org,
39+
},
40+
);
41+
};
42+
43+
export const getListConfigurationsQueryKey = (orgId: string, args?: ListConfigurationsQueryArgs) => {
44+
const key: any[] = [BASE_KEY, "list", { orgId }];
45+
if (args) {
46+
key.push(args);
47+
}
48+
49+
return key;
50+
};

components/dashboard/src/repositories/list/RepoListItem.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ import { TextMuted } from "@podkit/typography/TextMuted";
1010
import { Text } from "@podkit/typography/Text";
1111
import { Link } from "react-router-dom";
1212
import { Button } from "../../components/Button";
13-
import { Project } from "@gitpod/public-api/lib/gitpod/experimental/v1/projects_pb";
13+
import { Configuration } from "@gitpod/public-api/lib/gitpod/v1/configuration_pb";
1414

1515
type Props = {
16-
project: Project;
16+
configuration: Configuration;
1717
};
18-
export const RepositoryListItem: FC<Props> = ({ project }) => {
19-
const url = usePrettyRepoURL(project.cloneUrl);
18+
export const RepositoryListItem: FC<Props> = ({ configuration }) => {
19+
const url = usePrettyRepoURL(configuration.cloneUrl);
2020

2121
return (
22-
<li key={project.id} className="flex flex-row w-full space-between items-center">
22+
<li key={configuration.id} className="flex flex-row w-full space-between items-center">
2323
<div className="flex flex-col flex-grow gap-1">
24-
<Text className="font-semibold">{project.name}</Text>
24+
<Text className="font-semibold">{configuration.name}</Text>
2525
<TextMuted className="text-sm">{url}</TextMuted>
2626
</div>
2727

2828
<div>
29-
<Link to={`/repositories/${project.id}`}>
29+
<Link to={`/repositories/${configuration.id}`}>
3030
<Button type="secondary">View</Button>
3131
</Link>
3232
</div>

components/dashboard/src/repositories/list/RepositoryList.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@
66

77
import { FC, useCallback, useState } from "react";
88
import Header from "../../components/Header";
9-
import { useListProjectsQuery } from "../../data/projects/project-queries";
109
import { Loader2 } from "lucide-react";
1110
import { useHistory } from "react-router-dom";
1211
import { Project } from "@gitpod/gitpod-protocol";
1312
import { CreateProjectModal } from "../../projects/create-project-modal/CreateProjectModal";
1413
import { Button } from "../../components/Button";
1514
import { RepositoryListItem } from "./RepoListItem";
15+
import { useListConfigurationsQuery } from "../../data/configurations/configuration-queries";
16+
import { useStateWithDebounce } from "../../hooks/use-state-with-debounce";
17+
import { TextInput } from "../../components/forms/TextInputField";
1618

1719
const RepositoryListPage: FC = () => {
1820
const history = useHistory();
19-
const { data, isLoading } = useListProjectsQuery({ page: 1, pageSize: 10 });
21+
const [searchTerm, setSearchTerm, debouncedSearchTerm] = useStateWithDebounce("");
22+
const { data, isLoading } = useListConfigurationsQuery({ searchTerm: debouncedSearchTerm, page: 1, pageSize: 10 });
2023
const [showCreateProjectModal, setShowCreateProjectModal] = useState(false);
2124

2225
const handleProjectCreated = useCallback(
@@ -35,11 +38,17 @@ const RepositoryListPage: FC = () => {
3538
<Button onClick={() => setShowCreateProjectModal(true)}>Configure Repository</Button>
3639
</div>
3740

41+
<div>
42+
<TextInput value={searchTerm} onChange={setSearchTerm} placeholder="Search repositories" />
43+
</div>
44+
3845
{isLoading && <Loader2 className="animate-spin" />}
3946

4047
<ul className="space-y-2 mt-8">
4148
{!isLoading &&
42-
data?.projects.map((project) => <RepositoryListItem key={project.id} project={project} />)}
49+
data?.configurations.map((configuration) => (
50+
<RepositoryListItem key={configuration.id} configuration={configuration} />
51+
))}
4352
</ul>
4453
</div>
4554

components/dashboard/src/service/public-api.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { TokensService } from "@gitpod/public-api/lib/gitpod/experimental/v1/tok
1818
import { WorkspacesService as WorkspaceV1Service } from "@gitpod/public-api/lib/gitpod/experimental/v1/workspaces_connect";
1919
import { OrganizationService } from "@gitpod/public-api/lib/gitpod/v1/organization_connect";
2020
import { WorkspaceService } from "@gitpod/public-api/lib/gitpod/v1/workspace_connect";
21+
import { ConfigurationService } from "@gitpod/public-api/lib/gitpod/v1/configuration_connect";
2122
import { getMetricsInterceptor } from "@gitpod/public-api/lib/metrics";
2223
import { getExperimentsClient } from "../experiments/client";
2324
import { JsonRpcOrganizationClient } from "./json-rpc-organization-client";
@@ -45,6 +46,8 @@ export const organizationClient = createServiceClient(
4546
new JsonRpcOrganizationClient(),
4647
"organization",
4748
);
49+
// No jsonrcp client for the configuration service as it's only used in new UI of the dashboard
50+
export const configurationClient = createServiceClient(ConfigurationService);
4851

4952
export async function listAllProjects(opts: { orgId: string }): Promise<ProtocolProject[]> {
5053
let pagination = {

components/server/src/api/server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ export class API {
303303
bind(TeamsServiceAPI).toSelf().inSingletonScope();
304304
bind(WorkspaceServiceAPI).toSelf().inSingletonScope();
305305
bind(OrganizationServiceAPI).toSelf().inSingletonScope();
306+
bind(ConfigurationServiceAPI).toSelf().inSingletonScope();
306307
bind(StatsServiceAPI).toSelf().inSingletonScope();
307308
bind(API).toSelf().inSingletonScope();
308309
}

0 commit comments

Comments
 (0)