Skip to content

Commit 2a5705f

Browse files
committed
[dashboard] fix deletion of workspaces
1 parent 78e2bf5 commit 2a5705f

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

components/dashboard/src/workspaces/WorkspaceEntry.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,14 @@ export function WorkspaceEntry({ desc, model }: { desc: WorkspaceInfo, model: Wo
5353
{
5454
title: 'Open',
5555
href: startUrl.toString()
56-
},
57-
{
56+
}];
57+
if (state === 'running') {
58+
menuEntries.push({
5859
title: 'Stop',
5960
onClick: () => getGitpodService().server.stopWorkspace(ws.id)
60-
},
61+
});
62+
}
63+
menuEntries.push(
6164
{
6265
title: 'Download',
6366
href: downloadURL
@@ -84,7 +87,7 @@ export function WorkspaceEntry({ desc, model }: { desc: WorkspaceInfo, model: Wo
8487
setModalVisible(true);
8588
}
8689
}
87-
];
90+
);
8891
const project = getProject(ws);
8992
const showChanges = (event: MouseEvent) => {
9093
event.preventDefault();
@@ -139,7 +142,7 @@ export function WorkspaceEntry({ desc, model }: { desc: WorkspaceInfo, model: Wo
139142
<div className="flex">
140143
<div className="flex-1"></div>
141144
<button className="cursor-pointer px-3 py-2 text-white text-sm rounded-md border-2 border-red-800 bg-red-600 hover:bg-red-800"
142-
onClick={() => getGitpodService().server.deleteWorkspace(ws.id)}>
145+
onClick={() => model.deleteWorkspace(ws.id)}>
143146
Delete
144147
</button>
145148
</div>

components/dashboard/src/workspaces/workspace-model.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Disposable, DisposableCollection, GitpodClient, WorkspaceInfo, Workspac
22
import { getGitpodService } from "../service/service";
33

44
export class WorkspaceModel implements Disposable, Partial<GitpodClient> {
5-
5+
66
protected workspaces = new Map<string,WorkspaceInfo>();
77
protected currentlyFetching = new Set<string>();
88
protected disposables = new DisposableCollection();
@@ -15,7 +15,7 @@ export class WorkspaceModel implements Disposable, Partial<GitpodClient> {
1515
constructor(protected setWorkspaces: (ws: WorkspaceInfo[]) => void) {
1616
this.internalRefetch();
1717
}
18-
18+
1919
protected internalRefetch() {
2020
this.disposables.dispose();
2121
this.disposables = new DisposableCollection();
@@ -27,17 +27,17 @@ export class WorkspaceModel implements Disposable, Partial<GitpodClient> {
2727
});
2828
this.disposables.push(getGitpodService().registerClient(this));
2929
}
30-
30+
3131
protected updateMap(workspaces: WorkspaceInfo[]) {
3232
for (const ws of workspaces) {
3333
this.workspaces.set(ws.workspace.id, ws);
3434
}
3535
}
36-
36+
3737
dispose(): void {
3838
this.disposables.dispose();
3939
}
40-
40+
4141
async onInstanceUpdate(instance: WorkspaceInstance) {
4242
if (this.workspaces) {
4343
if (this.workspaces.has(instance.workspaceId)) {
@@ -58,7 +58,13 @@ export class WorkspaceModel implements Disposable, Partial<GitpodClient> {
5858
}
5959
}
6060
}
61-
61+
62+
async deleteWorkspace(id: string): Promise<void> {
63+
await getGitpodService().server.deleteWorkspace(id);
64+
this.workspaces.delete(id);
65+
this.notifyWorkpaces();
66+
}
67+
6268
protected internalActive = true;
6369
get active() {
6470
return this.internalActive;

0 commit comments

Comments
 (0)