import "./preferences.scss"; import React from "react"; import { observer } from "mobx-react"; import { action, computed, observable } from "mobx"; 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 { Button } from "../button"; import { themeStore } from "../../theme.store"; import { Tooltip } from "../tooltip"; import { KubectlBinaries } from "./kubectl-binaries"; import { appPreferenceRegistry } from "../../../extensions/registries/app-preference-registry"; import { PageLayout } from "../layout/page-layout"; import { AddHelmRepoDialog } from "./add-helm-repo-dialog"; @observer export class Preferences extends React.Component { @observable helmLoading = false; @observable helmRepos: HelmRepo[] = []; @observable helmAddedRepos = observable.map(); @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() { await this.loadHelmRepos(); } @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

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

Helm

); })}
); } }