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

Slots in core #5775

Merged
merged 75 commits into from Feb 29, 2024
Merged

Slots in core #5775

merged 75 commits into from Feb 29, 2024

Conversation

sneridagh
Copy link
Member

@sneridagh sneridagh commented Feb 20, 2024

Let's see if we finally make this happen, at least the "static" ones.

  • Finish docs
  • Add Cypress tests in coresandbox
  • Add a few slots here and there in Volto core?
  • Unregister slot component
  • Reorder slots components

Copy link

netlify bot commented Feb 20, 2024

Deploy Preview for plone-components canceled.

Name Link
🔨 Latest commit 64c8c11
🔍 Latest deploy log https://app.netlify.com/sites/plone-components/deploys/65e05b7cd82f89000892376b

Copy link

netlify bot commented Feb 20, 2024

Deploy Preview for volto ready!

Name Link
🔨 Latest commit 64c8c11
🔍 Latest deploy log https://app.netlify.com/sites/volto/deploys/65e05b7c27fe1a0008833688
😎 Deploy Preview https://deploy-preview-5775--volto.netlify.app/configuration/slots.html
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Collaborator

@stevepiercy stevepiercy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I asked a few questions, too, so these suggestions will need to be reviewed as onesies.

packages/registry/src/registry.test.tsx Outdated Show resolved Hide resolved
packages/registry/src/registry.test.tsx Outdated Show resolved Hide resolved
docs/source/configuration/slots.md Show resolved Hide resolved
docs/source/configuration/slots.md Outdated Show resolved Hide resolved
docs/source/configuration/slots.md Outdated Show resolved Hide resolved
docs/source/configuration/slots.md Outdated Show resolved Hide resolved
docs/source/configuration/slots.md Outdated Show resolved Hide resolved
docs/source/configuration/slots.md Outdated Show resolved Hide resolved
docs/source/configuration/slots.md Outdated Show resolved Hide resolved
docs/source/configuration/slots.md Outdated Show resolved Hide resolved
sneridagh and others added 2 commits February 22, 2024 08:49
Co-authored-by: Steve Piercy <web@stevepiercy.com>
Co-authored-by: Steve Piercy <web@stevepiercy.com>
@@ -244,13 +245,15 @@ class View extends Component {
: null
}
/>
<SlotRenderer name="aboveContent" content={this.props.content} />
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@plone/volto-team would be interesting to hear what other slots you think should be added.
I am thinking of plone 4 viewlets managers that we had, if we need to add something to the header
and footer as well or we keep it simple for starters and add extra slots as needed.
So for sure I am hoping that others also give feedback on this work.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would for sure like to have built-in slots above and below the title in the title block.

Header and footer also makes sense conceptually...but then I guess we should move the existing rendering of these into slots, which is probably hard to do without it becoming a breaking change.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should include a list of the built-in slots in the documentation.

Copy link
Member Author

@sneridagh sneridagh Feb 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davisagli I've thought about the above and below title too. However, there's a couple of drawbacks, eg. How about the edit mode? Should they appear too there? How about if you move the title block around? Unlikely, but possible. But I agree that they will solve more problems than bring.

In fact, the aboveContentTitle in Volto is always the aboveContent to be safe. Probably in classic made much more sense.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the default slots available.

@stevepiercy
Copy link
Collaborator

@sneridagh I significantly overhauled the Anatomy section, per our conversation yesterday. There are a couple of missing pieces, as noted.

Copy link
Sponsor Member

@davisagli davisagli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stevepiercy Thanks, I think the rewritten Anatomy section is clearer.

docs/source/configuration/slots.md Show resolved Hide resolved
docs/source/configuration/slots.md Outdated Show resolved Hide resolved
docs/source/configuration/slots.md Outdated Show resolved Hide resolved
```

When the slot components with the same name and component under a given slot have all of their predicates return `true`, then that component will render in the slot.
Else, if there are slot components with the same name, but with a different component, and without predicates, then that different component will render.
Copy link
Member Author

@sneridagh sneridagh Feb 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not accurate, at least how I understand it by reading it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The below example is cocrrect though.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the component doesn't have any effect on which SlotComponent is chosen; it's only used for rendering after the right SlotComponent is chosen.

For each name, the algorithm picks the first SlotComponent with predicates that return true (or no predicates), and its component will be rendered. There's nothing looking for all predicates from SlotComponents with the same component.

```

When the slot components with the same name and component under a given slot have all of their predicates return `true`, then that component will render in the slot.
Else, if there are slot components with the same name, but with a different component, and without predicates, then that different component will render.
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the component doesn't have any effect on which SlotComponent is chosen; it's only used for rendering after the right SlotComponent is chosen.

For each name, the algorithm picks the first SlotComponent with predicates that return true (or no predicates), and its component will be rendered. There's nothing looking for all predicates from SlotComponents with the same component.


Thus the example slot renderer will have the following behavior.

- When both a user visits the route beginning with `/de/about`, and the content type is either a Document or News Item, then the component `PageHeader` will render in the `aboveContent` slot.
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. PageHeader will be used if the route starts with /de/about OR if the content type is Document or News Item. Matching either condition is sufficient; they don't have to both be true.

Thus the example slot renderer will have the following behavior.

- When both a user visits the route beginning with `/de/about`, and the content type is either a Document or News Item, then the component `PageHeader` will render in the `aboveContent` slot.
- When one or both of the predicates are false, then the component `DefaultHeader` will render in the `aboveContent` slot.
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. The SlotComponent with no predicates is only used if all predicates return false.

@sneridagh
Copy link
Member Author

@stevepiercy let's go together this morning through all of it and let's fix the inconsistencies, I'd like to merge it asap.

@sneridagh
Copy link
Member Author

@davisagli waiting for your last input before merging!

Copy link
Sponsor Member

@davisagli davisagli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stevepiercy @sneridagh Thanks, the docs look ok to me now

@sneridagh
Copy link
Member Author

Thanks everybody for the effort on making this a reality, years in the making, I think it's one of the best additions in the last years to Volto (and not only just Volto, the feature it's on @plone/registry so it can be anywhere...

And it shouldn't end here, the persistent slots that @tiberiuichim worked on some years ago is still relevant and valuable, and it's there to resurrect when we are ready to do so.

@sneridagh sneridagh merged commit b65b54a into main Feb 29, 2024
65 checks passed
@sneridagh sneridagh deleted the slots2024 branch February 29, 2024 21:53
sneridagh added a commit that referenced this pull request Feb 29, 2024
* main:
  Slots in core (#5775)
@davisagli davisagli mentioned this pull request Mar 7, 2024
@sneridagh sneridagh mentioned this pull request May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants