1
0
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:
Jari Kolehmainen 2020-11-13 19:37:03 +02:00 committed by GitHub
parent 648dbfee98
commit 0fb859a22a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 14 deletions

View File

@ -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")
})
}) })

View File

@ -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>;
} }

View File

@ -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);
} }