Turn on strict mode in tsconfig.json, some helpful lints, and required cleanup where strictness necessitates it (#5195)

* Turn on strict mode in tsconfig.json

- Add route, clusterRoute, and payloadValidatedClusterRoute helper
  functions to improve types with backend routes

- Turn on the following new lints:
  - react/jsx-first-prop-new-line
  - react/jsx-wrap-multilines
  - react/jsx-one-expression-per-line
  - react/jsx-max-props-per-line
  - react/jsx-indent
  - react/jsx-indent-props

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix build

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Replace KubeObject scope strings with enum

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Revert package.json version changes

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* revert move hostedCluster(Id)

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* change some type param names to be not single letters

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* remove copy-extension-themes

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* add new make clean action

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix build to not use webpack for generating types

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix kube-object-menu.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix select.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix catalog.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* revert move fileNameMigration to index

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix ref logic error

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix log-resource-selector.test.tsx tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix dock-store.test.ts test by overriding createStorage to not touch file system

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix cluster.test.ts tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix kube=api.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fixed hotbar-store.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix kubeconfig-manager.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix cluster-role-bindings/__tests__/dialog.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix role-bindings/__tests__/dialog.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix pods.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix delete-cluster-dialog.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix daemonset.store.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix replicaset.store.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix statefulsets/dialog/dialog.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix replicasets/scale-dialog/dialog.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix deployments.store.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix deployments/scale/dialog.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix cronjob.store.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix stateful-set.api.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix deployment.api.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix api-manager.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix statefulset.store.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix job.store.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix pods.store.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix scroll-spy.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix hotbar-remove-command.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix catalog-entity-registry.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix welcome.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix verify-that-all-routes-have-route-component.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix pod-tolerations.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* better fix for previous 3 fixes, plus also select.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix kube-object-menu.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix app-paths.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix dock-tabs.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix isReactNode typing

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix sub-title.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix drawer.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix list-layout.tsx and header.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix error-boundary.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix upgrade-chart/store.ts and dock-tab.store.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix install-chart/store.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix edit-resource/store.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix create-resource/store.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix namespace-select.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix namespace-select-filter.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix crd-list.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix wrong types for extensions

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix circular dependency

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix circular dependency on catalogCategoryRegistry

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix api-kube

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix type errors, most <Select /> errors

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fixing more type errors

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* some more fixing type errors

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* convert all KubeApis to injectable with legacy global backups

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* factor out into a common file all the exports

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* convert all KubeObjectStores to injectable with legacy global backups

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix lint

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* remove unused legacy KubeApi globals

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix bad previous commit

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* more crash fixing

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* try and fix behavioural tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix sidebar-and-tab-navigation-for-core.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix sidebar-and-tab-navigation-for-extensions.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix navigation-using-application-menu.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix catalog.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Make ThemeStore non-singleton and fix navigation-to-terminal-preferences.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* extensions.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix catalog-entity-registry.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix navigation-using-application-menu.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix log-resource-selector.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix dock-tabs.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix delete-cluster-dialog.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix navigation-to-kubernetes-preferences.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix navigation-to-editor-preferences.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix navigation-to-proxy-preferences.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix navigation-using-application-menu.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix navigation-to-application-preferences.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix dock-store.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix select.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix role-bindings/__tests__/dialog.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix hotbar-remove-command.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix cluster-role-bindings/__tests__/dialog.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix navigation-to-extension-specific-preferences.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix navigation-to-telemetry-preferences.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix closing-preferences.test.tsx

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix navigation-to-editor-preferences.test.ts

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix navigation-to-proxy-preferences.test.ts

- Fix other type errors too

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* final tweaks

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Add more tsconfig files, fix bug in <Catalog>

- Make all of history, navigation injectable

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix type errors

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Convert all of kube-details-params/ and navigate/ to injectable

- This fixes a runtime error that was encountered during testing

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix runtime errors on renderer

- remove all static uses of `createPageParam` (and then removed the
  legacy global)
- Made LensRendererExtension and LensMainExtension just used
  dependencies and not the getLegacyDi
- Fixed circular dep in extension-loader

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Move registerStore calls to after injectMany

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* replace all the rest of the legacy uses of apiManager

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix stack overflow and cycles in DI

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix NamespaceSelectFilter not opening

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix WizardStep and AddNamespaceDialog

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix KubeApi's not being registered

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* cleanup WindowManager

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Proper fix for Wizard, fix NamespaceStore.subscribe

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Rewrite withTooltip to be more type correct

- Fixes mobx related "too many recursive actions" error

- Change all the uses of withTooltips to be functional components

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Add e2e test to cover kube api registration

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* cleanup internal-commands

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* remove cast in <Animate>

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix command-palette e2e test

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix type error after rebase

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix test name

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix lint

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix code to help CodeQL scanner

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* update intree extension lock files

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix build-extensions picking wrong @types/react

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix tests from rebase

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix type error

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Make KubeconfigSyncManager more injectable

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix crash in test mode for Dialog

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* make Select snapshots deterministic

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix new type error

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix kube-object.store.test.ts typing

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix merge build issues

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix snapshots after merge

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix lint after merge

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* reexport BaseKubeJsonApiObjectMetadata

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix typo in terminalSpawningPool

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* remove duplicate license header

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix typo to waitUntilDefined

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* remove iter use from getLegacyGlobalDiForExtensionApi

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* remove complex createStorage override

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* override logger with mocks only when needed for tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* remove specialized overrideStore flags for getDiForUnitTesting

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* remove unnecessary | undefined types from the exactOptionalFieldTypes experiment

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* use more descriptive name for local test mocks

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* remove unnecessary addition to 'make clean' target

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* remove oddity of KubeObjectStore.getById(undefined) being allowed

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* rename KubeObject.getDescriptor in favour of name without fundemental JS meaning

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Simplify legacyRegisterApi when working in behaviour unit tests

- Don't emit within main environment as there should be no auto
  registering there

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* change confusing variable name in ReactiveDuration

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* make visitor pattern more explicit for Entity contextMenuOpen

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* toggleDetails -> toggleKubeDetailsPane is more specific

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* remove outdated comment

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix bug where LensExtension dependencies are not set

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Fix tests from the revert of react 18

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix more tests from merge

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix typings with new is-compatible-extension tests

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* more type fixing

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Revert in-tree extension versions

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Improve name of guarding injectable for stores and apis

- New name better implies that it is just a guard state and does not do
  anything

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* Add helper for <Select>.isMulti for storing in a Set<Value>

Signed-off-by: Sebastian Malton <sebastian@malton.name>

* fix is-compatible-extension.test.ts types

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton authored and GitHub committed 2022-05-16 07:17:57 -04:00
1 parent 381d77c633
commit dfcb7c3330
1062 files changed
+26512 -28689

No files matched your search

@@ -9,6 +9,8 @@ import { ClusterLocalTerminalSetting } from "../cluster-local-terminal-settings"
import userEvent from "@testing-library/user-event";
import { stat } from "fs/promises";
import { Notifications } from "../../../notifications";
import type { Stats } from "fs";
import type { Cluster } from "../../../../../common/cluster/cluster";
const mockStat = stat as jest.MockedFunction<typeof stat>;
@@ -28,7 +30,7 @@ describe("ClusterLocalTerminalSettings", () => {
});
it("should render without errors", () => {
const dom = render(<ClusterLocalTerminalSetting cluster={null}/>);
const dom = render(<ClusterLocalTerminalSetting cluster={null as never}/>);
expect(dom.container).toBeInstanceOf(HTMLElement);
});
@@ -42,7 +44,7 @@ describe("ClusterLocalTerminalSettings", () => {
getKubeconfig: jest.fn(() => ({
getContextObject: jest.fn(() => ({})),
})),
} as any;
} as unknown as Cluster;
const dom = render(<ClusterLocalTerminalSetting cluster={cluster}/>);
expect(await dom.findByDisplayValue("/foobar")).toBeDefined();
@@ -59,7 +61,7 @@ describe("ClusterLocalTerminalSettings", () => {
namespace: "blat",
})),
})),
} as any;
} as unknown as Cluster;
const dom = render(<ClusterLocalTerminalSetting cluster={cluster}/>);
expect(await dom.findByDisplayValue("/foobar")).toBeDefined();
@@ -74,7 +76,7 @@ describe("ClusterLocalTerminalSettings", () => {
getKubeconfig: jest.fn(() => ({
getContextObject: jest.fn(() => ({})),
})),
} as any;
} as unknown as Cluster;
const dom = render(<ClusterLocalTerminalSetting cluster={cluster}/>);
const dn = await dom.findByTestId("default-namespace");
@@ -87,19 +89,19 @@ describe("ClusterLocalTerminalSettings", () => {
});
it("should save the new CWD if path is a directory", async () => {
mockStat.mockImplementation(async (path: string) => {
mockStat.mockImplementation(async (path) => {
expect(path).toBe("/foobar");
return {
isDirectory: () => true,
} as any;
} as Stats;
});
const cluster = {
getKubeconfig: jest.fn(() => ({
getContextObject: jest.fn(() => ({})),
})),
} as any;
} as unknown as Cluster;
const dom = render(<ClusterLocalTerminalSetting cluster={cluster}/>);
const dn = await dom.findByTestId("working-directory");
@@ -112,20 +114,20 @@ describe("ClusterLocalTerminalSettings", () => {
});
it("should not save the new CWD if path is a file", async () => {
mockStat.mockImplementation(async (path: string) => {
mockStat.mockImplementation(async (path) => {
expect(path).toBe("/foobar");
return {
isDirectory: () => false,
isFile: () => true,
} as any;
} as Stats;
});
const cluster = {
getKubeconfig: jest.fn(() => ({
getContextObject: jest.fn(() => ({})),
})),
} as any;
} as unknown as Cluster;
const dom = render(<ClusterLocalTerminalSetting cluster={cluster}/>);
const dn = await dom.findByTestId("working-directory");
@@ -43,7 +43,7 @@ export class ClusterAccessibleNamespaces extends React.Component<ClusterAccessib
inputTheme="round-black"
/>
<small className="hint">
This setting is useful for manually specifying which namespaces you have access to. This is useful when you do not have permissions to list namespaces.
This setting is useful for manually specifying which namespaces you have access to. This is useful when you do not have permissions to list namespaces.
</small>
</>
);
@@ -47,7 +47,7 @@ export class ClusterIconSetting extends React.Component<ClusterIconSettingProps>
cluster.preferences.icon = `data:${file.type};base64,${buf.toString("base64")}`;
} catch (e) {
this.errorText = e.toString();
this.errorText = String(e);
this.status = GeneralInputStatus.ERROR;
}
}
@@ -63,8 +63,8 @@ export class ClusterIconSetting extends React.Component<ClusterIconSettingProps>
onUploadClick() {
this.element
.current
.querySelector<HTMLInputElement>("input[type=file]")
.click();
?.querySelector<HTMLInputElement>("input[type=file]")
?.click();
}
render() {
@@ -76,14 +76,14 @@ export class ClusterIconSetting extends React.Component<ClusterIconSettingProps>
<div className="mr-5">
<FilePicker
accept="image/*"
label={
label={(
<Avatar
colorHash={`${entity.getName()}-${entity.metadata.source}`}
title={entity.getName()}
src={entity.spec.icon?.src}
size={53}
/>
}
)}
onOverSizeLimit={OverSizeLimitStyle.FILTER}
handler={this.onIconPick}
/>
@@ -10,7 +10,7 @@ import { Input } from "../../input";
import { SubTitle } from "../../layout/sub-title";
import { stat } from "fs/promises";
import { Notifications } from "../../notifications";
import { resolveTilde } from "../../../utils";
import { isErrnoException, resolveTilde } from "../../../utils";
import { Icon } from "../../icon";
import { PathPicker } from "../../path-picker";
import { isWindows } from "../../../../common/vars";
@@ -61,7 +61,7 @@ async function validateDirectory(dir: string): Promise<string | false> {
return `the provided path is ${getUserReadableFileType(stats)} and not a directory.`;
} catch (error) {
switch (error?.code) {
switch (isErrnoException(error) ? error.code : undefined) {
case "ENOENT":
return `the provided path does not exist.`;
case "EACCES":
@@ -92,7 +92,7 @@ export const ClusterLocalTerminalSetting = observer(({ cluster }: ClusterLocalTe
useEffect(() => {
(async () => {
const kubeconfig = await cluster.getKubeconfig();
const { namespace } = kubeconfig.getContextObject(cluster.contextName);
const { namespace } = kubeconfig.getContextObject(cluster.contextName) ?? {};
if (namespace) {
setPlaceholderDefaultNamespace(namespace);
@@ -115,7 +115,10 @@ export const ClusterLocalTerminalSetting = observer(({ cluster }: ClusterLocalTe
Notifications.error(
<>
<b>Terminal Working Directory</b>
<p>Your changes were not saved because {errorMessage}</p>
<p>
{"Your changes were not saved because "}
{errorMessage}
</p>
</>,
);
} else {
@@ -155,7 +158,7 @@ export const ClusterLocalTerminalSetting = observer(({ cluster }: ClusterLocalTe
onChange={setDirectory}
onBlur={() => commitDirectory(directory)}
placeholder={isWindows ? "$USERPROFILE" : "$HOME"}
iconRight={
iconRight={(
<>
{
directory && (
@@ -172,10 +175,11 @@ export const ClusterLocalTerminalSetting = observer(({ cluster }: ClusterLocalTe
onClick={openFilePicker}
/>
</>
}
)}
/>
<small className="hint">
An explicit start path where the terminal will be launched,{" "}
An explicit start path where the terminal will be launched,
{" "}
this is used as the current working directory (cwd) for the shell process.
</small>
</section>
@@ -5,8 +5,7 @@
import React from "react";
import { disposeOnUnmount, observer } from "mobx-react";
import type { SelectOption } from "../../select/select";
import { Select } from "../../select/select";
import { onMultiSelectFor, Select } from "../../select/select";
import { Icon } from "../../icon/icon";
import { Button } from "../../button/button";
import { SubTitle } from "../../layout/sub-title";
@@ -41,21 +40,8 @@ export class ClusterMetricsSetting extends React.Component<ClusterMetricsSetting
this.props.cluster.preferences.hiddenMetrics = Array.from(this.hiddenMetrics);
};
onChangeSelect = (values: SelectOption<ClusterMetricsResourceType>[]) => {
for (const { value } of values) {
if (this.hiddenMetrics.has(value)) {
this.hiddenMetrics.delete(value);
} else {
this.hiddenMetrics.add(value);
}
}
this.save();
};
onChangeButton = () => {
Object.keys(ClusterMetricsResourceType).map(value =>
this.hiddenMetrics.add(value),
);
this.hiddenMetrics.replace(Object.keys(ClusterMetricsResourceType));
this.save();
};
@@ -64,14 +50,13 @@ export class ClusterMetricsSetting extends React.Component<ClusterMetricsSetting
this.save();
};
formatOptionLabel = ({ value: resource }: SelectOption<ClusterMetricsResourceType>) => (
<div className="flex gaps align-center">
<span>{resource}</span>
{this.hiddenMetrics.has(resource) && <Icon smallest material="check" className="box right" />}
</div>
);
renderMetricsSelect() {
const metricResourceTypeOptions = Object.values(ClusterMetricsResourceType)
.map(type => ({
value: type,
label: type,
isSelected: this.hiddenMetrics.has(type),
}));
return (
<>
@@ -84,9 +69,20 @@ export class ClusterMetricsSetting extends React.Component<ClusterMetricsSetting
onMenuClose={this.save}
closeMenuOnSelect={false}
controlShouldRenderValue={false}
options={Object.values(ClusterMetricsResourceType)}
onChange={this.onChangeSelect}
formatOptionLabel={this.formatOptionLabel}
options={metricResourceTypeOptions}
onChange={onMultiSelectFor(this.hiddenMetrics)}
formatOptionLabel={(option) => (
<div className="flex gaps align-center">
<span>{option.value}</span>
{option.isSelected && (
<Icon
smallest
material="check"
className="box right"
/>
)}
</div>
)}
themeName="lens"
/>
<Button
@@ -20,17 +20,29 @@ export interface ClusterPrometheusSettingProps {
cluster: Cluster;
}
const autoDetectPrometheus = Symbol("auto-detect-prometheus");
type ProviderValue = typeof autoDetectPrometheus | string;
@observer
export class ClusterPrometheusSetting extends React.Component<ClusterPrometheusSettingProps> {
@observable path = "";
@observable provider = "";
@observable selectedOption: ProviderValue = autoDetectPrometheus;
@observable loading = true;
@observable loadedOptions: MetricProviderInfo[] = [];
readonly loadedOptions = observable.map<string, MetricProviderInfo>();
@computed get options(): SelectOption<string>[] {
@computed get options(): SelectOption<ProviderValue>[] {
return [
{ value: "", label: "Auto detect" },
...this.loadedOptions.map(({ name, id }) => ({ value: id, label: name })),
{
value: autoDetectPrometheus,
label: "Auto Detect Prometheus",
isSelected: autoDetectPrometheus === this.selectedOption,
},
...Array.from(this.loadedOptions, ([id, provider]) => ({
value: id,
label: provider.name,
isSelected: id === this.selectedOption,
})),
];
}
@@ -40,11 +52,11 @@ export class ClusterPrometheusSetting extends React.Component<ClusterPrometheusS
}
@computed get canEditPrometheusPath(): boolean {
return Boolean(
this.loadedOptions
.find(opt => opt.id === this.provider)
?.isConfigurable,
);
if (!this.selectedOption || this.selectedOption === autoDetectPrometheus) {
return false;
}
return this.loadedOptions.get(this.selectedOption)?.isConfigurable ?? false;
}
componentDidMount() {
@@ -61,9 +73,9 @@ export class ClusterPrometheusSetting extends React.Component<ClusterPrometheusS
}
if (prometheusProvider) {
this.provider = prometheusProvider.type;
this.selectedOption = this.options.find(opt => opt.value === prometheusProvider.type)?.value ?? autoDetectPrometheus;
} else {
this.provider = "";
this.selectedOption = autoDetectPrometheus;
}
}),
);
@@ -72,22 +84,19 @@ export class ClusterPrometheusSetting extends React.Component<ClusterPrometheusS
.getMetricProviders()
.then(values => {
this.loading = false;
if (values) {
this.loadedOptions = values;
}
this.loadedOptions.replace(values.map(provider => [provider.id, provider]));
});
}
parsePrometheusPath = () => {
if (!this.provider || !this.path) {
return null;
if (!this.selectedOption || !this.path) {
return undefined;
}
const parsed = this.path.split(/\/|:/, 3);
const apiPrefix = this.path.substring(parsed.join("/").length);
if (!parsed[0] || !parsed[1] || !parsed[2]) {
return null;
return undefined;
}
return {
@@ -99,9 +108,9 @@ export class ClusterPrometheusSetting extends React.Component<ClusterPrometheusS
};
onSaveProvider = () => {
this.props.cluster.preferences.prometheusProvider = this.provider ?
{ type: this.provider } :
null;
this.props.cluster.preferences.prometheusProvider = typeof this.selectedOption === "string"
? { type: this.selectedOption }
: undefined;
};
onSavePath = () => {
@@ -112,28 +121,30 @@ export class ClusterPrometheusSetting extends React.Component<ClusterPrometheusS
return (
<>
<section>
<SubTitle title="Prometheus"/>
<SubTitle title="Prometheus" />
{
this.loading
? <Spinner />
: <>
<Select
id="cluster-prometheus-settings-input"
value={this.provider}
onChange={({ value }) => {
this.provider = value;
this.onSaveProvider();
}}
options={this.options}
themeName="lens"
/>
<small className="hint">What query format is used to fetch metrics from Prometheus</small>
</>
: (
<>
<Select
id="cluster-prometheus-settings-input"
value={this.selectedOption}
onChange={option => {
this.selectedOption = option?.value ?? autoDetectPrometheus;
this.onSaveProvider();
}}
options={this.options}
themeName="lens"
/>
<small className="hint">What query format is used to fetch metrics from Prometheus</small>
</>
)
}
</section>
{this.canEditPrometheusPath && (
<>
<hr/>
<hr />
<section>
<SubTitle title="Prometheus service address" />
<Input
@@ -144,8 +155,7 @@ export class ClusterPrometheusSetting extends React.Component<ClusterPrometheusS
placeholder="<namespace>/<service>:<port>"
/>
<small className="hint">
An address to an existing Prometheus installation{" "}
({"<namespace>/<service>:<port>"}). {productName} tries to auto-detect address if left empty.
{`An address to an existing Prometheus installation (<namespace>/<service>:<port>). ${productName} tries to auto-detect address if left empty.`}
</small>
</section>
</>
@@ -53,7 +53,11 @@ export class ShowMetricsSetting extends React.Component<ShowMetricsSettingProps>
const tooltipId = `${name}`;
return (
<Badge key={name} flat expandable={false}>
<Badge
key={name}
flat
expandable={false}
>
<span id={tooltipId}>{name}</span>
<Icon
smallest