Skip to content

Commit b107a6d

Browse files
committed
Address feedback
1 parent 7b727dc commit b107a6d

File tree

5 files changed

+42
-73
lines changed

5 files changed

+42
-73
lines changed

components/dashboard/src/service/service.tsx

Lines changed: 41 additions & 2 deletions
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();
241+
}
242+
234243
this.sendInfoUpdate(this.latestInfo);
235244
};
236245
reconcile();
@@ -252,10 +261,40 @@ export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
252261
workspaceType: this.workspace.spec?.type === WorkspaceSpec_WorkspaceType.PREBUILD ? "prebuild" : "regular",
253262
credentialsToken: this.ideCredentials,
254263
ownerId: this.workspace.metadata?.ownerId ?? "",
255-
contextUrl: this.workspace.metadata?.originalContextUrl ?? "",
256264
};
257265
}
258266

267+
private async redirectToCustomUrl() {
268+
const isDataOps = await getExperimentsClient().getValueAsync("dataops", false, {
269+
user: { id: this.user!.id },
270+
gitpodHost: window.location.host,
271+
});
272+
const dataOpsRedirectUrl = await getExperimentsClient().getValueAsync("dataops_redirect_url", "undefined", {
273+
user: { id: this.user!.id },
274+
gitpodHost: window.location.host,
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+
259298
// implements
260299

261300
private async auth() {

components/gitpod-protocol/src/frontend-dashboard-service.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export namespace IDEFrontendDashboardService {
5151
workspaceDescription: string;
5252
workspaceType: string;
5353
credentialsToken: string;
54-
contextUrl: string;
5554
}
5655

5756
export interface SetStateData {

components/supervisor/frontend/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
"stream-browserify": "^2.0.1",
1313
"url": "^0.11.1",
1414
"util": "^0.11.1",
15-
"uuid": "8.3.2",
16-
"configcat-js": "^6.0.0"
15+
"uuid": "8.3.2"
1716
},
1817
"devDependencies": {
1918
"@types/sharedworker": "^0.0.29",

components/supervisor/frontend/src/experiments/client.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

components/supervisor/frontend/src/index.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,20 @@ require("../src/shared/index.css");
4949

5050
import { WorkspaceInstancePhase } from "@gitpod/gitpod-protocol";
5151
import { DisposableCollection } from "@gitpod/gitpod-protocol/lib/util/disposable";
52-
import { IDEFrontendDashboardService } from "@gitpod/gitpod-protocol/lib/frontend-dashboard-service";
5352
import * as heartBeat from "./ide/heart-beat";
5453
import * as IDEFrontendService from "./ide/ide-frontend-service-impl";
5554
import * as IDEWorker from "./ide/ide-worker";
5655
import * as IDEWebSocket from "./ide/ide-web-socket";
5756
import { SupervisorServiceClient } from "./ide/supervisor-service-client";
5857
import * as LoadingFrame from "./shared/loading-frame";
5958
import { workspaceUrl } from "./shared/urls";
60-
import { getExperimentsClient } from "./experiments/client";
6159

6260
window.gitpod = {} as any;
6361
IDEWorker.install();
6462
IDEWebSocket.install();
6563
const ideService = IDEFrontendService.create();
6664
const loadingIDE = new Promise((resolve) => window.addEventListener("DOMContentLoaded", resolve, { once: true }));
6765
const toStop = new DisposableCollection();
68-
const experimentsClient = getExperimentsClient();
6966

7067
document.body.style.visibility = "hidden";
7168
LoadingFrame.load().then(async (loading) => {
@@ -287,7 +284,6 @@ LoadingFrame.load().then(async (loading) => {
287284
IDEWebSocket.connectWorkspace(),
288285
frontendDashboardServiceClient.onInfoUpdate((status) => {
289286
if (status.statusPhase === "stopping" || status.statusPhase === "stopped") {
290-
maybeRedirectToCustomUrl(frontendDashboardServiceClient.latestInfo);
291287
toStop.dispose();
292288
}
293289
}),
@@ -299,32 +295,3 @@ LoadingFrame.load().then(async (loading) => {
299295
//#endregion
300296
})();
301297
});
302-
303-
async function maybeRedirectToCustomUrl(info: IDEFrontendDashboardService.Info) {
304-
const isDataOps = await experimentsClient.getValueAsync("dataops", false, {
305-
user: { id: info.loggedUserId },
306-
});
307-
const dataOpsRedirectUrl = await experimentsClient.getValueAsync("dataops_redirect_url", "undefined", {
308-
user: { id: info.loggedUserId },
309-
});
310-
311-
if (!isDataOps) {
312-
return;
313-
}
314-
315-
try {
316-
const params: Record<string, string> = { workspaceID: info.workspaceID };
317-
let redirectURL: string;
318-
if (dataOpsRedirectUrl === "undefined") {
319-
redirectURL = info.contextUrl;
320-
} else {
321-
redirectURL = dataOpsRedirectUrl;
322-
params.contextURL = info.contextUrl;
323-
}
324-
const url = new URL(redirectURL);
325-
url.search = new URLSearchParams(params).toString();
326-
window.location.href = url.toString();
327-
} catch {
328-
console.error("Invalid redirect URL");
329-
}
330-
}

0 commit comments

Comments
 (0)