Skip to content

Commit 8b67614

Browse files
committed
Display warning if there are more than 100 variations to edit
1 parent 7e4f77b commit 8b67614

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

WooCommerce/Classes/ViewRelated/Products/Variations/Bulk Update/BulkUpdateViewController.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ final class BulkUpdateViewController: UIViewController, GhostableViewController
7777
self.sections = sections
7878
self.removeGhostContent()
7979
self.tableView.reloadData()
80+
self.displayTooManyVariationsWarningIfNeeded()
8081
case .error:
8182
self.removeGhostContent()
8283
self.displaySyncingError()
@@ -147,6 +148,26 @@ final class BulkUpdateViewController: UIViewController, GhostableViewController
147148
let viewController = BulkUpdatePriceViewController(viewModel: bulkUpdatePriceSettingsViewModel)
148149
show(viewController, sender: nil)
149150
}
151+
152+
/// Displays a warning informing the user that only the first 100 variations would be editted.
153+
/// This is due to API limitations.
154+
///
155+
private func displayTooManyVariationsWarningIfNeeded() {
156+
guard viewModel.shouldShowVariationLimitWarning else {
157+
return
158+
}
159+
160+
let bannerViewModel = TopBannerViewModel(title: nil,
161+
infoText: Localization.tooManyVariations,
162+
icon: .noticeImage,
163+
iconTintColor: .warning,
164+
isExpanded: false,
165+
topButton: .none,
166+
type: .warning)
167+
let banner = TopBannerView(viewModel: bannerViewModel)
168+
tableView.tableHeaderView = banner
169+
tableView.updateHeaderHeight()
170+
}
150171
}
151172

152173
// MARK: - UITableViewDataSource Conformance
@@ -267,6 +288,8 @@ private extension BulkUpdateViewController {
267288
static let noticeRetryAction = NSLocalizedString("Retry", comment: "Retry Action")
268289
static let pricesUpdated = NSLocalizedString("Prices updated successfully.",
269290
comment: "Notice title when updating the price via the bulk variation screen")
291+
static let tooManyVariations = NSLocalizedString("Only the first 100 variations will be updated.",
292+
comment: "Warning when trying to bulk edit more than 100 variations")
270293
}
271294
}
272295

WooCommerce/Classes/ViewRelated/Products/Variations/Bulk Update/BulkUpdateViewModel.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ final class BulkUpdateViewModel {
2626
private let currencyFormatter: CurrencyFormatter
2727
private var onCancelButtonTapped: () -> Void
2828

29+
/// Returns `true` if there are more than 100 variations to edit.
30+
///
31+
let shouldShowVariationLimitWarning: Bool
32+
2933
/// Product Variations Controller.
3034
///
3135
private lazy var resultsController: ResultsController<StorageProductVariation> = {
@@ -48,6 +52,7 @@ final class BulkUpdateViewModel {
4852

4953
init(siteID: Int64,
5054
productID: Int64,
55+
variationCount: Int,
5156
onCancelButtonTapped: @escaping () -> Void,
5257
storageManager: StorageManagerType = ServiceLocator.storageManager,
5358
storesManager: StoresManager = ServiceLocator.stores,
@@ -59,6 +64,7 @@ final class BulkUpdateViewModel {
5964
self.storesManager = storesManager
6065
self.currencySettings = currencySettings
6166
self.currencyFormatter = CurrencyFormatter(currencySettings: currencySettings)
67+
self.shouldShowVariationLimitWarning = variationCount > Constants.numberOfObjects
6268
syncState = .notStarted
6369
}
6470

WooCommerce/Classes/ViewRelated/Products/Variations/ProductVariationsViewController.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,10 @@ private extension ProductVariationsViewController {
575575
actionSheet.addDefaultActionWithTitle(ActionSheetStrings.bulkUpdate) { [weak self] _ in
576576
guard let self = self else { return }
577577

578-
let viewModel = BulkUpdateViewModel(siteID: self.siteID, productID: self.productID, onCancelButtonTapped: { [weak self] in
578+
let viewModel = BulkUpdateViewModel(siteID: self.siteID,
579+
productID: self.productID,
580+
variationCount: self.product.variations.count,
581+
onCancelButtonTapped: { [weak self] in
579582
self?.dismiss(animated: true)
580583
})
581584
let navigationController = WooNavigationController(rootViewController: BulkUpdateViewController(viewModel: viewModel))

0 commit comments

Comments
 (0)