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:
parent
885af07d0b
commit
f03134225e
@ -26,6 +26,7 @@ import { observer } from "mobx-react";
|
|||||||
import { BaseRegistry } from "./base-registry";
|
import { BaseRegistry } from "./base-registry";
|
||||||
import { LensExtension, LensExtensionId, sanitizeExtensionName } from "../lens-extension";
|
import { LensExtension, LensExtensionId, sanitizeExtensionName } from "../lens-extension";
|
||||||
import { createPageParam, PageParam, PageParamInit, searchParamsOptions } from "../../renderer/navigation";
|
import { createPageParam, PageParam, PageParamInit, searchParamsOptions } from "../../renderer/navigation";
|
||||||
|
import { computed, observable } from "mobx";
|
||||||
|
|
||||||
export interface PageRegistration {
|
export interface PageRegistration {
|
||||||
/**
|
/**
|
||||||
@ -92,6 +93,8 @@ export function getExtensionPageUrl(target: PageTarget): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class PageRegistry extends BaseRegistry<PageRegistration, RegisteredPage> {
|
class PageRegistry extends BaseRegistry<PageRegistration, RegisteredPage> {
|
||||||
|
protected knownUrls = observable.set<string>();
|
||||||
|
|
||||||
protected getRegisteredItem(page: PageRegistration, ext: LensExtension): RegisteredPage {
|
protected getRegisteredItem(page: PageRegistration, ext: LensExtension): RegisteredPage {
|
||||||
const { id: pageId } = page;
|
const { id: pageId } = page;
|
||||||
const extensionId = ext.name;
|
const extensionId = ext.name;
|
||||||
@ -99,6 +102,8 @@ class PageRegistry extends BaseRegistry<PageRegistration, RegisteredPage> {
|
|||||||
const components = this.normalizeComponents(page.components, params);
|
const components = this.normalizeComponents(page.components, params);
|
||||||
const url = getExtensionPageUrl({ extensionId, pageId });
|
const url = getExtensionPageUrl({ extensionId, pageId });
|
||||||
|
|
||||||
|
this.knownUrls.add(url);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: pageId, extensionId, params, components, url,
|
id: pageId, extensionId, params, components, url,
|
||||||
};
|
};
|
||||||
@ -135,10 +140,7 @@ class PageRegistry extends BaseRegistry<PageRegistration, RegisteredPage> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (notAStringValue && !(parse || stringify)) {
|
if (notAStringValue && !(parse || stringify)) {
|
||||||
throw new Error(
|
throw new Error(`PageRegistry: param's "${paramName}" initialization has failed: paramInit.parse() and paramInit.stringify() are required for non string | string[] "defaultValue"`);
|
||||||
`PageRegistry: param's "${paramName}" initialization has failed:
|
|
||||||
paramInit.parse() and paramInit.stringify() are required for non string | string[] "defaultValue"`,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
paramInit.defaultValue = value;
|
paramInit.defaultValue = value;
|
||||||
@ -152,6 +154,13 @@ class PageRegistry extends BaseRegistry<PageRegistration, RegisteredPage> {
|
|||||||
return normalizedParams;
|
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 {
|
getByPageTarget(target: PageTarget): RegisteredPage | null {
|
||||||
return this.getItems().find(page => page.extensionId === target.extensionId && page.id === target.pageId) || null;
|
return this.getItems().find(page => page.extensionId === target.extensionId && page.id === target.pageId) || null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -211,6 +211,12 @@ export class ClusterFrame extends React.Component {
|
|||||||
{this.renderExtensionTabLayoutRoutes()}
|
{this.renderExtensionTabLayoutRoutes()}
|
||||||
{this.renderExtensionRoutes()}
|
{this.renderExtensionRoutes()}
|
||||||
<Redirect exact from="/" to={this.startUrl}/>
|
<Redirect exact from="/" to={this.startUrl}/>
|
||||||
|
{
|
||||||
|
ClusterPageRegistry
|
||||||
|
.getInstance()
|
||||||
|
.redirectEntries
|
||||||
|
.map(url => <Redirect key={url} from={url} to={this.startUrl} />)
|
||||||
|
}
|
||||||
<Route component={NotFound}/>
|
<Route component={NotFound}/>
|
||||||
</Switch>
|
</Switch>
|
||||||
</MainLayout>
|
</MainLayout>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user