Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Overhaul visual side of bulk actions bar
dominik-zeglen101c9a8df73e
diff --git a/saleor/static/dashboard/js/components/bulk-actions.js b/saleor/static/dashboard/js/components/bulk-actions.jsindex 20fdc5cb38..f6d9b0624f 100644--- a/saleor/static/dashboard/js/components/bulk-actions.js+++ b/saleor/static/dashboard/js/components/bulk-actions.js@@ -1,28 +1,34 @@-function updateSelectedItemsText () {+function moveSelectAllCheckbox(bulk, selectAllState) {+ const $selectAll = $('#select-all-products').parent()[0].innerHTML;+ const $headerContainer = $('thead .bulk-checkbox');+ const $actionBarContainer = $('.data-table-bulk-actions__select-all');+ if (bulk) {+ $headerContainer.html('');+ $actionBarContainer[0].innerHTML = $selectAll;+ } else {+ $actionBarContainer.html('');+ $headerContainer[0].innerHTML = $selectAll;+ }+ $actionBarContainer.find('#select-all-products').prop('checked', selectAllState);+ $('.select-all').on('change', onSelectAll);+}++function updateSelectedItemsText (selectAllState) {+ if ([true, false].indexOf(selectAllState) === -1) {+ selectAllState = false;+ }const count = $('.select-item:checked').length - $('#select-all-products:checked').length;- const $counterTextNode = $('.data-table-header-action-selected-items');- const $header = $('.data-table-header-alternative');+ const $counterTextNode = $('.data-table-bulk-actions__selected-items');+ const $header = $('.data-table-bulk-actions');const counterText = ngettext('item selected', 'items selected', count);if (!count) {$header.addClass('single').removeClass('bulk');+ moveSelectAllCheckbox(false, selectAllState);} else {$counterTextNode.html(`${count} ${counterText}`);$header.addClass('bulk').removeClass('single');- }-}--function onSwitchActions (e) {- const $target = $(e.currentTarget);- const $targetForm = $target.parents('form');- const $btnChecked = $targetForm.find('.btn-show-when-checked');- const $btnUnchecked = $targetForm.find('.btn-show-when-unchecked');- if ($targetForm.find('.switch-actions:checked').length) {- $btnChecked.show();- $btnUnchecked.hide();- } else {- $btnUnchecked.show();- $btnChecked.hide();+ moveSelectAllCheckbox(true, selectAllState);}}@@ -31,7 +37,9 @@ function onSelectAll (e) {const $targetForm = $target.parents('form');const $items = $targetForm.find('.switch-actions');$items.prop('checked', $target[0].checked);- updateSelectedItemsText();+ console.log($target[0].checked);+ $target.off('change');+ updateSelectedItemsText($target[0].checked);}function onSubmit (e) {@@ -44,7 +52,6 @@ function onSubmit (e) {// -----updateSelectedItemsText();-$('.select-all').on('change', onSelectAll);-$('.switch-actions').on('change', onSwitchActions);+$('.select-all').on('click', onSelectAll);$('.select-item').on('change', updateSelectedItemsText);$('.bulk-actions a').on('click', onSubmit);diff --git a/saleor/static/dashboard/scss/components/_data-table.scss b/saleor/static/dashboard/scss/components/_data-table.scssindex 24e0b3779a..d1af7138eb 100644--- a/saleor/static/dashboard/scss/components/_data-table.scss+++ b/saleor/static/dashboard/scss/components/_data-table.scss@@ -19,28 +19,23 @@padding: 14px 8px;}- &-header-alternative {+ &-bulk-actions {box-shadow: none;transition: $transition-duration;- max-height: 0;overflow: hidden;- .show-single, .show-bulk {- display: none;+ display: none;+ position: absolute;+ right: 0;+ z-index: 1;+ padding: 0 24px 0 0;+ @media (max-width: $small-screen) {+ height: 56px;+ overflow: visible;}&.bulk {background: #fff;color: $off-black;- max-height: 100px;- border-bottom: 1px #d0d0d0 solid;- .show-bulk {- display: block;- }- th, a {- color: color('teal', 'base');- }- .data-table-header-action-selected-items {- margin-left: 13px;- }+ display: block;}&.single {background: #fff;@@ -51,6 +46,49 @@color: $secondary-color;}}+ a {+ color: $secondary-color;+ }+ &__selected-items {+ margin-left: -10px;+ line-height: 56px;+ }+ &__action-choice {+ width: calc(100% - 60px);+ position: absolute;+ right: 0;+ ul {+ li {+ a {+ margin: 0;+ }+ }+ }+ @media (max-width: $small-screen) {+ display: none;+ }+ }+ &__dropdown-container {+ right: -5px;+ position: relative;+ display: none;+ svg {+ fill: $grey-color;+ }+ a {+ line-height: 70px;+ }+ @media (max-width: $small-screen) {+ display: block;+ }+ }+ &__select-all {+ float: left;+ margin: 11px 8px 0 24px;+ @media (max-width: $small-screen) {+ margin: 6px 8px 0 24px;+ }+ }}&-header {diff --git a/templates/dashboard/product/_bulk_actions_bar.html b/templates/dashboard/product/_bulk_actions_bar.htmlnew file mode 100644index 0000000000..ac260d983d--- /dev/null+++ b/templates/dashboard/product/_bulk_actions_bar.html@@ -0,0 +1,31 @@+{% load static %}++<nav class="data-table-bulk-actions single">+ <div class="data-table-bulk-actions__select-all"></div>+ <div class="data-table-bulk-actions__selected-items col inline"></div>+ <div class="data-table-bulk-actions__action-choice">+ <ul class="right">+ {% for action, label in bulk_action_form.action.field.widget.choices %}+ <li>+ <a href=""+ data-action="{{ action }}"+ class="btn-flat waves-effect">{{ label|upper }}</a>+ </li>+ {% endfor %}+ </ul>+ </div>+ <div class="data-table-bulk-actions__dropdown-container">+ <a class="dropdown-button right" href="#!" data-activates="dropdown1" data-constrainwidth="false" data-gutter="-19" data-alignment="right">+ <svg data-src="{% static "dashboard/images/more-vert.svg" %}" height="24" width="24" />+ </a>+ <ul id="dropdown1" class="dropdown-content">+ {% for action, label in bulk_action_form.action.field.widget.choices %}+ <li>+ <a href=""+ data-action="{{ action }}"+ class="btn-flat waves-effect">{{ label|upper }}</a>+ </li>+ {% endfor %}+ </ul>+ </div>+</nav>diff --git a/templates/dashboard/product/list.html b/templates/dashboard/product/list.htmlindex 105ae2385d..f6aa850e2c 100644--- a/templates/dashboard/product/list.html+++ b/templates/dashboard/product/list.html@@ -50,20 +50,7 @@<form method="POST" action="{% url 'dashboard:product-bulk-update' %}" novalidate id="bulk-actions-form">{% csrf_token %}<input name="action" type="hidden" id="bulk-action" />- <nav class="data-table-header-alternative single">- <div class="bulk-info show-bulk">- <div class="data-table-header-action-selected-items col inline"></div>- </div>- <div class="bulk-actions show-bulk nav-wrapper">- <ul class="right">- {% for action, label in bulk_action_form.action.field.widget.choices %}- <li>- <a href="" data-action="{{ action }}" class="btn-flat waves-effect">{{ label|upper }}</a>- </li>- {% endfor %}- </ul>- </div>- </nav>+ {% include 'dashboard/product/_bulk_actions_bar.html' %}<div class="data-table-container"><table class="bordered highlight responsive data-table last-right-align"><thead>