From b73cdc2e83b066cf37c59769550bbf8c320405ee Mon Sep 17 00:00:00 2001 From: Ucanbarlic Date: Sat, 31 Aug 2024 18:01:06 +0200 Subject: [PATCH 1/4] Show correct code snippet for products type of plugin --- .../controllers/use_this_package_panel_controller.js | 3 ++- .../API/API+PackageController+GetRoute+Model.swift | 11 +++++++++++ .../Views/PackageController/GetRoute.Model+ext.swift | 4 +++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/FrontEnd/scripts/controllers/use_this_package_panel_controller.js b/FrontEnd/scripts/controllers/use_this_package_panel_controller.js index b6acb98e2..4c878ae58 100644 --- a/FrontEnd/scripts/controllers/use_this_package_panel_controller.js +++ b/FrontEnd/scripts/controllers/use_this_package_panel_controller.js @@ -26,6 +26,7 @@ export class UseThisPackagePanelController extends Controller { const optionElement = selectElement.options[selectElement.selectedIndex] const packageName = optionElement.dataset.package const productName = optionElement.dataset.product - this.snippetTarget.value = `.product(name: "${productName}", package: "${packageName}")` + const prefix = type == "plugin" ? ".plugin" : ".product" + this.snippetTarget.value = `${prefix}(name: "${productName}", package: "${packageName}")` } } diff --git a/Sources/App/Controllers/API/API+PackageController+GetRoute+Model.swift b/Sources/App/Controllers/API/API+PackageController+GetRoute+Model.swift index 7d1f3db11..903194a2d 100644 --- a/Sources/App/Controllers/API/API+PackageController+GetRoute+Model.swift +++ b/Sources/App/Controllers/API/API+PackageController+GetRoute+Model.swift @@ -235,6 +235,17 @@ extension API.PackageController.GetRoute.Model { case executable case plugin + var stringValue: String { + switch self { + case .library: + return "library" + case .executable: + return "executable" + case .plugin: + return "plugin" + } + } + init?(_ productType: App.ProductType) { switch productType { case .executable: diff --git a/Sources/App/Views/PackageController/GetRoute.Model+ext.swift b/Sources/App/Views/PackageController/GetRoute.Model+ext.swift index 0d5603801..7c177b6c7 100644 --- a/Sources/App/Views/PackageController/GetRoute.Model+ext.swift +++ b/Sources/App/Views/PackageController/GetRoute.Model+ext.swift @@ -415,10 +415,12 @@ extension API.PackageController.GetRoute.Model { .data(named: "action", value: "input->use-this-package-panel#updateProductSnippet"), .attribute(named: "name", value: "products"), .id("products"), - .forEach(products, { product in + // Filter out products of type `executable` until we add support for them. + .forEach(products.filter({ $0.type != .executable }), { product in .option( .data(named: "package", value: package), .data(named: "product", value: product.name), + .data(named: "type", value: product.type.stringValue), .value(product.name), .label(product.name) ) From acfa65c2f5da0726c21508532dd95fa10a19d7c7 Mon Sep 17 00:00:00 2001 From: Ucanbarlic Date: Sun, 1 Sep 2024 18:05:49 +0200 Subject: [PATCH 2/4] Use rawValue instead of stringValue --- .../use_this_package_panel_controller.js | 1 + .../API/API+PackageController+GetRoute+Model.swift | 13 +------------ .../PackageController/GetRoute.Model+ext.swift | 2 +- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/FrontEnd/scripts/controllers/use_this_package_panel_controller.js b/FrontEnd/scripts/controllers/use_this_package_panel_controller.js index 4c878ae58..6ade1bf3c 100644 --- a/FrontEnd/scripts/controllers/use_this_package_panel_controller.js +++ b/FrontEnd/scripts/controllers/use_this_package_panel_controller.js @@ -26,6 +26,7 @@ export class UseThisPackagePanelController extends Controller { const optionElement = selectElement.options[selectElement.selectedIndex] const packageName = optionElement.dataset.package const productName = optionElement.dataset.product + const type = optionElement.dataset.type const prefix = type == "plugin" ? ".plugin" : ".product" this.snippetTarget.value = `${prefix}(name: "${productName}", package: "${packageName}")` } diff --git a/Sources/App/Controllers/API/API+PackageController+GetRoute+Model.swift b/Sources/App/Controllers/API/API+PackageController+GetRoute+Model.swift index 903194a2d..211e5fb17 100644 --- a/Sources/App/Controllers/API/API+PackageController+GetRoute+Model.swift +++ b/Sources/App/Controllers/API/API+PackageController+GetRoute+Model.swift @@ -230,22 +230,11 @@ extension API.PackageController.GetRoute.Model { self.type = type } - enum ProductType: Codable, Equatable { + enum ProductType: String, Codable, Equatable { case library case executable case plugin - var stringValue: String { - switch self { - case .library: - return "library" - case .executable: - return "executable" - case .plugin: - return "plugin" - } - } - init?(_ productType: App.ProductType) { switch productType { case .executable: diff --git a/Sources/App/Views/PackageController/GetRoute.Model+ext.swift b/Sources/App/Views/PackageController/GetRoute.Model+ext.swift index 7c177b6c7..d4e77d1ef 100644 --- a/Sources/App/Views/PackageController/GetRoute.Model+ext.swift +++ b/Sources/App/Views/PackageController/GetRoute.Model+ext.swift @@ -420,7 +420,7 @@ extension API.PackageController.GetRoute.Model { .option( .data(named: "package", value: package), .data(named: "product", value: product.name), - .data(named: "type", value: product.type.stringValue), + .data(named: "type", value: product.type.rawValue), .value(product.name), .label(product.name) ) From f06f19e730f6f4425a1dcccab7344fa447517eac Mon Sep 17 00:00:00 2001 From: "Sven A. Schmidt" Date: Mon, 2 Sep 2024 08:03:04 +0200 Subject: [PATCH 3/4] Update snapshots --- .../WebpageSnapshotTests/test_PackageShowView.1.html | 7 +++---- ...t_PackageShowView_app_store_incompatible_license.1.html | 7 +++---- .../test_PackageShowView_binary_targets.1.html | 7 +++---- ...st_PackageShowView_canonicalURL_noImageSnapshots.1.html | 7 +++---- .../test_PackageShowView_emoji_summary.1.html | 7 +++---- .../test_PackageShowView_few_keywords.1.html | 7 +++---- .../test_PackageShowView_many_keywords.1.html | 7 +++---- .../test_PackageShowView_no_authors_activity.1.html | 7 +++---- .../test_PackageShowView_no_builds.1.html | 7 +++---- .../test_PackageShowView_no_license.1.html | 7 +++---- .../test_PackageShowView_open_source_license.1.html | 7 +++---- .../test_PackageShowView_other_license.1.html | 7 +++---- .../test_PackageShowView_single_row_tables.1.html | 7 +++---- .../test_PackageShowView_withPackageFundingLinks.1.html | 7 +++---- .../test_PackageShowView_with_documentation_link.1.html | 7 +++---- 15 files changed, 45 insertions(+), 60 deletions(-) diff --git a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView.1.html b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView.1.html index a4bc91a67..acd51447a 100644 --- a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView.1.html +++ b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView.1.html @@ -134,10 +134,9 @@

When working with a Swift Package Manager manifest:

diff --git a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_app_store_incompatible_license.1.html b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_app_store_incompatible_license.1.html index 03d9478ad..7160ef77c 100644 --- a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_app_store_incompatible_license.1.html +++ b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_app_store_incompatible_license.1.html @@ -134,10 +134,9 @@

When working with a Swift Package Manager manifest:

diff --git a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_binary_targets.1.html b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_binary_targets.1.html index 9e40b2f62..bf4b8964b 100644 --- a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_binary_targets.1.html +++ b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_binary_targets.1.html @@ -134,10 +134,9 @@

When working with a Swift Package Manager manifest:

diff --git a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_canonicalURL_noImageSnapshots.1.html b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_canonicalURL_noImageSnapshots.1.html index 9b21f42d1..fef533860 100644 --- a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_canonicalURL_noImageSnapshots.1.html +++ b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_canonicalURL_noImageSnapshots.1.html @@ -134,10 +134,9 @@

When working with a Swift Package Manager manifest:

diff --git a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_emoji_summary.1.html b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_emoji_summary.1.html index bd301b418..1c398fb5f 100644 --- a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_emoji_summary.1.html +++ b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_emoji_summary.1.html @@ -134,10 +134,9 @@

When working with a Swift Package Manager manifest:

diff --git a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_few_keywords.1.html b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_few_keywords.1.html index 5568ea300..08bb9f1a0 100644 --- a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_few_keywords.1.html +++ b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_few_keywords.1.html @@ -134,10 +134,9 @@

When working with a Swift Package Manager manifest:

diff --git a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_many_keywords.1.html b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_many_keywords.1.html index 3000136a4..0e92661e9 100644 --- a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_many_keywords.1.html +++ b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_many_keywords.1.html @@ -134,10 +134,9 @@

When working with a Swift Package Manager manifest:

diff --git a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_no_authors_activity.1.html b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_no_authors_activity.1.html index 8cc10270e..9cd6319d2 100644 --- a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_no_authors_activity.1.html +++ b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_no_authors_activity.1.html @@ -134,10 +134,9 @@

When working with a Swift Package Manager manifest:

diff --git a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_no_builds.1.html b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_no_builds.1.html index 4a701f7d7..60ba39935 100644 --- a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_no_builds.1.html +++ b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_no_builds.1.html @@ -134,10 +134,9 @@

When working with a Swift Package Manager manifest:

diff --git a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_no_license.1.html b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_no_license.1.html index d4d037ebc..479835fa2 100644 --- a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_no_license.1.html +++ b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_no_license.1.html @@ -134,10 +134,9 @@

When working with a Swift Package Manager manifest:

diff --git a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_open_source_license.1.html b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_open_source_license.1.html index 9ebe6b129..fea7b2e54 100644 --- a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_open_source_license.1.html +++ b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_open_source_license.1.html @@ -134,10 +134,9 @@

When working with a Swift Package Manager manifest:

diff --git a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_other_license.1.html b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_other_license.1.html index 019243243..36a831414 100644 --- a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_other_license.1.html +++ b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_other_license.1.html @@ -134,10 +134,9 @@

When working with a Swift Package Manager manifest:

diff --git a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_single_row_tables.1.html b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_single_row_tables.1.html index 676039fb0..f307df133 100644 --- a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_single_row_tables.1.html +++ b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_single_row_tables.1.html @@ -134,10 +134,9 @@

When working with a Swift Package Manager manifest:

diff --git a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_withPackageFundingLinks.1.html b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_withPackageFundingLinks.1.html index 19873f1fd..343194699 100644 --- a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_withPackageFundingLinks.1.html +++ b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_withPackageFundingLinks.1.html @@ -134,10 +134,9 @@

When working with a Swift Package Manager manifest:

diff --git a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_with_documentation_link.1.html b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_with_documentation_link.1.html index 8683b542f..72f51add3 100644 --- a/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_with_documentation_link.1.html +++ b/Tests/AppTests/__Snapshots__/WebpageSnapshotTests/test_PackageShowView_with_documentation_link.1.html @@ -134,10 +134,9 @@

When working with a Swift Package Manager manifest:

From a63a26c256912d993b2fa5782667289229b3eff7 Mon Sep 17 00:00:00 2001 From: "Sven A. Schmidt" Date: Mon, 2 Sep 2024 08:22:49 +0200 Subject: [PATCH 4/4] Fix JS linting issue --- .../scripts/controllers/use_this_package_panel_controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FrontEnd/scripts/controllers/use_this_package_panel_controller.js b/FrontEnd/scripts/controllers/use_this_package_panel_controller.js index 6ade1bf3c..ca677e3bc 100644 --- a/FrontEnd/scripts/controllers/use_this_package_panel_controller.js +++ b/FrontEnd/scripts/controllers/use_this_package_panel_controller.js @@ -27,7 +27,7 @@ export class UseThisPackagePanelController extends Controller { const packageName = optionElement.dataset.package const productName = optionElement.dataset.product const type = optionElement.dataset.type - const prefix = type == "plugin" ? ".plugin" : ".product" + const prefix = type == 'plugin' ? '.plugin' : '.product' this.snippetTarget.value = `${prefix}(name: "${productName}", package: "${packageName}")` } }