From adc99636c58d3737e60b09496f8da0b89ab5b747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Tron=C3=AD=C4=8Dek?= Date: Thu, 19 Dec 2024 08:55:47 +0000 Subject: [PATCH 1/3] [dashboard] Fix Arc favourites --- .../components/podkit/buttons/LinkButton.tsx | 13 ++++--- .../dashboard/src/start/StartWorkspace.tsx | 37 ++++++++++++++++++- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/components/dashboard/src/components/podkit/buttons/LinkButton.tsx b/components/dashboard/src/components/podkit/buttons/LinkButton.tsx index 3e8cf39bd27805..2083f59b3714ab 100644 --- a/components/dashboard/src/components/podkit/buttons/LinkButton.tsx +++ b/components/dashboard/src/components/podkit/buttons/LinkButton.tsx @@ -6,27 +6,30 @@ import { Link } from "react-router-dom"; import { Button, ButtonProps } from "@podkit/buttons/Button"; -import React from "react"; +import { forwardRef, HTMLAttributeAnchorTarget } from "react"; export interface LinkButtonProps extends ButtonProps { asChild?: false; href: string; + target?: HTMLAttributeAnchorTarget; isExternalUrl?: boolean; } /** * A HTML anchor element styled as a button. */ -export const LinkButton = React.forwardRef( - ({ asChild, children, href, ...props }, ref) => { +export const LinkButton = forwardRef( + ({ asChild, children, href, target, ...props }, ref) => { return ( ); diff --git a/components/dashboard/src/start/StartWorkspace.tsx b/components/dashboard/src/start/StartWorkspace.tsx index bb0263710cac51..3ccda75b938c0e 100644 --- a/components/dashboard/src/start/StartWorkspace.tsx +++ b/components/dashboard/src/start/StartWorkspace.tsx @@ -36,6 +36,7 @@ import { import { PartialMessage } from "@bufbuild/protobuf"; import { trackEvent } from "../Analytics"; import { fromWorkspaceName } from "../workspaces/RenameWorkspaceModal"; +import { LinkButton } from "@podkit/buttons/LinkButton"; const sessionId = v4(); @@ -102,6 +103,10 @@ export interface StartWorkspaceState { ideOptions?: IDEOptions; isSSHModalVisible?: boolean; ownerToken?: string; + /** + * Set to prevent multiple redirects to the same URL when the User Agent ignores our wish to open links in the same tab (by setting window.location.href). + */ + redirected?: boolean; } // TODO: use Function Components @@ -458,11 +463,17 @@ export default class StartWorkspace extends React.Component; // Pending means the workspace does not yet consume resources in the cluster, but rather is looking for - // some space within the cluster. If for example the cluster needs to scale up to accomodate the + // some space within the cluster. If for example the cluster needs to scale up to accommodate the // workspace, the workspace will be in Pending state until that happened. case WorkspacePhase_Phase.PENDING: phase = StartPhase.Preparing; @@ -755,6 +766,30 @@ export default class StartWorkspace extends React.Component {statusMessage} + {this.state.redirected && ( + <> + + We redirected you to your workspace, but your browser probably opened it in another tab. + + +
+ + Go to Dashboard + + {this.state.workspace?.status?.workspaceUrl && + this.state.workspace.status.phase?.name === WorkspacePhase_Phase.RUNNING && ( + + Re-open Workspace + + )} +
+ + )} ); } From 9826ca51eee006b0316b2ab377e1bf7903b7ed4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20Tron=C3=AD=C4=8Dek?= Date: Thu, 19 Dec 2024 09:15:09 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=92=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/dashboard/src/start/StartWorkspace.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/dashboard/src/start/StartWorkspace.tsx b/components/dashboard/src/start/StartWorkspace.tsx index 3ccda75b938c0e..8c570068058504 100644 --- a/components/dashboard/src/start/StartWorkspace.tsx +++ b/components/dashboard/src/start/StartWorkspace.tsx @@ -188,7 +188,7 @@ export default class StartWorkspace extends React.Component Date: Thu, 19 Dec 2024 11:45:02 +0000 Subject: [PATCH 3/3] Fix banner <> redirect race --- components/dashboard/src/start/StartWorkspace.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/components/dashboard/src/start/StartWorkspace.tsx b/components/dashboard/src/start/StartWorkspace.tsx index 8c570068058504..e49bc754073cd5 100644 --- a/components/dashboard/src/start/StartWorkspace.tsx +++ b/components/dashboard/src/start/StartWorkspace.tsx @@ -107,6 +107,10 @@ export interface StartWorkspaceState { * Set to prevent multiple redirects to the same URL when the User Agent ignores our wish to open links in the same tab (by setting window.location.href). */ redirected?: boolean; + /** + * Determines whether `redirected` has been `true` for long enough to display our "new tab" info banner without racing with same-tab redirection in regular setups + */ + showRedirectMessage?: boolean; } // TODO: use Function Components @@ -474,6 +478,9 @@ export default class StartWorkspace extends React.Component { + this.setState({ showRedirectMessage: true }); + }, 2000); } private openDesktopLink(link: string) { @@ -767,7 +774,7 @@ export default class StartWorkspace extends React.Component {statusMessage} - {this.state.redirected && ( + {this.state.showRedirectMessage && ( <> We redirected you to your workspace, but your browser probably opened it in another tab.