Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC 66: EnumBlock #66

Closed
wants to merge 4 commits into from
Closed

RFC 66: EnumBlock #66

wants to merge 4 commits into from

Conversation

kaedroho
Copy link
Contributor

@kaedroho kaedroho commented Dec 30, 2020

@kaedroho kaedroho changed the title EnumBlock RFC 66: EnumBlock Dec 30, 2020
@kaedroho kaedroho added the 1:New label Dec 30, 2020
@kaedroho kaedroho mentioned this pull request Dec 30, 2020
@kaedroho
Copy link
Contributor Author

kaedroho commented Jan 6, 2021

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
Member

SwitchBlock or CaseBlock 🤷‍♂️

@kaedroho
Copy link
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
Copy link
Contributor Author

kaedroho commented Apr 19, 2022

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
Copy link
Contributor Author

kaedroho commented Apr 4, 2024

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
Copy link

jams2 commented Apr 4, 2024

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants