Skip to content

feat: add "updated" search param to workspaces #11714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: add "updated" search param to workspaces
  • Loading branch information
Emyrk committed Jan 23, 2024
commit a83a2816186099a541c2b48f158055ae5ffe3439
1 change: 1 addition & 0 deletions coderd/database/modelqueries.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ func (q *sqlQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg GetWorkspa
arg.Dormant,
arg.LastUsedBefore,
arg.LastUsedAfter,
arg.UsingActive,
arg.Offset,
arg.Limit,
)
Expand Down
47 changes: 27 additions & 20 deletions coderd/database/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions coderd/database/queries/workspaces.sql
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ WHERE
-- name: GetWorkspaces :many
SELECT
workspaces.*,
COALESCE(template_name.template_name, 'unknown') as template_name,
COALESCE(template.name, 'unknown') as template_name,
latest_build.template_version_id,
latest_build.template_version_name,
COUNT(*) OVER () as count
Expand Down Expand Up @@ -120,12 +120,12 @@ LEFT JOIN LATERAL (
) latest_build ON TRUE
LEFT JOIN LATERAL (
SELECT
templates.name AS template_name
*
FROM
templates
WHERE
templates.id = workspaces.template_id
) template_name ON true
) template ON true
WHERE
-- Optionally include deleted workspaces
workspaces.deleted = @deleted
Expand Down Expand Up @@ -259,6 +259,11 @@ WHERE
workspaces.last_used_at >= @last_used_after
ELSE true
END
AND CASE
WHEN sqlc.narg('using_active') :: boolean IS NOT NULL THEN
(latest_build.template_version_id = template.active_version_id) = sqlc.narg('using_active') :: boolean
ELSE true
END
-- Authorize Filter clause will be injected below in GetAuthorizedWorkspaces
-- @authorize_filter
ORDER BY
Expand Down
7 changes: 7 additions & 0 deletions coderd/searchquery/search.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package searchquery

import (
"database/sql"
"fmt"
"net/url"
"strings"
Expand Down Expand Up @@ -110,6 +111,12 @@ func Workspaces(query string, page codersdk.Pagination, agentInactiveDisconnectT
filter.Dormant = parser.Boolean(values, false, "dormant")
filter.LastUsedAfter = parser.Time3339Nano(values, time.Time{}, "last_used_after")
filter.LastUsedBefore = parser.Time3339Nano(values, time.Time{}, "last_used_before")
filter.UsingActive = sql.NullBool{
// UsingActive returns if the workspace is on the latest template active version.
// This means the workspace is "up to date".
Bool: parser.Boolean(values, false, "updated"),
Valid: values.Has("updated"),
}

parser.ErrorExcessParams(values)
return filter, parser.Errors
Expand Down
11 changes: 11 additions & 0 deletions coderd/searchquery/search_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package searchquery_test

import (
"database/sql"
"fmt"
"strings"
"testing"
Expand Down Expand Up @@ -116,6 +117,16 @@ func TestSearchWorkspace(t *testing.T) {
OwnerUsername: "foo",
},
},
{
Name: "Updated",
Query: `updated:true`,
Expected: database.GetWorkspacesParams{
UsingActive: sql.NullBool{
Bool: true,
Valid: true,
},
},
},

// Failures
{
Expand Down