Skip to content

Commit 24cc79f

Browse files
committed
use getConfiguration in dashboard
1 parent 1508e56 commit 24cc79f

File tree

4 files changed

+34
-18
lines changed

4 files changed

+34
-18
lines changed

components/dashboard/src/data/configurations/configuration-queries.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@
77
import { useQuery } from "@tanstack/react-query";
88
import { useCurrentOrg } from "../organizations/orgs-query";
99
import { configurationClient } from "../../service/public-api";
10+
import { Configuration } from "@gitpod/public-api/lib/gitpod/v1/configuration_pb";
1011

1112
const BASE_KEY = "configurations";
1213

13-
type ListConfigurationsQueryArgs = {
14+
type ListConfigurationsArgs = {
1415
searchTerm?: string;
1516
page: number;
1617
pageSize: number;
1718
};
1819

19-
export const useListConfigurationsQuery = ({ searchTerm = "", page, pageSize }: ListConfigurationsQueryArgs) => {
20+
export const useListConfigurations = ({ searchTerm = "", page, pageSize }: ListConfigurationsArgs) => {
2021
const { data: org } = useCurrentOrg();
2122

2223
return useQuery(
@@ -26,25 +27,41 @@ export const useListConfigurationsQuery = ({ searchTerm = "", page, pageSize }:
2627
throw new Error("No org currently selected");
2728
}
2829

29-
const response = await configurationClient.listConfigurations({
30+
const { configurations, pagination } = await configurationClient.listConfigurations({
3031
organizationId: org.id,
3132
searchTerm,
3233
pagination: { page, pageSize },
3334
});
3435

35-
return response;
36+
return { configurations, pagination };
3637
},
3738
{
3839
enabled: !!org,
3940
},
4041
);
4142
};
4243

43-
export const getListConfigurationsQueryKey = (orgId: string, args?: ListConfigurationsQueryArgs) => {
44+
export const getListConfigurationsQueryKey = (orgId: string, args?: ListConfigurationsArgs) => {
4445
const key: any[] = [BASE_KEY, "list", { orgId }];
4546
if (args) {
4647
key.push(args);
4748
}
4849

4950
return key;
5051
};
52+
53+
export const useConfiguration = (configurationId: string) => {
54+
return useQuery<Configuration | undefined, Error>(getConfigurationQueryKey(configurationId), async () => {
55+
const { configuration } = await configurationClient.getConfiguration({
56+
configurationId,
57+
});
58+
59+
return configuration;
60+
});
61+
};
62+
63+
export const getConfigurationQueryKey = (configurationId: string) => {
64+
const key: any[] = [BASE_KEY, { configurationId }];
65+
66+
return key;
67+
};

components/dashboard/src/repositories/detail/RepositoryDetail.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
import { FC } from "react";
88
import Header from "../../components/Header";
99
import { useParams } from "react-router";
10-
import { useProject } from "../../data/projects/project-queries";
1110
import { Button } from "../../components/Button";
1211
import { RepositoryNameForm } from "./RepositoryName";
1312
import { Loader2 } from "lucide-react";
1413
import Alert from "../../components/Alert";
14+
import { useConfiguration } from "../../data/configurations/configuration-queries";
1515

1616
type PageRouteParams = {
1717
id: string;
1818
};
1919
const RepositoryDetailPage: FC = () => {
2020
const { id } = useParams<PageRouteParams>();
21-
const { data, error, isLoading, refetch } = useProject({ id });
21+
const { data, error, isLoading, refetch } = useConfiguration(id);
2222

2323
return (
2424
<>
@@ -42,7 +42,7 @@ const RepositoryDetailPage: FC = () => {
4242
// TODO: add a better not-found UI w/ link back to repositories
4343
<div>Sorry, we couldn't find that repository configuration.</div>
4444
) : (
45-
<RepositoryNameForm project={data} />
45+
<RepositoryNameForm configuration={data} />
4646
))}
4747
</div>
4848
</>

components/dashboard/src/repositories/detail/RepositoryName.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,24 @@
44
* See License.AGPL.txt in the project root for license information.
55
*/
66

7-
// TODO: fix mismatched project types when we build repo configuration apis
8-
import { Project } from "@gitpod/gitpod-protocol/lib/teams-projects-protocol";
97
import { Button } from "../../components/Button";
108
import { TextInputField } from "../../components/forms/TextInputField";
119
import { FC, useCallback, useState } from "react";
1210
import { useUpdateProject } from "../../data/projects/project-queries";
1311
import { useToast } from "../../components/toasts/Toasts";
1412
import { useOnBlurError } from "../../hooks/use-onblur-error";
13+
import { Configuration } from "@gitpod/public-api/lib/gitpod/v1/configuration_pb";
1514

1615
const MAX_LENGTH = 100;
1716

1817
type Props = {
19-
project: Project;
18+
configuration: Configuration;
2019
};
2120

22-
export const RepositoryNameForm: FC<Props> = ({ project }) => {
21+
export const RepositoryNameForm: FC<Props> = ({ configuration }) => {
2322
const { toast } = useToast();
2423
const updateProject = useUpdateProject();
25-
const [projectName, setProjectName] = useState(project.name);
24+
const [projectName, setProjectName] = useState(configuration.name);
2625

2726
const nameError = useOnBlurError("Sorry, this name is too long.", projectName.length <= MAX_LENGTH);
2827

@@ -37,7 +36,7 @@ export const RepositoryNameForm: FC<Props> = ({ project }) => {
3736

3837
updateProject.mutate(
3938
{
40-
id: project.id,
39+
id: configuration.id,
4140
name: projectName,
4241
},
4342
{
@@ -47,7 +46,7 @@ export const RepositoryNameForm: FC<Props> = ({ project }) => {
4746
},
4847
);
4948
},
50-
[nameError.isValid, updateProject, project.id, projectName, toast],
49+
[nameError.isValid, updateProject, configuration.id, projectName, toast],
5150
);
5251

5352
return (
@@ -63,7 +62,7 @@ export const RepositoryNameForm: FC<Props> = ({ project }) => {
6362
<Button
6463
className="mt-4"
6564
htmlType="submit"
66-
disabled={project.name === projectName}
65+
disabled={configuration.name === projectName}
6766
loading={updateProject.isLoading}
6867
>
6968
Update Name

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ import { Project } from "@gitpod/gitpod-protocol";
1212
import { CreateProjectModal } from "../../projects/create-project-modal/CreateProjectModal";
1313
import { Button } from "../../components/Button";
1414
import { RepositoryListItem } from "./RepoListItem";
15-
import { useListConfigurationsQuery } from "../../data/configurations/configuration-queries";
15+
import { useListConfigurations } from "../../data/configurations/configuration-queries";
1616
import { useStateWithDebounce } from "../../hooks/use-state-with-debounce";
1717
import { TextInput } from "../../components/forms/TextInputField";
1818

1919
const RepositoryListPage: FC = () => {
2020
const history = useHistory();
2121
const [searchTerm, setSearchTerm, debouncedSearchTerm] = useStateWithDebounce("");
22-
const { data, isLoading } = useListConfigurationsQuery({ searchTerm: debouncedSearchTerm, page: 1, pageSize: 10 });
22+
const { data, isLoading } = useListConfigurations({ searchTerm: debouncedSearchTerm, page: 1, pageSize: 10 });
2323
const [showCreateProjectModal, setShowCreateProjectModal] = useState(false);
2424

2525
const handleProjectCreated = useCallback(

0 commit comments

Comments
 (0)