-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestListView.swift
More file actions
204 lines (182 loc) · 7.31 KB
/
Copy pathTestListView.swift
File metadata and controls
204 lines (182 loc) · 7.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
//
// TesterListView.swift
// IOSAccessAssessment
//
// Created by Himanshu on 3/3/26.
//
import SwiftUI
import TipKit
import PointNMapShared
enum TestListViewError: Error, LocalizedError {
case workspacesUnavailable
case workspaceIdUnavailable
var errorDescription: String? {
switch self {
case .workspacesUnavailable:
return "Workspaces are unavailable. Please ensure you have access to the workspace datasets."
case .workspaceIdUnavailable:
return "Workspace ID is unavailable. Please ensure you are in a valid workspace."
}
}
}
struct TestEnvironmentListView: View {
let selectedClasses: [AccessibilityFeatureClass]
let selectedAttributesByClass: [AccessibilityFeatureClass: Set<AccessibilityFeatureAttribute>]
@Environment(\.dismiss) var dismiss
@StateObject private var datasetLister: DatasetLister = DatasetLister()
@State private var selectedEnvironment: APIEnvironment?
var body: some View {
VStack {
HStack {
Text("Please select an environment dataset:")
.font(.subheadline)
.padding(.bottom, 5)
}
if datasetLister.environmentDirectories.count > 0 {
List {
ForEach(datasetLister.environmentDirectories, id: \.self) { environmentDir in
Button {
selectEnvironment(environmentDir: environmentDir)
} label: {
Text(environmentDir.url.lastPathComponent)
.foregroundColor(.primary)
.cornerRadius(8)
}
}
}
} else {
Text("No environment datasets found.")
Spacer()
}
}
.navigationBarTitle("Test: Environment Selection", displayMode: .inline)
.onAppear {
do {
try datasetLister.configure()
} catch {
print("Error fetching environment datasets: \(error)")
}
}
.navigationDestination(item: $selectedEnvironment) { environmentDir in
TestWorkspaceListView(
selectedClasses: selectedClasses, selectedAttributesByClass: selectedAttributesByClass,
datasetLister: datasetLister
)
}
}
func selectEnvironment(environmentDir: EnvironmentDirectory) {
do {
try datasetLister.selectEnvironment(environmentDirectory: environmentDir)
self.selectedEnvironment = environmentDir.apiEnvironment
} catch {
print("Error selecting environment: \(error)")
}
}
}
/**
TestWorkspaceListView displays the possible workspace datasets whose inputs can be used to simulate the mapping.
*/
struct TestWorkspaceListView: View {
let selectedClasses: [AccessibilityFeatureClass]
let selectedAttributesByClass: [AccessibilityFeatureClass: Set<AccessibilityFeatureAttribute>]
@ObservedObject var datasetLister: DatasetLister
@Environment(\.dismiss) var dismiss
@State private var selectedWorkspace: WorkspaceDirectory?
// let datasetLister: DatasetLister = DatasetLister()
var body: some View {
VStack {
HStack {
Text("Please select a workspace dataset:")
.font(.subheadline)
.padding(.bottom, 5)
}
if datasetLister.workspaceDirectories.count > 0 {
List {
ForEach(datasetLister.workspaceDirectories, id: \.self) { workspaceDir in
Button {
selectWorkspace(workspaceDir: workspaceDir)
} label: {
Text(workspaceDir.url.lastPathComponent)
.foregroundColor(.primary)
.cornerRadius(8)
}
}
}
} else {
Text("No workspace datasets found.")
Spacer()
}
}
.navigationBarTitle("Test: Workspace Selection", displayMode: .inline)
.navigationDestination(item: $selectedWorkspace) { workspaceDir in
TestChangesetListView(
selectedClasses: selectedClasses, selectedAttributesByClass: selectedAttributesByClass,
datasetLister: datasetLister
)
}
}
func selectWorkspace(workspaceDir: WorkspaceDirectory) {
do {
try datasetLister.selectWorkspace(workspaceDirectory: workspaceDir)
self.selectedWorkspace = workspaceDir
} catch {
print("Error selecting workspace: \(error)")
}
}
}
/**
TestChangesetListView displays the possible changesets of a workspace whose inputs can be used to simulate the mapping.
*/
struct TestChangesetListView: View {
let selectedClasses: [AccessibilityFeatureClass]
let selectedAttributesByClass: [AccessibilityFeatureClass: Set<AccessibilityFeatureAttribute>]
@ObservedObject var datasetLister: DatasetLister
@Environment(\.dismiss) var dismiss
@State private var selectedChangeset: ChangesetDirectory?
var body: some View {
VStack {
HStack {
Text("Please select a changeset dataset:")
.font(.subheadline)
.padding(.bottom, 5)
}
if datasetLister.changesetDirectories.count > 0 {
List {
ForEach(datasetLister.changesetDirectories, id: \.self) { changesetDir in
Button {
selectChangeset(changesetDir: changesetDir)
} label: {
Text(changesetDir.url.lastPathComponent)
.foregroundColor(.primary)
.cornerRadius(8)
}
}
}
} else {
Text("No changeset datasets found for the selected workspace.")
Spacer()
}
}
.navigationBarTitle("Test: Changeset Selection", displayMode: .inline)
.navigationDestination(item: $selectedChangeset) { changesetDir in
changesetDestination(changesetDir: changesetDir)
}
}
func selectChangeset(changesetDir: ChangesetDirectory) {
self.selectedChangeset = changesetDir
datasetLister.selectChangeset(changesetDirectory: changesetDir)
}
@ViewBuilder
private func changesetDestination(changesetDir: ChangesetDirectory) -> some View {
if let selectedEnvironment = datasetLister.selectedEnvironment,
let selectedWorkspace = datasetLister.selectedWorkspace {
TestCameraView(
selectedClasses: selectedClasses, selectedAttributesByClass: selectedAttributesByClass,
selectedEnvironment: selectedEnvironment.apiEnvironment,
workspaceId: selectedWorkspace.workspaceId, changesetId: changesetDir.changesetId
)
} else {
Text("Missing environment or workspace selection.")
}
}
}