jedcunningham commented on a change in pull request #11652:
URL: https://github.com/apache/airflow/pull/11652#discussion_r691614791
##########
File path: airflow/www/templates/airflow/dags.html
##########
@@ -20,6 +20,39 @@
{% extends base_template %}
{% from 'appbuilder/loading_dots.html' import loading_dots %}
+{%- macro verbose_ordering_name(ordering) -%}
+ {{ 'descending' if ordering == 'desc' else ('ascending' if ordering ==
'asc' else ordering) }}
+{%- endmacro -%}
+
+{%- macro sorted_th_link(name, attr_name) -%}
+ {% set request_ordering = (request.args.get('orderDir', 'unsorted')) %}
+ {% set curr_ordering = ('unsorted' if request.args.get('orderDir') !=
attr_name else request_ordering ) %}
+ {% set new_ordering = ('asc' if request.args.get('orderDir') != attr_name
or curr_ordering != 'asc' else 'desc' ) %}
Review comment:
```suggestion
{% set curr_ordering = ('unsorted' if request.args.get('orderBy') !=
attr_name else request_ordering ) %}
{% set new_ordering = ('asc' if request.args.get('orderBy') != attr_name
or curr_ordering != 'asc' else 'desc' ) %}
```
##########
File path: tests/www/views/test_views_dags.py
##########
@@ -0,0 +1,77 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+from airflow.models.dag import DagModel
+from airflow.www.views import build_dag_sorting_query, dag_query_for_key,
query_ordering_transform_for_key
+
+
+def test_dag_sorting_query():
+
+ dag_id_query = dag_query_for_key(sorting_key='dag_id')
+ dag_id_query_casetest = dag_query_for_key(sorting_key='dAg_Id')
+
+ assert dag_id_query == DagModel.dag_id
+ assert dag_id_query_casetest == dag_id_query
+
+ owner_query = dag_query_for_key(sorting_key='owner')
+ owner_query_casetest = dag_query_for_key(sorting_key='oWnEr')
+
+ assert owner_query == DagModel.owners
+ assert owner_query != dag_id_query
+ assert owner_query_casetest == owner_query
+
+ schedule_query = dag_query_for_key(sorting_key='next_dagrun')
+
+ assert schedule_query == DagModel.next_dagrun
+ assert schedule_query != dag_id_query
+ assert schedule_query != owner_query
Review comment:
nit: This whole section could utilize `pytest.mark.parameterize` which
would make it cleaner imo, e.g. (untested):
```suggestion
@pytest.mark.parameterize(
"key, expected_query",
[
["dag_id", DagModel.dag_id],
["dAg_Id", DagModel.dag_id],
["owner", DagModel.owners],
["oWnEr", DagModel.owners],
["next_dagrun", DagModel.next_dagrun],
["NEXT_DAGRUN", DagModel.next_dagrun],
]
)
def test_dag_query_for_key(key, expected_query):
assert dag_query_for_key(sorting_key=key) == expected_query
```
The same pattern could be used for `query_ordering_transform_for_key` and
`build_dag_sorting_query`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]