From df132444bda0c0fe0caec65becead4eaaedc3841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Tron=C3=AD=C4=8Dek?= Date: Fri, 24 Jan 2025 14:29:28 +0000 Subject: [PATCH] Remove unused Dashboard components and hooks --- components/dashboard/src/components/Card.tsx | 21 --- .../src/components/RepositoryURL.tsx | 17 -- .../dashboard/src/components/SolidCard.tsx | 21 --- .../auth-providers/get-auth-provider-query.ts | 26 --- .../current-user/authenticated-user-query.ts | 23 --- .../latest-project-prebuild-query.ts | 41 ----- .../src/data/projects/project-queries.ts | 94 ---------- .../projects/set-project-env-var-mutation.ts | 26 --- .../dashboard/src/hooks/use-local-storage.ts | 35 ---- .../dashboard/src/icons/GitpodEngraved.tsx | 93 ---------- .../dashboard/src/icons/IconEarlyAccess.tsx | 165 ------------------ 11 files changed, 562 deletions(-) delete mode 100644 components/dashboard/src/components/Card.tsx delete mode 100644 components/dashboard/src/components/RepositoryURL.tsx delete mode 100644 components/dashboard/src/components/SolidCard.tsx delete mode 100644 components/dashboard/src/data/auth-providers/get-auth-provider-query.ts delete mode 100644 components/dashboard/src/data/current-user/authenticated-user-query.ts delete mode 100644 components/dashboard/src/data/prebuilds/latest-project-prebuild-query.ts delete mode 100644 components/dashboard/src/data/projects/project-queries.ts delete mode 100644 components/dashboard/src/data/projects/set-project-env-var-mutation.ts delete mode 100644 components/dashboard/src/hooks/use-local-storage.ts delete mode 100644 components/dashboard/src/icons/GitpodEngraved.tsx delete mode 100644 components/dashboard/src/icons/IconEarlyAccess.tsx diff --git a/components/dashboard/src/components/Card.tsx b/components/dashboard/src/components/Card.tsx deleted file mode 100644 index 4f832dfde879e5..00000000000000 --- a/components/dashboard/src/components/Card.tsx +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright (c) 2021 Gitpod GmbH. All rights reserved. - * Licensed under the GNU Affero General Public License (AGPL). - * See License.AGPL.txt in the project root for license information. - */ - -function Card(p: { className?: string; onClick?: () => void; children?: React.ReactNode }) { - return ( -
- {p.children} -
- ); -} - -export default Card; diff --git a/components/dashboard/src/components/RepositoryURL.tsx b/components/dashboard/src/components/RepositoryURL.tsx deleted file mode 100644 index ef3180738534a9..00000000000000 --- a/components/dashboard/src/components/RepositoryURL.tsx +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Copyright (c) 2023 Gitpod GmbH. All rights reserved. - * Licensed under the GNU Affero General Public License (AGPL). - * See License.AGPL.txt in the project root for license information. - */ - -import { FC } from "react"; - -type Props = { - className?: string; - children: string; -}; -export const RepositoryURL: FC = ({ className, children }) => { - const cleanURL = children.endsWith(".git") ? children.slice(0, -4) : children; - - return {cleanURL}; -}; diff --git a/components/dashboard/src/components/SolidCard.tsx b/components/dashboard/src/components/SolidCard.tsx deleted file mode 100644 index 0e61d5197c6217..00000000000000 --- a/components/dashboard/src/components/SolidCard.tsx +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright (c) 2021 Gitpod GmbH. All rights reserved. - * Licensed under the GNU Affero General Public License (AGPL). - * See License.AGPL.txt in the project root for license information. - */ - -function SolidCard(p: { className?: string; onClick?: () => void; children?: React.ReactNode }) { - return ( -
- {p.children} -
- ); -} - -export default SolidCard; diff --git a/components/dashboard/src/data/auth-providers/get-auth-provider-query.ts b/components/dashboard/src/data/auth-providers/get-auth-provider-query.ts deleted file mode 100644 index 93faf19b670509..00000000000000 --- a/components/dashboard/src/data/auth-providers/get-auth-provider-query.ts +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2023 Gitpod GmbH. All rights reserved. - * Licensed under the GNU Affero General Public License (AGPL). - * See License.AGPL.txt in the project root for license information. - */ - -import { useQuery } from "@tanstack/react-query"; -import { authProviderClient } from "../../service/public-api"; -import { AuthProvider, GetAuthProviderRequest } from "@gitpod/public-api/lib/gitpod/v1/authprovider_pb"; - -export const useGetAuthProviderQuery = (authProviderId: string | undefined) => { - return useQuery(getAuthProviderQueryKey(authProviderId || ""), async () => { - if (!authProviderId) { - return; - } - const { authProvider } = await authProviderClient.getAuthProvider( - new GetAuthProviderRequest({ - authProviderId: authProviderId, - }), - ); - - return authProvider; - }); -}; - -export const getAuthProviderQueryKey = (authProviderId: string) => ["auth-provider", { authProviderId }]; diff --git a/components/dashboard/src/data/current-user/authenticated-user-query.ts b/components/dashboard/src/data/current-user/authenticated-user-query.ts deleted file mode 100644 index f9fde8b45e28fe..00000000000000 --- a/components/dashboard/src/data/current-user/authenticated-user-query.ts +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright (c) 2023 Gitpod GmbH. All rights reserved. - * Licensed under the GNU Affero General Public License (AGPL). - * See License.AGPL.txt in the project root for license information. - */ - -import { useQuery } from "@tanstack/react-query"; -import { userClient } from "../../service/public-api"; -import { GetAuthenticatedUserRequest, User } from "@gitpod/public-api/lib/gitpod/v1/user_pb"; - -export const useAuthenticatedUser = () => { - const query = useQuery({ - queryKey: getAuthenticatedUserQueryKey(), - queryFn: async () => { - const params = new GetAuthenticatedUserRequest(); - const response = await userClient.getAuthenticatedUser(params); - return response.user!; - }, - }); - return query; -}; - -export const getAuthenticatedUserQueryKey = () => ["authenticated-user", {}]; diff --git a/components/dashboard/src/data/prebuilds/latest-project-prebuild-query.ts b/components/dashboard/src/data/prebuilds/latest-project-prebuild-query.ts deleted file mode 100644 index afb5640793ad5d..00000000000000 --- a/components/dashboard/src/data/prebuilds/latest-project-prebuild-query.ts +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright (c) 2023 Gitpod GmbH. All rights reserved. - * Licensed under the GNU Affero General Public License (AGPL). - * See License.AGPL.txt in the project root for license information. - */ - -import { useQuery } from "@tanstack/react-query"; -import { prebuildClient } from "../../service/public-api"; -import { Prebuild } from "@gitpod/public-api/lib/gitpod/v1/prebuild_pb"; -import { ApplicationError, ErrorCodes } from "@gitpod/gitpod-protocol/lib/messaging/error"; - -type Args = { - projectId: string; -}; -export const useLatestProjectPrebuildQuery = ({ projectId }: Args) => { - return useQuery({ - queryKey: getLatestProjectPrebuildQueryKey(projectId), - // Prevent bursting for latest project prebuilds too frequently - staleTime: 1000 * 60 * 1, // 1 minute - queryFn: async () => { - try { - const response = await prebuildClient.listPrebuilds({ - configurationId: projectId, - pagination: { - pageSize: 1, - }, - }); - return response.prebuilds[0] || null; - } catch (e) { - if (ApplicationError.hasErrorCode(e) && e.code === ErrorCodes.NOT_FOUND) { - return null; - } - throw e; - } - }, - }); -}; - -export const getLatestProjectPrebuildQueryKey = (projectId: string) => { - return ["prebuilds", "latest", { projectId }]; -}; diff --git a/components/dashboard/src/data/projects/project-queries.ts b/components/dashboard/src/data/projects/project-queries.ts deleted file mode 100644 index 4fbf122d168415..00000000000000 --- a/components/dashboard/src/data/projects/project-queries.ts +++ /dev/null @@ -1,94 +0,0 @@ -/** - * Copyright (c) 2023 Gitpod GmbH. All rights reserved. - * Licensed under the GNU Affero General Public License (AGPL). - * See License.AGPL.txt in the project root for license information. - */ - -import { Project } from "@gitpod/gitpod-protocol/lib/teams-projects-protocol"; -import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; -import { useCurrentOrg } from "../organizations/orgs-query"; -import { listAllProjects, projectsService } from "../../service/public-api"; -import type { PartialProject } from "@gitpod/gitpod-protocol"; -import { getGitpodService } from "../../service/service"; - -const BASE_KEY = "projects"; - -type UseProjectArgs = { - id: string; -}; -export const useProject = ({ id }: UseProjectArgs) => { - const { data: org } = useCurrentOrg(); - - return useQuery( - getProjectQueryKey(org?.id || "", id), - async () => { - if (!org) { - throw new Error("No current org"); - } - - // TODO: This is temporary until we create a project by id endpoint - // Waiting to tackle that once we have the new grpc setup for server - const projects = await listAllProjects({ orgId: org.id }); - const project = projects.find((p) => p.id === id); - - return project || null; - }, - { - enabled: !!org, - }, - ); -}; - -const getProjectQueryKey = (orgId: string, id: string) => { - return [BASE_KEY, { orgId, id }]; -}; - -type ListProjectsQueryArgs = { - page: number; - pageSize: number; -}; - -export const useListProjectsQuery = ({ page, pageSize }: ListProjectsQueryArgs) => { - const { data: org } = useCurrentOrg(); - - return useQuery( - getListProjectsQueryKey(org?.id || "", { page, pageSize }), - async () => { - if (!org) { - throw new Error("No org currently selected"); - } - - return projectsService.listProjects({ teamId: org.id, pagination: { page, pageSize } }); - }, - { - enabled: !!org, - }, - ); -}; - -export const getListProjectsQueryKey = (orgId: string, args?: ListProjectsQueryArgs) => { - const key: any[] = [BASE_KEY, "list", { orgId }]; - if (args) { - key.push(args); - } - - return key; -}; - -export const useUpdateProject = () => { - const { data: org } = useCurrentOrg(); - const client = useQueryClient(); - - return useMutation(async (settings) => { - if (!org) { - throw new Error("No org currently selected"); - } - - await getGitpodService().server.updateProjectPartial(settings); - - // Invalidate project - client.invalidateQueries(getProjectQueryKey(org.id, settings.id)); - // Invalidate project list queries - client.invalidateQueries(getListProjectsQueryKey(org.id)); - }); -}; diff --git a/components/dashboard/src/data/projects/set-project-env-var-mutation.ts b/components/dashboard/src/data/projects/set-project-env-var-mutation.ts deleted file mode 100644 index b9e3271b12fa1c..00000000000000 --- a/components/dashboard/src/data/projects/set-project-env-var-mutation.ts +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Copyright (c) 2023 Gitpod GmbH. All rights reserved. - * Licensed under the GNU Affero General Public License (AGPL). - * See License.AGPL.txt in the project root for license information. - */ - -import { useMutation } from "@tanstack/react-query"; -import { envVarClient } from "../../service/public-api"; -import { EnvironmentVariableAdmission } from "@gitpod/public-api/lib/gitpod/v1/envvar_pb"; - -type SetProjectEnvVarArgs = { - configurationId: string; - name: string; - value: string; - admission: EnvironmentVariableAdmission; -}; -export const useSetProjectEnvVar = () => { - return useMutation(async ({ configurationId, name, value, admission }) => { - await envVarClient.createConfigurationEnvironmentVariable({ - name, - value, - configurationId, - admission, - }); - }); -}; diff --git a/components/dashboard/src/hooks/use-local-storage.ts b/components/dashboard/src/hooks/use-local-storage.ts deleted file mode 100644 index f0ab5aa0922faa..00000000000000 --- a/components/dashboard/src/hooks/use-local-storage.ts +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright (c) 2022 Gitpod GmbH. All rights reserved. - * Licensed under the GNU Affero General Public License (AGPL). - * See License.AGPL.txt in the project root for license information. - */ - -import { Dispatch, SetStateAction, useEffect, useState } from "react"; - -type SetValue = Dispatch>; - -export function useLocalStorage(key: string, initialValue: T): [T, SetValue] { - const [storedValue, setStoredValue] = useState(() => { - try { - const item = window?.localStorage?.getItem(key); - if (item) { - return JSON.parse(item); - } - } catch (error) { - console.log(error); - } - return initialValue; - }); - - useEffect(() => { - try { - if (typeof window !== "undefined") { - window.localStorage.setItem(key, JSON.stringify(storedValue)); - } - } catch (error) { - console.log(error); - } - }, [key, storedValue]); - - return [storedValue, setStoredValue]; -} diff --git a/components/dashboard/src/icons/GitpodEngraved.tsx b/components/dashboard/src/icons/GitpodEngraved.tsx deleted file mode 100644 index a4828aacaf346b..00000000000000 --- a/components/dashboard/src/icons/GitpodEngraved.tsx +++ /dev/null @@ -1,93 +0,0 @@ -/** - * Copyright (c) 2024 Gitpod GmbH. All rights reserved. - * Licensed under the GNU Affero General Public License (AGPL). - * See License.AGPL.txt in the project root for license information. - */ - -import { PropsWithClassName } from "@podkit/lib/cn"; -import type { FC } from "react"; - -export const IconGitpodEngraved: FC<{ variant: "light" | "dark" } & PropsWithClassName> = ({ variant, className }) => { - switch (variant) { - case "light": - return ( - - - - - - - - - - - - - - - - - - ); - case "dark": - return ( - - - - - - - - - - - - - - - - - - ); - } -}; diff --git a/components/dashboard/src/icons/IconEarlyAccess.tsx b/components/dashboard/src/icons/IconEarlyAccess.tsx deleted file mode 100644 index 6cb35193d72b46..00000000000000 --- a/components/dashboard/src/icons/IconEarlyAccess.tsx +++ /dev/null @@ -1,165 +0,0 @@ -/** - * Copyright (c) 2024 Gitpod GmbH. All rights reserved. - * Licensed under the GNU Affero General Public License (AGPL). - * See License.AGPL.txt in the project root for license information. - */ - -// shamelessly stolen from the Flex repo - -import { PropsWithClassName } from "@podkit/lib/cn"; -import { FC } from "react"; - -export const IconEarlyAccess: FC<{ variant: "light" | "dark" } & PropsWithClassName> = ({ variant, className }) => { - switch (variant) { - case "light": - return ( - - - - - - - - - - - - - - - - - - - - - - - - - ); - case "dark": - return ( - - - - - - - - - - - - - - - - - - - - - - - - - ); - } -};