From 99b6393396e378b12406ed926a64530a38d506a4 Mon Sep 17 00:00:00 2001 From: Nayan Bhut Date: Thu, 15 Oct 2026 17:19:44 +0530 Subject: [PATCH 1/3] Fix locale selection after deletion --- App Store Tests/ValidationTests.swift | 15 +++++++++++++ Shipyard/ShipyardAppInfoView.swift | 32 ++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/App Store Tests/ValidationTests.swift b/App Store Tests/ValidationTests.swift index e624a53..463b3ff 100644 --- a/App Store Tests/ValidationTests.swift +++ b/App Store Tests/ValidationTests.swift @@ -10,6 +10,21 @@ import XCTest @testable import Shipyard final class ValidationTests: XCTestCase { + func testAppInfoLocaleSelectionMovesToPrimaryAfterDeletion() { + XCTAssertEqual( + ShipyardAppInfoView.localeAfterDeleting( + "ca", + availableLocales: ["en-US"], + primaryLocale: "en-US"), + "en-US") + XCTAssertEqual( + ShipyardAppInfoView.localeAfterDeleting( + "ca", + availableLocales: ["de-DE", "fr-FR"], + primaryLocale: "en-US"), + "de-DE") + } + @MainActor func testBuildsQueryLoadsTenBuildsForSelectedVersion() { let query = DetailViewModel.buildsQueryParams( diff --git a/Shipyard/ShipyardAppInfoView.swift b/Shipyard/ShipyardAppInfoView.swift index a35ec26..d48988d 100644 --- a/Shipyard/ShipyardAppInfoView.swift +++ b/Shipyard/ShipyardAppInfoView.swift @@ -889,15 +889,37 @@ 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() + 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 } + return primaryLocale.flatMap { primary in + remaining.first(where: { $0 == primary }) + } ?? remaining.first + ?? primaryLocale + ?? BetaLocalizationLocales.defaultLocale } private func save() async { From 24fe42a4e7b3319c2d66e1e8e581c9cda99272a1 Mon Sep 17 00:00:00 2001 From: Nayan Bhut Date: Thu, 15 Oct 2026 17:23:50 +0530 Subject: [PATCH 2/3] Handle locale deletion races --- App Store Tests/ValidationTests.swift | 18 +++++++++++++++--- Shipyard/ShipyardAppInfoView.swift | 19 ++++++++++--------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/App Store Tests/ValidationTests.swift b/App Store Tests/ValidationTests.swift index 463b3ff..e296f3c 100644 --- a/App Store Tests/ValidationTests.swift +++ b/App Store Tests/ValidationTests.swift @@ -10,19 +10,31 @@ import XCTest @testable import Shipyard final class ValidationTests: XCTestCase { - func testAppInfoLocaleSelectionMovesToPrimaryAfterDeletion() { + func testAppInfoLocaleSelectionChoosesValidLocaleAfterDeletion() { XCTAssertEqual( ShipyardAppInfoView.localeAfterDeleting( "ca", - availableLocales: ["en-US"], + availableLocales: ["ca", "en-US"], primaryLocale: "en-US"), "en-US") XCTAssertEqual( ShipyardAppInfoView.localeAfterDeleting( "ca", - availableLocales: ["de-DE", "fr-FR"], + 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 diff --git a/Shipyard/ShipyardAppInfoView.swift b/Shipyard/ShipyardAppInfoView.swift index d48988d..17e52e8 100644 --- a/Shipyard/ShipyardAppInfoView.swift +++ b/Shipyard/ShipyardAppInfoView.swift @@ -895,10 +895,12 @@ struct ShipyardAppInfoView: View { toastCenter.show("Couldn't remove localization", detail: message, variant: .error) return } - switchToLocale(Self.localeAfterDeleting( - removedLocale, - availableLocales: locales, - primaryLocale: app.primaryLocale)) + if locale == removedLocale { + switchToLocale(Self.localeAfterDeleting( + removedLocale, + availableLocales: locales, + primaryLocale: app.primaryLocale)) + } toastCenter.show( "Localization removed", detail: BetaLocalizationLocales.displayName(for: removedLocale), @@ -915,11 +917,10 @@ struct ShipyardAppInfoView: View { primaryLocale: String? ) -> String { let remaining = availableLocales.filter { $0 != removedLocale } - return primaryLocale.flatMap { primary in - remaining.first(where: { $0 == primary }) - } ?? remaining.first - ?? primaryLocale - ?? BetaLocalizationLocales.defaultLocale + if let primaryLocale, remaining.contains(primaryLocale) { + return primaryLocale + } + return remaining.first ?? primaryLocale ?? BetaLocalizationLocales.defaultLocale } private func save() async { From 6ac2afd08c1df9007b915a01000005a70221ef46 Mon Sep 17 00:00:00 2001 From: Nayan Bhut Date: Thu, 15 Oct 2026 17:48:35 +0530 Subject: [PATCH 3/3] Prepare Shipyard 1.0 build 6 release --- App Store.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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;