Skip to content

Commit e6bf79e

Browse files
authored
Revert "Revert "Redirect on workspace stop" (#19323)" (#19325)
* Revert "Revert "Redirect on workspace stop" (#19323)" This reverts commit 827a1a0. * Fix * Fix * 💄
1 parent 668c0a1 commit e6bf79e

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

components/dashboard/src/service/service.tsx

Lines changed: 44 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,40 @@ 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([
292+
...Array.from(url.searchParams.entries()),
293+
...Object.entries(params),
294+
]).toString();
295+
this.relocate(url.toString());
296+
} catch {
297+
console.error("Invalid redirect URL");
298+
}
299+
}
300+
258301
// implements
259302

260303
private async auth() {

components/supervisor/frontend/src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ 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

6768
document.body.style.visibility = "hidden";
6869
LoadingFrame.load().then(async (loading) => {
@@ -73,6 +74,10 @@ LoadingFrame.load().then(async (loading) => {
7374
return;
7475
}
7576

77+
frontendDashboardServiceClient.onWillRedirect(() => {
78+
willRedirect = true;
79+
});
80+
7681
document.title = frontendDashboardServiceClient.latestInfo.workspaceDescription ?? "gitpod";
7782
window.gitpod.loggedUserID = frontendDashboardServiceClient.latestInfo.loggedUserId;
7883
window.gitpod.openDesktopIDE = frontendDashboardServiceClient.openDesktopIDE.bind(frontendDashboardServiceClient);
@@ -159,7 +164,7 @@ LoadingFrame.load().then(async (loading) => {
159164
};
160165
const updateCurrentFrame = () => {
161166
const newCurrent = nextFrame();
162-
if (current === newCurrent) {
167+
if (current === newCurrent || willRedirect) {
163168
return;
164169
}
165170
current.style.visibility = "hidden";

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)) {

0 commit comments

Comments
 (0)