From 80608995b34880b40f135293d46258af31f453ec Mon Sep 17 00:00:00 2001 From: Brent Bovenzi Date: Thu, 7 Nov 2024 16:12:31 -0500 Subject: [PATCH] Make sure a default sort is persisted through tableUrlState (#43803) --- .../components/DataTable/searchParams.test.ts | 19 +++++++++++++++++++ .../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 b04fe668db5c2..b14bf954e96f6 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 39001b097f349..1308a2f31e42e 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 }; };