ixc / wagtail-instance-selector

A widget for Wagtail's admin that allows you to create and select related items
MIT License
54 stars 17 forks source link

Nested InstanceSelectorPanel loses selectability #20

Open danthedeckie opened 3 years ago

danthedeckie commented 3 years ago

If I have open a Instance Selector Panel pop-up, and then create a new object in there to select, it's fine.

But if while it's open, I open an Instance Selector Panel defined on that object - so being 2 levels deep, kind of thing, then when I save the original object, it shows a regular admin listing view - so with 'edit' and 'delete' buttons, and no 'select' button.

Pseudo code:

class Category(ClusterableModel):
    name = models.CharField(max_length=100)

class Product(ClusterableModel):
    name = models.CharField(max_length=100)

    panels = [
        FieldPanel('name'),
        InlinePanel('categories')
    ]

class ProductCategory(ClusterableModel):
    category = ParentalKey(Category, on_delete=models.CASCADE, related_name="products")
    product = ParentalKey(Produce, on_delete=models.CASCADE, related_name="categories")

    panels = [
         InstanceSelectorPanel('category'),
         InstanceSelectorPanel('product'),
    ]

class ShopPage(Page):
    ...
    common_panels = [
        InlinePanel("shop_products"),
    ]

class ShopProduct(ClusterableModel):
    product = ParentalKey(Product, on_delete=models.CASCADE)
    parent_page = ParentalKey(ShopPage, on_delete=models.CASCADE, related_name="shop_products")
    panels = [
         InstanceSelectorPanel('product'),
         PageSelectorPanel('parent_page'),
    ]

I've solved currently by switching all of the sub-selectors into a more basic ModelChooserPanel that we're using in other places in the project.

markfinger commented 3 years ago

Thanks for the report.

This is the JS code that injects the "Select" button: https://github.com/ixc/wagtail-instance-selector/blob/7a62164d620b0fe5798d71e00012877c2ae93174/instance_selector/static/instance_selector/instance_selector_embed.js#L34-L47.

I'm unlikely to have the time to look into this myself, so PRs are welcome.

markfinger commented 3 years ago

Actually, could be this block of JS instead: https://github.com/ixc/wagtail-instance-selector/blob/7a62164d620b0fe5798d71e00012877c2ae93174/instance_selector/static/instance_selector/instance_selector_embed.js#L55-L82