chore: improve sorting

This commit is contained in:
Pablo Lara
2024-09-04 09:00:18 +02:00
parent 45f398bf30
commit a1021fbca7
2 changed files with 11 additions and 11 deletions
+6 -2
View File
@@ -16,9 +16,13 @@ export default async function Providers({
}: {
searchParams?: {
query?: string;
page: string;
page?: string;
sort?: string;
filter?: string;
};
}) {
const searchParamsKey = JSON.stringify(searchParams || {});
return (
<>
<Header title="Providers" icon="fluent:cloud-sync-24-regular" />
@@ -28,7 +32,7 @@ export default async function Providers({
<AddProviderModal />
</div>
<Spacer y={6} />
<Suspense key={searchParams?.page} fallback={<SkeletonTableProvider />}>
<Suspense key={searchParamsKey} fallback={<SkeletonTableProvider />}>
<SSRDataTable searchParams={searchParams} />
</Suspense>
</div>
@@ -30,19 +30,15 @@ export const DataTableColumnHeader = <TData, TValue>({
const currentSortParam = searchParams.get("sort");
let newSortParam = "";
if (
!currentSortParam ||
currentSortParam === "" ||
currentSortParam !== param
) {
// Sort ascending for the first time or switch to a different column
newSortParam = `${param}`;
} else if (currentSortParam === param) {
if (currentSortParam === `${param}`) {
// If already sorting ascending, switch to descending
newSortParam = `-${param}`;
} else if (currentSortParam === `-${param}`) {
// If already sorting descending, remove sorting
newSortParam = "";
} else {
// Sort ascending for the first time or switch to a different column
newSortParam = `${param}`;
}
// Construct the new URL with the sorting parameter
@@ -76,7 +72,7 @@ export const DataTableColumnHeader = <TData, TValue>({
<Button
variant="light"
size="md"
className="h-8"
className="text-slate-500 dark:text-slate-400 h-8"
onClick={getToggleSortingHandler}
>
<span>{title}</span>