mirror of
https://github.com/coder/coder.git
synced 2025-07-09 11:45:56 +00:00
feat: Show custom resource icons in the UI (#4020)
This commit is contained in:
@ -1801,6 +1801,7 @@ func (q *fakeQuerier) InsertWorkspaceResource(_ context.Context, arg database.In
|
||||
Type: arg.Type,
|
||||
Name: arg.Name,
|
||||
Hide: arg.Hide,
|
||||
Icon: arg.Icon,
|
||||
}
|
||||
q.provisionerJobResources = append(q.provisionerJobResources, resource)
|
||||
return resource, nil
|
||||
|
3
coderd/database/dump.sql
generated
3
coderd/database/dump.sql
generated
@ -368,7 +368,8 @@ CREATE TABLE workspace_resources (
|
||||
transition workspace_transition NOT NULL,
|
||||
type character varying(192) NOT NULL,
|
||||
name character varying(64) NOT NULL,
|
||||
hide boolean DEFAULT false NOT NULL
|
||||
hide boolean DEFAULT false NOT NULL,
|
||||
icon character varying(256) DEFAULT ''::character varying NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE workspaces (
|
||||
|
@ -0,0 +1,2 @@
|
||||
ALTER TABLE workspace_resources
|
||||
DROP COLUMN icon;
|
@ -0,0 +1,2 @@
|
||||
ALTER TABLE workspace_resources
|
||||
ADD COLUMN icon VARCHAR(256) NOT NULL DEFAULT ''
|
@ -588,6 +588,7 @@ type WorkspaceResource struct {
|
||||
Type string `db:"type" json:"type"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Hide bool `db:"hide" json:"hide"`
|
||||
Icon string `db:"icon" json:"icon"`
|
||||
}
|
||||
|
||||
type WorkspaceResourceMetadatum struct {
|
||||
|
@ -4356,7 +4356,7 @@ func (q *sqlQuerier) UpdateWorkspaceBuildByID(ctx context.Context, arg UpdateWor
|
||||
|
||||
const getWorkspaceResourceByID = `-- name: GetWorkspaceResourceByID :one
|
||||
SELECT
|
||||
id, created_at, job_id, transition, type, name, hide
|
||||
id, created_at, job_id, transition, type, name, hide, icon
|
||||
FROM
|
||||
workspace_resources
|
||||
WHERE
|
||||
@ -4374,6 +4374,7 @@ func (q *sqlQuerier) GetWorkspaceResourceByID(ctx context.Context, id uuid.UUID)
|
||||
&i.Type,
|
||||
&i.Name,
|
||||
&i.Hide,
|
||||
&i.Icon,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
@ -4488,7 +4489,7 @@ func (q *sqlQuerier) GetWorkspaceResourceMetadataCreatedAfter(ctx context.Contex
|
||||
|
||||
const getWorkspaceResourcesByJobID = `-- name: GetWorkspaceResourcesByJobID :many
|
||||
SELECT
|
||||
id, created_at, job_id, transition, type, name, hide
|
||||
id, created_at, job_id, transition, type, name, hide, icon
|
||||
FROM
|
||||
workspace_resources
|
||||
WHERE
|
||||
@ -4512,6 +4513,7 @@ func (q *sqlQuerier) GetWorkspaceResourcesByJobID(ctx context.Context, jobID uui
|
||||
&i.Type,
|
||||
&i.Name,
|
||||
&i.Hide,
|
||||
&i.Icon,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -4527,7 +4529,7 @@ func (q *sqlQuerier) GetWorkspaceResourcesByJobID(ctx context.Context, jobID uui
|
||||
}
|
||||
|
||||
const getWorkspaceResourcesCreatedAfter = `-- name: GetWorkspaceResourcesCreatedAfter :many
|
||||
SELECT id, created_at, job_id, transition, type, name, hide FROM workspace_resources WHERE created_at > $1
|
||||
SELECT id, created_at, job_id, transition, type, name, hide, icon FROM workspace_resources WHERE created_at > $1
|
||||
`
|
||||
|
||||
func (q *sqlQuerier) GetWorkspaceResourcesCreatedAfter(ctx context.Context, createdAt time.Time) ([]WorkspaceResource, error) {
|
||||
@ -4547,6 +4549,7 @@ func (q *sqlQuerier) GetWorkspaceResourcesCreatedAfter(ctx context.Context, crea
|
||||
&i.Type,
|
||||
&i.Name,
|
||||
&i.Hide,
|
||||
&i.Icon,
|
||||
); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -4563,9 +4566,9 @@ func (q *sqlQuerier) GetWorkspaceResourcesCreatedAfter(ctx context.Context, crea
|
||||
|
||||
const insertWorkspaceResource = `-- name: InsertWorkspaceResource :one
|
||||
INSERT INTO
|
||||
workspace_resources (id, created_at, job_id, transition, type, name, hide)
|
||||
workspace_resources (id, created_at, job_id, transition, type, name, hide, icon)
|
||||
VALUES
|
||||
($1, $2, $3, $4, $5, $6, $7) RETURNING id, created_at, job_id, transition, type, name, hide
|
||||
($1, $2, $3, $4, $5, $6, $7, $8) RETURNING id, created_at, job_id, transition, type, name, hide, icon
|
||||
`
|
||||
|
||||
type InsertWorkspaceResourceParams struct {
|
||||
@ -4576,6 +4579,7 @@ type InsertWorkspaceResourceParams struct {
|
||||
Type string `db:"type" json:"type"`
|
||||
Name string `db:"name" json:"name"`
|
||||
Hide bool `db:"hide" json:"hide"`
|
||||
Icon string `db:"icon" json:"icon"`
|
||||
}
|
||||
|
||||
func (q *sqlQuerier) InsertWorkspaceResource(ctx context.Context, arg InsertWorkspaceResourceParams) (WorkspaceResource, error) {
|
||||
@ -4587,6 +4591,7 @@ func (q *sqlQuerier) InsertWorkspaceResource(ctx context.Context, arg InsertWork
|
||||
arg.Type,
|
||||
arg.Name,
|
||||
arg.Hide,
|
||||
arg.Icon,
|
||||
)
|
||||
var i WorkspaceResource
|
||||
err := row.Scan(
|
||||
@ -4597,6 +4602,7 @@ func (q *sqlQuerier) InsertWorkspaceResource(ctx context.Context, arg InsertWork
|
||||
&i.Type,
|
||||
&i.Name,
|
||||
&i.Hide,
|
||||
&i.Icon,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
@ -19,9 +19,9 @@ SELECT * FROM workspace_resources WHERE created_at > $1;
|
||||
|
||||
-- name: InsertWorkspaceResource :one
|
||||
INSERT INTO
|
||||
workspace_resources (id, created_at, job_id, transition, type, name, hide)
|
||||
workspace_resources (id, created_at, job_id, transition, type, name, hide, icon)
|
||||
VALUES
|
||||
($1, $2, $3, $4, $5, $6, $7) RETURNING *;
|
||||
($1, $2, $3, $4, $5, $6, $7, $8) RETURNING *;
|
||||
|
||||
-- name: GetWorkspaceResourceMetadataByResourceID :many
|
||||
SELECT
|
||||
|
@ -753,6 +753,7 @@ func insertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
|
||||
Type: protoResource.Type,
|
||||
Name: protoResource.Name,
|
||||
Hide: protoResource.Hide,
|
||||
Icon: protoResource.Icon,
|
||||
})
|
||||
if err != nil {
|
||||
return xerrors.Errorf("insert provisioner job resource %q: %w", protoResource.Name, err)
|
||||
|
@ -707,6 +707,7 @@ func convertWorkspaceResource(resource database.WorkspaceResource, agents []code
|
||||
Type: resource.Type,
|
||||
Name: resource.Name,
|
||||
Hide: resource.Hide,
|
||||
Icon: resource.Icon,
|
||||
Agents: agents,
|
||||
Metadata: convertedMetadata,
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ func TestWorkspaceResource(t *testing.T) {
|
||||
Resources: []*proto.Resource{{
|
||||
Name: "beta",
|
||||
Type: "example",
|
||||
Icon: "/icon/server.svg",
|
||||
Agents: []*proto.Agent{{
|
||||
Id: "something",
|
||||
Name: "b",
|
||||
@ -60,9 +61,11 @@ func TestWorkspaceResource(t *testing.T) {
|
||||
resource, err := client.WorkspaceResource(ctx, resources[1].ID)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, resource.Agents, 2)
|
||||
// Ensure it's sorted alphabetically!
|
||||
// Ensure agents are sorted alphabetically!
|
||||
require.Equal(t, "a", resource.Agents[0].Name)
|
||||
require.Equal(t, "b", resource.Agents[1].Name)
|
||||
// Ensure Icon is present
|
||||
require.Equal(t, "/icon/server.svg", resources[1].Icon)
|
||||
})
|
||||
|
||||
t.Run("Apps", func(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user