Skip to content

Commit da125ed

Browse files
authored
Migrate InstallationService GetInstallationWorkspaceDefaultImage method (#19221)
1 parent 633f991 commit da125ed

File tree

13 files changed

+581
-247
lines changed

13 files changed

+581
-247
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 { installationClient } from "../../service/public-api";
9+
10+
export const useInstallationDefaultWorkspaceImageQuery = () => {
11+
return useQuery({
12+
queryKey: ["installation-default-workspace-image"],
13+
staleTime: 1000 * 60 * 10, // 10 minute
14+
queryFn: async () => {
15+
const response = await installationClient.getInstallationWorkspaceDefaultImage({});
16+
return response.defaultWorkspaceImage;
17+
},
18+
});
19+
};

components/dashboard/src/data/workspaces/default-workspace-image-query.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,9 @@
55
*/
66

77
import { useQuery } from "@tanstack/react-query";
8-
import { getGitpodService } from "../../service/service";
9-
import { GetDefaultWorkspaceImageResult } from "@gitpod/gitpod-protocol";
108
import { GetWorkspaceDefaultImageResponse } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
119
import { workspaceClient } from "../../service/public-api";
1210

13-
export const useDefaultWorkspaceImageQuery = (workspaceId?: string) => {
14-
return useQuery<GetDefaultWorkspaceImageResult>({
15-
queryKey: ["default-workspace-image", { workspaceId }],
16-
staleTime: 1000 * 60 * 10, // 10 minute
17-
queryFn: async () => {
18-
// without `workspaceId` getDefaultWorkspaceImage will return org setting and if not set fallback to installation
19-
return await getGitpodService().server.getDefaultWorkspaceImage({ workspaceId });
20-
},
21-
});
22-
};
23-
2411
export const useWorkspaceDefaultImageQuery = (workspaceId: string) => {
2512
return useQuery<GetWorkspaceDefaultImageResponse>({
2613
queryKey: ["default-workspace-image-v2", { workspaceId }],

components/dashboard/src/service/json-rpc-installation-client.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,26 @@ import {
1818
ListBlockedEmailDomainsResponse,
1919
CreateBlockedEmailDomainRequest,
2020
CreateBlockedEmailDomainResponse,
21+
GetInstallationWorkspaceDefaultImageRequest,
22+
GetInstallationWorkspaceDefaultImageResponse,
2123
} from "@gitpod/public-api/lib/gitpod/v1/installation_pb";
2224
import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error";
2325
import { getGitpodService } from "./service";
2426
import { converter } from "./public-api";
2527
import { PaginationResponse } from "@gitpod/public-api/lib/gitpod/v1/pagination_pb";
2628

2729
export class JsonRpcInstallationClient implements PromiseClient<typeof InstallationService> {
30+
async getInstallationWorkspaceDefaultImage(
31+
_request: PartialMessage<GetInstallationWorkspaceDefaultImageRequest>,
32+
_options?: CallOptions,
33+
): Promise<GetInstallationWorkspaceDefaultImageResponse> {
34+
const result = await getGitpodService().server.getDefaultWorkspaceImage({});
35+
if (result.source !== "installation") {
36+
throw new ApplicationError(ErrorCodes.INTERNAL_SERVER_ERROR, "unexpected image source");
37+
}
38+
return new GetInstallationWorkspaceDefaultImageResponse({ defaultWorkspaceImage: result.image });
39+
}
40+
2841
async listBlockedRepositories(
2942
request: PartialMessage<ListBlockedRepositoriesRequest>,
3043
_options?: CallOptions | undefined,

components/dashboard/src/teams/TeamSettings.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { useOrgSettingsQuery } from "../data/organizations/org-settings-query";
1919
import { useCurrentOrg, useOrganizationsInvalidator } from "../data/organizations/orgs-query";
2020
import { useUpdateOrgMutation } from "../data/organizations/update-org-mutation";
2121
import { useUpdateOrgSettingsMutation } from "../data/organizations/update-org-settings-mutation";
22-
import { useDefaultWorkspaceImageQuery } from "../data/workspaces/default-workspace-image-query";
2322
import { useOnBlurError } from "../hooks/use-onblur-error";
2423
import { ReactComponent as Stack } from "../icons/Stack.svg";
2524
import { organizationClient } from "../service/public-api";
@@ -28,6 +27,7 @@ import { useCurrentUser } from "../user-context";
2827
import { OrgSettingsPage } from "./OrgSettingsPage";
2928
import { ErrorCode } from "@gitpod/gitpod-protocol/lib/messaging/error";
3029
import { Button } from "@podkit/buttons/Button";
30+
import { useInstallationDefaultWorkspaceImageQuery } from "../data/installation/default-workspace-image-query";
3131

3232
export default function TeamSettingsPage() {
3333
const user = useCurrentUser();
@@ -176,7 +176,7 @@ export default function TeamSettingsPage() {
176176
function OrgSettingsForm(props: { org?: Organization; isOwner: boolean }) {
177177
const { org, isOwner } = props;
178178
const { data: settings, isLoading } = useOrgSettingsQuery();
179-
const { data: imageInfo } = useDefaultWorkspaceImageQuery();
179+
const { data: installationDefaultImage } = useInstallationDefaultWorkspaceImageQuery();
180180
const updateTeamSettings = useUpdateOrgSettingsMutation();
181181

182182
const [showImageEditModal, setShowImageEditModal] = useState(false);
@@ -238,14 +238,14 @@ function OrgSettingsForm(props: { org?: Organization; isOwner: boolean }) {
238238
<WorkspaceImageButton
239239
disabled={!isOwner}
240240
settings={settings}
241-
defaultWorkspaceImage={imageInfo?.image}
241+
installationDefaultWorkspaceImage={installationDefaultImage}
242242
onClick={() => setShowImageEditModal(true)}
243243
/>
244244

245245
{showImageEditModal && (
246246
<OrgDefaultWorkspaceImageModal
247247
settings={settings}
248-
globalDefaultImage={imageInfo?.image}
248+
installationDefaultWorkspaceImage={installationDefaultImage}
249249
onClose={() => setShowImageEditModal(false)}
250250
/>
251251
)}
@@ -255,7 +255,7 @@ function OrgSettingsForm(props: { org?: Organization; isOwner: boolean }) {
255255

256256
function WorkspaceImageButton(props: {
257257
settings?: OrganizationSettings;
258-
defaultWorkspaceImage?: string;
258+
installationDefaultWorkspaceImage?: string;
259259
onClick: () => void;
260260
disabled?: boolean;
261261
}) {
@@ -282,7 +282,7 @@ function WorkspaceImageButton(props: {
282282
};
283283
}
284284

285-
const image = props.settings?.defaultWorkspaceImage || props.defaultWorkspaceImage || "";
285+
const image = props.settings?.defaultWorkspaceImage || props.installationDefaultWorkspaceImage || "";
286286

287287
const descList = useMemo(() => {
288288
const arr: ReactNode[] = [<span>Default image</span>];
@@ -335,7 +335,7 @@ function WorkspaceImageButton(props: {
335335
}
336336

337337
interface OrgDefaultWorkspaceImageModalProps {
338-
globalDefaultImage: string | undefined;
338+
installationDefaultWorkspaceImage: string | undefined;
339339
settings: OrganizationSettings | undefined;
340340
onClose: () => void;
341341
}
@@ -385,7 +385,7 @@ function OrgDefaultWorkspaceImageModal(props: OrgDefaultWorkspaceImageModalProps
385385
<TextInputField
386386
label="Default Image"
387387
hint="Use any official or custom workspace image from Docker Hub or any private container registry that the Gitpod instance can access."
388-
placeholder={props.globalDefaultImage}
388+
placeholder={props.installationDefaultWorkspaceImage}
389389
value={defaultWorkspaceImage}
390390
onChange={setDefaultWorkspaceImage}
391391
/>

components/public-api/gitpod/v1/installation.proto

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import "google/protobuf/timestamp.proto";
99
option go_package = "github.com/gitpod-io/gitpod/components/public-api/go/v1";
1010

1111
service InstallationService {
12+
// GetInstallationWorkspaceDefaultImage returns the default image for current
13+
// Gitpod Installation.
14+
rpc GetInstallationWorkspaceDefaultImage(GetInstallationWorkspaceDefaultImageRequest) returns (GetInstallationWorkspaceDefaultImageResponse) {}
15+
1216
// ListBlockedRepositories lists blocked repositories.
1317
rpc ListBlockedRepositories(ListBlockedRepositoriesRequest) returns (ListBlockedRepositoriesResponse) {}
1418

@@ -25,6 +29,12 @@ service InstallationService {
2529
rpc CreateBlockedEmailDomain(CreateBlockedEmailDomainRequest) returns (CreateBlockedEmailDomainResponse) {}
2630
}
2731

32+
message GetInstallationWorkspaceDefaultImageRequest {}
33+
34+
message GetInstallationWorkspaceDefaultImageResponse {
35+
string default_workspace_image = 1;
36+
}
37+
2838
message ListBlockedRepositoriesRequest {
2939
// pagination contains the pagination options for listing blocked repositories
3040
PaginationRequest pagination = 1;

0 commit comments

Comments
 (0)