SpinaCMS/Spina

"New page" button disappears when I make a custom page undeletable

benzado opened this issue · 6 comments

I've just integrated Spina into an existing Rails app (very easy, thank you!) and I'm setting up a theme; specifically I've been defining a lot of Custom Pages. Along the way I noticed that the "New page" button had disappeared!

After some trial and error, I realized it had something to do with whether the custom pages were deletable or not. After digging into the source code, I learned that:

  • NewPageButtonComponent only renders if there are any view templates available (that makes sense)
  • PagesController populates the list of templates by calling Spina::Current.theme.new_page_templates
  • Theme excludes view templates based on the result of is_custom_undeletable_page?

That method is defined like so:

    # Check if view_template is defined as a custom undeletable page
    def is_custom_undeletable_page?(view_template_name)
      @custom_pages.any? { |page| page[:view_template] == view_template_name && !page[:deletable] }
    end

So, apparently, if I define a custom page and mark the page undeletable, that also affects whatever view template the page is using, and prevents that view template from being used to create new pages.

As a new user, that is very surprising behavior! I checked the commit history to see if I could learn why the test was added, but it's present in the repo's initial commit, so it's a mystery to me.

The workaround is very simple (define separate view templates), so it's not going to prevent me from moving forward, but it is confusing and I think either the restriction ought to be removed or an explanation added to the documentation. I'm happy to submit a PR for either but I'll need some guidance first.

I agree, this is surprising behavior! I think the config should be more explicit so it's clear what the UI should do. Feel free to open a PR :)

Sorry, I don’t understand. Are you suggesting changing the behavior or documenting the existing behavior?

I'm suggesting changing the behavior.

It's weird that the available view templates are dependent on "custom pages that are undeletable". I'd like to make it easier to define which view templates are available for new/existing pages instead of inferring that from custom pages.

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

I've just come across this on a website too.

Expected behavior - All templates should be available as a new page, regardless if they are used for a custom page.

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.