Skip to content

XWIKI-23332: The width of the required rights modal depends on the displayed rights #4322

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

michitux
Copy link
Contributor

Jira URL

https://jira.xwiki.org/browse/XWIKI-23332

Changes

Description

  • Measure the width of the rights using JavaScript.
  • Switch to the vertical layout in JavaScript based on the available vs. required width.

Clarifications

  • I originally developed these changes to fix https://jira.xwiki.org/browse/XWIKI-23288 before I noticed a much simpler option to ignore the width of the analysis results.
  • With these changes, the width of the modal is always 600px again. Depending on the hints that are displayed but also depending on the translations of the names of the rights, this might not be enough so we can get the vertical layout also on big screens. If this isn't desired, we could also make the modal a bit wider in general - but I'm not sure how to choose that width.
  • I'm not really happy with all this JavaScript logic. I'm wondering if we should simplify it by using some of the following ideas:
    • In JavaScript, generate CSS code and attach it to the HTML with a media or container query with the exact width that we measured on the content. This would eliminate the need for the JavaScript code for changing the class but generating CSS code in JavaScript doesn't seem that nice to me. This should also eliminate the flickering that you can see in the video below.
    • Simplify width measurements by hiding the rights differently, e.g., combining visibility: hidden and height: 0. This would actually solve the scenario described in the Jira issue even without any JavaScript code.

I would be happy to get some feedback on these options that I mentioned above or also any other feedback and then I can update the code.

Screenshots & Video

Bildschirmaufnahme_20250624_151651.webm

Executed Tests

Manual tests as we have no real way to test such visual changes.

Expected merging strategy

  • Prefers squash: Yes
  • Backport on branches:
    • Might not be important enough.

…on the displayed rights

* Measure the width of the rights using JavaScript.
* Switch to the vertical layout in JavaScript based on the available vs.
  required width.
@michitux michitux self-assigned this Jun 24, 2025
@michitux michitux requested a review from manuelleduc June 24, 2025 13:30
@michitux michitux changed the title XWIKI-23332: The width of the required rights modal varies depends on the displayed rights XWIKI-23332: The width of the required rights modal depends on the displayed rights Jun 24, 2025
/**
* @returns {number} the minimum width of the rights list in horizontal layout
*/
#computeMinWidth()
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious about this # prefix. Is it a new naming rule I missed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_properties - I'm not sure if we've used them yet but to me, it seemed logical to use them as they are relatively widely supported.

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, I'm used to the private typescript keyword, but indeed the JavaScript equivalent seems widely adopted https://caniuse.com/mdn-javascript_classes_private_class_fields

* @param delay the delay in milliseconds
* @returns {(function(...[*]): void)|*} a debounced version of the function
*/
#debounce(fn, delay)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised we don't have an existing debounce method we can import from somewhere else.

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 found two other places where local debounce methods were declared but nothing I could import.

@@ -241,6 +241,8 @@ define('xwiki-requiredrights-dialog', [
event.preventDefault();
this.save();
});

this.#setupResponsiveLayoutInitialization();
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this method is called to perform something equivalent to the removed CSS, and to avoid having hardcoded width in the media queries, but it's not so clear to me by reading the code.
Also wdyt of explaining the technical constraints forcing us to do something we usually do 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.

There is a comment below #setupResponsiveLayout that might explain what we do here. See also my comments in the PR description, I'm not 100% sure it's the best way to do it.

* We use JavaScript to manage the responsive layout as we don't know in advance the width of the rights
* list in horizontal layout, and thus we can't define a breakpoint in CSS using a media/container query.
* This could be reconsidered when CSS environment variables become available which should greatly simplify
* this code.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is the comment that hopefully explains why we use this method.

/**
* @returns {number} the minimum width of the rights list in horizontal layout
*/
#computeMinWidth()
Copy link
Contributor

Choose a reason for hiding this comment

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

The name of the method also does not state clearly that it has side effects on this.rightsList

Copy link
Contributor

@manuelleduc manuelleduc left a comment

Choose a reason for hiding this comment

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

I agree with your conclusion that it's not satisfying to use JavaScript to handle this, but I fail to think of a better approach.
Maybe @tkrieck knows a way to change the grid system of an element based on an overflow?

@tkrieck
Copy link
Contributor

tkrieck commented Jun 25, 2025

I agree with your conclusion that it's not satisfying to use JavaScript to handle this, but I fail to think of a better approach.
Maybe @tkrieck knows a way to change the grid system of an element based on an overflow?

In CSS, for now, there's nothing exactly like that. We could use flex positioning for larger viewports and switch to the proper mobile view in grid using a breakpoint (screen-sm-min perhaps).

Until the breakpoint is reached, the items in the list will wrap, like the image below. While I agree that is not as nice as the solution with JS, it's perfectly usable.

Screenshot 2025-06-25 at 09 42 27

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

Successfully merging this pull request may close these issues.

3 participants