From 2b24a4288380d5dfe8d871db07f13db0a087c048 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Tue, 2 Aug 2022 09:44:32 -0700 Subject: [PATCH] Fix Pod Container sorting not correlating to visuals (#5175) --- src/common/utils/tuple.ts | 5 +++-- src/renderer/components/+workloads-pods/pods.tsx | 2 +- src/renderer/components/table/__tests__/getSorted.test.ts | 4 ++-- src/renderer/components/table/sorting.ts | 5 ++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/common/utils/tuple.ts b/src/common/utils/tuple.ts index 2714ec23fa..1268678617 100644 --- a/src/common/utils/tuple.ts +++ b/src/common/utils/tuple.ts @@ -24,8 +24,9 @@ type TupleOfImpl = R["length"] extends * @yields A tuple of the next element from each of the sources * @returns The tuple of all the sources as soon as at least one of the sources is exausted */ -export function zip(src1: T[]): Iterator<[T], Tuple>; -export function zip(src1: T[], src2: T[]): Iterator<[T, T], Tuple>; +export function zip(...sources: Tuple): Iterator, Tuple>; +export function zip(...sources: Tuple): Iterator, Tuple>; +export function zip(...sources: Tuple): Iterator, Tuple>; export function* zip(...sources: Tuple): Iterator, Tuple> { const maxSafeLength = Math.min(...sources.map(source => source.length)); diff --git a/src/renderer/components/+workloads-pods/pods.tsx b/src/renderer/components/+workloads-pods/pods.tsx index b1b7f8cdac..147353f6d6 100644 --- a/src/renderer/components/+workloads-pods/pods.tsx +++ b/src/renderer/components/+workloads-pods/pods.tsx @@ -113,7 +113,7 @@ class NonInjectedPods extends React.Component { sortingCallbacks={{ [columnId.name]: pod => getConvertedParts(pod.getName()), [columnId.namespace]: pod => pod.getNs(), - [columnId.containers]: pod => pod.getContainers().length, + [columnId.containers]: pod => pod.getContainerStatuses().length, [columnId.restarts]: pod => pod.getRestartsCount(), [columnId.owners]: pod => pod.getOwnerRefs().map(ref => ref.kind), [columnId.qos]: pod => pod.getQosClass(), diff --git a/src/renderer/components/table/__tests__/getSorted.test.ts b/src/renderer/components/table/__tests__/getSorted.test.ts index 2724f2a61f..e05063c320 100644 --- a/src/renderer/components/table/__tests__/getSorted.test.ts +++ b/src/renderer/components/table/__tests__/getSorted.test.ts @@ -26,10 +26,10 @@ describe("Table tests", () => { expect(i).toStrictEqual([1, 2, 4, 3]); }); - it("should sort numerically asc (by defaul) and not touch the original list", () => { + it("should sort numerically asc (by default) and not touch the original list", () => { const i = [1, 2, 4, 3]; - expect(getSorted(i, v => v, "foobar")).toStrictEqual([1, 2, 3, 4]); + expect(getSorted(i, v => v)).toStrictEqual([1, 2, 3, 4]); expect(i).toStrictEqual([1, 2, 4, 3]); }); diff --git a/src/renderer/components/table/sorting.ts b/src/renderer/components/table/sorting.ts index 370c3733c2..828ae1e378 100644 --- a/src/renderer/components/table/sorting.ts +++ b/src/renderer/components/table/sorting.ts @@ -3,15 +3,14 @@ * Licensed under MIT License. See LICENSE in root directory for more information. */ -import type { TableSortCallback } from "./table"; +import type { TableOrderBy, TableSortCallback } from "./table"; import { Ordering, rectifyOrdering, sortCompare, tuple } from "../../utils"; -export function getSorted(rawItems: T[], sortingCallback: TableSortCallback | undefined, orderByRaw: string): T[] { +export function getSorted(rawItems: T[], sortingCallback: TableSortCallback | undefined, orderBy: TableOrderBy = "asc"): T[] { if (typeof sortingCallback !== "function") { return rawItems; } - const orderBy = orderByRaw === "asc" || orderByRaw === "desc" ? orderByRaw : "asc"; const sortData = rawItems.map((item, index) => ({ index, sortBy: sortingCallback(item),