mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: Sort workspaces by last used then name (#3943)
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -913,6 +914,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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user