refactoring + fix subPages routePath

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

No files matched your search

+2 -6
View File
@@ -44,13 +44,9 @@ export class LensExtension {
return this.manifest.description return this.manifest.description
} }
getPageUrl(baseUrl = "") { getPageRoute(suffixPathOrUrl = "") {
const validUrlName = this.name.replace("@", "").replace("/", "-"); const validUrlName = this.name.replace("@", "").replace("/", "-");
return compile(this.routePrefix)({ name: validUrlName }) + baseUrl; return compile(this.routePrefix)({ name: validUrlName }) + suffixPathOrUrl;
}
getPageRoute(baseRoute = "") {
return this.getPageUrl() + baseRoute;
} }
@action @action
+1 -1
View File
@@ -8,7 +8,7 @@ export class LensMainExtension extends LensExtension {
async navigate(location?: string, frameId?: number) { async navigate(location?: string, frameId?: number) {
const windowManager = WindowManager.getInstance<WindowManager>(); 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); await windowManager.navigate(url, frameId);
} }
} }
+1 -1
View File
@@ -16,6 +16,6 @@ export class LensRendererExtension extends LensExtension {
async navigate(location?: string) { async navigate(location?: string) {
const { navigate } = await import("../renderer/navigation"); const { navigate } = await import("../renderer/navigation");
navigate(this.getPageUrl(location)); navigate(this.getPageRoute(location));
} }
} }
@@ -23,10 +23,10 @@ export interface PageMenuComponents {
export class PageMenuRegistry<T extends PageMenuRegistration> extends BaseRegistry<T> { export class PageMenuRegistry<T extends PageMenuRegistration> extends BaseRegistry<T> {
getItems() { getItems() {
return super.getItems().map(item => { return super.getItems().map(menuItem => ({
item.url = item.extension.getPageUrl(item.url) ...menuItem,
return item url: menuItem.extension.getPageRoute(menuItem.url),
}); }));
} }
} }
+10 -3
View File
@@ -22,9 +22,16 @@ export interface PageComponents {
export class PageRegistry<T extends PageRegistration> extends BaseRegistry<T> { export class PageRegistry<T extends PageRegistration> extends BaseRegistry<T> {
getItems() { getItems() {
return super.getItems().map(item => { return super.getItems().map(page => {
item.routePath = item.extension.getPageRoute(item.routePath) const pageRoute = page.extension.getPageRoute(page.routePath);
return item return {
...page,
routePath: pageRoute,
subPages: page?.subPages?.map(subPage => ({
...subPage,
routePath: pageRoute + subPage.routePath
}))
}
}); });
} }
} }