mirror of
https://github.com/fosrl/pangolin.git
synced 2026-05-23 01:05:27 +00:00
⚡️ prevent SitetableCell from rerendering unnecessarily
This commit is contained in:
@@ -45,6 +45,7 @@ import { usePathname, useRouter } from "next/navigation";
|
|||||||
import {
|
import {
|
||||||
startTransition,
|
startTransition,
|
||||||
useEffect,
|
useEffect,
|
||||||
|
useMemo,
|
||||||
useOptimistic,
|
useOptimistic,
|
||||||
useState,
|
useState,
|
||||||
useTransition
|
useTransition
|
||||||
@@ -180,7 +181,8 @@ export default function SitesTable({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const columns: ExtendedColumnDef<SiteRow>[] = [
|
const columns = useMemo<ExtendedColumnDef<SiteRow>[]>(() => {
|
||||||
|
const cols: ExtendedColumnDef<SiteRow>[] = [
|
||||||
{
|
{
|
||||||
accessorKey: "name",
|
accessorKey: "name",
|
||||||
enableHiding: false,
|
enableHiding: false,
|
||||||
@@ -470,26 +472,6 @@ export default function SitesTable({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
...(isLabelFeatureEnabled
|
|
||||||
? [
|
|
||||||
{
|
|
||||||
accessorKey: "labels",
|
|
||||||
header: () => (
|
|
||||||
<span className="p-3 text-end w-full inline-block">
|
|
||||||
{t("labels")}
|
|
||||||
</span>
|
|
||||||
),
|
|
||||||
cell: ({ row }: { row: { original: SiteRow } }) => {
|
|
||||||
return (
|
|
||||||
<SiteLabelCell
|
|
||||||
site={row.original}
|
|
||||||
orgId={orgId}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
: []),
|
|
||||||
{
|
{
|
||||||
id: "actions",
|
id: "actions",
|
||||||
enableHiding: false,
|
enableHiding: false,
|
||||||
@@ -544,7 +526,24 @@ export default function SitesTable({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (isLabelFeatureEnabled) {
|
||||||
|
cols.splice(cols.length - 1, 0, {
|
||||||
|
accessorKey: "labels",
|
||||||
|
header: () => (
|
||||||
|
<span className="p-3 text-end w-full inline-block">
|
||||||
|
{t("labels")}
|
||||||
|
</span>
|
||||||
|
),
|
||||||
|
cell: ({ row }: { row: { original: SiteRow } }) => (
|
||||||
|
<SiteLabelCell site={row.original} orgId={orgId} />
|
||||||
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return cols;
|
||||||
|
}, [isLabelFeatureEnabled, orgId, t, searchParams]);
|
||||||
|
|
||||||
function toggleSort(column: string) {
|
function toggleSort(column: string) {
|
||||||
const newSearch = getNextSortOrder(column, searchParams);
|
const newSearch = getNextSortOrder(column, searchParams);
|
||||||
|
|||||||
Reference in New Issue
Block a user