Skip to content
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

Redirect web page when instance changed #9004

Merged
merged 1 commit into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 6 additions & 43 deletions components/dashboard/src/start/StartWorkspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,11 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps,

// Redirect to workspaceURL if we are not yet running in an iframe.
// It happens this late if we were waiting for a docker build.
if (!this.props.runsInIFrame && workspaceInstance.ideUrl && !this.props.dontAutostart) {
if (
!this.props.runsInIFrame &&
workspaceInstance.ideUrl &&
(!this.props.dontAutostart || workspaceInstance.status.phase === "running")
geropl marked this conversation as resolved.
Show resolved Hide resolved
) {
this.redirectTo(workspaceInstance.ideUrl);
return;
}
Expand Down Expand Up @@ -431,48 +435,7 @@ export default class StartWorkspace extends React.Component<StartWorkspaceProps,
}
if (!this.state.desktopIde) {
phase = StartPhase.Running;

geropl marked this conversation as resolved.
Show resolved Hide resolved
if (this.props.dontAutostart) {
// hide the progress bar, as we're already running
phase = undefined;
title = "Running";

// in case we dontAutostart the IDE we have to provide controls to do so
statusMessage = (
<div>
<div className="flex space-x-3 items-center text-left rounded-xl m-auto px-4 h-16 w-72 mt-4 mb-2 bg-gray-100 dark:bg-gray-800">
<div className="rounded-full w-3 h-3 text-sm bg-green-500">&nbsp;</div>
<div>
<p className="text-gray-700 dark:text-gray-200 font-semibold w-56 truncate">
{this.state.workspaceInstance.workspaceId}
</p>
<a target="_parent" href={contextURL}>
<p className="w-56 truncate hover:text-blue-600 dark:hover:text-blue-400">
{contextURL}
</p>
</a>
</div>
</div>
<div className="mt-10 justify-center flex space-x-2">
<a target="_parent" href={gitpodHostUrl.asDashboard().toString()}>
<button className="secondary">Go to Dashboard</button>
</a>
<a
target="_parent"
href={
gitpodHostUrl
.asStart(this.props.workspaceId)
.toString() /** move over 'start' here to fetch fresh credentials in case this is an older tab */
}
>
<button>Open Workspace</button>
</a>
</div>
</div>
);
} else {
statusMessage = <p className="text-base text-gray-400">Opening Workspace …</p>;
}
statusMessage = <p className="text-base text-gray-400">Opening Workspace …</p>;
} else {
phase = StartPhase.IdeReady;
const openLink = this.state.desktopIde.link;
Expand Down
10 changes: 10 additions & 0 deletions components/supervisor/frontend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,19 @@ const toStop = new DisposableCollection();
//#region current-frame
let current: HTMLElement = loading.frame;
let desktopRedirected = false;
let currentInstanceId = "";
const nextFrame = () => {
const instance = gitpodServiceClient.info.latestInstance;
if (instance) {
// refresh web page when instanceId changed
if (currentInstanceId !== "") {
if (instance.id !== currentInstanceId && instance.ideUrl !== "") {
currentInstanceId = instance.id;
window.location.href = instance.ideUrl;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

}
} else {
currentInstanceId = instance.id;
}
if (instance.status.phase === 'running') {
if (!hideDesktopIde) {
if (isDesktopIde == undefined) {
Expand Down