generated from bitwarden/template
-
Notifications
You must be signed in to change notification settings - Fork 53
BIT-348, BIT-351, & BIT-1121: Add, Save, View, & Edit Card Type Cipher #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2d2f70b
BIT-348: Add / Edit Card Item UI
eliot-livefront 69f9d74
BIT-351: Save & View Card Item
eliot-livefront 9195a56
BIT-1121: View Item Copy Values
eliot-livefront d21ddb0
Merge branch 'main' into eliot/BIT-348-Add-Card-Type
eliot-livefront 6fdac2a
Merge branch 'main' into eliot/BIT-348-Add-Card-Type
eliot-livefront 54e7292
Merge branch 'main' into eliot/BIT-348-Add-Card-Type
eliot-livefront 7e834c0
Test Updates
eliot-livefront d216e34
Test Revisions
eliot-livefront 206ced1
Merge branch 'main' into eliot/BIT-348-Add-Card-Type
eliot-livefront adb13bb
Documentation Updates
eliot-livefront File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
BitwardenShared/UI/Vault/VaultItem/AddEditItem/AddEditCardItem/AddEditCardItemAction.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// MARK: AddEditCardItemAction | ||
|
||
/// An enum of actions for adding or editing a card Item in its add/edit state. | ||
/// | ||
enum AddEditCardItemAction: Equatable { | ||
/// The brand of the card changed. | ||
case brandChanged(DefaultableType<CardComponent.Brand>) | ||
|
||
/// The name of the card holder changed. | ||
case cardholderNameChanged(String) | ||
|
||
/// The number of the card changed. | ||
case cardNumberChanged(String) | ||
|
||
/// The security code of the card changed. | ||
case cardSecurityCodeChanged(String) | ||
|
||
/// The expiration month of the card changed. | ||
case expirationMonthChanged(DefaultableType<CardComponent.Month>) | ||
|
||
/// The expiration year of the card changed. | ||
case expirationYearChanged(String) | ||
|
||
/// Toggle for code visibility changed. | ||
case toggleCodeVisibilityChanged(Bool) | ||
|
||
/// Toggle for number visibility changed. | ||
case toggleNumberVisibilityChanged(Bool) | ||
} |
29 changes: 29 additions & 0 deletions
29
BitwardenShared/UI/Vault/VaultItem/AddEditItem/AddEditCardItem/AddEditCardItemState.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// MARK: AddEditCardItemState | ||
|
||
/// A protocol for a sendable type that models a Card Item in it's add/edit state. | ||
/// | ||
protocol AddEditCardItemState: Equatable, Sendable { | ||
/// The brand of the card. | ||
var brand: DefaultableType<CardComponent.Brand> { get set } | ||
|
||
/// The name of the card holder. | ||
var cardholderName: String { get set } | ||
|
||
/// The number of the card. | ||
var cardNumber: String { get set } | ||
|
||
/// The security code of the card. | ||
var cardSecurityCode: String { get set } | ||
|
||
/// The expiration month of the card. | ||
var expirationMonth: DefaultableType<CardComponent.Month> { get set } | ||
|
||
/// The expiration year of the card. | ||
var expirationYear: String { get set } | ||
|
||
/// The visibility of the security code. | ||
var isCodeVisible: Bool { get set } | ||
|
||
/// The visibility of the card number. | ||
var isNumberVisible: Bool { get set } | ||
} |
148 changes: 148 additions & 0 deletions
148
BitwardenShared/UI/Vault/VaultItem/AddEditItem/AddEditCardItem/AddEditCardItemView.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import SwiftUI | ||
|
||
// MARK: - AddEditCardItemView | ||
|
||
/// A view that allows the user to add or edit a card item for a vault. | ||
/// | ||
struct AddEditCardItemView: View { | ||
eliot-livefront marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// MARK: Properties | ||
|
||
/// The `Store` for this view. | ||
@ObservedObject var store: Store<any AddEditCardItemState, AddEditCardItemAction, AddEditItemEffect> | ||
|
||
var body: some View { | ||
LazyVStack(spacing: 16.0) { | ||
BitwardenTextField( | ||
title: Localizations.cardholderName, | ||
text: store.binding( | ||
get: \.cardholderName, | ||
send: AddEditCardItemAction.cardholderNameChanged | ||
) | ||
) | ||
|
||
BitwardenTextField( | ||
title: Localizations.number, | ||
text: store.binding( | ||
get: \.cardNumber, | ||
send: AddEditCardItemAction.cardNumberChanged | ||
), isPasswordVisible: store.binding( | ||
get: \.isNumberVisible, | ||
send: AddEditCardItemAction.toggleNumberVisibilityChanged | ||
) | ||
) | ||
.textFieldConfiguration(.password) | ||
|
||
BitwardenMenuField( | ||
title: Localizations.brand, | ||
options: DefaultableType<CardComponent.Brand>.allCases, | ||
selection: store.binding( | ||
get: \.brand, | ||
send: AddEditCardItemAction.brandChanged | ||
) | ||
) | ||
|
||
BitwardenMenuField( | ||
title: Localizations.expirationMonth, | ||
options: DefaultableType<CardComponent.Month>.allCases, | ||
selection: store.binding( | ||
get: \.expirationMonth, | ||
send: AddEditCardItemAction.expirationMonthChanged | ||
) | ||
) | ||
|
||
BitwardenTextField( | ||
title: Localizations.expirationYear, | ||
text: store.binding( | ||
get: \.expirationYear, | ||
send: AddEditCardItemAction.expirationYearChanged | ||
) | ||
) | ||
|
||
BitwardenTextField( | ||
title: Localizations.securityCode, | ||
text: store.binding( | ||
get: \.cardSecurityCode, | ||
send: AddEditCardItemAction.cardSecurityCodeChanged | ||
), isPasswordVisible: store.binding( | ||
get: \.isCodeVisible, | ||
send: AddEditCardItemAction.toggleCodeVisibilityChanged | ||
) | ||
) | ||
.textFieldConfiguration(.password) | ||
} | ||
} | ||
} | ||
|
||
#if DEBUG | ||
struct AddEditCardItemView_Previews: PreviewProvider { | ||
static var previews: some View { | ||
NavigationView { | ||
ScrollView { | ||
AddEditCardItemView( | ||
store: Store( | ||
processor: StateProcessor( | ||
state: CardItemState() as (any AddEditCardItemState) | ||
) | ||
) | ||
) | ||
.padding(16) | ||
} | ||
.background(Asset.Colors.backgroundSecondary.swiftUIColor) | ||
.navigationBar(title: "Empty Add Edit State", titleDisplayMode: .inline) | ||
} | ||
.previewDisplayName("Empty Add Edit State") | ||
|
||
NavigationView { | ||
ScrollView { | ||
AddEditCardItemView( | ||
store: Store( | ||
processor: StateProcessor( | ||
state: { | ||
var state = CardItemState() | ||
state.brand = .custom(.visa) | ||
state.cardNumber = "4400123456789" | ||
state.cardSecurityCode = "123" | ||
state.cardholderName = "Bitwarden User" | ||
state.expirationMonth = .custom(.aug) | ||
state.expirationYear = "1989" | ||
return state | ||
}() as (any AddEditCardItemState) | ||
) | ||
) | ||
) | ||
.padding(16) | ||
} | ||
.background(Asset.Colors.backgroundSecondary.swiftUIColor) | ||
.navigationBar(title: "Hidden Add Edit State", titleDisplayMode: .inline) | ||
} | ||
.previewDisplayName("Hidden Add Edit State") | ||
|
||
NavigationView { | ||
ScrollView { | ||
AddEditCardItemView( | ||
store: Store( | ||
processor: StateProcessor( | ||
state: { | ||
var state = CardItemState() | ||
state.brand = .custom(.visa) | ||
state.cardNumber = "4400123456789" | ||
state.cardSecurityCode = "123" | ||
state.cardholderName = "Bitwarden User" | ||
state.expirationMonth = .custom(.aug) | ||
state.expirationYear = "1989" | ||
state.isCodeVisible = true | ||
state.isNumberVisible = true | ||
return state | ||
}() as (any AddEditCardItemState) | ||
) | ||
) | ||
) | ||
.padding(16) | ||
} | ||
.background(Asset.Colors.backgroundSecondary.swiftUIColor) | ||
.navigationBar(title: "Visible Add Edit State", titleDisplayMode: .inline) | ||
} | ||
.previewDisplayName("Visible Add Edit State") | ||
} | ||
} | ||
#endif |
23 changes: 23 additions & 0 deletions
23
...ardenShared/UI/Vault/VaultItem/AddEditItem/AddEditCardItem/AddEditCardItemViewTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import SnapshotTesting | ||
import XCTest | ||
|
||
@testable import BitwardenShared | ||
|
||
class AddEditCardItemViewTests: BitwardenTestCase { | ||
// MARK: Snapshots | ||
|
||
/// Test preview snapshots of the `AddEditCardItemView`. | ||
/// | ||
func test_snapshot_addEditCardItemView() { | ||
for preview in AddEditCardItemView_Previews._allPreviews { | ||
assertSnapshots( | ||
matching: preview.content, | ||
as: [ | ||
.defaultPortrait, | ||
.defaultPortraitDark, | ||
.tallPortraitAX5(heightMultiple: 1.75), | ||
] | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π€ I'm curious the benefit we get from having this protocol and
ViewCardItemState
over usingCardItemState
directly?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My goal was to build in some separation from the State to the ViewState and remove the ability to mutate the struct in a view configuration. I build this pattern to match the one used for
CipherItemState
,AddEditItemState
, andViewVaultItemState