-
Notifications
You must be signed in to change notification settings - Fork 16.3k
[AIRFLOW-3967] Extract Jinja directive from Javascript #4787
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
Conversation
53394a9 to
4bdf387
Compare
potiuk
left a comment
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.
Nice simplification of the UI variables. Enables more improvements in the UI code.
4bdf387 to
3e705b9
Compare
|
I finished my work. It looks good to me. However, I encourage you to submit your suggestions. @ashb Can I ask for review? |
aff94be to
223bc2d
Compare
5416927 to
553c368
Compare
Codecov Report
@@ Coverage Diff @@
## master #4787 +/- ##
==========================================
- Coverage 80.02% 78.35% -1.68%
==========================================
Files 594 467 -127
Lines 34769 29771 -4998
==========================================
- Hits 27824 23326 -4498
+ Misses 6945 6445 -500
Continue to review full report at Codecov.
|
|
I'd use |
|
Not all variables have an assigned element. in other cases, this will complicate the code unnecessarily ex. csrf token. In other cases, I will try to introduce your change. |
|
You can add new empty html span tags, just the way you introduced the meta tags in the PR. |
|
I do not know if adding empty elements in a body is a good idea. HEAD better describes the purpose and use of the code. It is clearer for me.
The CSRF token is not associated with a specific document element, but it's a metadata for current page. The fact that there is a function in jQuery is not a reason for me to use it. |
|
True, that the CSRF token here is a metadata and not associated with any element. That was just an idea to use the empty tags, you can of course use data attributes on the top container as this is more relevant there. Up to you how you want to handle this. |
21600b7 to
ac2586a
Compare
|
@ashb i updated a PR.Now, code bluring is done without JS. Hostname/Clock code has been simplified |
ac2586a to
b7e9b84
Compare
ec8e226 to
77d40a2
Compare
|
I'd love to see this get merged. In #4893 (adding time-zone support on the UI), I've also been wrestling with how to invoke Javascript functions with Jinja-templated variables supplied by the server as arguments. The approach I settled on was to expose these functions in a webpack library and invoke them from inline scripts (example). The approach in this PR seems cleaner though, since it gets rid of inline scripting altogether. |
|
I chose the easiest way ( |
505b1a0 to
b18bbc0
Compare
|
@mik-laj -> are you still working on that? I will be happy to take a look once it is ready. |
|
@potiuk Yes. I'm working on it. I think it's finished, but I did not have time to make sure it was merged. In addition, the previous commiter was busy preparing a new release of Airflow and I did not want to take his time. |
b18bbc0 to
7e8fb7f
Compare
|
@mik-laj BTW I found when looking for something else that Flask-AppBuilder has inline script tags too, so to enforce our CSP policy we'd need to do a bit of work there in that project too (or to customize the base templates further) |
|
@ashb, in the future, we can also deal with this problem. It's important to me that ESLInt will work right now. I want to do small steps to improve Javascript code |
|
@mik-laj absolutely. I just mentioning it before I forget. Looking at this right now. |
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.
This doesn't have | tojson on it - should it? Also how does this cope with a double-quote in the variable somewher?
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.
Quoting should be fine then, but I do think we need tojson on all of these (think, but an not certain)
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.
Now the quotation mark can not appear in the name of the dag.
If I tried to do it, I got an error message.
airflow.exceptions.AirflowException: The key (example_bash_operator">Awesome) has to be made of alphanumeric characters, dashes, dots and underscores exclusively
I have changed the value of the dag_id field in a function from views.py file to show this problem.
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.
| tojson on all of these too?
ashb
left a comment
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.
Questions about escaping - I'm not sure they are needed or not but please verify.
And I think util.js is now include twice on many pages.
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.
Dup include?
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.
We have already discussed this in the past.
#4787 (comment)
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.
We have already discussed this in the past. Double imports in rendered file mean that this views needs libraries several times in several views. This will be more readable when the code will be in separate files and we could use a "import" statement. Currently, we must use such syntax.
#4787 (comment)
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.
We have already discussed this in the past. Double imports in rendered file mean that this views needs libraries several times in several views. This will be more readable when the code will be in separate files and we could use a "import" statement. Currently, we must use such syntax.
#4787 (comment)
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.
Given this is inline it won't be compiled: what browsers do/don't support const? (I'm way out of date with what is ES "Next" and what is widely supported now)
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.
If we accept this patch, in the next change I will extract the Javascript code into separate files to be able to compile it into old browsers - babel. New JS features are too widely accepted in the community to write code in old standards.
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.
In addition, your suggestion is not compatible with the code rules adopted in the project. This project follow the Airbnb recommendation
https://github.com/apache/airflow/blob/master/CONTRIBUTING.md#javascript-style-guide
2.1 Use const for all of your references; avoid using var. eslint: prefer-const, no-const-assign
2.2 If you must reassign references, use let instead of var. eslint: no-var
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.
Introduction your suggestion will also add confusion in the code, because the "var" syntax is used in the same file. The code does not work on older versions of the Internet Explorer. However, there are a lot of reasons why this does not work and the best solution is to extract the code for separate files and transpile all JS using Babel. Transpilation will allow the developer to use new syntax and functionality, but browsers will execute code that conforms to the old standards.
Please note that some of the JS code is currently being transpiled.
https://github.com/apache/airflow/blob/master/airflow/www/package.json#L29-L34
This is not a problem that we want to solve in this PR. The JS code has many issues that have to be gradually solved.
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.
Summary: In the current state of the code, we can not worry about unsupported browsers. Support for other browsers can be introduced in a separate PR.
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 hope that the arguments will be fine for you.
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.
Dup include?
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.
We have already discussed this in the past. Double imports in rendered file mean that this views needs libraries several times in several views. This will be more readable when the code will be in separate files and we could use a "import" statement. Currently, we must use such syntax.
#4787 (comment)
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.
Dup include?
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.
We have already discussed this in the past. Double imports in rendered file mean that this views needs libraries several times in several views. This will be more readable when the code will be in separate files and we could use a "import" statement. Currently, we must use such syntax.
#4787 (comment)
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.
We have two identical script tags - once here and again in the top level template. Even ignoring import statement we don't need a duplicate script tag do we?
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.
| tojson?
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 updated a PR. Now this PR use | tojson | forceescape to make the code more explict.
7e8fb7f to
b1edcff
Compare
|
What's the status of this PR? |
|
Do you want to work on it? Unfortunately, I'm busy and I don't have time to finish it. I will be happy if someone take my changes and finishes them. I am going on vacation in 5 hours, so I will be AFK for a week. |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |

Make sure you have checked all steps below.
Jira
Description
The current state is unexpected because:
As a next step, I would like to:
For a long-term goal, I would like to
@jmcarp I saw that you changed HTML / JS files recently. What do you think about the change and plans for the future? Does what I want to do in the future make sense for you?
Tests
Commits
Documentation
Code Quality
flake8