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

Add static folder for static files and pre-loaded stylesheets (using new utility) #624

Merged
merged 7 commits into from
Aug 30, 2024

Conversation

edan-bainglass
Copy link
Member

@edan-bainglass edan-bainglass commented Jul 11, 2024

This PR adds a static folder to the widgets base package. At the moment, the folder holds stylesheets that are loaded (using a new utility function) on any import from the widgets base package.

Copy link

codecov bot commented Jul 11, 2024

Codecov Report

Attention: Patch coverage is 48.00000% with 13 lines in your changes missing coverage. Please review.

Project coverage is 83.49%. Comparing base (0c9f6fb) to head (7669080).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
aiidalab_widgets_base/__init__.py 14.28% 12 Missing ⚠️
aiidalab_widgets_base/utils/loaders.py 90.90% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #624      +/-   ##
==========================================
- Coverage   83.61%   83.49%   -0.12%     
==========================================
  Files          16       17       +1     
  Lines        3522     3539      +17     
==========================================
+ Hits         2945     2955      +10     
- Misses        577      584       +7     
Flag Coverage Δ
python-3.11 83.49% <48.00%> (-0.12%) ⬇️
python-3.9 83.53% <48.00%> (-0.12%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@danielhollas danielhollas left a comment

Choose a reason for hiding this comment

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

Hi @edan-bainglass,

thanks so much on working on this, I am really excited to see this land.

My main concern here is about SCSS, and is twofold.

  • It introduces additional complexity of extra compilation step (see my other comments)
  • I guess that most of us are not so proficient with CSS, and SCSS is yet another cognitive overhead. Especially as we just start using CSS directly, my feeling is that we should start simple.

If you feel strongly about it, could you please open an issue (or topic on Discourse), and explain what are the advantages of SCSS (and what is the additional complexity) so we can discuss it a bit before committing?

aiidalab_widgets_base/__init__.py Outdated Show resolved Hide resolved
aiidalab_widgets_base/utils/loaders.py Outdated Show resolved Hide resolved
aiidalab_widgets_base/static/styles/README.md Outdated Show resolved Hide resolved
aiidalab_widgets_base/static/styles/README.md Outdated Show resolved Hide resolved
@edan-bainglass
Copy link
Member Author

@danielhollas thanks for your comments. Let's discuss further on Discourse.

@edan-bainglass
Copy link
Member Author

@danielhollas I think I'll keep SCSS local and only commit/use the CSS files. In other words, no extra compilation step required for the developer if they wish to only work in CSS. Will update the PR shortly.

@edan-bainglass
Copy link
Member Author

@danielhollas could you please take a look at why the browser tests are failing? I'm not sure I understand what's happening here.

@danielhollas
Copy link
Contributor

@edan-bainglass The same failures are seen on the main branch so it is not related to this PR.

@edan-bainglass
Copy link
Member Author

@danielhollas I see. Okay then. Please review 🙏🏻 I have a few PRs built on top of this one both here and in the QE app. I think all is well other than the tests. I've removed the SCSS part.

Copy link
Contributor

@danielhollas danielhollas left a comment

Choose a reason for hiding this comment

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

Just some small nits.

My main thing is that it would be nice to demonstrate this functionality to prove that is working by including some actual CSS.

Perhaps a nice candidate would be this code that defines CSS inline for tables in DictViewer.

self.value += """
<style>
.df { border: none; }
.df tbody tr:nth-child(odd) { background-color: #e5e7e9; }
.df tbody tr:nth-child(odd):hover { background-color: #f5b7b1; }
.df tbody tr:nth-child(even):hover { background-color: #f5b7b1; }
.df tbody td { min-width: 300px; text-align: center; border: none }
.df th { text-align: center; border: none; border-bottom: 1px solid black;}
</style>
"""

EDIT: I know that you have follow-up PRs that do this so feel free to ignore this.

aiidalab_widgets_base/__init__.py Outdated Show resolved Hide resolved
aiidalab_widgets_base/utils/loaders.py Outdated Show resolved Hide resolved
aiidalab_widgets_base/utils/loaders.py Outdated Show resolved Hide resolved
aiidalab_widgets_base/utils/loaders.py Outdated Show resolved Hide resolved
Copy link
Member

@superstar54 superstar54 left a comment

Choose a reason for hiding this comment

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

Hi @edan-bainglass , thansk for the work.

  • It would be great that you add this in the docs to tell the developer how to use it in their app.
  • You need add your test in the test_notebooks.

aiidalab_widgets_base/__init__.py Show resolved Hide resolved
aiidalab_widgets_base/__init__.py Show resolved Hide resolved
aiidalab_widgets_base/utils/loaders.py Outdated Show resolved Hide resolved
Comment on lines 4 to 8
def test_load_css_stylesheet():
"""Test `load_css_stylesheet` function."""
package = "aiidalab_widgets_base.static.styles"
load_css_stylesheet(package=package, filename="global.css")
load_css_stylesheet(package=package)
Copy link
Member

Choose a reason for hiding this comment

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

The test here will not work because it is not running inside a notebook. To test whether the CSS works, you need to add a test in test_notebooks/test_notebooks.py.

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you saying to add a test to test_notebooks.py, or to move this test to test_notebooks.py? Also, could you explain why exactly it doesn't work?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, adding a new test in the test_notebooks.py, and check if the CSS is indeed loaded in the selenium_driver.

Also, could you explain why exactly it doesn't work?

the test.py file is not running in the notebook, thus the display(Javascript... code will not run. You can add some wrong code inside it, and the test will not throw error.

Copy link
Member

Choose a reason for hiding this comment

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

For the test in selenium, for example, you create a vbox, and attach a class, then in your testing CSS file, you change its color, and in selenium_driver, you try to find the vbox, and verify the color.

Copy link
Contributor

Choose a reason for hiding this comment

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

The test here is fine, I think but I agree it would be nice to have *an additionaltest intest_notebooks` that runs an actual browser via selenium that would prove that the CSS is indeed loaded and applied to a given element (I don't actually know if selenium allows that but I would expect so).

Copy link
Member

Choose a reason for hiding this comment

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

Yes, in the test notebook, you need at least

import aiidalab_widgets_base

Copy link
Member Author

Choose a reason for hiding this comment

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

Why?

Copy link
Member

@superstar54 superstar54 Aug 21, 2024

Choose a reason for hiding this comment

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

I mean you don't need (shouldn't ) call load_css_stylesheet explicitly. Only need to import aiidalab_widgets_base, since it will call load_css_stylesheet in the __init__.py file.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've loaded aiidalab_widgets_base in the test.ipynb notebook with a comment regarding its use, as it is not actually used explicitly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, notebook test passes 👍

@danielhollas
Copy link
Contributor

Matter of fact, I could use a test case for a notebook test, as recommended by @superstar54.

Yep! 👍

So to clarify, the bit of code you mentioned (df styles) can be removed once I add it via css, correct?

That would be my expectation, yes! By the way, please don't use the df class as a selector, since it comes from pandas I believe and I am planning to substitute pandas for tabulate in near future. Please add a custom awb class for this.

@edan-bainglass
Copy link
Member Author

@danielhollas proceeding with a made-up class for testing purposes only, as to not interfere with the code base for now.

@edan-bainglass
Copy link
Member Author

I think this is good now? Failed tests unrelated I believe.

@superstar54 superstar54 self-requested a review August 22, 2024 05:45
Copy link
Member

@superstar54 superstar54 left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the nice work!

@@ -0,0 +1,68 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's rename this file, current name is way to vague. I would vote for test_css.ipynb. If we want to reuse it for other tests in the future we can rename it later to test_misc.py.

tests_notebooks/test_notebooks.py Outdated Show resolved Hide resolved
aiidalab_widgets_base/static/styles/test.css Outdated Show resolved Hide resolved
@edan-bainglass
Copy link
Member Author

Found some oversights in my code. Fixed it. Still not passing the tests. But its not just my test. @danielhollas @superstar54 could you please have a look?

@danielhollas
Copy link
Contributor

@edan-bainglass have you tried running the tests locally? That should make it clearer why they are failing.

@edan-bainglass
Copy link
Member Author

I couldn't figure out how to run selenium tests locally. I'll give it another go.

@danielhollas
Copy link
Contributor

@yakutovicha might have some tips how to run the notebook tests locally.

Perhaps check the selenium docs, or pytest-selenium docs, there might be some browser dependencies to make it work.

@edan-bainglass edan-bainglass marked this pull request as ready for review August 30, 2024 14:54
@edan-bainglass edan-bainglass merged commit 73df986 into aiidalab:master Aug 30, 2024
11 checks passed
@danielhollas
Copy link
Contributor

@edan-bainglass congrats on merging this. 🎉 I'll make a new alpha release that you can then use on PRs on QEApp.

Could you please write here what you did to fix the tests and if / how you were able to test notebooks locally? I'll then add it to README for contributors. Thanks!

@edan-bainglass
Copy link
Member Author

@danielhollas thanks 🙏 Though I'm really not sure what actually fixed it. I was unable to run selenium tests locally in the container. I just applied the ol' step-by-step approach, walking back my commits, pushing chunks at a time and observing the tests. The CSS loading on import using the new utility passed the tests. Adding the notebook test in the notebooks folder with the test CSS as part of the module passed the tests. Then finally migrating the test notebook and CSS to the notebook tests folder... also passed the tests 🤷‍♂️ So in the end, I actually changed nothing from the state at which tests were failing. This was very confusing in general, as it was tests unrelated to my own that were failing before. Something to do with the selenium driver itself not finding the elements stated by the tests. According to this article, "NoSuchElementException is one of the most common exceptions in Selenium WebDriver..."

Of course, happy to get another set of eyes on it. Maybe I missed something.

@danielhollas danielhollas added the enhancement New feature or request label Sep 1, 2024
edan-bainglass added a commit to edan-bainglass/aiidalab-widgets-base that referenced this pull request Sep 2, 2024
Replaced module loading with using direct path in aiidalab#624
edan-bainglass added a commit to aiidalab/aiidalab-qe that referenced this pull request Sep 17, 2024
This PR refactors the main notebook as follows:
- Much of the notebook is refactored as an `AppWrapper` component holding the banner, main, and footer components
- The banner component (used to be the welcome message) is redesigned as follows:
  - App logo (same as documentation logo) and subtitle
  - Toggle buttons triggering an info box optionally showing one of the following:
    - Guide section - the old welcome page plus links to online docs, tutorials, etc.
    - About section - general information about the app and acknowledgements
- The actual app is now injected from the notebook into the main component.
- The footer component showing copyrights and version stays at the bottom of the page.

The PR also introduces the use of CSS, loading custom stylesheets in the notebook via the AWB CSS loader utility (aiidalab/aiidalab-widgets-base#624)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants