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

refactoring + fix subPages routePath

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2020-11-13 10:26:49 +02:00
parent 97068f4c07
commit ac9adfbbb8
5 changed files with 18 additions and 15 deletions

View File

@ -44,13 +44,9 @@ export class LensExtension {
return this.manifest.description
}
getPageUrl(baseUrl = "") {
getPageRoute(suffixPathOrUrl = "") {
const validUrlName = this.name.replace("@", "").replace("/", "-");
return compile(this.routePrefix)({ name: validUrlName }) + baseUrl;
}
getPageRoute(baseRoute = "") {
return this.getPageUrl() + baseRoute;
return compile(this.routePrefix)({ name: validUrlName }) + suffixPathOrUrl;
}
@action

View File

@ -8,7 +8,7 @@ export class LensMainExtension extends LensExtension {
async navigate(location?: string, frameId?: number) {
const windowManager = WindowManager.getInstance<WindowManager>();
const url = this.getPageUrl(location); // get full path to extension's page
const url = this.getPageRoute(location); // get full path to extension's page
await windowManager.navigate(url, frameId);
}
}

View File

@ -16,6 +16,6 @@ export class LensRendererExtension extends LensExtension {
async navigate(location?: string) {
const { navigate } = await import("../renderer/navigation");
navigate(this.getPageUrl(location));
navigate(this.getPageRoute(location));
}
}

View File

@ -23,10 +23,10 @@ export interface PageMenuComponents {
export class PageMenuRegistry<T extends PageMenuRegistration> extends BaseRegistry<T> {
getItems() {
return super.getItems().map(item => {
item.url = item.extension.getPageUrl(item.url)
return item
});
return super.getItems().map(menuItem => ({
...menuItem,
url: menuItem.extension.getPageRoute(menuItem.url),
}));
}
}

View File

@ -22,9 +22,16 @@ export interface PageComponents {
export class PageRegistry<T extends PageRegistration> extends BaseRegistry<T> {
getItems() {
return super.getItems().map(item => {
item.routePath = item.extension.getPageRoute(item.routePath)
return item
return super.getItems().map(page => {
const pageRoute = page.extension.getPageRoute(page.routePath);
return {
...page,
routePath: pageRoute,
subPages: page?.subPages?.map(subPage => ({
...subPage,
routePath: pageRoute + subPage.routePath
}))
}
});
}
}