diff --git a/App Store Tests/ValidationTests.swift b/App Store Tests/ValidationTests.swift index e624a53..e296f3c 100644 --- a/App Store Tests/ValidationTests.swift +++ b/App Store Tests/ValidationTests.swift @@ -10,6 +10,33 @@ import XCTest @testable import Shipyard final class ValidationTests: XCTestCase { + func testAppInfoLocaleSelectionChoosesValidLocaleAfterDeletion() { + XCTAssertEqual( + ShipyardAppInfoView.localeAfterDeleting( + "ca", + availableLocales: ["ca", "en-US"], + primaryLocale: "en-US"), + "en-US") + XCTAssertEqual( + ShipyardAppInfoView.localeAfterDeleting( + "ca", + availableLocales: ["ca", "de-DE", "fr-FR"], + primaryLocale: "en-US"), + "de-DE") + XCTAssertEqual( + ShipyardAppInfoView.localeAfterDeleting( + "ca", + availableLocales: ["ca"], + primaryLocale: "en-US"), + "en-US") + XCTAssertEqual( + ShipyardAppInfoView.localeAfterDeleting( + "ca", + availableLocales: ["ca"], + primaryLocale: nil), + BetaLocalizationLocales.defaultLocale) + } + @MainActor func testBuildsQueryLoadsTenBuildsForSelectedVersion() { let query = DetailViewModel.buildsQueryParams( diff --git a/App Store.xcodeproj/project.pbxproj b/App Store.xcodeproj/project.pbxproj index 89ed816..8edfe91 100644 --- a/App Store.xcodeproj/project.pbxproj +++ b/App Store.xcodeproj/project.pbxproj @@ -1026,7 +1026,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 5; + CURRENT_PROJECT_VERSION = 6; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_ASSET_PATHS = "\"App Store/Preview Content\""; DEVELOPMENT_TEAM = SQ2XJ67YNR; @@ -1064,7 +1064,7 @@ CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; - CURRENT_PROJECT_VERSION = 5; + CURRENT_PROJECT_VERSION = 6; DEAD_CODE_STRIPPING = YES; DEVELOPMENT_ASSET_PATHS = "\"App Store/Preview Content\""; DEVELOPMENT_TEAM = SQ2XJ67YNR; diff --git a/Shipyard/ShipyardAppInfoView.swift b/Shipyard/ShipyardAppInfoView.swift index a35ec26..17e52e8 100644 --- a/Shipyard/ShipyardAppInfoView.swift +++ b/Shipyard/ShipyardAppInfoView.swift @@ -889,15 +889,38 @@ struct ShipyardAppInfoView: View { private func removeLocale() async { guard let record = versionLocalization else { return } - if let message = await detailVM.deleteVersionLocalization(id: record.id, locale: locale) { + let removedLocale = locale + if let message = await detailVM.deleteVersionLocalization(id: record.id, locale: removedLocale) { saveError = message toastCenter.show("Couldn't remove localization", detail: message, variant: .error) return } - toastCenter.show("Localization removed", detail: BetaLocalizationLocales.displayName(for: locale), variant: .success) - for field in Field.allCases { drafts.removeValue(forKey: field.rawValue) } - draftSignature = "" - syncDrafts() + if locale == removedLocale { + switchToLocale(Self.localeAfterDeleting( + removedLocale, + availableLocales: locales, + primaryLocale: app.primaryLocale)) + } + toastCenter.show( + "Localization removed", + detail: BetaLocalizationLocales.displayName(for: removedLocale), + variant: .success) + } + + /// Keeps the picker on a real record after deleting its current locale. + /// Prefer Apple's primary locale, then the first remaining locale. When + /// the version has no localizations left, keep the primary/default code + /// selected so the empty editor still has a useful locale context. + static func localeAfterDeleting( + _ removedLocale: String, + availableLocales: [String], + primaryLocale: String? + ) -> String { + let remaining = availableLocales.filter { $0 != removedLocale } + if let primaryLocale, remaining.contains(primaryLocale) { + return primaryLocale + } + return remaining.first ?? primaryLocale ?? BetaLocalizationLocales.defaultLocale } private func save() async {