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

Rework client-side script for connection form. #14052

Merged
merged 2 commits into from Feb 11, 2021

Conversation

yjwong
Copy link
Contributor

@yjwong yjwong commented Feb 3, 2021

Before this, fields on the connection form were dynamically changed by adding and removing the "hide" CSS class. If a provider were to add a field that requires validation (e.g. InputRequired), or if a different field type was used (e.g. NumberField), the entire form would be unsaveable, even if the currently selected connection type had nothing to do with that provider.

This change takes a different approach; upon loading, the DOM elements for all extra fields are saved into a Map, then removed from the DOM tree. When another connection type is selected, these elements are restored into the DOM.

With this change, we still can't use wtforms.validators.InputRequired because of server-side validation, however, a provider can subclass InputRequired and conditionally validate based on connection type. Here's an example:

class InputRequired(wtforms.validators.InputRequired):
    field_flags = ('required', )

    def __call__(self, form, field):
        conn_type = form.conn_type.data
        if conn_type == MyHook.conn_type:
            super().__call__(form, field)

closes: #13985

Note: I wasn't sure about the conventions for JavaScript files here; some lines had semicolons, some didn't. In my change, I just made sure that every line ended with a semicolon, but I didn't want to change the other lines to avoid creating too much noise.

Another thing I'm unsure about is Airflow's browser support policy. This change does away with a lot of jQuery use, instead opting for standard DOM APIs. In particular, Array.from is used, which means that this won't be supported by any version of Internet Explorer. Microsoft themselves are EOLing IE by 17th August 2021 for their own products, so not sure how much of an issue this is.

Before this, fields on the connection form were dynamically changed by
adding and removing the "hide" CSS class. If a provider were to add a
field that requires validation (e.g. InputRequired), or if a different
field type was used (e.g. NumberField), the entire form would be
unsaveable, even if the currently selected connection type had nothing
to do with that provider.

This change takes a different approach; upon loading, the DOM elements
for all extra fields are saved into a Map, then removed from the DOM
tree. When another connection type is selected, these elements are
restored into the DOM.
@boring-cyborg boring-cyborg bot added area:UI Related to UI/UX. For Frontend Developers. area:webserver Webserver related Issues labels Feb 3, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Feb 3, 2021

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 Contribution Guide (https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst)
Here are some useful points:

  • Pay attention to the quality of your code (flake8, pylint 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.
    Apache Airflow is a community-driven project and together we are making it better 🚀.
    In case of doubts contact the developers at:
    Mailing List: dev@airflow.apache.org
    Slack: https://s.apache.org/airflow-slack

@yjwong yjwong marked this pull request as draft February 3, 2021 20:37
@bbovenzi
Copy link
Contributor

bbovenzi commented Feb 4, 2021

This is significantly easier to read than the previous jQuery. We already have Array.from() and other es6 syntax elsewhere in the app, so if those are good then there shouldn't be any problem here.

@yjwong yjwong marked this pull request as ready for review February 5, 2021 03:23
Copy link
Contributor

@ryanahamilton ryanahamilton left a comment

Choose a reason for hiding this comment

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

Very nice work @yjwong! I just had one tiny suggestion.

airflow/www/static/js/connection_form.js Outdated Show resolved Hide resolved
Co-authored-by: Ryan Hamilton <ryan@ryanahamilton.com>
@yjwong
Copy link
Contributor Author

yjwong commented Feb 10, 2021

Applied the suggestion, thanks for the review @ryanahamilton!

@github-actions
Copy link

The PR is likely OK to be merged with just subset of tests for default Python and Database versions without running the full matrix of tests, because it does not modify the core of Airflow. If the committers decide that the full tests matrix is needed, they will add the label 'full tests needed'. Then you should rebase to the latest master or amend the last commit of the PR, and push it with --force-with-lease.

@github-actions github-actions bot added the okay to merge It's ok to merge this PR as it does not require more tests label Feb 10, 2021
@ryanahamilton ryanahamilton merged commit 98bbe5a into apache:master Feb 11, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Feb 11, 2021

Awesome work, congrats on your first merged pull request!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:UI Related to UI/UX. For Frontend Developers. area:webserver Webserver related Issues okay to merge It's ok to merge this PR as it does not require more tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't save any connection if provider-provided connection form widgets have fields marked as InputRequired
4 participants