mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
fix: always show a newly created workspace at the top of the list (#6984)
Fixes #5795.
This commit is contained in:
@ -3361,6 +3361,7 @@ func (q *fakeQuerier) InsertWorkspace(_ context.Context, arg database.InsertWork
|
|||||||
Name: arg.Name,
|
Name: arg.Name,
|
||||||
AutostartSchedule: arg.AutostartSchedule,
|
AutostartSchedule: arg.AutostartSchedule,
|
||||||
Ttl: arg.Ttl,
|
Ttl: arg.Ttl,
|
||||||
|
LastUsedAt: arg.LastUsedAt,
|
||||||
}
|
}
|
||||||
q.workspaces = append(q.workspaces, workspace)
|
q.workspaces = append(q.workspaces, workspace)
|
||||||
return workspace, nil
|
return workspace, nil
|
||||||
|
@ -145,6 +145,7 @@ func Workspace(t testing.TB, db database.Store, orig database.Workspace) databas
|
|||||||
UpdatedAt: takeFirst(orig.UpdatedAt, database.Now()),
|
UpdatedAt: takeFirst(orig.UpdatedAt, database.Now()),
|
||||||
OrganizationID: takeFirst(orig.OrganizationID, uuid.New()),
|
OrganizationID: takeFirst(orig.OrganizationID, uuid.New()),
|
||||||
TemplateID: takeFirst(orig.TemplateID, uuid.New()),
|
TemplateID: takeFirst(orig.TemplateID, uuid.New()),
|
||||||
|
LastUsedAt: takeFirst(orig.LastUsedAt, database.Now()),
|
||||||
Name: takeFirst(orig.Name, namesgenerator.GetRandomName(1)),
|
Name: takeFirst(orig.Name, namesgenerator.GetRandomName(1)),
|
||||||
AutostartSchedule: orig.AutostartSchedule,
|
AutostartSchedule: orig.AutostartSchedule,
|
||||||
Ttl: orig.Ttl,
|
Ttl: orig.Ttl,
|
||||||
|
@ -8014,10 +8014,11 @@ INSERT INTO
|
|||||||
template_id,
|
template_id,
|
||||||
name,
|
name,
|
||||||
autostart_schedule,
|
autostart_schedule,
|
||||||
ttl
|
ttl,
|
||||||
|
last_used_at
|
||||||
)
|
)
|
||||||
VALUES
|
VALUES
|
||||||
($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING id, created_at, updated_at, owner_id, organization_id, template_id, deleted, name, autostart_schedule, ttl, last_used_at
|
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING id, created_at, updated_at, owner_id, organization_id, template_id, deleted, name, autostart_schedule, ttl, last_used_at
|
||||||
`
|
`
|
||||||
|
|
||||||
type InsertWorkspaceParams struct {
|
type InsertWorkspaceParams struct {
|
||||||
@ -8030,6 +8031,7 @@ type InsertWorkspaceParams struct {
|
|||||||
Name string `db:"name" json:"name"`
|
Name string `db:"name" json:"name"`
|
||||||
AutostartSchedule sql.NullString `db:"autostart_schedule" json:"autostart_schedule"`
|
AutostartSchedule sql.NullString `db:"autostart_schedule" json:"autostart_schedule"`
|
||||||
Ttl sql.NullInt64 `db:"ttl" json:"ttl"`
|
Ttl sql.NullInt64 `db:"ttl" json:"ttl"`
|
||||||
|
LastUsedAt time.Time `db:"last_used_at" json:"last_used_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *sqlQuerier) InsertWorkspace(ctx context.Context, arg InsertWorkspaceParams) (Workspace, error) {
|
func (q *sqlQuerier) InsertWorkspace(ctx context.Context, arg InsertWorkspaceParams) (Workspace, error) {
|
||||||
@ -8043,6 +8045,7 @@ func (q *sqlQuerier) InsertWorkspace(ctx context.Context, arg InsertWorkspacePar
|
|||||||
arg.Name,
|
arg.Name,
|
||||||
arg.AutostartSchedule,
|
arg.AutostartSchedule,
|
||||||
arg.Ttl,
|
arg.Ttl,
|
||||||
|
arg.LastUsedAt,
|
||||||
)
|
)
|
||||||
var i Workspace
|
var i Workspace
|
||||||
err := row.Scan(
|
err := row.Scan(
|
||||||
|
@ -270,10 +270,11 @@ INSERT INTO
|
|||||||
template_id,
|
template_id,
|
||||||
name,
|
name,
|
||||||
autostart_schedule,
|
autostart_schedule,
|
||||||
ttl
|
ttl,
|
||||||
|
last_used_at
|
||||||
)
|
)
|
||||||
VALUES
|
VALUES
|
||||||
($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING *;
|
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING *;
|
||||||
|
|
||||||
-- name: UpdateWorkspaceDeletedByID :exec
|
-- name: UpdateWorkspaceDeletedByID :exec
|
||||||
UPDATE
|
UPDATE
|
||||||
|
@ -58,13 +58,9 @@ func TestDeploymentInsights(t *testing.T) {
|
|||||||
daus, err := client.DeploymentDAUs(context.Background())
|
daus, err := client.DeploymentDAUs(context.Background())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.Equal(t, &codersdk.DeploymentDAUsResponse{
|
|
||||||
Entries: []codersdk.DAUEntry{},
|
|
||||||
}, daus, "no DAUs when stats are empty")
|
|
||||||
|
|
||||||
res, err := client.Workspaces(ctx, codersdk.WorkspaceFilter{})
|
res, err := client.Workspaces(ctx, codersdk.WorkspaceFilter{})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Zero(t, res.Workspaces[0].LastUsedAt)
|
assert.NotZero(t, res.Workspaces[0].LastUsedAt)
|
||||||
|
|
||||||
conn, err := client.DialWorkspaceAgent(ctx, resources[0].Agents[0].ID, &codersdk.DialWorkspaceAgentOptions{
|
conn, err := client.DialWorkspaceAgent(ctx, resources[0].Agents[0].ID, &codersdk.DialWorkspaceAgentOptions{
|
||||||
Logger: slogtest.Make(t, nil).Named("tailnet"),
|
Logger: slogtest.Make(t, nil).Named("tailnet"),
|
||||||
|
@ -480,6 +480,9 @@ func (api *API) postWorkspacesByOrganization(rw http.ResponseWriter, r *http.Req
|
|||||||
Name: createWorkspace.Name,
|
Name: createWorkspace.Name,
|
||||||
AutostartSchedule: dbAutostartSchedule,
|
AutostartSchedule: dbAutostartSchedule,
|
||||||
Ttl: dbTTL,
|
Ttl: dbTTL,
|
||||||
|
// The workspaces page will sort by last used at, and it's useful to
|
||||||
|
// have the newly created workspace at the top of the list!
|
||||||
|
LastUsedAt: database.Now(),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("insert workspace: %w", err)
|
return xerrors.Errorf("insert workspace: %w", err)
|
||||||
|
Reference in New Issue
Block a user