1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Simplify getOrderedVersions

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-11-15 09:57:07 -05:00
parent 9230cadf2c
commit 2a1e3db02d

View File

@ -26,6 +26,7 @@ import { asLegacyGlobalForExtensionApi } from "../../extensions/as-legacy-global
import { apiKubeInjectionToken } from "./api-kube";
import type AbortController from "abort-controller";
import loggerInjectable from "../logger.injectable";
import { matches } from "lodash/fp";
/**
* The options used for creating a `KubeApi`
@ -156,24 +157,12 @@ export interface KubeApiResourceVersionList {
versions: KubeApiResourceVersion[];
}
const getOrderedVersions = (list: KubeApiResourceVersionList): KubeApiResourceVersion[] => {
const result = [
list.preferredVersion,
];
const not = <T>(fn: (val: T) => boolean) => (val: T) => !(fn(val));
for (const version of list.versions) {
if (
version.groupVersion === list.preferredVersion.groupVersion
&& version.version === list.preferredVersion.version
) {
continue;
}
result.push(version);
}
return result;
};
const getOrderedVersions = (list: KubeApiResourceVersionList): KubeApiResourceVersion[] => [
list.preferredVersion,
...list.versions.filter(not(matches(list.preferredVersion))),
];
export type PropagationPolicy = undefined | "Orphan" | "Foreground" | "Background";