mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat(workspaces): change sorting order of the workspace list (#7594)
* feat(workspaces): implement sorting order on workspace list * split slice into its own function and test it * use require instead of assert * Update coderd/workspaces_internal_test.go Co-authored-by: Cian Johnston <cian@coder.com> * refactor tests into table tests * fix test --------- Co-authored-by: Cian Johnston <cian@coder.com>
This commit is contained in:
co-authored by
Cian Johnston
parent
5d711fc95a
commit
4a320617b4
+23
-5
@@ -1147,16 +1147,34 @@ func convertWorkspaces(workspaces []database.Workspace, data workspaceData) ([]c
|
||||
&owner,
|
||||
))
|
||||
}
|
||||
sort.Slice(apiWorkspaces, func(i, j int) bool {
|
||||
iw := apiWorkspaces[i]
|
||||
jw := apiWorkspaces[j]
|
||||
|
||||
sortWorkspaces(apiWorkspaces)
|
||||
|
||||
return apiWorkspaces, nil
|
||||
}
|
||||
|
||||
func sortWorkspaces(workspaces []codersdk.Workspace) {
|
||||
sort.Slice(workspaces, func(i, j int) bool {
|
||||
iw := workspaces[i]
|
||||
jw := workspaces[j]
|
||||
|
||||
if iw.LatestBuild.Status == codersdk.WorkspaceStatusRunning && jw.LatestBuild.Status != codersdk.WorkspaceStatusRunning {
|
||||
return true
|
||||
}
|
||||
|
||||
if jw.LatestBuild.Status == codersdk.WorkspaceStatusRunning && iw.LatestBuild.Status != codersdk.WorkspaceStatusRunning {
|
||||
return false
|
||||
}
|
||||
|
||||
if iw.OwnerID != jw.OwnerID {
|
||||
return iw.OwnerName < jw.OwnerName
|
||||
}
|
||||
|
||||
if jw.LastUsedAt.IsZero() && iw.LastUsedAt.IsZero() {
|
||||
return iw.Name < jw.Name
|
||||
}
|
||||
return iw.LastUsedAt.After(jw.LastUsedAt)
|
||||
})
|
||||
|
||||
return apiWorkspaces, nil
|
||||
}
|
||||
|
||||
func convertWorkspace(
|
||||
|
||||
Reference in New Issue
Block a user