mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Merge branch 'master' into compare-update-and-release-dates
This commit is contained in:
commit
28174f0ad1
421 files changed
+31514
-5159
No files matched your search
@@ -39,9 +39,9 @@ interface Dependencies {
|
||||
function getContexts(config: KubeConfig): Map<string, Option> {
|
||||
return new Map(
|
||||
splitConfig(config)
|
||||
.map(({ config, error }) => [config.currentContext, {
|
||||
.map(({ config, validationResult }) => [config.currentContext, {
|
||||
config,
|
||||
error,
|
||||
error: validationResult.error?.toString(),
|
||||
}]),
|
||||
);
|
||||
}
|
||||
@@ -134,7 +134,7 @@ class NonInjectedAddCluster extends React.Component<Dependencies> {
|
||||
{this.allErrors.length > 0 && (
|
||||
<>
|
||||
<h3>KubeConfig Yaml Validation Errors:</h3>
|
||||
{...this.allErrors.map(error => <div key={error} className="error">{error}</div>)}
|
||||
{this.allErrors.map(error => <div key={error} className="error">{error}</div>)}
|
||||
</>
|
||||
)}
|
||||
<div className="actions-panel">
|
||||
|
||||
@@ -8,12 +8,15 @@
|
||||
}
|
||||
|
||||
.parent {
|
||||
@apply uppercase font-bold;
|
||||
color: var(--textColorAccent);
|
||||
font-size: small;
|
||||
text-transform: uppercase;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.catalog {
|
||||
@apply p-5 font-bold text-2xl;
|
||||
font-size: medium;
|
||||
padding: var(--padding) calc(var(--padding) * 1.5);
|
||||
font-weight: bold;
|
||||
color: var(--textColorAccent);
|
||||
}
|
||||
@@ -48,6 +48,7 @@
|
||||
transition: none;
|
||||
opacity: 0;
|
||||
margin-left: var(--padding);
|
||||
width: calc(var(--unit) * 2);
|
||||
|
||||
&:hover {
|
||||
/* Drop styles defined for <Icon/> */
|
||||
|
||||
@@ -11,7 +11,7 @@ import { cssNames } from "../../utils";
|
||||
import type { NavigateToEntitySettings } from "../../../common/front-end-routing/routes/entity-settings/navigate-to-entity-settings.injectable";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import navigateToEntitySettingsInjectable from "../../../common/front-end-routing/routes/entity-settings/navigate-to-entity-settings.injectable";
|
||||
import hostedClusterInjectable from "../../../common/cluster-store/hosted-cluster.injectable";
|
||||
import hostedClusterInjectable from "../../cluster-frame-context/hosted-cluster.injectable";
|
||||
|
||||
export interface ClusterNoMetricsProps {
|
||||
className: string;
|
||||
|
||||
@@ -17,14 +17,13 @@ import { ClusterIssues } from "./cluster-issues";
|
||||
import { ClusterMetrics } from "./cluster-metrics";
|
||||
import type { ClusterOverviewStore } from "./cluster-overview-store/cluster-overview-store";
|
||||
import { ClusterPieCharts } from "./cluster-pie-charts";
|
||||
import { getActiveClusterEntity } from "../../api/catalog/entity/legacy-globals";
|
||||
import { ClusterMetricsResourceType } from "../../../common/cluster-types";
|
||||
import type { EventStore } from "../+events/store";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import clusterOverviewStoreInjectable from "./cluster-overview-store/cluster-overview-store.injectable";
|
||||
import type { SubscribeStores } from "../../kube-watch-api/kube-watch-api";
|
||||
import type { Cluster } from "../../../common/cluster/cluster";
|
||||
import hostedClusterInjectable from "../../../common/cluster-store/hosted-cluster.injectable";
|
||||
import hostedClusterInjectable from "../../cluster-frame-context/hosted-cluster.injectable";
|
||||
import assert from "assert";
|
||||
import subscribeStoresInjectable from "../../kube-watch-api/subscribe-stores.injectable";
|
||||
import podStoreInjectable from "../+workloads-pods/store.injectable";
|
||||
@@ -71,7 +70,7 @@ class NonInjectedClusterOverview extends React.Component<Dependencies> {
|
||||
this.metricPoller.stop();
|
||||
}
|
||||
|
||||
renderMetrics(isMetricsHidden?: boolean) {
|
||||
renderMetrics(isMetricsHidden: boolean) {
|
||||
if (isMetricsHidden) {
|
||||
return null;
|
||||
}
|
||||
@@ -84,7 +83,7 @@ class NonInjectedClusterOverview extends React.Component<Dependencies> {
|
||||
);
|
||||
}
|
||||
|
||||
renderClusterOverview(isLoaded: boolean, isMetricsHidden?: boolean) {
|
||||
renderClusterOverview(isLoaded: boolean, isMetricsHidden: boolean) {
|
||||
if (!isLoaded) {
|
||||
return <Spinner center/>;
|
||||
}
|
||||
@@ -98,9 +97,9 @@ class NonInjectedClusterOverview extends React.Component<Dependencies> {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { eventStore, nodeStore } = this.props;
|
||||
const { eventStore, nodeStore, hostedCluster } = this.props;
|
||||
const isLoaded = nodeStore.isLoaded && eventStore.isLoaded;
|
||||
const isMetricHidden = getActiveClusterEntity()?.isMetricHidden(ClusterMetricsResourceType.Cluster);
|
||||
const isMetricHidden = hostedCluster.isMetricHidden(ClusterMetricsResourceType.Cluster);
|
||||
|
||||
return (
|
||||
<TabLayout>
|
||||
|
||||
+2
-2
@@ -8,10 +8,10 @@ import crdListRouteInjectable from "../../../common/front-end-routing/routes/clu
|
||||
import customResourceDefinitionsInjectable from "./custom-resources.injectable";
|
||||
import { groupBy, matches, noop, some, toPairs } from "lodash/fp";
|
||||
import customResourcesRouteInjectable from "../../../common/front-end-routing/routes/cluster/custom-resources/custom-resources/custom-resources-route.injectable";
|
||||
import currentPathParametersInjectable from "../../routes/current-path-parameters.injectable";
|
||||
import type { SidebarItemRegistration } from "../layout/sidebar-items.injectable";
|
||||
import routeIsActiveInjectable from "../../routes/route-is-active.injectable";
|
||||
import navigateToCustomResourcesInjectable from "../../../common/front-end-routing/routes/cluster/custom-resources/custom-resources/navigate-to-custom-resources.injectable";
|
||||
import routePathParametersInjectable from "../../routes/route-path-parameters.injectable";
|
||||
|
||||
const sidebarItemsForDefinitionGroupsInjectable = getInjectable({
|
||||
id: "sidebar-items-for-definition-groups",
|
||||
@@ -24,7 +24,7 @@ const sidebarItemsForDefinitionGroupsInjectable = getInjectable({
|
||||
const crdRoute = di.inject(customResourcesRouteInjectable);
|
||||
const crdRouteIsActive = di.inject(routeIsActiveInjectable, crdRoute);
|
||||
const crdListRoute = di.inject(crdListRouteInjectable);
|
||||
const pathParameters = di.inject(currentPathParametersInjectable);
|
||||
const pathParameters = di.inject(routePathParametersInjectable, crdRoute);
|
||||
const navigateToCustomResources = di.inject(navigateToCustomResourcesInjectable);
|
||||
|
||||
return computed((): SidebarItemRegistration[] => {
|
||||
|
||||
@@ -14,7 +14,6 @@ import { readFileNotify } from "../read-file-notify/read-file-notify";
|
||||
import type { InstallRequest } from "../attempt-install/install-request";
|
||||
import type { ExtensionInfo } from "../attempt-install-by-info.injectable";
|
||||
import type { ExtensionInstallationStateStore } from "../../../../extensions/extension-installation-state-store/extension-installation-state-store";
|
||||
import { AsyncInputValidationError } from "../../input/input_validators";
|
||||
|
||||
export type InstallFromInput = (input: string) => Promise<void>;
|
||||
|
||||
@@ -34,7 +33,7 @@ export const installFromInput = ({
|
||||
|
||||
try {
|
||||
// fixme: improve error messages for non-tar-file URLs
|
||||
if (InputValidators.isUrl.validate(input, {})) {
|
||||
if (InputValidators.isUrl.validate(input)) {
|
||||
// install via url
|
||||
disposer = extensionInstallationStateStore.startPreInstall();
|
||||
const { promise } = downloadFile({ url: input, timeout: 10 * 60 * 1000 });
|
||||
@@ -44,23 +43,19 @@ export const installFromInput = ({
|
||||
}
|
||||
|
||||
try {
|
||||
await InputValidators.isPath.validate(input, {});
|
||||
await InputValidators.isPath.validate(input);
|
||||
|
||||
// install from system path
|
||||
const fileName = path.basename(input);
|
||||
|
||||
return await attemptInstall({ fileName, dataP: readFileNotify(input) });
|
||||
} catch (error) {
|
||||
if (error instanceof AsyncInputValidationError) {
|
||||
const extNameCaptures = InputValidators.isExtensionNameInstallRegex.captures(input);
|
||||
const extNameCaptures = InputValidators.isExtensionNameInstallRegex.captures(input);
|
||||
|
||||
if (extNameCaptures) {
|
||||
const { name, version } = extNameCaptures;
|
||||
if (extNameCaptures) {
|
||||
const { name, version } = extNameCaptures;
|
||||
|
||||
return await attemptInstallByInfo({ name, version });
|
||||
}
|
||||
} else {
|
||||
throw error;
|
||||
return await attemptInstallByInfo({ name, version });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,10 +13,9 @@ import { Input, InputValidators } from "../input";
|
||||
import { SubTitle } from "../layout/sub-title";
|
||||
import { TooltipPosition } from "../tooltip";
|
||||
import type { ExtensionInstallationStateStore } from "../../../extensions/extension-installation-state-store/extension-installation-state-store";
|
||||
import extensionInstallationStateStoreInjectable
|
||||
from "../../../extensions/extension-installation-state-store/extension-installation-state-store.injectable";
|
||||
import extensionInstallationStateStoreInjectable from "../../../extensions/extension-installation-state-store/extension-installation-state-store.injectable";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import { inputValidator } from "../input/input_validators";
|
||||
import { unionInputValidatorsAsync } from "../input/input_validators";
|
||||
|
||||
export interface InstallProps {
|
||||
installPath: string;
|
||||
@@ -30,18 +29,14 @@ interface Dependencies {
|
||||
extensionInstallationStateStore: ExtensionInstallationStateStore;
|
||||
}
|
||||
|
||||
const installInputValidators = [
|
||||
const installInputValidator = unionInputValidatorsAsync(
|
||||
{
|
||||
message: "Invalid URL, absolute path, or extension name",
|
||||
},
|
||||
InputValidators.isUrl,
|
||||
InputValidators.isPath,
|
||||
InputValidators.isExtensionNameInstall,
|
||||
];
|
||||
|
||||
const installInputValidator = inputValidator({
|
||||
message: "Invalid URL, absolute path, or extension name",
|
||||
validate: (value: string, props) => (
|
||||
installInputValidators.some(({ validate }) => validate(value, props))
|
||||
),
|
||||
});
|
||||
InputValidators.isPath,
|
||||
);
|
||||
|
||||
const NonInjectedInstall: React.FC<Dependencies & InstallProps> = ({
|
||||
installPath,
|
||||
|
||||
@@ -4,8 +4,12 @@
|
||||
*/
|
||||
|
||||
.notice {
|
||||
@apply p-8 flex flex-col gap-2 rounded-lg;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: calc(var(--unit) * 2);
|
||||
background-color: var(--inputControlBackground);
|
||||
border: 1px solid var(--boxShadow);
|
||||
color: var(--textColorTertiary);
|
||||
border-radius: 4px;
|
||||
padding: calc(var(--padding) * 2);
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import createInstallChartTabInjectable from "../dock/install-chart/create-instal
|
||||
import { Notifications } from "../notifications";
|
||||
import HelmLogoPlaceholder from "./helm-placeholder.svg";
|
||||
import type { SingleValue } from "react-select";
|
||||
import { AbortController } from "abort-controller";
|
||||
|
||||
export interface HelmChartDetailsProps {
|
||||
chart: HelmChart;
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { computed, onBecomeObserved, onBecomeUnobserved } from "mobx";
|
||||
import subscribeStoresInjectable from "../../kube-watch-api/subscribe-stores.injectable";
|
||||
import secretStoreInjectable from "../+config-secrets/store.injectable";
|
||||
|
||||
const releaseSecretsInjectable = getInjectable({
|
||||
id: "release-secrets",
|
||||
|
||||
instantiate: (di) => {
|
||||
const subscribeStores = di.inject(subscribeStoresInjectable);
|
||||
const secretStore = di.inject(secretStoreInjectable);
|
||||
|
||||
const releaseSecrets = computed(() =>
|
||||
secretStore.contextItems.filter((secret) =>
|
||||
secret.type.startsWith("helm.sh/release"),
|
||||
),
|
||||
);
|
||||
|
||||
let unsubscribe: () => void;
|
||||
|
||||
onBecomeObserved(releaseSecrets, () => {
|
||||
unsubscribe = subscribeStores([secretStore]);
|
||||
});
|
||||
|
||||
onBecomeUnobserved(releaseSecrets, () => {
|
||||
unsubscribe?.();
|
||||
});
|
||||
|
||||
return releaseSecrets;
|
||||
},
|
||||
});
|
||||
|
||||
export default releaseSecretsInjectable;
|
||||
@@ -7,6 +7,7 @@ import { asyncComputed } from "@ogre-tools/injectable-react";
|
||||
import namespaceStoreInjectable from "../+namespaces/store.injectable";
|
||||
import { listReleases } from "../../../common/k8s-api/endpoints/helm-releases.api";
|
||||
import clusterFrameContextInjectable from "../../cluster-frame-context/cluster-frame-context.injectable";
|
||||
import releaseSecretsInjectable from "./release-secrets.injectable";
|
||||
|
||||
const releasesInjectable = getInjectable({
|
||||
id: "releases",
|
||||
@@ -14,10 +15,13 @@ const releasesInjectable = getInjectable({
|
||||
instantiate: (di) => {
|
||||
const clusterContext = di.inject(clusterFrameContextInjectable);
|
||||
const namespaceStore = di.inject(namespaceStoreInjectable);
|
||||
const releaseSecrets = di.inject(releaseSecretsInjectable);
|
||||
|
||||
return asyncComputed(async () => {
|
||||
const contextNamespaces = namespaceStore.contextNamespaces || [];
|
||||
|
||||
void releaseSecrets.get();
|
||||
|
||||
const isLoadingAll =
|
||||
clusterContext.allNamespaces?.length > 1 &&
|
||||
clusterContext.cluster?.accessibleNamespaces.length === 0 &&
|
||||
|
||||
@@ -59,6 +59,8 @@
|
||||
&__option {
|
||||
white-space: normal;
|
||||
word-break: break-all;
|
||||
padding: 4px 8px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,5 +82,5 @@ const InjectedNamespaceSelect = withInjectables<Dependencies, NamespaceSelectPro
|
||||
});
|
||||
|
||||
export function NamespaceSelect<IsMulti extends boolean = false>(props: NamespaceSelectProps<IsMulti>): JSX.Element {
|
||||
return <InjectedNamespaceSelect {...(props as never)} />;
|
||||
return <InjectedNamespaceSelect {...(props as unknown as NamespaceSelectProps<boolean>)} />;
|
||||
}
|
||||
@@ -114,7 +114,7 @@ export class NamespaceStore extends KubeObjectStore<Namespace, NamespaceApi> {
|
||||
* if user has given static list of namespaces let's not start watches
|
||||
* because watch adds stuff that's not wanted or will just fail
|
||||
*/
|
||||
if (this.context.cluster.accessibleNamespaces.length > 0) {
|
||||
if ((this.context?.cluster.accessibleNamespaces.length ?? 0) > 0) {
|
||||
return noop;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,220 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import "./add-helm-repo-dialog.scss";
|
||||
|
||||
import React from "react";
|
||||
import type { FileFilter } from "electron";
|
||||
import { observable, makeObservable, action } from "mobx";
|
||||
import { observer } from "mobx-react";
|
||||
import type { DialogProps } from "../dialog";
|
||||
import { Dialog } from "../dialog";
|
||||
import { Wizard, WizardStep } from "../wizard";
|
||||
import { Input } from "../input";
|
||||
import { Checkbox } from "../checkbox";
|
||||
import { Button } from "../button";
|
||||
import { systemName, isUrl, isPath } from "../input/input_validators";
|
||||
import { SubTitle } from "../layout/sub-title";
|
||||
import { Icon } from "../icon";
|
||||
import { Notifications } from "../notifications";
|
||||
import { type HelmRepo, HelmRepoManager } from "../../../main/helm/helm-repo-manager";
|
||||
import { requestOpenFilePickingDialog } from "../../ipc";
|
||||
|
||||
export interface AddHelmRepoDialogProps extends Partial<DialogProps> {
|
||||
onAddRepo: () => void;
|
||||
}
|
||||
|
||||
enum FileType {
|
||||
CaFile = "caFile",
|
||||
KeyFile = "keyFile",
|
||||
CertFile = "certFile",
|
||||
}
|
||||
|
||||
const dialogState = observable.object({
|
||||
isOpen: false,
|
||||
});
|
||||
|
||||
function getEmptyRepo(): HelmRepo {
|
||||
return { name: "", url: "", username: "", password: "", insecureSkipTlsVerify: false, caFile: "", keyFile: "", certFile: "" };
|
||||
}
|
||||
@observer
|
||||
export class AddHelmRepoDialog extends React.Component<AddHelmRepoDialogProps> {
|
||||
private static keyExtensions = ["key", "keystore", "jks", "p12", "pfx", "pem"];
|
||||
private static certExtensions = ["crt", "cer", "ca-bundle", "p7b", "p7c", "p7s", "p12", "pfx", "pem"];
|
||||
|
||||
constructor(props: AddHelmRepoDialogProps) {
|
||||
super(props);
|
||||
makeObservable(this);
|
||||
}
|
||||
|
||||
static open() {
|
||||
dialogState.isOpen = true;
|
||||
}
|
||||
|
||||
static close() {
|
||||
dialogState.isOpen = false;
|
||||
}
|
||||
|
||||
@observable helmRepo = getEmptyRepo();
|
||||
@observable showOptions = false;
|
||||
|
||||
@action
|
||||
close = () => {
|
||||
AddHelmRepoDialog.close();
|
||||
this.helmRepo = getEmptyRepo();
|
||||
this.showOptions = false;
|
||||
};
|
||||
|
||||
setFilepath(type: FileType, value: string) {
|
||||
this.helmRepo[type] = value;
|
||||
}
|
||||
|
||||
getFilePath(type: FileType) {
|
||||
return this.helmRepo[type];
|
||||
}
|
||||
|
||||
async selectFileDialog(type: FileType, fileFilter: FileFilter) {
|
||||
const { canceled, filePaths } = await requestOpenFilePickingDialog({
|
||||
defaultPath: this.getFilePath(type),
|
||||
properties: ["openFile", "showHiddenFiles"],
|
||||
message: `Select file`,
|
||||
buttonLabel: `Use file`,
|
||||
filters: [
|
||||
fileFilter,
|
||||
{ name: "Any", extensions: ["*"] },
|
||||
],
|
||||
});
|
||||
|
||||
if (!canceled && filePaths.length) {
|
||||
this.setFilepath(type, filePaths[0]);
|
||||
}
|
||||
}
|
||||
|
||||
async addCustomRepo() {
|
||||
try {
|
||||
await HelmRepoManager.getInstance().addRepo(this.helmRepo);
|
||||
Notifications.ok((
|
||||
<>
|
||||
{"Helm repository "}
|
||||
<b>{this.helmRepo.name}</b>
|
||||
{" has been added."}
|
||||
</>
|
||||
));
|
||||
this.props.onAddRepo();
|
||||
this.close();
|
||||
} catch (err) {
|
||||
Notifications.error((
|
||||
<>
|
||||
{"Adding helm branch "}
|
||||
<b>{this.helmRepo.name}</b>
|
||||
{" has failed: "}
|
||||
{String(err)}
|
||||
</>
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
renderFileInput(placeholder:string, fileType:FileType, fileExtensions:string[]){
|
||||
return (
|
||||
<div className="flex gaps align-center">
|
||||
<Input
|
||||
placeholder={placeholder}
|
||||
validators={isPath}
|
||||
className="box grow"
|
||||
value={this.getFilePath(fileType)}
|
||||
onChange={v => this.setFilepath(fileType, v)}
|
||||
/>
|
||||
<Icon
|
||||
material="folder"
|
||||
onClick={() => this.selectFileDialog(fileType, { name: placeholder, extensions: fileExtensions })}
|
||||
tooltip="Browse"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
renderOptions() {
|
||||
return (
|
||||
<>
|
||||
<SubTitle title="Security settings" />
|
||||
<Checkbox
|
||||
label="Skip TLS certificate checks for the repository"
|
||||
value={this.helmRepo.insecureSkipTlsVerify}
|
||||
onChange={v => this.helmRepo.insecureSkipTlsVerify = v}
|
||||
/>
|
||||
{this.renderFileInput("Key file", FileType.KeyFile, AddHelmRepoDialog.keyExtensions)}
|
||||
{this.renderFileInput("Ca file", FileType.CaFile, AddHelmRepoDialog.certExtensions)}
|
||||
{this.renderFileInput("Certificate file", FileType.CertFile, AddHelmRepoDialog.certExtensions)}
|
||||
<SubTitle title="Chart Repository Credentials" />
|
||||
<Input
|
||||
placeholder="Username"
|
||||
value={this.helmRepo.username}
|
||||
onChange= {v => this.helmRepo.username = v}
|
||||
/>
|
||||
<Input
|
||||
type="password"
|
||||
placeholder="Password"
|
||||
value={this.helmRepo.password}
|
||||
onChange={v => this.helmRepo.password = v}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { ...dialogProps } = this.props;
|
||||
|
||||
const header = <h5>Add custom Helm Repo</h5>;
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
{...dialogProps}
|
||||
className="AddHelmRepoDialog"
|
||||
isOpen={dialogState.isOpen}
|
||||
close={this.close}
|
||||
>
|
||||
<Wizard header={header} done={this.close}>
|
||||
<WizardStep
|
||||
contentClass="flow column"
|
||||
nextLabel="Add"
|
||||
next={() => this.addCustomRepo()}
|
||||
>
|
||||
<div className="flex column gaps">
|
||||
<Input
|
||||
autoFocus
|
||||
required
|
||||
placeholder="Helm repo name"
|
||||
trim
|
||||
validators={systemName}
|
||||
value={this.helmRepo.name}
|
||||
onChange={v => this.helmRepo.name = v}
|
||||
/>
|
||||
<Input
|
||||
required
|
||||
placeholder="URL"
|
||||
validators={isUrl}
|
||||
value={this.helmRepo.url}
|
||||
onChange={v => this.helmRepo.url = v}
|
||||
/>
|
||||
<Button
|
||||
plain
|
||||
className="accordion"
|
||||
onClick={() => this.showOptions = !this.showOptions}
|
||||
>
|
||||
More
|
||||
<Icon
|
||||
small
|
||||
tooltip="More"
|
||||
material={this.showOptions ? "remove" : "add"}
|
||||
/>
|
||||
</Button>
|
||||
{this.showOptions && this.renderOptions()}
|
||||
</div>
|
||||
</WizardStep>
|
||||
</Wizard>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
export interface AppPreferenceTabRegistration {
|
||||
title: string;
|
||||
id: string;
|
||||
orderNumber?: number;
|
||||
}
|
||||
|
||||
+6
-9
@@ -7,16 +7,17 @@ import { filter, map } from "lodash/fp";
|
||||
import { extensionRegistratorInjectionToken } from "../../../extensions/extension-loader/extension-registrator-injection-token";
|
||||
import type { LensRendererExtension } from "../../../extensions/lens-renderer-extension";
|
||||
import { pipeline } from "@ogre-tools/fp";
|
||||
import { extensionPreferenceItemInjectionToken } from "./extension-preference-items.injectable";
|
||||
import { extensionPreferenceItemInjectionToken } from "./extension-preference-items-injection-token";
|
||||
|
||||
const extensionPreferenceItemRegistratorInjectable = getInjectable({
|
||||
id: "extension-preference-item-registrator",
|
||||
|
||||
instantiate:
|
||||
(di) =>
|
||||
(ext, extensionInstallationCount) => {
|
||||
() =>
|
||||
(ext) => {
|
||||
const extension = ext as LensRendererExtension;
|
||||
const injectables = pipeline(
|
||||
|
||||
return pipeline(
|
||||
extension.appPreferences,
|
||||
|
||||
filter(
|
||||
@@ -27,7 +28,7 @@ const extensionPreferenceItemRegistratorInjectable = getInjectable({
|
||||
const id = `extension-preferences-item-${registration.id}-for-extension-${extension.sanitizedExtensionId}`;
|
||||
|
||||
return getInjectable({
|
||||
id: `${id}-for-instance-${extensionInstallationCount}`,
|
||||
id,
|
||||
injectionToken: extensionPreferenceItemInjectionToken,
|
||||
|
||||
instantiate: () => ({
|
||||
@@ -43,10 +44,6 @@ const extensionPreferenceItemRegistratorInjectable = getInjectable({
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
di.register(...injectables);
|
||||
|
||||
return;
|
||||
},
|
||||
|
||||
injectionToken: extensionRegistratorInjectionToken,
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { LensRendererExtension } from "../../../extensions/lens-renderer-extension";
|
||||
import type { RegisteredAppPreference } from "./app-preferences/app-preference-registration";
|
||||
|
||||
interface ExtensionPreferenceItem extends RegisteredAppPreference {
|
||||
extension: LensRendererExtension;
|
||||
}
|
||||
|
||||
export const extensionPreferenceItemInjectionToken = getInjectionToken<ExtensionPreferenceItem>({
|
||||
id: "extension-preference-item-injection-token",
|
||||
});
|
||||
|
||||
@@ -2,19 +2,11 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { pipeline } from "@ogre-tools/fp";
|
||||
import { getInjectable, getInjectionToken } from "@ogre-tools/injectable";
|
||||
import { filter, overSome } from "lodash/fp";
|
||||
import { computed } from "mobx";
|
||||
import rendererExtensionsInjectable from "../../../extensions/renderer-extensions.injectable";
|
||||
import type { LensRendererExtension } from "../../../extensions/lens-renderer-extension";
|
||||
import { computedInjectManyInjectable } from "@ogre-tools/injectable-extension-for-mobx";
|
||||
import type { RegisteredAppPreference } from "./app-preferences/app-preference-registration";
|
||||
|
||||
interface ExtensionPreferenceItem extends RegisteredAppPreference {
|
||||
extension: LensRendererExtension;
|
||||
}
|
||||
|
||||
export const extensionPreferenceItemInjectionToken = getInjectionToken<ExtensionPreferenceItem>({
|
||||
export const extensionPreferenceItemInjectionToken = getInjectionToken<RegisteredAppPreference>({
|
||||
id: "extension-preference-item-injection-token",
|
||||
});
|
||||
|
||||
@@ -22,29 +14,10 @@ const extensionsPreferenceItemsInjectable = getInjectable({
|
||||
id: "extension-preference-items",
|
||||
|
||||
instantiate: (di) => {
|
||||
const extensions = di.inject(rendererExtensionsInjectable);
|
||||
const computedInjectMany = di.inject(computedInjectManyInjectable);
|
||||
|
||||
return computed(() => {
|
||||
const enabledExtensions = extensions.get();
|
||||
|
||||
return pipeline(
|
||||
di.injectMany(extensionPreferenceItemInjectionToken),
|
||||
|
||||
filter((item) =>
|
||||
overSome([
|
||||
isNonExtensionItem,
|
||||
isEnabledExtensionItemFor(enabledExtensions),
|
||||
])(item),
|
||||
),
|
||||
);
|
||||
});
|
||||
return computedInjectMany(extensionPreferenceItemInjectionToken);
|
||||
},
|
||||
});
|
||||
|
||||
const isNonExtensionItem = (item: ExtensionPreferenceItem) => !item.extension;
|
||||
|
||||
const isEnabledExtensionItemFor =
|
||||
(enabledExtensions: LensRendererExtension[]) => (item: ExtensionPreferenceItem) =>
|
||||
!!enabledExtensions.find((extension) => extension === item.extension);
|
||||
|
||||
export default extensionsPreferenceItemsInjectable;
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { computed } from "mobx";
|
||||
import extensionPreferencesRouteInjectable from "../../../common/front-end-routing/routes/preferences/extension/extension-preferences-route.injectable";
|
||||
import rendererExtensionsInjectable from "../../../extensions/renderer-extensions.injectable";
|
||||
import routePathParametersInjectable from "../../routes/route-path-parameters.injectable";
|
||||
import { getExtensionPreferenceItems } from "./get-extension-preference-items";
|
||||
|
||||
const extensionPreferencesModelInjectable = getInjectable({
|
||||
id: "extension-preferences-model",
|
||||
|
||||
instantiate: (di) => {
|
||||
const route = di.inject(extensionPreferencesRouteInjectable);
|
||||
const pathParameters = di.inject(routePathParametersInjectable, route);
|
||||
const extensions = di.inject(rendererExtensionsInjectable);
|
||||
|
||||
return computed(() => {
|
||||
const { extensionId, tabId } = pathParameters.get();
|
||||
const targetExtension = extensions.get().find((extension) => extension.sanitizedExtensionId === extensionId);
|
||||
|
||||
return {
|
||||
extensionName: targetExtension?.manifest.name,
|
||||
preferenceItems: getExtensionPreferenceItems(targetExtension, tabId),
|
||||
};
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default extensionPreferencesModelInjectable;
|
||||
+5
-9
@@ -13,10 +13,11 @@ const extensionTelemetryPreferenceItemRegistratorInjectable = getInjectable({
|
||||
id: "extension-telemetry-preference-item-registrator",
|
||||
|
||||
instantiate:
|
||||
(di) =>
|
||||
(ext, extensionInstallationCount) => {
|
||||
() =>
|
||||
(ext) => {
|
||||
const extension = ext as LensRendererExtension;
|
||||
const injectables = pipeline(
|
||||
|
||||
return pipeline(
|
||||
extension.appPreferences,
|
||||
|
||||
filter(
|
||||
@@ -27,13 +28,12 @@ const extensionTelemetryPreferenceItemRegistratorInjectable = getInjectable({
|
||||
const id = `telemetry-preferences-item-${registration.id}-for-extension-${extension.sanitizedExtensionId}`;
|
||||
|
||||
return getInjectable({
|
||||
id: `${id}-for-instance-${extensionInstallationCount}`,
|
||||
id,
|
||||
injectionToken: telemetryPreferenceItemInjectionToken,
|
||||
|
||||
instantiate: () => ({
|
||||
id: registration.id || id,
|
||||
title: registration.title,
|
||||
extension,
|
||||
|
||||
components: {
|
||||
Hint: registration.components.Hint,
|
||||
@@ -43,10 +43,6 @@ const extensionTelemetryPreferenceItemRegistratorInjectable = getInjectable({
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
di.register(...injectables);
|
||||
|
||||
return;
|
||||
},
|
||||
|
||||
injectionToken: extensionRegistratorInjectionToken,
|
||||
|
||||
@@ -8,36 +8,55 @@ import type { IComputedValue } from "mobx";
|
||||
import { observer } from "mobx-react";
|
||||
import React from "react";
|
||||
import type { RegisteredAppPreference } from "./app-preferences/app-preference-registration";
|
||||
import extensionPreferencesModelInjectable from "./extension-preference-model.injectable";
|
||||
import { ExtensionSettings } from "./extension-settings";
|
||||
import { Preferences } from "./preferences";
|
||||
import extensionsPreferenceItemsInjectable from "./extension-preference-items.injectable";
|
||||
|
||||
interface Dependencies {
|
||||
preferenceItems: IComputedValue<RegisteredAppPreference[]>;
|
||||
model: IComputedValue<{
|
||||
preferenceItems: RegisteredAppPreference[];
|
||||
extensionName?: string;
|
||||
}>;
|
||||
}
|
||||
|
||||
const NonInjectedExtensions = ({ preferenceItems }: Dependencies) => (
|
||||
<Preferences data-testid="extension-preferences-page">
|
||||
<section id="extensions">
|
||||
<h2>Extensions</h2>
|
||||
{preferenceItems.get().map((preferenceItem) => (
|
||||
<ExtensionSettings
|
||||
key={preferenceItem.id}
|
||||
setting={preferenceItem}
|
||||
size="small"
|
||||
data-testid={`extension-preference-item-for-${preferenceItem.id}`}
|
||||
/>
|
||||
))}
|
||||
</section>
|
||||
</Preferences>
|
||||
);
|
||||
const NonInjectedExtensions = ({ model }: Dependencies) => {
|
||||
const { extensionName, preferenceItems } = model.get();
|
||||
|
||||
return (
|
||||
<Preferences data-testid="extension-preferences-page">
|
||||
<section id="extensions">
|
||||
<h2>
|
||||
{extensionName}
|
||||
{" "}
|
||||
preferences
|
||||
</h2>
|
||||
{!extensionName && (
|
||||
<div
|
||||
className="flex items-center"
|
||||
data-testid="error-for-extension-not-being-present"
|
||||
>
|
||||
No extension found
|
||||
</div>
|
||||
)}
|
||||
{preferenceItems.map((preferenceItem, index) => (
|
||||
<ExtensionSettings
|
||||
key={`${preferenceItem.id}-${index}`}
|
||||
setting={preferenceItem}
|
||||
size="small"
|
||||
data-testid={`extension-preference-item-for-${preferenceItem.id}`}
|
||||
/>
|
||||
))}
|
||||
</section>
|
||||
</Preferences>
|
||||
);
|
||||
};
|
||||
|
||||
export const Extensions = withInjectables<Dependencies>(
|
||||
observer(NonInjectedExtensions),
|
||||
|
||||
{
|
||||
getProps: (di) => ({
|
||||
preferenceItems: di.inject(extensionsPreferenceItemsInjectable),
|
||||
model: di.inject(extensionPreferencesModelInjectable),
|
||||
}),
|
||||
},
|
||||
);
|
||||
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { LensRendererExtension } from "../../../extensions/lens-renderer-extension";
|
||||
import type { RegisteredAppPreference } from "./app-preferences/app-preference-registration";
|
||||
|
||||
export function getExtensionPreferenceItems(extension?: LensRendererExtension, tabId?: string): RegisteredAppPreference[] {
|
||||
if (!extension) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const preferences = extension.appPreferences.map(preference => ({
|
||||
id: preference.id || preference.title,
|
||||
...preference,
|
||||
}));
|
||||
|
||||
if (tabId) {
|
||||
return preferences.filter(preference => preference.showInPreferencesTab == tabId);
|
||||
}
|
||||
|
||||
return preferences.filter(preference => !preference.showInPreferencesTab);
|
||||
}
|
||||
@@ -1,202 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import styles from "./helm-charts.module.scss";
|
||||
|
||||
import React from "react";
|
||||
import { observable, makeObservable, computed } from "mobx";
|
||||
|
||||
import type { HelmRepo } from "../../../main/helm/helm-repo-manager";
|
||||
import { HelmRepoManager } from "../../../main/helm/helm-repo-manager";
|
||||
import { Button } from "../button";
|
||||
import { Icon } from "../icon";
|
||||
import { Notifications } from "../notifications";
|
||||
import type { SelectOption } from "../select";
|
||||
import { Select } from "../select";
|
||||
import { AddHelmRepoDialog } from "./add-helm-repo-dialog";
|
||||
import { observer } from "mobx-react";
|
||||
import { RemovableItem } from "./removable-item";
|
||||
import { Notice } from "../+extensions/notice";
|
||||
import { Spinner } from "../spinner";
|
||||
import { noop } from "../../utils";
|
||||
import type { SingleValue } from "react-select";
|
||||
|
||||
@observer
|
||||
export class HelmCharts extends React.Component {
|
||||
@observable loadingRepos = false;
|
||||
@observable loadingAvailableRepos = false;
|
||||
@observable repos: HelmRepo[] = [];
|
||||
@observable addedRepos = observable.map<string, HelmRepo>();
|
||||
|
||||
constructor(props: {}) {
|
||||
super(props);
|
||||
makeObservable(this);
|
||||
}
|
||||
|
||||
@computed get repoOptions() {
|
||||
return this.repos.map(repo => ({
|
||||
value: repo,
|
||||
label: repo.name,
|
||||
isSelected: this.addedRepos.has(repo.name),
|
||||
}));
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.loadAvailableRepos().catch(noop);
|
||||
this.loadRepos().catch(noop);
|
||||
}
|
||||
|
||||
async loadAvailableRepos() {
|
||||
this.loadingAvailableRepos = true;
|
||||
|
||||
try {
|
||||
if (!this.repos.length) {
|
||||
this.repos = await HelmRepoManager.getInstance().loadAvailableRepos();
|
||||
}
|
||||
} catch (err) {
|
||||
Notifications.error(String(err));
|
||||
}
|
||||
|
||||
this.loadingAvailableRepos = false;
|
||||
}
|
||||
|
||||
async loadRepos() {
|
||||
this.loadingRepos = true;
|
||||
|
||||
try {
|
||||
const repos = await HelmRepoManager.getInstance().repositories(); // via helm-cli
|
||||
|
||||
this.addedRepos.replace(repos.map(repo => [repo.name, repo]));
|
||||
} catch (err) {
|
||||
Notifications.error(String(err));
|
||||
}
|
||||
|
||||
this.loadingRepos = false;
|
||||
}
|
||||
|
||||
async addRepo(repo: HelmRepo) {
|
||||
try {
|
||||
await HelmRepoManager.getInstance().addRepo(repo);
|
||||
this.addedRepos.set(repo.name, repo);
|
||||
} catch (err) {
|
||||
Notifications.error((
|
||||
<>
|
||||
{"Adding helm branch "}
|
||||
<b>{repo.name}</b>
|
||||
{" has failed: "}
|
||||
{String(err)}
|
||||
</>
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
async removeRepo(repo: HelmRepo) {
|
||||
try {
|
||||
await HelmRepoManager.getInstance().removeRepo(repo);
|
||||
this.addedRepos.delete(repo.name);
|
||||
} catch (err) {
|
||||
Notifications.error(
|
||||
<>
|
||||
{"Removing helm branch "}
|
||||
<b>{repo.name}</b>
|
||||
{" has failed: "}
|
||||
{String(err)}
|
||||
</>,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
onRepoSelect = async (option: SingleValue<{ value: HelmRepo }>): Promise<void> => {
|
||||
if (!option) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.addedRepos.has(option.value.name)) {
|
||||
return void Notifications.ok((
|
||||
<>
|
||||
{"Helm repo "}
|
||||
<b>{option.value.name}</b>
|
||||
{" already in use."}
|
||||
</>
|
||||
));
|
||||
}
|
||||
|
||||
await this.addRepo(option.value);
|
||||
};
|
||||
|
||||
formatOptionLabel = ({ value, isSelected }: SelectOption<HelmRepo>) => (
|
||||
<div className="flex gaps">
|
||||
<span>{value.name}</span>
|
||||
{isSelected && (
|
||||
<Icon
|
||||
small
|
||||
material="check"
|
||||
className="box right" />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
renderRepositories() {
|
||||
const repos = Array.from(this.addedRepos);
|
||||
|
||||
if (this.loadingRepos) {
|
||||
return <div className="pt-5 relative"><Spinner center/></div>;
|
||||
}
|
||||
|
||||
if (!repos.length) {
|
||||
return (
|
||||
<Notice>
|
||||
<div className="flex-grow text-center">The repositories have not been added yet</div>
|
||||
</Notice>
|
||||
);
|
||||
}
|
||||
|
||||
return repos.map(([name, repo]) => {
|
||||
return (
|
||||
<RemovableItem
|
||||
key={name}
|
||||
onRemove={() => this.removeRepo(repo)}
|
||||
className="mt-3"
|
||||
>
|
||||
<div>
|
||||
<div data-testid="repository-name" className={styles.repoName}>{name}</div>
|
||||
<div className={styles.repoUrl}>{repo.url}</div>
|
||||
</div>
|
||||
</RemovableItem>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<div className="flex gaps">
|
||||
<Select
|
||||
id="HelmRepoSelect"
|
||||
placeholder="Repositories"
|
||||
isLoading={this.loadingAvailableRepos}
|
||||
isDisabled={this.loadingAvailableRepos}
|
||||
options={this.repoOptions}
|
||||
onChange={this.onRepoSelect}
|
||||
value={this.repos}
|
||||
formatOptionLabel={this.formatOptionLabel}
|
||||
controlShouldRenderValue={false}
|
||||
className="box grow"
|
||||
themeName="lens"
|
||||
/>
|
||||
<Button
|
||||
primary
|
||||
label="Add Custom Helm Repo"
|
||||
onClick={AddHelmRepoDialog.open}
|
||||
/>
|
||||
</div>
|
||||
<AddHelmRepoDialog onAddRepo={() => this.loadRepos()}/>
|
||||
<div className={styles.repos}>
|
||||
{this.renderRepositories()}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,7 @@
|
||||
*/
|
||||
import { observer } from "mobx-react";
|
||||
import React from "react";
|
||||
|
||||
import { HelmCharts } from "./helm-charts";
|
||||
import { HelmCharts } from "./kubernetes/helm-charts/helm-charts";
|
||||
import { KubeconfigSyncs } from "./kubeconfig-syncs";
|
||||
import { KubectlBinaries } from "./kubectl-binaries";
|
||||
import { Preferences } from "./preferences";
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { asyncComputed } from "@ogre-tools/injectable-react";
|
||||
import getActiveHelmRepositoriesChannelInjectable from "../../../../../common/helm/get-active-helm-repositories-channel.injectable";
|
||||
import { requestFromChannelInjectionToken } from "../../../../../common/utils/channel/request-from-channel-injection-token";
|
||||
import showErrorNotificationInjectable from "../../../notifications/show-error-notification.injectable";
|
||||
import helmRepositoriesErrorStateInjectable from "./helm-repositories-error-state.injectable";
|
||||
import { runInAction } from "mobx";
|
||||
|
||||
const activeHelmRepositoriesInjectable = getInjectable({
|
||||
id: "active-helm-repositories",
|
||||
|
||||
instantiate: (di) => {
|
||||
const requestFromChannel = di.inject(requestFromChannelInjectionToken);
|
||||
const getHelmRepositoriesChannel = di.inject(getActiveHelmRepositoriesChannelInjectable);
|
||||
const showErrorNotification = di.inject(showErrorNotificationInjectable);
|
||||
const helmRepositoriesErrorState = di.inject(helmRepositoriesErrorStateInjectable);
|
||||
|
||||
return asyncComputed(async () => {
|
||||
const result = await requestFromChannel(getHelmRepositoriesChannel);
|
||||
|
||||
if (result.callWasSuccessful) {
|
||||
return result.response;
|
||||
} else {
|
||||
showErrorNotification(result.error);
|
||||
|
||||
runInAction(() =>
|
||||
helmRepositoriesErrorState.set({
|
||||
controlsAreShown: false,
|
||||
errorMessage: result.error,
|
||||
}),
|
||||
);
|
||||
|
||||
return [];
|
||||
}
|
||||
}, []);
|
||||
},
|
||||
});
|
||||
|
||||
export default activeHelmRepositoriesInjectable;
|
||||
File renamed without changes.
+152
@@ -0,0 +1,152 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import "./add-helm-repo-dialog.scss";
|
||||
|
||||
import React from "react";
|
||||
import { Wizard, WizardStep } from "../../../../wizard";
|
||||
import { Input } from "../../../../input";
|
||||
import { systemName, isUrl } from "../../../../input/input_validators";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import customHelmRepoInjectable from "./custom-helm-repo.injectable";
|
||||
import type { HelmRepo } from "../../../../../../common/helm/helm-repo";
|
||||
import { observer } from "mobx-react";
|
||||
import type { IObservableValue } from "mobx";
|
||||
import { action } from "mobx";
|
||||
import submitCustomHelmRepositoryInjectable from "./submit-custom-helm-repository.injectable";
|
||||
import hideDialogForAddingCustomHelmRepositoryInjectable from "./dialog-visibility/hide-dialog-for-adding-custom-helm-repository.injectable";
|
||||
import { Button } from "../../../../button";
|
||||
import { Icon } from "../../../../icon";
|
||||
import maximalCustomHelmRepoOptionsAreShownInjectable from "./maximal-custom-helm-repo-options-are-shown.injectable";
|
||||
import { SubTitle } from "../../../../layout/sub-title";
|
||||
import { Checkbox } from "../../../../checkbox";
|
||||
import { HelmFileInput } from "./helm-file-input/helm-file-input";
|
||||
|
||||
interface Dependencies {
|
||||
helmRepo: HelmRepo;
|
||||
hideDialog: () => void;
|
||||
submitCustomRepository: (repository: HelmRepo) => Promise<void>;
|
||||
maximalOptionsAreShown: IObservableValue<boolean>;
|
||||
}
|
||||
|
||||
const NonInjectedActivationOfCustomHelmRepositoryDialogContent = observer(({ helmRepo, submitCustomRepository, maximalOptionsAreShown, hideDialog } : Dependencies) => (
|
||||
<Wizard header={<h5>Add custom Helm Repo</h5>} done={hideDialog}>
|
||||
<WizardStep
|
||||
contentClass="flow column"
|
||||
nextLabel="Add"
|
||||
next={() => submitCustomRepository(helmRepo)}
|
||||
testIdForNext="custom-helm-repository-submit-button"
|
||||
testIdForPrev="custom-helm-repository-cancel-button"
|
||||
>
|
||||
<div className="flex column gaps" data-testid="add-custom-helm-repository-dialog">
|
||||
<Input
|
||||
autoFocus
|
||||
required
|
||||
placeholder="Helm repo name"
|
||||
trim
|
||||
validators={systemName}
|
||||
value={helmRepo.name}
|
||||
onChange={action(v => helmRepo.name = v)}
|
||||
data-testid="custom-helm-repository-name-input"
|
||||
/>
|
||||
<Input
|
||||
required
|
||||
placeholder="URL"
|
||||
validators={isUrl}
|
||||
value={helmRepo.url}
|
||||
onChange={action(v => helmRepo.url = v)}
|
||||
data-testid="custom-helm-repository-url-input"
|
||||
/>
|
||||
<Button
|
||||
plain
|
||||
className="accordion"
|
||||
data-testid="toggle-maximal-options-for-custom-helm-repository-button"
|
||||
onClick={action(() => maximalOptionsAreShown.set(!maximalOptionsAreShown.get()))}
|
||||
>
|
||||
More
|
||||
<Icon
|
||||
small
|
||||
tooltip="More"
|
||||
material={maximalOptionsAreShown.get() ? "remove" : "add"}
|
||||
/>
|
||||
</Button>
|
||||
|
||||
{maximalOptionsAreShown.get() && (
|
||||
<div data-testid="maximal-options-for-custom-helm-repository-dialog">
|
||||
<SubTitle title="Security settings" />
|
||||
|
||||
<Checkbox
|
||||
label="Skip TLS certificate checks for the repository"
|
||||
value={helmRepo.insecureSkipTlsVerify}
|
||||
onChange={action(v => {
|
||||
helmRepo.insecureSkipTlsVerify = v;
|
||||
})}
|
||||
data-testid="custom-helm-repository-verify-tls-input"
|
||||
/>
|
||||
|
||||
<HelmFileInput
|
||||
placeholder="Key file"
|
||||
value={helmRepo.keyFile || ""}
|
||||
setValue={action((value) => helmRepo.keyFile = value)}
|
||||
fileExtensions={keyExtensions}
|
||||
data-testid="custom-helm-repository-key-file-input"
|
||||
/>
|
||||
|
||||
<HelmFileInput
|
||||
placeholder="Ca file"
|
||||
value={helmRepo.caFile || ""}
|
||||
setValue={action((value) => helmRepo.caFile = value)}
|
||||
fileExtensions={certExtensions}
|
||||
data-testid="custom-helm-repository-ca-cert-file-input"
|
||||
/>
|
||||
|
||||
<HelmFileInput
|
||||
placeholder="Certificate file"
|
||||
value={helmRepo.certFile || ""}
|
||||
setValue={action((value) => helmRepo.certFile = value)}
|
||||
fileExtensions={certExtensions}
|
||||
data-testid="custom-helm-repository-cert-file-input"
|
||||
/>
|
||||
|
||||
<SubTitle title="Chart Repository Credentials" />
|
||||
|
||||
<Input
|
||||
placeholder="Username"
|
||||
value={helmRepo.username}
|
||||
onChange= {action(v => helmRepo.username = v)}
|
||||
data-testid="custom-helm-repository-username-input"
|
||||
/>
|
||||
<Input
|
||||
type="password"
|
||||
placeholder="Password"
|
||||
value={helmRepo.password}
|
||||
onChange={action(v => helmRepo.password = v)}
|
||||
data-testid="custom-helm-repository-password-input"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</WizardStep>
|
||||
</Wizard>
|
||||
));
|
||||
|
||||
|
||||
|
||||
export const AddingOfCustomHelmRepositoryDialogContent = withInjectables<Dependencies>(
|
||||
NonInjectedActivationOfCustomHelmRepositoryDialogContent,
|
||||
|
||||
{
|
||||
getProps: (di) => ({
|
||||
helmRepo: di.inject(customHelmRepoInjectable),
|
||||
hideDialog: di.inject(hideDialogForAddingCustomHelmRepositoryInjectable),
|
||||
submitCustomRepository: di.inject(submitCustomHelmRepositoryInjectable),
|
||||
maximalOptionsAreShown: di.inject(maximalCustomHelmRepoOptionsAreShownInjectable),
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
const keyExtensions = ["key", "keystore", "jks", "p12", "pfx", "pem"];
|
||||
const certExtensions = ["crt", "cer", "ca-bundle", "p7b", "p7c", "p7s", "p12", "pfx", "pem"];
|
||||
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import "./add-helm-repo-dialog.scss";
|
||||
|
||||
import React from "react";
|
||||
import { Dialog } from "../../../../dialog";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import { AddingOfCustomHelmRepositoryDialogContent } from "./adding-of-custom-helm-repository-dialog-content";
|
||||
import addingOfCustomHelmRepositoryDialogIsVisibleInjectable from "./dialog-visibility/adding-of-custom-helm-repository-dialog-is-visible.injectable";
|
||||
import type { IObservableValue } from "mobx";
|
||||
import { observer } from "mobx-react";
|
||||
import hideDialogForAddingCustomHelmRepositoryInjectable from "./dialog-visibility/hide-dialog-for-adding-custom-helm-repository.injectable";
|
||||
|
||||
interface Dependencies {
|
||||
contentIsVisible: IObservableValue<boolean>;
|
||||
hideDialog: () => void;
|
||||
}
|
||||
|
||||
const NonInjectedActivationOfCustomHelmRepositoryDialog = observer(({
|
||||
contentIsVisible,
|
||||
hideDialog,
|
||||
}: Dependencies) => (
|
||||
<div>
|
||||
<Dialog
|
||||
className="AddHelmRepoDialog"
|
||||
isOpen={contentIsVisible.get()}
|
||||
close={hideDialog}
|
||||
>
|
||||
{contentIsVisible.get() && <AddingOfCustomHelmRepositoryDialogContent />}
|
||||
</Dialog>
|
||||
</div>
|
||||
));
|
||||
|
||||
|
||||
export const AddingOfCustomHelmRepositoryDialog = withInjectables<Dependencies>(
|
||||
NonInjectedActivationOfCustomHelmRepositoryDialog,
|
||||
|
||||
{
|
||||
getProps: (di) => ({
|
||||
contentIsVisible: di.inject(addingOfCustomHelmRepositoryDialogIsVisibleInjectable),
|
||||
hideDialog: di.inject(hideDialogForAddingCustomHelmRepositoryInjectable),
|
||||
}),
|
||||
},
|
||||
);
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import React from "react";
|
||||
import { Button } from "../../../../button";
|
||||
import showDialogForAddingCustomHelmRepositoryInjectable from "./dialog-visibility/show-dialog-for-adding-custom-helm-repository.injectable";
|
||||
|
||||
interface Dependencies {
|
||||
showDialog: () => void;
|
||||
}
|
||||
|
||||
const NonInjectedActivationOfCustomHelmRepositoryOpenButton = ({ showDialog }: Dependencies) => (
|
||||
<Button
|
||||
primary
|
||||
label="Add Custom Helm Repo"
|
||||
onClick={showDialog}
|
||||
data-testid="add-custom-helm-repo-button"
|
||||
/>
|
||||
);
|
||||
|
||||
export const AddingOfCustomHelmRepositoryOpenButton = withInjectables<Dependencies>(
|
||||
NonInjectedActivationOfCustomHelmRepositoryOpenButton,
|
||||
|
||||
{
|
||||
getProps: (di) => ({
|
||||
showDialog: di.inject(showDialogForAddingCustomHelmRepositoryInjectable),
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable, lifecycleEnum } from "@ogre-tools/injectable";
|
||||
import { observable } from "mobx";
|
||||
|
||||
const customHelmRepoInjectable = getInjectable({
|
||||
id: "custom-helm-repo",
|
||||
|
||||
instantiate: () => observable({
|
||||
name: "",
|
||||
url: "",
|
||||
username: "",
|
||||
password: "",
|
||||
insecureSkipTlsVerify: false,
|
||||
caFile: "",
|
||||
keyFile: "",
|
||||
certFile: "",
|
||||
}),
|
||||
|
||||
lifecycle: lifecycleEnum.transient,
|
||||
});
|
||||
|
||||
export default customHelmRepoInjectable;
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { observable } from "mobx";
|
||||
|
||||
const addingOfCustomHelmRepositoryDialogIsVisibleInjectable = getInjectable({
|
||||
id: "adding-of-custom-helm-repository-dialog-is-visible",
|
||||
instantiate: () => observable.box(false),
|
||||
});
|
||||
|
||||
export default addingOfCustomHelmRepositoryDialogIsVisibleInjectable;
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { action } from "mobx";
|
||||
import addingOfCustomHelmRepositoryDialogIsVisibleInjectable from "./adding-of-custom-helm-repository-dialog-is-visible.injectable";
|
||||
|
||||
const hideDialogForAddingCustomHelmRepositoryInjectable = getInjectable({
|
||||
id: "hide-dialog-for-adding-custom-helm-repository",
|
||||
|
||||
instantiate: (di) => {
|
||||
const state = di.inject(addingOfCustomHelmRepositoryDialogIsVisibleInjectable);
|
||||
|
||||
return action(() => {
|
||||
state.set(false);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default hideDialogForAddingCustomHelmRepositoryInjectable;
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { action } from "mobx";
|
||||
import addingOfCustomHelmRepositoryDialogIsVisibleInjectable from "./adding-of-custom-helm-repository-dialog-is-visible.injectable";
|
||||
|
||||
const showDialogForAddingCustomHelmRepositoryInjectable = getInjectable({
|
||||
id: "show-dialog-for-adding-custom-helm-repository",
|
||||
|
||||
instantiate: (di) => {
|
||||
const state = di.inject(addingOfCustomHelmRepositoryDialogIsVisibleInjectable);
|
||||
|
||||
return action(() => {
|
||||
state.set(true);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default showDialogForAddingCustomHelmRepositoryInjectable;
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { FileFilter } from "electron";
|
||||
import { requestOpenFilePickingDialog } from "../../../../../../ipc";
|
||||
|
||||
const getFilePathsInjectable = getInjectable({
|
||||
id: "get-file-paths",
|
||||
|
||||
instantiate: () => async (fileFilter: FileFilter) =>
|
||||
await requestOpenFilePickingDialog({
|
||||
properties: ["openFile", "showHiddenFiles"],
|
||||
message: `Select file`,
|
||||
buttonLabel: `Use file`,
|
||||
filters: [fileFilter, { name: "Any", extensions: ["*"] }],
|
||||
}),
|
||||
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default getFilePathsInjectable;
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { InputValidator } from "../../../../../input";
|
||||
import { Input } from "../../../../../input";
|
||||
import { Icon } from "../../../../../icon";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import React from "react";
|
||||
import getFilePathsInjectable from "./get-file-paths.injectable";
|
||||
import type { FileFilter } from "electron";
|
||||
import isPathInjectable from "../../../../../input/validators/is-path.injectable";
|
||||
|
||||
interface HelmFileInputProps {
|
||||
placeholder: string;
|
||||
fileExtensions: string[];
|
||||
value: string;
|
||||
setValue: (value: string) => void;
|
||||
"data-testid"?: string;
|
||||
}
|
||||
|
||||
interface Dependencies {
|
||||
getFilePaths: (fileFilter: FileFilter) => Promise<{ canceled: boolean; filePaths: string[] }>;
|
||||
isPath: InputValidator<true>;
|
||||
}
|
||||
|
||||
const NonInjectedHelmFileInput = ({
|
||||
placeholder,
|
||||
value,
|
||||
setValue,
|
||||
fileExtensions,
|
||||
getFilePaths,
|
||||
isPath,
|
||||
"data-testid": testId,
|
||||
}: Dependencies & HelmFileInputProps) => (
|
||||
<div className="flex gaps align-center">
|
||||
<Input
|
||||
placeholder={placeholder}
|
||||
validators={isPath}
|
||||
className="box grow"
|
||||
value={value}
|
||||
onChange={(v) => setValue(v)}
|
||||
data-testid={testId}
|
||||
/>
|
||||
<Icon
|
||||
material="folder"
|
||||
|
||||
onClick={async () => {
|
||||
const { canceled, filePaths } = await getFilePaths({
|
||||
name: placeholder,
|
||||
extensions: fileExtensions,
|
||||
});
|
||||
|
||||
if (!canceled && filePaths.length) {
|
||||
setValue(filePaths[0]);
|
||||
}
|
||||
}}
|
||||
|
||||
tooltip="Browse"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
export const HelmFileInput = withInjectables<Dependencies, HelmFileInputProps>(
|
||||
NonInjectedHelmFileInput,
|
||||
|
||||
{
|
||||
getProps: (di, props) => ({
|
||||
getFilePaths: di.inject(getFilePathsInjectable),
|
||||
isPath: di.inject(isPathInjectable),
|
||||
...props,
|
||||
}),
|
||||
},
|
||||
);
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { observable } from "mobx";
|
||||
|
||||
const maximalCustomHelmRepoOptionsAreShownInjectable = getInjectable({
|
||||
id: "maximal-custom-helm-repo-options-are-shown",
|
||||
instantiate: () => observable.box(false),
|
||||
});
|
||||
|
||||
export default maximalCustomHelmRepoOptionsAreShownInjectable;
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { HelmRepo } from "../../../../../../common/helm/helm-repo";
|
||||
import addHelmRepositoryInjectable from "../adding-of-public-helm-repository/select-helm-repository/add-helm-repository.injectable";
|
||||
import hideDialogForAddingCustomHelmRepositoryInjectable from "./dialog-visibility/hide-dialog-for-adding-custom-helm-repository.injectable";
|
||||
|
||||
const submitCustomHelmRepositoryInjectable = getInjectable({
|
||||
id: "submit-custom-helm-repository",
|
||||
|
||||
instantiate: (di) => {
|
||||
const addHelmRepository = di.inject(addHelmRepositoryInjectable);
|
||||
const hideDialog = di.inject(hideDialogForAddingCustomHelmRepositoryInjectable);
|
||||
|
||||
return async (repository: HelmRepo) => {
|
||||
await addHelmRepository(repository);
|
||||
|
||||
hideDialog();
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default submitCustomHelmRepositoryInjectable;
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { IAsyncComputed } from "@ogre-tools/injectable-react";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import React from "react";
|
||||
import publicHelmRepositoriesInjectable from "./public-helm-repositories/public-helm-repositories.injectable";
|
||||
import type { HelmRepo } from "../../../../../../common/helm/helm-repo";
|
||||
import type { SelectOption } from "../../../../select";
|
||||
import { Select } from "../../../../select";
|
||||
import { Icon } from "../../../../icon";
|
||||
import { observer } from "mobx-react";
|
||||
import type { SingleValue } from "react-select";
|
||||
import selectHelmRepositoryInjectable from "./select-helm-repository/select-helm-repository.injectable";
|
||||
import { matches } from "lodash/fp";
|
||||
import activeHelmRepositoriesInjectable from "../active-helm-repositories.injectable";
|
||||
|
||||
interface Dependencies {
|
||||
publicRepositories: IAsyncComputed<HelmRepo[]>;
|
||||
activeRepositories: IAsyncComputed<HelmRepo[]>;
|
||||
selectRepository: (value: SingleValue<SelectOption<HelmRepo>>) => void;
|
||||
}
|
||||
|
||||
const NonInjectedAddingOfPublicHelmRepository = observer(({
|
||||
publicRepositories,
|
||||
activeRepositories,
|
||||
selectRepository,
|
||||
}: Dependencies) => {
|
||||
const dereferencesPublicRepositories = publicRepositories.value.get();
|
||||
const dereferencesActiveRepositories = activeRepositories.value.get();
|
||||
|
||||
const valuesAreLoading = publicRepositories.pending.get() || activeRepositories.pending.get();
|
||||
|
||||
const repositoryOptions = dereferencesPublicRepositories.map(repository => ({
|
||||
value: repository,
|
||||
label: repository.name,
|
||||
isSelected: !!dereferencesActiveRepositories.find(matches({ name: repository.name })),
|
||||
}));
|
||||
|
||||
return (
|
||||
<Select
|
||||
id="selection-of-active-public-helm-repository"
|
||||
placeholder="Repositories"
|
||||
isLoading={valuesAreLoading}
|
||||
isDisabled={valuesAreLoading}
|
||||
options={repositoryOptions}
|
||||
onChange={selectRepository}
|
||||
value={dereferencesPublicRepositories}
|
||||
formatOptionLabel={formatOptionLabel}
|
||||
controlShouldRenderValue={false}
|
||||
className="box grow"
|
||||
themeName="lens"
|
||||
/>
|
||||
);
|
||||
});
|
||||
|
||||
export const AddingOfPublicHelmRepository = withInjectables<Dependencies>(
|
||||
NonInjectedAddingOfPublicHelmRepository,
|
||||
|
||||
{
|
||||
getProps: (di) => ({
|
||||
publicRepositories: di.inject(publicHelmRepositoriesInjectable),
|
||||
activeRepositories: di.inject(activeHelmRepositoriesInjectable),
|
||||
selectRepository: di.inject(selectHelmRepositoryInjectable),
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
const formatOptionLabel = ({ value, isSelected }: SelectOption<HelmRepo>) => (
|
||||
<div className="flex gaps">
|
||||
<span>{value.name}</span>
|
||||
{isSelected && (
|
||||
<Icon
|
||||
small
|
||||
material="check"
|
||||
className="box right" />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { sortBy } from "lodash/fp";
|
||||
import type { HelmRepo } from "../../../../../../../common/helm/helm-repo";
|
||||
import { customRequestPromise } from "../../../../../../../common/request";
|
||||
|
||||
const callForPublicHelmRepositoriesInjectable = getInjectable({
|
||||
id: "call-for-public-helm-repositories",
|
||||
|
||||
instantiate: () => async (): Promise<HelmRepo[]> => {
|
||||
const res = await customRequestPromise({
|
||||
uri: "https://github.com/lensapp/artifact-hub-repositories/releases/download/latest/repositories.json",
|
||||
json: true,
|
||||
resolveWithFullResponse: true,
|
||||
timeout: 10000,
|
||||
});
|
||||
|
||||
const repositories = res.body as HelmRepo[];
|
||||
|
||||
return sortBy(repo => repo.name, repositories);
|
||||
},
|
||||
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default callForPublicHelmRepositoriesInjectable;
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { asyncComputed } from "@ogre-tools/injectable-react";
|
||||
import callForPublicHelmRepositoriesInjectable from "./call-for-public-helm-repositories.injectable";
|
||||
|
||||
const publicHelmRepositoriesInjectable = getInjectable({
|
||||
id: "public-helm-repositories",
|
||||
|
||||
instantiate: (di) => {
|
||||
const callForPublicHelmRepositories = di.inject(callForPublicHelmRepositoriesInjectable);
|
||||
|
||||
return asyncComputed(async () => {
|
||||
return await callForPublicHelmRepositories();
|
||||
}, []);
|
||||
},
|
||||
});
|
||||
|
||||
export default publicHelmRepositoriesInjectable;
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import addHelmRepositoryChannelInjectable from "../../../../../../../common/helm/add-helm-repository-channel.injectable";
|
||||
import type { HelmRepo } from "../../../../../../../common/helm/helm-repo";
|
||||
import { requestFromChannelInjectionToken } from "../../../../../../../common/utils/channel/request-from-channel-injection-token";
|
||||
import activeHelmRepositoriesInjectable from "../../active-helm-repositories.injectable";
|
||||
import showErrorNotificationInjectable from "../../../../../notifications/show-error-notification.injectable";
|
||||
import showSuccessNotificationInjectable from "../../../../../notifications/show-success-notification.injectable";
|
||||
|
||||
const addHelmRepositoryInjectable = getInjectable({
|
||||
id: "add-public-helm-repository",
|
||||
|
||||
instantiate: (di) => {
|
||||
const requestFromChannel = di.inject(requestFromChannelInjectionToken);
|
||||
const addHelmRepositoryChannel = di.inject(addHelmRepositoryChannelInjectable);
|
||||
const activeHelmRepositories = di.inject(activeHelmRepositoriesInjectable);
|
||||
const showErrorNotification = di.inject(showErrorNotificationInjectable);
|
||||
const showSuccessNotification = di.inject(showSuccessNotificationInjectable);
|
||||
|
||||
return async (repository: HelmRepo) => {
|
||||
const result = await requestFromChannel(
|
||||
addHelmRepositoryChannel,
|
||||
repository,
|
||||
);
|
||||
|
||||
if (result.callWasSuccessful) {
|
||||
showSuccessNotification(
|
||||
`Helm repository ${repository.name} has been added.`,
|
||||
);
|
||||
|
||||
activeHelmRepositories.invalidate();
|
||||
} else {
|
||||
showErrorNotification(result.error);
|
||||
}
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default addHelmRepositoryInjectable;
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import addHelmRepositoryInjectable from "./add-helm-repository.injectable";
|
||||
import type { SelectOption } from "../../../../../select";
|
||||
import type { HelmRepo } from "../../../../../../../common/helm/helm-repo";
|
||||
import type { SingleValue } from "react-select";
|
||||
import removeHelmRepositoryInjectable from "../../remove-helm-repository.injectable";
|
||||
|
||||
const selectHelmRepositoryInjectable = getInjectable({
|
||||
id: "select-helm-repository",
|
||||
|
||||
instantiate: (di) => {
|
||||
const addHelmRepository = di.inject(addHelmRepositoryInjectable);
|
||||
const removeHelmRepository = di.inject(removeHelmRepositoryInjectable);
|
||||
|
||||
return (selected: SingleValue<SelectOption<HelmRepo>>) => {
|
||||
if (!selected) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!selected.isSelected) {
|
||||
addHelmRepository(selected.value);
|
||||
} else {
|
||||
removeHelmRepository(selected.value);
|
||||
}
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default selectHelmRepositoryInjectable;
|
||||
+12
-2
@@ -4,12 +4,22 @@
|
||||
*/
|
||||
|
||||
.repos {
|
||||
@apply mt-6 flex flex-col;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-top: calc(var(--margin) * 2);
|
||||
}
|
||||
|
||||
.repos .repo + .repo {
|
||||
margin-top: calc(var(--margin) * 1.5);
|
||||
}
|
||||
|
||||
.contents {
|
||||
display: flex;
|
||||
gap: var(--padding);
|
||||
}
|
||||
|
||||
.repoName {
|
||||
font-weight: 500;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.repoUrl {
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
|
||||
import { HelmRepositories } from "./helm-repositories";
|
||||
import { AddingOfPublicHelmRepository } from "./adding-of-public-helm-repository/adding-of-public-helm-repository";
|
||||
import { AddingOfCustomHelmRepositoryOpenButton } from "./adding-of-custom-helm-repository/adding-of-custom-helm-repository-open-button";
|
||||
import { AddingOfCustomHelmRepositoryDialog } from "./adding-of-custom-helm-repository/adding-of-custom-helm-repository-dialog";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import type { HelmRepositoriesErrorState } from "./helm-repositories-error-state.injectable";
|
||||
import helmRepositoriesErrorStateInjectable from "./helm-repositories-error-state.injectable";
|
||||
import type { IObservableValue } from "mobx";
|
||||
import { observer } from "mobx-react";
|
||||
import { Notice } from "../../../+extensions/notice";
|
||||
|
||||
interface Dependencies {
|
||||
helmRepositoriesErrorState: IObservableValue<HelmRepositoriesErrorState>;
|
||||
}
|
||||
|
||||
const NonInjectedHelmCharts = observer(
|
||||
({ helmRepositoriesErrorState }: Dependencies) => {
|
||||
const state = helmRepositoriesErrorState.get();
|
||||
|
||||
return (
|
||||
<div>
|
||||
{!state.controlsAreShown && (
|
||||
<Notice>
|
||||
<div className="flex-grow text-center">{state.errorMessage}</div>
|
||||
</Notice>
|
||||
)}
|
||||
|
||||
{state.controlsAreShown && (
|
||||
<div data-testid="helm-controls">
|
||||
<div className="flex gaps">
|
||||
<AddingOfPublicHelmRepository />
|
||||
|
||||
<AddingOfCustomHelmRepositoryOpenButton />
|
||||
</div>
|
||||
|
||||
<HelmRepositories />
|
||||
|
||||
<AddingOfCustomHelmRepositoryDialog />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
export const HelmCharts = withInjectables<Dependencies>(
|
||||
NonInjectedHelmCharts,
|
||||
|
||||
{
|
||||
getProps: (di) => ({
|
||||
helmRepositoriesErrorState: di.inject(helmRepositoriesErrorStateInjectable),
|
||||
}),
|
||||
},
|
||||
);
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { observable } from "mobx";
|
||||
|
||||
export type HelmRepositoriesErrorState =
|
||||
| { controlsAreShown: true }
|
||||
| { controlsAreShown: false; errorMessage: string };
|
||||
|
||||
const helmRepositoriesErrorStateInjectable = getInjectable({
|
||||
id: "helm-repositories-error-state",
|
||||
|
||||
instantiate: () =>
|
||||
observable.box<HelmRepositoriesErrorState>({ controlsAreShown: true }),
|
||||
});
|
||||
|
||||
export default helmRepositoriesErrorStateInjectable;
|
||||
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import styles from "./helm-charts.module.scss";
|
||||
|
||||
import React from "react";
|
||||
|
||||
import { observer } from "mobx-react";
|
||||
import activeHelmRepositoriesInjectable from "./active-helm-repositories.injectable";
|
||||
import type { IAsyncComputed } from "@ogre-tools/injectable-react";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import { Spinner } from "../../../spinner";
|
||||
import type { HelmRepo } from "../../../../../common/helm/helm-repo";
|
||||
import { RemovableItem } from "../../removable-item";
|
||||
import removeHelmRepositoryInjectable from "./remove-helm-repository.injectable";
|
||||
|
||||
interface Dependencies {
|
||||
activeHelmRepositories: IAsyncComputed<HelmRepo[]>;
|
||||
removeRepository: (repository: HelmRepo) => Promise<void>;
|
||||
}
|
||||
|
||||
const NonInjectedActiveHelmRepositories = observer(({ activeHelmRepositories, removeRepository }: Dependencies) => {
|
||||
if (activeHelmRepositories.pending.get()) {
|
||||
return (
|
||||
<div className={styles.repos}>
|
||||
<div className="pt-5 relative">
|
||||
<Spinner center data-testid="helm-repositories-are-loading" />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const repositories = activeHelmRepositories.value.get();
|
||||
|
||||
return (
|
||||
<div className={styles.repos}>
|
||||
{repositories.map((repository) => (
|
||||
<RemovableItem
|
||||
key={repository.name}
|
||||
onRemove={() => removeRepository(repository)}
|
||||
className={styles.repo}
|
||||
data-testid={`remove-helm-repository-${repository.name}`}
|
||||
>
|
||||
<div>
|
||||
<div data-testid={`helm-repository-${repository.name}`} className={styles.repoName}>
|
||||
{repository.name}
|
||||
</div>
|
||||
|
||||
<div className={styles.repoUrl}>{repository.url}</div>
|
||||
</div>
|
||||
</RemovableItem>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
export const HelmRepositories = withInjectables<Dependencies>(
|
||||
NonInjectedActiveHelmRepositories,
|
||||
|
||||
{
|
||||
getProps: (di) => ({
|
||||
activeHelmRepositories: di.inject(activeHelmRepositoriesInjectable),
|
||||
removeRepository: di.inject(removeHelmRepositoryInjectable),
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { HelmRepo } from "../../../../../common/helm/helm-repo";
|
||||
import { requestFromChannelInjectionToken } from "../../../../../common/utils/channel/request-from-channel-injection-token";
|
||||
import activeHelmRepositoriesInjectable from "./active-helm-repositories.injectable";
|
||||
import removeHelmRepositoryChannelInjectable from "../../../../../common/helm/remove-helm-repository-channel.injectable";
|
||||
|
||||
const removePublicHelmRepositoryInjectable = getInjectable({
|
||||
id: "remove-public-helm-repository",
|
||||
|
||||
instantiate: (di) => {
|
||||
const requestFromChannel = di.inject(requestFromChannelInjectionToken);
|
||||
const removeHelmRepositoryChannel = di.inject(removeHelmRepositoryChannelInjectable);
|
||||
const activeHelmRepositories = di.inject(activeHelmRepositoriesInjectable);
|
||||
|
||||
return async (repository: HelmRepo) => {
|
||||
await requestFromChannel(removeHelmRepositoryChannel, repository);
|
||||
|
||||
activeHelmRepositories.invalidate();
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default removePublicHelmRepositoryInjectable;
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import "@testing-library/jest-dom/extend-expect";
|
||||
import type { RenderResult } from "@testing-library/react";
|
||||
import { computed } from "mobx";
|
||||
import { noop } from "../../../../utils";
|
||||
import type { ApplicationBuilder } from "../../../test-utils/get-application-builder";
|
||||
import { getApplicationBuilder } from "../../../test-utils/get-application-builder";
|
||||
import type { PreferenceNavigationItem } from "../preference-navigation-items.injectable";
|
||||
import preferenceNavigationItemsInjectable from "../preference-navigation-items.injectable";
|
||||
|
||||
describe.only("preferences - navigation block with links", () => {
|
||||
let applicationBuilder: ApplicationBuilder;
|
||||
|
||||
beforeEach(() => {
|
||||
applicationBuilder = getApplicationBuilder();
|
||||
});
|
||||
|
||||
describe("given in preferences, when rendered", () => {
|
||||
let renderer: RenderResult;
|
||||
|
||||
describe("when general navigation items passed", () => {
|
||||
beforeEach(async () => {
|
||||
applicationBuilder.beforeApplicationStart(({ rendererDi }) => {
|
||||
rendererDi.override(preferenceNavigationItemsInjectable, () =>
|
||||
computed(() => generalNavItems),
|
||||
);
|
||||
});
|
||||
|
||||
applicationBuilder.beforeRender(() => {
|
||||
applicationBuilder.preferences.navigate();
|
||||
});
|
||||
|
||||
renderer = await applicationBuilder.render();
|
||||
});
|
||||
|
||||
const links = ["General", "Proxy"];
|
||||
|
||||
it.each(links)("renders link with text content %s", (link) => {
|
||||
expect(renderer.container).toHaveTextContent(link);
|
||||
});
|
||||
|
||||
it("does not show custom settings block", () => {
|
||||
expect(
|
||||
renderer.queryByTestId("extension-settings"),
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("when general + extension navigation items passed", () => {
|
||||
beforeEach(async () => {
|
||||
applicationBuilder.beforeApplicationStart(({ rendererDi }) => {
|
||||
rendererDi.override(preferenceNavigationItemsInjectable, () =>
|
||||
computed(() => [...generalNavItems, ...extensionNavItems]),
|
||||
);
|
||||
});
|
||||
|
||||
applicationBuilder.beforeRender(() => {
|
||||
applicationBuilder.preferences.navigate();
|
||||
});
|
||||
|
||||
renderer = await applicationBuilder.render();
|
||||
});
|
||||
|
||||
const generalLinks = ["General", "Proxy"];
|
||||
|
||||
it.each(generalLinks)(
|
||||
"renders general link with text content %s",
|
||||
(link) => {
|
||||
expect(renderer.container).toHaveTextContent(link);
|
||||
},
|
||||
);
|
||||
|
||||
it("shows custom settings block", () => {
|
||||
expect(
|
||||
renderer.queryByTestId("extension-settings"),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
const extensionLinks = ["lensapp-node-menu", "lensapp-pod-menu"];
|
||||
|
||||
it.each(extensionLinks)("shows extension navigation item %s", (link) => {
|
||||
expect(
|
||||
renderer.getByTestId(
|
||||
`tab-link-for-extension-preferences-navigation-item-${link}`,
|
||||
),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders extension navigation items inside custom settings block", () => {
|
||||
const settingsBlock = renderer.getByTestId("extension-settings");
|
||||
|
||||
expect(settingsBlock).toHaveTextContent("lensapp-node-menu");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const generalNavItems: PreferenceNavigationItem[] = [
|
||||
{
|
||||
id: "general",
|
||||
label: "General",
|
||||
isActive: computed(() => false),
|
||||
isVisible: computed(() => true),
|
||||
navigate: () => noop,
|
||||
orderNumber: 0,
|
||||
parent: "general",
|
||||
},
|
||||
{
|
||||
id: "proxy",
|
||||
label: "Proxy",
|
||||
isActive: computed(() => false),
|
||||
isVisible: computed(() => true),
|
||||
navigate: () => noop,
|
||||
orderNumber: 1,
|
||||
parent: "general",
|
||||
},
|
||||
];
|
||||
|
||||
const extensionNavItems = [
|
||||
{
|
||||
id: "extension-preferences-navigation-item-lensapp-node-menu",
|
||||
label: "lensapp-node-menu",
|
||||
isActive: computed(() => false),
|
||||
isVisible: computed(() => true),
|
||||
navigate: () => noop,
|
||||
orderNumber: 0,
|
||||
parent: "extensions",
|
||||
},
|
||||
{
|
||||
id: "extension-preferences-navigation-item-lensapp-pod-menu",
|
||||
label: "lensapp-pod-menu",
|
||||
isActive: computed(() => false),
|
||||
isVisible: computed(() => true),
|
||||
navigate: () => noop,
|
||||
orderNumber: 0,
|
||||
parent: "extensions",
|
||||
},
|
||||
{
|
||||
id: "extension-preferences-navigation-item-metrics-plugin",
|
||||
label: "metrics-plugin",
|
||||
isActive: computed(() => false),
|
||||
isVisible: computed(() => false),
|
||||
navigate: () => noop,
|
||||
orderNumber: 0,
|
||||
parent: "extensions",
|
||||
},
|
||||
];
|
||||
|
||||
+1
@@ -24,6 +24,7 @@ const applicationPreferencesNavigationItemInjectable = getInjectable({
|
||||
return {
|
||||
id: "application",
|
||||
label: "App",
|
||||
parent: "general",
|
||||
navigate: navigateToPreferenceTab(route),
|
||||
isActive: routeIsActive,
|
||||
isVisible: computed(() => true),
|
||||
|
||||
+1
@@ -24,6 +24,7 @@ const editorPreferencesNavigationItemInjectable = getInjectable({
|
||||
return {
|
||||
id: "editor",
|
||||
label: "Editor",
|
||||
parent: "general",
|
||||
navigate: navigateToPreferenceTab(route),
|
||||
isActive: routeIsActive,
|
||||
isVisible: computed(() => true),
|
||||
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { computed } from "mobx";
|
||||
import { map } from "lodash/fp";
|
||||
|
||||
import routeIsActiveInjectable from "../../../routes/route-is-active.injectable";
|
||||
import { preferenceNavigationItemInjectionToken } from "./preference-navigation-items.injectable";
|
||||
|
||||
import type { LensRendererExtension } from "../../../../extensions/lens-renderer-extension";
|
||||
import { extensionRegistratorInjectionToken } from "../../../../extensions/extension-loader/extension-registrator-injection-token";
|
||||
import { pipeline } from "@ogre-tools/fp";
|
||||
import extensionPreferencesRouteInjectable from "../../../../common/front-end-routing/routes/preferences/extension/extension-preferences-route.injectable";
|
||||
import navigateToExtensionPreferencesInjectable from "../../../../common/front-end-routing/routes/preferences/extension/navigate-to-extension-preferences.injectable";
|
||||
import type { LensExtension } from "../../../../extensions/lens-extension";
|
||||
import routePathParametersInjectable from "../../../routes/route-path-parameters.injectable";
|
||||
|
||||
const extensionSpecificTabNavigationItemRegistratorInjectable = getInjectable({
|
||||
id: "extension-specific-tab-preferences-navigation-items",
|
||||
|
||||
instantiate: (di) => {
|
||||
return (ext: LensExtension) => {
|
||||
const extension = ext as LensRendererExtension;
|
||||
const navigateToExtensionPreferences = di.inject(
|
||||
navigateToExtensionPreferencesInjectable,
|
||||
);
|
||||
const route = di.inject(extensionPreferencesRouteInjectable);
|
||||
const routeIsActive = di.inject(routeIsActiveInjectable, route);
|
||||
const pathParameters = di.inject(routePathParametersInjectable, route);
|
||||
|
||||
return pipeline(
|
||||
extension.appPreferenceTabs,
|
||||
|
||||
map((tab) => {
|
||||
const id = `extension-${extension.sanitizedExtensionId}-nav-item-${tab.id}`;
|
||||
const isActive = computed(() => routeIsActive.get() && pathParameters.get().tabId === tab.id);
|
||||
|
||||
return getInjectable({
|
||||
id,
|
||||
injectionToken: preferenceNavigationItemInjectionToken,
|
||||
instantiate: () => ({
|
||||
id,
|
||||
label: tab.title,
|
||||
parent: "general",
|
||||
orderNumber: tab.orderNumber || 100,
|
||||
navigate: () => navigateToExtensionPreferences(extension.sanitizedExtensionId, tab.id),
|
||||
isVisible: computed(() => true),
|
||||
isActive,
|
||||
}),
|
||||
});
|
||||
}),
|
||||
);
|
||||
};
|
||||
},
|
||||
injectionToken: extensionRegistratorInjectionToken,
|
||||
});
|
||||
|
||||
export default extensionSpecificTabNavigationItemRegistratorInjectable;
|
||||
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import React from "react";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import type { IComputedValue } from "mobx";
|
||||
import type { PreferenceNavigationItem } from "./preference-navigation-items.injectable";
|
||||
import { Icon } from "../../icon";
|
||||
import { PreferencesNavigationTab } from "./preference-navigation-tab";
|
||||
import preferenceNavigationItemsForGroupInjectable from "./preference-navigation-items-for-group.injectable";
|
||||
import { observer } from "mobx-react";
|
||||
|
||||
interface Dependencies {
|
||||
navigationItems: IComputedValue<PreferenceNavigationItem[]>;
|
||||
}
|
||||
|
||||
const NonInjectedExtensionsNavGroup = observer((props: Dependencies) => {
|
||||
if (!props.navigationItems.get().length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div data-testid="extension-settings">
|
||||
<hr/>
|
||||
<div className="header flex items-center">
|
||||
<Icon
|
||||
material="extension"
|
||||
smallest
|
||||
className="mr-3"
|
||||
/>
|
||||
{" "}
|
||||
Extensions
|
||||
</div>
|
||||
<div>
|
||||
{props.navigationItems.get().map(item => (
|
||||
<PreferencesNavigationTab
|
||||
key={item.id}
|
||||
item={item}
|
||||
data-testid={`tab-link-for-${item.id}`}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
export const ExtensionsNavGroup = withInjectables<Dependencies>(
|
||||
NonInjectedExtensionsNavGroup,
|
||||
|
||||
{
|
||||
getProps: (di) => ({
|
||||
navigationItems: di.inject(preferenceNavigationItemsForGroupInjectable, "extensions"),
|
||||
}),
|
||||
},
|
||||
);
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { computed } from "mobx";
|
||||
import extensionPreferencesRouteInjectable from "../../../../common/front-end-routing/routes/preferences/extension/extension-preferences-route.injectable";
|
||||
import navigateToExtensionPreferencesInjectable from "../../../../common/front-end-routing/routes/preferences/extension/navigate-to-extension-preferences.injectable";
|
||||
import { extensionRegistratorInjectionToken } from "../../../../extensions/extension-loader/extension-registrator-injection-token";
|
||||
import type { LensRendererExtension } from "../../../../extensions/lens-renderer-extension";
|
||||
import routeIsActiveInjectable from "../../../routes/route-is-active.injectable";
|
||||
import routePathParametersInjectable from "../../../routes/route-path-parameters.injectable";
|
||||
import { preferenceNavigationItemInjectionToken } from "./preference-navigation-items.injectable";
|
||||
|
||||
const extensionPreferencesNavigationItemRegistratorInjectable = getInjectable({
|
||||
id: "extension-preferences-navigation-item",
|
||||
|
||||
instantiate: (di) => {
|
||||
return (ext) => {
|
||||
const extension = ext as LensRendererExtension;
|
||||
const navigateToExtensionPreferences = di.inject(
|
||||
navigateToExtensionPreferencesInjectable,
|
||||
);
|
||||
|
||||
const extensionHasPreferences = extension.appPreferences.length > 0;
|
||||
const extensionHasGeneralPreferences = extension.appPreferences.some(preferences =>
|
||||
!preferences.showInPreferencesTab,
|
||||
);
|
||||
const isVisible = computed(() => extensionHasPreferences && extensionHasGeneralPreferences);
|
||||
const extensionRoute = di.inject(extensionPreferencesRouteInjectable);
|
||||
const pathParameters = di.inject(routePathParametersInjectable, extensionRoute);
|
||||
const routeIsActive = di.inject(routeIsActiveInjectable, extensionRoute);
|
||||
const isActive = computed(() => routeIsActive.get() && pathParameters.get().extensionId === extension.sanitizedExtensionId);
|
||||
const id = `extension-preferences-navigation-item-${extension.sanitizedExtensionId}`;
|
||||
|
||||
const injectable = getInjectable({
|
||||
id,
|
||||
injectionToken: preferenceNavigationItemInjectionToken,
|
||||
instantiate: () => ({
|
||||
id: `extension-${extension.sanitizedExtensionId}`,
|
||||
label: `${extension.name}`,
|
||||
navigate: () => navigateToExtensionPreferences(extension.sanitizedExtensionId),
|
||||
isActive,
|
||||
isVisible,
|
||||
orderNumber: 20,
|
||||
parent: "extensions",
|
||||
}),
|
||||
});
|
||||
|
||||
return [injectable];
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: extensionRegistratorInjectionToken,
|
||||
});
|
||||
|
||||
export default extensionPreferencesNavigationItemRegistratorInjectable;
|
||||
-51
@@ -1,51 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { preferenceNavigationItemInjectionToken } from "./preference-navigation-items.injectable";
|
||||
import routeIsActiveInjectable from "../../../routes/route-is-active.injectable";
|
||||
import { computed } from "mobx";
|
||||
import extensionsPreferenceItemsInjectable from "../extension-preference-items.injectable";
|
||||
import extensionPreferencesRouteInjectable from "../../../../common/front-end-routing/routes/preferences/extension/extension-preferences-route.injectable";
|
||||
import navigateToPreferenceTabInjectable from "./navigate-to-preference-tab.injectable";
|
||||
|
||||
const extensionsPreferencesNavigationItemInjectable = getInjectable({
|
||||
id: "extension-preferences-navigation-item",
|
||||
|
||||
instantiate: (di) => {
|
||||
const preferenceItems = di.inject(
|
||||
extensionsPreferenceItemsInjectable,
|
||||
);
|
||||
|
||||
const navigateToPreferenceTab = di.inject(
|
||||
navigateToPreferenceTabInjectable,
|
||||
);
|
||||
|
||||
const route = di.inject(
|
||||
extensionPreferencesRouteInjectable,
|
||||
);
|
||||
|
||||
const routeIsActive = di.inject(
|
||||
routeIsActiveInjectable,
|
||||
route,
|
||||
);
|
||||
|
||||
return {
|
||||
id: "extensions",
|
||||
label: "Extensions",
|
||||
navigate: navigateToPreferenceTab(route),
|
||||
isActive: routeIsActive,
|
||||
|
||||
isVisible: computed(
|
||||
() => preferenceItems.get().length > 0,
|
||||
),
|
||||
|
||||
orderNumber: 70,
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: preferenceNavigationItemInjectionToken,
|
||||
});
|
||||
|
||||
export default extensionsPreferencesNavigationItemInjectable;
|
||||
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import React from "react";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import type { IComputedValue } from "mobx";
|
||||
import type { PreferenceNavigationItem } from "./preference-navigation-items.injectable";
|
||||
import { PreferencesNavigationTab } from "./preference-navigation-tab";
|
||||
import preferenceNavigationItemsForGroupInjectable from "./preference-navigation-items-for-group.injectable";
|
||||
import { observer } from "mobx-react";
|
||||
|
||||
interface Dependencies {
|
||||
navigationItems: IComputedValue<PreferenceNavigationItem[]>;
|
||||
}
|
||||
|
||||
const NonInjectedGeneralNavGroup = observer((props: Dependencies) => {
|
||||
if (!props.navigationItems.get().length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
<div className="header">Preferences</div>
|
||||
|
||||
{props.navigationItems.get().map(item => (
|
||||
<PreferencesNavigationTab
|
||||
key={item.id}
|
||||
item={item}
|
||||
data-testid={`tab-link-for-${item.id}`}
|
||||
/>
|
||||
))}
|
||||
</React.Fragment>
|
||||
);
|
||||
});
|
||||
|
||||
export const GeneralNavGroup = withInjectables<Dependencies>(
|
||||
NonInjectedGeneralNavGroup,
|
||||
|
||||
{
|
||||
getProps: (di) => ({
|
||||
navigationItems: di.inject(preferenceNavigationItemsForGroupInjectable, "general"),
|
||||
}),
|
||||
},
|
||||
);
|
||||
+1
@@ -27,6 +27,7 @@ const kubernetesPreferencesNavigationItemInjectable = getInjectable({
|
||||
return {
|
||||
id: "kubernetes",
|
||||
label: "Kubernetes",
|
||||
parent: "general",
|
||||
navigate: navigateToPreferenceTab(route),
|
||||
isActive: routeIsActive,
|
||||
isVisible: computed(() => true),
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { Route } from "../../../../common/front-end-routing/route-injection-token";
|
||||
import type { Route } from "../../../../common/front-end-routing/front-end-route-injection-token";
|
||||
import { navigateToRouteInjectionToken } from "../../../../common/front-end-routing/navigate-to-route-injection-token";
|
||||
|
||||
const navigateToPreferenceTabInjectable = getInjectable({
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import {
|
||||
getInjectable,
|
||||
lifecycleEnum,
|
||||
} from "@ogre-tools/injectable";
|
||||
import { computed } from "mobx";
|
||||
import type { PreferenceNavigationItem } from "./preference-navigation-items.injectable";
|
||||
import preferenceNavigationItemsInjectable from "./preference-navigation-items.injectable";
|
||||
|
||||
const preferenceNavigationItemsForGroupInjectable = getInjectable({
|
||||
id: "preference-navigation-items-for-group",
|
||||
|
||||
instantiate: (di, group: string) => {
|
||||
const preferenceNavigationItems = di.inject(preferenceNavigationItemsInjectable);
|
||||
|
||||
return computed((): PreferenceNavigationItem[] =>
|
||||
preferenceNavigationItems.get().filter((item) => item.parent == group),
|
||||
);
|
||||
},
|
||||
|
||||
lifecycle: lifecycleEnum.keyedSingleton({
|
||||
getInstanceKey: (di, group: string) => group,
|
||||
}),
|
||||
});
|
||||
|
||||
export default preferenceNavigationItemsForGroupInjectable;
|
||||
|
||||
+10
-4
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
import { pipeline } from "@ogre-tools/fp";
|
||||
import { getInjectable, getInjectionToken } from "@ogre-tools/injectable";
|
||||
import { computedInjectManyInjectable } from "@ogre-tools/injectable-extension-for-mobx";
|
||||
import { filter, orderBy } from "lodash/fp";
|
||||
import type { IComputedValue } from "mobx";
|
||||
import { computed } from "mobx";
|
||||
@@ -20,19 +21,24 @@ export interface PreferenceNavigationItem {
|
||||
isVisible: IComputedValue<boolean>;
|
||||
navigate: () => void;
|
||||
orderNumber: number;
|
||||
parent: string;
|
||||
}
|
||||
|
||||
const preferenceNavigationItemsInjectable = getInjectable({
|
||||
id: "preference-navigation-items",
|
||||
|
||||
instantiate: (di) =>
|
||||
computed((): PreferenceNavigationItem[] =>
|
||||
instantiate: (di) => {
|
||||
const computedInjectMany = di.inject(computedInjectManyInjectable);
|
||||
const navigationItems = computedInjectMany(preferenceNavigationItemInjectionToken);
|
||||
|
||||
return computed((): PreferenceNavigationItem[] =>
|
||||
pipeline(
|
||||
di.injectMany(preferenceNavigationItemInjectionToken),
|
||||
navigationItems.get(),
|
||||
filter((item) => !!item.isVisible.get()),
|
||||
(items) => orderBy([(item) => item.orderNumber], ["asc"], items),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
export default preferenceNavigationItemsInjectable;
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { observer } from "mobx-react";
|
||||
import React from "react";
|
||||
import { Tab } from "../../tabs";
|
||||
import type { PreferenceNavigationItem } from "./preference-navigation-items.injectable";
|
||||
|
||||
interface PreferenceNavigationTabProps extends React.DOMAttributes<HTMLElement> {
|
||||
item: PreferenceNavigationItem;
|
||||
}
|
||||
|
||||
export const PreferencesNavigationTab = observer(({ item }: PreferenceNavigationTabProps) => (
|
||||
<Tab
|
||||
value={item}
|
||||
label={item.label}
|
||||
data-testid={`tab-link-for-${item.id}`}
|
||||
active={item.isActive.get()}
|
||||
/>
|
||||
));
|
||||
+15
-53
@@ -2,61 +2,23 @@
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { Tab, Tabs } from "../../tabs";
|
||||
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import type { IComputedValue } from "mobx";
|
||||
import React from "react";
|
||||
import { Tabs } from "../../tabs";
|
||||
import { ExtensionsNavGroup } from "./extensions-nav-group";
|
||||
import { GeneralNavGroup } from "./general-nav-group";
|
||||
import type {
|
||||
PreferenceNavigationItem,
|
||||
} from "./preference-navigation-items.injectable";
|
||||
import preferenceNavigationItemsInjectable from "./preference-navigation-items.injectable";
|
||||
|
||||
import { observer } from "mobx-react";
|
||||
|
||||
interface Dependencies {
|
||||
navigationItems: IComputedValue<PreferenceNavigationItem[]>;
|
||||
}
|
||||
|
||||
const NonInjectedPreferencesNavigation = ({
|
||||
navigationItems,
|
||||
}: Dependencies) => (
|
||||
<Tabs
|
||||
className="flex column"
|
||||
scrollable={false}
|
||||
onChange={(item: PreferenceNavigationItem) => item.navigate()}
|
||||
>
|
||||
<div className="header">Preferences</div>
|
||||
|
||||
{navigationItems.get().map((item) => (
|
||||
<PreferencesNavigationTab
|
||||
key={item.id}
|
||||
item={item}
|
||||
data-testid={`tab-link-for-${item.id}`}
|
||||
/>
|
||||
))}
|
||||
</Tabs>
|
||||
);
|
||||
|
||||
interface PreferenceNavigationTabProps extends React.DOMAttributes<HTMLElement> {
|
||||
item: PreferenceNavigationItem;
|
||||
}
|
||||
|
||||
const PreferencesNavigationTab = observer(({ item }: PreferenceNavigationTabProps) => (
|
||||
<Tab
|
||||
value={item}
|
||||
label={item.label}
|
||||
data-testid={`tab-link-for-${item.id}`}
|
||||
active={item.isActive.get()}
|
||||
/>
|
||||
));
|
||||
|
||||
export const PreferencesNavigation = withInjectables<Dependencies>(
|
||||
NonInjectedPreferencesNavigation,
|
||||
|
||||
{
|
||||
getProps: (di) => ({
|
||||
navigationItems: di.inject(preferenceNavigationItemsInjectable),
|
||||
}),
|
||||
},
|
||||
);
|
||||
export const PreferencesNavigation = () => {
|
||||
return (
|
||||
<Tabs
|
||||
className="flex column"
|
||||
scrollable={false}
|
||||
onChange={(item: PreferenceNavigationItem) => item.navigate()}
|
||||
>
|
||||
<GeneralNavGroup/>
|
||||
<ExtensionsNavGroup/>
|
||||
</Tabs>
|
||||
);
|
||||
};
|
||||
+1
@@ -24,6 +24,7 @@ const proxyPreferencesNavigationItemInjectable = getInjectable({
|
||||
return {
|
||||
id: "proxy",
|
||||
label: "Proxy",
|
||||
parent: "general",
|
||||
navigate: navigateToPreferenceTab(route),
|
||||
isActive: routeIsActive,
|
||||
isVisible: computed(() => true),
|
||||
|
||||
+1
@@ -32,6 +32,7 @@ const terminalPreferencesNavigationItemInjectable = getInjectable({
|
||||
return {
|
||||
id: "telemetry",
|
||||
label: "Telemetry",
|
||||
parent: "general",
|
||||
navigate: navigateToPreferenceTab(route),
|
||||
isActive: routeIsActive,
|
||||
|
||||
|
||||
+1
@@ -24,6 +24,7 @@ const terminalPreferencesNavigationItemInjectable = getInjectable({
|
||||
return {
|
||||
id: "terminal",
|
||||
label: "Terminal",
|
||||
parent: "general",
|
||||
navigate: navigateToPreferenceTab(route),
|
||||
isActive: routeIsActive,
|
||||
isVisible: computed(() => true),
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
.item {
|
||||
--flex-gap: 1.2rem;
|
||||
--flex-gap: 0.5rem;
|
||||
|
||||
@apply rounded-md px-7 py-5 shadow-sm;
|
||||
background: var(--inputControlBackground);
|
||||
min-height: 65px;
|
||||
border-radius: 3px;
|
||||
padding: calc(var(--padding) * 1.5);
|
||||
}
|
||||
@@ -14,9 +14,10 @@ export interface RemovableItemProps extends DOMAttributes<any>{
|
||||
icon?: string;
|
||||
onRemove: () => void;
|
||||
className?: string;
|
||||
"data-testid"?: string;
|
||||
}
|
||||
|
||||
export function RemovableItem({ icon, onRemove, children, className, ...rest }: RemovableItemProps) {
|
||||
export function RemovableItem({ icon, onRemove, children, className, "data-testid": testId, ...rest }: RemovableItemProps) {
|
||||
return (
|
||||
<div className={cssNames(styles.item, "flex gaps align-center justify-space-between", className)} {...rest}>
|
||||
{icon && (
|
||||
@@ -27,6 +28,7 @@ export function RemovableItem({ icon, onRemove, children, className, ...rest }:
|
||||
material="delete"
|
||||
onClick={onRemove}
|
||||
tooltip="Remove"
|
||||
data-testid={testId}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -3,48 +3,22 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable, getInjectionToken } from "@ogre-tools/injectable";
|
||||
import rendererExtensionsInjectable from "../../../extensions/renderer-extensions.injectable";
|
||||
import { pipeline } from "@ogre-tools/fp";
|
||||
import { filter, overSome } from "lodash/fp";
|
||||
import { computed } from "mobx";
|
||||
import type { LensRendererExtension } from "../../../extensions/lens-renderer-extension";
|
||||
import { computedInjectManyInjectable } from "@ogre-tools/injectable-extension-for-mobx";
|
||||
import type { AppPreferenceRegistration } from "./app-preferences/app-preference-registration";
|
||||
|
||||
export interface ExtensionTelemetryPreferenceRegistration extends AppPreferenceRegistration {
|
||||
extension?: LensRendererExtension;
|
||||
}
|
||||
|
||||
export const telemetryPreferenceItemInjectionToken = getInjectionToken<ExtensionTelemetryPreferenceRegistration>({
|
||||
export const telemetryPreferenceItemInjectionToken = getInjectionToken<AppPreferenceRegistration>({
|
||||
id: "telemetry-preference-item-injection-token",
|
||||
});
|
||||
|
||||
const telemetryPreferenceItemsInjectable = getInjectable({
|
||||
id: "telemetry-preference-items",
|
||||
|
||||
instantiate: (di) => {
|
||||
const extensions = di.inject(rendererExtensionsInjectable);
|
||||
const computedInjectMany = di.inject(computedInjectManyInjectable);
|
||||
|
||||
return computed(() => {
|
||||
const enabledExtensions = extensions.get();
|
||||
|
||||
return pipeline(
|
||||
di.injectMany(telemetryPreferenceItemInjectionToken),
|
||||
filter((item) =>
|
||||
overSome([
|
||||
isNonExtensionItem,
|
||||
isEnabledExtensionItemFor(enabledExtensions),
|
||||
])(item),
|
||||
),
|
||||
);
|
||||
});
|
||||
return computedInjectMany(telemetryPreferenceItemInjectionToken);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
const isNonExtensionItem = (item: ExtensionTelemetryPreferenceRegistration) => !item.extension;
|
||||
|
||||
const isEnabledExtensionItemFor =
|
||||
(enabledExtensions: LensRendererExtension[]) => (item: ExtensionTelemetryPreferenceRegistration) =>
|
||||
!!enabledExtensions.find((extension) => extension === item.extension);
|
||||
|
||||
|
||||
export default telemetryPreferenceItemsInjectable;
|
||||
|
||||
@@ -11,13 +11,13 @@ import { ExtensionSettings } from "./extension-settings";
|
||||
import type { IComputedValue } from "mobx";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import { Preferences } from "./preferences";
|
||||
import type { ExtensionTelemetryPreferenceRegistration } from "./telemetry-preference-items.injectable";
|
||||
import telemetryPreferenceItemsInjectable from "./telemetry-preference-items.injectable";
|
||||
import sentryDnsUrlInjectable from "./sentry-dns-url.injectable";
|
||||
import userStoreInjectable from "../../../common/user-store/user-store.injectable";
|
||||
import type { AppPreferenceRegistration } from "./app-preferences/app-preference-registration";
|
||||
|
||||
interface Dependencies {
|
||||
telemetryPreferenceItems: IComputedValue<ExtensionTelemetryPreferenceRegistration[]>;
|
||||
telemetryPreferenceItems: IComputedValue<AppPreferenceRegistration[]>;
|
||||
sentryDnsUrl: string;
|
||||
userStore: UserStore;
|
||||
}
|
||||
|
||||
@@ -68,6 +68,9 @@
|
||||
html, body {
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
body {
|
||||
color: var(--textColorPrimary);
|
||||
background-color: var(--mainBackground);
|
||||
font-size: var(--font-size);
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
|
||||
&:not(.isExpanded) {
|
||||
white-space: unset;
|
||||
overflow: unset;
|
||||
text-overflow: unset;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { observable } from "mobx";
|
||||
|
||||
const badgeHasTextSelectedStateInjectable = getInjectable({
|
||||
id: "badge-has-text-selected-state",
|
||||
instantiate: () => observable.box(false),
|
||||
});
|
||||
|
||||
export default badgeHasTextSelectedStateInjectable;
|
||||
@@ -12,51 +12,48 @@ import { CommandDialog } from "./command-dialog";
|
||||
import type { ClusterId } from "../../../common/cluster-types";
|
||||
import type { CommandOverlay } from "./command-overlay.injectable";
|
||||
import commandOverlayInjectable from "./command-overlay.injectable";
|
||||
import { isMac } from "../../../common/vars";
|
||||
import type { CatalogEntityRegistry } from "../../api/catalog/entity/registry";
|
||||
import { broadcastMessage, ipcRendererOn } from "../../../common/ipc";
|
||||
import type { Disposer } from "../../utils";
|
||||
import type { ipcRendererOn } from "../../../common/ipc";
|
||||
import { broadcastMessage } from "../../../common/ipc";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import type { AddWindowEventListener } from "../../window/event-listener.injectable";
|
||||
import windowAddEventListenerInjectable from "../../window/event-listener.injectable";
|
||||
import type { IComputedValue } from "mobx";
|
||||
import matchedClusterIdInjectable from "../../navigation/matched-cluster-id.injectable";
|
||||
import catalogEntityRegistryInjectable from "../../api/catalog/entity/registry.injectable";
|
||||
import hostedClusterIdInjectable from "../../../common/cluster-store/hosted-cluster-id.injectable";
|
||||
import hostedClusterIdInjectable from "../../cluster-frame-context/hosted-cluster-id.injectable";
|
||||
import isMacInjectable from "../../../common/vars/is-mac.injectable";
|
||||
import legacyOnChannelListenInjectable from "../../ipc/legacy-channel-listen.injectable";
|
||||
|
||||
interface Dependencies {
|
||||
addWindowEventListener: <K extends keyof WindowEventMap>(type: K, listener: (this: Window, ev: WindowEventMap[K]) => any, options?: boolean | AddEventListenerOptions) => Disposer;
|
||||
addWindowEventListener: AddWindowEventListener;
|
||||
commandOverlay: CommandOverlay;
|
||||
clusterId?: ClusterId;
|
||||
matchedClusterId: IComputedValue<ClusterId>;
|
||||
entityRegistry: CatalogEntityRegistry;
|
||||
clusterId: ClusterId | undefined;
|
||||
matchedClusterId: IComputedValue<ClusterId | undefined>;
|
||||
isMac: boolean;
|
||||
legacyOnChannelListen: typeof ipcRendererOn;
|
||||
}
|
||||
|
||||
@observer
|
||||
class NonInjectedCommandContainer extends React.Component<Dependencies> {
|
||||
private escHandler(event: KeyboardEvent) {
|
||||
const { commandOverlay } = this.props;
|
||||
|
||||
private escHandler = (event: KeyboardEvent) => {
|
||||
if (event.key === "Escape") {
|
||||
event.stopPropagation();
|
||||
commandOverlay.close();
|
||||
this.props.commandOverlay.close();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
handleCommandPalette = () => {
|
||||
const { commandOverlay, entityRegistry } = this.props;
|
||||
const clusterIsActive = this.props.matchedClusterId.get() !== undefined;
|
||||
const matchedClusterId = this.props.matchedClusterId.get();
|
||||
|
||||
if (clusterIsActive) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
broadcastMessage(`command-palette:${entityRegistry.activeEntity!.getId()}:open`);
|
||||
if (matchedClusterId !== undefined) {
|
||||
broadcastMessage(`command-palette:${matchedClusterId}:open`);
|
||||
} else {
|
||||
commandOverlay.open(<CommandDialog />);
|
||||
this.props.commandOverlay.open(<CommandDialog />);
|
||||
}
|
||||
};
|
||||
|
||||
onKeyboardShortcut(action: () => void) {
|
||||
return ({ key, shiftKey, ctrlKey, altKey, metaKey }: KeyboardEvent) => {
|
||||
const ctrlOrCmd = isMac ? metaKey && !ctrlKey : !metaKey && ctrlKey;
|
||||
const ctrlOrCmd = this.props.isMac ? metaKey && !ctrlKey : !metaKey && ctrlKey;
|
||||
|
||||
if (key === "p" && shiftKey && ctrlOrCmd && !altKey) {
|
||||
action();
|
||||
@@ -75,9 +72,9 @@ class NonInjectedCommandContainer extends React.Component<Dependencies> {
|
||||
: "command-palette:open";
|
||||
|
||||
disposeOnUnmount(this, [
|
||||
ipcRendererOn(ipcChannel, action),
|
||||
this.props.legacyOnChannelListen(ipcChannel, action),
|
||||
addWindowEventListener("keydown", this.onKeyboardShortcut(action)),
|
||||
addWindowEventListener("keyup", (e) => this.escHandler(e), true),
|
||||
addWindowEventListener("keyup", this.escHandler, true),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -106,6 +103,7 @@ export const CommandContainer = withInjectables<Dependencies>(NonInjectedCommand
|
||||
addWindowEventListener: di.inject(windowAddEventListenerInjectable),
|
||||
commandOverlay: di.inject(commandOverlayInjectable),
|
||||
matchedClusterId: di.inject(matchedClusterIdInjectable),
|
||||
entityRegistry: di.inject(catalogEntityRegistryInjectable),
|
||||
isMac: di.inject(isMacInjectable),
|
||||
legacyOnChannelListen: di.inject(legacyOnChannelListenInjectable),
|
||||
}),
|
||||
});
|
||||
+22
-10
@@ -9,9 +9,8 @@ import type { RenderResult } from "@testing-library/react";
|
||||
import mockFs from "mock-fs";
|
||||
import React from "react";
|
||||
import * as selectEvent from "react-select-event";
|
||||
import type { Cluster } from "../../../../common/cluster/cluster";
|
||||
import { DeleteClusterDialog } from "../view";
|
||||
import type { ClusterModel } from "../../../../common/cluster-types";
|
||||
import type { CreateCluster } from "../../../../common/cluster/create-cluster-injection-token";
|
||||
import { createClusterInjectionToken } from "../../../../common/cluster/create-cluster-injection-token";
|
||||
import createContextHandlerInjectable from "../../../../main/context-handler/create-context-handler.injectable";
|
||||
import type { OpenDeleteClusterDialog } from "../open.injectable";
|
||||
@@ -20,7 +19,7 @@ import storesAndApisCanBeCreatedInjectable from "../../../stores-apis-can-be-cre
|
||||
import createKubeconfigManagerInjectable from "../../../../main/kubeconfig-manager/create-kubeconfig-manager.injectable";
|
||||
import type { ApplicationBuilder } from "../../test-utils/get-application-builder";
|
||||
import { getApplicationBuilder } from "../../test-utils/get-application-builder";
|
||||
import { routeInjectionToken } from "../../../../common/front-end-routing/route-injection-token";
|
||||
import { frontEndRouteInjectionToken } from "../../../../common/front-end-routing/front-end-route-injection-token";
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { computed } from "mobx";
|
||||
import { routeSpecificComponentInjectionToken } from "../../../routes/route-specific-component-injection-token";
|
||||
@@ -46,14 +45,16 @@ jest.mock("electron", () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
const currentClusterServerUrl = "https://localhost";
|
||||
const nonCurrentClusterServerUrl = "http://localhost";
|
||||
const multiClusterConfig = `
|
||||
apiVersion: v1
|
||||
clusters:
|
||||
- cluster:
|
||||
server: https://localhost
|
||||
server: ${currentClusterServerUrl}
|
||||
name: some-current-context-cluster
|
||||
- cluster:
|
||||
server: http://localhost
|
||||
server: ${nonCurrentClusterServerUrl}
|
||||
name: some-non-current-context-cluster
|
||||
contexts:
|
||||
- context:
|
||||
@@ -73,11 +74,12 @@ users:
|
||||
token: kubeconfig-user-q4lm4:xxxyyyy
|
||||
`;
|
||||
|
||||
const singleClusterServerUrl = "http://localhost";
|
||||
const singleClusterConfig = `
|
||||
apiVersion: v1
|
||||
clusters:
|
||||
- cluster:
|
||||
server: http://localhost
|
||||
server: ${singleClusterServerUrl}
|
||||
name: some-cluster
|
||||
contexts:
|
||||
- context:
|
||||
@@ -97,7 +99,7 @@ let config: KubeConfig;
|
||||
|
||||
describe("<DeleteClusterDialog />", () => {
|
||||
let applicationBuilder: ApplicationBuilder;
|
||||
let createCluster: (model: ClusterModel) => Cluster;
|
||||
let createCluster: CreateCluster;
|
||||
let openDeleteClusterDialog: OpenDeleteClusterDialog;
|
||||
|
||||
beforeEach(async () => {
|
||||
@@ -157,6 +159,8 @@ describe("<DeleteClusterDialog />", () => {
|
||||
clusterName: "some-current-context-cluster",
|
||||
},
|
||||
kubeConfigPath: "./temp-kube-config",
|
||||
}, {
|
||||
clusterServerUrl: currentClusterServerUrl,
|
||||
});
|
||||
|
||||
openDeleteClusterDialog({ cluster, config });
|
||||
@@ -204,6 +208,8 @@ describe("<DeleteClusterDialog />", () => {
|
||||
clusterName: "minikube",
|
||||
},
|
||||
kubeConfigPath: "./temp-kube-config",
|
||||
}, {
|
||||
clusterServerUrl: nonCurrentClusterServerUrl,
|
||||
});
|
||||
|
||||
openDeleteClusterDialog({ cluster, config });
|
||||
@@ -221,6 +227,8 @@ describe("<DeleteClusterDialog />", () => {
|
||||
clusterName: "some-current-context-cluster",
|
||||
},
|
||||
kubeConfigPath: "./temp-kube-config",
|
||||
}, {
|
||||
clusterServerUrl: currentClusterServerUrl,
|
||||
});
|
||||
|
||||
openDeleteClusterDialog({ cluster, config });
|
||||
@@ -236,6 +244,8 @@ describe("<DeleteClusterDialog />", () => {
|
||||
clusterName: "some-current-context-cluster",
|
||||
},
|
||||
kubeConfigPath: "./temp-kube-config",
|
||||
}, {
|
||||
clusterServerUrl: currentClusterServerUrl,
|
||||
});
|
||||
|
||||
openDeleteClusterDialog({ cluster, config });
|
||||
@@ -259,12 +269,12 @@ describe("<DeleteClusterDialog />", () => {
|
||||
const cluster = createCluster({
|
||||
id: "some-non-current-context-cluster",
|
||||
contextName: "some-non-current-context",
|
||||
|
||||
preferences: {
|
||||
clusterName: "some-non-current-context-cluster",
|
||||
},
|
||||
|
||||
kubeConfigPath: "./temp-kube-config",
|
||||
}, {
|
||||
clusterServerUrl: nonCurrentClusterServerUrl,
|
||||
});
|
||||
|
||||
const spy = jest.spyOn(cluster, "isInLocalKubeconfig").mockImplementation(() => true);
|
||||
@@ -301,6 +311,8 @@ describe("<DeleteClusterDialog />", () => {
|
||||
clusterName: "some-cluster",
|
||||
},
|
||||
kubeConfigPath: "./temp-kube-config",
|
||||
}, {
|
||||
clusterServerUrl: singleClusterServerUrl,
|
||||
});
|
||||
|
||||
openDeleteClusterDialog({ cluster, config });
|
||||
@@ -319,7 +331,7 @@ const testRouteInjectable = getInjectable({
|
||||
isEnabled: computed(() => true),
|
||||
}),
|
||||
|
||||
injectionToken: routeInjectionToken,
|
||||
injectionToken: frontEndRouteInjectionToken,
|
||||
});
|
||||
|
||||
const testRouteComponentInjectable = getInjectable({
|
||||
|
||||
@@ -1,17 +1,22 @@
|
||||
.warning {
|
||||
@apply mt-4 flex py-4 px-6 rounded-md items-center;
|
||||
display: flex;
|
||||
margin-top: var(--margin);
|
||||
padding: calc(var(--padding) * 2) calc(var(--padding) * 3);
|
||||
border-radius: 4px;
|
||||
align-items: center;
|
||||
background: #fad8d7;
|
||||
color: #797979;
|
||||
}
|
||||
|
||||
.warningIcon {
|
||||
@apply mr-5;
|
||||
margin-right: calc(var(--margin) * 2.4);
|
||||
font-size: 26px;
|
||||
}
|
||||
|
||||
.dialog {
|
||||
> div {
|
||||
@apply rounded-md bg-white;
|
||||
border-radius: 4px;
|
||||
background-color: white;
|
||||
max-width: 600px;
|
||||
min-width: calc(45 * var(--unit));
|
||||
}
|
||||
@@ -22,11 +27,14 @@
|
||||
}
|
||||
|
||||
.dialogContent {
|
||||
@apply p-9 leading-9;
|
||||
padding: calc(var(--padding) * 2) calc(var(--padding) * 3);
|
||||
}
|
||||
|
||||
.dialogButtons {
|
||||
@apply flex justify-end p-7 rounded-md;
|
||||
display: flex;
|
||||
border-radius: 4px;
|
||||
justify-content: flex-end;
|
||||
padding: calc(var(--padding) * 2);
|
||||
background: #f4f4f4;
|
||||
|
||||
> * {
|
||||
@@ -35,7 +43,7 @@
|
||||
}
|
||||
|
||||
.hr {
|
||||
@apply mt-7;
|
||||
margin-top: calc(var(--margin) * 3);
|
||||
height: 1px;
|
||||
background: #dfdfdf80;
|
||||
}
|
||||
@@ -204,9 +204,9 @@ class NonInjectedDeleteClusterDialog extends React.Component<Dependencies> {
|
||||
<div className={styles.dialogContent}>
|
||||
{this.renderDeleteMessage(state)}
|
||||
{this.renderWarning(state)}
|
||||
<hr className={styles.hr} />
|
||||
{contexts.length > 0 && (
|
||||
<>
|
||||
<hr className={styles.hr} />
|
||||
<div className="mt-4">
|
||||
<Checkbox
|
||||
data-testid="context-switch"
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import directoryForUserDataInjectable from "../../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
import hostedClusterIdInjectable from "../../../../common/cluster-store/hosted-cluster-id.injectable";
|
||||
import hostedClusterIdInjectable from "../../../cluster-frame-context/hosted-cluster-id.injectable";
|
||||
import { getDiForUnitTesting } from "../../../getDiForUnitTesting";
|
||||
import type { DockStore, DockTab } from "../dock/store";
|
||||
import { TabKind } from "../dock/store";
|
||||
|
||||
@@ -19,7 +19,7 @@ import directoryForUserDataInjectable from "../../../../common/app-paths/directo
|
||||
import getConfigurationFileModelInjectable from "../../../../common/get-configuration-file-model/get-configuration-file-model.injectable";
|
||||
import appVersionInjectable from "../../../../common/get-configuration-file-model/app-version/app-version.injectable";
|
||||
import assert from "assert";
|
||||
import hostedClusterIdInjectable from "../../../../common/cluster-store/hosted-cluster-id.injectable";
|
||||
import hostedClusterIdInjectable from "../../../cluster-frame-context/hosted-cluster-id.injectable";
|
||||
|
||||
jest.mock("electron", () => ({
|
||||
app: {
|
||||
|
||||
@@ -94,5 +94,5 @@
|
||||
.title {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
margin-right: 2.5rem;
|
||||
margin-right: calc(var(--margin) * 3);
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import { Icon } from "../../icon";
|
||||
export function ToBottom({ onClick }: { onClick: () => void }) {
|
||||
return (
|
||||
<button
|
||||
className="absolute top-3 right-3 z-10 rounded-md flex align-center px-1.5 py-1.5 pl-3.5"
|
||||
className="absolute top-3 right-3 z-10 rounded-md flex align-center px-1 py-1 pl-3"
|
||||
style={{ backgroundColor: "var(--blue)" }}
|
||||
onClick={evt => {
|
||||
evt.currentTarget.blur();
|
||||
|
||||
@@ -84,5 +84,5 @@ class DefaultedEditableList<T> extends React.Component<EditableListProps<T> & ty
|
||||
}
|
||||
|
||||
export function EditableList<T>(props: EditableListProps<T>) {
|
||||
return <DefaultedEditableList {...props as never}/>;
|
||||
return <DefaultedEditableList {...props as object}/>;
|
||||
}
|
||||
@@ -204,7 +204,7 @@ class DefaultedFilePicker extends React.Component<FilePickerProps & typeof defau
|
||||
return (
|
||||
<div className="FilePicker">
|
||||
<label className="flex gaps align-center" htmlFor="file-upload">
|
||||
{label}
|
||||
{label}
|
||||
{" "}
|
||||
{this.getIconRight()}
|
||||
</label>
|
||||
@@ -232,4 +232,4 @@ class DefaultedFilePicker extends React.Component<FilePickerProps & typeof defau
|
||||
}
|
||||
}
|
||||
|
||||
export const FilePicker = (props: FilePickerProps) => <DefaultedFilePicker {...(props as never)} />;
|
||||
export const FilePicker = (props: FilePickerProps) => <DefaultedFilePicker {...(props as FilePickerProps & typeof defaultProps)} />;
|
||||
@@ -3,11 +3,86 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { isEmail, isUrl, systemName } from "../input_validators";
|
||||
import { isEmail, isUrl, systemName, unionInputValidators, unionInputValidatorsAsync } from "../input_validators";
|
||||
|
||||
type TextValidationCase = [string, boolean];
|
||||
|
||||
describe("input validation tests", () => {
|
||||
describe("unionInputValidators()", () => {
|
||||
const emailOrUrl = unionInputValidators(
|
||||
{
|
||||
message: "Not an email or URL",
|
||||
},
|
||||
isEmail,
|
||||
isUrl,
|
||||
);
|
||||
|
||||
it.each([
|
||||
"abc@news.com",
|
||||
"abc@news.co.uk",
|
||||
])("Given '%s' is a valid email, emailOrUrl matches", (input) => {
|
||||
expect(emailOrUrl.validate(input)).toBe(true);
|
||||
});
|
||||
|
||||
it.each([
|
||||
"https://github-production-registry-package-file-4f11e5.s3.amazonaws.com/307985088/68bbbf00-309f-11eb-8457-a15e4efe9e77?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20201127%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20201127T123754Z&X-Amz-Expires=300&X-Amz-Signature=9b8167f00685a20d980224d397892195abc187cdb2934cefb79edcd7ec600f78&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=0&response-content-disposition=filename%3Dstarboard-lens-extension-0.0.1-alpha.1-npm.tgz&response-content-type=application%2Foctet-stream",
|
||||
"http://www.google.com",
|
||||
])("Given '%s' is a valid url, emailOrUrl matches", (input) => {
|
||||
expect(emailOrUrl.validate(input)).toBe(true);
|
||||
});
|
||||
|
||||
it.each([
|
||||
"hello",
|
||||
"57",
|
||||
])("Given '%s' is neither a valid email nor URL, emailOrUrl does not match", (input) => {
|
||||
expect(emailOrUrl.validate(input)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("unionInputValidatorsAsync()", () => {
|
||||
const emailOrUrl = unionInputValidatorsAsync(
|
||||
{
|
||||
message: "Not an email or URL",
|
||||
},
|
||||
isEmail,
|
||||
isUrl,
|
||||
);
|
||||
|
||||
it.each([
|
||||
"abc@news.com",
|
||||
"abc@news.co.uk",
|
||||
])("Given '%s' is a valid email, emailOrUrl matches", async (input) => {
|
||||
try {
|
||||
await emailOrUrl.validate(input);
|
||||
} catch {
|
||||
fail("Should not throw on valid input");
|
||||
}
|
||||
});
|
||||
|
||||
it.each([
|
||||
"https://github-production-registry-package-file-4f11e5.s3.amazonaws.com/307985088/68bbbf00-309f-11eb-8457-a15e4efe9e77?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20201127%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20201127T123754Z&X-Amz-Expires=300&X-Amz-Signature=9b8167f00685a20d980224d397892195abc187cdb2934cefb79edcd7ec600f78&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=0&response-content-disposition=filename%3Dstarboard-lens-extension-0.0.1-alpha.1-npm.tgz&response-content-type=application%2Foctet-stream",
|
||||
"http://www.google.com",
|
||||
])("Given '%s' is a valid url, emailOrUrl matches", async (input) => {
|
||||
try {
|
||||
await emailOrUrl.validate(input);
|
||||
} catch {
|
||||
fail("Should not throw on valid input");
|
||||
}
|
||||
});
|
||||
|
||||
it.each([
|
||||
"hello",
|
||||
"57",
|
||||
])("Given '%s' is neither a valid email nor URL, emailOrUrl does not match", async (input) => {
|
||||
try {
|
||||
await emailOrUrl.validate(input);
|
||||
fail("Should throw on invalid input");
|
||||
} catch {
|
||||
// We want this to happen
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("isEmail tests", () => {
|
||||
const tests: TextValidationCase[] = [
|
||||
["abc@news.com", true],
|
||||
@@ -21,7 +96,7 @@ describe("input validation tests", () => {
|
||||
];
|
||||
|
||||
it.each(tests)("validate %s", (input, output) => {
|
||||
expect(isEmail.validate(input, {})).toBe(output);
|
||||
expect(isEmail.validate(input)).toBe(output);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -38,7 +113,7 @@ describe("input validation tests", () => {
|
||||
];
|
||||
|
||||
it.each(cases)("validate %s", (input, output) => {
|
||||
expect(isUrl.validate(input, {})).toBe(output);
|
||||
expect(isUrl.validate(input)).toBe(output);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -68,7 +143,7 @@ describe("input validation tests", () => {
|
||||
];
|
||||
|
||||
it.each(tests)("validate %s", (input, output) => {
|
||||
expect(systemName.validate(input, {})).toBe(output);
|
||||
expect(systemName.validate(input)).toBe(output);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -7,20 +7,37 @@ import "./input.scss";
|
||||
|
||||
import type { DOMAttributes, InputHTMLAttributes, TextareaHTMLAttributes } from "react";
|
||||
import React from "react";
|
||||
import { autoBind, cssNames, debouncePromise, getRandId } from "../../utils";
|
||||
import { autoBind, cssNames, debouncePromise, getRandId, isPromiseSettledFulfilled } from "../../utils";
|
||||
import { Icon } from "../icon";
|
||||
import type { TooltipProps } from "../tooltip";
|
||||
import { Tooltip } from "../tooltip";
|
||||
import * as Validators from "./input_validators";
|
||||
import type { InputValidator } from "./input_validators";
|
||||
import isFunction from "lodash/isFunction";
|
||||
import type { InputValidator, InputValidation, InputValidationResult, SyncValidationMessage } from "./input_validators";
|
||||
import uniqueId from "lodash/uniqueId";
|
||||
import { debounce } from "lodash";
|
||||
|
||||
const { conditionalValidators, ...InputValidators } = Validators;
|
||||
const {
|
||||
conditionalValidators,
|
||||
asyncInputValidator,
|
||||
inputValidator,
|
||||
isAsyncValidator,
|
||||
unionInputValidatorsAsync,
|
||||
...InputValidators
|
||||
} = Validators;
|
||||
|
||||
export { InputValidators };
|
||||
export type { InputValidator };
|
||||
export {
|
||||
InputValidators,
|
||||
asyncInputValidator,
|
||||
inputValidator,
|
||||
isAsyncValidator,
|
||||
unionInputValidatorsAsync,
|
||||
};
|
||||
export type {
|
||||
InputValidator,
|
||||
InputValidation,
|
||||
InputValidationResult,
|
||||
SyncValidationMessage,
|
||||
};
|
||||
|
||||
type InputElement = HTMLInputElement | HTMLTextAreaElement;
|
||||
type InputElementProps =
|
||||
@@ -78,15 +95,11 @@ const defaultProps: Partial<InputProps> = {
|
||||
blurOnEnter: true,
|
||||
};
|
||||
|
||||
function isAsyncValidator(validator: InputValidator<boolean>): validator is InputValidator<true> {
|
||||
return typeof validator.debounce === "number";
|
||||
}
|
||||
|
||||
export class Input extends React.Component<InputProps, State> {
|
||||
static defaultProps = defaultProps as object;
|
||||
|
||||
public input: InputElement | null = null;
|
||||
public validators: InputValidator<boolean>[] = [];
|
||||
public validators: InputValidator[] = [];
|
||||
|
||||
public state: State = {
|
||||
focused: false,
|
||||
@@ -155,7 +168,7 @@ export class Input extends React.Component<InputProps, State> {
|
||||
async validate() {
|
||||
const value = this.getValue();
|
||||
let validationId = (this.validationId = ""); // reset every time for async validators
|
||||
const asyncValidators: Promise<any>[] = [];
|
||||
const asyncValidators: Promise<React.ReactNode>[] = [];
|
||||
const errors: React.ReactNode[] = [];
|
||||
|
||||
// run validators
|
||||
@@ -169,28 +182,15 @@ export class Input extends React.Component<InputProps, State> {
|
||||
if (!validationId) {
|
||||
this.validationId = validationId = uniqueId("validation_id_");
|
||||
}
|
||||
asyncValidators.push(
|
||||
validator.validate(value, this.props).then(
|
||||
() => null, // don't consider any valid result from promise since we interested in errors only
|
||||
error => this.getValidatorError(value, validator) || error,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
const isValid = validator.validate(value, this.props);
|
||||
|
||||
if (isValid === false) {
|
||||
asyncValidators.push((async () => {
|
||||
try {
|
||||
await validator.validate(value, this.props);
|
||||
} catch (error) {
|
||||
return this.getValidatorError(value, validator) || (error instanceof Error ? error.message : String(error));
|
||||
}
|
||||
})());
|
||||
} else if (!validator.validate(value, this.props)) {
|
||||
errors.push(this.getValidatorError(value, validator));
|
||||
} else if (isValid instanceof Promise) {
|
||||
if (!validationId) {
|
||||
this.validationId = validationId = uniqueId("validation_id_");
|
||||
}
|
||||
asyncValidators.push(
|
||||
isValid.then(
|
||||
() => null, // don't consider any valid result from promise since we interested in errors only
|
||||
error => this.getValidatorError(value, validator) || error,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,10 +200,15 @@ export class Input extends React.Component<InputProps, State> {
|
||||
// handle async validators result
|
||||
if (asyncValidators.length > 0) {
|
||||
this.setState({ validating: true, valid: false });
|
||||
const asyncErrors = await Promise.all(asyncValidators);
|
||||
const asyncErrors = await Promise.allSettled(asyncValidators);
|
||||
|
||||
if (this.validationId === validationId) {
|
||||
this.setValidation(errors.concat(...asyncErrors.filter(err => err)));
|
||||
errors.push(...asyncErrors
|
||||
.filter(isPromiseSettledFulfilled)
|
||||
.map(res => res.value)
|
||||
.filter(Boolean));
|
||||
|
||||
this.setValidation(errors);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,10 +223,10 @@ export class Input extends React.Component<InputProps, State> {
|
||||
});
|
||||
}
|
||||
|
||||
private getValidatorError(value: string, { message }: InputValidator<boolean>) {
|
||||
if (isFunction(message)) return message(value, this.props);
|
||||
|
||||
return message || "";
|
||||
private getValidatorError(value: string, { message }: InputValidator) {
|
||||
return typeof message === "function"
|
||||
? message(value, this.props)
|
||||
: message;
|
||||
}
|
||||
|
||||
private setupValidators() {
|
||||
@@ -445,8 +450,8 @@ export class Input extends React.Component<InputProps, State> {
|
||||
<label className="input-area flex gaps align-center" id="">
|
||||
{this.renderIcon(iconLeft)}
|
||||
{multiLine
|
||||
? <textarea {...inputProps as never} />
|
||||
: <input {...inputProps as never} />
|
||||
? <textarea {...inputProps as object} />
|
||||
: <input {...inputProps as object} />
|
||||
}
|
||||
{this.renderIcon(iconRight)}
|
||||
{contentRight}
|
||||
|
||||
@@ -4,41 +4,113 @@
|
||||
*/
|
||||
|
||||
import type { InputProps } from "./input";
|
||||
import type { ReactNode } from "react";
|
||||
import type React from "react";
|
||||
import fse from "fs-extra";
|
||||
import { TypedRegEx } from "typed-regex";
|
||||
import type { SetRequired } from "type-fest";
|
||||
|
||||
export class AsyncInputValidationError extends Error {
|
||||
}
|
||||
export type InputValidationResult<IsAsync extends boolean> =
|
||||
IsAsync extends true
|
||||
? Promise<void>
|
||||
: boolean;
|
||||
|
||||
export type InputValidator<IsAsync extends boolean> = {
|
||||
export type InputValidation<IsAsync extends boolean> = (value: string, props?: InputProps) => InputValidationResult<IsAsync>;
|
||||
|
||||
export type SyncValidationMessage = React.ReactNode | ((value: string, props?: InputProps) => React.ReactNode);
|
||||
|
||||
export type InputValidator<IsAsync extends boolean = boolean> = {
|
||||
/**
|
||||
* Filters itself based on the input props
|
||||
*/
|
||||
condition?: (props: InputProps) => any;
|
||||
} & (
|
||||
IsAsync extends false
|
||||
IsAsync extends true
|
||||
? {
|
||||
validate: (value: string, props: InputProps) => boolean;
|
||||
message: ReactNode | ((value: string, props: InputProps) => ReactNode | string);
|
||||
debounce?: undefined;
|
||||
/**
|
||||
* The validation message maybe either specified from the `message` field (higher priority)
|
||||
* or if that is not provided then the message will retrived from the rejected with value
|
||||
*/
|
||||
validate: InputValidation<true>;
|
||||
message?: SyncValidationMessage;
|
||||
debounce: number;
|
||||
}
|
||||
: {
|
||||
/**
|
||||
* If asyncronous then the rejection message is the error message
|
||||
*
|
||||
* This function MUST reject with an instance of {@link AsyncInputValidationError}
|
||||
*/
|
||||
validate: (value: string, props: InputProps) => Promise<void>;
|
||||
message?: undefined;
|
||||
debounce: number;
|
||||
validate: InputValidation<false>;
|
||||
message: SyncValidationMessage;
|
||||
debounce?: undefined;
|
||||
}
|
||||
);
|
||||
|
||||
export function inputValidator<IsAsync extends boolean = false>(validator: InputValidator<IsAsync>): InputValidator<IsAsync> {
|
||||
export function isAsyncValidator(validator: InputValidator<boolean>): validator is InputValidator<true> {
|
||||
return typeof validator.debounce === "number";
|
||||
}
|
||||
|
||||
export function asyncInputValidator(validator: InputValidator<true>): InputValidator<true> {
|
||||
return validator;
|
||||
}
|
||||
|
||||
export function inputValidator(validator: InputValidator<false>): InputValidator<false> {
|
||||
return validator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new input validator from a list of syncronous input validators. Will match as valid if
|
||||
* one of the input validators matches the input
|
||||
*/
|
||||
export function unionInputValidators(
|
||||
baseValidator: Pick<InputValidator<false>, "condition" | "message">,
|
||||
...validators: InputValidator<false>[]
|
||||
): InputValidator<false> {
|
||||
return inputValidator({
|
||||
...baseValidator,
|
||||
validate: (value, props) => validators.some(validator => validator.validate(value, props)),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new input validator from a list of syncronous or async input validators. Will match as
|
||||
* valid if one of the input validators matches the input
|
||||
*/
|
||||
export function unionInputValidatorsAsync(
|
||||
baseValidator: SetRequired<Pick<InputValidator<boolean>, "condition" | "message">, "message">,
|
||||
...validators: InputValidator<boolean>[]
|
||||
): InputValidator<true> {
|
||||
const longestDebounce = Math.max(
|
||||
...validators
|
||||
.filter(isAsyncValidator)
|
||||
.map(validator => validator.debounce),
|
||||
0,
|
||||
);
|
||||
|
||||
return asyncInputValidator({
|
||||
debounce: longestDebounce,
|
||||
validate: async (value, props) => {
|
||||
for (const validator of validators) {
|
||||
if (isAsyncValidator(validator)) {
|
||||
try {
|
||||
await validator.validate(value, props);
|
||||
|
||||
return;
|
||||
} catch {
|
||||
// Do nothing
|
||||
}
|
||||
} else {
|
||||
if (validator.validate(value, props)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If no validator returns `true` then mark as invalid by throwing. The message will be
|
||||
* obtained from the `message` field.
|
||||
*/
|
||||
throw new Error();
|
||||
},
|
||||
...baseValidator,
|
||||
});
|
||||
}
|
||||
|
||||
export const isRequired = inputValidator({
|
||||
condition: ({ required }) => required,
|
||||
message: () => `This field is required`,
|
||||
@@ -53,7 +125,7 @@ export const isEmail = inputValidator({
|
||||
|
||||
export const isNumber = inputValidator({
|
||||
condition: ({ type }) => type === "number",
|
||||
message(value, { min, max }) {
|
||||
message(value, { min, max } = {}) {
|
||||
const minMax: string = [
|
||||
typeof min === "number" ? `min: ${min}` : undefined,
|
||||
typeof max === "number" ? `max: ${max}` : undefined,
|
||||
@@ -61,7 +133,7 @@ export const isNumber = inputValidator({
|
||||
|
||||
return `Invalid number${minMax ? ` (${minMax})` : ""}`;
|
||||
},
|
||||
validate: (value, { min, max }) => {
|
||||
validate: (value, { min, max } = {}) => {
|
||||
const numVal = +value;
|
||||
|
||||
return !(
|
||||
@@ -100,30 +172,26 @@ export const isExtensionNameInstall = inputValidator({
|
||||
validate: value => isExtensionNameInstallRegex.isMatch(value),
|
||||
});
|
||||
|
||||
export const isPath = inputValidator<true>({
|
||||
export const isPath = asyncInputValidator({
|
||||
debounce: 100,
|
||||
condition: ({ type }) => type === "text",
|
||||
validate: async value => {
|
||||
try {
|
||||
await fse.pathExists(value);
|
||||
} catch {
|
||||
throw new AsyncInputValidationError(`${value} is not a valid file path`);
|
||||
if (!await fse.pathExists(value)) {
|
||||
throw new Error(`"${value}" is not a valid file path`);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export const minLength = inputValidator({
|
||||
condition: ({ minLength }) => !!minLength,
|
||||
message: (value, { minLength }) => `Minimum length is ${minLength}`,
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
validate: (value, { minLength }) => value.length >= minLength!,
|
||||
message: (value, { minLength = 0 } = {}) => `Minimum length is ${minLength}`,
|
||||
validate: (value, { minLength = 0 } = {}) => value.length >= minLength,
|
||||
});
|
||||
|
||||
export const maxLength = inputValidator({
|
||||
condition: ({ maxLength }) => !!maxLength,
|
||||
message: (value, { maxLength }) => `Maximum length is ${maxLength}`,
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
validate: (value, { maxLength }) => value.length <= maxLength!,
|
||||
message: (value, { maxLength = 0 } = {}) => `Maximum length is ${maxLength}`,
|
||||
validate: (value, { maxLength = 0 } = {}) => value.length <= maxLength,
|
||||
});
|
||||
|
||||
const systemNameMatcher = /^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$/;
|
||||
@@ -135,7 +203,7 @@ export const systemName = inputValidator({
|
||||
|
||||
export const accountId = inputValidator({
|
||||
message: () => `Invalid account ID`,
|
||||
validate: (value, props) => (isEmail.validate(value, props) || systemName.validate(value, props)),
|
||||
validate: (value) => (isEmail.validate(value) || systemName.validate(value)),
|
||||
});
|
||||
|
||||
export const conditionalValidators = [
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { asyncInputValidator } from "../input_validators";
|
||||
import pathExistsInjectable from "../../../../common/fs/path-exists.injectable";
|
||||
|
||||
const isPathInjectable = getInjectable({
|
||||
id: "is-path",
|
||||
|
||||
instantiate: (di) => {
|
||||
const pathExists = di.inject(pathExistsInjectable);
|
||||
|
||||
return asyncInputValidator({
|
||||
debounce: 100,
|
||||
condition: ({ type }) => type === "text",
|
||||
validate: async value => {
|
||||
if (!await pathExists(value)) {
|
||||
throw new Error(`"${value}" is not a valid file path`);
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default isPathInjectable;
|
||||
@@ -18,17 +18,16 @@ import type { LensRendererExtension } from "../../../extensions/lens-renderer-ex
|
||||
const extensionSidebarItemRegistratorInjectable = getInjectable({
|
||||
id: "extension-sidebar-item-registrator",
|
||||
|
||||
instantiate: (di) => (ext, extensionInstallationCount) => {
|
||||
instantiate: (di) => (ext) => {
|
||||
const extension = ext as LensRendererExtension;
|
||||
const navigateToRoute = di.inject(navigateToRouteInjectionToken);
|
||||
const routes = di.inject(routesInjectable);
|
||||
|
||||
const sidebarItemsForExtensionInjectable = getInjectable({
|
||||
id: `sidebar-items-for-extension-${extension.sanitizedExtensionId}-instance-${extensionInstallationCount}`,
|
||||
id: `sidebar-items-for-extension-${extension.sanitizedExtensionId}`,
|
||||
injectionToken: sidebarItemsInjectionToken,
|
||||
|
||||
instantiate: (di) => {
|
||||
const navigateToRoute = di.inject(navigateToRouteInjectionToken);
|
||||
const routes = di.inject(routesInjectable);
|
||||
|
||||
return computed(() => {
|
||||
const extensionRoutes = routes.get().filter(matches({ extension }));
|
||||
|
||||
@@ -44,7 +43,6 @@ const extensionSidebarItemRegistratorInjectable = getInjectable({
|
||||
|
||||
const res: SidebarItemRegistration = {
|
||||
id: `${extension.sanitizedExtensionId}-${registration.id}`,
|
||||
extension,
|
||||
orderNumber: 9999,
|
||||
|
||||
parentId: registration.parentId
|
||||
@@ -73,7 +71,9 @@ const extensionSidebarItemRegistratorInjectable = getInjectable({
|
||||
},
|
||||
});
|
||||
|
||||
di.register(sidebarItemsForExtensionInjectable);
|
||||
return [
|
||||
sidebarItemsForExtensionInjectable,
|
||||
];
|
||||
},
|
||||
|
||||
injectionToken: extensionRegistratorInjectionToken,
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
|
||||
.sidebar {
|
||||
width: 218px;
|
||||
padding: 60px 0 60px 20px;
|
||||
padding: 60px 10px 60px 20px;
|
||||
|
||||
h2 {
|
||||
font-size: 15px;
|
||||
@@ -52,10 +52,6 @@
|
||||
margin-right: 20px;
|
||||
height: 1px;
|
||||
border-top: thin solid var(--hrColor);
|
||||
|
||||
&:first-child {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.Tabs {
|
||||
@@ -63,7 +59,6 @@
|
||||
padding: 6px 10px;
|
||||
font-size: 13px;
|
||||
font-weight: 800;
|
||||
line-height: 16px;
|
||||
text-transform: uppercase;
|
||||
color: var(--textColorPrimary);
|
||||
|
||||
@@ -76,14 +71,10 @@
|
||||
padding: 6px 10px;
|
||||
margin-bottom: 2px;
|
||||
border-radius: 4px;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
font-size: 15px;
|
||||
line-height: 20px;
|
||||
cursor: pointer;
|
||||
border-top-right-radius: 0;
|
||||
border-bottom-right-radius: 0;
|
||||
white-space: normal;
|
||||
|
||||
&::after {
|
||||
content: none;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
.SidebarCluster {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 1.25rem;
|
||||
padding: calc(var(--padding) * 1.2);
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
@@ -38,13 +38,12 @@
|
||||
|
||||
.menu {
|
||||
width: 200px;
|
||||
margin-top: -1.25rem;
|
||||
margin-left: 1.25rem;
|
||||
margin-top: -10px;
|
||||
}
|
||||
|
||||
.avatar {
|
||||
font-weight: 500;
|
||||
margin-right: 1.25rem;
|
||||
margin-right: calc(var(--margin) * 1.5);
|
||||
}
|
||||
|
||||
.loadingAvatar {
|
||||
|
||||
@@ -80,9 +80,7 @@ class NonInjectedSidebarItem extends React.Component<
|
||||
return (
|
||||
<div
|
||||
className={cssNames("SidebarItem")}
|
||||
data-testid="sidebar-item"
|
||||
data-test-id={this.id}
|
||||
data-id-test={this.id}
|
||||
data-testid={`sidebar-item-${this.id}`}
|
||||
data-is-active-test={this.isActive}
|
||||
data-parent-id-test={this.registration.parentId}
|
||||
>
|
||||
|
||||
@@ -6,7 +6,7 @@ import { getInjectable, getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { IComputedValue } from "mobx";
|
||||
import { computed } from "mobx";
|
||||
import { pipeline } from "@ogre-tools/fp";
|
||||
|
||||
import { computedInjectManyInjectable } from "@ogre-tools/injectable-extension-for-mobx";
|
||||
import {
|
||||
filter,
|
||||
flatMap,
|
||||
@@ -15,11 +15,8 @@ import {
|
||||
isEmpty,
|
||||
map,
|
||||
orderBy,
|
||||
overSome,
|
||||
some,
|
||||
} from "lodash/fp";
|
||||
import rendererExtensionsInjectable from "../../../extensions/renderer-extensions.injectable";
|
||||
import type { LensRendererExtension } from "../../../extensions/lens-renderer-extension";
|
||||
|
||||
export interface SidebarItemRegistration {
|
||||
id: string;
|
||||
@@ -30,7 +27,6 @@ export interface SidebarItemRegistration {
|
||||
isActive?: IComputedValue<boolean>;
|
||||
isVisible?: IComputedValue<boolean>;
|
||||
orderNumber: number;
|
||||
extension?: LensRendererExtension;
|
||||
}
|
||||
|
||||
export const sidebarItemsInjectionToken = getInjectionToken<
|
||||
@@ -47,25 +43,14 @@ const sidebarItemsInjectable = getInjectable({
|
||||
id: "sidebar-items",
|
||||
|
||||
instantiate: (di) => {
|
||||
const extensions = di.inject(rendererExtensionsInjectable);
|
||||
const computedInjectMany = di.inject(computedInjectManyInjectable);
|
||||
|
||||
const sidebarItemRegistrations = computedInjectMany(sidebarItemsInjectionToken);
|
||||
|
||||
return computed((): HierarchicalSidebarItem[] => {
|
||||
const enabledExtensions = extensions.get();
|
||||
|
||||
const sidebarItemRegistrations = di.injectMany(
|
||||
sidebarItemsInjectionToken,
|
||||
);
|
||||
|
||||
const registrations = pipeline(
|
||||
sidebarItemRegistrations,
|
||||
sidebarItemRegistrations.get(),
|
||||
flatMap(dereference),
|
||||
|
||||
filter(
|
||||
overSome([
|
||||
isNonExtensionSidebarItem,
|
||||
isEnabledExtensionSidebarItemFor(enabledExtensions),
|
||||
]),
|
||||
),
|
||||
);
|
||||
|
||||
const getSidebarItemsHierarchy = (registrations: SidebarItemRegistration[]) => {
|
||||
@@ -114,14 +99,6 @@ const sidebarItemsInjectable = getInjectable({
|
||||
},
|
||||
});
|
||||
|
||||
const isNonExtensionSidebarItem = (sidebarItem: SidebarItemRegistration) =>
|
||||
!sidebarItem.extension;
|
||||
|
||||
const isEnabledExtensionSidebarItemFor =
|
||||
(enabledExtensions: LensRendererExtension[]) =>
|
||||
(sidebarItem: SidebarItemRegistration) =>
|
||||
!!enabledExtensions.find((x) => x === sidebarItem.extension);
|
||||
|
||||
const dereference = (items: IComputedValue<SidebarItemRegistration[]>) =>
|
||||
items.get();
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { WindowAction } from "../../../../common/ipc/window";
|
||||
import { requestWindowAction } from "../../../ipc";
|
||||
|
||||
const closeWindowInjectable = getInjectable({
|
||||
id: "close-window",
|
||||
instantiate: () => () => requestWindowAction(WindowAction.CLOSE),
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default closeWindowInjectable;
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { WindowAction } from "../../../../common/ipc/window";
|
||||
import { requestWindowAction } from "../../../ipc";
|
||||
|
||||
const goBackInjectable = getInjectable({
|
||||
id: "go-back",
|
||||
instantiate: () => () => requestWindowAction(WindowAction.GO_BACK),
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default goBackInjectable;
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { WindowAction } from "../../../../common/ipc/window";
|
||||
import { requestWindowAction } from "../../../ipc";
|
||||
|
||||
const goForwardInjectable = getInjectable({
|
||||
id: "go-forward",
|
||||
instantiate: () => () => requestWindowAction(WindowAction.GO_FORWARD),
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default goForwardInjectable;
|
||||
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { WindowAction } from "../../../../common/ipc/window";
|
||||
import { requestWindowAction } from "../../../ipc";
|
||||
|
||||
const maximizeWindowInjectable = getInjectable({
|
||||
id: "maximize-window",
|
||||
instantiate: () => () => requestWindowAction(WindowAction.MINIMIZE),
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default maximizeWindowInjectable;
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { computed } from "mobx";
|
||||
import topBarStateInjectable from "./state.injectable";
|
||||
|
||||
const topBarNextEnabledInjectable = getInjectable({
|
||||
id: "top-bar-next-enabled",
|
||||
instantiate: (di) => {
|
||||
const state = di.inject(topBarStateInjectable);
|
||||
|
||||
return computed(() => state.nextEnabled);
|
||||
},
|
||||
});
|
||||
|
||||
export default topBarNextEnabledInjectable;
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { emitOpenAppMenuAsContextMenu } from "../../../ipc";
|
||||
|
||||
const openAppContextMenuInjectable = getInjectable({
|
||||
id: "open-app-context-menu",
|
||||
instantiate: () => emitOpenAppMenuAsContextMenu,
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default openAppContextMenuInjectable;
|
||||
@@ -0,0 +1,18 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { computed } from "mobx";
|
||||
import topBarStateInjectable from "./state.injectable";
|
||||
|
||||
const topBarPrevEnabledInjectable = getInjectable({
|
||||
id: "top-bar-prev-enabled",
|
||||
instantiate: (di) => {
|
||||
const state = di.inject(topBarStateInjectable);
|
||||
|
||||
return computed(() => state.prevEnabled);
|
||||
},
|
||||
});
|
||||
|
||||
export default topBarPrevEnabledInjectable;
|
||||
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { action } from "mobx";
|
||||
import { beforeFrameStartsInjectionToken } from "../../../before-frame-starts/before-frame-starts-injection-token";
|
||||
import ipcRendererInjectable from "../../../utils/channel/ipc-renderer.injectable";
|
||||
import topBarStateInjectable from "./state.injectable";
|
||||
|
||||
// TODO: replace with a SyncBox
|
||||
const startTopbarStateSyncInjectable = getInjectable({
|
||||
id: "start-topbar-state-sync",
|
||||
instantiate: (di) => {
|
||||
const state = di.inject(topBarStateInjectable);
|
||||
const ipcRenderer = di.inject(ipcRendererInjectable);
|
||||
|
||||
return {
|
||||
run: () => {
|
||||
ipcRenderer.on("history:can-go-back", action((event, canGoBack: boolean) => {
|
||||
state.prevEnabled = canGoBack;
|
||||
}));
|
||||
|
||||
ipcRenderer.on("history:can-go-forward", action((event, canGoForward: boolean) => {
|
||||
state.nextEnabled = canGoForward;
|
||||
}));
|
||||
},
|
||||
};
|
||||
},
|
||||
injectionToken: beforeFrameStartsInjectionToken,
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default startTopbarStateSyncInjectable;
|
||||
Loaded 100 of 421 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user