Skip to content

Commit

Permalink
Make sure a default sort is persisted through tableUrlState (apache#4…
Browse files Browse the repository at this point in the history
  • Loading branch information
bbovenzi authored Nov 7, 2024
1 parent af0837c commit 8060899
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
19 changes: 19 additions & 0 deletions airflow/ui/src/components/DataTable/searchParams.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe("searchParams", () => {
);
});
});

describe("searchParamsToState", () => {
it("can parse search params back to table state", () => {
expect(
Expand All @@ -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" }],
});
});
});
});
4 changes: 3 additions & 1 deletion airflow/ui/src/components/DataTable/searchParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ export const searchParamsToState = (
id: sort.replace("-", ""),
}));

urlState = { ...urlState, sorting };
if (sorting.length) {
urlState = { ...urlState, sorting };
}

return { ...defaultState, ...urlState };
};

0 comments on commit 8060899

Please sign in to comment.