Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e2d352c

Browse files
committedDec 5, 2024·
review
1 parent d7b1356 commit e2d352c

File tree

5 files changed

+37
-21
lines changed

5 files changed

+37
-21
lines changed
 

‎Coder Desktop/Coder Desktop/Preview Content/PreviewVPN.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ import SwiftUI
22

33
class PreviewVPN: Coder_Desktop.VPNService {
44
@Published var state: Coder_Desktop.VPNServiceState = .disabled
5-
@Published var agents: [Coder_Desktop.AgentRow] = [
6-
AgentRow(id: UUID(), name: "dogfood2", status: .red, copyableDNS: "asdf.coder", workspaceName: "dogfood2"),
7-
AgentRow(id: UUID(), name: "testing-a-very-long-name", status: .green, copyableDNS: "asdf.coder",
5+
@Published var agents: [Coder_Desktop.Agent] = [
6+
Agent(id: UUID(), name: "dogfood2", status: .error, copyableDNS: "asdf.coder", workspaceName: "dogfood2"),
7+
Agent(id: UUID(), name: "testing-a-very-long-name", status: .okay, copyableDNS: "asdf.coder",
88
workspaceName: "testing-a-very-long-name"
99
),
10-
AgentRow(id: UUID(), name: "opensrc", status: .yellow, copyableDNS: "asdf.coder", workspaceName: "opensrc"),
11-
AgentRow(id: UUID(), name: "gvisor", status: .gray, copyableDNS: "asdf.coder", workspaceName: "gvisor"),
12-
AgentRow(id: UUID(), name: "example", status: .gray, copyableDNS: "asdf.coder", workspaceName: "example"),
13-
AgentRow(id: UUID(), name: "dogfood2", status: .red, copyableDNS: "asdf.coder", workspaceName: "dogfood2"),
14-
AgentRow(id: UUID(), name: "testing-a-very-long-name", status: .green, copyableDNS: "asdf.coder",
10+
Agent(id: UUID(), name: "opensrc", status: .warn, copyableDNS: "asdf.coder", workspaceName: "opensrc"),
11+
Agent(id: UUID(), name: "gvisor", status: .off, copyableDNS: "asdf.coder", workspaceName: "gvisor"),
12+
Agent(id: UUID(), name: "example", status: .off, copyableDNS: "asdf.coder", workspaceName: "example"),
13+
Agent(id: UUID(), name: "dogfood2", status: .error, copyableDNS: "asdf.coder", workspaceName: "dogfood2"),
14+
Agent(id: UUID(), name: "testing-a-very-long-name", status: .okay, copyableDNS: "asdf.coder",
1515
workspaceName: "testing-a-very-long-name"
1616
),
17-
AgentRow(id: UUID(), name: "opensrc", status: .yellow, copyableDNS: "asdf.coder", workspaceName: "opensrc"),
18-
AgentRow(id: UUID(), name: "gvisor", status: .gray, copyableDNS: "asdf.coder", workspaceName: "gvisor"),
19-
AgentRow(id: UUID(), name: "example", status: .gray, copyableDNS: "asdf.coder", workspaceName: "example"),
17+
Agent(id: UUID(), name: "opensrc", status: .warn, copyableDNS: "asdf.coder", workspaceName: "opensrc"),
18+
Agent(id: UUID(), name: "gvisor", status: .off, copyableDNS: "asdf.coder", workspaceName: "gvisor"),
19+
Agent(id: UUID(), name: "example", status: .off, copyableDNS: "asdf.coder", workspaceName: "example"),
2020
]
2121
let shouldFail: Bool
2222

‎Coder Desktop/Coder Desktop/VPNService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import SwiftUI
22

33
protocol VPNService: ObservableObject {
44
var state: VPNServiceState { get }
5-
var agents: [AgentRow] { get }
5+
var agents: [Agent] { get }
66
func start() async
77
// Stop must be idempotent
88
func stop() async

‎Coder Desktop/Coder Desktop/Views/AgentRow.swift renamed to ‎Coder Desktop/Coder Desktop/Views/Agent.swift

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
11
import SwiftUI
22

3-
struct AgentRow: Identifiable, Equatable {
3+
struct Agent: Identifiable, Equatable {
44
let id: UUID
55
let name: String
6-
let status: Color
6+
let status: AgentStatus
77
let copyableDNS: String
88
let workspaceName: String
99
}
1010

11+
enum AgentStatus: Equatable {
12+
case okay
13+
case warn
14+
case error
15+
case off
16+
17+
public var color: Color {
18+
switch self {
19+
case .okay: return .green
20+
case .warn: return .yellow
21+
case .error: return .red
22+
case .off: return .gray
23+
}
24+
}
25+
}
26+
1127
struct AgentRowView: View {
12-
let workspace: AgentRow
28+
let workspace: Agent
1329
let baseAccessURL: URL
1430
@State private var nameIsSelected: Bool = false
1531
@State private var copyIsSelected: Bool = false
@@ -34,10 +50,10 @@ struct AgentRowView: View {
3450
HStack(spacing: Theme.Size.trayPadding) {
3551
ZStack {
3652
Circle()
37-
.fill(workspace.status.opacity(0.4))
53+
.fill(workspace.status.color.opacity(0.4))
3854
.frame(width: 12, height: 12)
3955
Circle()
40-
.fill(workspace.status.opacity(1.0))
56+
.fill(workspace.status.color.opacity(1.0))
4157
.frame(width: 7, height: 7)
4258
}
4359
Text(fmtWsName).lineLimit(1).truncationMode(.tail)

‎Coder Desktop/Coder DesktopTests/AgentsTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import ViewInspector
33
import XCTest
44

55
final class AgentsTests: XCTestCase {
6-
private func createMockAgents(count: Int) -> [AgentRow] {
6+
private func createMockAgents(count: Int) -> [Agent] {
77
return (1...count).map {
8-
AgentRow(
8+
Agent(
99
id: UUID(),
1010
name: "a\($0)",
11-
status: .green,
11+
status: .okay,
1212
copyableDNS: "a\($0).example.com",
1313
workspaceName: "w\($0)"
1414
)

‎Coder Desktop/Coder DesktopTests/Util.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import SwiftUI
44
class MockVPNService: VPNService, ObservableObject {
55
@Published var state: Coder_Desktop.VPNServiceState = .disabled
66
@Published var baseAccessURL: URL = URL(string: "https://dev.coder.com")!
7-
@Published var agents: [Coder_Desktop.AgentRow] = []
7+
@Published var agents: [Coder_Desktop.Agent] = []
88
var onStart: (() async -> Void)?
99
var onStop: (() async -> Void)?
1010

0 commit comments

Comments
 (0)
Please sign in to comment.