Skip to content

Commit 11f6546

Browse files
[PM-20538] Display toast on flight recorder log deletion (#1618)
1 parent d500dbc commit 11f6546

File tree

6 files changed

+31
-0
lines changed

6 files changed

+31
-0
lines changed

BitwardenShared/UI/Platform/Application/Support/Localizations/en.lproj/Localizable.strings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,3 +1192,5 @@
11921192
"NewTextSend" = "New text Send";
11931193
"EditFileSend" = "Edit file Send";
11941194
"EditTextSend" = "Edit text Send";
1195+
"LogDeleted" = "Log deleted";
1196+
"AllLogsDeleted" = "All logs deleted";

BitwardenShared/UI/Platform/Settings/Settings/About/FlightRecorderLogs/FlightRecorderLogsAction.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@ enum FlightRecorderLogsAction: Equatable {
1717

1818
/// Share all flight recorder logs.
1919
case shareAll
20+
21+
/// The toast was shown or hidden.
22+
case toastShown(Toast?)
2023
}

BitwardenShared/UI/Platform/Settings/Settings/About/FlightRecorderLogs/FlightRecorderLogsProcessor.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ final class FlightRecorderLogsProcessor: StateProcessor<
6363
case .shareAll:
6464
let urls = state.logs.map(\.url)
6565
coordinator.navigate(to: .shareURLs(urls))
66+
case let .toastShown(newValue):
67+
state.toast = newValue
6668
}
6769
}
6870

@@ -85,6 +87,7 @@ final class FlightRecorderLogsProcessor: StateProcessor<
8587
confirmDeletion(isBulkDeletion: true) {
8688
do {
8789
try await self.services.flightRecorder.deleteInactiveLogs()
90+
self.state.toast = Toast(title: Localizations.allLogsDeleted)
8891
await self.loadData()
8992
} catch {
9093
self.services.errorReporter.log(error: error)
@@ -99,6 +102,7 @@ final class FlightRecorderLogsProcessor: StateProcessor<
99102
confirmDeletion(isBulkDeletion: false) {
100103
do {
101104
try await self.services.flightRecorder.deleteLog(log)
105+
self.state.toast = Toast(title: Localizations.logDeleted)
102106
await self.loadData()
103107
} catch {
104108
self.services.errorReporter.log(error: error)

BitwardenShared/UI/Platform/Settings/Settings/About/FlightRecorderLogs/FlightRecorderLogsProcessorTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class FlightRecorderLogsProcessorTests: BitwardenTestCase {
8585

8686
XCTAssertEqual(flightRecorder.deleteLogLogs, [log])
8787
XCTAssertTrue(flightRecorder.fetchLogsCalled)
88+
XCTAssertEqual(subject.state.toast, Toast(title: Localizations.logDeleted))
8889
}
8990

9091
/// `receive(_:)` with `.delete` logs an error and shows an error alert if an error occurs.
@@ -101,6 +102,7 @@ class FlightRecorderLogsProcessorTests: BitwardenTestCase {
101102

102103
XCTAssertEqual(coordinator.errorAlertsShown as? [BitwardenTestError], [.example])
103104
XCTAssertEqual(errorReporter.errors as? [BitwardenTestError], [.example])
105+
XCTAssertNil(subject.state.toast)
104106
}
105107

106108
/// `receive(_:)` with `.deleteAll` shows a confirmation alert and then deletes the inactive logs.
@@ -118,6 +120,7 @@ class FlightRecorderLogsProcessorTests: BitwardenTestCase {
118120

119121
XCTAssertTrue(flightRecorder.deleteInactiveLogsCalled)
120122
XCTAssertTrue(flightRecorder.fetchLogsCalled)
123+
XCTAssertEqual(subject.state.toast, Toast(title: Localizations.allLogsDeleted))
121124
}
122125

123126
/// `receive(_:)` with `.deleteAll` logs an error and shows an error alert if an error occurs.
@@ -134,6 +137,7 @@ class FlightRecorderLogsProcessorTests: BitwardenTestCase {
134137

135138
XCTAssertEqual(coordinator.errorAlertsShown as? [BitwardenTestError], [.example])
136139
XCTAssertEqual(errorReporter.errors as? [BitwardenTestError], [.example])
140+
XCTAssertNil(subject.state.toast)
137141
}
138142

139143
/// `receive(_:)` with `.dismiss` dismisses the view.
@@ -169,4 +173,15 @@ class FlightRecorderLogsProcessorTests: BitwardenTestCase {
169173
])
170174
)
171175
}
176+
177+
/// `receive(_:)` with `.toastShown` updates the state's toast value.
178+
@MainActor
179+
func test_receive_toastShown() {
180+
let toast = Toast(title: "toast!")
181+
subject.receive(.toastShown(toast))
182+
XCTAssertEqual(subject.state.toast, toast)
183+
184+
subject.receive(.toastShown(nil))
185+
XCTAssertNil(subject.state.toast)
186+
}
172187
}

BitwardenShared/UI/Platform/Settings/Settings/About/FlightRecorderLogs/FlightRecorderLogsState.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ struct FlightRecorderLogsState: Equatable {
88
/// The list of flight recorder logs on the device.
99
var logs = [FlightRecorderLogMetadata]()
1010

11+
/// A toast message to show in the view.
12+
var toast: Toast?
13+
1114
// MARK: Computed Properties
1215

1316
/// Whether the delete all option is enabled.

BitwardenShared/UI/Platform/Settings/Settings/About/FlightRecorderLogs/FlightRecorderLogsView.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ struct FlightRecorderLogsView: View {
2121
content
2222
.navigationBar(title: Localizations.recordedLogs, titleDisplayMode: .inline)
2323
.task { await store.perform(.loadData) }
24+
.toast(store.binding(
25+
get: \.toast,
26+
send: FlightRecorderLogsAction.toastShown
27+
))
2428
.toolbar {
2529
closeToolbarItem {
2630
store.send(.dismiss)

0 commit comments

Comments
 (0)