mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
feat: paginate workspaces page (#4647)
* Start - still needs api call changes * Some xservice changes * Finish adding count to xservice * Mock out api call on frontend * Handle errors * Doctor getWorkspaces * Add types, start writing count function * Hook up route * Use empty page struct * Write interface and database fake * SQL query * Fix params type * Missed a spot * Space after alert banner * Fix model queries * Unpack query correctly * Fix filter-page interaction * Make mobile friendly * Format * Test backend * Fix key * Delete unnecessary conditional * Add test helpers * Use limit constant * Show widget with no count * Add test * Format * make gen from garretts workspace idk why * fix authorize test' * Hide widget with 0 records * Fix tests * Format * Fix types generated * Fix story * Add alert banner story * Format * Fix import * Format * Try removing story * Revert "Fix story" This reverts commitc06765b7fb
. * Add counts to page view story * Revert "Try removing story" This reverts commit476019b041
. Co-authored-by: Garrett <garrett@coder.com>
This commit is contained in:
@ -112,6 +112,7 @@ func (q *sqlQuerier) GetTemplateGroupRoles(ctx context.Context, id uuid.UUID) ([
|
||||
|
||||
type workspaceQuerier interface {
|
||||
GetAuthorizedWorkspaces(ctx context.Context, arg GetWorkspacesParams, authorizedFilter rbac.AuthorizeFilter) ([]Workspace, error)
|
||||
GetAuthorizedWorkspaceCount(ctx context.Context, arg GetWorkspaceCountParams, authorizedFilter rbac.AuthorizeFilter) (int64, error)
|
||||
}
|
||||
|
||||
// GetAuthorizedWorkspaces returns all workspaces that the user is authorized to access.
|
||||
@ -166,3 +167,23 @@ func (q *sqlQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg GetWorkspa
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) GetAuthorizedWorkspaceCount(ctx context.Context, arg GetWorkspaceCountParams, authorizedFilter rbac.AuthorizeFilter) (int64, error) {
|
||||
// In order to properly use ORDER BY, OFFSET, and LIMIT, we need to inject the
|
||||
// authorizedFilter between the end of the where clause and those statements.
|
||||
filter := strings.Replace(getWorkspaceCount, "-- @authorize_filter", fmt.Sprintf(" AND %s", authorizedFilter.SQLString(rbac.NoACLConfig())), 1)
|
||||
// The name comment is for metric tracking
|
||||
query := fmt.Sprintf("-- name: GetAuthorizedWorkspaceCount :one\n%s", filter)
|
||||
row := q.db.QueryRowContext(ctx, query,
|
||||
arg.Deleted,
|
||||
arg.Status,
|
||||
arg.OwnerID,
|
||||
arg.OwnerUsername,
|
||||
arg.TemplateName,
|
||||
pq.Array(arg.TemplateIds),
|
||||
arg.Name,
|
||||
)
|
||||
var count int64
|
||||
err := row.Scan(&count)
|
||||
return count, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user