Skip to content

Commit

Permalink
Fix AccountSetup view ignoring all identity providers per section b…
Browse files Browse the repository at this point in the history
…ut one (#81)

# Fix `AccountSetup` view ignoring all identity providers per section
but one

## ♻️ Current situation & Problem
Currently, the AccountSetupView groups the AccountService's
`IdentityProvider`s by their section, to determine their order.
As a result of this being implemented using a dictionary, with the
providers as values, only the last provider per section is kept.
This means that, if an AccountService specifies multiple
IdentityProviders for a section, most of them (all but one) will not be
shown to the user.

## ⚙️ Release Notes 
- Fixed `@IdentityProvider`s sometimes not being included in the
`AccountSetup` view.

## 📚 Documentation
n/a

## ✅ Testing
n/a

## 📝 Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).
  • Loading branch information
lukaskollmer authored Jan 20, 2025
1 parent de42790 commit 41aed07
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions Sources/SpeziAccount/AccountSetup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// SPDX-License-Identifier: MIT
//

import OrderedCollections
import SpeziViews
import SwiftUI

Expand Down Expand Up @@ -139,20 +138,21 @@ public struct AccountSetup<Header: View, Continue: View>: View {
EmptyServicesWarning()
} else {
VStack {
let categorized = account.accountSetupComponents.reduce(into: OrderedDictionary()) { partialResult, component in
let components = account.accountSetupComponents.reduce(
into: [AccountSetupSection: [any AnyAccountSetupComponent]]()
) { dict, component in
guard component.configuration.isEnabled else {
return
}
partialResult[component.configuration.section] = component
dict[component.configuration.section, default: []].append(component)
}

ForEach(categorized.keys.sorted(), id: \.self) { placement in
if let component = categorized[placement] {
component.anyView

if categorized.keys.last != placement {
ServicesDivider()
}
.sorted { $0.key < $1.key }
.flatMap(\.value)

ForEach(0..<components.endIndex, id: \.self) { idx in
components[idx].anyView
if idx < components.endIndex - 1 {
ServicesDivider()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/SpeziAccountTests/SnapshotTesting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ final class SnapshotTesting: XCTestCase {
assertSnapshot(of: view3, as: .image(layout: .device(config: .iPhone13Pro)), named: "iphone-view3")
assertSnapshot(of: view4, as: .image(layout: .device(config: .iPhone13Pro)), named: "iphone-view4")
assertSnapshot(of: view5, as: .image(layout: .device(config: .iPhone13Pro)), named: "iphone-view5")

assertSnapshot(of: view0Signup, as: .image(layout: .device(config: .iPhone13Pro)), named: "iphone-view0-signup")
assertSnapshot(of: view1Signup, as: .image(layout: .device(config: .iPhone13Pro)), named: "iphone-view1-signup")
assertSnapshot(of: view2Signup, as: .image(layout: .device(config: .iPhone13Pro)), named: "iphone-view2-signup")
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 41aed07

Please sign in to comment.