Skip to content

Commit 3e68650

Browse files
authored
feat: support order property of coder_app resource (#12077)
1 parent 1e9a3c9 commit 3e68650

File tree

18 files changed

+306
-195
lines changed

18 files changed

+306
-195
lines changed

coderd/database/db2sdk/db2sdk.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77
"net/url"
8+
"sort"
89
"strconv"
910
"strings"
1011
"time"
@@ -414,6 +415,16 @@ func AppSubdomain(dbApp database.WorkspaceApp, agentName, workspaceName, ownerNa
414415
}
415416

416417
func Apps(dbApps []database.WorkspaceApp, agent database.WorkspaceAgent, ownerName string, workspace database.Workspace) []codersdk.WorkspaceApp {
418+
sort.Slice(dbApps, func(i, j int) bool {
419+
if dbApps[i].DisplayOrder != dbApps[j].DisplayOrder {
420+
return dbApps[i].DisplayOrder < dbApps[j].DisplayOrder
421+
}
422+
if dbApps[i].DisplayName != dbApps[j].DisplayName {
423+
return dbApps[i].DisplayName < dbApps[j].DisplayName
424+
}
425+
return dbApps[i].Slug < dbApps[j].Slug
426+
})
427+
417428
apps := make([]codersdk.WorkspaceApp, 0)
418429
for _, dbApp := range dbApps {
419430
apps = append(apps, codersdk.WorkspaceApp{

coderd/database/dbgen/dbgen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ func WorkspaceApp(t testing.TB, db database.Store, orig database.WorkspaceApp) d
465465
HealthcheckInterval: takeFirst(orig.HealthcheckInterval, 60),
466466
HealthcheckThreshold: takeFirst(orig.HealthcheckThreshold, 60),
467467
Health: takeFirst(orig.Health, database.WorkspaceAppHealthHealthy),
468+
DisplayOrder: takeFirst(orig.DisplayOrder, 1),
468469
})
469470
require.NoError(t, err, "insert app")
470471
return resource

coderd/database/dbmem/dbmem.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5826,6 +5826,7 @@ func (q *FakeQuerier) InsertWorkspaceApp(_ context.Context, arg database.InsertW
58265826
HealthcheckInterval: arg.HealthcheckInterval,
58275827
HealthcheckThreshold: arg.HealthcheckThreshold,
58285828
Health: arg.Health,
5829+
DisplayOrder: arg.DisplayOrder,
58295830
}
58305831
q.workspaceApps = append(q.workspaceApps, workspaceApp)
58315832
return workspaceApp, nil

coderd/database/dump.sql

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE workspace_apps DROP COLUMN display_order;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ALTER TABLE workspace_apps ADD COLUMN display_order integer NOT NULL DEFAULT 0;
2+
3+
COMMENT ON COLUMN workspace_apps.display_order
4+
IS 'Specifies the order in which to display agent app in user interfaces.';

coderd/database/models.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 14 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/workspaceapps.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ INSERT INTO
2727
healthcheck_url,
2828
healthcheck_interval,
2929
healthcheck_threshold,
30-
health
30+
health,
31+
display_order
3132
)
3233
VALUES
33-
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15) RETURNING *;
34+
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16) RETURNING *;
3435

3536
-- name: UpdateWorkspaceAppHealthByID :exec
3637
UPDATE

coderd/provisionerdserver/provisionerdserver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,7 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
16481648
HealthcheckInterval: app.Healthcheck.Interval,
16491649
HealthcheckThreshold: app.Healthcheck.Threshold,
16501650
Health: health,
1651+
DisplayOrder: int32(app.Order),
16511652
})
16521653
if err != nil {
16531654
return xerrors.Errorf("insert app: %w", err)

0 commit comments

Comments
 (0)