Skip to content

RFC 66: EnumBlock#66

Closed
kaedroho wants to merge 4 commits into
mainfrom
enumblock
Closed

RFC 66: EnumBlock#66
kaedroho wants to merge 4 commits into
mainfrom
enumblock

Conversation

@kaedroho

@kaedroho kaedroho commented Dec 30, 2020

Copy link
Copy Markdown
Contributor

@kaedroho kaedroho changed the title EnumBlock RFC 66: EnumBlock Dec 30, 2020
@kaedroho kaedroho added the 1:New Newly-submitted RFC, awaiting initial triage by the core team label Dec 30, 2020
@kaedroho kaedroho mentioned this pull request Dec 30, 2020
@kaedroho

kaedroho commented Jan 6, 2021

Copy link
Copy Markdown
Contributor Author

We discussed this at the team meeting today. Nobody objected to the idea in principle, but @gasman thought the name would be confusing.

The name comes from Rust's enum type, but maybe that was a bad idea since enums are usually a mapping of symbols to numbers in other languages.

Any thoughts on UnionBlock? (following C's union type) or any other ideas?

@loicteixeira

Copy link
Copy Markdown
Member

SwitchBlock or CaseBlock 🤷‍♂️

@kaedroho kaedroho added 4:Final Comment Period A 10-day final review window before the RFC is merged ('active') or rejected and removed 1:New Newly-submitted RFC, awaiting initial triage by the core team labels Jul 28, 2021
@kaedroho

Copy link
Copy Markdown
Contributor Author

Planning on closing this one, it didn't exactly get a very enthusiastic response when I presented it so I'm going to focus on other things

@kaedroho kaedroho closed this Oct 11, 2021
@kaedroho kaedroho deleted the enumblock branch October 11, 2021 10:51
@kaedroho kaedroho restored the enumblock branch April 19, 2022 08:56
@kaedroho kaedroho reopened this Apr 19, 2022
@kaedroho kaedroho added 1:New Newly-submitted RFC, awaiting initial triage by the core team and removed 4:Final Comment Period A 10-day final review window before the RFC is merged ('active') or rejected labels Apr 19, 2022
@kaedroho

kaedroho commented Apr 19, 2022

Copy link
Copy Markdown
Contributor Author

Reopening as I feel like this is a missing piece in our set of block types and I'd like to push for it to be included in Wagtail!

I think there are three fundamental data structures that should make up a StreamField:

  • A way to manage a sequence of blocks of the same type (ListBlock)
  • A way to manage a set of blocks that appear together (StructBlock)
  • A way to manage a choice between multiple types (UnionBlock)

Adding UnionBlock, would mean that Wagtail gains a new useful block type, and we could also redefine StreamBlock in terms of these block types. For example:

StreamBlock([
    ('type_a', TypeABlock()),
    ('type_b', TypeBBlock()),
])
ListBlock(UnionBlock([
    ('type_a', TypeABlock()),
    ('type_b', TypeBBlock()),
]))

This would mean all sequences are managed by the same type. I'm not saying that we should drop support forStreamBlock as it provides the stream UI, but the internal data structure could be managed by ListBlock instead.

A use for UnionBlock on its own could be as a way to define a link that could be either a page chooser or a URL:

class LinkedImageBlock(StructBlock):
    image = ImageChooserBlock()
    link = UnionBlock([
        ('internal', PageChooserBlock()),
        ('external', URLBlock()),
    ])

@jams2 jams2 mentioned this pull request Mar 11, 2024
@kaedroho

kaedroho commented Apr 4, 2024

Copy link
Copy Markdown
Contributor Author

Closing in favor of #94 which seems to be the same idea with a much better RFC. Great work @jams2!

@kaedroho kaedroho closed this Apr 4, 2024
@zerolab zerolab deleted the enumblock branch April 4, 2024 10:35
@jams2

jams2 commented Apr 4, 2024

Copy link
Copy Markdown

Thanks @kaedroho - I missed this when I started writing #94, I will review it properly before responding to feedback there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1:New Newly-submitted RFC, awaiting initial triage by the core team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants