Skip to content

Commit 0561f6b

Browse files
authored
Add common app routes to the protocol renderer router (lensapp#2272)
1 parent ca39379 commit 0561f6b

File tree

17 files changed

+129
-33
lines changed

17 files changed

+129
-33
lines changed

docs/clusters/adding-clusters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Add clusters by clicking the **Add Cluster** button in the left-side menu.
44

5-
1. Click the **Add Cluster** button (indicated with a '+' icon).
5+
1. Click the **Add Cluster** button (indicated with a '+' icon). Or [click here](lens://app/cluster).
66
2. Enter the path to your kubeconfig file. You'll need to have a kubeconfig file for the cluster you want to add. You can either browse for the path from the file system or or enter it directly.
77

88
Selected [cluster contexts](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/#context) are added as a separate item in the left-side cluster menu to allow you to operate easily on multiple clusters and/or contexts.

docs/extensions/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Lens Extension API
22

3-
Customize and enhance the Lens experience with the Lens Extension API. Use the extension API to create menus or page content. The same extension API was used to create many of Lens's core features.
3+
Customize and enhance the Lens experience with the Lens Extension API.
4+
Use the extension API to create menus or page content.
5+
The same extension API was used to create many of Lens's core features.
6+
To install your first extension you should goto the [extension page](lens://app/extensions) in lens.
47

58
This documentation describes:
69

docs/getting-started/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,6 @@ To stay current with the Lens features, you can review the [release notes](https
7272

7373
## Next Steps
7474

75+
- [Launch Lens](lens://app/landing)
7576
- [Add clusters](../clusters/adding-clusters.md)
7677
- [Watch introductory videos](./introductory-videos.md)

docs/getting-started/preferences.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
# Preferences
22

3-
43
## Color Themes
54

65
The Color Themes option in Lens preferences lets you set the colors in the Lens user interface to suit your liking.
76

8-
1. Go to **File** > **Preferences** (**Lens** > **Preferences** on Mac).
9-
2. Select your preferred theme from the **Color Theme** dropdown.
7+
1. Go to **File** > **Preferences** (**Lens** > **Preferences** on Mac). Or follow [this link](lens://app/preferences?highlight=appearance).
8+
2. Select your preferred theme from the **Color Theme** dropdown.
109
![Color Theme](images/color-theme.png)
1110

1211

@@ -19,10 +18,9 @@ Lens collects telemetry data, which is used to help us understand how to improve
1918

2019
If you don't wish to send usage data to Mirantis, you can disable the "Telemetry & Usage Tracking" in the Lens preferences.
2120

22-
1. Go to **File** > **Preferences** (**Lens** > **Preferences** on Mac).
21+
1. Go to **File** > **Preferences** (**Lens** > **Preferences** on Mac). Or follow [this link](lens://app/preferences?highlight=telemetry-tracking).
2322
2. Scroll down to **Telemetry & Usage Tracking**
24-
3. Uncheck **Allow Telemetry & Usage Tracking**.
23+
3. Uncheck **Allow Telemetry & Usage Tracking**.
2524

2625
This will silence all telemetry events from Lens going forward. Telemetry information may have been collected and sent up until the point when you disable this setting.
2726
![Disable Telemetry & Usage Tracking](images/disabled-telemetry-usage-tracking.png)
28-

extensions/telemetry/renderer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default class TelemetryRendererExtension extends LensRendererExtension {
88
appPreferences = [
99
{
1010
title: "Telemetry & Usage Tracking",
11+
id: "telemetry-tracking",
1112
components: {
1213
Hint: () => <TelemetryPreferenceHint/>,
1314
Input: () => <TelemetryPreferenceInput telemetry={telemetryPreferencesStore}/>

src/common/protocol-handler/router.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,12 @@ export abstract class LensProtocolRouter extends Singleton {
184184
* @param pathSchema the URI path schema to match against for this handler
185185
* @param handler a function that will be called if a protocol path matches
186186
*/
187-
public addInternalHandler(urlSchema: string, handler: RouteHandler): void {
187+
public addInternalHandler(urlSchema: string, handler: RouteHandler): this {
188188
pathToRegexp(urlSchema); // verify now that the schema is valid
189189
logger.info(`${LensProtocolRouter.LoggingPrefix}: internal registering ${urlSchema}`);
190190
this.internalRoutes.set(urlSchema, handler);
191+
192+
return this;
191193
}
192194

193195
/**

src/common/utils/buildUrl.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@ import { compile } from "path-to-regexp";
33
export interface IURLParams<P extends object = {}, Q extends object = {}> {
44
params?: P;
55
query?: Q;
6+
fragment?: string;
67
}
78

89
export function buildURL<P extends object = {}, Q extends object = {}>(path: string | any) {
910
const pathBuilder = compile(String(path));
1011

11-
return function ({ params, query }: IURLParams<P, Q> = {}) {
12+
return function ({ params, query, fragment }: IURLParams<P, Q> = {}): string {
1213
const queryParams = query ? new URLSearchParams(Object.entries(query)).toString() : "";
14+
const parts = [
15+
pathBuilder(params),
16+
queryParams && `?${queryParams}`,
17+
fragment && `#${fragment}`,
18+
];
1319

14-
return pathBuilder(params) + (queryParams ? `?${queryParams}` : "");
20+
return parts.filter(Boolean).join("");
1521
};
1622
}

src/extensions/registries/app-preference-registry.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,21 @@ export interface AppPreferenceComponents {
88

99
export interface AppPreferenceRegistration {
1010
title: string;
11+
id?: string;
1112
components: AppPreferenceComponents;
1213
}
1314

14-
export class AppPreferenceRegistry extends BaseRegistry<AppPreferenceRegistration> {
15+
export interface RegisteredAppPreference extends AppPreferenceRegistration {
16+
id: string;
17+
}
18+
19+
export class AppPreferenceRegistry extends BaseRegistry<AppPreferenceRegistration, RegisteredAppPreference> {
20+
getRegisteredItem(item: AppPreferenceRegistration): RegisteredAppPreference {
21+
return {
22+
id: item.id || item.title.toLowerCase().replace(/[^0-9a-zA-Z]+/g, "-"),
23+
...item,
24+
};
25+
}
1526
}
1627

1728
export const appPreferenceRegistry = new AppPreferenceRegistry();

src/renderer/components/+preferences/preferences.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import "./preferences.scss";
22

33
import React from "react";
4-
import { computed, observable } from "mobx";
5-
import { observer } from "mobx-react";
4+
import { computed, observable, reaction } from "mobx";
5+
import { disposeOnUnmount, observer } from "mobx-react";
66

77
import { userStore } from "../../../common/user-store";
88
import { isWindows } from "../../../common/vars";
@@ -16,6 +16,7 @@ import { Select, SelectOption } from "../select";
1616
import { HelmCharts } from "./helm-charts";
1717
import { KubectlBinaries } from "./kubectl-binaries";
1818
import { ScrollSpy } from "../scroll-spy/scroll-spy";
19+
import { navigation } from "../../navigation";
1920

2021
@observer
2122
export class Preferences extends React.Component {
@@ -29,6 +30,21 @@ export class Preferences extends React.Component {
2930
}));
3031
}
3132

33+
componentDidMount() {
34+
disposeOnUnmount(this, [
35+
reaction(() => navigation.location.hash, hash => {
36+
const fragment = hash.slice(1); // hash is /^(#\w.)?$/
37+
38+
if (fragment) {
39+
// ignore empty framents
40+
document.getElementById(fragment)?.scrollIntoView();
41+
}
42+
}, {
43+
fireImmediately: true
44+
})
45+
]);
46+
}
47+
3248
render() {
3349
const { preferences } = userStore;
3450
const header = <h2>Preferences</h2>;
@@ -133,10 +149,10 @@ export class Preferences extends React.Component {
133149
<section>
134150
<h1>Extensions</h1>
135151
</section>
136-
{appPreferenceRegistry.getItems().map(({ title, components: { Hint, Input } }, index) => {
152+
{appPreferenceRegistry.getItems().map(({ title, id, components: { Hint, Input } }, index) => {
137153
return (
138154
<section key={index} id={title}>
139-
<h2>{title}</h2>
155+
<h2 id={id}>{title}</h2>
140156
<Input/>
141157
<small className="hint">
142158
<Hint/>

src/renderer/lens-app.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { ConfirmDialog } from "./components/confirm-dialog";
1212
import { extensionLoader } from "../extensions/extension-loader";
1313
import { broadcastMessage } from "../common/ipc";
1414
import { CommandContainer } from "./components/command-palette/command-container";
15-
import { LensProtocolRouterRenderer } from "./protocol-handler/router";
15+
import { LensProtocolRouterRenderer, bindProtocolAddRouteHandlers } from "./protocol-handler";
1616
import { registerIpcHandlers } from "./ipc";
1717
import { ipcRenderer } from "electron";
1818

@@ -21,6 +21,7 @@ export class LensApp extends React.Component {
2121
static async init() {
2222
extensionLoader.loadOnClusterManagerRenderer();
2323
LensProtocolRouterRenderer.getInstance<LensProtocolRouterRenderer>().init();
24+
bindProtocolAddRouteHandlers();
2425
window.addEventListener("offline", () => {
2526
broadcastMessage("network:offline");
2627
});

0 commit comments

Comments
 (0)