Merge branch 'master' into fix-big-cluster-table-freeze

This commit is contained in:
Alex Andreev committed 2022-03-31 10:13:28 +03:00
commit 130bc3e3d9
9 files changed
+102 -71

No files matched your search

+1 -1
View File
@@ -655,7 +655,7 @@ export class KubeApi<T extends KubeObject> {
if (event.type === "ERROR" && event.object.kind === "Status") {
errorReceived = true;
return callback(null, new KubeStatus(event.object as any));
return callback(null, new KubeStatus(event.object));
}
this.modifyWatchEvent(event);
+40 -23
View File
@@ -19,6 +19,7 @@ import type { RequestInit } from "node-fetch";
// eslint-disable-next-line import/no-named-as-default
import AbortController from "abort-controller";
import type { Patch } from "rfc6902";
import logger from "../logger";
export interface KubeObjectStoreLoadingParams {
namespaces: string[];
@@ -454,35 +455,51 @@ export abstract class KubeObjectStore<T extends KubeObject> extends ItemStore<T>
@action
protected updateFromEventsBuffer() {
// TODO: Convert items from Array to Map to avoid doing findIndex many times per second (events delay)
// Also, its worth to use Web Worker for such operations to prevent blocking UI
// https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers
const items = this.getItems();
for (const { type, object } of this.eventsBuffer.clear()) {
// TODO: Convert items from Array to Map to avoid doing findIndex many times per second (events delay)
// Also, its worth to use Web Worker for such operations to prevent blocking UI
// https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers
const index = items.findIndex(item => item.getId() === object.metadata?.uid);
const item = items[index];
for (const event of this.eventsBuffer.clear()) {
if (event.type === "ERROR") {
continue;
}
switch (type) {
case "ADDED":
try {
const { type, object } = event;
// falls through
case "MODIFIED": {
const newItem = new this.api.objectConstructor(object);
if (!item) {
items.push(newItem);
} else {
items[index] = newItem;
}
break;
if (!object.metadata?.uid) {
logger.warn("[KUBE-STORE]: watch event did not have defined .metadata.uid, skipping", { event });
// Other parts of the code will break if this happens
continue;
}
case "DELETED":
if (item) {
items.splice(index, 1);
const index = items.findIndex(item => item.getId() === object.metadata.uid);
const item = items[index];
switch (type) {
case "ADDED":
// fallthrough
case "MODIFIED": {
const newItem = new this.api.objectConstructor(object);
if (!item) {
items.push(newItem);
} else {
items[index] = newItem;
}
break;
}
break;
case "DELETED":
if (item) {
items.splice(index, 1);
}
break;
}
} catch (error) {
logger.error("[KUBE-STORE]: failed to handle event from watch buffer", { error, event });
}
}
+8 -4
View File
@@ -4,9 +4,13 @@
*/
import type { KubeJsonApiData } from "./kube-json-api";
import type { KubeStatusData } from "./kube-object";
export interface IKubeWatchEvent<T extends KubeJsonApiData> {
type: "ADDED" | "MODIFIED" | "DELETED" | "ERROR";
object?: T;
}
export type IKubeWatchEvent<T extends KubeJsonApiData> = {
type: "ADDED" | "MODIFIED" | "DELETED";
object: T;
} | {
type: "ERROR";
object: KubeStatusData;
};
+6 -9
View File
@@ -57,14 +57,7 @@ function getLabelFromTitle(title: string) {
export function Avatar(props: AvatarProps) {
const { title, variant = "rounded", size = 32, colorHash, children, background, imgProps, src, className, disabled, ...rest } = props;
const getBackgroundColor = () => {
if (src) {
return "transparent";
}
return background || randomColor({ seed: colorHash, luminosity: "dark" });
};
const colorFromHash = randomColor({ seed: colorHash, luminosity: "dark" });
const renderContents = () => {
if (src) {
@@ -81,7 +74,11 @@ export function Avatar(props: AvatarProps) {
[styles.rounded]: variant == "rounded",
[styles.disabled]: disabled,
}, className)}
style={{ width: `${size}px`, height: `${size}px`, backgroundColor: getBackgroundColor() }}
style={{
width: `${size}px`,
height: `${size}px`,
background: background || (src ? "transparent" : colorFromHash),
}}
{...rest}
>
{renderContents()}
+1
View File
@@ -69,6 +69,7 @@
flex: 1;
overflow: hidden;
transition: flex-basis 25ms ease-in;
background: var(--dockInfoBackground);
&.terminal {
background: var(--terminalBackground);
@@ -4,7 +4,8 @@
*/
.HotbarIcon {
--iconActiveShadow: 0 0 0px 3px var(--clusterMenuBackground), 0 0 0px 6px var(--textColorAccent);
--corner: 0px 0px 0px 1px var(--clusterMenuBackground);
--iconActiveShadow: var(--corner), var(--corner), 0 0 0px 3px var(--clusterMenuBackground), 0 0 0px 6px var(--textColorAccent);
--iconHoverShadow: 0 0 0px 3px var(--clusterMenuBackground), 0 0 0px 6px #ffffff50;
display: flex;
@@ -24,6 +25,10 @@
.avatar {
border-radius: 6px;
&.hasImage {
background-color: var(--clusterMenuCellBackground);
}
}
.active {
@@ -61,7 +61,7 @@ export const HotbarIcon = observer(({ menuItems = [], size = 40, tooltip, ...pro
id={id}
title={title}
colorHash={`${title}-${source}`}
className={cssNames(styles.avatar, { [styles.active]: active })}
className={cssNames(styles.avatar, { [styles.active]: active, [styles.hasImage]: !!src })}
disabled={disabled}
size={size}
src={src}