wagtail-deprecated / wagtail-react-streamfield

Powerful field for inserting multiple blocks with nesting. (NO LONGER MAINTAINED - See Wagtail 2.13 Release Notes)
https://wagtail.github.io/react-streamfield/public/
BSD 3-Clause "New" or "Revised" License
74 stars 23 forks source link

Better ways to control SIMPLE vs COLLAPSIBLE #31

Closed unexceptable closed 5 years ago

unexceptable commented 5 years ago

The current approach to controlling SIMPLE vs COLLAPSIBLE is tedious as described here: https://github.com/noripyt/wagtail-react-streamfield/issues/13#issuecomment-443483114

In fact it kind of reduces the usefulness of this streamfield if you have to define every block like this to do so. I have over 20 block types (and I'm sure others have more), and some of the ones I use are stock from Wagtail (the Tableblock). The developer experience with this method sucks because I'd have to redefine each. :disappointed:

It would have made far more sense to make COLLAPSIBLE the default, but with all of the blocks open so it effectively starts like the SIMPLE layout. You then have the per block ability to define if you want to default closed, or never be able to close (SIMPLE). You then also allow a StreamField level definition/override which makes all blocks start open or closed, or forces them into either COLLAPSIBLE or SIMPLE.

I don't entirely even see the usefulness of SIMPLE when COLLAPSIBLE but defaulting to open (and the above ways to control that) is effectively SIMPLE but with more control. We should leave SIMPLE for those that really want it, but Wagtail is all about better UX first, and COLLAPSIBLE is better UX.

The entirely collapsible nature of wagtail-condensedinlinepanel was what made it so useful, and I was so happy to see that here and in the early versions of this. I'm sad I missed the discussion around this if there was one, because this 180 to what was the design before 1.0.0 is a bit sad. :disappointed:

In response to #28 and #13

cloudratha commented 5 years ago

It's quite easy to create your own CollapsedStructBlock and base your Blocks off that.

You can get more creative, I have something like this:

class CollapsedStructBlock(StructBlock):
    def get_layout(self):
        return self.COLLAPSIBLE

    def get_definition(self):
        definition = super().get_definition()
        definition["label"] = " ".join(
            re.sub(
                "([A-Z][a-z]+)",
                r" \1",
                re.sub(
                    "([A-Z]+)", r" \1", self.__class__.__name__.replace("Block", "")
                ),
            ).split()
        )
        return definition
BertrandBordage commented 5 years ago

This issue is no longer relevant. We have removed the COLLAPSIBLE vs SIMPLE layouts. There is just a single layout now that cannot be configured: a mix between these two layouts, with everything open by default and collapsible blocks.