Skip to content

Commit 80f042f

Browse files
feat: Add icon to templates (#3561)
1 parent 57f3410 commit 80f042f

File tree

17 files changed

+66
-12
lines changed

17 files changed

+66
-12
lines changed

cli/templateedit.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func templateEdit() *cobra.Command {
1515
var (
1616
name string
1717
description string
18+
icon string
1819
maxTTL time.Duration
1920
minAutostartInterval time.Duration
2021
)
@@ -41,6 +42,7 @@ func templateEdit() *cobra.Command {
4142
req := codersdk.UpdateTemplateMeta{
4243
Name: name,
4344
Description: description,
45+
Icon: icon,
4446
MaxTTLMillis: maxTTL.Milliseconds(),
4547
MinAutostartIntervalMillis: minAutostartInterval.Milliseconds(),
4648
}
@@ -56,6 +58,7 @@ func templateEdit() *cobra.Command {
5658

5759
cmd.Flags().StringVarP(&name, "name", "", "", "Edit the template name")
5860
cmd.Flags().StringVarP(&description, "description", "", "", "Edit the template description")
61+
cmd.Flags().StringVarP(&icon, "icon", "", "", "Edit the template icon path")
5962
cmd.Flags().DurationVarP(&maxTTL, "max-ttl", "", 0, "Edit the template maximum time before shutdown")
6063
cmd.Flags().DurationVarP(&minAutostartInterval, "min-autostart-interval", "", 0, "Edit the template minimum autostart interval")
6164
cliui.AllowSkipPrompt(cmd)

cli/templateedit_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ func TestTemplateEdit(t *testing.T) {
2525
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
2626
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID, func(ctr *codersdk.CreateTemplateRequest) {
2727
ctr.Description = "original description"
28+
ctr.Icon = "/icons/default-icon.png"
2829
ctr.MaxTTLMillis = ptr.Ref(24 * time.Hour.Milliseconds())
2930
ctr.MinAutostartIntervalMillis = ptr.Ref(time.Hour.Milliseconds())
3031
})
3132

3233
// Test the cli command.
3334
name := "new-template-name"
3435
desc := "lorem ipsum dolor sit amet et cetera"
36+
icon := "/icons/new-icon.png"
3537
maxTTL := 12 * time.Hour
3638
minAutostartInterval := time.Minute
3739
cmdArgs := []string{
@@ -40,6 +42,7 @@ func TestTemplateEdit(t *testing.T) {
4042
template.Name,
4143
"--name", name,
4244
"--description", desc,
45+
"--icon", icon,
4346
"--max-ttl", maxTTL.String(),
4447
"--min-autostart-interval", minAutostartInterval.String(),
4548
}
@@ -55,6 +58,7 @@ func TestTemplateEdit(t *testing.T) {
5558
require.NoError(t, err)
5659
assert.Equal(t, name, updated.Name)
5760
assert.Equal(t, desc, updated.Description)
61+
assert.Equal(t, icon, updated.Icon)
5862
assert.Equal(t, maxTTL.Milliseconds(), updated.MaxTTLMillis)
5963
assert.Equal(t, minAutostartInterval.Milliseconds(), updated.MinAutostartIntervalMillis)
6064
})
@@ -67,6 +71,7 @@ func TestTemplateEdit(t *testing.T) {
6771
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
6872
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID, func(ctr *codersdk.CreateTemplateRequest) {
6973
ctr.Description = "original description"
74+
ctr.Icon = "/icons/default-icon.png"
7075
ctr.MaxTTLMillis = ptr.Ref(24 * time.Hour.Milliseconds())
7176
ctr.MinAutostartIntervalMillis = ptr.Ref(time.Hour.Milliseconds())
7277
})
@@ -78,6 +83,7 @@ func TestTemplateEdit(t *testing.T) {
7883
template.Name,
7984
"--name", template.Name,
8085
"--description", template.Description,
86+
"--icon", template.Icon,
8187
"--max-ttl", (time.Duration(template.MaxTTLMillis) * time.Millisecond).String(),
8288
"--min-autostart-interval", (time.Duration(template.MinAutostartIntervalMillis) * time.Millisecond).String(),
8389
}
@@ -93,6 +99,7 @@ func TestTemplateEdit(t *testing.T) {
9399
require.NoError(t, err)
94100
assert.Equal(t, template.Name, updated.Name)
95101
assert.Equal(t, template.Description, updated.Description)
102+
assert.Equal(t, template.Icon, updated.Icon)
96103
assert.Equal(t, template.MaxTTLMillis, updated.MaxTTLMillis)
97104
assert.Equal(t, template.MinAutostartIntervalMillis, updated.MinAutostartIntervalMillis)
98105
})

coderd/audit/table.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ var AuditableResources = auditMap(map[any]map[string]Action{
7070
"provisioner": ActionTrack,
7171
"active_version_id": ActionTrack,
7272
"description": ActionTrack,
73+
"icon": ActionTrack,
7374
"max_ttl": ActionTrack,
7475
"min_autostart_interval": ActionTrack,
7576
"created_by": ActionTrack,

coderd/database/databasefake/databasefake.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,7 @@ func (q *fakeQuerier) UpdateTemplateMetaByID(_ context.Context, arg database.Upd
883883
tpl.UpdatedAt = database.Now()
884884
tpl.Name = arg.Name
885885
tpl.Description = arg.Description
886+
tpl.Icon = arg.Icon
886887
tpl.MaxTtl = arg.MaxTtl
887888
tpl.MinAutostartInterval = arg.MinAutostartInterval
888889
q.templates[idx] = tpl

coderd/database/dump.sql

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE templates DROP COLUMN icon;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE templates ADD COLUMN icon VARCHAR(256) NOT NULL DEFAULT '';

coderd/database/models.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries.sql.go

Lines changed: 19 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/queries/templates.sql

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ INSERT INTO
6767
description,
6868
max_ttl,
6969
min_autostart_interval,
70-
created_by
70+
created_by,
71+
icon
7172
)
7273
VALUES
73-
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING *;
74+
($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) RETURNING *;
7475

7576
-- name: UpdateTemplateActiveVersionByID :exec
7677
UPDATE
@@ -98,7 +99,8 @@ SET
9899
description = $3,
99100
max_ttl = $4,
100101
min_autostart_interval = $5,
101-
name = $6
102+
name = $6,
103+
icon = $7
102104
WHERE
103105
id = $1
104106
RETURNING

0 commit comments

Comments
 (0)