mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-04 10:05:53 +02:00
add datasize helper and add correct sorting to sitestable
This commit is contained in:
parent
0e4f35e87a
commit
26207bd951
2 changed files with 24 additions and 2 deletions
|
@ -27,6 +27,7 @@ import { formatAxiosError } from "@app/lib/api";
|
|||
import { createApiClient } from "@app/lib/api";
|
||||
import { useEnvContext } from "@app/hooks/useEnvContext";
|
||||
import CreateSiteFormModal from "./CreateSiteModal";
|
||||
import { parseDataSize } from '@app/lib/dataSize';
|
||||
|
||||
export type SiteRow = {
|
||||
id: number;
|
||||
|
@ -197,7 +198,12 @@ export default function SitesTable({ sites, orgId }: SitesTableProps) {
|
|||
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
},
|
||||
sortingFn: (rowA, rowB) => {
|
||||
const a = parseDataSize(rowA.original.mbIn);
|
||||
const b = parseDataSize(rowB.original.mbIn);
|
||||
return a > b ? 1 : a < b ? -1 : 0;
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: "mbOut",
|
||||
|
@ -213,7 +219,12 @@ export default function SitesTable({ sites, orgId }: SitesTableProps) {
|
|||
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
},
|
||||
sortingFn: (rowA, rowB) => {
|
||||
const a = parseDataSize(rowA.original.mbOut);
|
||||
const b = parseDataSize(rowB.original.mbOut);
|
||||
return a > b ? 1 : a < b ? -1 : 0;
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: "type",
|
||||
|
|
11
src/lib/dataSize.ts
Normal file
11
src/lib/dataSize.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
export function parseDataSize(sizeStr: string): number {
|
||||
if (!sizeStr) return 0;
|
||||
const match = sizeStr.trim().toUpperCase().match(/^([\d.]+)\s*([KMGT]?B)$/);
|
||||
if (!match) return 0;
|
||||
const [, numStr, unit] = match;
|
||||
const num = parseFloat(numStr) || 0;
|
||||
const multipliers: Record<string, number> = {
|
||||
B: 1, KB: 1024, MB: 1024**2, GB: 1024**3, TB: 1024**4,
|
||||
};
|
||||
return num * (multipliers[unit] || 1);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue