Skip to content

feat: add API to fetch page direction - #15598

Merged
taefi merged 2 commits into
masterfrom
taefi/add-api-to-get-page-dir
Jan 2, 2023
Merged

taefi merged 2 commits into
masterfrom
taefi/add-api-to-get-page-dir

Conversation

@taefi

@taefi taefi commented Jan 1, 2023

Copy link
Copy Markdown
Contributor

Description

Add API to fetch the document.dir from browser
and pass it to the provided callback.

Fixes #15597

Type of change

  • Bugfix
  • Feature

Checklist

  • I have read the contribution guide: https://vaadin.com/docs/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

Additional for Feature type of change

  • Enhancement / new feature was discussed in a corresponding GitHub issue and Acceptance Criteria were created.

@taefi

taefi commented Jan 1, 2023

Copy link
Copy Markdown
Contributor Author

This change has no dependency on the new features of the platform, and it can be back-ported to all the versions.

@github-actions

github-actions Bot commented Jan 1, 2023 •

Copy link
Copy Markdown
Contributor

Test Results

   933 files  ±0     933 suites  ±0   56m 0s ⏱️ - 6m 13s
5 850 tests +3  5 814 ✔️ +3  36 💤 ±0  0 ❌ ±0 
6 103 runs  +2  6 060 ✔️ +2  43 💤 ±0  0 ❌ ±0 

Results for commit 5322fef. ± Comparison against base commit fcba203.

♻️ This comment has been updated with latest results.

@mcollovati mcollovati left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just a thought: it seems a bit odd to me that we set the direction on UI, but fetch it from Page.

Would it make sense to store direction value in UI or in UIInternals (as we do for title, for example) and have also a UI.getDirection() method?

* to be notified when the direction is resolved.
*/
public void fetchPageDirection(SerializableConsumer<Direction> callback) {
UI.getCurrent().getPage().executeJs("return document.dir")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we need UI.getCurrent().getPage() here, since the method is not static? Could it be simply a call to executeJs?

Suggested change
UI.getCurrent().getPage().executeJs("return document.dir")
executeJs("return document.dir")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was a left over from my draft codes, good catch!

@sonarqubecloud

sonarqubecloud Bot commented Jan 1, 2023

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@taefi

taefi commented Jan 1, 2023 •

Copy link
Copy Markdown
Contributor Author

Would it make sense to store direction value in UI or in UIInternals (as we do for title, for example) and have also a UI.getDirection() method?

IMO, keeping the state for those kind of stuff that can be changed on the client-side (for instance with a custom Js script) makes it hard to keep it in sync with the corresponding value on the server side, and would make it complicated to cover corner cases, and it becomes unreliable as the result. Reading it from the browser on demand would be much simpler. But, I'm open to new ideas.

Just a thought: it seems a bit odd to me that we set the direction on UI, but fetch it from Page.

It is a little hard to decide where to put an API when it comes to decide between Page and UI, and to be honest, I also struggled over this a little, but in the end I decided to put into the Page class since it was technically close to fetchCurrentUrl method. But, there's no heart feelings ;) I can move it to the UI class, as the added method and the correspondent tests aren't complicated and dependent on something in the Page class specifically.

@mcollovati

Copy link
Copy Markdown
Collaborator

If we don't hold state and always fetch the information from the client, I think it is fine to have the method on Page class

@taefi taefi changed the title feat: add API to get/fetch page direction feat: add API to fetch page direction Jan 2, 2023
@taefi
taefi merged commit 9ce01e3 into master Jan 2, 2023
@taefi
taefi deleted the taefi/add-api-to-get-page-dir branch January 2, 2023 09:35
vaadin-bot pushed a commit that referenced this pull request Jan 2, 2023
Add API to fetch the document.dir from browser
and pass it to the provided callback.

Fixes #15597
vaadin-bot pushed a commit that referenced this pull request Jan 2, 2023
Add API to fetch the document.dir from browser
and pass it to the provided callback.

Fixes #15597
MarcinVaadin pushed a commit that referenced this pull request Jan 2, 2023
Add API to fetch the document.dir from browser
and pass it to the provided callback.

Fixes #15597

Co-authored-by: Soroosh Taefi <taefi.soroosh@gmail.com>
MarcinVaadin pushed a commit that referenced this pull request Jan 2, 2023
Add API to fetch the document.dir from browser
and pass it to the provided callback.

Fixes #15597

Co-authored-by: Soroosh Taefi <taefi.soroosh@gmail.com>
@ZheSun88

ZheSun88 commented Jan 4, 2023

Copy link
Copy Markdown
Member

this is a new feature, which should not be picked to maintenance branch. 23.2 and 23.3

ZheSun88 added a commit that referenced this pull request Jan 5, 2023
ZheSun88 added a commit that referenced this pull request Jan 5, 2023
ZheSun88 added a commit that referenced this pull request Jan 5, 2023
ZheSun88 added a commit that referenced this pull request Jan 5, 2023
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.

Consider adding API to get the page direction (LTR/RTL)

4 participants