airflow icon indicating copy to clipboard operation
airflow copied to clipboard

ADD prototype version dark mode for Airflow UI

Open YounHS opened this issue 1 year ago • 12 comments

related: #11334

We've been seeing requests for a dark mode feature in the Airflow UI for a while now.

I tested it using docker-compose.yaml.

After testing, I was able to set dark mode and light mode.

The only thing I noticed is that after switching to dark mode, the light theme is visible for a very short time when the page is updated.

I think there should be a way to smooth this out in the future.

As-Is

  • This picture is just extract from airflow github readme.
  • I want to emphasize with this illustration that the dark/light mode toggle was not originally there.

image

To-Be

  • Dark Mode image

  • Light Mode image

You can toggle the dark/light mode by clicking the crescent icon on the right side of the navigation bar.

If you changed the color of the navigation bar via a setting like AIRFLOW__WEBSERVER__NAVBAR_COLOR, the dark/light mode will be applied accordingly.


FIX

  • Resolved slight light mode initially visible on page refresh after switching to dark mode
    • To do this, we added a new function CustomAirflow to views.py, which checks for the previous theme state just above the head tag.

YounHS avatar May 02 '24 01:05 YounHS

Congratulations on your first Pull Request and welcome to the Apache Airflow community! If you have any issues or are unsure about any anything please check our Contributors' Guide (https://github.com/apache/airflow/blob/main/contributing-docs/README.rst) Here are some useful points:

  • Pay attention to the quality of your code (ruff, mypy and type annotations). Our pre-commits will help you with that.
  • In case of a new feature add useful documentation (in docstrings or in docs/ directory). Adding a new operator? Check this short guide Consider adding an example DAG that shows how users should use it.
  • Consider using Breeze environment for testing locally, it's a heavy docker but it ships with a working Airflow and a lot of integrations.
  • Be patient and persistent. It might take some time to get a review or get the final approval from Committers.
  • Please follow ASF Code of Conduct for all communication including (but not limited to) comments on Pull Requests, Mailing list and Slack.
  • Be sure to read the Airflow Coding style.
  • Always keep your Pull Requests rebased, otherwise your build might fail due to changes not related to your commits. Apache Airflow is a community-driven project and together we are making it better 🚀. In case of doubts contact the developers at: Mailing List: [email protected] Slack: https://s.apache.org/airflow-slack

boring-cyborg[bot] avatar May 02 '24 01:05 boring-cyborg[bot]

Nice to see dark mode feature. The screen shot that you shared doesn't show the text properly. is it during switch mode. are there any other screenshots?

Hi @dirrao The captured screen contains sensitive information, so we've mosaicked it, thank you for your understanding! :)

And As you said, you can toggle between dark and light mode by toggling the moon icon right on navigation bar. I've added a capture screen for light mode!

YounHS avatar May 02 '24 06:05 YounHS

So in the dark mode screenshot, text is actually white (like in the nav bar) and it being very extremely low contrast is just a side effect of the mosaic? It would be helpful if there’s a non-filtered example. I have some worry about the blue used in links, for example.

uranusjr avatar May 03 '24 06:05 uranusjr

The screenshots illustrate that this will certainly be an appealing feature—I really wish the execution were as easy as this… The path that we should take (IMO) to enabling color mode in a sustainable manner is to migrate the rest of the UI to React. Within the React app, Chakra, the UI framework being employed, already has a robust color mode support baked in. The problem is that the React app is nested within the aged Flask+Bootstrap app and the two frameworks don't share a common color mode system. I'm sure it would be possible to bridge the divide/logic between them, but one would have to determine if that is worth the effort versus investing time in migrating more/the remaining UI to the React app. Once the UI is entirely in React, enabling it will trivial.

ryanahamilton avatar May 03 '24 11:05 ryanahamilton

hi @uranusjr. I removed the mosaicked part and created a test DAG to recapture it :)

YounHS avatar May 03 '24 16:05 YounHS

I am 80% okay with this interim. Anyway when moving to full-React we need to rework this thing. Found no problem on all existing pages with Firefox+Chromium on Ubuntu.

What irritates me is really that flickering during page load. I also checked with PR #39345 merged-in but this also did not help. Can this be improved?

I checked when setting my browser (Firefox as well as Chromium) to Dark mode explicitly, I'd expect the browser setting initially is picked-up. It is not. Can you add this?

jscheffl avatar May 04 '24 20:05 jscheffl

Hello, @jscheffl I fix the flickering problem. for this solution, I add custom function in views.py. It just a prototype, so please excuse the messy code.

Add. I test flickering solution by chrome browser! maybe firefox also run well i think.

YounHS avatar May 09 '24 07:05 YounHS

@jscheffl sry, I checked this prob!

I initially thought that I would only need to modify the airflow/www side, but for "security", "browse", and "admin", modifying views.py would not fix the problem.

This would require modifying the flask_appbuilder side, which I couldn't do.

So, I solved this by deleting the custom classes I added to views.py and simply adding the script tag to the head of main.html.

YounHS avatar May 12 '24 04:05 YounHS

@jscheffl I realized that fixing flickering is quite a tricky task. In order to fix this properly, i need to modify the html on the flask_appbuilder side.

However, i realized that it is currently not possible to modify the html of flaks_appbuilder within the airflow file. Therefore, I adjusted the position of the theme switching script syntax to optimize the flickering phenomenon.

I've tested it locally with chrome and had no issues, but if you experience flickering with this revision, please let me know!

YounHS avatar May 12 '24 23:05 YounHS

I did manual tests... cool: No flickering, consistent UI. Good to be merged.

Oh... I'm so glad to hear that! :) workflow fail cause I have lint prob 😢

YounHS avatar May 17 '24 00:05 YounHS

@bbovenzi looking for a second reviewer, you also had an opinion on the PR?

jscheffl avatar May 18 '24 09:05 jscheffl

@bbovenzi looking for a second reviewer, you also had an opinion on the PR?

@jscheffl Thank you. I don't have any other opinion. I just want you to know that I'm releasing this feature to make dark mode available to those who need it, as I was using it roughly myself.

YounHS avatar May 18 '24 10:05 YounHS

Oh, no just another small static check glitch. Else finally looks OK.

jscheffl avatar Jun 25 '24 18:06 jscheffl

Awesome work, congrats on your first merged pull request! You are invited to check our Issue Tracker for additional contributions.

boring-cyborg[bot] avatar Jun 26 '24 18:06 boring-cyborg[bot]

WOOOOOOOOHOOOOO!!!!

potiuk avatar Jun 26 '24 18:06 potiuk

+1! Very good and impactful contribution!

vincbeck avatar Jun 26 '24 18:06 vincbeck

What's the Hashtag we use to mark PR a candidate for PR of the month @jedcunningham ?

potiuk avatar Jun 26 '24 18:06 potiuk

@potiuk: #protm (source, hash is optional, but more fun 😄 )

jedcunningham avatar Jun 26 '24 19:06 jedcunningham

So ... It's DONE... Since you mentioned it :)

potiuk avatar Jun 26 '24 19:06 potiuk

One more small comment. I just run it and I think the background is a little too dark. Most of the dark-mode apps I have result with dark-but-not-black background and when I tried Airflow in dark mode it looks pitch-black.

potiuk avatar Jun 26 '24 19:06 potiuk

One more small comment. I just run it and I think the background is a little too dark. Most of the dark-mode apps I have result with dark-but-not-black background and when I tried Airflow in dark mode it looks pitch-black.

Now whining post-merge... there had been sufficient time to test :-D but also until 2.10 still time to update CSS if you think it is tooo dark.

jscheffl avatar Jun 26 '24 20:06 jscheffl

image

potiuk avatar Jun 26 '24 20:06 potiuk

(and to excuse myself - I DID try it at some point in time, but it did not work then :D )

potiuk avatar Jun 26 '24 20:06 potiuk

One more small comment. I just run it and I think the background is a little too dark. Most of the dark-mode apps I have result with dark-but-not-black background and when I tried Airflow in dark mode it looks pitch-black.

Yeah, that's why I wanted the experimental flag. All this does it invert the colors vs creating a true dark theme. It will be better in Airflow 3.0 :)

bbovenzi avatar Jun 27 '24 18:06 bbovenzi