Skip to content

Commit 21a462d

Browse files
svenefftingeroboquat
authored andcommitted
[dashboard] sort workspaces by activity
1 parent 1157fae commit 21a462d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,23 @@ export class WorkspaceModel implements Disposable, Partial<GitpodClient> {
136136
.indexOf(this.searchTerm!.toLowerCase()) !== -1,
137137
);
138138
}
139+
const now = new Date().toISOString();
140+
function activeDate(info: WorkspaceInfo): string {
141+
if (!info.latestInstance) {
142+
return info.workspace.creationTime;
143+
}
144+
if (info.latestInstance.status.phase === "stopped" || info.latestInstance.status.phase === "unknown") {
145+
return WorkspaceInfo.lastActiveISODate(info);
146+
}
147+
return info.latestInstance.stoppedTime || info.latestInstance.stoppingTime || now;
148+
}
139149
infos = infos.sort((a, b) => {
140-
return WorkspaceInfo.lastActiveISODate(b).localeCompare(WorkspaceInfo.lastActiveISODate(a));
150+
const result = activeDate(b).localeCompare(activeDate(a));
151+
if (result === 0) {
152+
// both active now? order by creationtime
153+
return WorkspaceInfo.lastActiveISODate(b).localeCompare(WorkspaceInfo.lastActiveISODate(a));
154+
}
155+
return result;
141156
});
142157
const activeInfo = infos.filter((ws) => this.isActive(ws));
143158
const inActiveInfo = infos.filter((ws) => !this.isActive(ws));

0 commit comments

Comments
 (0)