Skip to content

Commit

Permalink
Show respective Heart Health Segment on tap on dashboard (#93)
Browse files Browse the repository at this point in the history
# Show respective Heart Health Segment on tap on dashboard

## ♻️ Current situation & Problem
Previously, a user could not select any items in the "Recent Vitals"
section on the dashboard. We received feedback suggesting that users
would like to open the respective charts on tap of each of these cards
on the dashboard.

Currently, I moved the state into `NavigationManager`. I'm not entirely
sure whether this is the right spot, since it is somewhat separate from
that... I was also thinking about `VitalsManager`, but it doesn't really
do any transition logic, but only fetching data and preparing it for
display, so I'm open for discussing about this.


## ⚙️ Release Notes 
- Make recent vitals cards on dashboard tappable. Tapping a card leads
to the respective chart on the Heart Health Page.


## 📚 Documentation
*Please ensure that you properly document any additions in conformance
to [Spezi Documentation
Guide](https://github.com/StanfordSpezi/.github/blob/main/DOCUMENTATIONGUIDE.md).*
*You can use this section to describe your solution, but we encourage
contributors to document your reasoning and changes using in-line
documentation.*


## ✅ Testing
*Please ensure that the PR meets the testing requirements set by CodeCov
and that new functionality is appropriately tested.*
*This section describes important information about the tests and why
some elements might not be testable.*


### Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordBDHG/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordBDHG/.github/blob/main/CONTRIBUTING.md).
  • Loading branch information
pauljohanneskraft authored Oct 3, 2024
1 parent 4d18f94 commit 7ee5b83
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
13 changes: 13 additions & 0 deletions ENGAGEHF/Dashboard/Vitals/RecentVitalsSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import SwiftUI


struct RecentVitalsSection: View {
@Environment(NavigationManager.self) private var navigationManager
@Environment(VitalsManager.self) private var vitalsManager
@Environment(HealthMeasurements.self) private var measurements

Expand Down Expand Up @@ -69,17 +70,29 @@ struct RecentVitalsSection: View {
units: massUnits.unitString,
measurement: weightMeasurement
)
.onTapGesture {
navigationManager.selectedTab = .heart
navigationManager.heartHealthVitalSelection = .weight
}
VitalsCard(
type: "Heart Rate",
units: "BPM",
measurement: heartRateMeasurement
)
.onTapGesture {
navigationManager.selectedTab = .heart
navigationManager.heartHealthVitalSelection = .heartRate
}
}
VitalsCard(
type: "Blood Pressure",
units: "mmHg",
measurement: bloodPressureMeasurement
)
.onTapGesture {
navigationManager.selectedTab = .heart
navigationManager.heartHealthVitalSelection = .bloodPressure
}
}
},
header: {
Expand Down
10 changes: 6 additions & 4 deletions ENGAGEHF/HeartHealth/HeartHealth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@
import SpeziViews
import SwiftUI


@MainActor
struct HeartHealth: View {
@Binding var presentingAccount: Bool

@Environment(NavigationManager.self) private var navigationManager
@Environment(VitalsManager.self) private var vitalsManager
@State private var vitalSelection: GraphSelection = .symptoms


var body: some View {
@Bindable var navigationManager = navigationManager

NavigationStack {
VStack(alignment: .trailing) {
GraphPicker(selection: $vitalSelection)
GraphPicker(selection: $navigationManager.heartHealthVitalSelection)
.padding(.horizontal)
VitalsList(vitalSelection: vitalSelection)
VitalsList(vitalSelection: navigationManager.heartHealthVitalSelection)
}
.navigationTitle("Heart Health")
.toolbar {
Expand Down
4 changes: 4 additions & 0 deletions ENGAGEHF/Managers/NavigationManager/NavigationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class NavigationManager: Module, EnvironmentAccessible {
var heartHealthPath = NavigationPath()
var homePath = NavigationPath()

var heartHealthVitalSelection: GraphSelection = .symptoms
var selectedTab: HomeView.Tabs = .home
var questionnaireId: String?
var showHealthSummary = false
Expand Down Expand Up @@ -56,6 +57,9 @@ class NavigationManager: Module, EnvironmentAccessible {
heartHealthPath = NavigationPath()
homePath = NavigationPath()

heartHealthVitalSelection = .symptoms
questionnaireId = nil
showHealthSummary = false
selectedTab = .home
}
}
Expand Down
20 changes: 17 additions & 3 deletions ENGAGEHFUITests/Dashboard/RecentVitalsUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ final class RecentVitalsUITests: XCTestCase {
XCTAssert(app.staticTexts["Weight Quantity: \(expectedWeight)"].exists)
XCTAssert(app.staticTexts["Weight Unit: \(weightUnit)"].exists)
XCTAssert(app.staticTexts["Weight Date: 6/5/2024, 12:33 PM"].exists)

app.staticTexts["Weight Quantity: \(expectedWeight)"].tap()
XCTAssert(app.staticTexts["Body Weight"].waitForExistence(timeout: 2.0))
}

func testHeartRateAndBloodPressure() throws {
Expand Down Expand Up @@ -95,14 +98,25 @@ final class RecentVitalsUITests: XCTestCase {


// Measurement has been successfully saved, and should be represented in the dashboard
XCTAssert(app.staticTexts["Recent Vitals"].waitForExistence(timeout: 0.5))
XCTAssert(app.staticTexts["Recent Vitals"].waitForExistence(timeout: 2.0))

XCTAssert(app.staticTexts["Heart Rate Quantity: 62"].exists)
let heartRateQuantityText = "Heart Rate Quantity: 62"
XCTAssert(app.staticTexts[heartRateQuantityText].exists)
XCTAssert(app.staticTexts["Heart Rate Unit: BPM"].exists)
XCTAssert(app.staticTexts["Heart Rate Date: 6/5/2024, 12:33 PM"].exists)

XCTAssert(app.staticTexts["Blood Pressure Quantity: 103/64"].exists)
app.staticTexts[heartRateQuantityText].tap()
XCTAssert(app.staticTexts["Heart Rate"].waitForExistence(timeout: 2.0))

app.goTo(tab: "Home")
XCTAssert(app.staticTexts["Recent Vitals"].waitForExistence(timeout: 2.0))

let bloodPressureQuantityText = "Blood Pressure Quantity: 103/64"
XCTAssert(app.staticTexts[bloodPressureQuantityText].exists)
XCTAssert(app.staticTexts["Blood Pressure Unit: mmHg"].exists)
XCTAssert(app.staticTexts["Blood Pressure Date: 6/5/2024, 12:33 PM"].exists)

app.staticTexts[bloodPressureQuantityText].tap()
XCTAssert(app.staticTexts["Blood Pressure"].waitForExistence(timeout: 2.0))
}
}

0 comments on commit 7ee5b83

Please sign in to comment.