Skip to content

Commit 2254576

Browse files
authored
fix container ports sorting (#776)
1 parent b286e75 commit 2254576

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

frontend/src/components/util.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,23 @@ export const DockerContainersSection = ({
916916
{
917917
accessorKey: "ports.0",
918918
size: 200,
919+
sortingFn: (a, b) => {
920+
const getMinHostPort = (row: typeof a) => {
921+
const ports = row.original.ports ?? [];
922+
if (!ports.length) return Number.POSITIVE_INFINITY;
923+
const nums = ports
924+
.map((p) => p.PublicPort)
925+
.filter((p): p is number => typeof p === "number")
926+
.map((n) => Number(n));
927+
if (!nums.length || nums.some((n) => Number.isNaN(n))) {
928+
return Number.POSITIVE_INFINITY;
929+
}
930+
return Math.min(...nums);
931+
};
932+
const pa = getMinHostPort(a);
933+
const pb = getMinHostPort(b);
934+
return pa === pb ? 0 : pa > pb ? 1 : -1;
935+
},
919936
header: ({ column }) => (
920937
<SortableHeader column={column} title="Ports" />
921938
),

frontend/src/pages/containers.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,23 @@ export default function ContainersPage() {
162162
{
163163
accessorKey: "ports.0",
164164
size: 200,
165+
sortingFn: (a, b) => {
166+
const getMinHostPort = (row: typeof a) => {
167+
const ports = row.original.ports ?? [];
168+
if (!ports.length) return Number.POSITIVE_INFINITY;
169+
const nums = ports
170+
.map((p) => p.PublicPort)
171+
.filter((p): p is number => typeof p === "number")
172+
.map((n) => Number(n));
173+
if (!nums.length || nums.some((n) => Number.isNaN(n))) {
174+
return Number.POSITIVE_INFINITY;
175+
}
176+
return Math.min(...nums);
177+
};
178+
const pa = getMinHostPort(a);
179+
const pb = getMinHostPort(b);
180+
return pa === pb ? 0 : pa > pb ? 1 : -1;
181+
},
165182
header: ({ column }) => (
166183
<SortableHeader column={column} title="Ports" />
167184
),

0 commit comments

Comments
 (0)