Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: Sort templates by workspaces count#3734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
BrunoQuaresma merged 3 commits intomainfrombq/fix-3713
Aug 30, 2022
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletionscoderd/templates.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"net/http"
"sort"
"time"

"github.com/go-chi/chi/v5"
Expand DownExpand Up@@ -673,6 +674,7 @@ func getCreatedByNamesByTemplateIDs(ctx context.Context, db database.Store, temp

func convertTemplates(templates []database.Template, workspaceCounts []database.GetWorkspaceOwnerCountsByTemplateIDsRow, createdByNameMap map[string]string) []codersdk.Template {
apiTemplates := make([]codersdk.Template, 0, len(templates))

for _, template := range templates {
found := false
for _, workspaceCount := range workspaceCounts {
Expand All@@ -687,6 +689,12 @@ func convertTemplates(templates []database.Template, workspaceCounts []database.
apiTemplates = append(apiTemplates, convertTemplate(template, uint32(0), createdByNameMap[template.ID.String()]))
}
}

// Sort templates by WorkspaceOwnerCount DESC
sort.SliceStable(apiTemplates, func(i, j int) bool {
return apiTemplates[i].WorkspaceOwnerCount > apiTemplates[j].WorkspaceOwnerCount
})

return apiTemplates
}

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp