Skip to content

Commit 0d6f66b

Browse files
committed
fix some stuff
1 parent 34a32d5 commit 0d6f66b

File tree

9 files changed

+48
-25
lines changed

9 files changed

+48
-25
lines changed

coderd/database/models.go

Lines changed: 1 addition & 1 deletion
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: 12 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/sqlc.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ overrides:
2727
- column: "template_with_users.group_acl"
2828
go_type:
2929
type: "TemplateACL"
30+
- column: "workspace_agents.default_apps"
31+
go_type: "github.com/lib/pq.StringArray"
3032
rename:
3133
template: TemplateTable
3234
template_with_user: Template

coderd/provisionerdserver/provisionerdserver.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/coder/coder/v2/coderd/tracing"
3939
"github.com/coder/coder/v2/codersdk"
4040
"github.com/coder/coder/v2/provisioner"
41+
"github.com/coder/coder/v2/provisioner/terraform"
4142
"github.com/coder/coder/v2/provisionerd/proto"
4243
"github.com/coder/coder/v2/provisionersdk"
4344
sdkproto "github.com/coder/coder/v2/provisionersdk/proto"
@@ -1185,6 +1186,10 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
11851186
prAgent.StartupScriptBehavior = string(codersdk.WorkspaceAgentStartupScriptBehaviorNonBlocking)
11861187
}
11871188

1189+
if slices.Contains(prAgent.DefaultApps, terraform.AllDefaultApps) {
1190+
prAgent.DefaultApps = nil
1191+
}
1192+
11881193
agentID := uuid.New()
11891194
dbAgent, err := db.InsertWorkspaceAgent(ctx, database.InsertWorkspaceAgentParams{
11901195
ID: agentID,

coderd/workspaceagents.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"github.com/go-chi/chi/v5"
2525
"github.com/google/uuid"
26+
"github.com/lib/pq"
2627
"golang.org/x/exp/slices"
2728
"golang.org/x/mod/semver"
2829
"golang.org/x/sync/errgroup"
@@ -1402,7 +1403,11 @@ func convertWorkspaceAgent(derpMap *tailcfg.DERPMap, coordinator tailnet.Coordin
14021403
return workspaceAgent, nil
14031404
}
14041405

1405-
func convertDefaultApps(apps []string) []codersdk.DefaultApp {
1406+
func convertDefaultApps(apps pq.StringArray) []codersdk.DefaultApp {
1407+
if apps == nil {
1408+
return codersdk.DefaultApps
1409+
}
1410+
14061411
dapps := make([]codersdk.DefaultApp, 0, len(apps))
14071412
for _, app := range apps {
14081413
switch codersdk.DefaultApp(app) {

codersdk/workspaceagents.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ const (
143143
DefaultAppSSH DefaultApp = "ssh-helper"
144144
)
145145

146+
var DefaultApps = []DefaultApp{DefaultAppVSCodeDesktop, DefaultAppWebTerminal, DefaultAppPortForward, DefaultAppWebTerminal, DefaultAppSSH}
147+
146148
type WorkspaceAgent struct {
147149
ID uuid.UUID `json:"id" format:"uuid"`
148150
CreatedAt time.Time `json:"created_at" format:"date-time"`

provisioner/terraform/resources.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ import (
1818
"github.com/coder/coder/v2/provisionersdk/proto"
1919
)
2020

21+
// AllDefaultApps denotes an agent resource that does not explicitly
22+
// specify a value for the 'default_apps' field. Protobuf does not distinguish
23+
// between an empty array and a nil array necessitating this special token.
24+
const AllDefaultApps = "*"
25+
2126
type agentMetadata struct {
2227
Key string `mapstructure:"key"`
2328
DisplayName string `mapstructure:"display_name"`
@@ -183,7 +188,7 @@ func ConvertState(modules []*tfjson.StateModule, rawGraph string) (*State, error
183188
})
184189
}
185190

186-
var defaultApps = []string{"*"}
191+
defaultApps := []string{AllDefaultApps}
187192
if attrs.DefaultApps != nil {
188193
defaultApps = *attrs.DefaultApps
189194
}

site/src/components/Resources/AgentRow.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,6 @@ export const AgentRow: FC<AgentRowProps> = ({
173173
[logListDivRef],
174174
)
175175

176-
const containsDefaultApp = (
177-
agent: WorkspaceAgent,
178-
name: DefaultApp,
179-
): boolean => {
180-
if (agent.default_apps.length == 0) {
181-
return false
182-
}
183-
184-
return agent.default_apps.includes(name)
185-
}
186-
187176
return (
188177
<Stack
189178
key={agent.id}
@@ -233,13 +222,15 @@ export const AgentRow: FC<AgentRowProps> = ({
233222
<div className={styles.agentButtons}>
234223
{shouldDisplayApps && (
235224
<>
236-
{containsDefaultApp(agent, "vscode-desktop") &&
225+
{(agent.default_apps.includes("vscode-desktop") ||
226+
agent.default_apps.includes("vscode-insiders")) &&
237227
!hideVSCodeDesktopButton && (
238228
<VSCodeDesktopButton
239229
userName={workspace.owner_name}
240230
workspaceName={workspace.name}
241231
agentName={agent.name}
242232
folderPath={agent.expanded_directory}
233+
defaultApps={agent.default_apps}
243234
/>
244235
)}
245236
{agent.apps.map((app) => (

site/src/components/VSCodeDesktopButton/VSCodeDesktopButton.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import ButtonGroup from "@mui/material/ButtonGroup"
88
import { useLocalStorage } from "hooks"
99
import Menu from "@mui/material/Menu"
1010
import MenuItem from "@mui/material/MenuItem"
11+
import { DefaultApp } from "api/typesGenerated"
1112

1213
export interface VSCodeDesktopButtonProps {
1314
userName: string
1415
workspaceName: string
1516
agentName?: string
1617
folderPath?: string
18+
defaultApps: DefaultApp[]
1719
}
1820

1921
type VSCodeVariant = "vscode" | "vscode-insiders"
@@ -40,13 +42,16 @@ export const VSCodeDesktopButton: FC<
4042
setIsVariantMenuOpen(false)
4143
}
4244

43-
return (
45+
const includesVSCodeDestop = props.defaultApps.includes("vscode-desktop")
46+
const includesVSCodeInsiders = props.defaultApps.includes("vscode-insiders")
47+
48+
return includesVSCodeDestop && includesVSCodeInsiders ? (
4449
<div>
4550
<ButtonGroup
4651
ref={menuAnchorRef}
4752
variant="outlined"
4853
sx={{
49-
// Workaround to make the border transitions smmothly on button groups
54+
// Workaround to make the border transitions smoothly on button groups
5055
"& > button:hover + button": {
5156
borderLeft: "1px solid #FFF",
5257
},
@@ -105,6 +110,10 @@ export const VSCodeDesktopButton: FC<
105110
</MenuItem>
106111
</Menu>
107112
</div>
113+
) : includesVSCodeDestop ? (
114+
<VSCodeButton {...props} />
115+
) : (
116+
<VSCodeInsidersButton {...props} />
108117
)
109118
}
110119

0 commit comments

Comments
 (0)