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

Commit3e68650

Browse files
authored
feat: supportorder property ofcoder_app resource (#12077)
1 parent1e9a3c9 commit3e68650

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
funcApps(dbApps []database.WorkspaceApp,agent database.WorkspaceAgent,ownerNamestring,workspace database.Workspace) []codersdk.WorkspaceApp {
418+
sort.Slice(dbApps,func(i,jint)bool {
419+
ifdbApps[i].DisplayOrder!=dbApps[j].DisplayOrder {
420+
returndbApps[i].DisplayOrder<dbApps[j].DisplayOrder
421+
}
422+
ifdbApps[i].DisplayName!=dbApps[j].DisplayName {
423+
returndbApps[i].DisplayName<dbApps[j].DisplayName
424+
}
425+
returndbApps[i].Slug<dbApps[j].Slug
426+
})
427+
417428
apps:=make([]codersdk.WorkspaceApp,0)
418429
for_,dbApp:=rangedbApps {
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
returnresource

‎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
returnworkspaceApp,nil

‎coderd/database/dump.sql

Lines changed: 4 additions & 1 deletion
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_apps 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_apps ADD COLUMN display_orderintegerNOT NULL DEFAULT0;
2+
3+
COMMENTON COLUMNworkspace_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 aboutcustomizing 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 aboutcustomizing 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
iferr!=nil {
16531654
returnxerrors.Errorf("insert app: %w",err)

‎coderd/workspaces_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2543,6 +2543,66 @@ func TestWorkspaceResource(t *testing.T) {
25432543
require.EqualValues(t,app.Healthcheck.Threshold,got.Healthcheck.Threshold)
25442544
})
25452545

2546+
t.Run("Apps_DisplayOrder",func(t*testing.T) {
2547+
t.Parallel()
2548+
client:=coderdtest.New(t,&coderdtest.Options{
2549+
IncludeProvisionerDaemon:true,
2550+
})
2551+
user:=coderdtest.CreateFirstUser(t,client)
2552+
apps:= []*proto.App{
2553+
{
2554+
Slug:"aaa",
2555+
DisplayName:"aaa",
2556+
},
2557+
{
2558+
Slug:"aaa-code-server",
2559+
Order:4,
2560+
},
2561+
{
2562+
Slug:"bbb-code-server",
2563+
Order:3,
2564+
},
2565+
{
2566+
Slug:"bbb",
2567+
},
2568+
}
2569+
version:=coderdtest.CreateTemplateVersion(t,client,user.OrganizationID,&echo.Responses{
2570+
Parse:echo.ParseComplete,
2571+
ProvisionApply: []*proto.Response{{
2572+
Type:&proto.Response_Apply{
2573+
Apply:&proto.ApplyComplete{
2574+
Resources: []*proto.Resource{{
2575+
Name:"some",
2576+
Type:"example",
2577+
Agents: []*proto.Agent{{
2578+
Id:"something",
2579+
Auth:&proto.Agent_Token{},
2580+
Apps:apps,
2581+
}},
2582+
}},
2583+
},
2584+
},
2585+
}},
2586+
})
2587+
coderdtest.AwaitTemplateVersionJobCompleted(t,client,version.ID)
2588+
template:=coderdtest.CreateTemplate(t,client,user.OrganizationID,version.ID)
2589+
workspace:=coderdtest.CreateWorkspace(t,client,user.OrganizationID,template.ID)
2590+
coderdtest.AwaitWorkspaceBuildJobCompleted(t,client,workspace.LatestBuild.ID)
2591+
2592+
ctx,cancel:=context.WithTimeout(context.Background(),testutil.WaitLong)
2593+
defercancel()
2594+
2595+
workspace,err:=client.Workspace(ctx,workspace.ID)
2596+
require.NoError(t,err)
2597+
require.Len(t,workspace.LatestBuild.Resources[0].Agents,1)
2598+
agent:=workspace.LatestBuild.Resources[0].Agents[0]
2599+
require.Len(t,agent.Apps,4)
2600+
require.Equal(t,"bbb",agent.Apps[0].Slug)// empty-display-name < "aaa"
2601+
require.Equal(t,"aaa",agent.Apps[1].Slug)// no order < any order
2602+
require.Equal(t,"bbb-code-server",agent.Apps[2].Slug)// order = 3 < order = 4
2603+
require.Equal(t,"aaa-code-server",agent.Apps[3].Slug)
2604+
})
2605+
25462606
t.Run("Metadata",func(t*testing.T) {
25472607
t.Parallel()
25482608
client:=coderdtest.New(t,&coderdtest.Options{

‎go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ require (
9696
github.com/coder/flogv1.1.0
9797
github.com/coder/prettyv0.0.0-20230908205945-e89ba86370e0
9898
github.com/coder/retryv1.5.1
99-
github.com/coder/terraform-provider-coderv0.14.1
99+
github.com/coder/terraform-provider-coderv0.14.2
100100
github.com/coder/wgtunnelv0.1.13-0.20231127054351-578bfff9b92a
101101
github.com/coreos/go-oidc/v3v3.9.0
102102
github.com/coreos/go-systemdv0.0.0-20191104093116-d3cd4ed1dbcf

‎go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ github.com/coder/ssh v0.0.0-20231128192721-70855dedb788 h1:YoUSJ19E8AtuUFVYBpXuO
204204
github.com/coder/sshv0.0.0-20231128192721-70855dedb788/go.mod h1:aGQbuCLyhRLMzZF067xc84Lh7JDs1FKwCmF1Crl9dxQ=
205205
github.com/coder/tailscalev1.1.1-0.20231205095743-61c97bad8c8b h1:ut/aL6oI8TjGdg4JI8+bKB9w5j73intbe0dJAmcmYyQ=
206206
github.com/coder/tailscalev1.1.1-0.20231205095743-61c97bad8c8b/go.mod h1:L8tPrwSi31RAMEMV8rjb0vYTGs7rXt8rAHbqY/p41j4=
207-
github.com/coder/terraform-provider-coderv0.14.1 h1:a97th+fVIs9i5kBj7WTOA4ssAAxaOTvwISLaYl4mbKw=
208-
github.com/coder/terraform-provider-coderv0.14.1/go.mod h1:pACHRoXSHBGyY696mLeQ1hR/Ag1G2wFk5bw0mT5Zp2g=
207+
github.com/coder/terraform-provider-coderv0.14.2 h1:CfQyQH9bOTI3cauxKJyPCUDkIcHOaMyFifxehkkkz/8=
208+
github.com/coder/terraform-provider-coderv0.14.2/go.mod h1:pACHRoXSHBGyY696mLeQ1hR/Ag1G2wFk5bw0mT5Zp2g=
209209
github.com/coder/wgtunnelv0.1.13-0.20231127054351-578bfff9b92a h1:KhR9LUVllMZ+e9lhubZ1HNrtJDgH5YLoTvpKwmrGag4=
210210
github.com/coder/wgtunnelv0.1.13-0.20231127054351-578bfff9b92a/go.mod h1:QzfptVUdEO+XbkzMKx1kw13i9wwpJlfI1RrZ6SNZ0hA=
211211
github.com/coder/wireguard-gov0.0.0-20230807234434-d825b45ccbf5 h1:eDk/42Kj4xN4yfE504LsvcFEo3dWUiCOaBiWJ2uIH2A=

‎provisioner/terraform/resources.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ type agentAppAttributes struct {
7676
Sharestring`mapstructure:"share"`
7777
Subdomainbool`mapstructure:"subdomain"`
7878
Healthcheck []appHealthcheckAttributes`mapstructure:"healthcheck"`
79+
Orderint64`mapstructure:"order"`
7980
}
8081

8182
typeagentEnvAttributesstruct {
@@ -437,6 +438,7 @@ func ConvertState(modules []*tfjson.StateModule, rawGraph string) (*State, error
437438
Subdomain:attrs.Subdomain,
438439
SharingLevel:sharingLevel,
439440
Healthcheck:healthcheck,
441+
Order:attrs.Order,
440442
})
441443
}
442444
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp