Skip to content

Commit

Permalink
IBX-6845: Matrix field columns table header not present until saved
Browse files Browse the repository at this point in the history
  • Loading branch information
GrabowskiM committed Oct 23, 2023
1 parent 4ff023c commit 3950d46
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/bundle/Resources/public/js/scripts/admin.contenttype.matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,41 @@
const settingsNode = event.target.closest(SELECTOR_SETTINGS_COLUMNS);
const template = settingsNode.querySelector(SELECTOR_TEMPLATE).innerHTML;
const node = settingsNode.querySelector(SELECTOR_COLUMNS_CONTAINER);
const emptyPlaceholder = node.querySelector('.ibexa-table__empty-table-cell');
const table = settingsNode.querySelector('.ibexa-table');
const tableHead = table.querySelector('.ibexa-table thead');
const emptyPlaceholder = table.querySelector('.ibexa-table__empty-table-cell');

if (emptyPlaceholder) {
emptyPlaceholder.closest('.ibexa-table__row').remove();

tableHead.hidden = false;
}

node.insertAdjacentHTML('beforeend', template.replace(NUMBER_PLACEHOLDER, getNextIndex(node)));

initColumns(settingsNode);
table.dispatchEvent(new CustomEvent('ibexa-refresh-main-table-checkbox'));
};
const removeItems = (event) => {
const settingsNode = event.target.closest(SELECTOR_SETTINGS_COLUMNS);
const checkedRows = findCheckedColumns(settingsNode);
const allRows = settingsNode.querySelectorAll(':not(.ibexa-table__template--empty-row) .ibexa-table__row');
const tableHead = settingsNode.querySelector('.ibexa-table thead');
const tableBody = settingsNode.querySelector('.ibexa-table__body');
const emptyPlaceholder = settingsNode.querySelector('.ibexa-table__template--empty-row')?.content.cloneNode(true);
const removedAllRows = checkedRows.length === allRows.length;

if (removedAllRows) {
tableBody.appendChild(emptyPlaceholder);
}

setTimeout(() => {
if (removedAllRows) {
tableHead.hidden = true;
}

findCheckedColumns(settingsNode).forEach((btn) => btn.closest(SELECTOR_COLUMN).remove());
checkedRows.forEach((btn) => btn.closest(SELECTOR_COLUMN).remove());
}, 1);

initColumns(settingsNode);
};
Expand Down

0 comments on commit 3950d46

Please sign in to comment.