-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[dashboard] Fix Arc favourites #20466
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,14 @@ 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; | ||
/** | ||
* 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 | ||
|
@@ -183,7 +192,7 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps, | |
this.toDispose.dispose(); | ||
} | ||
|
||
componentDidUpdate(prevPros: StartWorkspaceProps, prevState: StartWorkspaceState) { | ||
componentDidUpdate(_prevProps: StartWorkspaceProps, prevState: StartWorkspaceState) { | ||
const newPhase = this.state?.workspace?.status?.phase?.name; | ||
const oldPhase = prevState.workspace?.status?.phase?.name; | ||
const type = this.state.workspace?.spec?.type === WorkspaceSpec_WorkspaceType.PREBUILD ? "prebuild" : "regular"; | ||
|
@@ -458,11 +467,20 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps, | |
} | ||
|
||
redirectTo(url: string) { | ||
if (this.state.redirected) { | ||
console.info("Prevented another redirect", { url }); | ||
return; | ||
} | ||
if (this.props.runsInIFrame) { | ||
this.ideFrontendService?.relocate(url); | ||
} else { | ||
window.location.href = url; | ||
} | ||
|
||
this.setState({ redirected: true }); | ||
setTimeout(() => { | ||
this.setState({ showRedirectMessage: true }); | ||
}, 2000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2s might be a tad too short, but let's see. Worked for me right now. 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wanted to find a threshold which was not too short to prevent races, but also not too long to actually show up in time to be useful to the user. Will leave as is for now |
||
} | ||
|
||
private openDesktopLink(link: string) { | ||
|
@@ -503,7 +521,7 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps, | |
return <ImageBuildView workspaceId={this.state.workspace.id} />; | ||
|
||
// 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; | ||
|
@@ -746,6 +764,7 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps, | |
); | ||
break; | ||
} | ||
|
||
return ( | ||
<StartPage | ||
phase={phase} | ||
|
@@ -755,6 +774,30 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps, | |
workspaceId={this.props.workspaceId} | ||
> | ||
{statusMessage} | ||
{this.state.showRedirectMessage && ( | ||
<> | ||
<Alert type="info" className="mt-4 w-112"> | ||
geropl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
We redirected you to your workspace, but your browser probably opened it in another tab. | ||
</Alert> | ||
|
||
<div className="mt-4 justify-center flex space-x-2"> | ||
<LinkButton href={gitpodHostUrl.asWorkspacePage().toString()} target="_self" isExternalUrl> | ||
Go to Dashboard | ||
</LinkButton> | ||
{this.state.workspace?.status?.workspaceUrl && | ||
this.state.workspace.status.phase?.name === WorkspacePhase_Phase.RUNNING && ( | ||
<LinkButton | ||
variant={"secondary"} | ||
href={this.state.workspace.status.workspaceUrl} | ||
target="_self" | ||
isExternalUrl | ||
> | ||
Re-open Workspace | ||
</LinkButton> | ||
)} | ||
</div> | ||
</> | ||
)} | ||
</StartPage> | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
🫧 What are situations where we need to reset this value? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question: I'd say it's enough when React resets it when the page unmounts. On the page level, this prop should be permanent (or at least I don't see reasons why we'd forget about having redirected you somewhere).