Skip to content

Commit b73cdc2

Browse files
Show correct code snippet for products type of plugin
1 parent 77c6988 commit b73cdc2

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

FrontEnd/scripts/controllers/use_this_package_panel_controller.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export class UseThisPackagePanelController extends Controller {
2626
const optionElement = selectElement.options[selectElement.selectedIndex]
2727
const packageName = optionElement.dataset.package
2828
const productName = optionElement.dataset.product
29-
this.snippetTarget.value = `.product(name: "${productName}", package: "${packageName}")`
29+
const prefix = type == "plugin" ? ".plugin" : ".product"
30+
this.snippetTarget.value = `${prefix}(name: "${productName}", package: "${packageName}")`
3031
}
3132
}

Sources/App/Controllers/API/API+PackageController+GetRoute+Model.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,17 @@ extension API.PackageController.GetRoute.Model {
235235
case executable
236236
case plugin
237237

238+
var stringValue: String {
239+
switch self {
240+
case .library:
241+
return "library"
242+
case .executable:
243+
return "executable"
244+
case .plugin:
245+
return "plugin"
246+
}
247+
}
248+
238249
init?(_ productType: App.ProductType) {
239250
switch productType {
240251
case .executable:

Sources/App/Views/PackageController/GetRoute.Model+ext.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,10 +415,12 @@ extension API.PackageController.GetRoute.Model {
415415
.data(named: "action", value: "input->use-this-package-panel#updateProductSnippet"),
416416
.attribute(named: "name", value: "products"),
417417
.id("products"),
418-
.forEach(products, { product in
418+
// Filter out products of type `executable` until we add support for them.
419+
.forEach(products.filter({ $0.type != .executable }), { product in
419420
.option(
420421
.data(named: "package", value: package),
421422
.data(named: "product", value: product.name),
423+
.data(named: "type", value: product.type.stringValue),
422424
.value(product.name),
423425
.label(product.name)
424426
)

0 commit comments

Comments
 (0)