Skip to content

Commit c12bc39

Browse files
authored
fix: always show a newly created workspace at the top of the list (#6984)
Fixes #5795.
1 parent 46f42ea commit c12bc39

File tree

6 files changed

+14
-9
lines changed

6 files changed

+14
-9
lines changed

coderd/database/dbfake/databasefake.go

+1
Original file line numberDiff line numberDiff line change
@@ -3361,6 +3361,7 @@ func (q *fakeQuerier) InsertWorkspace(_ context.Context, arg database.InsertWork
33613361
Name: arg.Name,
33623362
AutostartSchedule: arg.AutostartSchedule,
33633363
Ttl: arg.Ttl,
3364+
LastUsedAt: arg.LastUsedAt,
33643365
}
33653366
q.workspaces = append(q.workspaces, workspace)
33663367
return workspace, nil

coderd/database/dbgen/generator.go

+1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ func Workspace(t testing.TB, db database.Store, orig database.Workspace) databas
145145
UpdatedAt: takeFirst(orig.UpdatedAt, database.Now()),
146146
OrganizationID: takeFirst(orig.OrganizationID, uuid.New()),
147147
TemplateID: takeFirst(orig.TemplateID, uuid.New()),
148+
LastUsedAt: takeFirst(orig.LastUsedAt, database.Now()),
148149
Name: takeFirst(orig.Name, namesgenerator.GetRandomName(1)),
149150
AutostartSchedule: orig.AutostartSchedule,
150151
Ttl: orig.Ttl,

coderd/database/queries.sql.go

+5-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/workspaces.sql

+3-2
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,11 @@ INSERT INTO
270270
template_id,
271271
name,
272272
autostart_schedule,
273-
ttl
273+
ttl,
274+
last_used_at
274275
)
275276
VALUES
276-
($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING *;
277+
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING *;
277278

278279
-- name: UpdateWorkspaceDeletedByID :exec
279280
UPDATE

coderd/insights_test.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,9 @@ func TestDeploymentInsights(t *testing.T) {
5858
daus, err := client.DeploymentDAUs(context.Background())
5959
require.NoError(t, err)
6060

61-
require.Equal(t, &codersdk.DeploymentDAUsResponse{
62-
Entries: []codersdk.DAUEntry{},
63-
}, daus, "no DAUs when stats are empty")
64-
6561
res, err := client.Workspaces(ctx, codersdk.WorkspaceFilter{})
6662
require.NoError(t, err)
67-
assert.Zero(t, res.Workspaces[0].LastUsedAt)
63+
assert.NotZero(t, res.Workspaces[0].LastUsedAt)
6864

6965
conn, err := client.DialWorkspaceAgent(ctx, resources[0].Agents[0].ID, &codersdk.DialWorkspaceAgentOptions{
7066
Logger: slogtest.Make(t, nil).Named("tailnet"),

coderd/workspaces.go

+3
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,9 @@ func (api *API) postWorkspacesByOrganization(rw http.ResponseWriter, r *http.Req
480480
Name: createWorkspace.Name,
481481
AutostartSchedule: dbAutostartSchedule,
482482
Ttl: dbTTL,
483+
// The workspaces page will sort by last used at, and it's useful to
484+
// have the newly created workspace at the top of the list!
485+
LastUsedAt: database.Now(),
483486
})
484487
if err != nil {
485488
return xerrors.Errorf("insert workspace: %w", err)

0 commit comments

Comments
 (0)