1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Reverted "use {useDefineForClassFields: true} in tsconfig.json" (various app-crash fixes)

This flag seems to be not possible to use with class-inheritance in some cases.

Example / demo:
`KubeObject` class has initial type definitions for the fields like: "metadata", "kind", etc.
and constructor() has Object.assign(this, data);
Meanwhile child class, e.g. KubeEvent inherited from KubeObject and has it's own extra type definitions for underlying resource, e.g. "involvedObject", "source", etc.

So calling super(data) doesn't work as expected for child class as it's own type definitions overwrites data from parent's constructor with `undefined` at later point.

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2021-05-12 16:32:18 +03:00
parent 0c83513e51
commit df686a64b9
27 changed files with 44 additions and 52 deletions

View File

@ -54,7 +54,7 @@ export class Cluster extends KubeObject {
static kind = "Cluster";
static apiBase = "/apis/cluster.k8s.io/v1alpha1/clusters";
declare spec: {
spec: {
clusterNetwork?: {
serviceDomain?: string;
pods?: {
@ -70,7 +70,7 @@ export class Cluster extends KubeObject {
};
};
};
declare status?: {
status?: {
apiEndpoints: {
host: string;
port: string;

View File

@ -22,7 +22,7 @@ export class CustomResourceDefinition extends KubeObject {
static namespaced = false;
static apiBase = "/apis/apiextensions.k8s.io/v1/customresourcedefinitions";
declare spec: {
spec: {
group: string;
version?: string; // deprecated in v1 api
names: {
@ -46,7 +46,7 @@ export class CustomResourceDefinition extends KubeObject {
};
additionalPrinterColumns?: AdditionalPrinterColumnsV1Beta[]; // removed in v1
};
declare status: {
status: {
conditions: {
lastTransitionTime: string;
message: string;

View File

@ -48,7 +48,7 @@ export class CronJob extends KubeObject {
autoBind(this);
}
declare spec: {
spec: {
schedule: string;
concurrencyPolicy: string;
suspend: boolean;
@ -81,7 +81,7 @@ export class CronJob extends KubeObject {
successfulJobsHistoryLimit: number;
failedJobsHistoryLimit: number;
};
declare status: {
status: {
lastScheduleTime?: string;
};

View File

@ -15,7 +15,7 @@ export class DaemonSet extends WorkloadKubeObject {
autoBind(this);
}
declare spec: {
spec: {
selector: {
matchLabels: {
[name: string]: string;
@ -57,7 +57,7 @@ export class DaemonSet extends WorkloadKubeObject {
};
revisionHistoryLimit: number;
};
declare status: {
status: {
currentNumberScheduled: number;
numberMisscheduled: number;
desiredNumberScheduled: number;

View File

@ -77,7 +77,7 @@ export class Deployment extends WorkloadKubeObject {
autoBind(this);
}
declare spec: {
spec: {
replicas: number;
selector: { matchLabels: { [app: string]: string } };
template: {
@ -156,7 +156,7 @@ export class Deployment extends WorkloadKubeObject {
};
};
};
declare status: {
status: {
observedGeneration: number;
replicas: number;
updatedReplicas: number;

View File

@ -1,21 +1,13 @@
import moment from "moment";
import { KubeObject } from "../kube-object";
import { formatDuration } from "../../utils/formatDuration";
import { autoBind } from "../../utils";
import { KubeApi } from "../kube-api";
import { KubeJsonApiData } from "../kube-json-api";
export class KubeEvent extends KubeObject {
static kind = "Event";
static namespaced = true;
static apiBase = "/api/v1/events";
constructor(data: KubeJsonApiData) {
super(data);
autoBind(this);
Object.assign(this, data); // TODO: figure out why this doesn't work from super()
}
involvedObject: {
kind: string;
namespace: string;

View File

@ -43,7 +43,7 @@ export class HorizontalPodAutoscaler extends KubeObject {
static namespaced = true;
static apiBase = "/apis/autoscaling/v2beta1/horizontalpodautoscalers";
declare spec: {
spec: {
scaleTargetRef: {
kind: string;
name: string;
@ -53,7 +53,7 @@ export class HorizontalPodAutoscaler extends KubeObject {
maxReplicas: number;
metrics: IHpaMetric[];
};
declare status: {
status: {
currentReplicas: number;
desiredReplicas: number;
currentMetrics: IHpaMetric[];

View File

@ -72,7 +72,7 @@ export class Ingress extends KubeObject {
autoBind(this);
}
declare spec: {
spec: {
tls: {
secretName: string;
}[];
@ -96,7 +96,7 @@ export class Ingress extends KubeObject {
}
}
};
declare status: {
status: {
loadBalancer: {
ingress: ILoadBalancerIngress[];
};

View File

@ -16,7 +16,7 @@ export class Job extends WorkloadKubeObject {
autoBind(this);
}
declare spec: {
spec: {
parallelism?: number;
completions?: number;
backoffLimit?: number;
@ -62,7 +62,7 @@ export class Job extends WorkloadKubeObject {
serviceAccount?: string;
schedulerName?: string;
};
declare status: {
status: {
conditions: {
type: string;
status: string;

View File

@ -40,7 +40,7 @@ export class LimitRange extends KubeObject {
autoBind(this);
}
declare spec: {
spec: {
limits: LimitRangeItem[];
};

View File

@ -18,7 +18,7 @@ export class Namespace extends KubeObject {
autoBind(this);
}
declare status?: {
status?: {
phase: string;
};

View File

@ -46,7 +46,7 @@ export class NetworkPolicy extends KubeObject {
autoBind(this);
}
declare spec: {
spec: {
podSelector: {
matchLabels: {
[label: string]: string;

View File

@ -39,7 +39,7 @@ export class Node extends KubeObject {
autoBind(this);
}
declare spec: {
spec: {
podCIDR: string;
externalID: string;
taints?: {
@ -49,7 +49,7 @@ export class Node extends KubeObject {
}[];
unschedulable?: boolean;
};
declare status: {
status: {
capacity: {
cpu: string;
memory: string;

View File

@ -32,7 +32,7 @@ export class PersistentVolumeClaim extends KubeObject {
autoBind(this);
}
declare spec: {
spec: {
accessModes: string[];
storageClassName: string;
selector: {
@ -51,7 +51,7 @@ export class PersistentVolumeClaim extends KubeObject {
};
};
};
declare status: {
status: {
phase: string; // Pending
};

View File

@ -14,7 +14,7 @@ export class PersistentVolume extends KubeObject {
autoBind(this);
}
declare spec: {
spec: {
capacity: {
storage: string; // 8Gi
};
@ -45,7 +45,7 @@ export class PersistentVolume extends KubeObject {
};
};
declare status: {
status: {
phase: string;
reason?: string;
};

View File

@ -13,12 +13,12 @@ export class PodDisruptionBudget extends KubeObject {
autoBind(this);
}
declare spec: {
spec: {
minAvailable: string;
maxUnavailable: string;
selector: { matchLabels: { [app: string]: string } };
};
declare status: {
status: {
currentHealthy: number
desiredHealthy: number
disruptionsAllowed: number

View File

@ -192,7 +192,7 @@ export class Pod extends WorkloadKubeObject {
autoBind(this);
}
declare spec: {
spec: {
volumes?: {
name: string;
persistentVolumeClaim: {
@ -249,7 +249,7 @@ export class Pod extends WorkloadKubeObject {
};
affinity?: IAffinity;
};
declare status?: {
status?: {
phase: string;
conditions: {
type: string;

View File

@ -13,7 +13,7 @@ export class PodSecurityPolicy extends KubeObject {
autoBind(this);
}
declare spec: {
spec: {
allowPrivilegeEscalation?: boolean;
allowedCSIDrivers?: {
name: string;

View File

@ -38,7 +38,7 @@ export class ReplicaSet extends WorkloadKubeObject {
autoBind(this);
}
declare spec: {
spec: {
replicas?: number;
selector: { matchLabels: { [app: string]: string } };
template?: {
@ -51,7 +51,7 @@ export class ReplicaSet extends WorkloadKubeObject {
};
minReadySeconds?: number;
};
declare status: {
status: {
replicas: number;
fullyLabeledReplicas?: number;
readyReplicas?: number;

View File

@ -40,7 +40,7 @@ export class ResourceQuota extends KubeObject {
this.spec = this.spec || {} as any;
}
declare spec: {
spec: {
hard: IResourceQuotaValues;
scopeSelector?: {
matchExpressions: {
@ -51,7 +51,7 @@ export class ResourceQuota extends KubeObject {
};
};
declare status: {
status: {
hard: IResourceQuotaValues;
used: IResourceQuotaValues;
};

View File

@ -25,12 +25,12 @@ export class SelfSubjectRulesReview extends KubeObject {
static namespaced = false;
static apiBase = "/apis/authorization.k8s.io/v1/selfsubjectrulesreviews";
declare spec: {
spec: {
// todo: add more types from api docs
namespace?: string;
};
declare status: {
status: {
resourceRules: ISelfSubjectReviewRule[];
nonResourceRules: ISelfSubjectReviewRule[];
incomplete: boolean;

View File

@ -40,7 +40,7 @@ export class Service extends KubeObject {
autoBind(this);
}
declare spec: {
spec: {
type: string;
clusterIP: string;
externalTrafficPolicy?: string;
@ -51,7 +51,7 @@ export class Service extends KubeObject {
externalIPs?: string[]; // https://kubernetes.io/docs/concepts/services-networking/service/#external-ips
};
declare status: {
status: {
loadBalancer?: {
ingress?: {
ip?: string;

View File

@ -38,7 +38,7 @@ export class StatefulSet extends WorkloadKubeObject {
autoBind(this);
}
declare spec: {
spec: {
serviceName: string;
replicas: number;
selector: {
@ -91,7 +91,7 @@ export class StatefulSet extends WorkloadKubeObject {
};
}[];
};
declare status: {
status: {
observedGeneration: number;
replicas: number;
currentReplicas: number;

View File

@ -145,7 +145,7 @@ export class KubeObject implements ItemObject {
kind: string;
metadata: IKubeObjectMetadata;
status?: any;
spec: any = {};
spec?: any;
get selfLink() {
return this.metadata.selfLink;

View File

@ -326,7 +326,7 @@ export class MenuItem extends React.Component<MenuItemProps> {
static defaultProps = defaultPropsMenuItem as object;
static contextType = MenuContext;
declare context: MenuContextValue;
public context: MenuContextValue;
public elem: HTMLElement;
constructor(props: MenuItemProps) {

View File

@ -62,7 +62,7 @@ export interface TabProps<D = any> extends DOMAttributes<HTMLElement> {
export class Tab extends React.PureComponent<TabProps> {
static contextType = TabsContext;
declare context: TabsContextValue;
public context: TabsContextValue;
public elem: HTMLElement;
get isActive() {

View File

@ -23,7 +23,7 @@
"allowSyntheticDefaultImports": true,
"traceResolution": false,
"resolveJsonModule": true,
"useDefineForClassFields": true,
"useDefineForClassFields": false,
"paths": {
"*": [
"node_modules/*",