1
0
mirror of https://github.com/lensapp/lens.git synced 2024-09-20 05:47:24 +03:00

Removed package "autobind-decorator" and @boundMethod in favour of "auto-bind" util for constructors-only. (#5218)

This commit is contained in:
Roman 2022-04-07 17:21:54 +03:00 committed by GitHub
parent 5f145e69e5
commit 06e7dfce5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
45 changed files with 150 additions and 180 deletions

View File

@ -210,7 +210,6 @@
"@types/circular-dependency-plugin": "5.0.5", "@types/circular-dependency-plugin": "5.0.5",
"abort-controller": "^3.0.0", "abort-controller": "^3.0.0",
"auto-bind": "^4.0.0", "auto-bind": "^4.0.0",
"autobind-decorator": "^2.4.0",
"await-lock": "^2.1.0", "await-lock": "^2.1.0",
"byline": "^5.0.0", "byline": "^5.0.0",
"chokidar": "^3.5.3", "chokidar": "^3.5.3",

View File

@ -3,7 +3,6 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { boundMethod, boundClass } from "autobind-decorator";
import type { Options } from "auto-bind"; import type { Options } from "auto-bind";
import autoBindClass from "auto-bind"; import autoBindClass from "auto-bind";
import autoBindReactClass from "auto-bind/react"; import autoBindReactClass from "auto-bind/react";
@ -16,10 +15,3 @@ export function autoBind<T extends object>(obj: T, opts?: Options): T {
return autoBindClass(obj, opts); return autoBindClass(obj, opts);
} }
// Class/method decorators
// Note: @boundClass doesn't work with mobx-6.x/@action decorator
export {
boundClass,
boundMethod,
};

View File

@ -9,7 +9,7 @@ import { SpeedDial, SpeedDialAction } from "@material-ui/lab";
import { Icon } from "../icon"; import { Icon } from "../icon";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import { observable, makeObservable, action } from "mobx"; import { observable, makeObservable, action } from "mobx";
import { boundMethod } from "../../../common/utils"; import { autoBind } from "../../../common/utils";
import type { CatalogCategory, CatalogEntityAddMenuContext, CatalogEntityAddMenu } from "../../api/catalog-entity"; import type { CatalogCategory, CatalogEntityAddMenuContext, CatalogEntityAddMenu } from "../../api/catalog-entity";
import { EventEmitter } from "events"; import { EventEmitter } from "events";
import { navigate } from "../../navigation"; import { navigate } from "../../navigation";
@ -29,6 +29,7 @@ export class CatalogAddButton extends React.Component<CatalogAddButtonProps> {
constructor(props: CatalogAddButtonProps) { constructor(props: CatalogAddButtonProps) {
super(props); super(props);
makeObservable(this); makeObservable(this);
autoBind(this);
} }
componentDidMount() { componentDidMount() {
@ -74,17 +75,14 @@ export class CatalogAddButton extends React.Component<CatalogAddButtonProps> {
return category.filteredItems(this.menuItems.get(category.getId()) || []); return category.filteredItems(this.menuItems.get(category.getId()) || []);
}; };
@boundMethod
onOpen() { onOpen() {
this.isOpen = true; this.isOpen = true;
} }
@boundMethod
onClose() { onClose() {
this.isOpen = false; this.isOpen = false;
} }
@boundMethod
onButtonClick() { onButtonClick() {
const defaultAction = this.items.find(item => item.defaultAction)?.onClick; const defaultAction = this.items.find(item => item.defaultAction)?.onClick;
const clickAction = defaultAction || (this.items.length === 1 ? this.items[0].onClick : null); const clickAction = defaultAction || (this.items.length === 1 ? this.items[0].onClick : null);

View File

@ -13,7 +13,7 @@ import { SubHeader } from "../layout/sub-header";
import { Table, TableCell, TableHead, TableRow } from "../table"; import { Table, TableCell, TableHead, TableRow } from "../table";
import { nodesStore } from "../+nodes/nodes.store"; import { nodesStore } from "../+nodes/nodes.store";
import { eventStore } from "../+events/event.store"; import { eventStore } from "../+events/event.store";
import { boundMethod, cssNames, prevDefault } from "../../utils"; import { cssNames, prevDefault } from "../../utils";
import type { ItemObject } from "../../../common/item.store"; import type { ItemObject } from "../../../common/item.store";
import { Spinner } from "../spinner"; import { Spinner } from "../spinner";
import { ThemeStore } from "../../theme.store"; import { ThemeStore } from "../../theme.store";
@ -72,8 +72,7 @@ export class ClusterIssues extends React.Component<ClusterIssuesProps> {
]; ];
} }
@boundMethod getTableRow = (uid: string) => {
getTableRow(uid: string) {
const { warnings } = this; const { warnings } = this;
const warning = warnings.find(warn => warn.getId() == uid); const warning = warnings.find(warn => warn.getId() == uid);
const { getId, getName, message, kind, selfLink, renderAge } = warning; const { getId, getName, message, kind, selfLink, renderAge } = warning;
@ -99,7 +98,7 @@ export class ClusterIssues extends React.Component<ClusterIssuesProps> {
</TableCell> </TableCell>
</TableRow> </TableRow>
); );
} };
renderContent() { renderContent() {
const { warnings } = this; const { warnings } = this;

View File

@ -11,7 +11,7 @@ import { getChartDetails } from "../../../common/k8s-api/endpoints/helm-charts.a
import { observable, makeObservable, reaction } from "mobx"; import { observable, makeObservable, reaction } from "mobx";
import { disposeOnUnmount, observer } from "mobx-react"; import { disposeOnUnmount, observer } from "mobx-react";
import { Drawer, DrawerItem } from "../drawer"; import { Drawer, DrawerItem } from "../drawer";
import { boundMethod, stopPropagation } from "../../utils"; import { autoBind, stopPropagation } from "../../utils";
import { MarkdownViewer } from "../markdown-viewer"; import { MarkdownViewer } from "../markdown-viewer";
import { Spinner } from "../spinner"; import { Spinner } from "../spinner";
import { Button } from "../button"; import { Button } from "../button";
@ -48,6 +48,7 @@ class NonInjectedHelmChartDetails extends Component<HelmChartDetailsProps & Depe
constructor(props: HelmChartDetailsProps & Dependencies) { constructor(props: HelmChartDetailsProps & Dependencies) {
super(props); super(props);
makeObservable(this); makeObservable(this);
autoBind(this);
} }
componentWillUnmount() { componentWillUnmount() {
@ -77,7 +78,6 @@ class NonInjectedHelmChartDetails extends Component<HelmChartDetailsProps & Depe
]); ]);
} }
@boundMethod
async onVersionChange({ value: chart }: SelectOption<HelmChart>) { async onVersionChange({ value: chart }: SelectOption<HelmChart>) {
this.selectedChart = chart; this.selectedChart = chart;
this.readme = null; this.readme = null;
@ -94,7 +94,6 @@ class NonInjectedHelmChartDetails extends Component<HelmChartDetailsProps & Depe
} }
} }
@boundMethod
install() { install() {
this.props.createInstallChartTab(this.selectedChart); this.props.createInstallChartTab(this.selectedChart);
this.props.hideDetails(); this.props.hideDetails();

View File

@ -10,7 +10,7 @@ import { computed, makeObservable, observable, reaction } from "mobx";
import { disposeOnUnmount, observer } from "mobx-react"; import { disposeOnUnmount, observer } from "mobx-react";
import { DrawerItem } from "../drawer"; import { DrawerItem } from "../drawer";
import type { Disposer } from "../../utils"; import type { Disposer } from "../../utils";
import { boundMethod, cssNames } from "../../utils"; import { cssNames } from "../../utils";
import { getMetricsForNamespace, type IPodMetrics, Namespace } from "../../../common/k8s-api/endpoints"; import { getMetricsForNamespace, type IPodMetrics, Namespace } from "../../../common/k8s-api/endpoints";
import type { KubeObjectDetailsProps } from "../kube-object-details"; import type { KubeObjectDetailsProps } from "../kube-object-details";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
@ -71,10 +71,9 @@ class NonInjectedNamespaceDetails extends React.Component<NamespaceDetailsProps
return limitRangeStore.getAllByNs(namespace); return limitRangeStore.getAllByNs(namespace);
} }
@boundMethod loadMetrics = async () => {
async loadMetrics() {
this.metrics = await getMetricsForNamespace(this.props.object.getName(), ""); this.metrics = await getMetricsForNamespace(this.props.object.getName(), "");
} };
render() { render() {
const { object: namespace } = this.props; const { object: namespace } = this.props;

View File

@ -9,10 +9,10 @@ import React from "react";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import type { EndpointSubset, Endpoint, EndpointAddress } from "../../../common/k8s-api/endpoints"; import type { EndpointSubset, Endpoint, EndpointAddress } from "../../../common/k8s-api/endpoints";
import { Table, TableCell, TableHead, TableRow } from "../table"; import { Table, TableCell, TableHead, TableRow } from "../table";
import { boundMethod } from "../../utils";
import { apiManager } from "../../../common/k8s-api/api-manager"; import { apiManager } from "../../../common/k8s-api/api-manager";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import { getDetailsUrl } from "../kube-detail-params"; import { getDetailsUrl } from "../kube-detail-params";
import { autoBind } from "../../../common/utils";
export interface EndpointSubsetListProps { export interface EndpointSubsetListProps {
subset: EndpointSubset; subset: EndpointSubset;
@ -21,6 +21,10 @@ export interface EndpointSubsetListProps {
@observer @observer
export class EndpointSubsetList extends React.Component<EndpointSubsetListProps> { export class EndpointSubsetList extends React.Component<EndpointSubsetListProps> {
constructor(props: EndpointSubsetListProps) {
super(props);
autoBind(this);
}
getAddressTableRow(ip: string) { getAddressTableRow(ip: string) {
const { subset } = this.props; const { subset } = this.props;
@ -29,7 +33,6 @@ export class EndpointSubsetList extends React.Component<EndpointSubsetListProps>
return this.renderAddressTableRow(address); return this.renderAddressTableRow(address);
} }
@boundMethod
getNotReadyAddressTableRow(ip: string) { getNotReadyAddressTableRow(ip: string) {
const { subset } = this.props; const { subset } = this.props;
const address = subset.getNotReadyAddresses().find(address => address.getId() == ip); const address = subset.getNotReadyAddresses().find(address => address.getId() == ip);
@ -37,7 +40,6 @@ export class EndpointSubsetList extends React.Component<EndpointSubsetListProps>
return this.renderAddressTableRow(address); return this.renderAddressTableRow(address);
} }
@boundMethod
renderAddressTable(addresses: EndpointAddress[], virtual: boolean) { renderAddressTable(addresses: EndpointAddress[], virtual: boolean) {
return ( return (
<div> <div>
@ -63,7 +65,6 @@ export class EndpointSubsetList extends React.Component<EndpointSubsetListProps>
); );
} }
@boundMethod
renderAddressTableRow(address: EndpointAddress) { renderAddressTableRow(address: EndpointAddress) {
const { endpoint } = this.props; const { endpoint } = this.props;

View File

@ -19,7 +19,6 @@ import { KubeObjectMeta } from "../kube-object-meta";
import { computeRuleDeclarations, getMetricsForIngress, type IIngressMetrics } from "../../../common/k8s-api/endpoints/ingress.api"; import { computeRuleDeclarations, getMetricsForIngress, type IIngressMetrics } from "../../../common/k8s-api/endpoints/ingress.api";
import { getActiveClusterEntity } from "../../api/catalog-entity-registry"; import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
import { ClusterMetricsResourceType } from "../../../common/cluster-types"; import { ClusterMetricsResourceType } from "../../../common/cluster-types";
import { boundMethod } from "../../utils";
import logger from "../../../common/logger"; import logger from "../../../common/logger";
export interface IngressDetailsProps extends KubeObjectDetailsProps<Ingress> { export interface IngressDetailsProps extends KubeObjectDetailsProps<Ingress> {
@ -42,12 +41,11 @@ export class IngressDetails extends React.Component<IngressDetailsProps> {
]); ]);
} }
@boundMethod loadMetrics = async () => {
async loadMetrics() {
const { object: ingress } = this.props; const { object: ingress } = this.props;
this.metrics = await getMetricsForIngress(ingress.getName(), ingress.getNs()); this.metrics = await getMetricsForIngress(ingress.getName(), ingress.getNs());
} };
renderPaths(ingress: Ingress) { renderPaths(ingress: Ingress) {
return ingress.getRules() return ingress.getRules()

View File

@ -4,7 +4,7 @@
*/ */
import React from "react"; import React from "react";
import { boundMethod, cssNames } from "../../utils"; import { autoBind, cssNames } from "../../utils";
import type { PortForwardItem, PortForwardStore } from "../../port-forward"; import type { PortForwardItem, PortForwardStore } from "../../port-forward";
import { openPortForward } from "../../port-forward"; import { openPortForward } from "../../port-forward";
import type { MenuActionsProps } from "../menu/menu-actions"; import type { MenuActionsProps } from "../menu/menu-actions";
@ -26,8 +26,12 @@ interface Dependencies {
openPortForwardDialog: (item: PortForwardItem) => void; openPortForwardDialog: (item: PortForwardItem) => void;
} }
class NonInjectedPortForwardMenu extends React.Component<PortForwardMenuProps & Dependencies> { class NonInjectedPortForwardMenu<Props extends PortForwardMenuProps & Dependencies> extends React.Component<Props> {
@boundMethod constructor(props: Props) {
super(props);
autoBind(this);
}
remove() { remove() {
const { portForward } = this.props; const { portForward } = this.props;

View File

@ -25,7 +25,6 @@ import { ClusterMetricsResourceType } from "../../../common/cluster-types";
import { NodeDetailsResources } from "./details-resources"; import { NodeDetailsResources } from "./details-resources";
import { DrawerTitle } from "../drawer/drawer-title"; import { DrawerTitle } from "../drawer/drawer-title";
import type { Disposer } from "../../utils"; import type { Disposer } from "../../utils";
import { boundMethod } from "../../utils";
import logger from "../../../common/logger"; import logger from "../../../common/logger";
import type { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import type { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
import type { KubeObject } from "../../../common/k8s-api/kube-object"; import type { KubeObject } from "../../../common/k8s-api/kube-object";
@ -61,12 +60,11 @@ class NonInjectedNodeDetails extends React.Component<NodeDetailsProps & Dependen
]); ]);
} }
@boundMethod loadMetrics = async () => {
async loadMetrics() {
const { object: node } = this.props; const { object: node } = this.props;
this.metrics = await getMetricsByNodeNames([node.getName()]); this.metrics = await getMetricsByNodeNames([node.getName()]);
} };
render() { render() {
const { object: node } = this.props; const { object: node } = this.props;

View File

@ -20,7 +20,6 @@ import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
import { ClusterMetricsResourceType } from "../../../common/cluster-types"; import { ClusterMetricsResourceType } from "../../../common/cluster-types";
import { KubeObjectMeta } from "../kube-object-meta"; import { KubeObjectMeta } from "../kube-object-meta";
import { getDetailsUrl } from "../kube-detail-params"; import { getDetailsUrl } from "../kube-detail-params";
import { boundMethod } from "../../utils";
import logger from "../../../common/logger"; import logger from "../../../common/logger";
export interface PersistentVolumeClaimDetailsProps extends KubeObjectDetailsProps<PersistentVolumeClaim> { export interface PersistentVolumeClaimDetailsProps extends KubeObjectDetailsProps<PersistentVolumeClaim> {
@ -43,12 +42,11 @@ export class PersistentVolumeClaimDetails extends React.Component<PersistentVolu
]); ]);
} }
@boundMethod loadMetrics = async () => {
async loadMetrics() {
const { object: volumeClaim } = this.props; const { object: volumeClaim } = this.props;
this.metrics = await getMetricsForPvc(volumeClaim); this.metrics = await getMetricsForPvc(volumeClaim);
} };
render() { render() {
const { object: volumeClaim } = this.props; const { object: volumeClaim } = this.props;

View File

@ -8,7 +8,6 @@ import "./volume-details-list.scss";
import React from "react"; import React from "react";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import type { PersistentVolume } from "../../../common/k8s-api/endpoints/persistent-volume.api"; import type { PersistentVolume } from "../../../common/k8s-api/endpoints/persistent-volume.api";
import { boundMethod } from "../../../common/utils/autobind";
import { TableRow } from "../table/table-row"; import { TableRow } from "../table/table-row";
import { cssNames, prevDefault } from "../../utils"; import { cssNames, prevDefault } from "../../utils";
import { showDetails } from "../kube-detail-params"; import { showDetails } from "../kube-detail-params";
@ -38,8 +37,7 @@ export class VolumeDetailsList extends React.Component<VolumeDetailsListProps> {
[sortBy.status]: (volume: PersistentVolume) => volume.getStatus(), [sortBy.status]: (volume: PersistentVolume) => volume.getStatus(),
}; };
@boundMethod getTableRow = (uid: string) => {
getTableRow(uid: string) {
const { persistentVolumes } = this.props; const { persistentVolumes } = this.props;
const volume = persistentVolumes.find(volume => volume.getId() === uid); const volume = persistentVolumes.find(volume => volume.getId() === uid);
@ -55,7 +53,7 @@ export class VolumeDetailsList extends React.Component<VolumeDetailsListProps> {
<TableCell className={cssNames("status", kebabCase(volume.getStatus()))}>{volume.getStatus()}</TableCell> <TableCell className={cssNames("status", kebabCase(volume.getStatus()))}>{volume.getStatus()}</TableCell>
</TableRow> </TableRow>
); );
} };
render() { render() {
const { persistentVolumes } = this.props; const { persistentVolumes } = this.props;

View File

@ -9,7 +9,7 @@ import { reaction } from "mobx";
import { disposeOnUnmount, observer } from "mobx-react"; import { disposeOnUnmount, observer } from "mobx-react";
import React from "react"; import React from "react";
import type { RoleBinding, RoleBindingSubject } from "../../../../common/k8s-api/endpoints"; import type { RoleBinding, RoleBindingSubject } from "../../../../common/k8s-api/endpoints";
import { prevDefault, boundMethod } from "../../../utils"; import { prevDefault } from "../../../utils";
import { AddRemoveButtons } from "../../add-remove-buttons"; import { AddRemoveButtons } from "../../add-remove-buttons";
import { ConfirmDialog } from "../../confirm-dialog"; import { ConfirmDialog } from "../../confirm-dialog";
import { DrawerTitle } from "../../drawer"; import { DrawerTitle } from "../../drawer";
@ -36,8 +36,7 @@ export class RoleBindingDetails extends React.Component<RoleBindingDetailsProps>
]); ]);
} }
@boundMethod removeSelectedSubjects = () => {
removeSelectedSubjects() {
const { object: roleBinding } = this.props; const { object: roleBinding } = this.props;
const { selectedSubjects } = this; const { selectedSubjects } = this;
@ -48,7 +47,7 @@ export class RoleBindingDetails extends React.Component<RoleBindingDetailsProps>
<p>Remove selected bindings for <b>{roleBinding.getName()}</b>?</p> <p>Remove selected bindings for <b>{roleBinding.getName()}</b>?</p>
), ),
}); });
} };
render() { render() {
const { selectedSubjects } = this; const { selectedSubjects } = this;

View File

@ -24,7 +24,6 @@ import { KubeObjectMeta } from "../kube-object-meta";
import { getActiveClusterEntity } from "../../api/catalog-entity-registry"; import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
import { ClusterMetricsResourceType } from "../../../common/cluster-types"; import { ClusterMetricsResourceType } from "../../../common/cluster-types";
import type { Disposer } from "../../utils"; import type { Disposer } from "../../utils";
import { boundMethod } from "../../utils";
import logger from "../../../common/logger"; import logger from "../../../common/logger";
import type { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import type { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
import type { KubeObject } from "../../../common/k8s-api/kube-object"; import type { KubeObject } from "../../../common/k8s-api/kube-object";
@ -59,12 +58,11 @@ class NonInjectedDaemonSetDetails extends React.Component<DaemonSetDetailsProps
]); ]);
} }
@boundMethod loadMetrics = async () => {
async loadMetrics() {
const { object: daemonSet } = this.props; const { object: daemonSet } = this.props;
this.metrics = await getMetricsForDaemonSets([daemonSet], daemonSet.getNs(), ""); this.metrics = await getMetricsForDaemonSets([daemonSet], daemonSet.getNs(), "");
} };
render() { render() {
const { object: daemonSet } = this.props; const { object: daemonSet } = this.props;

View File

@ -26,7 +26,6 @@ import { DeploymentReplicaSets } from "./deployment-replicasets";
import { getActiveClusterEntity } from "../../api/catalog-entity-registry"; import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
import { ClusterMetricsResourceType } from "../../../common/cluster-types"; import { ClusterMetricsResourceType } from "../../../common/cluster-types";
import type { Disposer } from "../../utils"; import type { Disposer } from "../../utils";
import { boundMethod } from "../../utils";
import logger from "../../../common/logger"; import logger from "../../../common/logger";
import type { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import type { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
import type { KubeObject } from "../../../common/k8s-api/kube-object"; import type { KubeObject } from "../../../common/k8s-api/kube-object";
@ -63,12 +62,11 @@ class NonInjectedDeploymentDetails extends React.Component<DeploymentDetailsProp
]); ]);
} }
@boundMethod loadMetrics = async () => {
async loadMetrics() {
const { object: deployment } = this.props; const { object: deployment } = this.props;
this.metrics = await getMetricsForDeployments([deployment], deployment.getNs(), ""); this.metrics = await getMetricsForDeployments([deployment], deployment.getNs(), "");
} };
render() { render() {
const { object: deployment } = this.props; const { object: deployment } = this.props;

View File

@ -25,7 +25,6 @@ import { podMetricTabs, PodCharts } from "../+workloads-pods/pod-charts";
import { ClusterMetricsResourceType } from "../../../common/cluster-types"; import { ClusterMetricsResourceType } from "../../../common/cluster-types";
import { getActiveClusterEntity } from "../../api/catalog-entity-registry"; import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
import { ResourceMetrics } from "../resource-metrics"; import { ResourceMetrics } from "../resource-metrics";
import { boundMethod } from "autobind-decorator";
import { getDetailsUrl } from "../kube-detail-params"; import { getDetailsUrl } from "../kube-detail-params";
import { apiManager } from "../../../common/k8s-api/api-manager"; import { apiManager } from "../../../common/k8s-api/api-manager";
import logger from "../../../common/logger"; import logger from "../../../common/logger";
@ -63,12 +62,11 @@ class NonInjectedJobDetails extends React.Component<JobDetailsProps & Dependenci
]); ]);
} }
@boundMethod loadMetrics = async () => {
async loadMetrics() {
const { object: job } = this.props; const { object: job } = this.props;
this.metrics = await getMetricsForJobs([job], job.getNs(), ""); this.metrics = await getMetricsForJobs([job], job.getNs(), "");
} };
render() { render() {
const { object: job } = this.props; const { object: job } = this.props;

View File

@ -11,7 +11,7 @@ import { reaction } from "mobx";
import { disposeOnUnmount, observer } from "mobx-react"; import { disposeOnUnmount, observer } from "mobx-react";
import { podsStore } from "./pods.store"; import { podsStore } from "./pods.store";
import type { Pod } from "../../../common/k8s-api/endpoints"; import type { Pod } from "../../../common/k8s-api/endpoints";
import { boundMethod, bytesToUnits, cssNames, interval, prevDefault } from "../../utils"; import { autoBind, bytesToUnits, cssNames, interval, prevDefault } from "../../utils";
import { LineProgress } from "../line-progress"; import { LineProgress } from "../line-progress";
import type { KubeObject } from "../../../common/k8s-api/kube-object"; import type { KubeObject } from "../../../common/k8s-api/kube-object";
import { Table, TableCell, TableHead, TableRow } from "../table"; import { Table, TableCell, TableHead, TableRow } from "../table";
@ -36,6 +36,11 @@ export interface PodDetailsListProps {
@observer @observer
export class PodDetailsList extends React.Component<PodDetailsListProps> { export class PodDetailsList extends React.Component<PodDetailsListProps> {
constructor(props: PodDetailsListProps) {
super(props);
autoBind(this);
}
private metricsWatcher = interval(120, () => { private metricsWatcher = interval(120, () => {
podsStore.loadKubeMetrics(this.props.owner.getNs()); podsStore.loadKubeMetrics(this.props.owner.getNs());
}); });
@ -88,7 +93,6 @@ export class PodDetailsList extends React.Component<PodDetailsListProps> {
); );
} }
@boundMethod
getTableRow(uid: string) { getTableRow(uid: string) {
const { pods } = this.props; const { pods } = this.props;
const pod = pods.find(pod => pod.getId() == uid); const pod = pods.find(pod => pod.getId() == uid);

View File

@ -13,7 +13,7 @@ import { observable, reaction, makeObservable } from "mobx";
import { type IPodMetrics, nodesApi, Pod, getMetricsForPods } from "../../../common/k8s-api/endpoints"; import { type IPodMetrics, nodesApi, Pod, getMetricsForPods } from "../../../common/k8s-api/endpoints";
import { DrawerItem, DrawerTitle } from "../drawer"; import { DrawerItem, DrawerTitle } from "../drawer";
import { Badge } from "../badge"; import { Badge } from "../badge";
import { boundMethod, cssNames, toJS } from "../../utils"; import { cssNames, toJS } from "../../utils";
import { PodDetailsContainer } from "./pod-details-container"; import { PodDetailsContainer } from "./pod-details-container";
import { PodDetailsAffinities } from "./pod-details-affinities"; import { PodDetailsAffinities } from "./pod-details-affinities";
import { PodDetailsTolerations } from "./pod-details-tolerations"; import { PodDetailsTolerations } from "./pod-details-tolerations";
@ -51,13 +51,12 @@ export class PodDetails extends React.Component<PodDetailsProps> {
]); ]);
} }
@boundMethod loadMetrics = async () => {
async loadMetrics() {
const { object: pod } = this.props; const { object: pod } = this.props;
this.metrics = await getMetricsForPods([pod], pod.getNs()); this.metrics = await getMetricsForPods([pod], pod.getNs());
this.containerMetrics = await getMetricsForPods([pod], pod.getNs(), "container, namespace"); this.containerMetrics = await getMetricsForPods([pod], pod.getNs(), "container, namespace");
} };
render() { render() {
const { object: pod } = this.props; const { object: pod } = this.props;

View File

@ -23,7 +23,6 @@ import { KubeObjectMeta } from "../kube-object-meta";
import { getActiveClusterEntity } from "../../api/catalog-entity-registry"; import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
import { ClusterMetricsResourceType } from "../../../common/cluster-types"; import { ClusterMetricsResourceType } from "../../../common/cluster-types";
import type { Disposer } from "../../utils"; import type { Disposer } from "../../utils";
import { boundMethod } from "../../utils";
import logger from "../../../common/logger"; import logger from "../../../common/logger";
import type { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import type { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
import type { KubeObject } from "../../../common/k8s-api/kube-object"; import type { KubeObject } from "../../../common/k8s-api/kube-object";
@ -59,12 +58,11 @@ class NonInjectedReplicaSetDetails extends React.Component<ReplicaSetDetailsProp
]); ]);
} }
@boundMethod loadMetrics = async () => {
async loadMetrics() {
const { object: replicaSet } = this.props; const { object: replicaSet } = this.props;
this.metrics = await getMetricsForReplicaSets([replicaSet], replicaSet.getNs(), ""); this.metrics = await getMetricsForReplicaSets([replicaSet], replicaSet.getNs(), "");
} };
render() { render() {
const { object: replicaSet } = this.props; const { object: replicaSet } = this.props;

View File

@ -24,7 +24,6 @@ import { KubeObjectMeta } from "../kube-object-meta";
import { getActiveClusterEntity } from "../../api/catalog-entity-registry"; import { getActiveClusterEntity } from "../../api/catalog-entity-registry";
import { ClusterMetricsResourceType } from "../../../common/cluster-types"; import { ClusterMetricsResourceType } from "../../../common/cluster-types";
import type { Disposer } from "../../utils"; import type { Disposer } from "../../utils";
import { boundMethod } from "../../utils";
import logger from "../../../common/logger"; import logger from "../../../common/logger";
import type { KubeObjectStore } from "../../../common/k8s-api/kube-object.store"; import type { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
import type { KubeObject } from "../../../common/k8s-api/kube-object"; import type { KubeObject } from "../../../common/k8s-api/kube-object";
@ -60,12 +59,11 @@ class NonInjectedStatefulSetDetails extends React.Component<StatefulSetDetailsPr
]); ]);
} }
@boundMethod loadMetrics = async () => {
async loadMetrics() {
const { object: statefulSet } = this.props; const { object: statefulSet } = this.props;
this.metrics = await getMetricsForStatefulSets([statefulSet], statefulSet.getNs(), ""); this.metrics = await getMetricsForStatefulSets([statefulSet], statefulSet.getNs(), "");
} };
render() { render() {
const { object: statefulSet } = this.props; const { object: statefulSet } = this.props;

View File

@ -11,7 +11,7 @@ import { observer } from "mobx-react";
import { cssNames } from "../../utils/cssNames"; import { cssNames } from "../../utils/cssNames";
import type { TooltipDecoratorProps } from "../tooltip"; import type { TooltipDecoratorProps } from "../tooltip";
import { withTooltip } from "../tooltip"; import { withTooltip } from "../tooltip";
import { boundMethod } from "../../utils"; import { autoBind } from "../../utils";
export interface BadgeProps extends React.HTMLAttributes<any>, TooltipDecoratorProps { export interface BadgeProps extends React.HTMLAttributes<any>, TooltipDecoratorProps {
small?: boolean; small?: boolean;
@ -44,6 +44,7 @@ export class Badge extends React.Component<BadgeProps> {
constructor(props: BadgeProps) { constructor(props: BadgeProps) {
super(props); super(props);
makeObservable(this); makeObservable(this);
autoBind(this);
} }
@computed get isExpandable() { @computed get isExpandable() {
@ -52,7 +53,6 @@ export class Badge extends React.Component<BadgeProps> {
return this.elem?.clientWidth < this.elem?.scrollWidth; return this.elem?.clientWidth < this.elem?.scrollWidth;
} }
@boundMethod
onMouseUp() { onMouseUp() {
if (!this.isExpandable || Badge.badgeMeta.hasTextSelected) { if (!this.isExpandable || Badge.badgeMeta.hasTextSelected) {
Badge.badgeMeta.hasTextSelected = false; Badge.badgeMeta.hasTextSelected = false;
@ -61,7 +61,6 @@ export class Badge extends React.Component<BadgeProps> {
} }
} }
@boundMethod
bindRef(elem: HTMLElement) { bindRef(elem: HTMLElement) {
this.elem = elem; this.elem = elem;
} }

View File

@ -5,7 +5,7 @@
import "./checkbox.scss"; import "./checkbox.scss";
import React from "react"; import React from "react";
import { boundMethod, cssNames } from "../../utils"; import { cssNames } from "../../utils";
export interface CheckboxProps<T = boolean> { export interface CheckboxProps<T = boolean> {
className?: string; className?: string;
@ -19,12 +19,11 @@ export interface CheckboxProps<T = boolean> {
export class Checkbox extends React.PureComponent<CheckboxProps> { export class Checkbox extends React.PureComponent<CheckboxProps> {
private input: HTMLInputElement; private input: HTMLInputElement;
@boundMethod onChange = (evt: React.ChangeEvent<HTMLInputElement>) => {
onChange(evt: React.ChangeEvent<HTMLInputElement>) {
if (this.props.onChange) { if (this.props.onChange) {
this.props.onChange(this.input.checked, evt); this.props.onChange(this.input.checked, evt);
} }
} };
getValue() { getValue() {
if (this.props.value !== undefined) return this.props.value; if (this.props.value !== undefined) return this.props.value;

View File

@ -5,7 +5,7 @@
import React from "react"; import React from "react";
import type { Cluster } from "../../../../common/cluster/cluster"; import type { Cluster } from "../../../../common/cluster/cluster";
import { boundMethod } from "../../../utils"; import { autoBind } from "../../../utils";
import { observable } from "mobx"; import { observable } from "mobx";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import type { KubernetesCluster } from "../../../../common/catalog-entities"; import type { KubernetesCluster } from "../../../../common/catalog-entities";
@ -28,9 +28,13 @@ export class ClusterIconSetting extends React.Component<ClusterIconSettingProps>
@observable status = GeneralInputStatus.CLEAN; @observable status = GeneralInputStatus.CLEAN;
@observable errorText?: string; @observable errorText?: string;
constructor(props: ClusterIconSettingProps) {
super(props);
autoBind(this);
}
private element = React.createRef<HTMLDivElement>(); private element = React.createRef<HTMLDivElement>();
@boundMethod
async onIconPick([file]: File[]) { async onIconPick([file]: File[]) {
if (!file) { if (!file) {
return; return;
@ -56,7 +60,6 @@ export class ClusterIconSetting extends React.Component<ClusterIconSettingProps>
this.props.cluster.preferences.icon = null; this.props.cluster.preferences.icon = null;
} }
@boundMethod
onUploadClick() { onUploadClick() {
this.element this.element
.current .current

View File

@ -7,7 +7,6 @@ import React from "react";
import type { Cluster } from "../../../../common/cluster/cluster"; import type { Cluster } from "../../../../common/cluster/cluster";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import { SubTitle } from "../../layout/sub-title"; import { SubTitle } from "../../layout/sub-title";
import { boundMethod } from "../../../../common/utils";
import { shell } from "electron"; import { shell } from "electron";
import { Notice } from "../../+extensions/notice"; import { Notice } from "../../+extensions/notice";
@ -17,13 +16,11 @@ export interface ClusterKubeconfigProps {
@observer @observer
export class ClusterKubeconfig extends React.Component<ClusterKubeconfigProps> { export class ClusterKubeconfig extends React.Component<ClusterKubeconfigProps> {
openKubeconfig = () => {
@boundMethod
openKubeconfig() {
const { cluster } = this.props; const { cluster } = this.props;
shell.showItemInFolder(cluster.kubeConfigPath); shell.showItemInFolder(cluster.kubeConfigPath);
} };
render() { render() {
return ( return (

View File

@ -11,7 +11,7 @@ import React from "react";
import { Button } from "../button"; import { Button } from "../button";
import { saveKubeconfig } from "./save-config"; import { saveKubeconfig } from "./save-config";
import { Notifications } from "../notifications"; import { Notifications } from "../notifications";
import { boundMethod } from "autobind-decorator"; import { autoBind } from "../../../common/utils";
import { Dialog } from "../dialog"; import { Dialog } from "../dialog";
import { Icon } from "../icon"; import { Icon } from "../icon";
import { Select } from "../select"; import { Select } from "../select";
@ -36,9 +36,9 @@ class NonInjectedDeleteClusterDialog extends React.Component<Dependencies> {
constructor(props: Dependencies) { constructor(props: Dependencies) {
super(props); super(props);
makeObservable(this); makeObservable(this);
autoBind(this);
} }
@boundMethod
onOpen() { onOpen() {
this.newCurrentContext = ""; this.newCurrentContext = "";
@ -47,7 +47,6 @@ class NonInjectedDeleteClusterDialog extends React.Component<Dependencies> {
} }
} }
@boundMethod
onClose() { onClose() {
this.props.model.close(); this.props.model.close();
this.showContextSwitch = false; this.showContextSwitch = false;
@ -65,7 +64,6 @@ class NonInjectedDeleteClusterDialog extends React.Component<Dependencies> {
} }
} }
@boundMethod
async onDelete() { async onDelete() {
const { cluster, config } = this.props.model; const { cluster, config } = this.props.model;

View File

@ -7,7 +7,7 @@ import styles from "./dock-tab.module.scss";
import React from "react"; import React from "react";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import { boundMethod, cssNames, prevDefault, isMiddleClick } from "../../utils"; import { autoBind, cssNames, prevDefault, isMiddleClick } from "../../utils";
import type { DockStore, DockTab as DockTabModel } from "./dock/store"; import type { DockStore, DockTab as DockTabModel } from "./dock/store";
import type { TabProps } from "../tabs"; import type { TabProps } from "../tabs";
import { Tab } from "../tabs"; import { Tab } from "../tabs";
@ -34,13 +34,13 @@ class NonInjectedDockTab extends React.Component<DockTabProps & Dependencies> {
constructor(props: DockTabProps & Dependencies) { constructor(props: DockTabProps & Dependencies) {
super(props); super(props);
makeObservable(this); makeObservable(this);
autoBind(this);
} }
get tabId() { get tabId() {
return this.props.value.id; return this.props.value.id;
} }
@boundMethod
close() { close() {
this.props.dockStore.closeTab(this.tabId); this.props.dockStore.closeTab(this.tabId);
} }

View File

@ -15,7 +15,7 @@ import moment from "moment-timezone";
import type { Align, ListOnScrollProps } from "react-window"; import type { Align, ListOnScrollProps } from "react-window";
import { SearchStore } from "../../../search-store/search-store"; import { SearchStore } from "../../../search-store/search-store";
import { UserStore } from "../../../../common/user-store"; import { UserStore } from "../../../../common/user-store";
import { array, boundMethod, cssNames } from "../../../utils"; import { array, autoBind, cssNames } from "../../../utils";
import { VirtualList } from "../../virtual-list"; import { VirtualList } from "../../virtual-list";
import { ToBottom } from "./to-bottom"; import { ToBottom } from "./to-bottom";
import type { LogTabViewModel } from "../logs/logs-view-model"; import type { LogTabViewModel } from "../logs/logs-view-model";
@ -39,6 +39,7 @@ export class LogList extends React.Component<LogListProps> {
constructor(props: LogListProps) { constructor(props: LogListProps) {
super(props); super(props);
makeObservable(this); makeObservable(this);
autoBind(this);
} }
componentDidMount() { componentDidMount() {
@ -51,14 +52,12 @@ export class LogList extends React.Component<LogListProps> {
]); ]);
} }
@boundMethod
onLogsInitialLoad(logs: string[], prevLogs: string[]) { onLogsInitialLoad(logs: string[], prevLogs: string[]) {
if (!prevLogs.length && logs.length) { if (!prevLogs.length && logs.length) {
this.isLastLineVisible = true; this.isLastLineVisible = true;
} }
} }
@boundMethod
onLogsUpdate() { onLogsUpdate() {
if (this.isLastLineVisible) { if (this.isLastLineVisible) {
setTimeout(() => { setTimeout(() => {
@ -67,7 +66,6 @@ export class LogList extends React.Component<LogListProps> {
} }
} }
@boundMethod
onUserScrolledUp(logs: string[], prevLogs: string[]) { onUserScrolledUp(logs: string[], prevLogs: string[]) {
if (!this.virtualListDiv.current) return; if (!this.virtualListDiv.current) return;

View File

@ -5,8 +5,8 @@
import "./terminal-dock-tab.scss"; import "./terminal-dock-tab.scss";
import React from "react"; import React from "react";
import { observer } from "mobx-react"; import { disposeOnUnmount, observer } from "mobx-react";
import { boundMethod, cssNames } from "../../../utils"; import { autoBind, cssNames } from "../../../utils";
import type { DockTabProps } from "../dock-tab"; import type { DockTabProps } from "../dock-tab";
import { DockTab } from "../dock-tab"; import { DockTab } from "../dock-tab";
import { Icon } from "../../icon"; import { Icon } from "../../icon";
@ -26,11 +26,18 @@ interface Dependencies {
} }
@observer @observer
class NonInjectedTerminalTab extends React.Component<TerminalTabProps & Dependencies> { class NonInjectedTerminalTab<Props extends TerminalTabProps & Dependencies> extends React.Component<Props> {
constructor(props: Props) {
super(props);
autoBind(this);
}
componentDidMount() { componentDidMount() {
reaction(() => this.isDisconnected === true, () => { disposeOnUnmount(this, [
this.props.dockStore.closeTab(this.tabId); reaction(() => this.isDisconnected === true, () => {
}); this.props.dockStore.closeTab(this.tabId);
}),
]);
} }
get tabId() { get tabId() {
@ -41,7 +48,6 @@ class NonInjectedTerminalTab extends React.Component<TerminalTabProps & Dependen
return this.props.terminalStore.isDisconnected(this.tabId); return this.props.terminalStore.isDisconnected(this.tabId);
} }
@boundMethod
reconnect() { reconnect() {
this.props.terminalStore.reconnect(this.tabId); this.props.terminalStore.reconnect(this.tabId);
} }

View File

@ -11,7 +11,7 @@ import React from "react";
import { Icon } from "../icon"; import { Icon } from "../icon";
import type { InputProps, InputValidator } from "../input"; import type { InputProps, InputValidator } from "../input";
import { Input } from "../input"; import { Input } from "../input";
import { boundMethod } from "../../utils"; import { autoBind } from "../../utils";
export interface EditableListProps<T> { export interface EditableListProps<T> {
items: T[]; items: T[];
@ -36,7 +36,11 @@ const defaultProps: Partial<EditableListProps<any>> = {
export class EditableList<T> extends React.Component<EditableListProps<T>> { export class EditableList<T> extends React.Component<EditableListProps<T>> {
static defaultProps = defaultProps as EditableListProps<any>; static defaultProps = defaultProps as EditableListProps<any>;
@boundMethod constructor(props: EditableListProps<T>) {
super(props);
autoBind(this);
}
onSubmit(val: string, evt: React.KeyboardEvent) { onSubmit(val: string, evt: React.KeyboardEvent) {
if (val) { if (val) {
evt.preventDefault(); evt.preventDefault();

View File

@ -9,7 +9,7 @@ import type { ReactNode } from "react";
import React, { createRef } from "react"; import React, { createRef } from "react";
import { NavLink } from "react-router-dom"; import { NavLink } from "react-router-dom";
import type { LocationDescriptor } from "history"; import type { LocationDescriptor } from "history";
import { boundMethod, cssNames } from "../../utils"; import { autoBind, cssNames } from "../../utils";
import type { TooltipDecoratorProps } from "../tooltip"; import type { TooltipDecoratorProps } from "../tooltip";
import { withTooltip } from "../tooltip"; import { withTooltip } from "../tooltip";
import isNumber from "lodash/isNumber"; import isNumber from "lodash/isNumber";
@ -43,13 +43,17 @@ export class Icon extends React.PureComponent<IconProps> {
return String(content).includes("svg+xml"); // data-url for raw svg-icon return String(content).includes("svg+xml"); // data-url for raw svg-icon
} }
constructor(props: IconProps) {
super(props);
autoBind(this);
}
get isInteractive() { get isInteractive() {
const { interactive, onClick, href, link } = this.props; const { interactive, onClick, href, link } = this.props;
return interactive ?? !!(onClick || href || link); return interactive ?? !!(onClick || href || link);
} }
@boundMethod
onClick(evt: React.MouseEvent) { onClick(evt: React.MouseEvent) {
if (this.props.disabled) { if (this.props.disabled) {
return; return;
@ -60,7 +64,6 @@ export class Icon extends React.PureComponent<IconProps> {
} }
} }
@boundMethod
onKeyDown(evt: React.KeyboardEvent<any>) { onKeyDown(evt: React.KeyboardEvent<any>) {
switch (evt.nativeEvent.code) { switch (evt.nativeEvent.code) {
case "Space": case "Space":

View File

@ -6,7 +6,7 @@
import "./drop-file-input.scss"; import "./drop-file-input.scss";
import React from "react"; import React from "react";
import type { IClassName } from "../../utils"; import type { IClassName } from "../../utils";
import { boundMethod, cssNames } from "../../utils"; import { autoBind, cssNames } from "../../utils";
import { observable, makeObservable } from "mobx"; import { observable, makeObservable } from "mobx";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import logger from "../../../main/logger"; import logger from "../../../main/logger";
@ -29,15 +29,14 @@ export class DropFileInput<T extends HTMLElement = any> extends React.Component<
constructor(props: DropFileInputProps) { constructor(props: DropFileInputProps) {
super(props); super(props);
makeObservable(this); makeObservable(this);
autoBind(this);
} }
@boundMethod
onDragEnter() { onDragEnter() {
this.dragCounter++; this.dragCounter++;
this.dropAreaActive = true; this.dropAreaActive = true;
} }
@boundMethod
onDragLeave() { onDragLeave() {
this.dragCounter--; this.dragCounter--;
@ -46,7 +45,6 @@ export class DropFileInput<T extends HTMLElement = any> extends React.Component<
} }
} }
@boundMethod
onDragOver(evt: React.DragEvent<T>) { onDragOver(evt: React.DragEvent<T>) {
if (this.props.onDragOver) { if (this.props.onDragOver) {
this.props.onDragOver(evt); this.props.onDragOver(evt);
@ -55,7 +53,6 @@ export class DropFileInput<T extends HTMLElement = any> extends React.Component<
evt.dataTransfer.dropEffect = "move"; evt.dataTransfer.dropEffect = "move";
} }
@boundMethod
onDrop(evt: React.DragEvent<T>) { onDrop(evt: React.DragEvent<T>) {
if (this.props.onDrop) { if (this.props.onDrop) {
this.props.onDrop(evt); this.props.onDrop(evt);

View File

@ -7,7 +7,7 @@ import "./input.scss";
import type { DOMAttributes, InputHTMLAttributes, TextareaHTMLAttributes } from "react"; import type { DOMAttributes, InputHTMLAttributes, TextareaHTMLAttributes } from "react";
import React from "react"; import React from "react";
import { boundMethod, cssNames, debouncePromise, getRandId } from "../../utils"; import { autoBind, cssNames, debouncePromise, getRandId } from "../../utils";
import { Icon } from "../icon"; import { Icon } from "../icon";
import type { TooltipProps } from "../tooltip"; import type { TooltipProps } from "../tooltip";
import { Tooltip } from "../tooltip"; import { Tooltip } from "../tooltip";
@ -91,6 +91,11 @@ export class Input extends React.Component<InputProps, State> {
submitted: false, submitted: false,
}; };
constructor(props: InputProps) {
super(props);
autoBind(this);
}
componentWillUnmount(): void { componentWillUnmount(): void {
this.setDirtyOnChange.cancel(); this.setDirtyOnChange.cancel();
} }
@ -220,7 +225,6 @@ export class Input extends React.Component<InputProps, State> {
this.setState({ dirty }); this.setState({ dirty });
} }
@boundMethod
onFocus(evt: React.FocusEvent<InputElement>) { onFocus(evt: React.FocusEvent<InputElement>) {
const { onFocus, autoSelectOnFocus } = this.props; const { onFocus, autoSelectOnFocus } = this.props;
@ -229,7 +233,6 @@ export class Input extends React.Component<InputProps, State> {
this.setState({ focused: true }); this.setState({ focused: true });
} }
@boundMethod
onBlur(evt: React.FocusEvent<InputElement>) { onBlur(evt: React.FocusEvent<InputElement>) {
this.props.onBlur?.(evt); this.props.onBlur?.(evt);
this.setState({ focused: false }); this.setState({ focused: false });
@ -237,7 +240,6 @@ export class Input extends React.Component<InputProps, State> {
setDirtyOnChange = debounce(() => this.setDirty(), 500); setDirtyOnChange = debounce(() => this.setDirty(), 500);
@boundMethod
onChange(evt: React.ChangeEvent<any>) { onChange(evt: React.ChangeEvent<any>) {
this.props.onChange?.(evt.currentTarget.value, evt); this.props.onChange?.(evt.currentTarget.value, evt);
this.validate(); this.validate();
@ -251,7 +253,6 @@ export class Input extends React.Component<InputProps, State> {
} }
} }
@boundMethod
onKeyDown(evt: React.KeyboardEvent<InputElement>) { onKeyDown(evt: React.KeyboardEvent<InputElement>) {
this.props.onKeyDown?.(evt); this.props.onKeyDown?.(evt);
@ -329,7 +330,6 @@ export class Input extends React.Component<InputProps, State> {
}; };
} }
@boundMethod
bindRef(elem: InputElement) { bindRef(elem: InputElement) {
this.input = elem; this.input = elem;
} }

View File

@ -7,7 +7,7 @@ import "./search-input.scss";
import React, { createRef } from "react"; import React, { createRef } from "react";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import { boundMethod, cssNames } from "../../utils"; import { cssNames, autoBind } from "../../utils";
import { Icon } from "../icon"; import { Icon } from "../icon";
import type { InputProps } from "./input"; import type { InputProps } from "./input";
import { Input } from "./input"; import { Input } from "./input";
@ -33,6 +33,11 @@ export class SearchInput extends React.Component<SearchInputProps> {
private inputRef = createRef<Input>(); private inputRef = createRef<Input>();
constructor(props: SearchInputProps) {
super(props);
autoBind(this);
}
componentDidMount() { componentDidMount() {
if (!this.props.bindGlobalFocusHotkey) return; if (!this.props.bindGlobalFocusHotkey) return;
window.addEventListener("keydown", this.onGlobalKey); window.addEventListener("keydown", this.onGlobalKey);
@ -42,14 +47,12 @@ export class SearchInput extends React.Component<SearchInputProps> {
window.removeEventListener("keydown", this.onGlobalKey); window.removeEventListener("keydown", this.onGlobalKey);
} }
@boundMethod
onGlobalKey(evt: KeyboardEvent) { onGlobalKey(evt: KeyboardEvent) {
if (evt.key === "f" && (isMac ? evt.metaKey : evt.ctrlKey)) { if (evt.key === "f" && (isMac ? evt.metaKey : evt.ctrlKey)) {
this.inputRef.current.focus(); this.inputRef.current.focus();
} }
} }
@boundMethod
onKeyDown(evt: React.KeyboardEvent<any>) { onKeyDown(evt: React.KeyboardEvent<any>) {
this.props.onKeyDown?.(evt); this.props.onKeyDown?.(evt);
@ -59,7 +62,6 @@ export class SearchInput extends React.Component<SearchInputProps> {
} }
} }
@boundMethod
clear() { clear() {
if (this.props.onClear) { if (this.props.onClear) {
this.props.onClear(); this.props.onClear();

View File

@ -14,7 +14,7 @@ import { ConfirmDialog } from "../confirm-dialog";
import type { TableCellProps, TableProps, TableRowProps, TableSortCallbacks } from "../table"; import type { TableCellProps, TableProps, TableRowProps, TableSortCallbacks } from "../table";
import { Table, TableCell, TableHead, TableRow } from "../table"; import { Table, TableCell, TableHead, TableRow } from "../table";
import type { IClassName } from "../../utils"; import type { IClassName } from "../../utils";
import { boundMethod, cssNames, isReactNode, prevDefault, stopPropagation } from "../../utils"; import { autoBind, cssNames, isReactNode, prevDefault, stopPropagation } from "../../utils";
import type { AddRemoveButtonsProps } from "../add-remove-buttons"; import type { AddRemoveButtonsProps } from "../add-remove-buttons";
import { AddRemoveButtons } from "../add-remove-buttons"; import { AddRemoveButtons } from "../add-remove-buttons";
import { NoItems } from "../no-items"; import { NoItems } from "../no-items";
@ -68,13 +68,13 @@ export class ItemListLayoutContent<I extends ItemObject> extends React.Component
constructor(props: ItemListLayoutContentProps<I>) { constructor(props: ItemListLayoutContentProps<I>) {
super(props); super(props);
makeObservable(this); makeObservable(this);
autoBind(this);
} }
@computed get failedToLoad() { @computed get failedToLoad() {
return this.props.store.failedLoading; return this.props.store.failedLoading;
} }
@boundMethod
renderRow(item: I) { renderRow(item: I) {
return this.getTableRow(item); return this.getTableRow(item);
} }
@ -133,7 +133,6 @@ export class ItemListLayoutContent<I extends ItemObject> extends React.Component
); );
} }
@boundMethod
getRow(uid: string) { getRow(uid: string) {
return ( return (
<div key={uid}> <div key={uid}>
@ -150,7 +149,6 @@ export class ItemListLayoutContent<I extends ItemObject> extends React.Component
); );
} }
@boundMethod
removeItemsDialog(selectedItems: I[]) { removeItemsDialog(selectedItems: I[]) {
const { customizeRemoveDialog, store } = this.props; const { customizeRemoveDialog, store } = this.props;
const visibleMaxNamesCount = 5; const visibleMaxNamesCount = 5;

View File

@ -11,7 +11,7 @@ import { computed, makeObservable, untracked } from "mobx";
import type { ConfirmDialogParams } from "../confirm-dialog"; import type { ConfirmDialogParams } from "../confirm-dialog";
import type { TableCellProps, TableProps, TableRowProps, TableSortCallbacks } from "../table"; import type { TableCellProps, TableProps, TableRowProps, TableSortCallbacks } from "../table";
import type { IClassName, StorageHelper } from "../../utils"; import type { IClassName, StorageHelper } from "../../utils";
import { boundMethod, cssNames, noop } from "../../utils"; import { autoBind, cssNames, noop } from "../../utils";
import type { AddRemoveButtonsProps } from "../add-remove-buttons"; import type { AddRemoveButtonsProps } from "../add-remove-buttons";
import type { ItemObject, ItemStore } from "../../../common/item.store"; import type { ItemObject, ItemStore } from "../../../common/item.store";
import type { SearchInputUrlProps } from "../input"; import type { SearchInputUrlProps } from "../input";
@ -120,6 +120,7 @@ class NonInjectedItemListLayout<I extends ItemObject> extends React.Component<It
constructor(props: ItemListLayoutProps<I> & Dependencies) { constructor(props: ItemListLayoutProps<I> & Dependencies) {
super(props); super(props);
makeObservable(this); makeObservable(this);
autoBind(this);
} }
async componentDidMount() { async componentDidMount() {
@ -160,7 +161,6 @@ class NonInjectedItemListLayout<I extends ItemObject> extends React.Component<It
return activeFilters; return activeFilters;
} }
@boundMethod
toggleFilters() { toggleFilters() {
this.showFilters = !this.showFilters; this.showFilters = !this.showFilters;
} }

View File

@ -4,7 +4,7 @@
*/ */
import React from "react"; import React from "react";
import { boundMethod, cssNames } from "../../utils"; import { autoBind, cssNames } from "../../utils";
import type { KubeObject } from "../../../common/k8s-api/kube-object"; import type { KubeObject } from "../../../common/k8s-api/kube-object";
import type { MenuActionsProps } from "../menu"; import type { MenuActionsProps } from "../menu";
import { MenuActions } from "../menu"; import { MenuActions } from "../menu";
@ -31,7 +31,11 @@ interface Dependencies {
createEditResourceTab: (kubeObject: KubeObject) => void; createEditResourceTab: (kubeObject: KubeObject) => void;
} }
class NonInjectedKubeObjectMenu<TKubeObject extends KubeObject> extends React.Component<KubeObjectMenuProps<TKubeObject> & Dependencies> { class NonInjectedKubeObjectMenu<TKubeObject extends KubeObject, Props extends KubeObjectMenuProps<TKubeObject> & Dependencies> extends React.Component<Props> {
constructor(props: Props) {
super(props);
autoBind(this);
}
get store() { get store() {
const { object } = this.props; const { object } = this.props;
@ -49,13 +53,11 @@ class NonInjectedKubeObjectMenu<TKubeObject extends KubeObject> extends React.Co
return this.props.removable ?? Boolean(this.store?.remove); return this.props.removable ?? Boolean(this.store?.remove);
} }
@boundMethod
async update() { async update() {
this.props.hideDetails(); this.props.hideDetails();
this.props.createEditResourceTab(this.props.object); this.props.createEditResourceTab(this.props.object);
} }
@boundMethod
async remove() { async remove() {
this.props.hideDetails(); this.props.hideDetails();
const { object, removeAction } = this.props; const { object, removeAction } = this.props;
@ -64,7 +66,6 @@ class NonInjectedKubeObjectMenu<TKubeObject extends KubeObject> extends React.Co
else await this.store.remove(object); else await this.store.remove(object);
} }
@boundMethod
renderRemoveMessage() { renderRemoveMessage() {
const { object } = this.props; const { object } = this.props;

View File

@ -8,7 +8,7 @@ import "./menu-actions.scss";
import React, { isValidElement } from "react"; import React, { isValidElement } from "react";
import { observable, makeObservable } from "mobx"; import { observable, makeObservable } from "mobx";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import { boundMethod, cssNames } from "../../utils"; import { autoBind, cssNames } from "../../utils";
import { ConfirmDialog } from "../confirm-dialog"; import { ConfirmDialog } from "../confirm-dialog";
import type { IconProps } from "../icon"; import type { IconProps } from "../icon";
import { Icon } from "../icon"; import { Icon } from "../icon";
@ -48,9 +48,9 @@ export class MenuActions extends React.Component<MenuActionsProps> {
constructor(props: MenuActionsProps) { constructor(props: MenuActionsProps) {
super(props); super(props);
makeObservable(this); makeObservable(this);
autoBind(this);
} }
@boundMethod
remove() { remove() {
const { removeAction } = this.props; const { removeAction } = this.props;
let { removeConfirmationMessage } = this.props; let { removeConfirmationMessage } = this.props;

View File

@ -6,7 +6,6 @@
import React from "react"; import React from "react";
import { makeObservable, observable } from "mobx"; import { makeObservable, observable } from "mobx";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import { boundMethod } from "../../utils";
export interface RenderDelayProps { export interface RenderDelayProps {
placeholder?: React.ReactNode; placeholder?: React.ReactNode;
@ -32,10 +31,7 @@ export class RenderDelay extends React.Component<RenderDelayProps> {
window.cancelIdleCallback(this.showContents); window.cancelIdleCallback(this.showContents);
} }
@boundMethod showContents = () => this.isVisible = true;
showContents() {
this.isVisible = true;
}
render() { render() {
if (!this.isVisible) { if (!this.isVisible) {

View File

@ -17,7 +17,7 @@ import type { ActionMeta, OptionTypeBase, Props as ReactSelectProps, Styles } fr
import type { CreatableProps } from "react-select/creatable"; import type { CreatableProps } from "react-select/creatable";
import { ThemeStore } from "../../theme.store"; import { ThemeStore } from "../../theme.store";
import { boundMethod, cssNames } from "../../utils"; import { autoBind, cssNames } from "../../utils";
const { Menu } = components; const { Menu } = components;
@ -52,6 +52,7 @@ export class Select extends React.Component<SelectProps> {
constructor(props: SelectProps) { constructor(props: SelectProps) {
super(props); super(props);
makeObservable(this); makeObservable(this);
autoBind(this);
} }
@computed get themeClass() { @computed get themeClass() {
@ -97,14 +98,12 @@ export class Select extends React.Component<SelectProps> {
return options as SelectOption[]; return options as SelectOption[];
} }
@boundMethod
onChange(value: SelectOption, meta: ActionMeta<any>) { onChange(value: SelectOption, meta: ActionMeta<any>) {
if (this.props.onChange) { if (this.props.onChange) {
this.props.onChange(value, meta); this.props.onChange(value, meta);
} }
} }
@boundMethod
onKeyDown(evt: React.KeyboardEvent<HTMLElement>) { onKeyDown(evt: React.KeyboardEvent<HTMLElement>) {
if (this.props.onKeyDown) { if (this.props.onKeyDown) {
this.props.onKeyDown(evt); this.props.onKeyDown(evt);

View File

@ -8,7 +8,7 @@ import type { TableSortBy, TableSortParams } from "./table";
import type { ReactNode } from "react"; import type { ReactNode } from "react";
import React from "react"; import React from "react";
import { boundMethod, cssNames, displayBooleans } from "../../utils"; import { autoBind, cssNames, displayBooleans } from "../../utils";
import { Icon } from "../icon"; import { Icon } from "../icon";
import { Checkbox } from "../checkbox"; import { Checkbox } from "../checkbox";
@ -78,7 +78,11 @@ export interface TableCellProps extends React.DOMAttributes<HTMLDivElement> {
} }
export class TableCell extends React.Component<TableCellProps> { export class TableCell extends React.Component<TableCellProps> {
@boundMethod constructor(props: TableCellProps) {
super(props);
autoBind(this);
}
onClick(evt: React.MouseEvent<HTMLDivElement>) { onClick(evt: React.MouseEvent<HTMLDivElement>) {
if (this.props.onClick) { if (this.props.onClick) {
this.props.onClick(evt); this.props.onClick(evt);

View File

@ -7,7 +7,7 @@ import "./table.scss";
import React from "react"; import React from "react";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import { boundMethod, cssNames } from "../../utils"; import { autoBind, cssNames } from "../../utils";
import type { TableRowElem, TableRowProps } from "./table-row"; import type { TableRowElem, TableRowProps } from "./table-row";
import { TableRow } from "./table-row"; import { TableRow } from "./table-row";
import type { TableHeadElem, TableHeadProps } from "./table-head"; import type { TableHeadElem, TableHeadProps } from "./table-head";
@ -99,6 +99,7 @@ class NonInjectedTable<Item> extends React.Component<TableProps<Item> & Dependen
constructor(props: TableProps<Item> & Dependencies) { constructor(props: TableProps<Item> & Dependencies) {
super(props); super(props);
makeObservable(this); makeObservable(this);
autoBind(this);
} }
componentDidMount() { componentDidMount() {
@ -173,7 +174,6 @@ class NonInjectedTable<Item> extends React.Component<TableProps<Item> & Dependen
onSort?.({ sortBy, orderBy }); onSort?.({ sortBy, orderBy });
} }
@boundMethod
sort(colName: TableSortBy) { sort(colName: TableSortBy) {
const { sortBy, orderBy } = this.sortParams; const { sortBy, orderBy } = this.sortParams;
const sameColumn = sortBy == colName; const sameColumn = sortBy == colName;

View File

@ -6,7 +6,7 @@
import "./tabs.scss"; import "./tabs.scss";
import type { DOMAttributes } from "react"; import type { DOMAttributes } from "react";
import React from "react"; import React from "react";
import { boundMethod, cssNames } from "../../utils"; import { autoBind, cssNames } from "../../utils";
import { Icon } from "../icon"; import { Icon } from "../icon";
const TabsContext = React.createContext<TabsContextValue>({}); const TabsContext = React.createContext<TabsContextValue>({});
@ -28,10 +28,7 @@ export interface TabsProps<D = any> extends TabsContextValue<D>, Omit<DOMAttribu
export class Tabs extends React.PureComponent<TabsProps> { export class Tabs extends React.PureComponent<TabsProps> {
public elem: HTMLElement; public elem: HTMLElement;
@boundMethod bindRef = (elem: HTMLElement) => this.elem = elem;
protected bindRef(elem: HTMLElement) {
this.elem = elem;
}
render() { render() {
const { center, wrap, onChange, value, autoFocus, scrollable = true, withBorder, ...elemProps } = this.props; const { center, wrap, onChange, value, autoFocus, scrollable = true, withBorder, ...elemProps } = this.props;
@ -69,6 +66,11 @@ export class Tab extends React.PureComponent<TabProps> {
declare context: TabsContextValue; declare context: TabsContextValue;
public ref = React.createRef<HTMLDivElement>(); public ref = React.createRef<HTMLDivElement>();
constructor(props: TabProps) {
super(props);
autoBind(this);
}
get isActive() { get isActive() {
const { active, value } = this.props; const { active, value } = this.props;
@ -84,7 +86,6 @@ export class Tab extends React.PureComponent<TabProps> {
this.ref.current?.scrollIntoViewIfNeeded?.(); this.ref.current?.scrollIntoViewIfNeeded?.();
} }
@boundMethod
onClick(evt: React.MouseEvent<HTMLElement>) { onClick(evt: React.MouseEvent<HTMLElement>) {
const { value, active, disabled, onClick } = this.props; const { value, active, disabled, onClick } = this.props;
@ -96,13 +97,11 @@ export class Tab extends React.PureComponent<TabProps> {
this.context.onChange?.(value); this.context.onChange?.(value);
} }
@boundMethod
onFocus(evt: React.FocusEvent<HTMLElement>) { onFocus(evt: React.FocusEvent<HTMLElement>) {
this.props.onFocus?.(evt); this.props.onFocus?.(evt);
this.scrollIntoView(); this.scrollIntoView();
} }
@boundMethod
onKeyDown(evt: React.KeyboardEvent<HTMLElement>) { onKeyDown(evt: React.KeyboardEvent<HTMLElement>) {
if (evt.key === " " || evt.key === "Enter") { if (evt.key === " " || evt.key === "Enter") {
this.ref.current?.click(); this.ref.current?.click();

View File

@ -9,7 +9,7 @@ import React from "react";
import { createPortal } from "react-dom"; import { createPortal } from "react-dom";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import type { IClassName } from "../../utils"; import type { IClassName } from "../../utils";
import { boundMethod, cssNames } from "../../utils"; import { cssNames, autoBind } from "../../utils";
import { observable, makeObservable, action } from "mobx"; import { observable, makeObservable, action } from "mobx";
export enum TooltipPosition { export enum TooltipPosition {
@ -61,6 +61,7 @@ export class Tooltip extends React.Component<TooltipProps> {
constructor(props: TooltipProps) { constructor(props: TooltipProps) {
super(props); super(props);
makeObservable(this); makeObservable(this);
autoBind(this);
} }
get targetElem(): HTMLElement { get targetElem(): HTMLElement {
@ -89,19 +90,18 @@ export class Tooltip extends React.Component<TooltipProps> {
this.hoverTarget.removeEventListener("mouseleave", this.onLeaveTarget); this.hoverTarget.removeEventListener("mouseleave", this.onLeaveTarget);
} }
@action.bound @action
protected onEnterTarget() { protected onEnterTarget() {
this.isVisible = true; this.isVisible = true;
requestAnimationFrame(action(() => this.isContentVisible = true)); requestAnimationFrame(action(() => this.isContentVisible = true));
} }
@action.bound @action
protected onLeaveTarget() { protected onLeaveTarget() {
this.isVisible = false; this.isVisible = false;
this.isContentVisible = false; this.isContentVisible = false;
} }
@boundMethod
refreshPosition() { refreshPosition() {
const { preferredPositions } = this.props; const { preferredPositions } = this.props;
const { elem, targetElem } = this; const { elem, targetElem } = this;
@ -219,7 +219,6 @@ export class Tooltip extends React.Component<TooltipProps> {
}; };
} }
@boundMethod
bindRef(elem: HTMLElement) { bindRef(elem: HTMLElement) {
this.elem = elem; this.elem = elem;
} }

View File

@ -4,7 +4,7 @@
*/ */
import { action, computed, observable, makeObservable } from "mobx"; import { action, computed, observable, makeObservable } from "mobx";
import { boundMethod } from "../utils"; import autoBind from "auto-bind";
export class SearchStore { export class SearchStore {
/** /**
@ -15,6 +15,11 @@ export class SearchStore {
return value ? value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") : ""; return value ? value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") : "";
} }
constructor() {
makeObservable(this);
autoBind(this);
}
/** /**
* Text in the search input * Text in the search input
* *
@ -36,10 +41,6 @@ export class SearchStore {
*/ */
@observable activeOverlayIndex = -1; @observable activeOverlayIndex = -1;
constructor() {
makeObservable(this);
}
/** /**
* Sets default activeOverlayIndex * Sets default activeOverlayIndex
* @param text An array of any textual data (logs, for example) * @param text An array of any textual data (logs, for example)
@ -109,12 +110,10 @@ export class SearchStore {
return prev; return prev;
} }
@boundMethod
public setNextOverlayActive(): void { public setNextOverlayActive(): void {
this.activeOverlayIndex = this.getNextOverlay(true); this.activeOverlayIndex = this.getNextOverlay(true);
} }
@boundMethod
public setPrevOverlayActive(): void { public setPrevOverlayActive(): void {
this.activeOverlayIndex = this.getPrevOverlay(true); this.activeOverlayIndex = this.getPrevOverlay(true);
} }
@ -140,7 +139,6 @@ export class SearchStore {
* @param line Index of the line where overlay is located * @param line Index of the line where overlay is located
* @param occurrence Number of the overlay within one line * @param occurrence Number of the overlay within one line
*/ */
@boundMethod
public isActiveOverlay(line: number, occurrence: number): boolean { public isActiveOverlay(line: number, occurrence: number): boolean {
const firstLineIndex = this.occurrences.findIndex(item => item === line); const firstLineIndex = this.occurrences.findIndex(item => item === line);

View File

@ -2913,11 +2913,6 @@ auto-bind@^4.0.0:
resolved "https://registry.yarnpkg.com/auto-bind/-/auto-bind-4.0.0.tgz#e3589fc6c2da8f7ca43ba9f84fa52a744fc997fb" resolved "https://registry.yarnpkg.com/auto-bind/-/auto-bind-4.0.0.tgz#e3589fc6c2da8f7ca43ba9f84fa52a744fc997fb"
integrity sha512-Hdw8qdNiqdJ8LqT0iK0sVzkFbzg6fhnQqqfWhBDxcHZvU75+B+ayzTy8x+k5Ix0Y92XOhOUlx74ps+bA6BeYMQ== integrity sha512-Hdw8qdNiqdJ8LqT0iK0sVzkFbzg6fhnQqqfWhBDxcHZvU75+B+ayzTy8x+k5Ix0Y92XOhOUlx74ps+bA6BeYMQ==
autobind-decorator@^2.4.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/autobind-decorator/-/autobind-decorator-2.4.0.tgz#ea9e1c98708cf3b5b356f7cf9f10f265ff18239c"
integrity sha512-OGYhWUO72V6DafbF8PM8rm3EPbfuyMZcJhtm5/n26IDwO18pohE4eNazLoCGhPiXOCD0gEGmrbU3849QvM8bbw==
await-lock@^2.1.0: await-lock@^2.1.0:
version "2.1.0" version "2.1.0"
resolved "https://registry.yarnpkg.com/await-lock/-/await-lock-2.1.0.tgz#bc78c51d229a34d5d90965a1c94770e772c6145e" resolved "https://registry.yarnpkg.com/await-lock/-/await-lock-2.1.0.tgz#bc78c51d229a34d5d90965a1c94770e772c6145e"