Skip to content

Commit f9720e0

Browse files
committed
Revert "Revert "Redirect on workspace stop" (#19323)"
This reverts commit 827a1a0.
1 parent d2c0ed2 commit f9720e0

File tree

5 files changed

+58
-6
lines changed

5 files changed

+58
-6
lines changed

components/dashboard/src/service/service.tsx

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
221221
this.workspace = workspaceResponse.workspace!;
222222
this.user = user;
223223
this.ideCredentials = ideCredentials;
224-
const reconcile = (status?: WorkspaceStatus) => {
224+
const reconcile = async (status?: WorkspaceStatus) => {
225225
const info = this.parseInfo(status ?? this.workspace.status!);
226226
this.latestInfo = info;
227227
const oldInstanceID = this.instanceID;
@@ -231,6 +231,15 @@ export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
231231
if (info.instanceId && oldInstanceID !== info.instanceId) {
232232
this.auth();
233233
}
234+
235+
// Redirect to custom url
236+
if (
237+
(info.statusPhase === "stopping" || info.statusPhase === "stopped") &&
238+
info.workspaceType === "regular"
239+
) {
240+
await this.redirectToCustomUrl(info);
241+
}
242+
234243
this.sendInfoUpdate(this.latestInfo);
235244
};
236245
reconcile();
@@ -255,6 +264,37 @@ export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
255264
};
256265
}
257266

267+
private async redirectToCustomUrl(info: IDEFrontendDashboardService.Info) {
268+
const isDataOps = await getExperimentsClient().getValueAsync("dataops", false, {
269+
user: { id: this.user!.id },
270+
gitpodHost: gitpodHostUrl.toString(),
271+
});
272+
const dataOpsRedirectUrl = await getExperimentsClient().getValueAsync("dataops_redirect_url", "undefined", {
273+
user: { id: this.user!.id },
274+
gitpodHost: gitpodHostUrl.toString(),
275+
});
276+
277+
if (!isDataOps) {
278+
return;
279+
}
280+
281+
try {
282+
const params: Record<string, string> = { workspaceID: info.workspaceID };
283+
let redirectURL: string;
284+
if (dataOpsRedirectUrl === "undefined") {
285+
redirectURL = this.workspace.metadata?.originalContextUrl ?? "";
286+
} else {
287+
redirectURL = dataOpsRedirectUrl;
288+
params.contextURL = this.workspace.metadata?.originalContextUrl ?? "";
289+
}
290+
const url = new URL(redirectURL);
291+
url.search = new URLSearchParams(params).toString();
292+
this.relocate(url.toString());
293+
} catch {
294+
console.error("Invalid redirect URL");
295+
}
296+
}
297+
258298
// implements
259299

260300
private async auth() {

components/supervisor/frontend/src/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ IDEWebSocket.install();
6363
const ideService = IDEFrontendService.create();
6464
const loadingIDE = new Promise((resolve) => window.addEventListener("DOMContentLoaded", resolve, { once: true }));
6565
const toStop = new DisposableCollection();
66+
let willRedirect = false;
6667

67-
document.body.style.visibility = "hidden";
6868
LoadingFrame.load().then(async (loading) => {
6969
const frontendDashboardServiceClient = loading.frontendDashboardServiceClient;
7070
await frontendDashboardServiceClient.initialize();
@@ -73,6 +73,10 @@ LoadingFrame.load().then(async (loading) => {
7373
return;
7474
}
7575

76+
frontendDashboardServiceClient.onWillRedirect(() => {
77+
willRedirect = true;
78+
});
79+
7680
document.title = frontendDashboardServiceClient.latestInfo.workspaceDescription ?? "gitpod";
7781
window.gitpod.loggedUserID = frontendDashboardServiceClient.latestInfo.loggedUserId;
7882
window.gitpod.openDesktopIDE = frontendDashboardServiceClient.openDesktopIDE.bind(frontendDashboardServiceClient);
@@ -159,11 +163,11 @@ LoadingFrame.load().then(async (loading) => {
159163
};
160164
const updateCurrentFrame = () => {
161165
const newCurrent = nextFrame();
162-
if (current === newCurrent) {
166+
if (current === newCurrent || willRedirect) {
163167
return;
164168
}
165-
current.style.visibility = "hidden";
166-
newCurrent.style.visibility = "visible";
169+
current.classList.toggle("hidden", true);
170+
newCurrent.classList.toggle("hidden", false);
167171
if (current === document.body) {
168172
while (document.body.firstChild && document.body.firstChild !== newCurrent) {
169173
document.body.removeChild(document.body.firstChild);

components/supervisor/frontend/src/shared/frontend-dashboard-service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export class FrontendDashboardServiceClient implements IDEFrontendDashboardServi
2121
private readonly onOpenBrowserIDEEmitter = new Emitter<void>();
2222
readonly onOpenBrowserIDE = this.onOpenBrowserIDEEmitter.event;
2323

24+
private readonly onWillRedirectEmitter = new Emitter<void>();
25+
readonly onWillRedirect = this.onWillRedirectEmitter.event;
26+
2427
private resolveInit!: () => void;
2528
private initPromise = new Promise<void>((resolve) => (this.resolveInit = resolve));
2629

@@ -50,6 +53,7 @@ export class FrontendDashboardServiceClient implements IDEFrontendDashboardServi
5053
this.onDidChangeEmitter.fire(this.latestInfo);
5154
}
5255
if (IDEFrontendDashboardService.isRelocateEventData(event.data)) {
56+
this.onWillRedirectEmitter.fire();
5357
window.location.href = event.data.url;
5458
}
5559
if (IDEFrontendDashboardService.isOpenBrowserIDE(event.data)) {

components/supervisor/frontend/src/shared/index.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@
1515
border: 0px;
1616
overflow: hidden;
1717
}
18+
19+
.gitpod-frame.hidden {
20+
width: 0px;
21+
height: 0px;
22+
}

components/supervisor/frontend/src/shared/loading-frame.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ export function load(): Promise<{
1414
return new Promise((resolve) => {
1515
const frame = document.createElement("iframe");
1616
frame.src = startUrl.toString();
17-
frame.style.visibility = "visible";
1817
frame.className = "gitpod-frame loading";
1918
document.body.prepend(frame);
2019

0 commit comments

Comments
 (0)