import "./preferences.scss" import React from "react"; import { observer } from "mobx-react"; import { action, computed, observable } from "mobx"; import { t, Trans } from "@lingui/macro"; import { _i18n } from "../../i18n"; import { WizardLayout } from "../layout/wizard-layout"; import { Icon } from "../icon"; import { Select, SelectOption } from "../select"; import { userStore } from "../../../common/user-store"; import { HelmRepo, repoManager } from "../../../main/helm/helm-repo-manager"; import { Input } from "../input"; import { Checkbox } from "../checkbox"; import { Notifications } from "../notifications"; import { Badge } from "../badge"; import { themeStore } from "../../theme.store"; import { history } from "../../navigation"; import { Tooltip } from "../tooltip"; @observer export class Preferences extends React.Component { @observable helmLoading = false; @observable helmRepos: HelmRepo[] = []; @observable helmAddedRepos = observable.map(); @observable downloadMirrorOptions: SelectOption[] = [ { value: "default", label: "Default (Google)" }, { value: "china", label: "China (Azure)" }, ] @observable httpProxy = userStore.preferences.httpsProxy || ""; @computed get themeOptions(): SelectOption[] { return themeStore.themes.map(theme => ({ label: theme.name, value: theme.id, })) } @computed get helmOptions(): SelectOption[] { return this.helmRepos.map(repo => ({ label: repo.name, value: repo, })) } async componentDidMount() { window.addEventListener('keydown', this.onEscapeKey); await this.loadHelmRepos(); } componentWillUnmount() { window.removeEventListener('keydown', this.onEscapeKey); } onEscapeKey = (evt: KeyboardEvent) => { if (evt.code === "Escape") { evt.stopPropagation(); history.goBack(); } } @action async loadHelmRepos() { this.helmLoading = true; try { if (!this.helmRepos.length) { this.helmRepos = await repoManager.loadAvailableRepos(); // via https://helm.sh } const repos = await repoManager.repositories(); // via helm-cli this.helmAddedRepos.clear(); repos.forEach(repo => this.helmAddedRepos.set(repo.name, repo)); } catch (err) { Notifications.error(String(err)); } this.helmLoading = false; } async addRepo(repo: HelmRepo) { try { await repoManager.addRepo(repo); this.helmAddedRepos.set(repo.name, repo); } catch (err) { Notifications.error(Adding helm branch {repo.name} has failed: {String(err)}) } } async removeRepo(repo: HelmRepo) { try { await repoManager.removeRepo(repo); this.helmAddedRepos.delete(repo.name); } catch (err) { Notifications.error( Removing helm branch {repo.name} has failed: {String(err)} ) } } onRepoSelect = async ({ value: repo }: SelectOption) => { const isAdded = this.helmAddedRepos.has(repo.name); if (isAdded) { Notifications.ok(Helm branch {repo.name} already in use) return; } this.helmLoading = true; await this.addRepo(repo); this.helmLoading = false; } formatHelmOptionLabel = ({ value: repo }: SelectOption) => { const isAdded = this.helmAddedRepos.has(repo.name); return (
{repo.name} {isAdded && }
) } render() { const { preferences } = userStore; const header = ( <>

Preferences

); return (

Color Theme

Download mirror for kubectl} options={this.downloadMirrorOptions} value={preferences.downloadMirror} onChange={({ value }: SelectOption) => preferences.downloadMirror = value} />

Helm

this.httpProxy = v} onBlur={() => preferences.httpsProxy = this.httpProxy} /> Proxy is used only for non-cluster communication.

Certificate Trust

Allow untrusted Certificate Authorities} value={preferences.allowUntrustedCAs} onChange={v => preferences.allowUntrustedCAs = v} /> This will make Lens to trust ANY certificate authority without any validations.{" "} Needed with some corporate proxies that do certificate re-writing.{" "} Does not affect cluster communications!

Telemetry & Usage Tracking

Allow telemetry & usage tracking} value={preferences.allowTelemetry} onChange={v => preferences.allowTelemetry = v} /> Telemetry & usage data is collected to continuously improve the Lens experience.
); } }