mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Merge branch 'master' into compare-update-and-release-dates
This commit is contained in:
commit
3207a6f057
375 files changed
+12294
-2430
No files matched your search
@@ -10,31 +10,8 @@ import url from "url";
|
||||
import { makeObservable, observable } from "mobx";
|
||||
import { ipcRenderer } from "electron";
|
||||
import logger from "../../common/logger";
|
||||
import { deserialize, serialize } from "v8";
|
||||
import { once } from "lodash";
|
||||
|
||||
export enum TerminalChannels {
|
||||
STDIN = "stdin",
|
||||
STDOUT = "stdout",
|
||||
CONNECTED = "connected",
|
||||
RESIZE = "resize",
|
||||
}
|
||||
|
||||
export type TerminalMessage = {
|
||||
type: TerminalChannels.STDIN;
|
||||
data: string;
|
||||
} | {
|
||||
type: TerminalChannels.STDOUT;
|
||||
data: string;
|
||||
} | {
|
||||
type: TerminalChannels.CONNECTED;
|
||||
} | {
|
||||
type: TerminalChannels.RESIZE;
|
||||
data: {
|
||||
width: number;
|
||||
height: number;
|
||||
};
|
||||
};
|
||||
import { type TerminalMessage, TerminalChannels } from "../../common/terminal/channels";
|
||||
|
||||
enum TerminalColor {
|
||||
RED = "\u001b[31m",
|
||||
@@ -133,13 +110,10 @@ export class TerminalApi extends WebSocketApi<TerminalEvents> {
|
||||
this.prependListener("connected", onReady);
|
||||
|
||||
super.connect(socketUrl);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
this.socket!.binaryType = "arraybuffer";
|
||||
}
|
||||
|
||||
sendMessage(message: TerminalMessage) {
|
||||
return this.send(serialize(message));
|
||||
return this.send(JSON.stringify(message));
|
||||
}
|
||||
|
||||
sendTerminalSize(cols: number, rows: number) {
|
||||
@@ -154,9 +128,9 @@ export class TerminalApi extends WebSocketApi<TerminalEvents> {
|
||||
}
|
||||
}
|
||||
|
||||
protected _onMessage({ data, ...evt }: MessageEvent<ArrayBuffer>): void {
|
||||
protected _onMessage({ data, ...evt }: MessageEvent<string>): void {
|
||||
try {
|
||||
const message: TerminalMessage = deserialize(new Uint8Array(data));
|
||||
const message = JSON.parse(data) as TerminalMessage;
|
||||
|
||||
switch (message.type) {
|
||||
case TerminalChannels.STDOUT:
|
||||
|
||||
@@ -9,6 +9,7 @@ import type TypedEventEmitter from "typed-emitter";
|
||||
import type { Arguments } from "typed-emitter";
|
||||
import { isDevelopment } from "../../common/vars";
|
||||
import type { Defaulted } from "../utils";
|
||||
import { TerminalChannels, type TerminalMessage } from "../../common/terminal/channels";
|
||||
|
||||
interface WebsocketApiParams {
|
||||
/**
|
||||
@@ -30,9 +31,9 @@ interface WebsocketApiParams {
|
||||
/**
|
||||
* The message for pinging the websocket
|
||||
*
|
||||
* @default "PING"
|
||||
* @default "{type: \"ping\"}"
|
||||
*/
|
||||
pingMessage?: string | ArrayBufferLike | Blob | ArrayBufferView;
|
||||
pingMessage?: string;
|
||||
|
||||
/**
|
||||
* If set to a number > 0, then the API will ping the socket on that interval.
|
||||
@@ -65,7 +66,7 @@ export interface WebSocketEvents {
|
||||
|
||||
export class WebSocketApi<Events extends WebSocketEvents> extends (EventEmitter as { new<T>(): TypedEventEmitter<T> })<Events> {
|
||||
protected socket: WebSocket | null = null;
|
||||
protected pendingCommands: (string | ArrayBufferLike | Blob | ArrayBufferView)[] = [];
|
||||
protected pendingCommands: string[] = [];
|
||||
protected reconnectTimer?: number;
|
||||
protected pingTimer?: number;
|
||||
protected params: Defaulted<WebsocketApiParams, keyof typeof WebSocketApi["defaultParams"]>;
|
||||
@@ -76,7 +77,7 @@ export class WebSocketApi<Events extends WebSocketEvents> extends (EventEmitter
|
||||
logging: isDevelopment,
|
||||
reconnectDelay: 10,
|
||||
flushOnOpen: true,
|
||||
pingMessage: "PING",
|
||||
pingMessage: JSON.stringify({ type: TerminalChannels.PING } as TerminalMessage),
|
||||
};
|
||||
|
||||
constructor(params: WebsocketApiParams) {
|
||||
@@ -149,7 +150,7 @@ export class WebSocketApi<Events extends WebSocketEvents> extends (EventEmitter
|
||||
}
|
||||
}
|
||||
|
||||
send(command: string | ArrayBufferLike | Blob | ArrayBufferView) {
|
||||
send(command: string) {
|
||||
if (this.getIsConnected()) {
|
||||
this.socket.send(command);
|
||||
} else {
|
||||
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import ipcRendererInjectable from "./ipc-renderer/ipc-renderer.injectable";
|
||||
import { getValueFromRegisteredChannel } from "./get-value-from-registered-channel";
|
||||
import type { Channel } from "../../../common/ipc-channel/channel";
|
||||
|
||||
export type GetValueFromRegisteredChannel = <TChannel extends Channel<TInstance>, TInstance>(channel: TChannel) => Promise<TChannel["_template"]>;
|
||||
|
||||
const getValueFromRegisteredChannelInjectable = getInjectable({
|
||||
id: "get-value-from-registered-channel",
|
||||
|
||||
instantiate: (di) => getValueFromRegisteredChannel({
|
||||
ipcRenderer: di.inject(ipcRendererInjectable),
|
||||
}),
|
||||
});
|
||||
|
||||
export default getValueFromRegisteredChannelInjectable;
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import type { IpcRenderer } from "electron";
|
||||
import type { Channel } from "../../../common/ipc-channel/channel";
|
||||
|
||||
interface Dependencies {
|
||||
ipcRenderer: IpcRenderer;
|
||||
}
|
||||
|
||||
export const getValueFromRegisteredChannel = ({ ipcRenderer }: Dependencies) =>
|
||||
<TChannel extends Channel<TInstance>, TInstance>(
|
||||
channel: TChannel,
|
||||
): Promise<TChannel["_template"]> =>
|
||||
ipcRenderer.invoke(channel.name);
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import ipcRendererInjectable from "./ipc-renderer/ipc-renderer.injectable";
|
||||
import type {
|
||||
IpcChannelListener,
|
||||
} from "../../ipc-channel-listeners/ipc-channel-listener-injection-token";
|
||||
|
||||
const registerIpcChannelListenerInjectable = getInjectable({
|
||||
id: "register-ipc-channel-listener",
|
||||
|
||||
instantiate: (di) => {
|
||||
const ipc = di.inject(ipcRendererInjectable);
|
||||
|
||||
return ({ channel, handle }: IpcChannelListener) => {
|
||||
ipc.on(channel.name, (_, data) => {
|
||||
handle(data);
|
||||
});
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default registerIpcChannelListenerInjectable;
|
||||
@@ -3,27 +3,29 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { appPathsIpcChannel } from "../../common/app-paths/app-path-injection-token";
|
||||
import getValueFromRegisteredChannelInjectable from "./get-value-from-registered-channel/get-value-from-registered-channel.injectable";
|
||||
import appPathsStateInjectable from "../../common/app-paths/app-paths-state.injectable";
|
||||
import { beforeFrameStartsInjectionToken } from "../before-frame-starts/before-frame-starts-injection-token";
|
||||
import appPathsChannelInjectable from "../../common/app-paths/app-paths-channel.injectable";
|
||||
import { requestFromChannelInjectionToken } from "../../common/utils/channel/request-from-channel-injection-token";
|
||||
|
||||
const setupAppPathsInjectable = getInjectable({
|
||||
id: "setup-app-paths",
|
||||
|
||||
instantiate: (di) => ({
|
||||
run: async () => {
|
||||
const getValueFromRegisteredChannel = di.inject(
|
||||
getValueFromRegisteredChannelInjectable,
|
||||
);
|
||||
instantiate: (di) => {
|
||||
const requestFromChannel = di.inject(requestFromChannelInjectionToken);
|
||||
const appPathsChannel = di.inject(appPathsChannelInjectable);
|
||||
const appPathsState = di.inject(appPathsStateInjectable);
|
||||
|
||||
const syncAppPaths = await getValueFromRegisteredChannel(appPathsIpcChannel);
|
||||
return {
|
||||
run: async () => {
|
||||
const appPaths = await requestFromChannel(
|
||||
appPathsChannel,
|
||||
);
|
||||
|
||||
const appPathsState = di.inject(appPathsStateInjectable);
|
||||
|
||||
appPathsState.set(syncAppPaths);
|
||||
},
|
||||
}),
|
||||
appPathsState.set(appPaths);
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: beforeFrameStartsInjectionToken,
|
||||
});
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { ApplicationUpdateStatusChannel, ApplicationUpdateStatusEventId } from "../../common/application-update/application-update-status-channel.injectable";
|
||||
import applicationUpdateStatusChannelInjectable from "../../common/application-update/application-update-status-channel.injectable";
|
||||
import showInfoNotificationInjectable from "../components/notifications/show-info-notification.injectable";
|
||||
import type { MessageChannelListener } from "../../common/utils/channel/message-channel-listener-injection-token";
|
||||
import { messageChannelListenerInjectionToken } from "../../common/utils/channel/message-channel-listener-injection-token";
|
||||
|
||||
const applicationUpdateStatusListenerInjectable = getInjectable({
|
||||
id: "application-update-status-listener",
|
||||
|
||||
instantiate: (di): MessageChannelListener<ApplicationUpdateStatusChannel> => {
|
||||
const channel = di.inject(applicationUpdateStatusChannelInjectable);
|
||||
const showInfoNotification = di.inject(showInfoNotificationInjectable);
|
||||
|
||||
const eventHandlers: Record<ApplicationUpdateStatusEventId, { handle: (version?: string) => void }> = {
|
||||
"checking-for-updates": {
|
||||
handle: () => {
|
||||
showInfoNotification("Checking for updates...");
|
||||
},
|
||||
},
|
||||
|
||||
"no-updates-available": {
|
||||
handle: () => {
|
||||
showInfoNotification("No new updates available");
|
||||
},
|
||||
},
|
||||
|
||||
"download-for-update-started": {
|
||||
handle: (version) => {
|
||||
showInfoNotification(`Download for version ${version} started...`);
|
||||
},
|
||||
},
|
||||
|
||||
"download-for-update-failed": {
|
||||
handle: () => {
|
||||
showInfoNotification("Download of update failed");
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
channel,
|
||||
|
||||
handler: ({ eventId, version }) => {
|
||||
eventHandlers[eventId].handle(version);
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: messageChannelListenerInjectionToken,
|
||||
});
|
||||
|
||||
export default applicationUpdateStatusListenerInjectable;
|
||||
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { AskBooleanQuestionChannel } from "../../common/ask-boolean/ask-boolean-question-channel.injectable";
|
||||
import askBooleanQuestionChannelInjectable from "../../common/ask-boolean/ask-boolean-question-channel.injectable";
|
||||
import showInfoNotificationInjectable from "../components/notifications/show-info-notification.injectable";
|
||||
import { Button } from "../components/button";
|
||||
import React from "react";
|
||||
import { messageToChannelInjectionToken } from "../../common/utils/channel/message-to-channel-injection-token";
|
||||
import askBooleanAnswerChannelInjectable from "../../common/ask-boolean/ask-boolean-answer-channel.injectable";
|
||||
import notificationsStoreInjectable from "../components/notifications/notifications-store.injectable";
|
||||
import type { MessageChannelListener } from "../../common/utils/channel/message-channel-listener-injection-token";
|
||||
import { messageChannelListenerInjectionToken } from "../../common/utils/channel/message-channel-listener-injection-token";
|
||||
|
||||
const askBooleanQuestionChannelListenerInjectable = getInjectable({
|
||||
id: "ask-boolean-question-channel-listener",
|
||||
|
||||
instantiate: (di): MessageChannelListener<AskBooleanQuestionChannel> => {
|
||||
const questionChannel = di.inject(askBooleanQuestionChannelInjectable);
|
||||
const showInfoNotification = di.inject(showInfoNotificationInjectable);
|
||||
const messageToChannel = di.inject(messageToChannelInjectionToken);
|
||||
const answerChannel = di.inject(askBooleanAnswerChannelInjectable);
|
||||
const notificationsStore = di.inject(notificationsStoreInjectable);
|
||||
|
||||
const sendAnswerFor = (id: string) => (value: boolean) => {
|
||||
messageToChannel(answerChannel, { id, value });
|
||||
};
|
||||
|
||||
const closeNotification = (notificationId: string) => {
|
||||
notificationsStore.remove(notificationId);
|
||||
};
|
||||
|
||||
const sendAnswerAndCloseNotificationFor = (sendAnswer: (value: boolean) => void, notificationId: string) => (value: boolean) => () => {
|
||||
sendAnswer(value);
|
||||
closeNotification(notificationId);
|
||||
};
|
||||
|
||||
return {
|
||||
channel: questionChannel,
|
||||
|
||||
handler: ({ id: questionId, title, question }) => {
|
||||
const notificationId = `ask-boolean-for-${questionId}`;
|
||||
|
||||
const sendAnswer = sendAnswerFor(questionId);
|
||||
const sendAnswerAndCloseNotification = sendAnswerAndCloseNotificationFor(sendAnswer, notificationId);
|
||||
|
||||
showInfoNotification(
|
||||
<AskBoolean
|
||||
id={questionId}
|
||||
title={title}
|
||||
message={question}
|
||||
onNo={sendAnswerAndCloseNotification(false)}
|
||||
onYes={sendAnswerAndCloseNotification(true)}
|
||||
/>,
|
||||
|
||||
{
|
||||
id: notificationId,
|
||||
timeout: 0,
|
||||
onClose: () => sendAnswer(false),
|
||||
},
|
||||
);
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
injectionToken: messageChannelListenerInjectionToken,
|
||||
});
|
||||
|
||||
export default askBooleanQuestionChannelListenerInjectable;
|
||||
|
||||
const AskBoolean = ({
|
||||
id,
|
||||
title,
|
||||
message,
|
||||
onNo,
|
||||
onYes,
|
||||
}: {
|
||||
id: string;
|
||||
title: string;
|
||||
message: string;
|
||||
onNo: () => void;
|
||||
onYes: () => void;
|
||||
}) => (
|
||||
<div className="flex column gaps" data-testid={`ask-boolean-${id}`}>
|
||||
<b>{title}</b>
|
||||
<p>{message}</p>
|
||||
|
||||
<div className="flex gaps row align-left box grow">
|
||||
<Button
|
||||
light
|
||||
label="Yes"
|
||||
onClick={onYes}
|
||||
data-testid={`ask-boolean-${id}-button-yes`}
|
||||
/>
|
||||
|
||||
<Button
|
||||
active
|
||||
outlined
|
||||
label="No"
|
||||
data-testid={`ask-boolean-${id}-button-no`}
|
||||
onClick={onNo}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
@@ -46,8 +46,7 @@ import { init } from "@sentry/electron/renderer";
|
||||
import kubernetesClusterCategoryInjectable from "../common/catalog/categories/kubernetes-cluster.injectable";
|
||||
import autoRegistrationInjectable from "../common/k8s-api/api-manager/auto-registration.injectable";
|
||||
import assert from "assert";
|
||||
import { beforeFrameStartsInjectionToken } from "./before-frame-starts/before-frame-starts-injection-token";
|
||||
import { runManyFor } from "../common/runnable/run-many-for";
|
||||
import startFrameInjectable from "./start-frame/start-frame.injectable";
|
||||
|
||||
configurePackages(); // global packages
|
||||
registerCustomThemes(); // monaco editor themes
|
||||
@@ -68,9 +67,9 @@ export async function bootstrap(di: DiContainer) {
|
||||
initializeSentryReporting(init);
|
||||
}
|
||||
|
||||
const beforeFrameStarts = runManyFor(di)(beforeFrameStartsInjectionToken);
|
||||
const startFrame = di.inject(startFrameInjectable);
|
||||
|
||||
await beforeFrameStarts();
|
||||
await startFrame();
|
||||
|
||||
// TODO: Consolidate import time side-effect to setup time
|
||||
bindEvents();
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
@import "../../components/mixins.scss";
|
||||
|
||||
.AddClusters {
|
||||
--flex-gap: calc(var(--unit) * 2);
|
||||
|
||||
|
||||
@@ -0,0 +1,163 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import type { CatalogCategoryMetadata, CatalogCategorySpec } from "../../../../common/catalog";
|
||||
import { CatalogEntity, categoryVersion } from "../../../../common/catalog";
|
||||
import { CatalogCategory } from "../../../api/catalog-entity";
|
||||
import { noop } from "../../../utils";
|
||||
import type { CatalogEntityStore } from "../catalog-entity-store/catalog-entity.store";
|
||||
import { catalogEntityStore } from "../catalog-entity-store/catalog-entity.store";
|
||||
|
||||
class TestEntityOne extends CatalogEntity {
|
||||
public static readonly apiVersion: string = "entity.k8slens.dev/v1alpha1";
|
||||
public static readonly kind: string = "TestEntityOne";
|
||||
|
||||
public readonly apiVersion = TestEntityOne.apiVersion;
|
||||
public readonly kind = TestEntityOne.kind;
|
||||
}
|
||||
|
||||
class TestEntityTwo extends CatalogEntity {
|
||||
public static readonly apiVersion: string = "entity.k8slens.dev/v1alpha1";
|
||||
public static readonly kind: string = "TestEntityTwo";
|
||||
|
||||
public readonly apiVersion = TestEntityTwo.apiVersion;
|
||||
public readonly kind = TestEntityTwo.kind;
|
||||
}
|
||||
|
||||
class TestCategoryOne extends CatalogCategory {
|
||||
apiVersion = "catalog.k8slens.dev/v1alpha1";
|
||||
kind = "CatalogCategory";
|
||||
metadata: CatalogCategoryMetadata = {
|
||||
icon: "dash",
|
||||
name: "test-one",
|
||||
};
|
||||
spec: CatalogCategorySpec = {
|
||||
group: "entity.k8slens.dev",
|
||||
versions: [
|
||||
categoryVersion("v1alpha1", TestEntityOne),
|
||||
],
|
||||
names: {
|
||||
kind: "KubernetesCluster",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
class TestCategoryTwo extends CatalogCategory {
|
||||
apiVersion = "catalog.k8slens.dev/v1alpha1";
|
||||
kind = "CatalogCategory";
|
||||
metadata: CatalogCategoryMetadata = {
|
||||
icon: "dash",
|
||||
name: "test-two",
|
||||
};
|
||||
spec: CatalogCategorySpec = {
|
||||
group: "entity.k8slens.dev",
|
||||
versions: [
|
||||
categoryVersion("v1alpha1", TestEntityTwo),
|
||||
],
|
||||
names: {
|
||||
kind: "KubernetesCluster",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe("CatalogEntityStore", () => {
|
||||
describe("getTotalCount", () => {
|
||||
let store: CatalogEntityStore;
|
||||
let testCategoryOne: TestCategoryOne;
|
||||
let testCategoryTwo: TestCategoryTwo;
|
||||
|
||||
beforeEach(() => {
|
||||
const entityItems = [
|
||||
new TestEntityOne({
|
||||
metadata: {
|
||||
labels: {},
|
||||
name: "my-test-one",
|
||||
uid: "1",
|
||||
},
|
||||
spec: {},
|
||||
status: {
|
||||
phase: "unknown",
|
||||
},
|
||||
}),
|
||||
new TestEntityOne({
|
||||
metadata: {
|
||||
labels: {},
|
||||
name: "my-test-two",
|
||||
uid: "2",
|
||||
},
|
||||
spec: {},
|
||||
status: {
|
||||
phase: "unknown",
|
||||
},
|
||||
}),
|
||||
new TestEntityTwo({
|
||||
metadata: {
|
||||
labels: {},
|
||||
name: "my-test-three",
|
||||
uid: "3",
|
||||
},
|
||||
spec: {},
|
||||
status: {
|
||||
phase: "unknown",
|
||||
},
|
||||
}),
|
||||
new TestEntityTwo({
|
||||
metadata: {
|
||||
labels: {},
|
||||
name: "my-test-four",
|
||||
uid: "4",
|
||||
},
|
||||
spec: {},
|
||||
status: {
|
||||
phase: "unknown",
|
||||
},
|
||||
}),
|
||||
new TestEntityTwo({
|
||||
metadata: {
|
||||
labels: {},
|
||||
name: "my-test-five",
|
||||
uid: "5",
|
||||
},
|
||||
spec: {},
|
||||
status: {
|
||||
phase: "unknown",
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
||||
testCategoryOne = new TestCategoryOne();
|
||||
testCategoryTwo = new TestCategoryTwo();
|
||||
store = catalogEntityStore({
|
||||
catalogRegistry: {
|
||||
items: [
|
||||
testCategoryOne,
|
||||
testCategoryTwo,
|
||||
],
|
||||
},
|
||||
entityRegistry: {
|
||||
onRun: noop,
|
||||
filteredItems: entityItems,
|
||||
getItemsForCategory: <T extends CatalogEntity>(category: CatalogCategory): T[] => {
|
||||
return entityItems.filter(item => category.spec.versions.some(version => item instanceof version.entityClass)) as T[];
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("given no active category, returns count of all kinds", () => {
|
||||
expect(store.getTotalCount()).toBe(5);
|
||||
});
|
||||
|
||||
it("given active category is TestCategoryOne, only returns count for those declared kinds", () => {
|
||||
store.activeCategory.set(testCategoryOne);
|
||||
expect(store.getTotalCount()).toBe(2);
|
||||
});
|
||||
|
||||
it("given active category is TestCategoryTwo, only returns count for those declared kinds", () => {
|
||||
store.activeCategory.set(testCategoryTwo);
|
||||
expect(store.getTotalCount()).toBe(3);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -12,9 +12,12 @@ import type { Disposer } from "../../../../common/utils";
|
||||
import { disposer } from "../../../../common/utils";
|
||||
import type { ItemListStore } from "../../item-object-list";
|
||||
|
||||
type EntityRegistry = Pick<CatalogEntityRegistry, "getItemsForCategory" | "filteredItems" | "onRun">;
|
||||
type CatalogRegistry = Pick<CatalogCategoryRegistry, "items">;
|
||||
|
||||
interface Dependencies {
|
||||
entityRegistry: CatalogEntityRegistry;
|
||||
catalogRegistry: CatalogCategoryRegistry;
|
||||
entityRegistry: EntityRegistry;
|
||||
catalogRegistry: CatalogRegistry;
|
||||
}
|
||||
|
||||
export type CatalogEntityStore = ItemListStore<CatalogEntity, false> & {
|
||||
@@ -71,7 +74,7 @@ export function catalogEntityStore({
|
||||
),
|
||||
onRun: entity => entityRegistry.onRun(entity),
|
||||
failedLoading: false,
|
||||
getTotalCount: () => entityRegistry.filteredItems.length,
|
||||
getTotalCount: () => entities.get().length,
|
||||
isLoaded: true,
|
||||
isSelected: (item) => item.getId() === selectedItemId.get(),
|
||||
isSelectedAll: () => false,
|
||||
|
||||
@@ -26,8 +26,6 @@ import appVersionInjectable from "../../../common/get-configuration-file-model/a
|
||||
import type { AppEvent } from "../../../common/app-event-bus/event-bus";
|
||||
import appEventBusInjectable from "../../../common/app-event-bus/app-event-bus.injectable";
|
||||
import { computed } from "mobx";
|
||||
import ipcRendererInjectable from "../../app-paths/get-value-from-registered-channel/ipc-renderer/ipc-renderer.injectable";
|
||||
import { UserStore } from "../../../common/user-store";
|
||||
import broadcastMessageInjectable from "../../../common/ipc/broadcast-message.injectable";
|
||||
|
||||
mockWindow();
|
||||
@@ -107,13 +105,7 @@ describe("<Catalog />", () => {
|
||||
catalogEntityItem = createMockCatalogEntity(onRun);
|
||||
catalogEntityRegistry = di.inject(catalogEntityRegistryInjectable);
|
||||
|
||||
UserStore.createInstance(); // TODO: replace with DI
|
||||
|
||||
di.override(catalogEntityRegistryInjectable, () => catalogEntityRegistry);
|
||||
di.override(ipcRendererInjectable, () => ({
|
||||
on: jest.fn(),
|
||||
invoke: jest.fn(), // TODO: replace with proper mocking via the IPC bridge
|
||||
} as never));
|
||||
|
||||
emitEvent = jest.fn();
|
||||
|
||||
@@ -129,7 +121,6 @@ describe("<Catalog />", () => {
|
||||
|
||||
afterEach(() => {
|
||||
CatalogEntityDetailRegistry.resetInstance();
|
||||
UserStore.resetInstance();
|
||||
jest.clearAllMocks();
|
||||
jest.restoreAllMocks();
|
||||
mockFs.restore();
|
||||
|
||||
+225
@@ -0,0 +1,225 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`<CustomResourceDetails /> with a CRD with a boolean field should display false in an additionalPrinterColumn as 'false' 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="CrdResourceDetails MyCrd"
|
||||
>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Created
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
<unknown>
|
||||
ago
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Name
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
first-crd
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
MyField
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
<ul>
|
||||
<li>
|
||||
false
|
||||
</li>
|
||||
</ul>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`<CustomResourceDetails /> with a CRD with a boolean field should display true in an additionalPrinterColumn as 'true' 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="CrdResourceDetails MyCrd"
|
||||
>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Created
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
<unknown>
|
||||
ago
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Name
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
first-crd
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
MyField
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
<ul>
|
||||
<li>
|
||||
true
|
||||
</li>
|
||||
</ul>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`<CustomResourceDetails /> with a CRD with a number field should display 0 in an additionalPrinterColumn as '0' 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="CrdResourceDetails MyCrd"
|
||||
>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Created
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
<unknown>
|
||||
ago
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Name
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
first-crd
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
MyField
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
<ul>
|
||||
<li>
|
||||
0
|
||||
</li>
|
||||
</ul>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`<CustomResourceDetails /> with a CRD with a number field should display 1234 in an additionalPrinterColumn as '1234' 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="CrdResourceDetails MyCrd"
|
||||
>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Created
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
<unknown>
|
||||
ago
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Name
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
first-crd
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
MyField
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
<ul>
|
||||
<li>
|
||||
1234
|
||||
</li>
|
||||
</ul>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
@@ -0,0 +1,206 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import { CustomResourceDefinition } from "../../../../common/k8s-api/endpoints";
|
||||
import { KubeObject } from "../../../../common/k8s-api/kube-object";
|
||||
import { getDiForUnitTesting } from "../../../getDiForUnitTesting";
|
||||
import type { DiRender } from "../../test-utils/renderFor";
|
||||
import { renderFor } from "../../test-utils/renderFor";
|
||||
import { CustomResourceDetails } from "../crd-resource-details";
|
||||
|
||||
describe("<CustomResourceDetails />", () => {
|
||||
let render: DiRender;
|
||||
|
||||
beforeEach(() => {
|
||||
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
|
||||
render = renderFor(di);
|
||||
});
|
||||
|
||||
describe("with a CRD with a boolean field", () => {
|
||||
let crd: CustomResourceDefinition;
|
||||
|
||||
beforeEach(() => {
|
||||
crd = new CustomResourceDefinition({
|
||||
apiVersion: "apiextensions.k8s.io/v1",
|
||||
kind: "CustomResourceDefinition",
|
||||
metadata: {
|
||||
name: "my-crd",
|
||||
resourceVersion: "1",
|
||||
selfLink: "/apis/apiextensions.k8s.io/v1/customresourcedefinitions/my-crd",
|
||||
uid: "1",
|
||||
},
|
||||
spec: {
|
||||
versions: [{
|
||||
name: "v1",
|
||||
served: true,
|
||||
storage: true,
|
||||
schema: {
|
||||
openAPIV3Schema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
spec: {
|
||||
type: "object",
|
||||
properties: {
|
||||
"my-field": {
|
||||
type: "boolean",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
additionalPrinterColumns: [
|
||||
{
|
||||
name: "MyField",
|
||||
jsonPath: ".spec.my-field",
|
||||
type: "boolean",
|
||||
},
|
||||
],
|
||||
}],
|
||||
group: "stable.lens.dev",
|
||||
names: {
|
||||
kind: "MyCrd",
|
||||
plural: "my-crds",
|
||||
},
|
||||
scope: "Cluster",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("should display false in an additionalPrinterColumn as 'false'", () => {
|
||||
const cr = new KubeObject({
|
||||
apiVersion: "stable.lens.dev/v1",
|
||||
kind: "MyCrd",
|
||||
metadata: {
|
||||
name: "first-crd",
|
||||
resourceVersion: "1",
|
||||
selfLink: "stable.lens.dev/v1/first-crd",
|
||||
uid: "2",
|
||||
},
|
||||
spec: {
|
||||
"my-field": false,
|
||||
},
|
||||
});
|
||||
const result = render(<CustomResourceDetails crd={crd} object={cr} />);
|
||||
|
||||
expect(result.container).toMatchSnapshot();
|
||||
expect(result.getByText("false")).toBeTruthy();
|
||||
});
|
||||
|
||||
it("should display true in an additionalPrinterColumn as 'true'", () => {
|
||||
const cr = new KubeObject({
|
||||
apiVersion: "stable.lens.dev/v1",
|
||||
kind: "MyCrd",
|
||||
metadata: {
|
||||
name: "first-crd",
|
||||
resourceVersion: "1",
|
||||
selfLink: "stable.lens.dev/v1/first-crd",
|
||||
uid: "2",
|
||||
},
|
||||
spec: {
|
||||
"my-field": true,
|
||||
},
|
||||
});
|
||||
const result = render(<CustomResourceDetails crd={crd} object={cr} />);
|
||||
|
||||
expect(result.container).toMatchSnapshot();
|
||||
expect(result.getByText("true")).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe("with a CRD with a number field", () => {
|
||||
let crd: CustomResourceDefinition;
|
||||
|
||||
beforeEach(() => {
|
||||
crd = new CustomResourceDefinition({
|
||||
apiVersion: "apiextensions.k8s.io/v1",
|
||||
kind: "CustomResourceDefinition",
|
||||
metadata: {
|
||||
name: "my-crd",
|
||||
resourceVersion: "1",
|
||||
selfLink: "/apis/apiextensions.k8s.io/v1/customresourcedefinitions/my-crd",
|
||||
uid: "1",
|
||||
},
|
||||
spec: {
|
||||
versions: [{
|
||||
name: "v1",
|
||||
served: true,
|
||||
storage: true,
|
||||
schema: {
|
||||
openAPIV3Schema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
spec: {
|
||||
type: "object",
|
||||
properties: {
|
||||
"my-field": {
|
||||
type: "number",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
additionalPrinterColumns: [
|
||||
{
|
||||
name: "MyField",
|
||||
jsonPath: ".spec.my-field",
|
||||
type: "number",
|
||||
},
|
||||
],
|
||||
}],
|
||||
group: "stable.lens.dev",
|
||||
names: {
|
||||
kind: "MyCrd",
|
||||
plural: "my-crds",
|
||||
},
|
||||
scope: "Cluster",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("should display 0 in an additionalPrinterColumn as '0'", () => {
|
||||
const cr = new KubeObject({
|
||||
apiVersion: "stable.lens.dev/v1",
|
||||
kind: "MyCrd",
|
||||
metadata: {
|
||||
name: "first-crd",
|
||||
resourceVersion: "1",
|
||||
selfLink: "stable.lens.dev/v1/first-crd",
|
||||
uid: "2",
|
||||
},
|
||||
spec: {
|
||||
"my-field": 0,
|
||||
},
|
||||
});
|
||||
const result = render(<CustomResourceDetails crd={crd} object={cr} />);
|
||||
|
||||
expect(result.container).toMatchSnapshot();
|
||||
expect(result.getByText("0")).toBeTruthy();
|
||||
});
|
||||
|
||||
it("should display 1234 in an additionalPrinterColumn as '1234'", () => {
|
||||
const cr = new KubeObject({
|
||||
apiVersion: "stable.lens.dev/v1",
|
||||
kind: "MyCrd",
|
||||
metadata: {
|
||||
name: "first-crd",
|
||||
resourceVersion: "1",
|
||||
selfLink: "stable.lens.dev/v1/first-crd",
|
||||
uid: "2",
|
||||
},
|
||||
spec: {
|
||||
"my-field": 1234,
|
||||
},
|
||||
});
|
||||
const result = render(<CustomResourceDetails crd={crd} object={cr} />);
|
||||
|
||||
expect(result.container).toMatchSnapshot();
|
||||
expect(result.getByText("1234")).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -25,7 +25,7 @@ export interface CustomResourceDetailsProps extends KubeObjectDetailsProps<KubeO
|
||||
crd: CustomResourceDefinition;
|
||||
}
|
||||
|
||||
function convertSpecValue(value: any): any {
|
||||
function convertSpecValue(value: unknown): React.ReactNode {
|
||||
if (Array.isArray(value)) {
|
||||
return (
|
||||
<ul>
|
||||
@@ -50,18 +50,22 @@ function convertSpecValue(value: any): any {
|
||||
);
|
||||
}
|
||||
|
||||
return value;
|
||||
if (
|
||||
typeof value === "boolean"
|
||||
|| typeof value === "string"
|
||||
|| typeof value === "number"
|
||||
) {
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@observer
|
||||
export class CustomResourceDetails extends React.Component<CustomResourceDetailsProps> {
|
||||
renderAdditionalColumns(resource: KubeObject, columns: AdditionalPrinterColumnsV1[]) {
|
||||
return columns.map(({ name, jsonPath }) => (
|
||||
<DrawerItem
|
||||
key={name}
|
||||
name={name}
|
||||
renderBoolean
|
||||
>
|
||||
<DrawerItem key={name} name={name}>
|
||||
{convertSpecValue(JSONPath.query(resource, convertKubectlJsonPathToNodeJsonPath(jsonPath)))}
|
||||
</DrawerItem>
|
||||
));
|
||||
|
||||
@@ -7,7 +7,6 @@ import "@testing-library/jest-dom/extend-expect";
|
||||
import { fireEvent, screen, waitFor } from "@testing-library/react";
|
||||
import fse from "fs-extra";
|
||||
import React from "react";
|
||||
import { UserStore } from "../../../../common/user-store";
|
||||
import type { ExtensionDiscovery } from "../../../../extensions/extension-discovery/extension-discovery";
|
||||
import type { ExtensionLoader } from "../../../../extensions/extension-loader";
|
||||
import { ConfirmDialog } from "../../confirm-dialog";
|
||||
@@ -96,13 +95,10 @@ describe("Extensions", () => {
|
||||
});
|
||||
|
||||
extensionDiscovery.uninstallExtension = jest.fn(() => Promise.resolve());
|
||||
|
||||
UserStore.createInstance();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
mockFs.restore();
|
||||
UserStore.resetInstance();
|
||||
});
|
||||
|
||||
it("disables uninstall and disable buttons while uninstalling", async () => {
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
|
||||
.notes {
|
||||
white-space: pre-line;
|
||||
font-family: "RobotoMono", monospace;
|
||||
font-family: var(--font-monospace);
|
||||
font-size: small;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,11 @@ export class NodeStore extends KubeObjectStore<Node, NodeApi> {
|
||||
}
|
||||
|
||||
@computed get masterNodes() {
|
||||
return this.items.filter(node => node.getRoleLabels().includes("master"));
|
||||
return this.items.filter(node => node.isMasterNode());
|
||||
}
|
||||
|
||||
@computed get workerNodes() {
|
||||
return this.items.filter(node => !node.getRoleLabels().includes("master"));
|
||||
return this.items.filter(node => !node.isMasterNode());
|
||||
}
|
||||
|
||||
getWarningsCount(): number {
|
||||
|
||||
@@ -12,7 +12,7 @@ import type { UserStore } from "../../../common/user-store";
|
||||
import { Input } from "../input";
|
||||
import { Switch } from "../switch";
|
||||
import moment from "moment-timezone";
|
||||
import { updateChannels, defaultExtensionRegistryUrl, defaultUpdateChannel, defaultLocaleTimezone, defaultExtensionRegistryUrlLocation } from "../../../common/user-store/preferences-helpers";
|
||||
import { defaultExtensionRegistryUrl, defaultLocaleTimezone, defaultExtensionRegistryUrlLocation } from "../../../common/user-store/preferences-helpers";
|
||||
import type { IComputedValue } from "mobx";
|
||||
import { runInAction } from "mobx";
|
||||
import { isUrl } from "../input/input_validators";
|
||||
@@ -24,11 +24,17 @@ import { Preferences } from "./preferences";
|
||||
import userStoreInjectable from "../../../common/user-store/user-store.injectable";
|
||||
import themeStoreInjectable from "../../themes/store.injectable";
|
||||
import { defaultThemeId } from "../../../common/vars";
|
||||
import { updateChannels } from "../../../common/application-update/update-channels";
|
||||
import { map, toPairs } from "lodash/fp";
|
||||
import { pipeline } from "@ogre-tools/fp";
|
||||
import type { SelectedUpdateChannel } from "../../../common/application-update/selected-update-channel/selected-update-channel.injectable";
|
||||
import selectedUpdateChannelInjectable from "../../../common/application-update/selected-update-channel/selected-update-channel.injectable";
|
||||
|
||||
interface Dependencies {
|
||||
appPreferenceItems: IComputedValue<RegisteredAppPreference[]>;
|
||||
userStore: UserStore;
|
||||
themeStore: ThemeStore;
|
||||
selectedUpdateChannel: SelectedUpdateChannel;
|
||||
}
|
||||
|
||||
const timezoneOptions = moment.tz.names()
|
||||
@@ -36,10 +42,16 @@ const timezoneOptions = moment.tz.names()
|
||||
value: timezone,
|
||||
label: timezone.replace("_", " "),
|
||||
}));
|
||||
const updateChannelOptions = Array.from(updateChannels, ([channel, { label }]) => ({
|
||||
value: channel,
|
||||
label,
|
||||
}));
|
||||
|
||||
const updateChannelOptions = pipeline(
|
||||
toPairs(updateChannels),
|
||||
|
||||
map(([, channel]) => ({
|
||||
value: channel.id,
|
||||
label: channel.label,
|
||||
})),
|
||||
);
|
||||
|
||||
const extensionInstallRegistryOptions = [
|
||||
{
|
||||
value: "default",
|
||||
@@ -55,7 +67,7 @@ const extensionInstallRegistryOptions = [
|
||||
},
|
||||
] as const;
|
||||
|
||||
const NonInjectedApplication: React.FC<Dependencies> = ({ appPreferenceItems, userStore, themeStore }) => {
|
||||
const NonInjectedApplication: React.FC<Dependencies> = ({ appPreferenceItems, userStore, themeStore, selectedUpdateChannel }) => {
|
||||
const [customUrl, setCustomUrl] = React.useState(userStore.extensionRegistryUrl.customUrl || "");
|
||||
const themeOptions = [
|
||||
{
|
||||
@@ -144,8 +156,8 @@ const NonInjectedApplication: React.FC<Dependencies> = ({ appPreferenceItems, us
|
||||
<Select
|
||||
id="update-channel-input"
|
||||
options={updateChannelOptions}
|
||||
value={userStore.updateChannel}
|
||||
onChange={value => userStore.updateChannel = value?.value ?? defaultUpdateChannel}
|
||||
value={selectedUpdateChannel.value.get().id}
|
||||
onChange={(selected) => selectedUpdateChannel.setValue(selected?.value) }
|
||||
themeName="lens"
|
||||
/>
|
||||
</section>
|
||||
@@ -175,6 +187,7 @@ export const Application = withInjectables<Dependencies>(
|
||||
appPreferenceItems: di.inject(appPreferencesInjectable),
|
||||
userStore: di.inject(userStoreInjectable),
|
||||
themeStore: di.inject(themeStoreInjectable),
|
||||
selectedUpdateChannel: di.inject(selectedUpdateChannelInjectable),
|
||||
}),
|
||||
},
|
||||
);
|
||||
@@ -4,18 +4,20 @@
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import { action } from "mobx";
|
||||
import { observer } from "mobx-react";
|
||||
import type { UserStore } from "../../../common/user-store";
|
||||
import { SubTitle } from "../layout/sub-title";
|
||||
import { Input, InputValidators } from "../input";
|
||||
import { Input } from "../input";
|
||||
import { Switch } from "../switch";
|
||||
import { Select } from "../select";
|
||||
import { Select, type SelectOption } from "../select";
|
||||
import type { ThemeStore } from "../../themes/store";
|
||||
import { Preferences } from "./preferences";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import userStoreInjectable from "../../../common/user-store/user-store.injectable";
|
||||
import themeStoreInjectable from "../../themes/store.injectable";
|
||||
import defaultShellInjectable from "./default-shell.injectable";
|
||||
import logger from "../../../common/logger";
|
||||
|
||||
interface Dependencies {
|
||||
userStore: UserStore;
|
||||
@@ -23,11 +25,12 @@ interface Dependencies {
|
||||
defaultShell: string;
|
||||
}
|
||||
|
||||
const NonInjectedTerminal = observer(({
|
||||
userStore,
|
||||
themeStore,
|
||||
defaultShell,
|
||||
}: Dependencies) => {
|
||||
const NonInjectedTerminal = observer((
|
||||
{
|
||||
userStore,
|
||||
themeStore,
|
||||
defaultShell,
|
||||
}: Dependencies) => {
|
||||
const themeOptions = [
|
||||
{
|
||||
value: "", // TODO: replace with a sentinal value that isn't string (and serialize it differently)
|
||||
@@ -39,6 +42,26 @@ const NonInjectedTerminal = observer(({
|
||||
})),
|
||||
];
|
||||
|
||||
// fonts must be declared in `fonts.scss` and at `template.html` (if early-preloading required)
|
||||
const supportedCustomFonts: SelectOption<string>[] = [
|
||||
"RobotoMono", "Anonymous Pro", "IBM Plex Mono", "JetBrains Mono", "Red Hat Mono",
|
||||
"Source Code Pro", "Space Mono", "Ubuntu Mono",
|
||||
].map(customFont => {
|
||||
const { fontFamily, fontSize } = userStore.terminalConfig;
|
||||
|
||||
return {
|
||||
label: <span style={{ fontFamily: customFont, fontSize }}>{customFont}</span>,
|
||||
value: customFont,
|
||||
isSelected: fontFamily === customFont,
|
||||
};
|
||||
});
|
||||
|
||||
const onFontFamilyChange = action(({ value: fontFamily }: SelectOption<string>) => {
|
||||
logger.info(`setting terminal font to ${fontFamily}`);
|
||||
|
||||
userStore.terminalConfig.fontFamily = fontFamily; // save to external storage
|
||||
});
|
||||
|
||||
return (
|
||||
<Preferences data-testid="terminal-preferences-page">
|
||||
<section>
|
||||
@@ -49,7 +72,7 @@ const NonInjectedTerminal = observer(({
|
||||
<Input
|
||||
theme="round-black"
|
||||
placeholder={defaultShell}
|
||||
value={userStore.shell}
|
||||
value={userStore.shell ?? ""}
|
||||
onChange={(value) => userStore.shell = value}
|
||||
/>
|
||||
</section>
|
||||
@@ -81,18 +104,19 @@ const NonInjectedTerminal = observer(({
|
||||
theme="round-black"
|
||||
type="number"
|
||||
min={10}
|
||||
validators={InputValidators.isNumber}
|
||||
value={userStore.terminalConfig.fontSize.toString()}
|
||||
max={50}
|
||||
defaultValue={userStore.terminalConfig.fontSize.toString()}
|
||||
onChange={(value) => userStore.terminalConfig.fontSize = Number(value)}
|
||||
/>
|
||||
</section>
|
||||
<section>
|
||||
<SubTitle title="Font family" />
|
||||
<Input
|
||||
theme="round-black"
|
||||
type="text"
|
||||
<Select
|
||||
themeName="lens"
|
||||
controlShouldRenderValue
|
||||
value={userStore.terminalConfig.fontFamily}
|
||||
onChange={(value) => userStore.terminalConfig.fontFamily = value}
|
||||
options={supportedCustomFonts}
|
||||
onChange={onFontFamilyChange as any}
|
||||
/>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
-5
@@ -12,7 +12,6 @@ import type { DiRender } from "../../../test-utils/renderFor";
|
||||
import { renderFor } from "../../../test-utils/renderFor";
|
||||
import clusterRoleStoreInjectable from "../../+cluster-roles/store.injectable";
|
||||
import storesAndApisCanBeCreatedInjectable from "../../../../stores-apis-can-be-created.injectable";
|
||||
import ipcRendererInjectable from "../../../../app-paths/get-value-from-registered-channel/ipc-renderer/ipc-renderer.injectable";
|
||||
|
||||
describe("ClusterRoleBindingDialog tests", () => {
|
||||
let render: DiRender;
|
||||
@@ -21,10 +20,6 @@ describe("ClusterRoleBindingDialog tests", () => {
|
||||
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
|
||||
di.override(storesAndApisCanBeCreatedInjectable, () => true);
|
||||
di.override(ipcRendererInjectable, () => ({
|
||||
on: jest.fn(),
|
||||
invoke: jest.fn(), // TODO: replace with proper mocking via the IPC bridge
|
||||
} as never));
|
||||
|
||||
render = renderFor(di);
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import { renderFor } from "../../../test-utils/renderFor";
|
||||
import directoryForUserDataInjectable from "../../../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
import clusterRoleStoreInjectable from "../../+cluster-roles/store.injectable";
|
||||
import storesAndApisCanBeCreatedInjectable from "../../../../stores-apis-can-be-created.injectable";
|
||||
import ipcRendererInjectable from "../../../../app-paths/get-value-from-registered-channel/ipc-renderer/ipc-renderer.injectable";
|
||||
|
||||
describe("RoleBindingDialog tests", () => {
|
||||
let render: DiRender;
|
||||
@@ -23,10 +22,6 @@ describe("RoleBindingDialog tests", () => {
|
||||
|
||||
di.override(storesAndApisCanBeCreatedInjectable, () => true);
|
||||
di.override(directoryForUserDataInjectable, () => "some-directory-for-user-data");
|
||||
di.override(ipcRendererInjectable, () => ({
|
||||
on: jest.fn(),
|
||||
invoke: jest.fn(), // TODO: replace with proper mocking via the IPC bridge
|
||||
} as never));
|
||||
|
||||
render = renderFor(di);
|
||||
|
||||
|
||||
+229
@@ -0,0 +1,229 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`<Projected /> renders 1`] = `
|
||||
<body>
|
||||
<div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Sources
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
`;
|
||||
|
||||
exports[`<Projected /> renders a secret source including overriding mode 1`] = `
|
||||
<body>
|
||||
<div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Default Mount Mode
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
0o777
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Sources
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
<div
|
||||
class="DrawerTitle sub-title"
|
||||
>
|
||||
Secret
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Name
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
my-projected-secret
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Items
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
<ul>
|
||||
<li>
|
||||
foo⇢/bar
|
||||
(0o666)
|
||||
</li>
|
||||
</ul>
|
||||
</span>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
`;
|
||||
|
||||
exports[`<Projected /> renders a secret source, when provided 1`] = `
|
||||
<body>
|
||||
<div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Default Mount Mode
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
0o777
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Sources
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
<div
|
||||
class="DrawerTitle sub-title"
|
||||
>
|
||||
Secret
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Name
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
my-projected-secret
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Items
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
<ul>
|
||||
<li>
|
||||
foo⇢/bar
|
||||
</li>
|
||||
</ul>
|
||||
</span>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
`;
|
||||
|
||||
exports[`<Projected /> renders default mount mode in octal when provided 1`] = `
|
||||
<body>
|
||||
<div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Default Mount Mode
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
0o777
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Sources
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
`;
|
||||
|
||||
exports[`<Projected /> renders when no sources array provided 1`] = `
|
||||
<body>
|
||||
<div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Default Mount Mode
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
0o777
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Sources
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
`;
|
||||
+229
@@ -0,0 +1,229 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`<CephFs /> should render 'false' for Readonly when false is provided 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Monitors
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
<ul />
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Mount Path
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
/
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Username
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
admin
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Secret Filepath
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
/etc/ceph/user.secret
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
data-testid="cephfs-readonly"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Readonly
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
false
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`<CephFs /> should render 'false' for Readonly when not provided 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Monitors
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
<ul />
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Mount Path
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
/
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Username
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
admin
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Secret Filepath
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
/etc/ceph/user.secret
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
data-testid="cephfs-readonly"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Readonly
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
false
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`<CephFs /> should render 'true' for Readonly when true is provided 1`] = `
|
||||
<div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Monitors
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
<ul />
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Mount Path
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
/
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Username
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
admin
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Secret Filepath
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
/etc/ceph/user.secret
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
class="DrawerItem"
|
||||
data-testid="cephfs-readonly"
|
||||
>
|
||||
<span
|
||||
class="name"
|
||||
>
|
||||
Readonly
|
||||
</span>
|
||||
<span
|
||||
class="value"
|
||||
>
|
||||
true
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { render } from "@testing-library/react";
|
||||
import React from "react";
|
||||
import type { CephfsSource } from "../../../../../../../common/k8s-api/endpoints";
|
||||
import { Pod } from "../../../../../../../common/k8s-api/endpoints";
|
||||
import { CephFs } from "../ceph-fs";
|
||||
|
||||
describe("<CephFs />", () => {
|
||||
it("should render 'false' for Readonly when not provided", () => {
|
||||
const cephfsName = "my-ceph";
|
||||
const cephfsVolume: CephfsSource = {
|
||||
monitors: [],
|
||||
};
|
||||
const pod = new Pod({
|
||||
apiVersion: "v1",
|
||||
kind: "Pod",
|
||||
metadata: {
|
||||
name: "my-pod",
|
||||
namespace: "default",
|
||||
resourceVersion: "1",
|
||||
uid: "123",
|
||||
selfLink: "/api/v1/pod/default/my-pod",
|
||||
},
|
||||
spec: {
|
||||
volumes: [{
|
||||
name: cephfsName,
|
||||
cephfs: cephfsVolume,
|
||||
}],
|
||||
},
|
||||
});
|
||||
const result = render((
|
||||
<CephFs
|
||||
pod={pod}
|
||||
variant={cephfsVolume}
|
||||
volumeName={cephfsName}
|
||||
/>
|
||||
));
|
||||
|
||||
expect(result.container).toMatchSnapshot();
|
||||
expect(result.getByTestId("cephfs-readonly")).toHaveTextContent("false");
|
||||
});
|
||||
|
||||
it("should render 'false' for Readonly when false is provided", () => {
|
||||
const cephfsName = "my-ceph";
|
||||
const cephfsVolume: CephfsSource = {
|
||||
monitors: [],
|
||||
readOnly: false,
|
||||
};
|
||||
const pod = new Pod({
|
||||
apiVersion: "v1",
|
||||
kind: "Pod",
|
||||
metadata: {
|
||||
name: "my-pod",
|
||||
namespace: "default",
|
||||
resourceVersion: "1",
|
||||
uid: "123",
|
||||
selfLink: "/api/v1/pod/default/my-pod",
|
||||
},
|
||||
spec: {
|
||||
volumes: [{
|
||||
name: cephfsName,
|
||||
cephfs: cephfsVolume,
|
||||
}],
|
||||
},
|
||||
});
|
||||
const result = render((
|
||||
<CephFs
|
||||
pod={pod}
|
||||
variant={cephfsVolume}
|
||||
volumeName={cephfsName}
|
||||
/>
|
||||
));
|
||||
|
||||
expect(result.container).toMatchSnapshot();
|
||||
expect(result.getByTestId("cephfs-readonly")).toHaveTextContent("false");
|
||||
});
|
||||
|
||||
it("should render 'true' for Readonly when true is provided", () => {
|
||||
const cephfsName = "my-ceph";
|
||||
const cephfsVolume: CephfsSource = {
|
||||
monitors: [],
|
||||
readOnly: true,
|
||||
};
|
||||
const pod = new Pod({
|
||||
apiVersion: "v1",
|
||||
kind: "Pod",
|
||||
metadata: {
|
||||
name: "my-pod",
|
||||
namespace: "default",
|
||||
resourceVersion: "1",
|
||||
uid: "123",
|
||||
selfLink: "/api/v1/pod/default/my-pod",
|
||||
},
|
||||
spec: {
|
||||
volumes: [{
|
||||
name: cephfsName,
|
||||
cephfs: cephfsVolume,
|
||||
}],
|
||||
},
|
||||
});
|
||||
const result = render((
|
||||
<CephFs
|
||||
pod={pod}
|
||||
variant={cephfsVolume}
|
||||
volumeName={cephfsName}
|
||||
/>
|
||||
));
|
||||
|
||||
expect(result.container).toMatchSnapshot();
|
||||
expect(result.getByTestId("cephfs-readonly")).toHaveTextContent("true");
|
||||
});
|
||||
});
|
||||
@@ -10,7 +10,7 @@ import type { VolumeVariantComponent } from "../variant-helpers";
|
||||
import { LocalRef } from "../variant-helpers";
|
||||
|
||||
export const CephFs: VolumeVariantComponent<"cephfs"> = (
|
||||
({ pod, variant: { monitors, path = "/", user = "admin", secretFile = "/etc/ceph/user.secret", secretRef, readOnly }}) => (
|
||||
({ pod, variant: { monitors, path = "/", user = "admin", secretFile = "/etc/ceph/user.secret", secretRef, readOnly = false }}) => (
|
||||
<>
|
||||
<DrawerItem name="Monitors">
|
||||
<ul>
|
||||
@@ -39,7 +39,7 @@ export const CephFs: VolumeVariantComponent<"cephfs"> = (
|
||||
</DrawerItem>
|
||||
)
|
||||
}
|
||||
<DrawerItem name="Readonly">
|
||||
<DrawerItem name="Readonly" data-testid="cephfs-readonly">
|
||||
{readOnly.toString()}
|
||||
</DrawerItem>
|
||||
</>
|
||||
|
||||
@@ -0,0 +1,197 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { render } from "@testing-library/react";
|
||||
import React from "react";
|
||||
import type { ProjectedSource } from "../../../../../../common/k8s-api/endpoints";
|
||||
import { Pod } from "../../../../../../common/k8s-api/endpoints";
|
||||
import { Projected } from "./projected";
|
||||
|
||||
describe("<Projected />", () => {
|
||||
it("renders", () => {
|
||||
const projectedVolume: ProjectedSource = { };
|
||||
const projectedVolumeName = "my-projected";
|
||||
const pod = new Pod({
|
||||
apiVersion: "v1",
|
||||
kind: "Pod",
|
||||
metadata: {
|
||||
name: "my-pod",
|
||||
namespace: "default",
|
||||
resourceVersion: "1",
|
||||
uid: "123",
|
||||
selfLink: "/api/v1/pod/default/my-pod",
|
||||
},
|
||||
spec: {
|
||||
volumes: [{
|
||||
name: projectedVolumeName,
|
||||
projected: projectedVolume,
|
||||
}],
|
||||
},
|
||||
});
|
||||
const result = render((
|
||||
<Projected
|
||||
pod={pod}
|
||||
volumeName={projectedVolumeName}
|
||||
variant={projectedVolume}
|
||||
/>
|
||||
));
|
||||
|
||||
expect(result.baseElement).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("renders default mount mode in octal when provided", () => {
|
||||
const projectedVolume: ProjectedSource = {
|
||||
defaultMode: 0o777,
|
||||
sources: [],
|
||||
};
|
||||
const projectedVolumeName = "my-projected";
|
||||
const pod = new Pod({
|
||||
apiVersion: "v1",
|
||||
kind: "Pod",
|
||||
metadata: {
|
||||
name: "my-pod",
|
||||
namespace: "default",
|
||||
resourceVersion: "1",
|
||||
uid: "123",
|
||||
selfLink: "/api/v1/pod/default/my-pod",
|
||||
},
|
||||
spec: {
|
||||
volumes: [{
|
||||
name: projectedVolumeName,
|
||||
projected: projectedVolume,
|
||||
}],
|
||||
},
|
||||
});
|
||||
const result = render((
|
||||
<Projected
|
||||
pod={pod}
|
||||
volumeName={projectedVolumeName}
|
||||
variant={projectedVolume}
|
||||
/>
|
||||
));
|
||||
|
||||
expect(result.baseElement).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("renders when no sources array provided", () => {
|
||||
const projectedVolume: ProjectedSource = {
|
||||
defaultMode: 0o777,
|
||||
};
|
||||
const projectedVolumeName = "my-projected";
|
||||
const pod = new Pod({
|
||||
apiVersion: "v1",
|
||||
kind: "Pod",
|
||||
metadata: {
|
||||
name: "my-pod",
|
||||
namespace: "default",
|
||||
resourceVersion: "1",
|
||||
uid: "123",
|
||||
selfLink: "/api/v1/pod/default/my-pod",
|
||||
},
|
||||
spec: {
|
||||
volumes: [{
|
||||
name: projectedVolumeName,
|
||||
projected: projectedVolume,
|
||||
}],
|
||||
},
|
||||
});
|
||||
const result = render((
|
||||
<Projected
|
||||
pod={pod}
|
||||
volumeName={projectedVolumeName}
|
||||
variant={projectedVolume}
|
||||
/>
|
||||
));
|
||||
|
||||
expect(result.baseElement).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("renders a secret source, when provided", () => {
|
||||
const projectedVolume: ProjectedSource = {
|
||||
defaultMode: 0o777,
|
||||
sources: [{
|
||||
secret: {
|
||||
name: "my-projected-secret",
|
||||
items: [{
|
||||
key: "foo",
|
||||
path: "/bar",
|
||||
}],
|
||||
},
|
||||
}],
|
||||
};
|
||||
const projectedVolumeName = "my-projected";
|
||||
const pod = new Pod({
|
||||
apiVersion: "v1",
|
||||
kind: "Pod",
|
||||
metadata: {
|
||||
name: "my-pod",
|
||||
namespace: "default",
|
||||
resourceVersion: "1",
|
||||
uid: "123",
|
||||
selfLink: "/api/v1/pod/default/my-pod",
|
||||
},
|
||||
spec: {
|
||||
volumes: [{
|
||||
name: projectedVolumeName,
|
||||
projected: projectedVolume,
|
||||
}],
|
||||
},
|
||||
});
|
||||
const result = render((
|
||||
<Projected
|
||||
pod={pod}
|
||||
volumeName={projectedVolumeName}
|
||||
variant={projectedVolume}
|
||||
/>
|
||||
));
|
||||
|
||||
expect(result.baseElement).toMatchSnapshot();
|
||||
expect(result.getByText("foo⇢/bar", { exact: false })).toBeTruthy();
|
||||
});
|
||||
|
||||
it("renders a secret source including overriding mode", () => {
|
||||
const projectedVolume: ProjectedSource = {
|
||||
defaultMode: 0o777,
|
||||
sources: [{
|
||||
secret: {
|
||||
name: "my-projected-secret",
|
||||
items: [{
|
||||
key: "foo",
|
||||
path: "/bar",
|
||||
mode: 0o666,
|
||||
}],
|
||||
},
|
||||
}],
|
||||
};
|
||||
const projectedVolumeName = "my-projected";
|
||||
const pod = new Pod({
|
||||
apiVersion: "v1",
|
||||
kind: "Pod",
|
||||
metadata: {
|
||||
name: "my-pod",
|
||||
namespace: "default",
|
||||
resourceVersion: "1",
|
||||
uid: "123",
|
||||
selfLink: "/api/v1/pod/default/my-pod",
|
||||
},
|
||||
spec: {
|
||||
volumes: [{
|
||||
name: projectedVolumeName,
|
||||
projected: projectedVolume,
|
||||
}],
|
||||
},
|
||||
});
|
||||
const result = render((
|
||||
<Projected
|
||||
pod={pod}
|
||||
volumeName={projectedVolumeName}
|
||||
variant={projectedVolume}
|
||||
/>
|
||||
));
|
||||
|
||||
expect(result.baseElement).toMatchSnapshot();
|
||||
expect(result.getByText("(0o666)", { exact: false })).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@@ -4,18 +4,21 @@
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import { displayMode } from "../../../../../utils";
|
||||
import { DrawerItem, DrawerTitle } from "../../../../drawer";
|
||||
import type { VolumeVariantComponent } from "../variant-helpers";
|
||||
|
||||
export const Projected: VolumeVariantComponent<"projected"> = (
|
||||
({ variant: { sources, defaultMode }}) => (
|
||||
<>
|
||||
<DrawerItem name="Default Mount Mode">
|
||||
{`0o${defaultMode.toString(8)}`}
|
||||
</DrawerItem>
|
||||
{typeof defaultMode === "number" && (
|
||||
<DrawerItem name="Default Mount Mode">
|
||||
{displayMode(defaultMode)}
|
||||
</DrawerItem>
|
||||
)}
|
||||
<DrawerItem name="Sources">
|
||||
{
|
||||
sources.map(({ secret, downwardAPI, configMap, serviceAccountToken }, index) => (
|
||||
sources?.map(({ secret, downwardAPI, configMap, serviceAccountToken }, index) => (
|
||||
<React.Fragment key={index}>
|
||||
{secret && (
|
||||
<>
|
||||
@@ -25,9 +28,12 @@ export const Projected: VolumeVariantComponent<"projected"> = (
|
||||
</DrawerItem>
|
||||
<DrawerItem name="Items">
|
||||
<ul>
|
||||
{secret.items?.map(({ key, path }) => (
|
||||
{secret.items?.map(({ key, path, mode }) => (
|
||||
<li key={key}>
|
||||
{`${key}⇢${path}`}
|
||||
{typeof mode === "number" && (
|
||||
` (${displayMode(mode)})`
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
||||
@@ -8,6 +8,8 @@ import React from "react";
|
||||
import { observable, makeObservable } from "mobx";
|
||||
import { observer } from "mobx-react";
|
||||
import { cssNames, noop } from "../../utils";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import requestAnimationFrameInjectable from "./request-animation-frame.injectable";
|
||||
|
||||
export type AnimateName = "opacity" | "slide-right" | "opacity-scale" | string;
|
||||
|
||||
@@ -21,8 +23,12 @@ export interface AnimateProps {
|
||||
children?: React.ReactNode;
|
||||
}
|
||||
|
||||
interface Dependencies {
|
||||
requestAnimationFrame: (callback: () => void) => void;
|
||||
}
|
||||
|
||||
@observer
|
||||
class DefaultedAnimate extends React.Component<AnimateProps & typeof DefaultedAnimate.defaultProps> {
|
||||
class DefaultedAnimate extends React.Component<AnimateProps & Dependencies & typeof DefaultedAnimate.defaultProps> {
|
||||
static defaultProps = {
|
||||
name: "opacity",
|
||||
enter: true,
|
||||
@@ -38,7 +44,7 @@ class DefaultedAnimate extends React.Component<AnimateProps & typeof DefaultedAn
|
||||
leave: false,
|
||||
};
|
||||
|
||||
constructor(props: AnimateProps & typeof DefaultedAnimate.defaultProps) {
|
||||
constructor(props: AnimateProps & Dependencies & typeof DefaultedAnimate.defaultProps) {
|
||||
super(props);
|
||||
makeObservable(this);
|
||||
}
|
||||
@@ -69,7 +75,8 @@ class DefaultedAnimate extends React.Component<AnimateProps & typeof DefaultedAn
|
||||
|
||||
enter() {
|
||||
this.isVisible = true; // triggers render() to apply css-animation in existing dom
|
||||
requestAnimationFrame(() => {
|
||||
|
||||
this.props.requestAnimationFrame(() => {
|
||||
this.statusClassName.enter = true;
|
||||
this.props.onEnter();
|
||||
});
|
||||
@@ -115,4 +122,17 @@ class DefaultedAnimate extends React.Component<AnimateProps & typeof DefaultedAn
|
||||
}
|
||||
}
|
||||
|
||||
export const Animate = (props: AnimateProps) => <DefaultedAnimate {...props} />;
|
||||
export const NonInjectedAnimate = (props: AnimateProps & Dependencies) => <DefaultedAnimate {...props} />;
|
||||
|
||||
export const Animate = withInjectables<Dependencies, AnimateProps>(
|
||||
NonInjectedAnimate,
|
||||
|
||||
{
|
||||
getProps: (di, props) => ({
|
||||
requestAnimationFrame: di.inject(requestAnimationFrameInjectable),
|
||||
...props,
|
||||
}),
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
|
||||
const requestAnimationFrameInjectable = getInjectable({
|
||||
id: "request-animation-frame",
|
||||
instantiate: () => (callback: () => void) => requestAnimationFrame(callback),
|
||||
causesSideEffects: true,
|
||||
});
|
||||
|
||||
export default requestAnimationFrameInjectable;
|
||||
@@ -12,12 +12,14 @@
|
||||
@import "./fonts";
|
||||
|
||||
:root {
|
||||
--flex-gap: #{$padding};
|
||||
--unit: 8px;
|
||||
--padding: var(--unit);
|
||||
--margin: var(--unit);
|
||||
--border-radius: 3px;
|
||||
--font-main: 'Roboto', 'Helvetica', 'Arial', sans-serif;
|
||||
--font-monospace: Lucida Console, Monaco, Consolas, monospace;
|
||||
--font-monospace: Lucida Console, Monaco, Consolas, monospace; // some defaults
|
||||
--font-terminal: var(--font-monospace); // overridden in terminal.ts, managed by common/user-store.ts
|
||||
--font-size-small: calc(1.5 * var(--unit));
|
||||
--font-size: calc(1.75 * var(--unit));
|
||||
--font-size-big: calc(2 * var(--unit));
|
||||
@@ -63,16 +65,13 @@
|
||||
color: var(--textColorAccent);
|
||||
}
|
||||
|
||||
html {
|
||||
font-size: 62.5%; // 1 rem == 10px
|
||||
color: var(--textColorPrimary);
|
||||
background-color: var(--mainBackground);
|
||||
--flex-gap: #{$padding};
|
||||
}
|
||||
|
||||
html, body {
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
color: var(--textColorPrimary);
|
||||
background-color: var(--mainBackground);
|
||||
font-size: var(--font-size);
|
||||
font-family: var(--font-main);
|
||||
}
|
||||
|
||||
#terminal-init {
|
||||
@@ -93,10 +92,6 @@ html, body {
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
font: $font-size $font-main;
|
||||
}
|
||||
|
||||
fieldset {
|
||||
border: 0;
|
||||
padding: 0;
|
||||
@@ -227,6 +222,22 @@ a {
|
||||
}
|
||||
}
|
||||
|
||||
#fonts-preloading {
|
||||
> span {
|
||||
position: absolute;
|
||||
visibility: hidden;
|
||||
height: 0;
|
||||
|
||||
&:before {
|
||||
width: 0;
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
content: "text-example"; // some text required to start applying/rendering font in document
|
||||
font-family: inherit; // font-family must be specified via style="" (see: template.html)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// app's common loading indicator, displaying on the route transitions
|
||||
#loading {
|
||||
position: absolute;
|
||||
|
||||
@@ -45,7 +45,6 @@ export class ClusterFrameHandler {
|
||||
|
||||
iframe.id = `cluster-frame-${cluster.id}`;
|
||||
iframe.name = cluster.contextName;
|
||||
iframe.style.display = "none";
|
||||
iframe.setAttribute("src", getClusterFrameUrl(clusterId));
|
||||
iframe.addEventListener("load", action(() => {
|
||||
logger.info(`[LENS-VIEW]: frame for clusterId=${clusterId} has loaded`);
|
||||
@@ -95,7 +94,7 @@ export class ClusterFrameHandler {
|
||||
ipcRenderer.send(clusterVisibilityHandler);
|
||||
|
||||
for (const { frame: view } of this.views.values()) {
|
||||
view.style.display = "none";
|
||||
view.classList.add("hidden");
|
||||
}
|
||||
|
||||
const cluster = clusterId
|
||||
@@ -113,9 +112,9 @@ export class ClusterFrameHandler {
|
||||
|
||||
return undefined;
|
||||
},
|
||||
(view) => {
|
||||
(view: LensView) => {
|
||||
logger.info(`[LENS-VIEW]: cluster id=${clusterId} should now be visible`);
|
||||
view.frame.style.display = "flex";
|
||||
view.frame.classList.remove("hidden");
|
||||
ipcRenderer.send(clusterVisibilityHandler, clusterId);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -35,7 +35,20 @@
|
||||
background-color: var(--mainBackground);
|
||||
|
||||
iframe {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex: 1;
|
||||
|
||||
// when updating font settings in the "Preferences -> Terminal" cluster's iframe
|
||||
// must be accessible in DOM (e.g. elem.getBoundingClientRect() must work)
|
||||
&.hidden {
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-2
@@ -26,6 +26,9 @@ import { computed } from "mobx";
|
||||
import { routeSpecificComponentInjectionToken } from "../../../routes/route-specific-component-injection-token";
|
||||
import { navigateToRouteInjectionToken } from "../../../../common/front-end-routing/navigate-to-route-injection-token";
|
||||
import hotbarStoreInjectable from "../../../../common/hotbars/store.injectable";
|
||||
import normalizedPlatformInjectable from "../../../../common/vars/normalized-platform.injectable";
|
||||
import kubectlBinaryNameInjectable from "../../../../main/kubectl/binary-name.injectable";
|
||||
import kubectlDownloadingNormalizedArchInjectable from "../../../../main/kubectl/normalized-arch.injectable";
|
||||
|
||||
jest.mock("electron", () => ({
|
||||
app: {
|
||||
@@ -101,8 +104,11 @@ describe("<DeleteClusterDialog />", () => {
|
||||
applicationBuilder = getApplicationBuilder();
|
||||
|
||||
applicationBuilder.beforeApplicationStart(({ mainDi, rendererDi }) => {
|
||||
mainDi.override(createContextHandlerInjectable, () => () => undefined as any);
|
||||
mainDi.override(createKubeconfigManagerInjectable, () => () => undefined as any);
|
||||
mainDi.override(createContextHandlerInjectable, () => () => undefined as never);
|
||||
mainDi.override(createKubeconfigManagerInjectable, () => () => undefined as never);
|
||||
mainDi.override(kubectlBinaryNameInjectable, () => "kubectl");
|
||||
mainDi.override(kubectlDownloadingNormalizedArchInjectable, () => "amd64");
|
||||
mainDi.override(normalizedPlatformInjectable, () => "darwin");
|
||||
|
||||
rendererDi.override(hotbarStoreInjectable, () => ({}));
|
||||
rendererDi.override(storesAndApisCanBeCreatedInjectable, () => true);
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
import directoryForUserDataInjectable from "../../../../common/app-paths/directory-for-user-data/directory-for-user-data.injectable";
|
||||
import hostedClusterIdInjectable from "../../../../common/cluster-store/hosted-cluster-id.injectable";
|
||||
import ipcRendererInjectable from "../../../app-paths/get-value-from-registered-channel/ipc-renderer/ipc-renderer.injectable";
|
||||
import { getDiForUnitTesting } from "../../../getDiForUnitTesting";
|
||||
import type { DockStore, DockTab } from "../dock/store";
|
||||
import { TabKind } from "../dock/store";
|
||||
@@ -26,10 +25,6 @@ describe("DockStore", () => {
|
||||
const di = getDiForUnitTesting({ doGeneralOverrides: true });
|
||||
|
||||
di.override(hostedClusterIdInjectable, () => "some-cluster-id");
|
||||
di.override(ipcRendererInjectable, () => ({
|
||||
on: jest.fn(),
|
||||
invoke: jest.fn(), // TODO: replace with proper mocking via the IPC bridge
|
||||
} as never));
|
||||
di.override(directoryForUserDataInjectable, () => "some-directory-for-user-data");
|
||||
|
||||
dockStore = di.inject(dockStoreInjectable);
|
||||
|
||||
@@ -20,7 +20,6 @@ import getConfigurationFileModelInjectable from "../../../../common/get-configur
|
||||
import appVersionInjectable from "../../../../common/get-configuration-file-model/app-version/app-version.injectable";
|
||||
import assert from "assert";
|
||||
import hostedClusterIdInjectable from "../../../../common/cluster-store/hosted-cluster-id.injectable";
|
||||
import ipcRendererInjectable from "../../../app-paths/get-value-from-registered-channel/ipc-renderer/ipc-renderer.injectable";
|
||||
|
||||
jest.mock("electron", () => ({
|
||||
app: {
|
||||
@@ -83,10 +82,6 @@ describe("<DockTabs />", () => {
|
||||
directoryForUserDataInjectable,
|
||||
() => "some-test-suite-specific-directory-for-user-data",
|
||||
);
|
||||
di.override(ipcRendererInjectable, () => ({
|
||||
on: jest.fn(),
|
||||
invoke: jest.fn(), // TODO: replace with proper mocking via the IPC bridge
|
||||
} as never));
|
||||
|
||||
di.permitSideEffects(getConfigurationFileModelInjectable);
|
||||
di.permitSideEffects(appVersionInjectable);
|
||||
|
||||
@@ -166,11 +166,7 @@ class NonInjectedDock extends React.Component<DockProps & Dependencies> {
|
||||
closeOnScroll={false}
|
||||
>
|
||||
<MenuItem className="create-terminal-tab" onClick={() => this.props.createTerminalTab()}>
|
||||
<Icon
|
||||
small
|
||||
svg="terminal"
|
||||
size={15}
|
||||
/>
|
||||
<Icon small material="terminal" />
|
||||
Terminal session
|
||||
</MenuItem>
|
||||
<MenuItem className="create-resource-tab" onClick={() => this.props.createResourceTab()}>
|
||||
|
||||
@@ -22,7 +22,6 @@ import { SearchStore } from "../../../../search-store/search-store";
|
||||
import getConfigurationFileModelInjectable from "../../../../../common/get-configuration-file-model/get-configuration-file-model.injectable";
|
||||
import appVersionInjectable from "../../../../../common/get-configuration-file-model/app-version/app-version.injectable";
|
||||
import assert from "assert";
|
||||
import ipcRendererInjectable from "../../../../app-paths/get-value-from-registered-channel/ipc-renderer/ipc-renderer.injectable";
|
||||
|
||||
jest.mock("electron", () => ({
|
||||
app: {
|
||||
@@ -132,10 +131,6 @@ describe("<LogResourceSelector />", () => {
|
||||
|
||||
di.override(directoryForUserDataInjectable, () => "some-directory-for-user-data");
|
||||
di.override(callForLogsInjectable, () => () => Promise.resolve("some-logs"));
|
||||
di.override(ipcRendererInjectable, () => ({
|
||||
on: jest.fn(),
|
||||
invoke: jest.fn(), // TODO: replace with proper mocking via the IPC bridge
|
||||
} as never));
|
||||
|
||||
di.permitSideEffects(getConfigurationFileModelInjectable);
|
||||
di.permitSideEffects(appVersionInjectable);
|
||||
|
||||
@@ -67,7 +67,6 @@ class NonInjectedTerminalTab<Props extends TerminalTabProps & Dependencies> exte
|
||||
}
|
||||
|
||||
render() {
|
||||
const tabIcon = <Icon material="terminal"/>;
|
||||
const className = cssNames("TerminalTab", this.props.className, {
|
||||
disconnected: this.isDisconnected,
|
||||
});
|
||||
@@ -78,7 +77,7 @@ class NonInjectedTerminalTab<Props extends TerminalTabProps & Dependencies> exte
|
||||
<DockTab
|
||||
{...tabProps}
|
||||
className={className}
|
||||
icon={tabIcon}
|
||||
icon={<Icon material="terminal" />}
|
||||
moreActions={this.isDisconnected && (
|
||||
<Icon
|
||||
small
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { when } from "mobx";
|
||||
import { TerminalChannels } from "../../../../common/terminal/channels";
|
||||
import { waitUntilDefined } from "../../../../common/utils/wait";
|
||||
import type { TerminalApi } from "../../../api/terminal-api";
|
||||
import { TerminalChannels } from "../../../api/terminal-api";
|
||||
import { noop } from "../../../utils";
|
||||
import { Notifications } from "../../notifications";
|
||||
import selectDockTabInjectable from "../dock/select-dock-tab.injectable";
|
||||
|
||||
@@ -10,7 +10,6 @@ import { Terminal as XTerm } from "xterm";
|
||||
import { FitAddon } from "xterm-addon-fit";
|
||||
import type { TabId } from "../dock/store";
|
||||
import type { TerminalApi } from "../../../api/terminal-api";
|
||||
import { TerminalChannels } from "../../../api/terminal-api";
|
||||
import type { ThemeStore } from "../../../themes/store";
|
||||
import { disposer } from "../../../utils";
|
||||
import { isMac } from "../../../../common/vars";
|
||||
@@ -19,6 +18,7 @@ import { clipboard } from "electron";
|
||||
import logger from "../../../../common/logger";
|
||||
import type { TerminalConfig } from "../../../../common/user-store/preferences-helpers";
|
||||
import assert from "assert";
|
||||
import { TerminalChannels } from "../../../../common/terminal/channels";
|
||||
|
||||
export interface TerminalDependencies {
|
||||
readonly spawningPool: HTMLElement;
|
||||
@@ -64,16 +64,30 @@ export class Terminal {
|
||||
}
|
||||
}
|
||||
|
||||
constructor(protected readonly dependencies: TerminalDependencies, { tabId, api }: TerminalArguments) {
|
||||
get fontFamily() {
|
||||
return this.dependencies.terminalConfig.get().fontFamily;
|
||||
}
|
||||
|
||||
get fontSize() {
|
||||
return this.dependencies.terminalConfig.get().fontSize;
|
||||
}
|
||||
|
||||
get theme(): Record<string/*paramName*/, string/*color*/> {
|
||||
return this.dependencies.themeStore.xtermColors;
|
||||
}
|
||||
|
||||
constructor(protected readonly dependencies: TerminalDependencies, {
|
||||
tabId,
|
||||
api,
|
||||
}: TerminalArguments) {
|
||||
this.tabId = tabId;
|
||||
this.api = api;
|
||||
const { fontSize, fontFamily } = this.dependencies.terminalConfig.get();
|
||||
|
||||
this.xterm = new XTerm({
|
||||
cursorBlink: true,
|
||||
cursorStyle: "bar",
|
||||
fontSize,
|
||||
fontFamily,
|
||||
fontSize: this.fontSize,
|
||||
fontFamily: this.fontFamily,
|
||||
});
|
||||
// enable terminal addons
|
||||
this.xterm.loadAddon(this.fitAddon);
|
||||
@@ -95,17 +109,11 @@ export class Terminal {
|
||||
window.addEventListener("resize", this.onResize);
|
||||
|
||||
this.disposer.push(
|
||||
reaction(() => this.dependencies.themeStore.xtermColors, colors => {
|
||||
this.xterm?.setOption("theme", colors);
|
||||
}, {
|
||||
fireImmediately: true,
|
||||
}),
|
||||
reaction(() => this.dependencies.terminalConfig.get().fontSize, this.setFontSize, {
|
||||
fireImmediately: true,
|
||||
}),
|
||||
reaction(() => this.dependencies.terminalConfig.get().fontFamily, this.setFontFamily, {
|
||||
reaction(() => this.theme, colors => this.xterm.setOption("theme", colors), {
|
||||
fireImmediately: true,
|
||||
}),
|
||||
reaction(() => this.fontSize, this.setFontSize, { fireImmediately: true }),
|
||||
reaction(() => this.fontFamily, this.setFontFamily, { fireImmediately: true }),
|
||||
() => onDataHandler.dispose(),
|
||||
() => this.fitAddon.dispose(),
|
||||
() => this.api.removeAllListeners(),
|
||||
@@ -120,15 +128,14 @@ export class Terminal {
|
||||
}
|
||||
|
||||
fit = () => {
|
||||
// Since this function is debounced we need to read this value as late as possible
|
||||
if (!this.xterm) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
this.fitAddon.fit();
|
||||
const { cols, rows } = this.xterm;
|
||||
const { cols, rows } = this.fitAddon.proposeDimensions();
|
||||
|
||||
// attempt to resize/fit terminal when it's not visible in DOM will crash with exception
|
||||
// see: https://github.com/xtermjs/xterm.js/issues/3118
|
||||
if (isNaN(cols) || isNaN(rows)) return;
|
||||
|
||||
this.fitAddon.fit();
|
||||
this.api.sendTerminalSize(cols, rows);
|
||||
} catch (error) {
|
||||
// see https://github.com/lensapp/lens/issues/1891
|
||||
@@ -197,12 +204,21 @@ export class Terminal {
|
||||
}
|
||||
};
|
||||
|
||||
setFontSize = (size: number) => {
|
||||
this.xterm.options.fontSize = size;
|
||||
setFontSize = (fontSize: number) => {
|
||||
logger.info(`[TERMINAL]: set fontSize to ${fontSize}`);
|
||||
|
||||
this.xterm.options.fontSize = fontSize;
|
||||
this.fit();
|
||||
};
|
||||
|
||||
setFontFamily = (family: string) => {
|
||||
this.xterm.options.fontFamily = family;
|
||||
setFontFamily = (fontFamily: string) => {
|
||||
logger.info(`[TERMINAL]: set fontFamily to ${fontFamily}`);
|
||||
|
||||
this.xterm.options.fontFamily = fontFamily;
|
||||
this.fit();
|
||||
|
||||
// provide css-variable within `:root {}`
|
||||
document.documentElement.style.setProperty("--font-terminal", fontFamily);
|
||||
};
|
||||
|
||||
keyHandler = (evt: KeyboardEvent): boolean => {
|
||||
|
||||
@@ -5,14 +5,20 @@
|
||||
|
||||
import "./drawer-item.scss";
|
||||
import React from "react";
|
||||
import { cssNames, displayBooleans } from "../../utils";
|
||||
import { cssNames } from "../../utils";
|
||||
|
||||
export interface DrawerItemProps extends React.HTMLAttributes<HTMLDivElement> {
|
||||
name: React.ReactNode;
|
||||
title?: string;
|
||||
labelsOnly?: boolean;
|
||||
hidden?: boolean;
|
||||
renderBoolean?: boolean; // show "true" or "false" for all of the children elements are "typeof boolean"
|
||||
|
||||
/**
|
||||
* @deprecated This prop is no longer used, you should stringify the booleans yourself.
|
||||
*
|
||||
* This was only meant to be an internal prop anyway.
|
||||
*/
|
||||
renderBooleans?: boolean;
|
||||
}
|
||||
|
||||
export function DrawerItem({
|
||||
@@ -22,7 +28,6 @@ export function DrawerItem({
|
||||
children,
|
||||
hidden = false,
|
||||
className,
|
||||
renderBoolean,
|
||||
...elemProps
|
||||
}: DrawerItemProps) {
|
||||
if (hidden) {
|
||||
@@ -36,7 +41,7 @@ export function DrawerItem({
|
||||
title={title}
|
||||
>
|
||||
<span className="name">{name}</span>
|
||||
<span className="value">{displayBooleans(renderBoolean, children)}</span>
|
||||
<span className="value">{children}</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -9,7 +9,12 @@ import { cssNames } from "../../utils";
|
||||
|
||||
export interface DrawerTitleProps {
|
||||
className?: string;
|
||||
children: React.ReactNode;
|
||||
children?: React.ReactNode;
|
||||
|
||||
/**
|
||||
* @deprecated Prefer passing the value as `children`
|
||||
*/
|
||||
title?: React.ReactNode;
|
||||
|
||||
/**
|
||||
* Specifies how large this title is
|
||||
|
||||
@@ -3,34 +3,99 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
// Custom fonts
|
||||
@import "~typeface-roboto/index.css";
|
||||
// App's main font
|
||||
// Downloaded from: https://fonts.google.com/specimen/Roboto
|
||||
@font-face {
|
||||
font-family: "Roboto";
|
||||
src: url("../fonts/Roboto-Light.ttf") format("truetype");
|
||||
font-display: swap;
|
||||
font-weight: 300; // "light"
|
||||
}
|
||||
|
||||
// Material Design Icons, used primarily in icon.tsx
|
||||
// Latest: https://github.com/google/material-design-icons/tree/master/font
|
||||
@font-face {
|
||||
font-family: "Roboto";
|
||||
src: url("../fonts/Roboto-LightItalic.ttf") format("truetype");
|
||||
font-display: swap;
|
||||
font-weight: 300; // "light" + italic
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "Roboto";
|
||||
src: url("../fonts/Roboto-Regular.ttf") format("truetype");
|
||||
font-display: swap;
|
||||
font-weight: 400; // "normal"
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "Roboto";
|
||||
src: url("../fonts/Roboto-Bold.ttf") format("truetype");
|
||||
font-display: swap;
|
||||
font-weight: 700; // "bold"
|
||||
}
|
||||
|
||||
|
||||
// Icon fonts, see: `icon.tsx`
|
||||
// Latest version for manual update: https://github.com/google/material-design-icons/tree/master/font
|
||||
@font-face {
|
||||
font-family: "Material Icons";
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
font-display: block;
|
||||
src: url("./fonts/MaterialIcons-Regular.ttf") format("truetype");
|
||||
src: url("../fonts/MaterialIcons-Regular.ttf") format("truetype");
|
||||
}
|
||||
|
||||
|
||||
// Terminal fonts (monospaced)
|
||||
// Source: https://fonts.google.com/?category=Monospace
|
||||
@font-face {
|
||||
font-family: "Anonymous Pro";
|
||||
src: local("Anonymous Pro"), url("../fonts/AnonymousPro-Regular.ttf") format("truetype");
|
||||
font-display: block;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "IBM Plex Mono";
|
||||
src: local("IBM Plex Mono"), url("../fonts/IBMPlexMono-Regular.ttf") format("truetype");
|
||||
font-display: block;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "JetBrains Mono";
|
||||
src: local("JetBrains Mono"), url("../fonts/JetBrainsMono-Regular.ttf") format("truetype");
|
||||
font-display: block;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "Red Hat Mono";
|
||||
src: local("Red Hat Mono"), url("../fonts/RedHatMono-Regular.ttf") format("truetype");
|
||||
font-display: block;
|
||||
}
|
||||
|
||||
|
||||
@font-face {
|
||||
font-family: "Source Code Pro";
|
||||
src: local("Source Code Pro"), url("../fonts/SourceCodePro-Regular.ttf") format("truetype");
|
||||
font-display: block;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "Space Mono";
|
||||
src: local("Space Mono"), url("../fonts/SpaceMono-Regular.ttf") format("truetype");
|
||||
font-display: block;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: "Ubuntu Mono";
|
||||
src: local("Ubuntu Mono"), url("../fonts/UbuntuMono-Regular.ttf") format("truetype");
|
||||
font-display: block;
|
||||
}
|
||||
|
||||
// Patched RobotoMono font with icons
|
||||
// RobotoMono Windows Compatible for using in terminal
|
||||
// https://github.com/ryanoasis/nerd-fonts/tree/master/patched-fonts/RobotoMono
|
||||
@font-face {
|
||||
font-family: 'RobotoMono';
|
||||
font-family: "RobotoMono";
|
||||
src: local("RobotoMono"), url("../fonts/Roboto-Mono-nerd.ttf") format("truetype");
|
||||
font-display: block;
|
||||
src: local('RobotoMono'), url('./fonts/roboto-mono-nerd.ttf') format('truetype');
|
||||
}
|
||||
|
||||
#fonts-preloading {
|
||||
> .icons {
|
||||
@include font-preload("Material Icons");
|
||||
}
|
||||
|
||||
> .terminal {
|
||||
@include font-preload("RobotoMono");
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -19,7 +19,6 @@ import getConfigurationFileModelInjectable from "../../../../common/get-configur
|
||||
import appVersionInjectable from "../../../../common/get-configuration-file-model/app-version/app-version.injectable";
|
||||
import type { HotbarStore } from "../../../../common/hotbars/store";
|
||||
import storesAndApisCanBeCreatedInjectable from "../../../stores-apis-can-be-created.injectable";
|
||||
import ipcRendererInjectable from "../../../app-paths/get-value-from-registered-channel/ipc-renderer/ipc-renderer.injectable";
|
||||
|
||||
const mockHotbars: Partial<Record<string, any>> = {
|
||||
"1": {
|
||||
@@ -47,10 +46,6 @@ describe("<HotbarRemoveCommand />", () => {
|
||||
|
||||
di.override(storesAndApisCanBeCreatedInjectable, () => true);
|
||||
di.override(directoryForUserDataInjectable, () => "some-directory-for-user-data");
|
||||
di.override(ipcRendererInjectable, () => ({
|
||||
on: jest.fn(),
|
||||
invoke: jest.fn(), // TODO: replace with proper mocking via the IPC bridge
|
||||
} as never));
|
||||
|
||||
di.permitSideEffects(hotbarStoreInjectable);
|
||||
di.permitSideEffects(getConfigurationFileModelInjectable);
|
||||
|
||||
@@ -12,7 +12,59 @@ import type { LocationDescriptor } from "history";
|
||||
import { cssNames } from "../../utils";
|
||||
import { withTooltip } from "../tooltip";
|
||||
import isNumber from "lodash/isNumber";
|
||||
import { decode } from "../../../common/utils/base64";
|
||||
import Configuration from "./configuration.svg";
|
||||
import Crane from "./crane.svg";
|
||||
import Group from "./group.svg";
|
||||
import Helm from "./helm.svg";
|
||||
import Install from "./install.svg";
|
||||
import Kube from "./kube.svg";
|
||||
import LensLogo from "./lens-logo.svg";
|
||||
import License from "./license.svg";
|
||||
import LogoLens from "./logo-lens.svg";
|
||||
import Logout from "./logout.svg";
|
||||
import Nodes from "./nodes.svg";
|
||||
import PushOff from "./push_off.svg";
|
||||
import PushPin from "./push_pin.svg";
|
||||
import Spinner from "./spinner.svg";
|
||||
import Ssh from "./ssh.svg";
|
||||
import Storage from "./storage.svg";
|
||||
import Terminal from "./terminal.svg";
|
||||
import Notice from "./notice.svg";
|
||||
import User from "./user.svg";
|
||||
import Users from "./users.svg";
|
||||
import Wheel from "./wheel.svg";
|
||||
import Workloads from "./workloads.svg";
|
||||
|
||||
/**
|
||||
* Mapping between the local file names and the svgs
|
||||
*
|
||||
* Because we only really want a fixed list of bundled icons, this is safer so that consumers of
|
||||
* `<Icon>` cannot pass in a `../some/path`.
|
||||
*/
|
||||
const localSvgIcons = new Map([
|
||||
["configuration", Configuration],
|
||||
["crane", Crane],
|
||||
["group", Group],
|
||||
["helm", Helm],
|
||||
["install", Install],
|
||||
["kube", Kube],
|
||||
["lens-logo", LensLogo],
|
||||
["license", License],
|
||||
["logo-lens", LogoLens],
|
||||
["logout", Logout],
|
||||
["nodes", Nodes],
|
||||
["push_off", PushOff],
|
||||
["push_pin", PushPin],
|
||||
["spinner", Spinner],
|
||||
["ssh", Ssh],
|
||||
["storage", Storage],
|
||||
["terminal", Terminal],
|
||||
["notice", Notice],
|
||||
["user", User],
|
||||
["users", Users],
|
||||
["wheel", Wheel],
|
||||
["workloads", Workloads],
|
||||
]);
|
||||
|
||||
export interface BaseIconProps {
|
||||
/**
|
||||
@@ -21,7 +73,28 @@ export interface BaseIconProps {
|
||||
material?: string;
|
||||
|
||||
/**
|
||||
* Either an SVG data URL or one of the following strings
|
||||
* Either an SVG XML or one of the following names
|
||||
* - configuration
|
||||
* - crane
|
||||
* - group
|
||||
* - helm
|
||||
* - install
|
||||
* - kube
|
||||
* - lens-logo
|
||||
* - license
|
||||
* - logo-lens
|
||||
* - logout
|
||||
* - nodes
|
||||
* - push_off
|
||||
* - push_pin
|
||||
* - spinner
|
||||
* - ssh
|
||||
* - storage
|
||||
* - terminal
|
||||
* - user
|
||||
* - users
|
||||
* - wheel
|
||||
* - workloads
|
||||
*/
|
||||
svg?: string;
|
||||
|
||||
@@ -78,8 +151,8 @@ export interface BaseIconProps {
|
||||
export interface IconProps extends React.HTMLAttributes<any>, BaseIconProps {}
|
||||
|
||||
export function isSvg(content: string): boolean {
|
||||
// data-url for raw svg-icon
|
||||
return String(content).includes("svg+xml");
|
||||
// source code of the asset
|
||||
return String(content).includes("<svg");
|
||||
}
|
||||
|
||||
const RawIcon = withTooltip((props: IconProps) => {
|
||||
@@ -131,13 +204,16 @@ const RawIcon = withTooltip((props: IconProps) => {
|
||||
|
||||
// render as inline svg-icon
|
||||
if (typeof svg === "string") {
|
||||
const dataUrlPrefix = "data:image/svg+xml;base64,";
|
||||
const svgIconDataUrl = svg.startsWith(dataUrlPrefix) ? svg : require(`./${svg}.svg`);
|
||||
const svgIconText = typeof svgIconDataUrl == "string" // decode xml from data-url
|
||||
? decode(svgIconDataUrl.replace(dataUrlPrefix, ""))
|
||||
: "";
|
||||
const svgIconText = isSvg(svg)
|
||||
? svg
|
||||
: localSvgIcons.get(svg) ?? "";
|
||||
|
||||
iconContent = <span className="icon" dangerouslySetInnerHTML={{ __html: svgIconText }} />;
|
||||
iconContent = (
|
||||
<span
|
||||
className="icon"
|
||||
dangerouslySetInnerHTML={{ __html: svgIconText }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
// render as material-icon
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<svg xmlns:osb="http://www.openswatchbook.org/uri/2009/osb"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" sodipodi:docname="notice.svg" inkscape:version="1.0 (4035a4f, 2020-05-01)" id="notice" version="1.1" viewBox="0 0 135.46666 135.46666" height="512" width="512">
|
||||
<defs id="defs2">
|
||||
<rect id="rect2785" height="134.1693" width="135.23837" y="0.26726951" x="-0.53453903" />
|
||||
<linearGradient osb:paint="solid" id="linearGradient837">
|
||||
<stop id="stop835" offset="0" style="stop-color:#000000;stop-opacity:1;" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<sodipodi:namedview inkscape:window-maximized="0" inkscape:window-y="0" inkscape:window-x="0" inkscape:window-height="1080" inkscape:window-width="1920" inkscape:pagecheckerboard="true" units="px" showgrid="false" inkscape:document-rotation="0" inkscape:current-layer="layer1" inkscape:document-units="px" inkscape:cy="263.00246" inkscape:cx="240.74335" inkscape:zoom="2.0359339" inkscape:pageshadow="2" inkscape:pageopacity="0.0" borderopacity="1.0" bordercolor="#666666" pagecolor="#ffffff" id="base" />
|
||||
<metadata id="metadata5">
|
||||
<rdf:RDF>
|
||||
<cc:Work rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g id="layer1" inkscape:groupmode="layer" inkscape:label="Layer 1">
|
||||
<ellipse ry="59.764721" rx="59.764713" cy="67.73333" cx="67.733345" id="path10" style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:15.9372;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
|
||||
<path id="path2807" d="M 58.707956,29.522524 H 76.674473 L 76.739452,43.330427 73.23062,71.076192 62.054343,71.043701 58.740444,43.427894 Z" style="fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
|
||||
<rect y="83.204803" x="59.292759" height="14.815064" width="16.861885" id="rect2809" style="fill:#000000;fill-opacity:1;stroke:none;" />
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.3 KiB |
@@ -14,7 +14,6 @@ import { Tooltip } from "../tooltip";
|
||||
import * as Validators from "./input_validators";
|
||||
import type { InputValidator } from "./input_validators";
|
||||
import isFunction from "lodash/isFunction";
|
||||
import isBoolean from "lodash/isBoolean";
|
||||
import uniqueId from "lodash/uniqueId";
|
||||
import { debounce } from "lodash";
|
||||
|
||||
@@ -24,7 +23,10 @@ export { InputValidators };
|
||||
export type { InputValidator };
|
||||
|
||||
type InputElement = HTMLInputElement | HTMLTextAreaElement;
|
||||
type InputElementProps = InputHTMLAttributes<HTMLInputElement> & TextareaHTMLAttributes<HTMLTextAreaElement> & DOMAttributes<InputElement>;
|
||||
type InputElementProps =
|
||||
InputHTMLAttributes<HTMLInputElement>
|
||||
& TextareaHTMLAttributes<HTMLTextAreaElement>
|
||||
& DOMAttributes<InputElement>;
|
||||
|
||||
export interface IconDataFnArg {
|
||||
isDirty: boolean;
|
||||
@@ -173,22 +175,18 @@ export class Input extends React.Component<InputProps, State> {
|
||||
error => this.getValidatorError(value, validator) || error,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
if (!validator.validate(value, this.props)) {
|
||||
errors.push(this.getValidatorError(value, validator));
|
||||
}
|
||||
}
|
||||
|
||||
const result = validator.validate(value, this.props);
|
||||
const isValid = validator.validate(value, this.props);
|
||||
|
||||
if (isBoolean(result) && !result) {
|
||||
if (isValid === false) {
|
||||
errors.push(this.getValidatorError(value, validator));
|
||||
} else if (result instanceof Promise) {
|
||||
} else if (isValid instanceof Promise) {
|
||||
if (!validationId) {
|
||||
this.validationId = validationId = uniqueId("validation_id_");
|
||||
}
|
||||
asyncValidators.push(
|
||||
result.then(
|
||||
isValid.then(
|
||||
() => null, // don't consider any valid result from promise since we interested in errors only
|
||||
error => this.getValidatorError(value, validator) || error,
|
||||
),
|
||||
@@ -266,17 +264,25 @@ export class Input extends React.Component<InputProps, State> {
|
||||
|
||||
setDirtyOnChange = debounce(() => this.setDirty(), 500);
|
||||
|
||||
onChange(evt: React.ChangeEvent<any>) {
|
||||
this.props.onChange?.(evt.currentTarget.value, evt);
|
||||
this.validate();
|
||||
async onChange(evt: React.ChangeEvent<any>) {
|
||||
const newValue = evt.currentTarget.value;
|
||||
const eventCopy = { ...evt };
|
||||
|
||||
this.autoFitHeight();
|
||||
this.setDirtyOnChange();
|
||||
|
||||
// re-render component when used as uncontrolled input
|
||||
// when used @defaultValue instead of @value changing real input.value doesn't call render()
|
||||
if (this.isUncontrolled && this.showMaxLenIndicator) {
|
||||
this.forceUpdate();
|
||||
// Handle uncontrolled components (`props.defaultValue` must be used instead `value`)
|
||||
if (this.isUncontrolled) {
|
||||
// update DOM since render() is not called on input's changes with uncontrolled inputs
|
||||
if (this.showMaxLenIndicator) this.forceUpdate();
|
||||
|
||||
// don't propagate changes for invalid values
|
||||
await this.validate();
|
||||
if (!this.state.valid) return; // skip
|
||||
}
|
||||
|
||||
// emit new value update
|
||||
this.props.onChange?.(newValue, eventCopy);
|
||||
}
|
||||
|
||||
onKeyDown(evt: React.KeyboardEvent<InputElement>) {
|
||||
@@ -299,7 +305,7 @@ export class Input extends React.Component<InputProps, State> {
|
||||
this.setDirty();
|
||||
}
|
||||
|
||||
if(this.props.blurOnEnter){
|
||||
if (this.props.blurOnEnter) {
|
||||
//pressing enter indicates that the edit is complete, we can unfocus now
|
||||
this.blur();
|
||||
}
|
||||
@@ -379,7 +385,6 @@ export class Input extends React.Component<InputProps, State> {
|
||||
multiLine, showValidationLine, validators, theme, maxRows, children, showErrorsAsTooltip,
|
||||
maxLength, rows, disabled, autoSelectOnFocus, iconLeft, iconRight, contentRight, id,
|
||||
dirty: _dirty, // excluded from passing to input-element
|
||||
defaultValue,
|
||||
trim,
|
||||
blurOnEnter,
|
||||
...inputProps
|
||||
|
||||
@@ -8,7 +8,8 @@ import type { ReactNode } from "react";
|
||||
import fse from "fs-extra";
|
||||
import { TypedRegEx } from "typed-regex";
|
||||
|
||||
export class AsyncInputValidationError extends Error {}
|
||||
export class AsyncInputValidationError extends Error {
|
||||
}
|
||||
|
||||
export type InputValidator<IsAsync extends boolean> = {
|
||||
/**
|
||||
@@ -32,7 +33,7 @@ export type InputValidator<IsAsync extends boolean> = {
|
||||
message?: undefined;
|
||||
debounce: number;
|
||||
}
|
||||
);
|
||||
);
|
||||
|
||||
export function inputValidator<IsAsync extends boolean = false>(validator: InputValidator<IsAsync>): InputValidator<IsAsync> {
|
||||
return validator;
|
||||
@@ -52,7 +53,14 @@ export const isEmail = inputValidator({
|
||||
|
||||
export const isNumber = inputValidator({
|
||||
condition: ({ type }) => type === "number",
|
||||
message: () => `Invalid number`,
|
||||
message(value, { min, max }) {
|
||||
const minMax: string = [
|
||||
typeof min === "number" ? `min: ${min}` : undefined,
|
||||
typeof max === "number" ? `max: ${max}` : undefined,
|
||||
].filter(Boolean).join(", ");
|
||||
|
||||
return `Invalid number${minMax ? ` (${minMax})` : ""}`;
|
||||
},
|
||||
validate: (value, { min, max }) => {
|
||||
const numVal = +value;
|
||||
|
||||
|
||||
+124
@@ -130,6 +130,130 @@ exports[`kube-object-menu given kube object when removing kube object renders 1`
|
||||
</body>
|
||||
`;
|
||||
|
||||
exports[`kube-object-menu given kube object when rerendered with different kube object renders 1`] = `
|
||||
<body>
|
||||
<div>
|
||||
<div>
|
||||
<ul
|
||||
class="Menu MenuActions flex KubeObjectMenu toolbar gaps right bottom"
|
||||
>
|
||||
<li
|
||||
class="MenuItem"
|
||||
data-testid="menu-action-delete"
|
||||
tabindex="0"
|
||||
>
|
||||
<i
|
||||
class="Icon material interactive focusable"
|
||||
tabindex="0"
|
||||
tooltip="Delete"
|
||||
>
|
||||
<span
|
||||
class="icon"
|
||||
data-icon-name="delete"
|
||||
>
|
||||
delete
|
||||
</span>
|
||||
</i>
|
||||
<span
|
||||
class="title"
|
||||
>
|
||||
Delete
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
`;
|
||||
|
||||
exports[`kube-object-menu given kube object when rerendered with different kube object when removing new kube object renders 1`] = `
|
||||
<body>
|
||||
<div>
|
||||
<div>
|
||||
<ul
|
||||
class="Menu MenuActions flex KubeObjectMenu toolbar gaps right bottom"
|
||||
>
|
||||
<li
|
||||
class="MenuItem"
|
||||
data-testid="menu-action-delete"
|
||||
tabindex="0"
|
||||
>
|
||||
<i
|
||||
class="Icon material interactive focusable"
|
||||
tabindex="0"
|
||||
tooltip="Delete"
|
||||
>
|
||||
<span
|
||||
class="icon"
|
||||
data-icon-name="delete"
|
||||
>
|
||||
delete
|
||||
</span>
|
||||
</i>
|
||||
<span
|
||||
class="title"
|
||||
>
|
||||
Delete
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="Dialog flex center ConfirmDialog modal"
|
||||
data-testid="confirmation-dialog"
|
||||
>
|
||||
<div
|
||||
class="box"
|
||||
>
|
||||
<div
|
||||
class="confirm-content"
|
||||
>
|
||||
<i
|
||||
class="Icon material focusable big"
|
||||
>
|
||||
<span
|
||||
class="icon"
|
||||
data-icon-name="warning"
|
||||
>
|
||||
warning
|
||||
</span>
|
||||
</i>
|
||||
|
||||
<p>
|
||||
Remove some-other-kind
|
||||
<b>
|
||||
some-other-namespace/some-other-name
|
||||
</b>
|
||||
from
|
||||
<b>
|
||||
Some name
|
||||
</b>
|
||||
?
|
||||
</p>
|
||||
</div>
|
||||
<div
|
||||
class="confirm-buttons"
|
||||
>
|
||||
<button
|
||||
class="Button cancel plain"
|
||||
type="button"
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
class="Button ok primary"
|
||||
data-testid="confirm"
|
||||
type="button"
|
||||
>
|
||||
Remove
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
`;
|
||||
|
||||
exports[`kube-object-menu given kube object with namespace when removing kube object, renders confirmation dialog with namespace 1`] = `
|
||||
<body>
|
||||
<div>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import React from "react";
|
||||
import type { RenderResult } from "@testing-library/react";
|
||||
import { screen, waitFor } from "@testing-library/react";
|
||||
import "@testing-library/jest-dom/extend-expect";
|
||||
import { KubeObject } from "../../../common/k8s-api/kube-object";
|
||||
@@ -125,7 +126,7 @@ describe("kube-object-menu", () => {
|
||||
});
|
||||
|
||||
describe("given kube object", () => {
|
||||
let baseElement: Element;
|
||||
let result: RenderResult;
|
||||
let removeActionMock: AsyncFnMock<() => void>;
|
||||
|
||||
beforeEach(async () => {
|
||||
@@ -142,8 +143,7 @@ describe("kube-object-menu", () => {
|
||||
});
|
||||
|
||||
removeActionMock = asyncFn();
|
||||
|
||||
({ baseElement } = render(
|
||||
result = render((
|
||||
<div>
|
||||
<ConfirmDialog animated={false} />
|
||||
|
||||
@@ -152,18 +152,61 @@ describe("kube-object-menu", () => {
|
||||
toolbar={true}
|
||||
removeAction={removeActionMock}
|
||||
/>
|
||||
</div>,
|
||||
</div>
|
||||
));
|
||||
});
|
||||
|
||||
it("renders", () => {
|
||||
expect(baseElement).toMatchSnapshot();
|
||||
expect(result.baseElement).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("does not open a confirmation dialog yet", () => {
|
||||
expect(screen.queryByTestId("confirmation-dialog")).toBeNull();
|
||||
});
|
||||
|
||||
describe("when rerendered with different kube object", () => {
|
||||
beforeEach(() => {
|
||||
const newObjectStub = KubeObject.create({
|
||||
apiVersion: "some-other-api-version",
|
||||
kind: "some-other-kind",
|
||||
metadata: {
|
||||
uid: "some-other-uid",
|
||||
name: "some-other-name",
|
||||
resourceVersion: "some-other-resource-version",
|
||||
namespace: "some-other-namespace",
|
||||
selfLink: "some-other-api-version/some-other-kind/some-other-namespace/some-other-name",
|
||||
},
|
||||
});
|
||||
|
||||
result.rerender(
|
||||
<div>
|
||||
<ConfirmDialog animated={false} />
|
||||
|
||||
<KubeObjectMenu
|
||||
object={newObjectStub}
|
||||
toolbar={true}
|
||||
removeAction={removeActionMock}
|
||||
/>
|
||||
</div>,
|
||||
);
|
||||
});
|
||||
|
||||
it("renders", () => {
|
||||
expect(result.baseElement).toMatchSnapshot();
|
||||
});
|
||||
|
||||
describe("when removing new kube object", () => {
|
||||
beforeEach(async () => {
|
||||
userEvent.click(await screen.findByTestId("menu-action-delete"));
|
||||
});
|
||||
|
||||
it("renders", async () => {
|
||||
await screen.findByTestId("confirmation-dialog");
|
||||
expect(result.baseElement).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("when removing kube object", () => {
|
||||
beforeEach(async () => {
|
||||
userEvent.click(await screen.findByTestId("menu-action-delete"));
|
||||
@@ -171,7 +214,7 @@ describe("kube-object-menu", () => {
|
||||
|
||||
it("renders", async () => {
|
||||
await screen.findByTestId("confirmation-dialog");
|
||||
expect(baseElement).toMatchSnapshot();
|
||||
expect(result.baseElement).toMatchSnapshot();
|
||||
});
|
||||
|
||||
describe("when remove is confirmed", () => {
|
||||
|
||||
@@ -49,6 +49,12 @@ interface Dependencies {
|
||||
class NonInjectedKubeObjectMenu<Kube extends KubeObject> extends React.Component<KubeObjectMenuProps<Kube> & Dependencies> {
|
||||
private menuItems = observable.array<KubeObjectContextMenuItem>();
|
||||
|
||||
componentDidUpdate(prevProps: Readonly<KubeObjectMenuProps<Kube> & Dependencies>): void {
|
||||
if (prevProps.object !== this.props.object && this.props.object) {
|
||||
this.emitOnContextMenuOpen(this.props.object);
|
||||
}
|
||||
}
|
||||
|
||||
private renderRemoveMessage(object: KubeObject) {
|
||||
const breadcrumbParts = [object.getNs(), object.getName()];
|
||||
const breadcrumb = breadcrumbParts.filter(identity).join("/");
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
@import "../../components/mixins.scss";
|
||||
|
||||
.KubeConfigDialog {
|
||||
:global(.Wizard) {
|
||||
width: 50vw;
|
||||
|
||||
@@ -59,20 +59,3 @@
|
||||
@content; // css-modules (*.module.scss)
|
||||
}
|
||||
}
|
||||
|
||||
// Makes custom @font-family available at earlier stages.
|
||||
// Element must exist in DOM as soon as possible to initiate preloading.
|
||||
@mixin font-preload($fontFamily) {
|
||||
position: absolute;
|
||||
visibility: hidden;
|
||||
height: 0;
|
||||
|
||||
&:before {
|
||||
width: 0;
|
||||
display: block;
|
||||
overflow: hidden;
|
||||
content: "x"; // some text required to start applying font in document
|
||||
font-family: $fontFamily; // imported name in @font-face declaration
|
||||
@content;
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,6 @@ import { UserStore } from "../../../common/user-store";
|
||||
import type { ThemeStore } from "../../themes/store";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import themeStoreInjectable from "../../themes/store.injectable";
|
||||
import logger from "../../../main/logger";
|
||||
|
||||
export type MonacoEditorId = string;
|
||||
|
||||
@@ -66,6 +65,11 @@ class NonInjectedMonacoEditor extends React.Component<MonacoEditorProps & Depend
|
||||
@observable readonly dimensions: { width?: number; height?: number } = {};
|
||||
@observable unmounting = false;
|
||||
|
||||
// TODO: investigate how to replace with "common/logger"
|
||||
// currently leads for stucking UI forever & infinite loop.
|
||||
// e.g. happens on tab change/create, maybe some other cases too.
|
||||
private logger = console;
|
||||
|
||||
constructor(props: MonacoEditorProps & Dependencies) {
|
||||
super(props);
|
||||
makeObservable(this);
|
||||
@@ -129,7 +133,7 @@ class NonInjectedMonacoEditor extends React.Component<MonacoEditorProps & Depend
|
||||
}
|
||||
|
||||
protected onModelChange(model: editor.ITextModel, oldModel?: editor.ITextModel) {
|
||||
logger.info("[MONACO]: model change", { model, oldModel }, this.logMetadata);
|
||||
this.logger.info("[MONACO]: model change", { model, oldModel }, this.logMetadata);
|
||||
|
||||
if (oldModel) {
|
||||
this.saveViewState(oldModel);
|
||||
@@ -166,9 +170,9 @@ class NonInjectedMonacoEditor extends React.Component<MonacoEditorProps & Depend
|
||||
componentDidMount() {
|
||||
try {
|
||||
this.createEditor();
|
||||
logger.info(`[MONACO]: editor did mount`, this.logMetadata);
|
||||
this.logger.info(`[MONACO]: editor did mount`, this.logMetadata);
|
||||
} catch (error) {
|
||||
logger.error(`[MONACO]: mounting failed: ${error}`, this.logMetadata);
|
||||
this.logger.error(`[MONACO]: mounting failed: ${error}`, this.logMetadata);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,7 +204,7 @@ class NonInjectedMonacoEditor extends React.Component<MonacoEditorProps & Depend
|
||||
...this.options,
|
||||
});
|
||||
|
||||
logger.info(`[MONACO]: editor created for language=${language}, theme=${theme}`, this.logMetadata);
|
||||
this.logger.info(`[MONACO]: editor created for language=${language}, theme=${theme}`, this.logMetadata);
|
||||
this.validateLazy(); // validate initial value
|
||||
this.restoreViewState(this.model); // restore previous state if any
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { NotificationsStore } from "./notifications.store";
|
||||
|
||||
const notificationsStoreInjectable = getInjectable({
|
||||
id: "notifications-store",
|
||||
instantiate: () => new NotificationsStore(),
|
||||
});
|
||||
|
||||
export default notificationsStoreInjectable;
|
||||
@@ -91,5 +91,3 @@ export class NotificationsStore {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const notificationsStore = new NotificationsStore();
|
||||
@@ -10,61 +10,25 @@ import { reaction } from "mobx";
|
||||
import { disposeOnUnmount, observer } from "mobx-react";
|
||||
import { JsonApiErrorParsed } from "../../../common/k8s-api/json-api";
|
||||
import { cssNames, prevDefault } from "../../utils";
|
||||
import type { Notification, NotificationMessage } from "./notifications.store";
|
||||
import { notificationsStore, NotificationStatus } from "./notifications.store";
|
||||
import type { Notification, NotificationMessage, NotificationsStore } from "./notifications.store";
|
||||
import { NotificationStatus } from "./notifications.store";
|
||||
import { Animate } from "../animate";
|
||||
import { Icon } from "../icon";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import { asLegacyGlobalForExtensionApi } from "../../../extensions/as-legacy-globals-for-extension-api/as-legacy-global-object-for-extension-api";
|
||||
import notificationsStoreInjectable from "./notifications-store.injectable";
|
||||
|
||||
interface Dependencies {
|
||||
store: NotificationsStore;
|
||||
}
|
||||
|
||||
@observer
|
||||
export class Notifications extends React.Component {
|
||||
class NonInjectedNotifications extends React.Component<Dependencies> {
|
||||
public elem: HTMLDivElement | null = null;
|
||||
|
||||
static ok(message: NotificationMessage) {
|
||||
return notificationsStore.add({
|
||||
message,
|
||||
timeout: 2_500,
|
||||
status: NotificationStatus.OK,
|
||||
});
|
||||
}
|
||||
|
||||
static checkedError(message: unknown, fallback: string, customOpts?: Partial<Omit<Notification, "message">>) {
|
||||
if (typeof message === "string" || message instanceof Error || message instanceof JsonApiErrorParsed) {
|
||||
return Notifications.error(message, customOpts);
|
||||
}
|
||||
|
||||
console.warn("Unknown notification error message, falling back to default", message);
|
||||
|
||||
return Notifications.error(fallback, customOpts);
|
||||
}
|
||||
|
||||
static error(message: NotificationMessage, customOpts: Partial<Omit<Notification, "message">> = {}) {
|
||||
return notificationsStore.add({
|
||||
message,
|
||||
timeout: 10_000,
|
||||
status: NotificationStatus.ERROR,
|
||||
...customOpts,
|
||||
});
|
||||
}
|
||||
|
||||
static shortInfo(message: NotificationMessage, customOpts: Partial<Omit<Notification, "message">> = {}) {
|
||||
return this.info(message, {
|
||||
timeout: 5_000,
|
||||
...customOpts,
|
||||
});
|
||||
}
|
||||
|
||||
static info(message: NotificationMessage, customOpts: Partial<Omit<Notification, "message">> = {}) {
|
||||
return notificationsStore.add({
|
||||
status: NotificationStatus.INFO,
|
||||
timeout: 0,
|
||||
message,
|
||||
...customOpts,
|
||||
});
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
disposeOnUnmount(this, [
|
||||
reaction(() => notificationsStore.notifications.length, () => {
|
||||
reaction(() => this.props.store.notifications.length, () => {
|
||||
this.scrollToLastNotification();
|
||||
}, { delay: 250 }),
|
||||
]);
|
||||
@@ -74,7 +38,7 @@ export class Notifications extends React.Component {
|
||||
if (!this.elem) {
|
||||
return;
|
||||
}
|
||||
this.elem.scrollTo({
|
||||
this.elem.scrollTo?.({
|
||||
top: this.elem.scrollHeight,
|
||||
behavior: "smooth",
|
||||
});
|
||||
@@ -91,7 +55,7 @@ export class Notifications extends React.Component {
|
||||
}
|
||||
|
||||
render() {
|
||||
const { notifications, remove, addAutoHideTimer, removeAutoHideTimer } = notificationsStore;
|
||||
const { notifications, remove, addAutoHideTimer, removeAutoHideTimer } = this.props.store;
|
||||
|
||||
return (
|
||||
<div className="Notifications flex column align-flex-end" ref={e => this.elem = e}>
|
||||
@@ -114,6 +78,7 @@ export class Notifications extends React.Component {
|
||||
<Icon
|
||||
material="close"
|
||||
className="close"
|
||||
data-testid={`close-notification-for-${id}`}
|
||||
onClick={prevDefault(() => {
|
||||
remove(id);
|
||||
onClose?.();
|
||||
@@ -128,3 +93,68 @@ export class Notifications extends React.Component {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const Notifications = withInjectables<Dependencies>(
|
||||
NonInjectedNotifications,
|
||||
|
||||
{
|
||||
getProps: (di) => ({
|
||||
store: di.inject(notificationsStoreInjectable),
|
||||
}),
|
||||
},
|
||||
) as React.FC & {
|
||||
ok: (message: NotificationMessage) => () => void;
|
||||
checkedError: (message: unknown, fallback: string, customOpts?: Partial<Omit<Notification, "message">>) => () => void;
|
||||
error: (message: NotificationMessage, customOpts?: Partial<Omit<Notification, "message">>) => () => void;
|
||||
shortInfo: (message: NotificationMessage, customOpts?: Partial<Omit<Notification, "message">>) => () => void;
|
||||
info: (message: NotificationMessage, customOpts?: Partial<Omit<Notification, "message">>) => () => void;
|
||||
};
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
const _notificationStore = asLegacyGlobalForExtensionApi(notificationsStoreInjectable);
|
||||
|
||||
Notifications.ok = (message: NotificationMessage) => {
|
||||
return _notificationStore.add({
|
||||
message,
|
||||
timeout: 2_500,
|
||||
status: NotificationStatus.OK,
|
||||
});
|
||||
};
|
||||
|
||||
Notifications.checkedError = (message, fallback, customOpts = {}) => {
|
||||
if (typeof message === "string" || message instanceof Error || message instanceof JsonApiErrorParsed) {
|
||||
return Notifications.error(message, customOpts);
|
||||
}
|
||||
|
||||
console.warn("Unknown notification error message, falling back to default", message);
|
||||
|
||||
return Notifications.error(fallback, customOpts);
|
||||
};
|
||||
|
||||
Notifications.error = (message, customOpts= {}) => {
|
||||
return _notificationStore.add({
|
||||
message,
|
||||
timeout: 10_000,
|
||||
status: NotificationStatus.ERROR,
|
||||
...customOpts,
|
||||
});
|
||||
};
|
||||
|
||||
Notifications.shortInfo = (message, customOpts = {}) => {
|
||||
return Notifications.info(message, {
|
||||
timeout: 5_000,
|
||||
...customOpts,
|
||||
});
|
||||
};
|
||||
|
||||
Notifications.info = (message, customOpts = {}) => {
|
||||
return _notificationStore.add({
|
||||
status: NotificationStatus.INFO,
|
||||
timeout: 0,
|
||||
message,
|
||||
...customOpts,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import type { NotificationMessage, Notification } from "./notifications.store";
|
||||
import { NotificationStatus } from "./notifications.store";
|
||||
import notificationsStoreInjectable from "./notifications-store.injectable";
|
||||
|
||||
const showInfoNotificationInjectable = getInjectable({
|
||||
id: "show-info-notification",
|
||||
|
||||
instantiate: (di) => {
|
||||
const notificationsStore = di.inject(notificationsStoreInjectable);
|
||||
|
||||
return (message: NotificationMessage, customOpts: Partial<Omit<Notification, "message">> = {}) =>
|
||||
notificationsStore.add({
|
||||
status: NotificationStatus.INFO,
|
||||
timeout: 5000,
|
||||
message,
|
||||
...customOpts,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default showInfoNotificationInjectable;
|
||||
@@ -17,7 +17,6 @@ import { computed } from "mobx";
|
||||
import type { LensRendererExtension } from "../../../extensions/lens-renderer-extension";
|
||||
import getConfigurationFileModelInjectable from "../../../common/get-configuration-file-model/get-configuration-file-model.injectable";
|
||||
import appVersionInjectable from "../../../common/get-configuration-file-model/app-version/app-version.injectable";
|
||||
import ipcRendererInjectable from "../../app-paths/get-value-from-registered-channel/ipc-renderer/ipc-renderer.injectable";
|
||||
|
||||
jest.mock("electron", () => ({
|
||||
ipcRenderer: {
|
||||
@@ -38,11 +37,7 @@ describe("<Select />", () => {
|
||||
|
||||
di.override(directoryForUserDataInjectable, () => "some-directory-for-user-data");
|
||||
di.override(rendererExtensionsInjectable, () => computed(() => [] as LensRendererExtension[]));
|
||||
di.override(ipcRendererInjectable, () => ({
|
||||
on: jest.fn(),
|
||||
invoke: jest.fn(), // TODO: replace with proper mocking via the IPC bridge
|
||||
} as never));
|
||||
|
||||
|
||||
di.permitSideEffects(getConfigurationFileModelInjectable);
|
||||
di.permitSideEffects(appVersionInjectable);
|
||||
});
|
||||
|
||||
@@ -22,7 +22,7 @@ const { Menu } = components;
|
||||
|
||||
export interface SelectOption<Value> {
|
||||
value: Value;
|
||||
label: string;
|
||||
label: React.ReactNode;
|
||||
isDisabled?: boolean;
|
||||
isSelected?: boolean;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
@import "../../components/mixins.scss";
|
||||
|
||||
.Switch {
|
||||
--thumb-size: 2rem;
|
||||
--thumb-color: hsl(0 0% 100%);
|
||||
|
||||
@@ -8,7 +8,7 @@ import type { TableSortBy, TableSortParams } from "./table";
|
||||
|
||||
import type { ReactNode } from "react";
|
||||
import React from "react";
|
||||
import { autoBind, cssNames, displayBooleans } from "../../utils";
|
||||
import { autoBind, cssNames } from "../../utils";
|
||||
import { Icon } from "../icon";
|
||||
import { Checkbox } from "../checkbox";
|
||||
|
||||
@@ -45,11 +45,6 @@ export interface TableCellProps extends React.DOMAttributes<HTMLDivElement> {
|
||||
*/
|
||||
isChecked?: boolean;
|
||||
|
||||
/**
|
||||
* show "true" or "false" for all of the children elements are "typeof boolean"
|
||||
*/
|
||||
renderBoolean?: boolean;
|
||||
|
||||
/**
|
||||
* column name, must be same as key in sortable object <Table sortable={}/>
|
||||
*/
|
||||
@@ -136,7 +131,6 @@ export class TableCell extends React.Component<TableCellProps> {
|
||||
_nowrap,
|
||||
children,
|
||||
title,
|
||||
renderBoolean: displayBoolean = false,
|
||||
showWithColumn,
|
||||
...cellProps
|
||||
} = this.props;
|
||||
@@ -147,7 +141,7 @@ export class TableCell extends React.Component<TableCellProps> {
|
||||
nowrap: _nowrap,
|
||||
sorting: _sort && typeof sortBy === "string",
|
||||
});
|
||||
const content = displayBooleans(displayBoolean, title || children);
|
||||
const content = title || children;
|
||||
|
||||
return (
|
||||
<div
|
||||
|
||||
@@ -18,19 +18,18 @@ import type { RenderResult } from "@testing-library/react";
|
||||
import { fireEvent } from "@testing-library/react";
|
||||
import type { KubeResource } from "../../../common/rbac";
|
||||
import { Sidebar } from "../layout/sidebar";
|
||||
import { getDisForUnitTesting } from "../../../test-utils/get-dis-for-unit-testing";
|
||||
import type { DiContainer } from "@ogre-tools/injectable";
|
||||
import clusterStoreInjectable from "../../../common/cluster-store/cluster-store.injectable";
|
||||
import type { ClusterStore } from "../../../common/cluster-store/cluster-store";
|
||||
import mainExtensionsInjectable from "../../../extensions/main-extensions.injectable";
|
||||
import currentRouteComponentInjectable from "../../routes/current-route-component.injectable";
|
||||
import { pipeline } from "@ogre-tools/fp";
|
||||
import { flatMap, compact, join, get, filter } from "lodash/fp";
|
||||
import { flatMap, compact, join, get, filter, map, matches, find } from "lodash/fp";
|
||||
import preferenceNavigationItemsInjectable from "../+preferences/preferences-navigation/preference-navigation-items.injectable";
|
||||
import navigateToPreferencesInjectable from "../../../common/front-end-routing/routes/preferences/navigate-to-preferences.injectable";
|
||||
import type { MenuItemOpts } from "../../../main/menu/application-menu-items.injectable";
|
||||
import applicationMenuItemsInjectable from "../../../main/menu/application-menu-items.injectable";
|
||||
import type { MenuItem, MenuItemConstructorOptions } from "electron";
|
||||
import type { MenuItemConstructorOptions, MenuItem } from "electron";
|
||||
import storesAndApisCanBeCreatedInjectable from "../../stores-apis-can-be-created.injectable";
|
||||
import navigateToHelmChartsInjectable from "../../../common/front-end-routing/routes/cluster/helm/charts/navigate-to-helm-charts.injectable";
|
||||
import hostedClusterInjectable from "../../../common/cluster-store/hosted-cluster.injectable";
|
||||
@@ -44,6 +43,15 @@ import { flushPromises } from "../../../common/test-utils/flush-promises";
|
||||
import type { NamespaceStore } from "../+namespaces/store";
|
||||
import namespaceStoreInjectable from "../+namespaces/store.injectable";
|
||||
import historyInjectable from "../../navigation/history.injectable";
|
||||
import electronTrayInjectable from "../../../main/tray/electron-tray/electron-tray.injectable";
|
||||
import applicationWindowInjectable from "../../../main/start-main-application/lens-window/application-window/application-window.injectable";
|
||||
import { Notifications } from "../notifications/notifications";
|
||||
import broadcastThatRootFrameIsRenderedInjectable from "../../frames/root-frame/broadcast-that-root-frame-is-rendered.injectable";
|
||||
import { getDiForUnitTesting as getRendererDi } from "../../getDiForUnitTesting";
|
||||
import { getDiForUnitTesting as getMainDi } from "../../../main/getDiForUnitTesting";
|
||||
import { overrideChannels } from "../../../test-utils/channel-fakes/override-channels";
|
||||
import type { TrayMenuItem } from "../../../main/tray/tray-menu-item/tray-menu-item-injection-token";
|
||||
import trayIconPathsInjectable from "../../../main/tray/tray-icon-path.injectable";
|
||||
|
||||
type Callback = (dis: DiContainers) => void | Promise<void>;
|
||||
|
||||
@@ -56,6 +64,12 @@ export interface ApplicationBuilder {
|
||||
beforeRender: (callback: Callback) => ApplicationBuilder;
|
||||
render: () => Promise<RenderResult>;
|
||||
|
||||
tray: {
|
||||
click: (id: string) => Promise<void>;
|
||||
get: (id: string) => TrayMenuItem | null;
|
||||
getIconPath: () => string;
|
||||
};
|
||||
|
||||
applicationMenu: {
|
||||
click: (path: string) => Promise<void>;
|
||||
};
|
||||
@@ -80,14 +94,23 @@ interface DiContainers {
|
||||
|
||||
interface Environment {
|
||||
renderSidebar: () => React.ReactNode;
|
||||
beforeRender: () => void;
|
||||
onAllowKubeResource: () => void;
|
||||
}
|
||||
|
||||
export const getApplicationBuilder = () => {
|
||||
const { rendererDi, mainDi } = getDisForUnitTesting({
|
||||
const mainDi = getMainDi({
|
||||
doGeneralOverrides: true,
|
||||
});
|
||||
|
||||
const overrideChannelsForWindow = overrideChannels(mainDi);
|
||||
|
||||
const rendererDi = getRendererDi({
|
||||
doGeneralOverrides: true,
|
||||
});
|
||||
|
||||
overrideChannelsForWindow(rendererDi);
|
||||
|
||||
const dis = { rendererDi, mainDi };
|
||||
|
||||
const clusterStoreStub = {
|
||||
@@ -110,6 +133,12 @@ export const getApplicationBuilder = () => {
|
||||
application: {
|
||||
renderSidebar: () => null,
|
||||
|
||||
beforeRender: () => {
|
||||
const nofifyThatRootFrameIsRendered = rendererDi.inject(broadcastThatRootFrameIsRenderedInjectable);
|
||||
|
||||
nofifyThatRootFrameIsRendered();
|
||||
},
|
||||
|
||||
onAllowKubeResource: () => {
|
||||
throw new Error(
|
||||
"Tried to allow kube resource when environment is not cluster frame.",
|
||||
@@ -119,6 +148,7 @@ export const getApplicationBuilder = () => {
|
||||
|
||||
clusterFrame: {
|
||||
renderSidebar: () => <Sidebar />,
|
||||
beforeRender: () => {},
|
||||
onAllowKubeResource: () => {},
|
||||
} as Environment,
|
||||
};
|
||||
@@ -138,6 +168,24 @@ export const getApplicationBuilder = () => {
|
||||
computed(() => []),
|
||||
);
|
||||
|
||||
const iconPaths = mainDi.inject(trayIconPathsInjectable);
|
||||
|
||||
let trayMenuItemsStateFake: TrayMenuItem[];
|
||||
let trayMenuIconPath: string;
|
||||
|
||||
mainDi.override(electronTrayInjectable, () => ({
|
||||
start: () => {
|
||||
trayMenuIconPath = iconPaths.normal;
|
||||
},
|
||||
stop: () => {},
|
||||
setMenuItems: (items) => {
|
||||
trayMenuItemsStateFake = items;
|
||||
},
|
||||
setIconPath: (path) => {
|
||||
trayMenuIconPath = path;
|
||||
},
|
||||
}));
|
||||
|
||||
let allowedResourcesState: IObservableArray<KubeResource>;
|
||||
let rendered: RenderResult;
|
||||
|
||||
@@ -170,6 +218,7 @@ export const getApplicationBuilder = () => {
|
||||
{
|
||||
menu: null as never,
|
||||
commandId: 0,
|
||||
userAccelerator: null,
|
||||
...menuItem,
|
||||
} as MenuItem,
|
||||
undefined,
|
||||
@@ -180,6 +229,32 @@ export const getApplicationBuilder = () => {
|
||||
},
|
||||
},
|
||||
|
||||
tray: {
|
||||
get: (id: string) => {
|
||||
return trayMenuItemsStateFake.find(matches({ id })) ?? null;
|
||||
},
|
||||
getIconPath: () => trayMenuIconPath,
|
||||
click: async (id: string) => {
|
||||
const menuItem = pipeline(
|
||||
trayMenuItemsStateFake,
|
||||
find((menuItem) => menuItem.id === id),
|
||||
);
|
||||
|
||||
if (!menuItem) {
|
||||
const availableIds = pipeline(
|
||||
trayMenuItemsStateFake,
|
||||
filter(item => !!item.click),
|
||||
map(item => item.id),
|
||||
join(", "),
|
||||
);
|
||||
|
||||
throw new Error(`Tried to click tray menu item with ID ${id} which does not exist. Available IDs are: "${availableIds}"`);
|
||||
}
|
||||
|
||||
await menuItem.click?.();
|
||||
},
|
||||
},
|
||||
|
||||
preferences: {
|
||||
close: () => {
|
||||
const link = rendered.getByTestId("close-preferences");
|
||||
@@ -318,6 +393,10 @@ export const getApplicationBuilder = () => {
|
||||
|
||||
await startMainApplication();
|
||||
|
||||
const applicationWindow = mainDi.inject(applicationWindowInjectable);
|
||||
|
||||
await applicationWindow.show();
|
||||
|
||||
const startFrame = rendererDi.inject(startFrameInjectable);
|
||||
|
||||
await startFrame();
|
||||
@@ -330,6 +409,8 @@ export const getApplicationBuilder = () => {
|
||||
await callback(dis);
|
||||
}
|
||||
|
||||
environment.beforeRender();
|
||||
|
||||
rendered = render(
|
||||
<Router history={history}>
|
||||
{environment.renderSidebar()}
|
||||
@@ -345,6 +426,8 @@ export const getApplicationBuilder = () => {
|
||||
return <Component />;
|
||||
}}
|
||||
</Observer>
|
||||
|
||||
<Notifications />
|
||||
</Router>,
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`<Tooltip /> does not render to DOM if not visibile 1`] = `
|
||||
<body>
|
||||
<div>
|
||||
<div
|
||||
id="my-target"
|
||||
>
|
||||
Target Text
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
`;
|
||||
|
||||
exports[`<Tooltip /> renders to DOM when forced to by visibile prop 1`] = `
|
||||
<body>
|
||||
<div>
|
||||
<div
|
||||
class="Tooltip visible"
|
||||
role="tooltip"
|
||||
>
|
||||
I am a tooltip
|
||||
</div>
|
||||
<div
|
||||
id="my-target"
|
||||
>
|
||||
Target Text
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
`;
|
||||
|
||||
exports[`<Tooltip /> renders to DOM when hovering over target 1`] = `
|
||||
<body>
|
||||
<div>
|
||||
<div
|
||||
class="Tooltip right"
|
||||
role="tooltip"
|
||||
style="left: 10px; top: 0px;"
|
||||
>
|
||||
I am a tooltip
|
||||
</div>
|
||||
<div
|
||||
id="my-target"
|
||||
>
|
||||
Target Text
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
`;
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import { render } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import assert from "assert";
|
||||
import React from "react";
|
||||
import { Tooltip } from "./tooltip";
|
||||
|
||||
describe("<Tooltip />", () => {
|
||||
it("does not render to DOM if not visibile", () => {
|
||||
const result = render((
|
||||
<>
|
||||
<Tooltip targetId="my-target" usePortal={false}>I am a tooltip</Tooltip>
|
||||
<div id="my-target">Target Text</div>
|
||||
</>
|
||||
));
|
||||
|
||||
expect(result.baseElement).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("renders to DOM when hovering over target", () => {
|
||||
const result = render((
|
||||
<>
|
||||
<Tooltip
|
||||
targetId="my-target"
|
||||
data-testid="tooltip"
|
||||
usePortal={false}
|
||||
>
|
||||
I am a tooltip
|
||||
</Tooltip>
|
||||
<div id="my-target">Target Text</div>
|
||||
</>
|
||||
));
|
||||
|
||||
const target = result.baseElement.querySelector("#my-target");
|
||||
|
||||
assert(target);
|
||||
|
||||
userEvent.hover(target);
|
||||
expect(result.baseElement).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("renders to DOM when forced to by visibile prop", () => {
|
||||
const result = render((
|
||||
<>
|
||||
<Tooltip
|
||||
targetId="my-target"
|
||||
data-testid="tooltip"
|
||||
visible={true}
|
||||
usePortal={false}
|
||||
>
|
||||
I am a tooltip
|
||||
</Tooltip>
|
||||
<div id="my-target">Target Text</div>
|
||||
</>
|
||||
));
|
||||
|
||||
expect(result.baseElement).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
@@ -55,7 +55,7 @@ export class Tooltip extends React.Component<TooltipProps> {
|
||||
|
||||
@observable.ref elem: HTMLDivElement | null = null;
|
||||
@observable activePosition?: TooltipPosition;
|
||||
@observable isVisible = this.props.visible ?? false;
|
||||
@observable isVisible = false;
|
||||
@observable isContentVisible = false; // animation manager
|
||||
|
||||
constructor(props: TooltipProps) {
|
||||
@@ -217,13 +217,14 @@ export class Tooltip extends React.Component<TooltipProps> {
|
||||
}
|
||||
|
||||
render() {
|
||||
if (!this.isVisible) {
|
||||
const { style, formatters, usePortal, children, visible = this.isVisible } = this.props;
|
||||
|
||||
if (!visible) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const { style, formatters, usePortal, children } = this.props;
|
||||
const className = cssNames("Tooltip", this.props.className, formatters, this.activePosition, {
|
||||
visible: this.isContentVisible,
|
||||
visible: this.isContentVisible || this.props.visible,
|
||||
formatter: !!formatters,
|
||||
});
|
||||
const tooltip = (
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { messageToChannelInjectionToken } from "../../../common/utils/channel/message-to-channel-injection-token";
|
||||
import rootFrameIsRenderedChannelInjectable from "../../../common/root-frame-rendered-channel/root-frame-rendered-channel.injectable";
|
||||
|
||||
const broadcastThatRootFrameIsRenderedInjectable = getInjectable({
|
||||
id: "broadcast-that-root-frame-is-rendered",
|
||||
|
||||
instantiate: (di) => {
|
||||
const messageToChannel = di.inject(messageToChannelInjectionToken);
|
||||
const rootFrameIsRenderedChannel = di.inject(rootFrameIsRenderedChannelInjectable);
|
||||
|
||||
return () => {
|
||||
messageToChannel(rootFrameIsRenderedChannel);
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
export default broadcastThatRootFrameIsRenderedInjectable;
|
||||
@@ -5,7 +5,7 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { initRootFrame } from "./init-root-frame";
|
||||
import extensionLoaderInjectable from "../../../../extensions/extension-loader/extension-loader.injectable";
|
||||
import ipcRendererInjectable from "../../../app-paths/get-value-from-registered-channel/ipc-renderer/ipc-renderer.injectable";
|
||||
import ipcRendererInjectable from "../../../utils/channel/ipc-renderer.injectable";
|
||||
import bindProtocolAddRouteHandlersInjectable from "../../../protocol-handler/bind-protocol-add-route-handlers/bind-protocol-add-route-handlers.injectable";
|
||||
import lensProtocolRouterRendererInjectable from "../../../protocol-handler/lens-protocol-router-renderer/lens-protocol-router-renderer.injectable";
|
||||
import catalogEntityRegistryInjectable from "../../../api/catalog/entity/registry.injectable";
|
||||
|
||||
@@ -11,17 +11,22 @@ import { ErrorBoundary } from "../../components/error-boundary";
|
||||
import { Notifications } from "../../components/notifications";
|
||||
import { ConfirmDialog } from "../../components/confirm-dialog";
|
||||
import { CommandContainer } from "../../components/command-palette/command-container";
|
||||
import { ipcRenderer } from "electron";
|
||||
import { IpcRendererNavigationEvents } from "../../navigation/events";
|
||||
import { withInjectables } from "@ogre-tools/injectable-react";
|
||||
import broadcastThatRootFrameIsRenderedInjectable from "./broadcast-that-root-frame-is-rendered.injectable";
|
||||
|
||||
// Todo: remove import-time side-effect.
|
||||
injectSystemCAs();
|
||||
|
||||
interface Dependencies {
|
||||
broadcastThatRootFrameIsRendered: () => void;
|
||||
}
|
||||
|
||||
@observer
|
||||
export class RootFrame extends React.Component {
|
||||
class NonInjectedRootFrame extends React.Component<Dependencies> {
|
||||
static displayName = "RootFrame";
|
||||
|
||||
componentDidMount() {
|
||||
ipcRenderer.send(IpcRendererNavigationEvents.LOADED);
|
||||
this.props.broadcastThatRootFrameIsRendered();
|
||||
}
|
||||
|
||||
render() {
|
||||
@@ -37,3 +42,14 @@ export class RootFrame extends React.Component {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export const RootFrame = withInjectables<Dependencies>(
|
||||
NonInjectedRootFrame,
|
||||
|
||||
{
|
||||
getProps: (di, props) => ({
|
||||
broadcastThatRootFrameIsRendered: di.inject(broadcastThatRootFrameIsRenderedInjectable),
|
||||
...props,
|
||||
}),
|
||||
},
|
||||
);
|
||||
@@ -7,12 +7,11 @@ import glob from "glob";
|
||||
import { memoize, noop } from "lodash/fp";
|
||||
import { createContainer } from "@ogre-tools/injectable";
|
||||
import { Environments, setLegacyGlobalDiForExtensionApi } from "../extensions/as-legacy-globals-for-extension-api/legacy-global-di-for-extension-api";
|
||||
import getValueFromRegisteredChannelInjectable from "./app-paths/get-value-from-registered-channel/get-value-from-registered-channel.injectable";
|
||||
import requestFromChannelInjectable from "./utils/channel/request-from-channel.injectable";
|
||||
import loggerInjectable from "../common/logger.injectable";
|
||||
import { overrideFsWithFakes } from "../test-utils/override-fs-with-fakes";
|
||||
import { createMemoryHistory } from "history";
|
||||
import registerIpcChannelListenerInjectable from "./app-paths/get-value-from-registered-channel/register-ipc-channel-listener.injectable";
|
||||
import focusWindowInjectable from "./ipc-channel-listeners/focus-window.injectable";
|
||||
import focusWindowInjectable from "./navigation/focus-window.injectable";
|
||||
import extensionsStoreInjectable from "../extensions/extensions-store/extensions-store.injectable";
|
||||
import type { ExtensionsStore } from "../extensions/extensions-store/extensions-store";
|
||||
import fileSystemProvisionerStoreInjectable from "../extensions/extension-loader/file-system-provisioner-store/file-system-provisioner-store.injectable";
|
||||
@@ -32,19 +31,22 @@ import { joinPathsFake } from "../common/test-utils/join-paths-fake";
|
||||
import hotbarStoreInjectable from "../common/hotbars/store.injectable";
|
||||
import terminalSpawningPoolInjectable from "./components/dock/terminal/terminal-spawning-pool.injectable";
|
||||
import hostedClusterIdInjectable from "../common/cluster-store/hosted-cluster-id.injectable";
|
||||
import type { GetDiForUnitTestingOptions } from "../test-utils/get-dis-for-unit-testing";
|
||||
import historyInjectable from "./navigation/history.injectable";
|
||||
import { ApiManager } from "../common/k8s-api/api-manager";
|
||||
import lensResourcesDirInjectable from "../common/vars/lens-resources-dir.injectable";
|
||||
import broadcastMessageInjectable from "../common/ipc/broadcast-message.injectable";
|
||||
import apiManagerInjectable from "../common/k8s-api/api-manager/manager.injectable";
|
||||
import ipcRendererInjectable
|
||||
from "./app-paths/get-value-from-registered-channel/ipc-renderer/ipc-renderer.injectable";
|
||||
import ipcRendererInjectable from "./utils/channel/ipc-renderer.injectable";
|
||||
import type { IpcRenderer } from "electron";
|
||||
import setupOnApiErrorListenersInjectable from "./api/setup-on-api-errors.injectable";
|
||||
import { observable } from "mobx";
|
||||
import defaultShellInjectable from "./components/+preferences/default-shell.injectable";
|
||||
import appVersionInjectable from "../common/get-configuration-file-model/app-version/app-version.injectable";
|
||||
import provideInitialValuesForSyncBoxesInjectable from "./utils/sync-box/provide-initial-values-for-sync-boxes.injectable";
|
||||
import requestAnimationFrameInjectable from "./components/animate/request-animation-frame.injectable";
|
||||
import getRandomIdInjectable from "../common/utils/get-random-id.injectable";
|
||||
|
||||
export const getDiForUnitTesting = (opts: GetDiForUnitTestingOptions = {}) => {
|
||||
export const getDiForUnitTesting = (opts: { doGeneralOverrides?: boolean } = {}) => {
|
||||
const {
|
||||
doGeneralOverrides = false,
|
||||
} = opts;
|
||||
@@ -65,6 +67,7 @@ export const getDiForUnitTesting = (opts: GetDiForUnitTestingOptions = {}) => {
|
||||
di.preventSideEffects();
|
||||
|
||||
if (doGeneralOverrides) {
|
||||
di.override(getRandomIdInjectable, () => () => "some-irrelevant-random-id");
|
||||
di.override(isMacInjectable, () => true);
|
||||
di.override(isWindowsInjectable, () => false);
|
||||
di.override(isLinuxInjectable, () => false);
|
||||
@@ -75,8 +78,12 @@ export const getDiForUnitTesting = (opts: GetDiForUnitTestingOptions = {}) => {
|
||||
di.override(getAbsolutePathInjectable, () => getAbsolutePathFake);
|
||||
di.override(joinPathsInjectable, () => joinPathsFake);
|
||||
|
||||
di.override(appVersionInjectable, () => "1.0.0");
|
||||
|
||||
di.override(historyInjectable, () => createMemoryHistory());
|
||||
|
||||
di.override(requestAnimationFrameInjectable, () => (callback) => callback());
|
||||
|
||||
di.override(lensResourcesDirInjectable, () => "/irrelevant");
|
||||
|
||||
di.override(ipcRendererInjectable, () => ({
|
||||
@@ -99,6 +106,9 @@ export const getDiForUnitTesting = (opts: GetDiForUnitTestingOptions = {}) => {
|
||||
di.override(clusterStoreInjectable, () => ({ getById: (id): Cluster => ({}) as Cluster }) as ClusterStore);
|
||||
|
||||
di.override(setupOnApiErrorListenersInjectable, () => ({ run: () => {} }));
|
||||
di.override(provideInitialValuesForSyncBoxesInjectable, () => ({ run: () => {} }));
|
||||
|
||||
di.override(defaultShellInjectable, () => "some-default-shell");
|
||||
|
||||
di.override(
|
||||
userStoreInjectable,
|
||||
@@ -114,8 +124,7 @@ export const getDiForUnitTesting = (opts: GetDiForUnitTestingOptions = {}) => {
|
||||
|
||||
di.override(apiManagerInjectable, () => new ApiManager());
|
||||
|
||||
di.override(getValueFromRegisteredChannelInjectable, () => () => Promise.resolve(undefined as never));
|
||||
di.override(registerIpcChannelListenerInjectable, () => () => undefined);
|
||||
di.override(requestFromChannelInjectable, () => () => Promise.resolve(undefined as never));
|
||||
|
||||
overrideFsWithFakes(di);
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectionToken } from "@ogre-tools/injectable";
|
||||
import type { Channel } from "../../common/ipc-channel/channel";
|
||||
|
||||
|
||||
export interface IpcChannelListener {
|
||||
channel: Channel<unknown>;
|
||||
handle: (value: any) => void;
|
||||
}
|
||||
|
||||
export const ipcChannelListenerInjectionToken =
|
||||
getInjectionToken<IpcChannelListener>({
|
||||
id: "ipc-channel-listener-injection-token",
|
||||
});
|
||||
@@ -1,28 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) OpenLens Authors. All rights reserved.
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import { ipcChannelListenerInjectionToken } from "./ipc-channel-listener-injection-token";
|
||||
import registerIpcChannelListenerInjectable from "../app-paths/get-value-from-registered-channel/register-ipc-channel-listener.injectable";
|
||||
import { beforeFrameStartsInjectionToken } from "../before-frame-starts/before-frame-starts-injection-token";
|
||||
|
||||
const registerIpcChannelListenersInjectable = getInjectable({
|
||||
id: "register-ipc-channel-listeners",
|
||||
|
||||
instantiate: di => ({
|
||||
run: async () => {
|
||||
const registerIpcChannelListener = di.inject(registerIpcChannelListenerInjectable);
|
||||
|
||||
const listeners = di.injectMany(ipcChannelListenerInjectionToken);
|
||||
|
||||
listeners.forEach(listener => {
|
||||
registerIpcChannelListener(listener);
|
||||
});
|
||||
},
|
||||
}),
|
||||
|
||||
injectionToken: beforeFrameStartsInjectionToken,
|
||||
});
|
||||
|
||||
export default registerIpcChannelListenersInjectable;
|
||||
@@ -5,17 +5,19 @@
|
||||
import { getInjectable } from "@ogre-tools/injectable";
|
||||
import navigateToEntitySettingsInjectable from "../../common/front-end-routing/routes/entity-settings/navigate-to-entity-settings.injectable";
|
||||
import type { ListNamespaceForbiddenArgs } from "../../common/ipc/cluster";
|
||||
import { Notifications, notificationsStore } from "../components/notifications";
|
||||
import { Notifications } from "../components/notifications";
|
||||
import { ClusterStore } from "../../common/cluster-store/cluster-store";
|
||||
import { Button } from "../components/button";
|
||||
import type { IpcRendererEvent } from "electron";
|
||||
import React from "react";
|
||||
import notificationsStoreInjectable from "../components/notifications/notifications-store.injectable";
|
||||
|
||||
const listNamespacesForbiddenHandlerInjectable = getInjectable({
|
||||
id: "list-namespaces-forbidden-handler",
|
||||
|
||||
instantiate: (di) => {
|
||||
const navigateToEntitySettings = di.inject(navigateToEntitySettingsInjectable);
|
||||
const notificationsStore = di.inject(notificationsStoreInjectable);
|
||||
|
||||
const notificationLastDisplayedAt = new Map<string, number>();
|
||||
const intervalBetweenNotifications = 1000 * 60; // 60s
|
||||
|
||||
@@ -3,89 +3,14 @@
|
||||
* Licensed under MIT License. See LICENSE in root directory for more information.
|
||||
*/
|
||||
|
||||
import React from "react";
|
||||
import type { IpcRendererEvent } from "electron";
|
||||
import { ipcRenderer } from "electron";
|
||||
import type { UpdateAvailableFromMain, BackchannelArg } from "../../common/ipc";
|
||||
import { areArgsUpdateAvailableFromMain, UpdateAvailableChannel, onCorrect, ipcRendererOn, AutoUpdateChecking, AutoUpdateNoUpdateAvailable } from "../../common/ipc";
|
||||
import { Notifications, notificationsStore } from "../components/notifications";
|
||||
import { Button } from "../components/button";
|
||||
import { isMac } from "../../common/vars";
|
||||
import { onCorrect } from "../../common/ipc";
|
||||
import { Notifications } from "../components/notifications";
|
||||
import { defaultHotbarCells } from "../../common/hotbars/types";
|
||||
import { type ListNamespaceForbiddenArgs, clusterListNamespaceForbiddenChannel, isListNamespaceForbiddenArgs } from "../../common/ipc/cluster";
|
||||
import { hotbarTooManyItemsChannel } from "../../common/ipc/hotbar";
|
||||
|
||||
function sendToBackchannel(backchannel: string, notificationId: string, data: BackchannelArg): void {
|
||||
notificationsStore.remove(notificationId);
|
||||
ipcRenderer.send(backchannel, data);
|
||||
}
|
||||
|
||||
function RenderYesButtons(props: { backchannel: string; notificationId: string }) {
|
||||
if (isMac) {
|
||||
/**
|
||||
* auto-updater's "installOnQuit" is not applicable for macOS as per their docs.
|
||||
*
|
||||
* See: https://github.com/electron-userland/electron-builder/blob/master/packages/electron-updater/src/AppUpdater.ts#L27-L32
|
||||
*/
|
||||
return (
|
||||
<Button
|
||||
light
|
||||
label="Yes"
|
||||
onClick={() => sendToBackchannel(props.backchannel, props.notificationId, { doUpdate: true, now: true })}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Button
|
||||
light
|
||||
label="Yes, now"
|
||||
onClick={() => sendToBackchannel(props.backchannel, props.notificationId, { doUpdate: true, now: true })}
|
||||
/>
|
||||
<Button
|
||||
active
|
||||
outlined
|
||||
label="Yes, later"
|
||||
onClick={() => sendToBackchannel(props.backchannel, props.notificationId, { doUpdate: true, now: false })}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function UpdateAvailableHandler(event: IpcRendererEvent, ...[backchannel, updateInfo]: UpdateAvailableFromMain): void {
|
||||
const notificationId = `update-available:${updateInfo.version}`;
|
||||
|
||||
Notifications.info(
|
||||
(
|
||||
<div className="flex column gaps">
|
||||
<b>Update Available</b>
|
||||
<p>
|
||||
{"Version "}
|
||||
{updateInfo.version}
|
||||
{" of Lens IDE is available and ready to be installed. Would you like to update now?"}
|
||||
</p>
|
||||
<p>Lens should restart automatically, if it doesn't please restart manually. Installed extensions might require updating.</p>
|
||||
<div className="flex gaps row align-left box grow">
|
||||
<RenderYesButtons backchannel={backchannel} notificationId={notificationId} />
|
||||
<Button
|
||||
active
|
||||
outlined
|
||||
label="No"
|
||||
onClick={() => sendToBackchannel(backchannel, notificationId, { doUpdate: false })}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
{
|
||||
id: notificationId,
|
||||
onClose() {
|
||||
sendToBackchannel(backchannel, notificationId, { doUpdate: false });
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function HotbarTooManyItemsHandler(): void {
|
||||
Notifications.error(`Cannot have more than ${defaultHotbarCells} items pinned to a hotbar`);
|
||||
}
|
||||
@@ -98,12 +23,6 @@ interface Dependencies {
|
||||
}
|
||||
|
||||
export const registerIpcListeners = ({ listNamespacesForbiddenHandler }: Dependencies) => () => {
|
||||
onCorrect({
|
||||
source: ipcRenderer,
|
||||
channel: UpdateAvailableChannel,
|
||||
listener: UpdateAvailableHandler,
|
||||
verifier: areArgsUpdateAvailableFromMain,
|
||||
});
|
||||
onCorrect({
|
||||
source: ipcRenderer,
|
||||
channel: clusterListNamespaceForbiddenChannel,
|
||||
@@ -115,11 +34,4 @@ export const registerIpcListeners = ({ listNamespacesForbiddenHandler }: Depende
|
||||
channel: hotbarTooManyItemsChannel,
|
||||
listener: HotbarTooManyItemsHandler,
|
||||
verifier: (args: unknown[]): args is [] => args.length === 0,
|
||||
});
|
||||
ipcRendererOn(AutoUpdateChecking, () => {
|
||||
Notifications.shortInfo("Checking for updates");
|
||||
});
|
||||
ipcRendererOn(AutoUpdateNoUpdateAvailable, () => {
|
||||
Notifications.shortInfo("No update is currently available");
|
||||
});
|
||||
};
|
||||
});};
|
||||
File renamed without changes.
Loaded 100 of 375 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user