From aa0d14be37226d1faf945caafe2d1a912d1eb5b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Cie=C5=9Blak?= Date: Thu, 28 Sep 2023 17:35:28 +0200 Subject: [PATCH] [v14] Make spacing of Connect My Computer status more consistent (#32736) * Make spacing of Connect My Computer status more consistent * Add server labels to Running story, add ErrorWithAlertAndLogs story * Change copy depending on whether the agent is running * Fix proxyVersion in story Co-authored-by: Grzegorz Zdunek --------- Co-authored-by: Grzegorz Zdunek --- .../CompatibilityPromise.tsx | 10 +- .../DocumentConnectMyComputerStatus.story.tsx | 109 +++++--- .../DocumentConnectMyComputerStatus.tsx | 237 ++++++++++-------- .../src/ui/ConnectMyComputer/Logs.tsx | 6 +- 4 files changed, 206 insertions(+), 156 deletions(-) diff --git a/web/packages/teleterm/src/ui/ConnectMyComputer/CompatibilityPromise.tsx b/web/packages/teleterm/src/ui/ConnectMyComputer/CompatibilityPromise.tsx index 58f6dc52a3cdb..76ab0b49428b5 100644 --- a/web/packages/teleterm/src/ui/ConnectMyComputer/CompatibilityPromise.tsx +++ b/web/packages/teleterm/src/ui/ConnectMyComputer/CompatibilityPromise.tsx @@ -15,8 +15,7 @@ */ import React from 'react'; -import { Text, ButtonPrimary, Alert } from 'design'; - +import { Text, ButtonPrimary, Alert, Flex } from 'design'; import Link from 'design/Link'; import { useAppContext } from 'teleterm/ui/appContextProvider'; @@ -92,9 +91,9 @@ export function CompatibilityError(props: { } return ( - <> + {!props.hideAlert && ( - + The agent version is not compatible with the cluster version )} @@ -110,7 +109,6 @@ export function CompatibilityError(props: { {$content} Visit the downloads page - + ); } diff --git a/web/packages/teleterm/src/ui/ConnectMyComputer/DocumentConnectMyComputerStatus/DocumentConnectMyComputerStatus.story.tsx b/web/packages/teleterm/src/ui/ConnectMyComputer/DocumentConnectMyComputerStatus/DocumentConnectMyComputerStatus.story.tsx index f7969ce189351..1bdc42c6e3c93 100644 --- a/web/packages/teleterm/src/ui/ConnectMyComputer/DocumentConnectMyComputerStatus/DocumentConnectMyComputerStatus.story.tsx +++ b/web/packages/teleterm/src/ui/ConnectMyComputer/DocumentConnectMyComputerStatus/DocumentConnectMyComputerStatus.story.tsx @@ -14,11 +14,13 @@ * limitations under the License. */ -import React from 'react'; +import React, { useLayoutEffect } from 'react'; -import { wait } from 'shared/utils/wait'; - -import { makeRootCluster } from 'teleterm/services/tshd/testHelpers'; +import { + makeRootCluster, + makeServer, + makeLabelsList, +} from 'teleterm/services/tshd/testHelpers'; import { MockAppContextProvider } from 'teleterm/ui/fixtures/MockAppContextProvider'; import AppContext from 'teleterm/ui/appContext'; @@ -30,6 +32,7 @@ import { makeRuntimeSettings } from 'teleterm/mainProcess/fixtures/mocks'; import { AgentCompatibilityError, ConnectMyComputerContextProvider, + NodeWaitJoinTimeout, } from '../connectMyComputerContext'; import { DocumentConnectMyComputerStatus } from './DocumentConnectMyComputerStatus'; @@ -43,7 +46,45 @@ export function NotStarted() { } export function Running() { - return ; + const appContext = new MockAppContext({ appVersion: '17.0.0' }); + + let agentUpdateListener: (state: AgentProcessState) => void; + appContext.mainProcessClient.subscribeToAgentUpdate = ( + rootClusterUri, + listener + ) => { + agentUpdateListener = listener; + return { cleanup: () => undefined }; + }; + appContext.connectMyComputerService.isAgentConfigFileCreated = () => + Promise.resolve(true); + appContext.connectMyComputerService.runAgent = async () => { + agentUpdateListener({ status: 'running' }); + }; + appContext.connectMyComputerService.waitForNodeToJoin = () => + Promise.resolve( + makeServer({ + hostname: 'staging-mac-mini', + labelsList: makeLabelsList({ + hostname: 'staging-mac-mini', + 'teleport.dev/connect-my-computer/owner': 'testuser@goteleport.com', + }), + }) + ); + + useLayoutEffect(() => { + ( + document.querySelector('[data-testid=start-agent]') as HTMLButtonElement + )?.click(); + }); + + return ( + + ); } export function Errored() { @@ -84,6 +125,30 @@ export function ExitedUnsuccessfully() { ); } +export function ErrorWithAlertAndLogs() { + const appContext = new MockAppContext({ appVersion: '17.0.0' }); + + appContext.connectMyComputerService.isAgentConfigFileCreated = () => + Promise.resolve(true); + appContext.connectMyComputerService.waitForNodeToJoin = () => + Promise.reject( + new NodeWaitJoinTimeout( + 'teleport: error: unknown short flag -non-existing-flag' + ) + ); + + return ( + + ); +} + export function FailedToReadAgentConfigFile() { const appContext = new MockAppContext(); appContext.connectMyComputerService.isAgentConfigFileCreated = async () => { @@ -182,40 +247,6 @@ function ShowState(props: { new MockAppContext({ appVersion: cluster.proxyVersion }); appContext.mainProcessClient.getAgentState = () => props.agentProcessState; - appContext.mainProcessClient.subscribeToAgentUpdate = ( - rootClusterUri, - listener - ) => { - listener(props.agentProcessState); - return { cleanup: () => undefined }; - }; - appContext.connectMyComputerService.runAgent = async () => { - await wait(1_000); - }; - appContext.connectMyComputerService.waitForNodeToJoin = async () => { - if (props.agentProcessState.status === 'running') { - await wait(2_000); - return { - uri: `${cluster.uri}/servers/178ef081-259b-4aa5-a018-449b5ea7e694`, - tunnel: false, - name: '178ef081-259b-4aa5-a018-449b5ea7e694', - hostname: 'staging-mac-mini', - addr: '127.0.0.1:3022', - labelsList: [ - { - name: 'hostname', - value: 'staging-mac-mini', - }, - { - name: 'teleport.dev/connect-my-computer', - value: 'testuser@goteleport.com', - }, - ], - }; - } - await wait(3_000); - throw new Error('TIMEOUT. Cannot find node.'); - }; appContext.configService.set('feature.connectMyComputer', true); appContext.clustersService.state.clusters.set(cluster.uri, cluster); appContext.workspacesService.setState(draftState => { diff --git a/web/packages/teleterm/src/ui/ConnectMyComputer/DocumentConnectMyComputerStatus/DocumentConnectMyComputerStatus.tsx b/web/packages/teleterm/src/ui/ConnectMyComputer/DocumentConnectMyComputerStatus/DocumentConnectMyComputerStatus.tsx index 7a973f22eea8a..f36ed115685bc 100644 --- a/web/packages/teleterm/src/ui/ConnectMyComputer/DocumentConnectMyComputerStatus/DocumentConnectMyComputerStatus.tsx +++ b/web/packages/teleterm/src/ui/ConnectMyComputer/DocumentConnectMyComputerStatus/DocumentConnectMyComputerStatus.tsx @@ -175,119 +175,140 @@ export function DocumentConnectMyComputerStatus( again. )} - - - - {/** The node name can be changed, so it might be different from the system hostname. */} - {agentNode?.hostname || hostname} - - props.theme.space[1]}px; - background: ${props => props.theme.colors.spotBackground[0]}; - `, - }} - menuProps={{ - anchorOrigin: { - vertical: 'bottom', - horizontal: 'right', - }, - transformOrigin: { - vertical: 'top', - horizontal: 'right', - }, - }} - > - Open agent logs directory - Remove agent - - - - {state => ( - - {renderLabels(agentNode.labelsList)} - - )} - - - {prettyCurrentAction.Icon && } - {prettyCurrentAction.title} - {showConnectAndStopAgentButtons && ( - + + + + + {/** The node name can be changed, so it might be different from the system hostname. */} + {agentNode?.hostname || hostname} + + props.theme.space[1]}px; + background: ${props => props.theme.colors.spotBackground[0]}; + `, + }} + menuProps={{ + anchorOrigin: { + vertical: 'bottom', + horizontal: 'right', + }, + transformOrigin: { + vertical: 'top', + horizontal: 'right', + }, + }} + > + + Open agent logs directory + + Remove agent + + + + - Stop Agent - - )} - - {prettyCurrentAction.error && ( - - {prettyCurrentAction.error} - - )} - {prettyCurrentAction.logs && } - - {isAgentIncompatible ? ( - - ) : ( - <> - - Connecting your computer will allow any cluster user with the role{' '} - {roleName} to access it as an SSH resource with the - user {systemUsername}. - - {showConnectAndStopAgentButtons ? ( - ( + + {renderLabels(agentNode.labelsList)} + + )} + + + + + + {prettyCurrentAction.Icon && ( + + )} + {prettyCurrentAction.title} + {showConnectAndStopAgentButtons && ( + + Stop Agent + + )} + + {prettyCurrentAction.error && ( + - Connect - + {prettyCurrentAction.error} + + )} + {prettyCurrentAction.logs && } + + + + {isAgentIncompatible ? ( + ) : ( - - Start Agent - + <> + {isRunning ? ( + + Any cluster user with the role {roleName} can + now access your computer as {systemUsername}. + + ) : ( + + Connecting your computer will allow any cluster user with the + role {roleName} to access it as an SSH + resource with the user {systemUsername}. + + )} + {showConnectAndStopAgentButtons ? ( + + Connect + + ) : ( + + Start Agent + + )} + )} - - )} + + ); } diff --git a/web/packages/teleterm/src/ui/ConnectMyComputer/Logs.tsx b/web/packages/teleterm/src/ui/ConnectMyComputer/Logs.tsx index 426f7d7603181..613990a5ff95b 100644 --- a/web/packages/teleterm/src/ui/ConnectMyComputer/Logs.tsx +++ b/web/packages/teleterm/src/ui/ConnectMyComputer/Logs.tsx @@ -23,8 +23,8 @@ interface LogsProps { export function Logs(props: LogsProps): JSX.Element { return ( - <> - Last 10 lines of logs: + + Last 10 lines of logs: - + ); }