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

Commit7a45360

Browse files
authored
feat: supportorder property ofcoder_agent (#12121)
1 parentc66e665 commit7a45360

21 files changed

+378
-276
lines changed

‎coderd/database/dbgen/dbgen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ func WorkspaceAgent(t testing.TB, db database.Store, orig database.WorkspaceAgen
176176
TroubleshootingURL:takeFirst(orig.TroubleshootingURL,"https://example.com"),
177177
MOTDFile:takeFirst(orig.TroubleshootingURL,""),
178178
DisplayApps:append([]database.DisplayApp{},orig.DisplayApps...),
179+
DisplayOrder:takeFirst(orig.DisplayOrder,1),
179180
})
180181
require.NoError(t,err,"insert workspace agent")
181182
returnagt

‎coderd/database/dbmem/dbmem.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5648,6 +5648,7 @@ func (q *FakeQuerier) InsertWorkspaceAgent(_ context.Context, arg database.Inser
56485648
MOTDFile:arg.MOTDFile,
56495649
LifecycleState:database.WorkspaceAgentLifecycleStateCreated,
56505650
DisplayApps:arg.DisplayApps,
5651+
DisplayOrder:arg.DisplayOrder,
56515652
}
56525653

56535654
q.workspaceAgents=append(q.workspaceAgents,agent)

‎coderd/database/dump.sql

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTERTABLE workspace_agents DROP COLUMN display_order;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
ALTERTABLE workspace_agents ADD COLUMN display_orderintegerNOT NULL DEFAULT0;
2+
3+
COMMENTON COLUMNworkspace_agents.display_order
4+
IS'Specifies the order in which to display agents in user interfaces.';

‎coderd/database/models.go

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

‎coderd/database/queries.sql.go

Lines changed: 18 additions & 8 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/queries/workspaceagents.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@ INSERT INTO
4646
connection_timeout_seconds,
4747
troubleshooting_url,
4848
motd_file,
49-
display_apps
49+
display_apps,
50+
display_order
5051
)
5152
VALUES
52-
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17) RETURNING*;
53+
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18) RETURNING*;
5354

5455
-- name: UpdateWorkspaceAgentConnectionByID :exec
5556
UPDATE

‎coderd/provisionerdserver/provisionerdserver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,7 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
15241524
DisplayApps:convertDisplayApps(prAgent.GetDisplayApps()),
15251525
InstanceMetadata: pqtype.NullRawMessage{},
15261526
ResourceMetadata: pqtype.NullRawMessage{},
1527+
DisplayOrder:int32(prAgent.Order),
15271528
})
15281529
iferr!=nil {
15291530
returnxerrors.Errorf("insert agent: %w",err)

‎coderd/workspacebuilds.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import (
55
"database/sql"
66
"errors"
77
"fmt"
8+
"math"
89
"net/http"
10+
"sort"
911
"strconv"
1012
"time"
1113

@@ -905,10 +907,22 @@ func (api *API) convertWorkspaceBuild(
905907

906908
resources:=resourcesByJobID[job.ProvisionerJob.ID]
907909
apiResources:=make([]codersdk.WorkspaceResource,0)
910+
resourceAgentsMinOrder:=map[uuid.UUID]int32{}// map[resource.ID]minOrder
908911
for_,resource:=rangeresources {
909912
agents:=agentsByResourceID[resource.ID]
913+
sort.Slice(agents,func(i,jint)bool {
914+
ifagents[i].DisplayOrder!=agents[j].DisplayOrder {
915+
returnagents[i].DisplayOrder<agents[j].DisplayOrder
916+
}
917+
returnagents[i].Name<agents[j].Name
918+
})
919+
910920
apiAgents:=make([]codersdk.WorkspaceAgent,0)
921+
resourceAgentsMinOrder[resource.ID]=math.MaxInt32
922+
911923
for_,agent:=rangeagents {
924+
resourceAgentsMinOrder[resource.ID]=min(resourceAgentsMinOrder[resource.ID],agent.DisplayOrder)
925+
912926
apps:=appsByAgentID[agent.ID]
913927
scripts:=scriptsByAgentID[agent.ID]
914928
logSources:=logSourcesByAgentID[agent.ID]
@@ -924,6 +938,15 @@ func (api *API) convertWorkspaceBuild(
924938
metadata:=append(make([]database.WorkspaceResourceMetadatum,0),metadataByResourceID[resource.ID]...)
925939
apiResources=append(apiResources,convertWorkspaceResource(resource,apiAgents,metadata))
926940
}
941+
sort.Slice(apiResources,func(i,jint)bool {
942+
orderI:=resourceAgentsMinOrder[apiResources[i].ID]
943+
orderJ:=resourceAgentsMinOrder[apiResources[j].ID]
944+
iforderI!=orderJ {
945+
returnorderI<orderJ
946+
}
947+
returnapiResources[i].Name<apiResources[j].Name
948+
})
949+
927950
apiJob:=convertProvisionerJob(job)
928951
transition:=codersdk.WorkspaceTransition(build.Transition)
929952
return codersdk.WorkspaceBuild{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp