Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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}")`
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var stringValue: String {
switch self {
case .library:
return "library"
case .executable:
return "executable"
case .plugin:
return "plugin"
}
}

We can remove this in favour of using rawValue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, I suppose you added a conformation to String on the ProductType?

init?(_ productType: App.ProductType) {
switch productType {
case .executable:
Expand Down
4 changes: 3 additions & 1 deletion Sources/App/Views/PackageController/GetRoute.Model+ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.data(named: "type", value: product.type.stringValue),
.data(named: "type", value: product.type.rawValue),

.value(product.name),
.label(product.name)
)
Expand Down