mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Default PageRegistration.routePath to path based on id (#1374)
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
648dbfee98
commit
0fb859a22a
@ -28,4 +28,8 @@ describe("getPageUrl", () => {
|
|||||||
ext.manifest.name = "@foo/bar"
|
ext.manifest.name = "@foo/bar"
|
||||||
expect(getPageUrl(ext)).toBe("/extension/foo-bar")
|
expect(getPageUrl(ext)).toBe("/extension/foo-bar")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("adds / prefix", () => {
|
||||||
|
expect(getPageUrl(ext, "test")).toBe("/extension/foo-bar/test")
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@ -18,11 +18,6 @@ export interface PageMenuRegistration {
|
|||||||
components: PageMenuComponents;
|
components: PageMenuComponents;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PageSubMenuRegistration {
|
|
||||||
url: string;
|
|
||||||
title: React.ReactNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PageMenuComponents {
|
export interface PageMenuComponents {
|
||||||
Icon: React.ComponentType<IconProps>;
|
Icon: React.ComponentType<IconProps>;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,12 +14,6 @@ export interface PageRegistration {
|
|||||||
components: PageComponents;
|
components: PageComponents;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SubPageRegistration {
|
|
||||||
routePath: string; // required for sub-pages
|
|
||||||
exact?: boolean;
|
|
||||||
components: PageComponents;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PageComponents {
|
export interface PageComponents {
|
||||||
Page: React.ComponentType<any>;
|
Page: React.ComponentType<any>;
|
||||||
}
|
}
|
||||||
@ -27,6 +21,9 @@ export interface PageComponents {
|
|||||||
const routePrefix = "/extension/:name"
|
const routePrefix = "/extension/:name"
|
||||||
|
|
||||||
export function getPageUrl(ext: LensExtension, baseUrl = "") {
|
export function getPageUrl(ext: LensExtension, baseUrl = "") {
|
||||||
|
if (baseUrl !== "" && !baseUrl.startsWith("/")) {
|
||||||
|
baseUrl = "/" + baseUrl
|
||||||
|
}
|
||||||
const validUrlName = ext.name.replace("@", "").replace("/", "-");
|
const validUrlName = ext.name.replace("@", "").replace("/", "-");
|
||||||
return compile(routePrefix)({ name: validUrlName }) + baseUrl;
|
return compile(routePrefix)({ name: validUrlName }) + baseUrl;
|
||||||
}
|
}
|
||||||
@ -35,9 +32,12 @@ export class PageRegistry<T extends PageRegistration> extends BaseRegistry<T> {
|
|||||||
|
|
||||||
@action
|
@action
|
||||||
add(items: T[], ext?: LensExtension) {
|
add(items: T[], ext?: LensExtension) {
|
||||||
const normalizedItems = items.map((i) => {
|
const normalizedItems = items.map((page) => {
|
||||||
i.routePath = getPageUrl(ext, i.routePath)
|
if (!page.routePath) {
|
||||||
return i
|
page.routePath = `/${page.id}`
|
||||||
|
}
|
||||||
|
page.routePath = getPageUrl(ext, page.routePath)
|
||||||
|
return page
|
||||||
})
|
})
|
||||||
return super.add(normalizedItems);
|
return super.add(normalizedItems);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user