From 768429c829fcd1c150b60516e05c71584828b0ff Mon Sep 17 00:00:00 2001 From: Pascal Breuninger Date: Thu, 8 Feb 2024 12:30:15 +0100 Subject: [PATCH] feat(desktop): display authentication status for pro instances; if not authenticated, clicking on icon will trigger relogin --- desktop/src/client/constants.ts | 1 + desktop/src/client/pro/client.ts | 6 +- desktop/src/client/pro/proCommands.ts | 9 ++- desktop/src/components/Layout/Pro.tsx | 67 ++++++++++++++----- .../contexts/DevPodContext/DevPodProvider.tsx | 2 +- desktop/src/types.ts | 7 ++ desktop/src/views/ProInstances/index.ts | 2 +- .../views/ProInstances/useLoginProModal.tsx | 66 +++++++++++++++++- 8 files changed, 132 insertions(+), 28 deletions(-) diff --git a/desktop/src/client/constants.ts b/desktop/src/client/constants.ts index e8355a2a9..7807ed3ec 100644 --- a/desktop/src/client/constants.ts +++ b/desktop/src/client/constants.ts @@ -50,5 +50,6 @@ export const DEVPOD_FLAG_TIMEOUT = "--timeout" export const DEVPOD_FLAG_DEVCONTAINER_PATH = "--devcontainer-path" export const DEVPOD_FLAG_WORKSPACE_ID = "--workspace-id" export const DEVPOD_FLAG_WORKSPACE_UID = "--workspace-uid" +export const DEVPOD_FLAG_LOGIN = "--login" export const DEVPOD_UI_ENV_VAR = "DEVPOD_UI" diff --git a/desktop/src/client/pro/client.ts b/desktop/src/client/pro/client.ts index 742048d0a..bb3a776f0 100644 --- a/desktop/src/client/pro/client.ts +++ b/desktop/src/client/pro/client.ts @@ -1,5 +1,5 @@ import { Result, ResultError } from "../../lib" -import { TImportWorkspaceConfig, TProID, TProInstance } from "../../types" +import { TImportWorkspaceConfig, TListProInstancesConfig, TProID, TProInstance } from "../../types" import { TDebuggable, TStreamEventListenerFn } from "../types" import { ProCommands } from "./proCommands" @@ -19,8 +19,8 @@ export class ProClient implements TDebuggable { return ProCommands.Login(host, providerName, accessKey, listener) } - public async listAll(): Promise> { - return ProCommands.ListProInstances() + public async listAll(config: TListProInstancesConfig): Promise> { + return ProCommands.ListProInstances(config) } public async remove(id: TProID) { diff --git a/desktop/src/client/pro/proCommands.ts b/desktop/src/client/pro/proCommands.ts index 67db496bf..c0906b2d2 100644 --- a/desktop/src/client/pro/proCommands.ts +++ b/desktop/src/client/pro/proCommands.ts @@ -1,5 +1,5 @@ import { Result, ResultError, Return, getErrorFromChildProcess } from "@/lib" -import { TImportWorkspaceConfig, TProID, TProInstance } from "@/types" +import { TImportWorkspaceConfig, TListProInstancesConfig, TProID, TProInstance } from "@/types" import { Command, isOk, serializeRawOptions, toFlagArg } from "../command" import { DEVPOD_COMMAND_DELETE, @@ -11,6 +11,7 @@ import { DEVPOD_FLAG_DEBUG, DEVPOD_FLAG_JSON_LOG_OUTPUT, DEVPOD_FLAG_JSON_OUTPUT, + DEVPOD_FLAG_LOGIN, DEVPOD_FLAG_PROVIDER, DEVPOD_FLAG_USE, DEVPOD_FLAG_WORKSPACE_ID, @@ -62,11 +63,15 @@ export class ProCommands { } } - static async ListProInstances(): Promise> { + static async ListProInstances( + config: TListProInstancesConfig + ): Promise> { + const maybeLoginFlag = config?.authenticate ? [DEVPOD_FLAG_LOGIN] : [] const result = await ProCommands.newCommand([ DEVPOD_COMMAND_PRO, DEVPOD_COMMAND_LIST, DEVPOD_FLAG_JSON_OUTPUT, + ...maybeLoginFlag, ]).run() if (result.err) { return result diff --git a/desktop/src/components/Layout/Pro.tsx b/desktop/src/components/Layout/Pro.tsx index 37dc9ad1f..db9d90f49 100644 --- a/desktop/src/components/Layout/Pro.tsx +++ b/desktop/src/components/Layout/Pro.tsx @@ -1,9 +1,9 @@ import { client } from "@/client" import { useProInstances, useSettings, useWorkspaces } from "@/contexts" -import { Briefcase, DevPodProBadge, Plus } from "@/icons" +import { Briefcase, CheckCircle, DevPodProBadge, ExclamationTriangle, Plus } from "@/icons" import { exists } from "@/lib" import { TProID, TProInstance } from "@/types" -import { useLoginProModal } from "@/views/ProInstances/useLoginProModal" +import { useLoginProModal, useReLoginProModal } from "@/views/ProInstances/useLoginProModal" import { useDeleteProviderModal } from "@/views/Providers/useDeleteProviderModal" import { ChevronDownIcon, CloseIcon } from "@chakra-ui/icons" import { @@ -35,6 +35,7 @@ import { IconTag } from "../Tag" export function Pro() { const [[proInstances]] = useProInstances() const { modal: loginProModal, handleOpenLogin: handleConnectClicked } = useLoginProModal() + const { modal: reLoginProModal, handleOpenLogin: handleReLoginClicked } = useReLoginProModal() const [isDeleting, setIsDeleting] = useState(false) const backgroundColor = useColorModeValue("white", "gray.900") @@ -101,17 +102,22 @@ export function Pro() { ) : ( - proInstances.map( - (proInstance) => - proInstance.host && ( - - ) - ) + proInstances.map((proInstance) => { + const host = proInstance.host + if (!host) { + return null + } + + return ( + handleReLoginClicked({ host })} + /> + ) + }) )} @@ -119,6 +125,7 @@ export function Pro() { {loginProModal} + {reLoginProModal} ) : ( + + + + ) + }, [resetModal, isOpen, login.status, terminal]) + + return { modal, handleOpenLogin } +}