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

IBX-1476: Disable Select All checkbox when all the checkboxes in the table row are disabled #239

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/bundle/Resources/public/js/scripts/admin.table.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function(global, doc, $, ibexa) {
const tablesWithBulkCheckbox = doc.querySelectorAll('.ibexa-table.ibexa-table--has-bulk-checkbox');
const ibexaTables = doc.querySelectorAll('.ibexa-table');
const setMainCheckboxState = (mainCheckbox, subCheckboxes, event) => {
const isFromJS = event?.detail?.isFromJS ?? false;

Expand Down Expand Up @@ -52,6 +52,12 @@

const checkboxesChangeListeners = new Map();
headCellsWithCheckboxes.forEach((headCellsWithCheckbox) => {
const hasBulkCheckbox = !!headCellsWithCheckbox.querySelector('.ibexa-table__header-cell-checkbox:not(.ibexa-table__header-cell-checkbox--custom-init)');
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const hasBulkCheckbox = !!headCellsWithCheckbox.querySelector('.ibexa-table__header-cell-checkbox:not(.ibexa-table__header-cell-checkbox--custom-init)');
const isCustomInit = !!headCellsWithCheckbox.querySelector('.ibexa-table__header-cell-checkbox:not(.ibexa-table__header-cell-checkbox--custom-init)');


if (!hasBulkCheckbox) {
return;
}

const mainCheckboxIndex = [...headCells].indexOf(headCellsWithCheckbox);
const mainCheckbox = headCellsWithCheckbox.querySelector('.ibexa-input--checkbox');
const subCheckboxes = tableBody.querySelectorAll(
Expand Down Expand Up @@ -90,7 +96,13 @@
tablesCheckboxesChangeListeners.delete(table);
};

tablesWithBulkCheckbox.forEach((table) => {
ibexaTables.forEach((table) => {
const tableHasBulkCheckbox = !!table.querySelector('.ibexa-table__header-cell-checkbox:not(.ibexa-table__header-cell-checkbox--custom-init)');

if (!tableHasBulkCheckbox) {
return;
}

addTableCheckboxesListeners(table);

table.addEventListener(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
{% if custom_urls_pager.currentPageResults is not empty %}
{% for custom_url in custom_urls_pager.currentPageResults %}
{% set body_row_cols = [] %}
{% set has_checkbox = false %}

{% set col_raw %}
{% if can_edit_custom_url %}
{{ form_widget(form_custom_url_remove.url_aliases[custom_url.id]) }}

{% set has_checkbox = true %}
{% else %}
{% do form_custom_url_remove.url_aliases.setRendered %}
{% endif %}
{% endset %}
{% set body_row_cols = body_row_cols|merge([{
content: col_raw,
has_checkbox,
raw: true,
}]) %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
>
{%- block content -%}
{%- if has_checkbox|default(false) -%}
<input class="ibexa-input ibexa-input--checkbox ibexa-table__header-cell-checkbox" type="checkbox">
<input
class="ibexa-input ibexa-input--checkbox ibexa-table__header-cell-checkbox
{%- if is_custom_bulk|default(false) %} ibexa-table__header-cell-checkbox--custom-init{%- endif -%}"
type="checkbox">
{%- endif -%}
<span
class="ibexa-table__header-cell-text-wrapper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{% for head_col in head_cols %}
{% include '@ibexadesign/ui/component/table/table_head_cell.html.twig' with {
has_checkbox: head_col.has_checkbox|default(false),
is_custom_bulk: head_col.is_custom_bulk|default(false),
has_icon: head_col.has_icon|default(false),
is_close_left: head_col.is_close_left is defined ? head_col.is_close_left : next_is_close_left|default(false),
content: head_col.content|default(''),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export default class TableViewComponent extends Component {
checked={anyLocationSelected}
onClick={this.selectAll} // We need onClick, because MS Edge does not trigger onChange when checkbox has indeterminate state. (ref: https://stackoverflow.com/a/33529024/5766602)
onChange={() => {}} // Dummy callback to not trigger React warning as we cannot use onChange on MS Edge
className="ibexa-input ibexa-input--checkbox"
className="ibexa-input ibexa-input--checkbox ibexa-table__header-cell-checkbox ibexa-table__header-cell-checkbox--custom-init"
/>
</th>
{this.renderBasicColumnsHeader()}
Expand All @@ -303,7 +303,7 @@ export default class TableViewComponent extends Component {
return (
<div className="c-table-view__wrapper">
<div className="c-table-view__scroller" ref={this._refScroller}>
<table className="table ibexa-table ibexa-table--has-bulk-checkbox c-table-view">
<table className="table ibexa-table c-table-view">
{this.renderHead()}
<tbody className="ibexa-table__body c-table-view__body">{renderedItems}</tbody>
</table>
Expand Down