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

Reroute to landing page from previously registered extension cluster pages

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-11-18 16:53:35 -05:00
parent 885af07d0b
commit f03134225e
2 changed files with 19 additions and 4 deletions

View File

@ -26,6 +26,7 @@ import { observer } from "mobx-react";
import { BaseRegistry } from "./base-registry";
import { LensExtension, LensExtensionId, sanitizeExtensionName } from "../lens-extension";
import { createPageParam, PageParam, PageParamInit, searchParamsOptions } from "../../renderer/navigation";
import { computed, observable } from "mobx";
export interface PageRegistration {
/**
@ -92,6 +93,8 @@ export function getExtensionPageUrl(target: PageTarget): string {
}
class PageRegistry extends BaseRegistry<PageRegistration, RegisteredPage> {
protected knownUrls = observable.set<string>();
protected getRegisteredItem(page: PageRegistration, ext: LensExtension): RegisteredPage {
const { id: pageId } = page;
const extensionId = ext.name;
@ -99,6 +102,8 @@ class PageRegistry extends BaseRegistry<PageRegistration, RegisteredPage> {
const components = this.normalizeComponents(page.components, params);
const url = getExtensionPageUrl({ extensionId, pageId });
this.knownUrls.add(url);
return {
id: pageId, extensionId, params, components, url,
};
@ -135,10 +140,7 @@ class PageRegistry extends BaseRegistry<PageRegistration, RegisteredPage> {
);
if (notAStringValue && !(parse || stringify)) {
throw new Error(
`PageRegistry: param's "${paramName}" initialization has failed:
paramInit.parse() and paramInit.stringify() are required for non string | string[] "defaultValue"`,
);
throw new Error(`PageRegistry: param's "${paramName}" initialization has failed: paramInit.parse() and paramInit.stringify() are required for non string | string[] "defaultValue"`);
}
paramInit.defaultValue = value;
@ -152,6 +154,13 @@ class PageRegistry extends BaseRegistry<PageRegistration, RegisteredPage> {
return normalizedParams;
}
/**
* Get the list of all known URLS that have been registered with this registry.
*/
@computed get redirectEntries() {
return [...this.knownUrls];
}
getByPageTarget(target: PageTarget): RegisteredPage | null {
return this.getItems().find(page => page.extensionId === target.extensionId && page.id === target.pageId) || null;
}

View File

@ -211,6 +211,12 @@ export class ClusterFrame extends React.Component {
{this.renderExtensionTabLayoutRoutes()}
{this.renderExtensionRoutes()}
<Redirect exact from="/" to={this.startUrl}/>
{
ClusterPageRegistry
.getInstance()
.redirectEntries
.map(url => <Redirect key={url} from={url} to={this.startUrl} />)
}
<Route component={NotFound}/>
</Switch>
</MainLayout>