-
Notifications
You must be signed in to change notification settings - Fork 121
[Shipping Labels] Show options to move selected items #15418
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
6 commits
Select commit
Hold shift + click to select a range
56eb2bb
New view for move items to specific shipments.
selanthiraiyan 1590f96
Fire callback upon selecting all items.
selanthiraiyan 05e2468
Show instructions as a subview instead of notice.
selanthiraiyan fba7d7d
Show move to notice upon selecting items.
selanthiraiyan e067f4a
Add helper to get selected shipment IDs.
selanthiraiyan e0f41f4
Merge branch 'trunk' into task/15306-select-item
selanthiraiyan 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
128 changes: 128 additions & 0 deletions
128
...WooShipping Create Shipping Labels/WooShipping Split Shipments/MoveToShipmentNotice.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,128 @@ | ||
| import SwiftUI | ||
|
|
||
| struct MoveToShipmentNoticeViewModel { | ||
| enum MoveTo { | ||
| case existingShipment(index: Int) | ||
| case newShipment | ||
| } | ||
|
|
||
| let selectedItemsCount: Int | ||
| let existingShipmentsCount: Int | ||
| let currentShipmentIndex: Int? | ||
| let actionHandler: ((MoveTo) -> Void) | ||
| } | ||
|
|
||
| struct MoveToShipmentNotice: View { | ||
| let viewModel: MoveToShipmentNoticeViewModel | ||
|
|
||
| var body: some View { | ||
| HStack { | ||
| Text(String.localizedStringWithFormat(Localization.message, viewModel.selectedItemsCount)) | ||
| .font(.subheadline) | ||
| .fontWeight(.semibold) | ||
| .foregroundColor(Color(uiColor: .text)) | ||
|
|
||
| Spacer() | ||
|
|
||
| if viewModel.existingShipmentsCount == 0 { | ||
| moveToNewShipment | ||
| } else { | ||
| menuWithExistingShipments | ||
| } | ||
| } | ||
| .padding(.horizontal, Layout.horizontalPadding) | ||
| .padding(.vertical, Layout.verticalPadding) | ||
| .background(.thickMaterial) | ||
| .cornerRadius(Layout.cornerRadius) | ||
| .shadow(color: .black.opacity(Layout.shadowColorOpacity), | ||
| radius: Layout.cornerRadius, | ||
| y: Layout.shadowYOffset) | ||
| } | ||
| } | ||
|
|
||
| private extension MoveToShipmentNotice { | ||
| var moveToNewShipment: some View { | ||
| Button { | ||
| viewModel.actionHandler(.newShipment) | ||
| } label: { | ||
| HStack(spacing: Layout.horizontalSpacing) { | ||
| Text(Localization.moveToNewShipment) | ||
| .font(.subheadline) | ||
| .fontWeight(.semibold) | ||
| } | ||
| .foregroundColor(Color(.accent)) | ||
| } | ||
| } | ||
|
|
||
| var menuWithExistingShipments: some View { | ||
| Menu { | ||
| ForEach(0..<viewModel.existingShipmentsCount, id: \.self) { index in | ||
| if viewModel.currentShipmentIndex != index { | ||
| Button(String.localizedStringWithFormat(Localization.shipment, index + 1), action: { | ||
| viewModel.actionHandler(.existingShipment(index: index)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| Button(Localization.newShipment, action: { | ||
| viewModel.actionHandler(.newShipment) | ||
| }) | ||
| } label: { | ||
| HStack(spacing: Layout.horizontalSpacing) { | ||
| Text(Localization.moveTo) | ||
| .font(.subheadline) | ||
| .fontWeight(.semibold) | ||
|
|
||
| Image(systemName: "chevron.up.chevron.down") | ||
| } | ||
| .foregroundColor(Color(.accent)) | ||
| } | ||
| .environment(\.menuOrder, .fixed) | ||
| } | ||
| } | ||
|
|
||
| private extension MoveToShipmentNotice { | ||
| enum Layout { | ||
| static let horizontalPadding: CGFloat = 16 | ||
| static let verticalPadding: CGFloat = 22 | ||
| static let horizontalSpacing: CGFloat = 8 | ||
| static let cornerRadius: CGFloat = 8 | ||
| static let shadowYOffset: CGFloat = 2 | ||
| static let shadowColorOpacity: CGFloat = 0.16 | ||
| } | ||
|
|
||
| enum Localization { | ||
| static let message = NSLocalizedString( | ||
| "wooShippingSplitShipments.MoveToShipmentNotice.title", | ||
| value: "%1$d selected", | ||
| comment: "The number of selected items in split shipments flow. %1$d is the number of selected items. Reads like: 2 selected" | ||
| ) | ||
| static let shipment = NSLocalizedString( | ||
| "wooShippingSplitShipments.MoveToShipmentNotice.shipment", | ||
| value: "Shipment %1$d", | ||
| comment: "Label used in the button to select the shipment in split shipments flow. %1$d is the shipment number. Reads like: Shipment 1" | ||
| ) | ||
| static let moveTo = NSLocalizedString( | ||
| "wooShippingSplitShipments.MoveToShipmentNotice.moveTo", | ||
| value: "Move to", | ||
| comment: "Button to move selected items to a shipment in split shipments flow" | ||
| ) | ||
| static let moveToNewShipment = NSLocalizedString( | ||
| "wooShippingSplitShipments.MoveToShipmentNotice.moveToNewShipment", | ||
| value: "Move to new shipment", | ||
| comment: "Button to move selected items to a new shipment in split shipments flow" | ||
| ) | ||
| static let newShipment = NSLocalizedString( | ||
| "wooShippingSplitShipments.MoveToShipmentNotice.newShipment", | ||
| value: "New shipment", | ||
| comment: "Title of the button to move selected items to a new shipment in split shipments flow" | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| #Preview { | ||
| MoveToShipmentNotice(viewModel: MoveToShipmentNoticeViewModel(selectedItemsCount: 4, | ||
| existingShipmentsCount: 3, | ||
| currentShipmentIndex: 1, | ||
| actionHandler: { _ in })) | ||
| } | ||
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 |
|---|---|---|
|
|
@@ -8,23 +8,28 @@ struct WooShippingSplitShipmentsDetailView: View { | |
|
|
||
| var body: some View { | ||
| NavigationView { | ||
| ScrollView { | ||
| VStack(alignment: .leading, spacing: Layout.contentPadding) { | ||
| AdaptiveStack(horizontalAlignment: .leading) { | ||
| Text(viewModel.itemsCountLabel) | ||
| .headlineStyle() | ||
| Spacer() | ||
| Text(viewModel.itemsDetailLabel) | ||
| .foregroundStyle(Color(.textSubtle)) | ||
| } | ||
| ZStack(alignment: .bottom) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| ScrollView { | ||
| VStack(alignment: .leading, spacing: Layout.contentPadding) { | ||
| AdaptiveStack(horizontalAlignment: .leading) { | ||
| Text(viewModel.itemsCountLabel) | ||
| .headlineStyle() | ||
| Spacer() | ||
| Text(viewModel.itemsDetailLabel) | ||
| .foregroundStyle(Color(.textSubtle)) | ||
| } | ||
|
|
||
| VStack(spacing: Layout.verticalSpacing) { | ||
| ForEach(viewModel.shipmentCardViewModels) { item in | ||
| CollapsibleShipmentCard(viewModel: item) | ||
| VStack(spacing: Layout.verticalSpacing) { | ||
| ForEach(viewModel.shipmentCardViewModels) { item in | ||
| CollapsibleShipmentCard(viewModel: item) | ||
| } | ||
| } | ||
| } | ||
| .padding(Layout.contentPadding) | ||
| } | ||
| .padding(Layout.contentPadding) | ||
|
|
||
| noticeStack | ||
| .padding(Layout.contentPadding) | ||
| } | ||
| .navigationBarTitleDisplayMode(.inline) | ||
| .navigationTitle(Localization.title) | ||
|
|
@@ -41,20 +46,73 @@ struct WooShippingSplitShipmentsDetailView: View { | |
| } | ||
| } | ||
| } | ||
| .notice($viewModel.instructionsNotice, autoDismiss: false) | ||
| .onAppear { | ||
| viewModel.onAppear() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private extension WooShippingSplitShipmentsDetailView { | ||
| var noticeStack: some View { | ||
| VStack(spacing: Layout.contentPadding) { | ||
| if let message = viewModel.instructions { | ||
| InstructionsSnackbar(message: message) { | ||
| viewModel.dismissInstructions() | ||
| } | ||
| } | ||
|
|
||
| if let moveTo = viewModel.moveToNoticeViewModel { | ||
| MoveToShipmentNotice(viewModel: moveTo) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private struct InstructionsSnackbar: View { | ||
| let message: String | ||
| let actionHandler: () -> Void | ||
|
|
||
| var body: some View { | ||
| HStack(alignment: .top, spacing: Layout.hSpacing) { | ||
| BoldableTextView(message) | ||
| .foregroundStyle(Color(.textInverted)) | ||
|
|
||
| Spacer() | ||
|
|
||
| Button { | ||
| actionHandler() | ||
| } label: { | ||
| Image(systemName: "xmark") | ||
| .foregroundStyle(Color(.withColorStudio(.gray))) | ||
| } | ||
| } | ||
| .padding(WooShippingSplitShipmentsDetailView.Layout.contentPadding) | ||
| .background { | ||
| RoundedRectangle(cornerRadius: WooShippingSplitShipmentsDetailView.Layout.cornerRadius) | ||
| .fill(Color(.text)) | ||
| .shadow(color: Color(.text).opacity(Layout.shadowColorOpacity), | ||
| radius: WooShippingSplitShipmentsDetailView.Layout.shadowRadius, | ||
| y: WooShippingSplitShipmentsDetailView.Layout.shadowYOffset) | ||
| } | ||
| } | ||
|
|
||
| private enum Layout { | ||
| static let hSpacing: CGFloat = 8 | ||
| static let shadowColorOpacity: CGFloat = 0.16 | ||
| } | ||
| } | ||
|
|
||
| fileprivate extension WooShippingSplitShipmentsDetailView { | ||
| enum Layout { | ||
| static let contentPadding: CGFloat = 16 | ||
| static let borderCornerRadius: CGFloat = 8 | ||
| static let shadowRadius: CGFloat = 8 | ||
| static let shadowYOffset: CGFloat = 2 | ||
| static let borderWidth: CGFloat = 0.5 | ||
| static let verticalSpacing: CGFloat = 8 | ||
| static let cornerRadius: CGFloat = 8 | ||
| } | ||
|
|
||
| enum Localization { | ||
| static let title = NSLocalizedString( | ||
| "wooShippingSplitShipmentsDetailView.title", | ||
|
|
||
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
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
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.
This should be an adaptive stack instead to ensure the contents are readable when the font size is really large on a narrow device.