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

Adding navigateWithoutHistoryChange() method

Signed-off-by: Alex Andreev <alex.andreev.email@gmail.com>
This commit is contained in:
Alex Andreev 2021-08-05 17:50:23 +03:00
parent 6fdb55ed3a
commit 0824121234
2 changed files with 9 additions and 25 deletions

View File

@ -23,7 +23,7 @@ import "./preferences.scss";
import { makeObservable, observable } from "mobx";
import { observer } from "mobx-react";
import React from "react";
import { matchPath, Redirect, Route, RouteComponentProps, RouteProps, Switch } from "react-router";
import { matchPath, Redirect, Route, RouteProps, Switch } from "react-router";
import {
appRoute,
@ -39,7 +39,7 @@ import {
telemetryURL,
} from "../../../common/routes";
import { AppPreferenceRegistry, RegisteredAppPreference } from "../../../extensions/registries/app-preference-registry";
import { navigate, navigation } from "../../navigation";
import { navigateWithoutHistoryChange, navigation } from "../../navigation";
import { SettingLayout } from "../layout/setting-layout";
import { SubTitle } from "../layout/sub-title";
import { Tab, Tabs } from "../tabs";
@ -47,42 +47,23 @@ import { Application } from "./application";
import { Kubernetes } from "./kubernetes";
import { LensProxy } from "./proxy";
import { Telemetry } from "./telemetry";
import { boundMethod } from "autobind-decorator";
interface Props extends RouteComponentProps<any> {
}
@observer
export class Preferences extends React.Component<Props> {
export class Preferences extends React.Component {
@observable historyLength: number | undefined;
constructor(props: Props) {
constructor(props: {}) {
super(props);
makeObservable(this);
}
componentDidMount() {
this.historyLength = this.props.history?.length;
}
@boundMethod
onClose() {
const stepsToGoBack = navigation.length - this.historyLength + 1;
if (isNaN(stepsToGoBack)) {
navigation.goBack();
} else {
navigation.go(-stepsToGoBack);
}
}
renderNavigation() {
const extensions = AppPreferenceRegistry.getInstance().getItems().filter(e => !e.showInPreferencesTab);
const currentLocation = navigation.location.pathname;
const isActive = (route: RouteProps) => !!matchPath(currentLocation, { path: route.path, exact: route.exact });
return (
<Tabs className="flex column" scrollable={false} onChange={(url) => navigate(url)}>
<Tabs className="flex column" scrollable={false} onChange={(url) => navigateWithoutHistoryChange({ pathname: url })}>
<div className="header">Preferences</div>
<Tab value={appURL()} label="Application" data-testid="application-tab" active={isActive(appRoute)}/>
<Tab value={proxyURL()} label="Proxy" data-testid="proxy-tab" active={isActive(proxyRoute)}/>
@ -101,7 +82,6 @@ export class Preferences extends React.Component<Props> {
navigation={this.renderNavigation()}
className="Preferences"
contentGaps={false}
back={this.onClose}
>
<Switch>
<Route path={appURL()} component={Application}/>

View File

@ -38,6 +38,10 @@ export function navigate(location: LocationDescriptor) {
}
}
export function navigateWithoutHistoryChange(location: Partial<Location>) {
navigation.merge(location, true);
}
export function createPageParam<V = string>(init: PageParamInit<V>) {
return new PageParam<V>(init, navigation);
}