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