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

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


The following commit(s) were added to refs/heads/main by this push:
     new 80608995b34 Make sure a default sort is persisted through 
tableUrlState (#43803)
80608995b34 is described below

commit 80608995b34880b40f135293d46258af31f453ec
Author: Brent Bovenzi <[email protected]>
AuthorDate: Thu Nov 7 16:12:31 2024 -0500

    Make sure a default sort is persisted through tableUrlState (#43803)
---
 .../ui/src/components/DataTable/searchParams.test.ts  | 19 +++++++++++++++++++
 airflow/ui/src/components/DataTable/searchParams.ts   |  4 +++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/airflow/ui/src/components/DataTable/searchParams.test.ts 
b/airflow/ui/src/components/DataTable/searchParams.test.ts
index b04fe668db5..b14bf954e96 100644
--- a/airflow/ui/src/components/DataTable/searchParams.test.ts
+++ b/airflow/ui/src/components/DataTable/searchParams.test.ts
@@ -37,6 +37,7 @@ describe("searchParams", () => {
       );
     });
   });
+
   describe("searchParamsToState", () => {
     it("can parse search params back to table state", () => {
       expect(
@@ -61,5 +62,23 @@ describe("searchParams", () => {
         ],
       });
     });
+
+    it("uses default sort correctly", () => {
+      expect(
+        searchParamsToState(new URLSearchParams("limit=20&offset=0"), {
+          pagination: {
+            pageIndex: 1,
+            pageSize: 5,
+          },
+          sorting: [{ desc: true, id: "when" }],
+        }),
+      ).toEqual({
+        pagination: {
+          pageIndex: 0,
+          pageSize: 20,
+        },
+        sorting: [{ desc: true, id: "when" }],
+      });
+    });
   });
 });
diff --git a/airflow/ui/src/components/DataTable/searchParams.ts 
b/airflow/ui/src/components/DataTable/searchParams.ts
index 39001b097f3..1308a2f31e4 100644
--- a/airflow/ui/src/components/DataTable/searchParams.ts
+++ b/airflow/ui/src/components/DataTable/searchParams.ts
@@ -94,7 +94,9 @@ export const searchParamsToState = (
     id: sort.replace("-", ""),
   }));
 
-  urlState = { ...urlState, sorting };
+  if (sorting.length) {
+    urlState = { ...urlState, sorting };
+  }
 
   return { ...defaultState, ...urlState };
 };

Reply via email to