Fix typos and remove unwanted code from bulk actions (#7613)

* [refactor] Fix typos and documentation

* [refactor] Remove unused attribute object_key

* [refactor] Remove filters from page explorer

* [refactor] Remove unused code of page filters
pull/7618/head
Shohan 2021-10-15 16:48:23 +05:30 zatwierdzone przez Matt Westcott
rodzic 51f71709c6
commit 4624d2d540
14 zmienionych plików z 8 dodań i 98 usunięć

Wyświetl plik

@ -3,7 +3,6 @@
const BULK_ACTION_PAGE_CHECKBOX_INPUT = '[data-bulk-action-checkbox]';
const BULK_ACTION_SELECT_ALL_CHECKBOX = '[data-bulk-action-select-all-checkbox]';
const BULK_ACTIONS_CHECKBOX_PARENT = '[data-bulk-action-parent-id]';
const BULK_ACTION_FILTER = '[data-bulk-action-filter]';
const BULK_ACTION_FOOTER = '[data-bulk-action-footer]';
const BULK_ACTION_NUM_OBJECTS = '[data-bulk-action-num-objects]';
const BULK_ACTION_NUM_OBJECTS_IN_LISTING = '[data-bulk-action-num-objects-in-listing]';
@ -122,42 +121,6 @@ function onClickSelectAllInListing(e) {
document.querySelector(BULK_ACTION_NUM_OBJECTS_IN_LISTING).classList.add('u-hidden');
}
/**
* Event listener for filter dropdown options
*/
function onClickFilter(e) {
e.preventDefault();
const filter = e.target.dataset.bulkActionFilter || '';
const changeEvent = new Event('change');
if (filter.length) {
/* split the filter string into [key,value] pairs and check for the values in the
BULK_ACTION_PAGE_CHECKBOX_INPUT dataset */
const [_key, value] = filter.split(':');
const key = `${_key[0].toUpperCase()}${_key.slice(1)}`;
for (const el of document.querySelectorAll(BULK_ACTION_PAGE_CHECKBOX_INPUT)) {
if (el.dataset[`page${key}`]) {
if (el.dataset[`page${key}`] === value) {
if (!el.checked) {
el.checked = true;
el.dispatchEvent(changeEvent);
}
} else {
if (el.checked) {
el.checked = false;
el.dispatchEvent(changeEvent);
}
}
}
}
} else {
/* If filter string is empty, select all checkboxes */
document.querySelectorAll(BULK_ACTION_SELECT_ALL_CHECKBOX).forEach(el => {
el.checked = true; // eslint-disable-line no-param-reassign
});
document.querySelector(BULK_ACTION_SELECT_ALL_CHECKBOX).dispatchEvent(changeEvent);
}
}
/**
* Event listener for bulk actions which appends selected ids to the corresponding action url
*/
@ -192,9 +155,6 @@ function addBulkActionListeners() {
document.querySelectorAll(BULK_ACTION_SELECT_ALL_CHECKBOX).forEach(el => {
el.addEventListener('change', onSelectAllChange);
});
document.querySelectorAll(BULK_ACTION_FILTER).forEach(
elem => elem.addEventListener('click', onClickFilter)
);
document.querySelectorAll(`${BULK_ACTION_FOOTER} .bulk-action-btn`).forEach(
elem => elem.addEventListener('click', onClickActionButton)
);

Wyświetl plik

@ -33,7 +33,7 @@ The Explorer page allows you to view a page's children and perform actions on th
* Selecting at least one checkbox will popup an action bar at the bottom, which will list all the available bulk actions for pages.
* Clicking on any action will take you to a separate page with all the selected pages, for confirmation
* Clicking on any action will take you to a separate view with all the selected pages, for confirmation
* Similar buttons are available for each child page. These are made visible on hover.
Reordering pages

Wyświetl plik

@ -1442,7 +1442,8 @@ Hooks for registering and customising bulk actions. See :ref:`here <custom_bulk_
@hooks.register("before_bulk_action")
def hook_func(request, action_type, objects, action_class_instance):
...
if action_type == 'delete':
return HttpResponse(f"{len(objects)} objects would be deleted", content_type="text/plain")
.. _after_bulk_action:
@ -1460,7 +1461,8 @@ Hooks for registering and customising bulk actions. See :ref:`here <custom_bulk_
@hooks.register("after_bulk_action")
def hook_func(request, action_type, objects, action_class_instance):
...
if action_type == 'delete':
return HttpResponse(f"{len(objects)} objects have been deleted", content_type="text/plain")

Wyświetl plik

@ -4,6 +4,6 @@
{% if obj_type == 'page' %}data-page-status="{% if obj.live %}live{% else %}draft{% endif %}"{% endif %}
data-object-id="{{obj.id}}" data-bulk-action-checkbox class="bulk-action-checkbox"
{% if checbox_aria_label %}aria-label="{{checkbox_aria_label}}"{% endif %}
{% if aria_labelledby %}aria_labelledby="{{ aria_labelledby_prefix }}{{ aria_labelledby }}{{ aria_labelledby_suffix }}"{% endif %}
{% if aria_labelledby %}aria-labelledby="{{ aria_labelledby_prefix }}{{ aria_labelledby }}{{ aria_labelledby_suffix }}"{% endif %}
/>
</td>

Wyświetl plik

@ -3,8 +3,5 @@
<div>
{% trans "Select all" as aria_label %}
<input data-bulk-action-select-all-checkbox type="checkbox" aria-label="{{aria_label}}" />
{% if show_filters %}
{% bulk_action_filters %}
{% endif %}
</div>
</th>

Wyświetl plik

@ -10,13 +10,7 @@
<ul class="c-dropdown__menu u-toggle u-arrow u-arrow--tl u-background">
{% for button in buttons %}
<li class="c-dropdown__item ">
<a href="{{ button.url }}" aria-label="{{ button.attrs.title }}"
{% if button.attrs.data %}
{% for data_key, data_value in button.attrs.data.items %}
data-{{data_key}}="{{data_value}}"
{% endfor %}
{% endif %}
class="u-link is-live {{ button.classes|join:' ' }}">
<a href="{{ button.url }}" aria-label="{{ button.attrs.title }}" class="u-link is-live {{ button.classes|join:' ' }}">
{{ button.label }}
</a>
</li>

Wyświetl plik

@ -32,7 +32,7 @@ ordering: the current sort parameter
{% endif %}
</th>
{% else %}
{% include 'wagtailadmin/bulk_actions/select_all_checkbox_cell.html' with parent=parent_page show_filters=True %}
{% include 'wagtailadmin/bulk_actions/select_all_checkbox_cell.html' with parent=parent_page %}
{% endif %}
<th class="title">
{% trans 'Title' as title_label %}

Wyświetl plik

@ -490,20 +490,6 @@ def page_listing_buttons(context, page, page_perms, is_parent=False):
return {'page': page, 'buttons': buttons}
@register.inclusion_tag("wagtailadmin/pages/listing/_button_with_dropdown.html",
takes_context=True)
def bulk_action_filters(context):
button_hooks = hooks.get_hooks('register_bulk_action_filters')
buttons = []
for hook in button_hooks:
buttons.extend(hook())
buttons.sort(key=lambda x: x.priority)
return {'buttons': buttons}
@register.inclusion_tag("wagtailadmin/pages/listing/_buttons.html",
takes_context=True)
def bulk_action_choices(context, app_label, model_name):

Wyświetl plik

@ -29,7 +29,6 @@ class BulkAction(ABC, FormView):
extras = dict()
action_priority = 100
models = []
object_key = 'object'
classes = set()
form_class = forms.Form

Wyświetl plik

@ -10,7 +10,6 @@ class DefaultPageForm(forms.Form):
class PageBulkAction(BulkAction):
models = [Page]
object_key = 'page'
form_class = DefaultPageForm
def get_context_data(self, **kwargs):

Wyświetl plik

@ -162,30 +162,6 @@ def register_workflow_tasks_menu_item():
return WorkflowTasksMenuItem(_('Workflow tasks'), reverse('wagtailadmin_workflows:task_index'), icon_name='thumbtack', order=150)
@hooks.register('register_bulk_action_filters')
def bulk_action_filters():
yield Button(
_('All'),
'?filters=',
attrs={'title': _("All pages"), 'data': {'bulk-action-filter': ""}},
priority=10
)
yield Button(
_('Status: Draft'),
'?filters=status:draft',
attrs={'title': _("Draft pages"), 'data': {'bulk-action-filter': _("status:draft")}},
priority=20
)
yield Button(
_('Status: Live'),
'?filters=status:live',
attrs={'title': _("Live pages"), 'data': {'bulk-action-filter': _("status:live")}},
priority=30
)
@hooks.register('register_page_listing_buttons')
def page_listing_buttons(page, page_perms, is_parent=False, next_url=None):
if page_perms.can_edit():

Wyświetl plik

@ -6,7 +6,6 @@ from wagtail.documents.permissions import permission_policy as documents_permiss
class DocumentBulkAction(BulkAction):
permission_policy = documents_permission_policy
models = [get_document_model()]
object_key = 'document'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

Wyświetl plik

@ -6,7 +6,6 @@ from wagtail.images.permissions import permission_policy as images_permission_po
class ImageBulkAction(BulkAction):
permission_policy = images_permission_policy
models = [get_image_model()]
object_key = 'image'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

Wyświetl plik

@ -5,4 +5,3 @@ from wagtail.admin.views.bulk_action import BulkAction
class UserBulkAction(BulkAction):
models = [get_user_model()]
object_key = 'user'