Skip to content

Commit d90529b

Browse files
author
Rafael Rodriguez
committed
feat: add tooltip field to workspace app
1 parent 42c19bc commit d90529b

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

docs/resources/app.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ resource "coder_app" "vim" {
7171
- `order` (Number) The order determines the position of app in the UI presentation. The lowest order is shown first and apps with equal order are sorted by name (ascending order).
7272
- `share` (String) Determines the level which the application is shared at. Valid levels are `"owner"` (default), `"authenticated"` and `"public"`. Level `"owner"` disables sharing on the app, so only the workspace owner can access it. Level `"authenticated"` shares the app with all authenticated users. Level `"public"` shares it with any user, including unauthenticated users. Permitted application sharing levels can be configured site-wide via a flag on `coder server` (Enterprise only).
7373
- `subdomain` (Boolean) Determines whether the app will be accessed via it's own subdomain or whether it will be accessed via a path on Coder. If wildcards have not been setup by the administrator then apps with `subdomain` set to `true` will not be accessible. Defaults to `false`.
74+
- `tooltip` (String) String with markdown support to display over the app icon in a workspace dashboard.
7475
- `url` (String) An external url if `external=true` or a URL to be proxied to from inside the workspace. This should be of the form `http://localhost:PORT[/SUBPATH]`. Either `command` or `url` may be specified, but not both.
7576

7677
### Read-Only

examples/resources/coder_app/resource.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ resource "coder_app" "code-server" {
1616
display_name = "VS Code"
1717
icon = "${data.coder_workspace.me.access_url}/icon/code.svg"
1818
url = "http://localhost:13337"
19+
tooltip = "You need to [Install Coder Desktop](https://coder.com/docs/user-guides/desktop#install-coder-desktop) to use this button."
1920
share = "owner"
2021
subdomain = false
2122
open_in = "window"

provider/app.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var (
2727
const (
2828
appDisplayNameMaxLength = 64 // database column limit
2929
appGroupNameMaxLength = 64
30+
appTooltipMaxLength = 512
3031
)
3132

3233
func appResource() *schema.Resource {
@@ -273,6 +274,23 @@ func appResource() *schema.Resource {
273274
return diag.Errorf(`invalid "coder_app" open_in value, must be one of "tab", "slim-window": %q`, valStr)
274275
},
275276
},
277+
"tooltip": {
278+
Type: schema.TypeString,
279+
Description: "String with markdown support to display over the app icon in a workspace dashboard.",
280+
ForceNew: true,
281+
Optional: true,
282+
ValidateDiagFunc: func(val any, c cty.Path) diag.Diagnostics {
283+
valStr, ok := val.(string)
284+
if !ok {
285+
return diag.Errorf("expected string, got %T", val)
286+
}
287+
288+
if len(valStr) > appTooltipMaxLength {
289+
return diag.Errorf("tooltip is too long (max %d characters)", appTooltipMaxLength)
290+
}
291+
return nil
292+
},
293+
},
276294
},
277295
}
278296
}

provider/app_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func TestApp(t *testing.T) {
4444
order = 4
4545
hidden = false
4646
open_in = "slim-window"
47+
tooltip = "You need to [Install Coder Desktop](https://coder.com/docs/user-guides/desktop#install-coder-desktop) to use this button."
4748
}
4849
`,
4950
Check: func(state *terraform.State) error {
@@ -68,6 +69,7 @@ func TestApp(t *testing.T) {
6869
"order",
6970
"hidden",
7071
"open_in",
72+
"tooltip",
7173
} {
7274
value := resource.Primary.Attributes[key]
7375
t.Logf("%q = %q", key, value)
@@ -535,4 +537,76 @@ func TestApp(t *testing.T) {
535537
})
536538
}
537539
})
540+
541+
t.Run("Tooltip", func(t *testing.T) {
542+
t.Parallel()
543+
544+
cases := []struct {
545+
name string
546+
tooltip string
547+
expectError *regexp.Regexp
548+
}{
549+
{
550+
name: "Empty",
551+
tooltip: "",
552+
},
553+
{
554+
name: "ValidTooltip",
555+
tooltip: "You need to [Install Coder Desktop](https://coder.com/docs/user-guides/desktop" +
556+
"#install-coder-desktop) to use this button.",
557+
},
558+
{
559+
name: "TooltipMaxLength", // < 512 characters
560+
tooltip: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut" +
561+
"labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco" +
562+
"laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in" +
563+
"voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat" +
564+
"non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Sed ut" +
565+
"perspiciatis unde omnis iste natus error sit voluptatem accusant",
566+
},
567+
{
568+
name: "TooltipTooLong", // > 512 characters
569+
tooltip: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor " +
570+
"incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud " +
571+
"exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor " +
572+
"in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint " +
573+
"occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. " +
574+
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque.",
575+
expectError: regexp.MustCompile("tooltip is too long"),
576+
},
577+
}
578+
579+
for _, c := range cases {
580+
c := c
581+
582+
t.Run(c.name, func(t *testing.T) {
583+
t.Parallel()
584+
585+
config := fmt.Sprintf(`
586+
provider "coder" {}
587+
resource "coder_agent" "dev" {
588+
os = "linux"
589+
arch = "amd64"
590+
}
591+
resource "coder_app" "code-server" {
592+
agent_id = coder_agent.dev.id
593+
slug = "code-server"
594+
display_name = "Testing"
595+
url = "http://localhost:13337"
596+
open_in = "slim-window"
597+
tooltip = "%s"
598+
}
599+
`, c.tooltip)
600+
601+
resource.Test(t, resource.TestCase{
602+
ProviderFactories: coderFactory(),
603+
IsUnitTest: true,
604+
Steps: []resource.TestStep{{
605+
Config: config,
606+
ExpectError: c.expectError,
607+
}},
608+
})
609+
})
610+
}
611+
})
538612
}

0 commit comments

Comments
 (0)