You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ry...@apache.org on 2021/04/16 21:34:31 UTC

[airflow] branch master updated: Persist tags params in pagination (#15411)

This is an automated email from the ASF dual-hosted git repository.

ryanahamilton pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/master by this push:
     new f878ec6  Persist tags params in pagination (#15411)
f878ec6 is described below

commit f878ec6c599a089a6d7516b7a66eed693f0c9037
Author: Ryan Hamilton <ry...@ryanahamilton.com>
AuthorDate: Fri Apr 16 17:34:10 2021 -0400

    Persist tags params in pagination (#15411)
---
 airflow/www/utils.py    | 21 +++++++++++++--------
 airflow/www/views.py    |  1 +
 tests/www/test_utils.py |  9 +++++++--
 3 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/airflow/www/utils.py b/airflow/www/utils.py
index af964dc..af34536 100644
--- a/airflow/www/utils.py
+++ b/airflow/www/utils.py
@@ -69,10 +69,10 @@ def should_hide_value_for_key(key_name):
 
 def get_params(**kwargs):
     """Return URL-encoded params"""
-    return urlencode({d: v for d, v in kwargs.items() if v is not None})
+    return urlencode({d: v for d, v in kwargs.items() if v is not None}, True)
 
 
-def generate_pages(current_page, num_of_pages, search=None, status=None, window=7):
+def generate_pages(current_page, num_of_pages, search=None, status=None, tags=None, window=7):
     """
     Generates the HTML for a paging component using a similar logic to the paging
     auto-generated by Flask managed views. The paging component defines a number of
@@ -81,7 +81,7 @@ def generate_pages(current_page, num_of_pages, search=None, status=None, window=
     current one in the middle of the pager component. When in the last pages,
     the pages won't scroll and just keep moving until the last page. Pager also contains
     <first, previous, ..., next, last> pages.
-    This component takes into account custom parameters such as search and status,
+    This component takes into account custom parameters such as search, status, and tags
     which could be added to the pages link in order to maintain the state between
     client and server. It also allows to make a bookmark on a specific paging state.
 
@@ -89,6 +89,7 @@ def generate_pages(current_page, num_of_pages, search=None, status=None, window=
     :param num_of_pages: the total number of pages
     :param search: the search query string, if any
     :param status: 'all', 'active', or 'paused'
+    :param tags: array of strings of the current filtered tags
     :param window: the number of pages to be shown in the paging component (7 default)
     :return: the HTML string of the paging component
     """
@@ -127,7 +128,9 @@ def generate_pages(current_page, num_of_pages, search=None, status=None, window=
 
     is_disabled = 'disabled' if current_page <= 0 else ''
 
-    first_node_link = void_link if is_disabled else f'?{get_params(page=0, search=search, status=status)}'
+    first_node_link = (
+        void_link if is_disabled else f'?{get_params(page=0, search=search, status=status, tags=tags)}'
+    )
     output.append(
         first_node.format(
             href_link=first_node_link,
@@ -137,7 +140,7 @@ def generate_pages(current_page, num_of_pages, search=None, status=None, window=
 
     page_link = void_link
     if current_page > 0:
-        page_link = f'?{get_params(page=current_page - 1, search=search, status=status)}'
+        page_link = f'?{get_params(page=current_page - 1, search=search, status=status, tags=tags)}'
 
     output.append(previous_node.format(href_link=page_link, disabled=is_disabled))  # noqa
 
@@ -159,7 +162,7 @@ def generate_pages(current_page, num_of_pages, search=None, status=None, window=
             'is_active': 'active' if is_current(current_page, page) else '',
             'href_link': void_link
             if is_current(current_page, page)
-            else f'?{get_params(page=page, search=search, status=status)}',
+            else f'?{get_params(page=page, search=search, status=status, tags=tags)}',
             'page_num': page + 1,
         }
         output.append(page_node.format(**vals))  # noqa
@@ -169,13 +172,15 @@ def generate_pages(current_page, num_of_pages, search=None, status=None, window=
     page_link = (
         void_link
         if current_page >= num_of_pages - 1
-        else f'?{get_params(page=current_page + 1, search=search, status=status)}'
+        else f'?{get_params(page=current_page + 1, search=search, status=status, tags=tags)}'
     )
 
     output.append(next_node.format(href_link=page_link, disabled=is_disabled))  # noqa
 
     last_node_link = (
-        void_link if is_disabled else f'?{get_params(page=last_page, search=search, status=status)}'
+        void_link
+        if is_disabled
+        else f'?{get_params(page=last_page, search=search, status=status, tags=tags)}'
     )
     output.append(
         last_node.format(
diff --git a/airflow/www/views.py b/airflow/www/views.py
index f5f3b78..5441434 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -653,6 +653,7 @@ class Airflow(AirflowBaseView):  # noqa: D101  pylint: disable=too-many-public-m
                 num_of_pages,
                 search=escape(arg_search_query) if arg_search_query else None,
                 status=arg_status_filter if arg_status_filter else None,
+                tags=arg_tags_filter if arg_tags_filter else None,
             ),
             num_runs=num_runs,
             tags=tags,
diff --git a/tests/www/test_utils.py b/tests/www/test_utils.py
index f4e50d9..f3f2db0 100644
--- a/tests/www/test_utils.py
+++ b/tests/www/test_utils.py
@@ -128,8 +128,13 @@ class TestUtils(unittest.TestCase):
         assert ['a=0', 'c=true'] == pairs
 
     def test_params_all(self):
-        query = utils.get_params(status='active', page=3, search='bash_')
-        assert {'page': ['3'], 'search': ['bash_'], 'status': ['active']} == parse_qs(query)
+        query = utils.get_params(tags=['tag1', 'tag2'], status='active', page=3, search='bash_')
+        assert {
+            'tags': ['tag1', 'tag2'],
+            'page': ['3'],
+            'search': ['bash_'],
+            'status': ['active'],
+        } == parse_qs(query)
 
     def test_params_escape(self):
         assert 'search=%27%3E%22%2F%3E%3Cimg+src%3Dx+onerror%3Dalert%281%29%3E' == utils.get_params(