-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Use default icons for FieldPanels and add docs/tests for Panel icon customisation #10320
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Manage this branch in SquashTest this branch here: https://laymonagepanel-icons-mx0in.squash.io |
self.bound_field.field refers to the form field instance. Some model fields share the same form field type by default, e.g. models.TextField uses forms.CharField
This removes the parameters that come from the base Panel class (e.g. heading, classname, etc.) from the specific panel types to avoid repetition. Instead, these parameters are properly documented in the separate "Panel customisation" section. They are also explicitly listed in the Panel API reference.
URLField/URLBlock: link-external RichTextField/RichTextBlock: pilcrow FloatField/DecimalField/FloatBlock/DecimalBlock: decimal RegexField/RegexBlock: regex PageChooserBlock: doc-empty-inverse IntegerField: None (will use the arrow-down-big) IntegerBlock: placeholder
…olving FieldPanel icon
thibaudcolas
force-pushed
the
panel-icons
branch
from
April 18, 2023 01:45
bb41e6a
to
8c5a539
Compare
thibaudcolas
approved these changes
Apr 18, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one @laymonage! All working as far as I can tell, just needed to SVGO-compress the new icons and add licensing information within.
|
||
This panel allows for the creation of a "cluster" of related objects over a join to a separate model, such as a list of related links or slides to an image carousel. For a full explanation on the usage of ``InlinePanel``, see :ref:`inline_models`. | ||
This panel allows for the creation of a "cluster" of related objects over a join to a separate model, such as a list of related links or slides to an image carousel. For a full explanation on the usage of ``InlinePanel``, see :ref:`inline_models`. To save space, you can :ref:`collapse the panel by default <collapsible>`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one!
thibaudcolas
added a commit
to thibaudcolas/wagtail
that referenced
this pull request
Apr 18, 2023
8 tasks
This was referenced Mar 16, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #10274
Notes:
I changed the default icon mechanism to check the model field first (instead of the form field). This is because model fields do not always have a 1:1 mapping to the form fields. For example,
models.TextField
andmodels.CharField
both useforms.CharField
.I spoke with Ben and he said we should use the
pilcrow
icon forTextField
s andRichTextField
s, but not forCharField
. This is because the pilcrow generally represents a paragraph, which doesn't mean much in the context ofCharField
s. If we check for the form field, we cannot differentiate betweenTextField
andCharField
, unless we check the widget as well. Thus, I made the code to check for the model field first.That said, apparently
FieldPanel
can be used without a model field:wagtail/wagtail/admin/tests/test_edit_handlers.py
Lines 678 to 685 in 18e5757
So, I added a fallback code to use the form field to check for the default icon if the field does not exist on the model.
For the same reason as the model vs form fields discrepancy, this means that the
RegexField
default will not be used unless either (a) the user creates a customRegexField
model field, or (b) the specified field does not exist on the model, and the form field isRegexField
.I tweaked the field class checking to also look through the MRO. This allows us to use
TaggableManager
to define the default icon, and it works for bothTaggableManager
andClusterableTaggableManager
. This also allows custom fields that are subclasses of the known fields to use our default icons.For chooser panels, this was slightly trickier. We need to check if the field is a
ForeignKey
, and if so, we have two options that I can think of:Page
,Image
, orDocument
, use the custom icon accordingly.I've revamped the docs for the panel types and the Panel API. There are some liberties that I took, and we might want Matthew to review the docs changes.
To test this, I've made a branch based on @thibaudcolas' "everything page" branch:
https://github.com/laymonage/bakerydemo/tree/feature/10274-everything-page-icons
The branch has been updated to remove the custom
icon="..."
argument in theFieldPanel
s. You can verify that even with the argument removed, the default icon will still be shown for the known fields.Please check the following:
make lint
from the Wagtail root.Please describe additional details for testing this change.
Footnotes
Development Testing ↩
Browser and device support ↩
Accessibility Target ↩