Skip to content

Commit 633f991

Browse files
authored
Migrate instanceUpdate on service.tsx (#19213)
* Migrate instanceUpdate on service.tsx * Remove useless code * Fix build
1 parent 46ff2d0 commit 633f991

26 files changed

+118
-56
lines changed

components/dashboard/src/service/service.tsx

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@ import {
1111
GitpodServerPath,
1212
GitpodService,
1313
GitpodServiceImpl,
14-
WorkspaceInfo,
1514
Disposable,
1615
} from "@gitpod/gitpod-protocol";
1716
import { WebSocketConnectionProvider } from "@gitpod/gitpod-protocol/lib/messaging/browser/connection";
1817
import { GitpodHostUrl } from "@gitpod/gitpod-protocol/lib/util/gitpod-host-url";
1918
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
2019
import { IDEFrontendDashboardService } from "@gitpod/gitpod-protocol/lib/frontend-dashboard-service";
2120
import { RemoteTrackMessage } from "@gitpod/gitpod-protocol/lib/analytics";
22-
import { helloService, stream, userClient, workspaceClient } from "./public-api";
21+
import { converter, helloService, stream, userClient, workspaceClient } from "./public-api";
2322
import { getExperimentsClient } from "../experiments/client";
2423
import { instrumentWebSocket } from "./metrics";
2524
import { LotsOfRepliesResponse } from "@gitpod/public-api/lib/gitpod/experimental/v1/dummy_pb";
2625
import { User } from "@gitpod/public-api/lib/gitpod/v1/user_pb";
26+
import { watchWorkspaceStatus } from "../data/workspaces/listen-to-workspace-ws-messages";
27+
import { Workspace, WorkspaceSpec_WorkspaceType, WorkspaceStatus } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
2728

2829
export const gitpodHostUrl = new GitpodHostUrl(window.location.toString());
2930

@@ -164,8 +165,9 @@ export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
164165
private ownerId: string | undefined;
165166
private user: User | undefined;
166167
private ideCredentials!: string;
168+
private workspace!: Workspace;
167169

168-
private latestInfo?: IDEFrontendDashboardService.Status;
170+
private latestInfo?: IDEFrontendDashboardService.Info;
169171

170172
private readonly onDidChangeEmitter = new Emitter<IDEFrontendDashboardService.SetStateData>();
171173
readonly onSetState = this.onDidChangeEmitter.event;
@@ -208,17 +210,18 @@ export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
208210
}
209211

210212
private async processServerInfo() {
211-
const [user, listener, ideCredentials] = await Promise.all([
213+
const [user, workspaceResponse, ideCredentials] = await Promise.all([
212214
userClient.getAuthenticatedUser({}).then((r) => r.user),
213-
this.service.listenToInstance(this.workspaceID),
215+
workspaceClient.getWorkspace({ workspaceId: this.workspaceID }),
214216
workspaceClient
215217
.getWorkspaceEditorCredentials({ workspaceId: this.workspaceID })
216218
.then((resp) => resp.editorCredentials),
217219
]);
220+
this.workspace = workspaceResponse.workspace!;
218221
this.user = user;
219222
this.ideCredentials = ideCredentials;
220-
const reconcile = () => {
221-
const info = this.parseInfo(listener.info);
223+
const reconcile = (status?: WorkspaceStatus) => {
224+
const info = this.parseInfo(status ?? this.workspace.status!);
222225
this.latestInfo = info;
223226
const oldInstanceID = this.instanceID;
224227
this.instanceID = info.instanceId;
@@ -227,27 +230,27 @@ export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
227230
if (info.instanceId && oldInstanceID !== info.instanceId) {
228231
this.auth();
229232
}
230-
231-
// TODO(hw): to be removed after IDE deployed
232-
this.sendStatusUpdate(this.latestInfo);
233-
// TODO(hw): end of todo
234233
this.sendInfoUpdate(this.latestInfo);
235234
};
236235
reconcile();
237-
listener.onDidChange(reconcile);
236+
watchWorkspaceStatus(this.workspaceID, (response) => {
237+
if (response.status) {
238+
reconcile(response.status);
239+
}
240+
});
238241
}
239242

240-
private parseInfo(workspace: WorkspaceInfo): IDEFrontendDashboardService.Info {
243+
private parseInfo(status: WorkspaceStatus): IDEFrontendDashboardService.Info {
241244
return {
242245
loggedUserId: this.user!.id,
243246
workspaceID: this.workspaceID,
244-
instanceId: workspace.latestInstance?.id,
245-
ideUrl: workspace.latestInstance?.ideUrl,
246-
statusPhase: workspace.latestInstance?.status.phase,
247-
workspaceDescription: workspace.workspace.description,
248-
workspaceType: workspace.workspace.type,
247+
instanceId: status.instanceId,
248+
ideUrl: status.workspaceUrl,
249+
statusPhase: status.phase?.name ? converter.fromPhase(status.phase?.name) : "unknown",
250+
workspaceDescription: this.workspace.metadata?.name ?? "",
251+
workspaceType: this.workspace.spec?.type === WorkspaceSpec_WorkspaceType.PREBUILD ? "prebuild" : "regular",
249252
credentialsToken: this.ideCredentials,
250-
ownerId: workspace.workspace.ownerId,
253+
ownerId: this.workspace.metadata?.ownerId ?? "",
251254
};
252255
}
253256

@@ -271,6 +274,7 @@ export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
271274
workspaceId: this.workspaceID,
272275
type: this.latestInfo?.workspaceType,
273276
};
277+
// TODO:
274278
this.service.server.trackEvent(msg);
275279
}
276280

@@ -300,19 +304,6 @@ export class IDEFrontendService implements IDEFrontendDashboardService.IServer {
300304
}
301305
}
302306

303-
// TODO(hw): to be removed after IDE deployed
304-
sendStatusUpdate(status: IDEFrontendDashboardService.Status): void {
305-
this.clientWindow.postMessage(
306-
{
307-
version: 1,
308-
type: "ide-status-update",
309-
status,
310-
} as IDEFrontendDashboardService.StatusUpdateEventData,
311-
"*",
312-
);
313-
}
314-
// TODO(hw): end of todo
315-
316307
sendInfoUpdate(info: IDEFrontendDashboardService.Info): void {
317308
this.clientWindow.postMessage(
318309
{

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

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,8 @@ export namespace IDEFrontendDashboardService {
3131
* IServer is the server side which is using in dashboard loading screen
3232
*/
3333
export interface IServer {
34-
// TODO(hw): to be removed after IDE deployed
35-
sendStatusUpdate(status: Status): void;
36-
// TODO(hw): end of todo
37-
sendInfoUpdate(info: Info): void;
3834
relocate(url: string): void;
35+
sendInfoUpdate(info: Info): void;
3936
openBrowserIDE(): void;
4037
}
4138

@@ -56,10 +53,6 @@ export namespace IDEFrontendDashboardService {
5653
credentialsToken: string;
5754
}
5855

59-
// TODO(hw): to be removed after IDE deployed
60-
export type Status = Info;
61-
// TODO(hw): end of todo
62-
6356
export interface SetStateData {
6457
ideFrontendFailureCause?: string;
6558
desktopIDE?: {
@@ -69,15 +62,6 @@ export namespace IDEFrontendDashboardService {
6962
};
7063
}
7164

72-
// TODO(hw): to be removed after IDE deployed
73-
export interface StatusUpdateEventData {
74-
// protocol version
75-
version?: number;
76-
type: "ide-status-update";
77-
status: Status;
78-
}
79-
// TODO(hw): end of todo
80-
8165
export interface InfoUpdateEventData {
8266
// protocol version
8367
version?: number;
@@ -113,12 +97,6 @@ export namespace IDEFrontendDashboardService {
11397
url: string;
11498
}
11599

116-
// TODO(hw): to be removed after IDE deployed
117-
export function isStatusUpdateEventData(obj: any): obj is StatusUpdateEventData {
118-
return obj != null && typeof obj === "object" && obj.type === "ide-status-update";
119-
}
120-
// TODO(hw): end of todo
121-
122100
export function isInfoUpdateEventData(obj: any): obj is InfoUpdateEventData {
123101
return obj != null && typeof obj === "object" && obj.type === "ide-info-update";
124102
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"result": "UNSPECIFIED",
3+
"err": ""
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"unknown"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"result": "STOPPED",
3+
"err": ""
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"stopped"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"result": "UNSPECIFIED",
3+
"err": ""
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"ANY_VALUE"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"result": "UNSPECIFIED",
3+
"err": ""
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"pause"

0 commit comments

Comments
 (0)