-
Notifications
You must be signed in to change notification settings - Fork 17
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
Conversation
Codecov ReportAttention: Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this 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?
@danielhollas thanks for your comments. Let's discuss further on Discourse. |
@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. |
@danielhollas could you please take a look at why the browser tests are failing? I'm not sure I understand what's happening here. |
@edan-bainglass The same failures are seen on the main branch so it is not related to this PR. |
@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. |
There was a problem hiding this 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.
aiidalab-widgets-base/aiidalab_widgets_base/viewers.py
Lines 104 to 113 in de5f0cc
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.
There was a problem hiding this 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
.
tests/test_loaders.py
Outdated
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 in
test_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).
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, notebook test passes 👍
Yep! 👍
That would be my expectation, yes! By the way, please don't use the |
@danielhollas proceeding with a made-up class for testing purposes only, as to not interfere with the code base for now. |
7e7fd31
to
f859695
Compare
I think this is good now? Failed tests unrelated I believe. |
There was a problem hiding this 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!
notebooks/test.ipynb
Outdated
@@ -0,0 +1,68 @@ | |||
{ |
There was a problem hiding this comment.
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
.
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? |
@edan-bainglass have you tried running the tests locally? That should make it clearer why they are failing. |
I couldn't figure out how to run selenium tests locally. I'll give it another go. |
@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. |
c3880d0
to
61f9792
Compare
7c8e259
to
d5c5086
Compare
@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! |
@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. |
Replaced module loading with using direct path in aiidalab#624
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)
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.