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

Using parseKubeApi instead of new utility

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2023-04-03 15:55:30 +03:00
parent d8b62a10cb
commit b3477a437e
3 changed files with 6 additions and 70 deletions

View File

@ -4,9 +4,7 @@
*/
import { getInjectable } from "@ogre-tools/injectable";
import type { AppEvent } from "../../../common/app-event-bus/event-bus";
import {
getWorkloadKindFromUrl,
} from "../../../renderer/components/kube-detail-params/get-workload-kind-from-url";
import { parseKubeApi } from "../../../common/k8s-api/kube-api-parse";
const navigateTo = [
"navigate-to-preference-tab-id",
@ -96,9 +94,11 @@ const externalActions = ["open-link-in-browser"];
const uiInteraction = [{
id: "show-details",
getParams: (selfLink: unknown) => ({
kind: getWorkloadKindFromUrl(selfLink as string),
}),
getParams: (selfLink: unknown) => {
return {
kind: parseKubeApi(selfLink as string).resource,
};
},
}];
const terminal = ["create-terminal-tab"];

View File

@ -1,50 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getWorkloadKindFromUrl } from "./get-workload-kind-from-url";
describe("getWorkloadKindFromUrl", () => {
it('returns "endpoints" for "/api/v1/namespaces/default/endpoints/kubernetes"', () => {
const str = "/api/v1/namespaces/default/endpoints/kubernetes";
const lastSegment = getWorkloadKindFromUrl(str);
expect(lastSegment).toEqual("endpoints");
});
it('returns "namespaces" for "/api/v1/namespaces/acme-org"', () => {
const str = "/api/v1/namespaces/acme-org";
const lastSegment = getWorkloadKindFromUrl(str);
expect(lastSegment).toEqual("namespaces");
});
it('returns "bar" for "/foo/bar/"', () => {
const str = "/foo/bar/";
const lastSegment = getWorkloadKindFromUrl(str);
expect(lastSegment).toEqual("bar");
});
it('returns null for ""', () => {
const str = "";
const lastSegment = getWorkloadKindFromUrl(str);
expect(lastSegment).toBeNull();
});
it('returns null for "/"', () => {
const str = "/";
const lastSegment = getWorkloadKindFromUrl(str);
expect(lastSegment).toBeNull();
});
it('returns null for "invalidurl"', () => {
const str = "invalidurl";
const lastSegment = getWorkloadKindFromUrl(str);
expect(lastSegment).toBeNull();
});
});

View File

@ -1,14 +0,0 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
export function getWorkloadKindFromUrl(url: string) {
return getLastSegment(url);
}
function getLastSegment(url: string) {
const regex = /\/([^/]*)\/[^/]*$/;
const result = regex.exec(url);
return result ? result[1] : null;
}