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-3456 Collapse all button support #1394

Open
wants to merge 4 commits into
base: 4.6
Choose a base branch
from
Open

Conversation

bozatko
Copy link
Contributor

@bozatko bozatko commented Nov 18, 2024

🎫 Issue IBX-3456

Related PRs:

Description:

For QA:

Documentation:

@bozatko bozatko changed the base branch from main to 4.6 November 18, 2024 11:51
src/bundle/Resources/public/js/scripts/core/collapse.js Outdated Show resolved Hide resolved
src/bundle/Resources/public/js/scripts/core/collapse.js Outdated Show resolved Hide resolved
src/bundle/Resources/public/js/scripts/core/collapse.js Outdated Show resolved Hide resolved
src/bundle/Resources/public/js/scripts/core/collapse.js Outdated Show resolved Hide resolved
src/bundle/Resources/public/js/scripts/core/collapse.js Outdated Show resolved Hide resolved
const checkIfChangeText = () => {
const allGroups = doc.querySelectorAll(MULTI_COLLAPSE_BODY_CLASS);
if (singleElementClicked.length === allGroups.length || singleElementClicked.length === 0) {
collapseAll.classList.toggle('d-none');
Copy link
Contributor

@lucasOsti lucasOsti Nov 18, 2024

Choose a reason for hiding this comment

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

I my opinion we should avoid using BS class d-none. I prefer toggle btn label not class. But I you want toggle class do it on btn then you won't have to change the class for two nodes, just one, and you can manage showing labels in CSS

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I followed the existing examples of implementation in the code, but I can change it in any other way.

const collapseAll = toggleAllBtn?.querySelector('.ibexa-attribute-group__toggler-collapse');
const MULTI_COLLAPSE_BODY_CLASS = '.multi-collapse';
let singleElementClicked = [];
const checkIfChangeText = () => {
Copy link
Contributor

@lucasOsti lucasOsti Nov 18, 2024

Choose a reason for hiding this comment

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

I think the name of the function is wrong because this function only toggles the d-none class.
I have one more question, what will happen if it will be 2 or 3 collapse all buttons for different groups?
I would probably create a new JS file that contain all the collapse/expand logic for multiple collpase. The button in the data-attribute could be given a selector which collapse it should collapse/expand/listen to, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I proposed a new name for the function. In my opinion, based on the YAGNI principle, we should first discuss the probability of such a situation before making such changes.

src/bundle/Resources/public/js/scripts/core/collapse.js Outdated Show resolved Hide resolved
src/bundle/Resources/public/js/scripts/core/collapse.js Outdated Show resolved Hide resolved
};
const handleCollapseAction = (expandAction) => {
singleElementClicked = [];
doc.querySelectorAll('.ibexa-collapse').forEach((collapseNode) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think here's some bigger problem - it should be contextualized in some way. Now you'll collapse ALL elements on page that has this class, even if they're in some totally different place and are used for something totally different.

Probably instead of doc you should use some container to limit to some specific part of site

Copy link

sonarcloud bot commented Nov 24, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants