From 500aade39a02ef48384f9f893d5c8d4d67add528 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Wed, 7 Sep 2022 20:02:51 +0000 Subject: [PATCH] fix: Sort workspaces by last used then name --- coderd/workspaces.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/coderd/workspaces.go b/coderd/workspaces.go index 7d74dc2597b79..4b4377597eb72 100644 --- a/coderd/workspaces.go +++ b/coderd/workspaces.go @@ -8,6 +8,7 @@ import ( "fmt" "net/http" "net/url" + "sort" "strconv" "strings" "time" @@ -916,6 +917,15 @@ func convertWorkspaces(ctx context.Context, db database.Store, workspaces []data } apiWorkspaces = append(apiWorkspaces, convertWorkspace(workspace, build, job, template, &owner, &initiator)) } + sort.Slice(apiWorkspaces, func(i, j int) bool { + iw := apiWorkspaces[i] + jw := apiWorkspaces[j] + if jw.LastUsedAt.IsZero() && iw.LastUsedAt.IsZero() { + return iw.Name < jw.Name + } + return iw.LastUsedAt.After(jw.LastUsedAt) + }) + return apiWorkspaces, nil }