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

Fix test failures due to newer dep versions

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-11-14 11:43:28 -05:00
parent e76e529f4a
commit 1eaf253205
3 changed files with 37 additions and 22 deletions

View File

@ -0,0 +1,16 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
/**
* Get an ordering function based on the function getter
*/
export function byValue<T>(getOrderValue: (src: T) => number): (left: T, right: T) => number {
return (left, right) => {
const leftValue = getOrderValue(left);
const rightValue = getOrderValue(right);
return leftValue - rightValue;
};
}

View File

@ -20,21 +20,23 @@ const currentKubeObjectInDetailsInjectable = getInjectable({
const urlParam = di.inject(kubeDetailsUrlParamInjectable);
const apiManager = di.inject(apiManagerInjectable);
return asyncComputed(async (): Promise<CurrentKubeObject> => {
const path = urlParam.get();
const store = apiManager.getStore(path);
return asyncComputed({
getValueFromObservedPromise: async (): Promise<CurrentKubeObject> => {
const path = urlParam.get();
const store = apiManager.getStore(path);
if (!store) {
return undefined;
}
if (!store) {
return undefined;
}
try {
const object = await store.loadFromPath(path);
try {
const object = await store.loadFromPath(path);
return { object };
} catch (error) {
return { error: String(error) };
}
return { object };
} catch (error) {
return { error: String(error) };
}
},
});
},
});

View File

@ -6,9 +6,8 @@ import { getInjectable } from "@ogre-tools/injectable";
import { computed } from "mobx";
import { computedInjectManyInjectable } from "@ogre-tools/injectable-extension-for-mobx";
import { filter, map, sortBy } from "lodash/fp";
import { pipeline } from "@ogre-tools/fp";
import { kubeObjectDetailItemInjectionToken } from "./kube-object-detail-item-injection-token";
import { byValue } from "../../../../common/utils/sort-function";
const kubeObjectDetailItemsInjectable = getInjectable({
id: "kube-object-detail-items",
@ -17,14 +16,12 @@ const kubeObjectDetailItemsInjectable = getInjectable({
const computedInjectMany = di.inject(computedInjectManyInjectable);
const items = computedInjectMany(kubeObjectDetailItemInjectionToken);
return computed(() => {
return pipeline(
items.get(),
filter((item) => item.enabled.get()),
sortBy((item) => item.orderNumber),
map((item) => item.Component),
);
});
return computed(() => (
items.get()
.filter(item => item.enabled.get())
.sort(byValue(item => item.orderNumber))
.map(item => item.Component)
));
},
});