You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "uranusjr (via GitHub)" <gi...@apache.org> on 2024/04/11 03:40:18 UTC

Re: [PR] Allow sort by on all fields in MappedInstances.tsx [airflow]

uranusjr commented on code in PR #38090:
URL: https://github.com/apache/airflow/pull/38090#discussion_r1560397252


##########
airflow/api_connexion/endpoints/task_instance_endpoint.py:
##########
@@ -239,16 +239,32 @@ def get_mapped_task_instances(
         .options(joinedload(TI.rendered_task_instance_fields))
     )
 
-    if order_by:
+    if order_by is not None:
         if order_by == "state":
             entry_query = entry_query.order_by(TI.state.asc(), TI.map_index.asc())
         elif order_by == "-state":
             entry_query = entry_query.order_by(TI.state.desc(), TI.map_index.asc())
+        elif order_by == "duration":
+            print("duration")
+            entry_query = entry_query.order_by(TI.duration.asc(), TI.map_index.asc())
+        elif order_by == "-duration":
+            print("-duration")
+            entry_query = entry_query.order_by(TI.duration.desc(), TI.map_index.asc())
+        elif order_by == "start_date":
+            entry_query = entry_query.order_by(TI.start_date.asc(), TI.map_index.asc())
+        elif order_by == "-start_date":
+            entry_query = entry_query.order_by(TI.start_date.desc(), TI.map_index.asc())
+        elif order_by == "end_date":
+            entry_query = entry_query.order_by(TI.end_date.asc(), TI.map_index.asc())
+        elif order_by == "-end_date":
+            entry_query = entry_query.order_by(TI.end_date.desc(), TI.map_index.asc())
         elif order_by == "-map_index":
+            print("map index!!")
             entry_query = entry_query.order_by(TI.map_index.desc())
         else:
             raise BadRequest(detail=f"Ordering with '{order_by}' is not supported")
     else:
+        print("map inde ascx!!")
         entry_query = entry_query.order_by(TI.map_index.asc())

Review Comment:
   We can flatten this to
   
   ```python
   if order is None:
       entry_query = entry_query.order_by(TI.map_index.asc())
   elif order_by == "state":
       entry_query = entry_query.order_by(TI.state.asc(), TI.map_index.asc())
   ... # More...
   ```



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org