mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Monaco editor refactoring (#4225)
* monaco editor refactoring Signed-off-by: Roman <ixrock@gmail.com> * clean up / responding to comments Signed-off-by: Roman <ixrock@gmail.com> * move custom monaco themes to own folder Signed-off-by: Roman <ixrock@gmail.com> * fix lint Signed-off-by: Roman <ixrock@gmail.com> * removed unused rules from webpack's config (renderer) Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
0ae4dfbeab
commit
368e2d9a00
@ -378,11 +378,12 @@ utils.describeIf(minikubeReady(TEST_NAMESPACE))("Minikube based tests", () => {
|
|||||||
await kubeApiServerRow.click();
|
await kubeApiServerRow.click();
|
||||||
await frame.waitForSelector(".Drawer", { state: "visible" });
|
await frame.waitForSelector(".Drawer", { state: "visible" });
|
||||||
|
|
||||||
const logButton = await frame.waitForSelector("ul.KubeObjectMenu li.MenuItem i.Icon span[data-icon-name='subject']");
|
const showPodLogsIcon = await frame.waitForSelector(".Drawer .drawer-title .Icon >> text=subject");
|
||||||
|
|
||||||
await logButton.click();
|
showPodLogsIcon.click();
|
||||||
|
|
||||||
// Check if controls are available
|
// Check if controls are available
|
||||||
|
await frame.waitForSelector(".Dock.isOpen");
|
||||||
await frame.waitForSelector(".LogList .VirtualList");
|
await frame.waitForSelector(".LogList .VirtualList");
|
||||||
await frame.waitForSelector(".LogResourceSelector");
|
await frame.waitForSelector(".LogResourceSelector");
|
||||||
|
|
||||||
@ -447,31 +448,31 @@ utils.describeIf(minikubeReady(TEST_NAMESPACE))("Minikube based tests", () => {
|
|||||||
await frame.waitForTimeout(100_000);
|
await frame.waitForTimeout(100_000);
|
||||||
}
|
}
|
||||||
|
|
||||||
const inputField = await frame.waitForSelector(".CreateResource div.react-monaco-editor-container");
|
const testPodName = "nginx-create-pod-test";
|
||||||
|
const monacoEditor = await frame.waitForSelector(`.Dock.isOpen [data-test-component="monaco-editor"]`);
|
||||||
|
|
||||||
await inputField.click();
|
await monacoEditor.click();
|
||||||
await inputField.type("apiVersion: v1", { delay: 10 });
|
await monacoEditor.type("apiVersion: v1", { delay: 10 });
|
||||||
await inputField.press("Enter", { delay: 10 });
|
await monacoEditor.press("Enter", { delay: 10 });
|
||||||
await inputField.type("kind: Pod", { delay: 10 });
|
await monacoEditor.type("kind: Pod", { delay: 10 });
|
||||||
await inputField.press("Enter", { delay: 10 });
|
await monacoEditor.press("Enter", { delay: 10 });
|
||||||
await inputField.type("metadata:", { delay: 10 });
|
await monacoEditor.type("metadata:", { delay: 10 });
|
||||||
await inputField.press("Enter", { delay: 10 });
|
await monacoEditor.press("Enter", { delay: 10 });
|
||||||
await inputField.type(" name: nginx-create-pod-test", { delay: 10 });
|
await monacoEditor.type(` name: ${testPodName}`, { delay: 10 });
|
||||||
await inputField.press("Enter", { delay: 10 });
|
await monacoEditor.press("Enter", { delay: 10 });
|
||||||
await inputField.type(`namespace: ${TEST_NAMESPACE}`, { delay: 10 });
|
await monacoEditor.type(`namespace: ${TEST_NAMESPACE}`, { delay: 10 });
|
||||||
await inputField.press("Enter", { delay: 10 });
|
await monacoEditor.press("Enter", { delay: 10 });
|
||||||
await inputField.press("Backspace", { delay: 10 });
|
await monacoEditor.press("Backspace", { delay: 10 });
|
||||||
await inputField.type("spec:", { delay: 10 });
|
await monacoEditor.type("spec:", { delay: 10 });
|
||||||
await inputField.press("Enter", { delay: 10 });
|
await monacoEditor.press("Enter", { delay: 10 });
|
||||||
await inputField.type(" containers:", { delay: 10 });
|
await monacoEditor.type(" containers:", { delay: 10 });
|
||||||
await inputField.press("Enter", { delay: 10 });
|
await monacoEditor.press("Enter", { delay: 10 });
|
||||||
await inputField.type("- name: nginx-create-pod-test", { delay: 10 });
|
await monacoEditor.type(`- name: ${testPodName}`, { delay: 10 });
|
||||||
await inputField.press("Enter", { delay: 10 });
|
await monacoEditor.press("Enter", { delay: 10 });
|
||||||
await inputField.type(" image: nginx:alpine", { delay: 10 });
|
await monacoEditor.type(" image: nginx:alpine", { delay: 10 });
|
||||||
await inputField.press("Enter", { delay: 10 });
|
await monacoEditor.press("Enter", { delay: 10 });
|
||||||
|
|
||||||
await frame.click("button.Button >> text='Create & Close'");
|
await frame.click(".Dock .Button >> text='Create'");
|
||||||
await frame.click("div.TableCell >> text=nginx-create-pod-test");
|
await frame.waitForSelector(`.TableCell >> text=${testPodName}`);
|
||||||
await frame.waitForSelector("div.drawer-title-text >> text='Pod: nginx-create-pod-test'");
|
|
||||||
}, 10*60*1000);
|
}, 10*60*1000);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -218,7 +218,8 @@
|
|||||||
"mock-fs": "^4.14.0",
|
"mock-fs": "^4.14.0",
|
||||||
"moment": "^2.29.1",
|
"moment": "^2.29.1",
|
||||||
"moment-timezone": "^0.5.33",
|
"moment-timezone": "^0.5.33",
|
||||||
"monaco-editor": "^0.26.1",
|
"monaco-editor": "^0.29.1",
|
||||||
|
"monaco-editor-webpack-plugin": "^5.0.0",
|
||||||
"node-fetch": "^2.6.6",
|
"node-fetch": "^2.6.6",
|
||||||
"node-pty": "^0.10.1",
|
"node-pty": "^0.10.1",
|
||||||
"npm": "^6.14.15",
|
"npm": "^6.14.15",
|
||||||
@ -228,7 +229,6 @@
|
|||||||
"react": "^17.0.2",
|
"react": "^17.0.2",
|
||||||
"react-dom": "^17.0.2",
|
"react-dom": "^17.0.2",
|
||||||
"react-material-ui-carousel": "^2.3.5",
|
"react-material-ui-carousel": "^2.3.5",
|
||||||
"react-monaco-editor": "^0.44.0",
|
|
||||||
"react-router": "^5.2.0",
|
"react-router": "^5.2.0",
|
||||||
"react-virtualized-auto-sizer": "^1.0.6",
|
"react-virtualized-auto-sizer": "^1.0.6",
|
||||||
"readable-stream": "^3.6.0",
|
"readable-stream": "^3.6.0",
|
||||||
|
|||||||
@ -23,8 +23,6 @@ import { SearchStore } from "../search-store";
|
|||||||
import { Console } from "console";
|
import { Console } from "console";
|
||||||
import { stdout, stderr } from "process";
|
import { stdout, stderr } from "process";
|
||||||
|
|
||||||
jest.mock("react-monaco-editor", () => null);
|
|
||||||
|
|
||||||
jest.mock("electron", () => ({
|
jest.mock("electron", () => ({
|
||||||
app: {
|
app: {
|
||||||
getPath: () => "/foo",
|
getPath: () => "/foo",
|
||||||
|
|||||||
@ -24,7 +24,7 @@ import path from "path";
|
|||||||
import os from "os";
|
import os from "os";
|
||||||
import { ThemeStore } from "../../renderer/theme.store";
|
import { ThemeStore } from "../../renderer/theme.store";
|
||||||
import { getAppVersion, ObservableToggleSet } from "../utils";
|
import { getAppVersion, ObservableToggleSet } from "../utils";
|
||||||
import type { monaco } from "react-monaco-editor";
|
import type { editor } from "monaco-editor";
|
||||||
import merge from "lodash/merge";
|
import merge from "lodash/merge";
|
||||||
import { SemVer } from "semver";
|
import { SemVer } from "semver";
|
||||||
|
|
||||||
@ -32,20 +32,19 @@ export interface KubeconfigSyncEntry extends KubeconfigSyncValue {
|
|||||||
filePath: string;
|
filePath: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface KubeconfigSyncValue { }
|
export interface KubeconfigSyncValue {
|
||||||
|
|
||||||
export interface EditorConfiguration {
|
|
||||||
miniMap?: monaco.editor.IEditorMinimapOptions;
|
|
||||||
lineNumbers?: monaco.editor.LineNumbersType;
|
|
||||||
tabSize?: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type EditorConfiguration = Pick<editor.IStandaloneEditorConstructionOptions,
|
||||||
|
"minimap" | "tabSize" | "lineNumbers">;
|
||||||
|
|
||||||
export const defaultEditorConfig: EditorConfiguration = {
|
export const defaultEditorConfig: EditorConfiguration = {
|
||||||
lineNumbers: "on",
|
|
||||||
miniMap: {
|
|
||||||
enabled: true,
|
|
||||||
},
|
|
||||||
tabSize: 2,
|
tabSize: 2,
|
||||||
|
lineNumbers: "on",
|
||||||
|
minimap: {
|
||||||
|
enabled: true,
|
||||||
|
side: "right",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
interface PreferenceDescription<T, R = T> {
|
interface PreferenceDescription<T, R = T> {
|
||||||
|
|||||||
@ -21,18 +21,16 @@
|
|||||||
|
|
||||||
import { app, ipcMain } from "electron";
|
import { app, ipcMain } from "electron";
|
||||||
import semver, { SemVer } from "semver";
|
import semver, { SemVer } from "semver";
|
||||||
import { action, computed, observable, reaction, makeObservable } from "mobx";
|
import { action, computed, makeObservable, observable, reaction } from "mobx";
|
||||||
import { BaseStore } from "../base-store";
|
import { BaseStore } from "../base-store";
|
||||||
import migrations from "../../migrations/user-store";
|
import migrations, { fileNameMigration } from "../../migrations/user-store";
|
||||||
import { getAppVersion } from "../utils/app-version";
|
import { getAppVersion } from "../utils/app-version";
|
||||||
import { kubeConfigDefaultPath } from "../kube-helpers";
|
import { kubeConfigDefaultPath } from "../kube-helpers";
|
||||||
import { appEventBus } from "../event-bus";
|
import { appEventBus } from "../event-bus";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { fileNameMigration } from "../../migrations/user-store";
|
|
||||||
import { ObservableToggleSet, toJS } from "../../renderer/utils";
|
import { ObservableToggleSet, toJS } from "../../renderer/utils";
|
||||||
import { DESCRIPTORS, KubeconfigSyncValue, UserPreferencesModel, EditorConfiguration } from "./preferences-helpers";
|
import { DESCRIPTORS, EditorConfiguration, KubeconfigSyncValue, UserPreferencesModel } from "./preferences-helpers";
|
||||||
import logger from "../../main/logger";
|
import logger from "../../main/logger";
|
||||||
import type { monaco } from "react-monaco-editor";
|
|
||||||
import { AppPaths } from "../app-paths";
|
import { AppPaths } from "../app-paths";
|
||||||
|
|
||||||
export interface UserStoreModel {
|
export interface UserStoreModel {
|
||||||
@ -92,7 +90,7 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
|
|||||||
/**
|
/**
|
||||||
* Monaco editor configs
|
* Monaco editor configs
|
||||||
*/
|
*/
|
||||||
@observable editorConfiguration:EditorConfiguration = { tabSize: null, miniMap: null, lineNumbers: null };
|
@observable editorConfiguration: EditorConfiguration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The set of file/folder paths to be synced
|
* The set of file/folder paths to be synced
|
||||||
@ -129,28 +127,6 @@ export class UserStore extends BaseStore<UserStoreModel> /* implements UserStore
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns monaco editor options for selected editor type (the place, where a particular instance of the editor is mounted)
|
|
||||||
getEditorOptions(): monaco.editor.IStandaloneEditorConstructionOptions {
|
|
||||||
return {
|
|
||||||
automaticLayout: true,
|
|
||||||
tabSize: this.editorConfiguration.tabSize,
|
|
||||||
minimap: this.editorConfiguration.miniMap,
|
|
||||||
lineNumbers: this.editorConfiguration.lineNumbers,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
setEditorLineNumbers(lineNumbers: monaco.editor.LineNumbersType) {
|
|
||||||
this.editorConfiguration.lineNumbers = lineNumbers;
|
|
||||||
}
|
|
||||||
|
|
||||||
setEditorTabSize(tabSize: number) {
|
|
||||||
this.editorConfiguration.tabSize = tabSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
enableEditorMinimap(miniMap: boolean ) {
|
|
||||||
this.editorConfiguration.miniMap.enabled = miniMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a column (by ID) for a table (by ID) is configured to be hidden
|
* Checks if a column (by ID) for a table (by ID) is configured to be hidden
|
||||||
* @param tableId The ID of the table to be checked against
|
* @param tableId The ID of the table to be checked against
|
||||||
|
|||||||
@ -19,19 +19,18 @@
|
|||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { jest } from "@jest/globals";
|
||||||
import { ClusterPageRegistry, getExtensionPageUrl, GlobalPageRegistry, PageParams } from "../page-registry";
|
import { ClusterPageRegistry, getExtensionPageUrl, GlobalPageRegistry, PageParams } from "../page-registry";
|
||||||
import { LensExtension } from "../../lens-extension";
|
import { LensExtension } from "../../lens-extension";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import fse from "fs-extra";
|
import fse from "fs-extra";
|
||||||
import { Console } from "console";
|
import { Console } from "console";
|
||||||
import { stdout, stderr } from "process";
|
import { stderr, stdout } from "process";
|
||||||
|
import { TerminalStore } from "../../../renderer/components/dock/terminal.store";
|
||||||
import { ThemeStore } from "../../../renderer/theme.store";
|
import { ThemeStore } from "../../../renderer/theme.store";
|
||||||
import { TerminalStore } from "../../renderer-api/components";
|
|
||||||
import { UserStore } from "../../../common/user-store";
|
import { UserStore } from "../../../common/user-store";
|
||||||
import { AppPaths } from "../../../common/app-paths";
|
import { AppPaths } from "../../../common/app-paths";
|
||||||
|
|
||||||
jest.mock("react-monaco-editor", () => null);
|
|
||||||
|
|
||||||
jest.mock("electron", () => ({
|
jest.mock("electron", () => ({
|
||||||
app: {
|
app: {
|
||||||
getVersion: () => "99.99.99",
|
getVersion: () => "99.99.99",
|
||||||
|
|||||||
@ -28,7 +28,6 @@ import * as ReactRouter from "react-router";
|
|||||||
import * as ReactRouterDom from "react-router-dom";
|
import * as ReactRouterDom from "react-router-dom";
|
||||||
import * as LensExtensionsCommonApi from "../extensions/common-api";
|
import * as LensExtensionsCommonApi from "../extensions/common-api";
|
||||||
import * as LensExtensionsRendererApi from "../extensions/renderer-api";
|
import * as LensExtensionsRendererApi from "../extensions/renderer-api";
|
||||||
import { monaco } from "react-monaco-editor";
|
|
||||||
import { render } from "react-dom";
|
import { render } from "react-dom";
|
||||||
import { delay } from "../common/utils";
|
import { delay } from "../common/utils";
|
||||||
import { isMac, isDevelopment } from "../common/vars";
|
import { isMac, isDevelopment } from "../common/vars";
|
||||||
@ -48,14 +47,15 @@ import { FilesystemProvisionerStore } from "../main/extension-filesystem";
|
|||||||
import { ThemeStore } from "./theme.store";
|
import { ThemeStore } from "./theme.store";
|
||||||
import { SentryInit } from "../common/sentry";
|
import { SentryInit } from "../common/sentry";
|
||||||
import { TerminalStore } from "./components/dock/terminal.store";
|
import { TerminalStore } from "./components/dock/terminal.store";
|
||||||
import cloudsMidnight from "./monaco-themes/Clouds Midnight.json";
|
|
||||||
import { AppPaths } from "../common/app-paths";
|
import { AppPaths } from "../common/app-paths";
|
||||||
|
import { registerCustomThemes } from "./components/monaco-editor";
|
||||||
|
|
||||||
if (process.isMainFrame) {
|
if (process.isMainFrame) {
|
||||||
SentryInit();
|
SentryInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
configurePackages();
|
configurePackages(); // global packages
|
||||||
|
registerCustomThemes(); // monaco editor themes
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If this is a development build, wait a second to attach
|
* If this is a development build, wait a second to attach
|
||||||
@ -106,12 +106,6 @@ export async function bootstrap(comp: () => Promise<AppComponent>) {
|
|||||||
ExtensionsStore.createInstance();
|
ExtensionsStore.createInstance();
|
||||||
FilesystemProvisionerStore.createInstance();
|
FilesystemProvisionerStore.createInstance();
|
||||||
|
|
||||||
// define Monaco Editor themes
|
|
||||||
const { base, ...params } = cloudsMidnight;
|
|
||||||
const baseTheme = base as monaco.editor.BuiltinTheme;
|
|
||||||
|
|
||||||
monaco.editor.defineTheme("clouds-midnight", { base: baseTheme, ...params });
|
|
||||||
|
|
||||||
// ThemeStore depends on: UserStore
|
// ThemeStore depends on: UserStore
|
||||||
ThemeStore.createInstance();
|
ThemeStore.createInstance();
|
||||||
|
|
||||||
|
|||||||
@ -20,38 +20,26 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
.AddClusters {
|
.AddClusters {
|
||||||
--flex-gap: #{$unit * 2};
|
--flex-gap: calc(var(--unit) * 2);
|
||||||
$spacing: $padding * 2;
|
|
||||||
|
|
||||||
.MonacoEditor {
|
|
||||||
min-height: 600px;
|
|
||||||
max-height: 600px;
|
|
||||||
border: 1px solid var(--colorVague);
|
|
||||||
border-radius: $radius;
|
|
||||||
|
|
||||||
.theme-light & {
|
|
||||||
border-color: var(--borderFaintColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
.editor {
|
|
||||||
border-radius: $radius;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
code {
|
code {
|
||||||
color: $pink-400;
|
color: rgb(236, 64, 122);
|
||||||
}
|
|
||||||
|
|
||||||
.text-primary {
|
|
||||||
color: var(--textColorAccent);
|
|
||||||
}
|
|
||||||
|
|
||||||
.hint {
|
|
||||||
display: block;
|
|
||||||
padding-top: 6px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
a[href] {
|
a[href] {
|
||||||
color: var(--colorInfo);
|
color: var(--colorInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.editor {
|
||||||
|
min-height: 600px;
|
||||||
|
max-height: 600px;
|
||||||
|
border: 1px solid var(--colorVague);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.theme-light) {
|
||||||
|
.editor {
|
||||||
|
border-color: var(--borderFaintColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -19,12 +19,12 @@
|
|||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import "./add-cluster.scss";
|
import styles from "./add-cluster.module.css";
|
||||||
|
|
||||||
import type { KubeConfig } from "@kubernetes/client-node";
|
import type { KubeConfig } from "@kubernetes/client-node";
|
||||||
import fse from "fs-extra";
|
import fse from "fs-extra";
|
||||||
import { debounce } from "lodash";
|
import { debounce } from "lodash";
|
||||||
import { action, computed, observable, makeObservable } from "mobx";
|
import { action, computed, makeObservable, observable } from "mobx";
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
@ -34,13 +34,11 @@ import { appEventBus } from "../../../common/event-bus";
|
|||||||
import { loadConfigFromString, splitConfig } from "../../../common/kube-helpers";
|
import { loadConfigFromString, splitConfig } from "../../../common/kube-helpers";
|
||||||
import { docsUrl } from "../../../common/vars";
|
import { docsUrl } from "../../../common/vars";
|
||||||
import { navigate } from "../../navigation";
|
import { navigate } from "../../navigation";
|
||||||
import { getCustomKubeConfigPath, cssNames, iter } from "../../utils";
|
import { getCustomKubeConfigPath, iter } from "../../utils";
|
||||||
import { Button } from "../button";
|
import { Button } from "../button";
|
||||||
import { Notifications } from "../notifications";
|
import { Notifications } from "../notifications";
|
||||||
import { SettingLayout } from "../layout/setting-layout";
|
import { SettingLayout } from "../layout/setting-layout";
|
||||||
import MonacoEditor from "react-monaco-editor";
|
import { MonacoEditor } from "../monaco-editor";
|
||||||
import { ThemeStore } from "../../theme.store";
|
|
||||||
import { UserStore } from "../../../common/user-store";
|
|
||||||
|
|
||||||
interface Option {
|
interface Option {
|
||||||
config: KubeConfig;
|
config: KubeConfig;
|
||||||
@ -85,7 +83,7 @@ export class AddCluster extends React.Component {
|
|||||||
const { config, error } = loadConfigFromString(this.customConfig.trim() || "{}");
|
const { config, error } = loadConfigFromString(this.customConfig.trim() || "{}");
|
||||||
|
|
||||||
this.kubeContexts.replace(getContexts(config));
|
this.kubeContexts.replace(getContexts(config));
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
this.errors.push(error.toString());
|
this.errors.push(error.toString());
|
||||||
}
|
}
|
||||||
@ -116,7 +114,7 @@ export class AddCluster extends React.Component {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<SettingLayout className="AddClusters">
|
<SettingLayout className={styles.AddClusters}>
|
||||||
<h2>Add Clusters from Kubeconfig</h2>
|
<h2>Add Clusters from Kubeconfig</h2>
|
||||||
<p>
|
<p>
|
||||||
Clusters added here are <b>not</b> merged into the <code>~/.kube/config</code> file.{" "}
|
Clusters added here are <b>not</b> merged into the <code>~/.kube/config</code> file.{" "}
|
||||||
@ -124,10 +122,8 @@ export class AddCluster extends React.Component {
|
|||||||
</p>
|
</p>
|
||||||
<div className="flex column">
|
<div className="flex column">
|
||||||
<MonacoEditor
|
<MonacoEditor
|
||||||
options={{ ...UserStore.getInstance().getEditorOptions() }}
|
autoFocus
|
||||||
className={cssNames("MonacoEditor")}
|
className={styles.editor}
|
||||||
theme={ThemeStore.getInstance().activeTheme.monacoTheme}
|
|
||||||
language="yaml"
|
|
||||||
value={this.customConfig}
|
value={this.customConfig}
|
||||||
onChange={value => {
|
onChange={value => {
|
||||||
this.customConfig = value;
|
this.customConfig = value;
|
||||||
|
|||||||
@ -86,13 +86,7 @@
|
|||||||
font-size: small;
|
font-size: small;
|
||||||
}
|
}
|
||||||
|
|
||||||
.values {
|
.values + .Button {
|
||||||
.MonacoEditor {
|
align-self: flex-start;
|
||||||
min-height: 300px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.MonacoEditor + .Button {
|
|
||||||
align-self: flex-start;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -24,7 +24,7 @@ import "./release-details.scss";
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import groupBy from "lodash/groupBy";
|
import groupBy from "lodash/groupBy";
|
||||||
import isEqual from "lodash/isEqual";
|
import isEqual from "lodash/isEqual";
|
||||||
import { observable, reaction, makeObservable } from "mobx";
|
import { makeObservable, observable, reaction } from "mobx";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import kebabCase from "lodash/kebabCase";
|
import kebabCase from "lodash/kebabCase";
|
||||||
import { getRelease, getReleaseValues, HelmRelease, IReleaseDetails } from "../../../common/k8s-api/endpoints/helm-releases.api";
|
import { getRelease, getReleaseValues, HelmRelease, IReleaseDetails } from "../../../common/k8s-api/endpoints/helm-releases.api";
|
||||||
@ -46,8 +46,7 @@ import { secretsStore } from "../+config-secrets/secrets.store";
|
|||||||
import { Secret } from "../../../common/k8s-api/endpoints";
|
import { Secret } from "../../../common/k8s-api/endpoints";
|
||||||
import { getDetailsUrl } from "../kube-detail-params";
|
import { getDetailsUrl } from "../kube-detail-params";
|
||||||
import { Checkbox } from "../checkbox";
|
import { Checkbox } from "../checkbox";
|
||||||
import MonacoEditor from "react-monaco-editor";
|
import { MonacoEditor } from "../monaco-editor";
|
||||||
import { UserStore } from "../../../common/user-store";
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
release: HelmRelease;
|
release: HelmRelease;
|
||||||
@ -97,7 +96,7 @@ export class ReleaseDetails extends Component<Props> {
|
|||||||
|
|
||||||
async loadDetails() {
|
async loadDetails() {
|
||||||
const { release } = this.props;
|
const { release } = this.props;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.details = null;
|
this.details = null;
|
||||||
this.details = await getRelease(release.getName(), release.getNs());
|
this.details = await getRelease(release.getName(), release.getNs());
|
||||||
@ -165,14 +164,13 @@ export class ReleaseDetails extends Component<Props> {
|
|||||||
disabled={valuesLoading}
|
disabled={valuesLoading}
|
||||||
/>
|
/>
|
||||||
<MonacoEditor
|
<MonacoEditor
|
||||||
language="yaml"
|
readOnly={valuesLoading}
|
||||||
|
className={cssNames({ loading: valuesLoading })}
|
||||||
|
style={{ minHeight: 300 }}
|
||||||
value={values}
|
value={values}
|
||||||
onChange={text => this.values = text}
|
onChange={text => this.values = text}
|
||||||
theme={ThemeStore.getInstance().activeTheme.monacoTheme}
|
|
||||||
className={cssNames("MonacoEditor", { loading: valuesLoading })}
|
|
||||||
options={{ readOnly: valuesLoading, ...UserStore.getInstance().getEditorOptions() }}
|
|
||||||
>
|
>
|
||||||
{valuesLoading && <Spinner center />}
|
{valuesLoading && <Spinner center/>}
|
||||||
</MonacoEditor>
|
</MonacoEditor>
|
||||||
<Button
|
<Button
|
||||||
primary
|
primary
|
||||||
|
|||||||
@ -44,8 +44,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.validation {
|
|
||||||
height: 400px;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@ -25,16 +25,13 @@ import React from "react";
|
|||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import { CustomResourceDefinition } from "../../../common/k8s-api/endpoints/crd.api";
|
import { CustomResourceDefinition } from "../../../common/k8s-api/endpoints/crd.api";
|
||||||
import { cssNames } from "../../utils";
|
|
||||||
import { ThemeStore } from "../../theme.store";
|
|
||||||
import { Badge } from "../badge";
|
import { Badge } from "../badge";
|
||||||
import { DrawerItem, DrawerTitle } from "../drawer";
|
import { DrawerItem, DrawerTitle } from "../drawer";
|
||||||
import type { KubeObjectDetailsProps } from "../kube-object-details";
|
import type { KubeObjectDetailsProps } from "../kube-object-details";
|
||||||
import { Table, TableCell, TableHead, TableRow } from "../table";
|
import { Table, TableCell, TableHead, TableRow } from "../table";
|
||||||
import { Input } from "../input";
|
import { Input } from "../input";
|
||||||
import { KubeObjectMeta } from "../kube-object-meta";
|
import { KubeObjectMeta } from "../kube-object-meta";
|
||||||
import MonacoEditor from "react-monaco-editor";
|
import { MonacoEditor } from "../monaco-editor";
|
||||||
import { UserStore } from "../../../common/user-store";
|
|
||||||
import logger from "../../../common/logger";
|
import logger from "../../../common/logger";
|
||||||
|
|
||||||
interface Props extends KubeObjectDetailsProps<CustomResourceDefinition> {
|
interface Props extends KubeObjectDetailsProps<CustomResourceDefinition> {
|
||||||
@ -127,43 +124,41 @@ export class CRDDetails extends React.Component<Props> {
|
|||||||
</TableRow>
|
</TableRow>
|
||||||
</Table>
|
</Table>
|
||||||
{printerColumns.length > 0 &&
|
{printerColumns.length > 0 &&
|
||||||
<>
|
<>
|
||||||
<DrawerTitle title="Additional Printer Columns"/>
|
<DrawerTitle title="Additional Printer Columns"/>
|
||||||
<Table selectable className="printer-columns box grow">
|
<Table selectable className="printer-columns box grow">
|
||||||
<TableHead>
|
<TableHead>
|
||||||
<TableCell className="name">Name</TableCell>
|
<TableCell className="name">Name</TableCell>
|
||||||
<TableCell className="type">Type</TableCell>
|
<TableCell className="type">Type</TableCell>
|
||||||
<TableCell className="json-path">JSON Path</TableCell>
|
<TableCell className="json-path">JSON Path</TableCell>
|
||||||
</TableHead>
|
</TableHead>
|
||||||
{
|
{
|
||||||
printerColumns.map((column, index) => {
|
printerColumns.map((column, index) => {
|
||||||
const { name, type, jsonPath } = column;
|
const { name, type, jsonPath } = column;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TableRow key={index}>
|
<TableRow key={index}>
|
||||||
<TableCell className="name">{name}</TableCell>
|
<TableCell className="name">{name}</TableCell>
|
||||||
<TableCell className="type">{type}</TableCell>
|
<TableCell className="type">{type}</TableCell>
|
||||||
<TableCell className="json-path">
|
<TableCell className="json-path">
|
||||||
<Badge label={jsonPath}/>
|
<Badge label={jsonPath}/>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
</Table>
|
</Table>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
{validation &&
|
{validation &&
|
||||||
<>
|
<>
|
||||||
<DrawerTitle title="Validation"/>
|
<DrawerTitle title="Validation"/>
|
||||||
<MonacoEditor
|
<MonacoEditor
|
||||||
options={{ readOnly: true, ...UserStore.getInstance().getEditorOptions() }}
|
readOnly
|
||||||
className={cssNames("MonacoEditor", "validation")}
|
value={validation}
|
||||||
theme={ThemeStore.getInstance().activeTheme.monacoTheme}
|
style={{ height: 400 }}
|
||||||
language="yaml"
|
/>
|
||||||
value={validation}
|
</>
|
||||||
/>
|
|
||||||
</>
|
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -22,10 +22,10 @@ import { observer } from "mobx-react";
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { UserStore } from "../../../common/user-store";
|
import { UserStore } from "../../../common/user-store";
|
||||||
import { FormSwitch, Switcher } from "../switch";
|
import { FormSwitch, Switcher } from "../switch";
|
||||||
|
import { Select } from "../select";
|
||||||
import { SubTitle } from "../layout/sub-title";
|
import { SubTitle } from "../layout/sub-title";
|
||||||
import { Input } from "../input";
|
import { SubHeader } from "../layout/sub-header";
|
||||||
import { isNumber } from "../input/input_validators";
|
import { Input, InputValidators } from "../input";
|
||||||
import { Select, SelectOption } from "../select";
|
|
||||||
|
|
||||||
enum EditorLineNumbersStyles {
|
enum EditorLineNumbersStyles {
|
||||||
on = "On",
|
on = "On",
|
||||||
@ -35,50 +35,60 @@ enum EditorLineNumbersStyles {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const Editor = observer(() => {
|
export const Editor = observer(() => {
|
||||||
const userStore = UserStore.getInstance();
|
const editorConfiguration = UserStore.getInstance().editorConfiguration;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section id="editor">
|
<section id="editor">
|
||||||
<h2 data-testid="editor-configuration-header">Editor configuration</h2>
|
<h2 data-testid="editor-configuration-header">Editor configuration</h2>
|
||||||
|
|
||||||
|
<SubTitle title="Minimap"/>
|
||||||
<section>
|
<section>
|
||||||
<FormSwitch
|
<div className="flex gaps justify-space-between">
|
||||||
control={
|
<div className="flex gaps align-center">
|
||||||
<Switcher
|
<FormSwitch
|
||||||
checked={userStore.editorConfiguration.miniMap.enabled}
|
label={<SubHeader compact>Show minimap</SubHeader>}
|
||||||
onChange={v => userStore.enableEditorMinimap(v.target.checked)}
|
control={
|
||||||
name="minimap"
|
<Switcher
|
||||||
|
checked={editorConfiguration.minimap.enabled}
|
||||||
|
onChange={(evt, checked) => editorConfiguration.minimap.enabled = checked}
|
||||||
|
/>
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
}
|
</div>
|
||||||
label="Show minimap"
|
<div className="flex gaps align-center">
|
||||||
/>
|
<SubHeader compact>Position</SubHeader>
|
||||||
|
<Select
|
||||||
|
themeName="lens"
|
||||||
|
options={["left", "right"]}
|
||||||
|
value={editorConfiguration.minimap.side}
|
||||||
|
onChange={({ value }) => editorConfiguration.minimap.side = value}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<SubTitle title="Line numbers"/>
|
<SubTitle title="Line numbers"/>
|
||||||
<Select
|
<Select
|
||||||
options={Object.entries(EditorLineNumbersStyles).map(entry => ({ label: entry[1], value: entry[0] }))}
|
options={Object.entries(EditorLineNumbersStyles).map(([value, label]) => ({ label, value }))}
|
||||||
value={userStore.editorConfiguration?.lineNumbers}
|
value={editorConfiguration.lineNumbers}
|
||||||
onChange={({ value }: SelectOption) => userStore.setEditorLineNumbers(value)}
|
onChange={({ value }) => editorConfiguration.lineNumbers = value}
|
||||||
themeName="lens"
|
themeName="lens"
|
||||||
/>
|
/>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section>
|
<section>
|
||||||
<SubTitle title="Tab size"/>
|
<SubTitle title="Tab size"/>
|
||||||
<Input
|
<Input
|
||||||
theme="round-black"
|
theme="round-black"
|
||||||
|
type="number"
|
||||||
min={1}
|
min={1}
|
||||||
max={10}
|
validators={InputValidators.isNumber}
|
||||||
validators={[isNumber]}
|
value={editorConfiguration.tabSize.toString()}
|
||||||
value={userStore.editorConfiguration.tabSize?.toString()}
|
onChange={value => editorConfiguration.tabSize = Number(value)}
|
||||||
onChange={value => {
|
|
||||||
const n = Number(value);
|
|
||||||
|
|
||||||
if (!isNaN(n)) {
|
|
||||||
userStore.setEditorTabSize(n);
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</section>
|
</section>
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,4 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
.AddRoleDialog {
|
.AddRoleDialog {
|
||||||
.MonacoEditor {
|
|
||||||
min-height: 200px;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,15 +19,11 @@
|
|||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import "./pod-details-affinities.scss";
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import yaml from "js-yaml";
|
import yaml from "js-yaml";
|
||||||
import { DrawerParamToggler, DrawerItem } from "../drawer";
|
import { DrawerItem, DrawerParamToggler } from "../drawer";
|
||||||
import type { Pod, Deployment, DaemonSet, StatefulSet, ReplicaSet, Job } from "../../../common/k8s-api/endpoints";
|
import type { DaemonSet, Deployment, Job, Pod, ReplicaSet, StatefulSet } from "../../../common/k8s-api/endpoints";
|
||||||
import MonacoEditor from "react-monaco-editor";
|
import { MonacoEditor } from "../monaco-editor";
|
||||||
import { cssNames } from "../../utils";
|
|
||||||
import { ThemeStore } from "../../theme.store";
|
|
||||||
import { UserStore } from "../../../common/user-store";
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
workload: Pod | Deployment | DaemonSet | StatefulSet | ReplicaSet | Job;
|
workload: Pod | Deployment | DaemonSet | StatefulSet | ReplicaSet | Job;
|
||||||
@ -44,15 +40,11 @@ export class PodDetailsAffinities extends React.Component<Props> {
|
|||||||
return (
|
return (
|
||||||
<DrawerItem name="Affinities" className="PodDetailsAffinities">
|
<DrawerItem name="Affinities" className="PodDetailsAffinities">
|
||||||
<DrawerParamToggler label={affinitiesNum}>
|
<DrawerParamToggler label={affinitiesNum}>
|
||||||
<div className="ace-container">
|
<MonacoEditor
|
||||||
<MonacoEditor
|
readOnly
|
||||||
options={{ readOnly: true, ...UserStore.getInstance().getEditorOptions() }}
|
style={{ height: 200 }}
|
||||||
className={cssNames("MonacoEditor")}
|
value={yaml.dump(affinities)}
|
||||||
theme={ThemeStore.getInstance().activeTheme.monacoTheme}
|
/>
|
||||||
language="yaml"
|
|
||||||
value={yaml.dump(affinities)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</DrawerParamToggler>
|
</DrawerParamToggler>
|
||||||
</DrawerItem>
|
</DrawerItem>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -23,7 +23,6 @@ import React from "react";
|
|||||||
import { fireEvent, render } from "@testing-library/react";
|
import { fireEvent, render } from "@testing-library/react";
|
||||||
import "@testing-library/jest-dom/extend-expect";
|
import "@testing-library/jest-dom/extend-expect";
|
||||||
import fse from "fs-extra";
|
import fse from "fs-extra";
|
||||||
|
|
||||||
import { DockTabs } from "../dock-tabs";
|
import { DockTabs } from "../dock-tabs";
|
||||||
import { dockStore, DockTab, TabKind } from "../dock.store";
|
import { dockStore, DockTab, TabKind } from "../dock.store";
|
||||||
import { noop } from "../../../utils";
|
import { noop } from "../../../utils";
|
||||||
@ -32,14 +31,6 @@ import { TerminalStore } from "../terminal.store";
|
|||||||
import { UserStore } from "../../../../common/user-store";
|
import { UserStore } from "../../../../common/user-store";
|
||||||
import { AppPaths } from "../../../../common/app-paths";
|
import { AppPaths } from "../../../../common/app-paths";
|
||||||
|
|
||||||
jest.mock("react-monaco-editor", () => ({
|
|
||||||
monaco: {
|
|
||||||
editor: {
|
|
||||||
getModel: jest.fn(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
jest.mock("electron", () => ({
|
jest.mock("electron", () => ({
|
||||||
app: {
|
app: {
|
||||||
getVersion: () => "99.99.99",
|
getVersion: () => "99.99.99",
|
||||||
|
|||||||
@ -33,8 +33,6 @@ import { UserStore } from "../../../../common/user-store";
|
|||||||
import mockFs from "mock-fs";
|
import mockFs from "mock-fs";
|
||||||
import { AppPaths } from "../../../../common/app-paths";
|
import { AppPaths } from "../../../../common/app-paths";
|
||||||
|
|
||||||
jest.mock("react-monaco-editor", () => null);
|
|
||||||
|
|
||||||
jest.mock("electron", () => ({
|
jest.mock("electron", () => ({
|
||||||
app: {
|
app: {
|
||||||
getVersion: () => "99.99.99",
|
getVersion: () => "99.99.99",
|
||||||
|
|||||||
@ -32,8 +32,6 @@ import { AppPaths } from "../../../../common/app-paths";
|
|||||||
|
|
||||||
mockWindow();
|
mockWindow();
|
||||||
|
|
||||||
jest.mock("react-monaco-editor", () => null);
|
|
||||||
|
|
||||||
jest.mock("electron", () => ({
|
jest.mock("electron", () => ({
|
||||||
app: {
|
app: {
|
||||||
getVersion: () => "99.99.99",
|
getVersion: () => "99.99.99",
|
||||||
|
|||||||
@ -24,30 +24,27 @@ import "./create-resource.scss";
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs-extra";
|
import fs from "fs-extra";
|
||||||
import { Select, GroupSelectOption, SelectOption } from "../select";
|
import { GroupSelectOption, Select, SelectOption } from "../select";
|
||||||
import yaml from "js-yaml";
|
import yaml from "js-yaml";
|
||||||
import { observable, makeObservable } from "mobx";
|
import { makeObservable, observable } from "mobx";
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import { cssNames } from "../../utils";
|
|
||||||
import { createResourceStore } from "./create-resource.store";
|
import { createResourceStore } from "./create-resource.store";
|
||||||
import type { DockTab } from "./dock.store";
|
import type { DockTab } from "./dock.store";
|
||||||
import { EditorPanel } from "./editor-panel";
|
import { EditorPanel } from "./editor-panel";
|
||||||
import { InfoPanel } from "./info-panel";
|
import { InfoPanel } from "./info-panel";
|
||||||
import * as resourceApplierApi from "../../../common/k8s-api/endpoints/resource-applier.api";
|
import * as resourceApplierApi from "../../../common/k8s-api/endpoints/resource-applier.api";
|
||||||
import { Notifications } from "../notifications";
|
import { Notifications } from "../notifications";
|
||||||
import { monacoModelsManager } from "./monaco-model-manager";
|
|
||||||
import logger from "../../../common/logger";
|
import logger from "../../../common/logger";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
className?: string;
|
|
||||||
tab: DockTab;
|
tab: DockTab;
|
||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class CreateResource extends React.Component<Props> {
|
export class CreateResource extends React.Component<Props> {
|
||||||
@observable currentTemplates:Map<string, SelectOption> = new Map();
|
@observable currentTemplates: Map<string, SelectOption> = new Map();
|
||||||
@observable error = "";
|
@observable error = "";
|
||||||
@observable templates:GroupSelectOption<SelectOption>[] = [];
|
@observable templates: GroupSelectOption<SelectOption>[] = [];
|
||||||
|
|
||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
super(props);
|
super(props);
|
||||||
@ -59,12 +56,12 @@ export class CreateResource extends React.Component<Props> {
|
|||||||
createResourceStore.watchUserTemplates(() => createResourceStore.getMergedTemplates().then(v => this.updateGroupSelectOptions(v)));
|
createResourceStore.watchUserTemplates(() => createResourceStore.getMergedTemplates().then(v => this.updateGroupSelectOptions(v)));
|
||||||
}
|
}
|
||||||
|
|
||||||
updateGroupSelectOptions(templates :Record<string, string[]>) {
|
updateGroupSelectOptions(templates: Record<string, string[]>) {
|
||||||
this.templates = Object.entries(templates)
|
this.templates = Object.entries(templates)
|
||||||
.map(([name, grouping]) => this.convertToGroup(name, grouping));
|
.map(([name, grouping]) => this.convertToGroup(name, grouping));
|
||||||
}
|
}
|
||||||
|
|
||||||
convertToGroup(group:string, items:string[]):GroupSelectOption {
|
convertToGroup(group: string, items: string[]): GroupSelectOption {
|
||||||
const options = items.map(v => ({ label: path.parse(v).name, value: v }));
|
const options = items.map(v => ({ label: path.parse(v).name, value: v }));
|
||||||
|
|
||||||
return { label: group, options };
|
return { label: group, options };
|
||||||
@ -82,16 +79,19 @@ export class CreateResource extends React.Component<Props> {
|
|||||||
return this.currentTemplates.get(this.tabId) ?? null;
|
return this.currentTemplates.get(this.tabId) ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
onChange = (value: string, error?: string) => {
|
onChange = (value: string) => {
|
||||||
|
this.error = ""; // reset first, validation goes later
|
||||||
createResourceStore.setData(this.tabId, value);
|
createResourceStore.setData(this.tabId, value);
|
||||||
this.error = error;
|
};
|
||||||
|
|
||||||
|
onError = (error: Error | string) => {
|
||||||
|
this.error = error.toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
onSelectTemplate = (item: SelectOption) => {
|
onSelectTemplate = (item: SelectOption) => {
|
||||||
this.currentTemplates.set(this.tabId, item);
|
this.currentTemplates.set(this.tabId, item);
|
||||||
fs.readFile(item.value, "utf8").then(v => {
|
fs.readFile(item.value, "utf8").then(v => {
|
||||||
createResourceStore.setData(this.tabId, v);
|
createResourceStore.setData(this.tabId, v);
|
||||||
monacoModelsManager.getModel(this.tabId).setValue(v ?? "");
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -129,42 +129,42 @@ export class CreateResource extends React.Component<Props> {
|
|||||||
return undefined;
|
return undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
renderControls(){
|
renderControls() {
|
||||||
return (
|
return (
|
||||||
<div className="flex gaps align-center">
|
<div className="flex gaps align-center">
|
||||||
<Select
|
<Select
|
||||||
autoConvertOptions = {false}
|
autoConvertOptions={false}
|
||||||
|
controlShouldRenderValue={false} // always keep initial placeholder
|
||||||
className="TemplateSelect"
|
className="TemplateSelect"
|
||||||
placeholder="Select Template ..."
|
placeholder="Select Template ..."
|
||||||
options={this.templates}
|
options={this.templates}
|
||||||
menuPlacement="top"
|
menuPlacement="top"
|
||||||
themeName="outlined"
|
themeName="outlined"
|
||||||
onChange={v => this.onSelectTemplate(v)}
|
onChange={v => this.onSelectTemplate(v)}
|
||||||
value = {this.currentTemplate}
|
value={this.currentTemplate}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { tabId, data, error, create, onChange } = this;
|
const { tabId, data, error } = this;
|
||||||
const { className } = this.props;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cssNames("CreateResource flex column", className)}>
|
<div className="CreateResource flex column">
|
||||||
<InfoPanel
|
<InfoPanel
|
||||||
tabId={tabId}
|
tabId={tabId}
|
||||||
error={error}
|
error={error}
|
||||||
controls={this.renderControls()}
|
controls={this.renderControls()}
|
||||||
submit={create}
|
submit={this.create}
|
||||||
submitLabel="Create"
|
submitLabel="Create"
|
||||||
showNotifications={false}
|
showNotifications={false}
|
||||||
/>
|
/>
|
||||||
<EditorPanel
|
<EditorPanel
|
||||||
tabId={tabId}
|
tabId={tabId}
|
||||||
value={data}
|
value={data}
|
||||||
onChange={onChange}
|
onChange={this.onChange}
|
||||||
|
onError={this.onError}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -81,7 +81,7 @@
|
|||||||
background: $terminalBackground;
|
background: $terminalBackground;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
transition: flex 60ms ease-in-out;
|
transition: flex-basis 25ms ease-in;
|
||||||
|
|
||||||
> *:not(.Spinner) {
|
> *:not(.Spinner) {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@ -91,8 +91,4 @@
|
|||||||
bottom: 0;
|
bottom: 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.MonacoEditor {
|
|
||||||
border: none;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,10 +20,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import * as uuid from "uuid";
|
import * as uuid from "uuid";
|
||||||
import { action, computed, IReactionOptions, makeObservable, observable, reaction } from "mobx";
|
import { action, comparer, computed, IReactionOptions, makeObservable, observable, reaction, runInAction } from "mobx";
|
||||||
import { autoBind, createStorage } from "../../utils";
|
import { autoBind, createStorage } from "../../utils";
|
||||||
import throttle from "lodash/throttle";
|
import throttle from "lodash/throttle";
|
||||||
import { monacoModelsManager } from "./monaco-model-manager";
|
|
||||||
|
|
||||||
export type TabId = string;
|
export type TabId = string;
|
||||||
|
|
||||||
@ -89,6 +88,27 @@ export interface DockStorageState {
|
|||||||
isOpen?: boolean;
|
isOpen?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DockTabChangeEvent {
|
||||||
|
tab: DockTab;
|
||||||
|
tabId: TabId;
|
||||||
|
prevTab?: DockTab;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DockTabChangeEventOptions extends IReactionOptions {
|
||||||
|
/**
|
||||||
|
* filter: by dockStore.selectedTab.kind == tabKind
|
||||||
|
*/
|
||||||
|
tabKind?: TabKind;
|
||||||
|
/**
|
||||||
|
* filter: dock and selected tab should be visible (default: true)
|
||||||
|
*/
|
||||||
|
dockIsVisible?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DockTabCloseEvent {
|
||||||
|
tabId: TabId; // closed tab id
|
||||||
|
}
|
||||||
|
|
||||||
export class DockStore implements DockStorageState {
|
export class DockStore implements DockStorageState {
|
||||||
constructor() {
|
constructor() {
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
@ -158,12 +178,6 @@ export class DockStore implements DockStorageState {
|
|||||||
private init() {
|
private init() {
|
||||||
// adjust terminal height if window size changes
|
// adjust terminal height if window size changes
|
||||||
window.addEventListener("resize", throttle(this.adjustHeight, 250));
|
window.addEventListener("resize", throttle(this.adjustHeight, 250));
|
||||||
// create monaco models
|
|
||||||
this.whenReady.then(() => {this.tabs.forEach(tab => {
|
|
||||||
if (this.usesMonacoEditor(tab)) {
|
|
||||||
monacoModelsManager.addModel(tab.id);
|
|
||||||
}
|
|
||||||
});});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get maxHeight() {
|
get maxHeight() {
|
||||||
@ -185,21 +199,44 @@ export class DockStore implements DockStorageState {
|
|||||||
return reaction(() => [this.height, this.fullSize], callback, options);
|
return reaction(() => [this.height, this.fullSize], callback, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
onTabChange(callback: (tabId: TabId) => void, options?: IReactionOptions) {
|
onTabClose(callback: (evt: DockTabCloseEvent) => void, options: IReactionOptions = {}) {
|
||||||
return reaction(() => this.selectedTabId, callback, options);
|
return reaction(() => dockStore.tabs.map(tab => tab.id), (tabs: TabId[], prevTabs?: TabId[]) => {
|
||||||
|
if (!Array.isArray(prevTabs)) {
|
||||||
|
return; // tabs not yet modified
|
||||||
|
}
|
||||||
|
|
||||||
|
const closedTabs: TabId[] = prevTabs.filter(id => !tabs.includes(id));
|
||||||
|
|
||||||
|
if (closedTabs.length > 0) {
|
||||||
|
runInAction(() => {
|
||||||
|
closedTabs.forEach(tabId => callback({ tabId }));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
equals: comparer.structural,
|
||||||
|
...options,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onTabChange(callback: (evt: DockTabChangeEvent) => void, options: DockTabChangeEventOptions = {}) {
|
||||||
|
const { tabKind, dockIsVisible = true, ...reactionOpts } = options;
|
||||||
|
|
||||||
|
return reaction(() => this.selectedTab, ((tab, prevTab) => {
|
||||||
|
if (!tab) return; // skip when dock is empty
|
||||||
|
if (tabKind && tabKind !== tab.kind) return; // handle specific tab.kind only
|
||||||
|
if (dockIsVisible && !this.isOpen) return;
|
||||||
|
|
||||||
|
callback({
|
||||||
|
tab, prevTab,
|
||||||
|
tabId: tab.id,
|
||||||
|
});
|
||||||
|
}), reactionOpts);
|
||||||
}
|
}
|
||||||
|
|
||||||
hasTabs() {
|
hasTabs() {
|
||||||
return this.tabs.length > 0;
|
return this.tabs.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
usesMonacoEditor(tab: DockTab): boolean {
|
|
||||||
return [TabKind.CREATE_RESOURCE,
|
|
||||||
TabKind.EDIT_RESOURCE,
|
|
||||||
TabKind.INSTALL_CHART,
|
|
||||||
TabKind.UPGRADE_CHART].includes(tab.kind);
|
|
||||||
}
|
|
||||||
|
|
||||||
@action
|
@action
|
||||||
open(fullSize?: boolean) {
|
open(fullSize?: boolean) {
|
||||||
this.isOpen = true;
|
this.isOpen = true;
|
||||||
@ -274,11 +311,6 @@ export class DockStore implements DockStorageState {
|
|||||||
title,
|
title,
|
||||||
};
|
};
|
||||||
|
|
||||||
// add monaco model
|
|
||||||
if (this.usesMonacoEditor(tab)) {
|
|
||||||
monacoModelsManager.addModel(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.tabs.push(tab);
|
this.tabs.push(tab);
|
||||||
this.selectTab(tab.id);
|
this.selectTab(tab.id);
|
||||||
this.open();
|
this.open();
|
||||||
@ -294,11 +326,6 @@ export class DockStore implements DockStorageState {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove monaco model
|
|
||||||
if (this.usesMonacoEditor(tab)) {
|
|
||||||
monacoModelsManager.removeModel(tabId);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.tabs = this.tabs.filter(tab => tab.id !== tabId);
|
this.tabs = this.tabs.filter(tab => tab.id !== tabId);
|
||||||
|
|
||||||
if (this.selectedTabId === tab.id) {
|
if (this.selectedTabId === tab.id) {
|
||||||
|
|||||||
@ -26,7 +26,6 @@ import { dockStore, DockTab, DockTabCreateSpecific, TabId, TabKind } from "./doc
|
|||||||
import type { KubeObject } from "../../../common/k8s-api/kube-object";
|
import type { KubeObject } from "../../../common/k8s-api/kube-object";
|
||||||
import { apiManager } from "../../../common/k8s-api/api-manager";
|
import { apiManager } from "../../../common/k8s-api/api-manager";
|
||||||
import type { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
|
import type { KubeObjectStore } from "../../../common/k8s-api/kube-object.store";
|
||||||
import { monacoModelsManager } from "./monaco-model-manager";
|
|
||||||
|
|
||||||
export interface EditingResource {
|
export interface EditingResource {
|
||||||
resource: string; // resource path, e.g. /api/v1/namespaces/default
|
resource: string; // resource path, e.g. /api/v1/namespaces/default
|
||||||
@ -63,7 +62,6 @@ export class EditResourceStore extends DockTabStore<EditingResource> {
|
|||||||
// preload resource for editing
|
// preload resource for editing
|
||||||
if (!obj && !store.isLoaded && !store.isLoading && isActiveTab) {
|
if (!obj && !store.isLoaded && !store.isLoading && isActiveTab) {
|
||||||
store.loadFromPath(resource).catch(noop);
|
store.loadFromPath(resource).catch(noop);
|
||||||
monacoModelsManager.getModel(tabId).setValue(resource);
|
|
||||||
}
|
}
|
||||||
// auto-close tab when resource removed from store
|
// auto-close tab when resource removed from store
|
||||||
else if (!obj && store.isLoaded) {
|
else if (!obj && store.isLoaded) {
|
||||||
|
|||||||
@ -26,7 +26,6 @@ import { action, computed, makeObservable, observable } from "mobx";
|
|||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import yaml from "js-yaml";
|
import yaml from "js-yaml";
|
||||||
import type { DockTab } from "./dock.store";
|
import type { DockTab } from "./dock.store";
|
||||||
import { cssNames } from "../../utils";
|
|
||||||
import { editResourceStore } from "./edit-resource.store";
|
import { editResourceStore } from "./edit-resource.store";
|
||||||
import { InfoPanel } from "./info-panel";
|
import { InfoPanel } from "./info-panel";
|
||||||
import { Badge } from "../badge";
|
import { Badge } from "../badge";
|
||||||
@ -36,7 +35,6 @@ import type { KubeObject } from "../../../common/k8s-api/kube-object";
|
|||||||
import { createPatch } from "rfc6902";
|
import { createPatch } from "rfc6902";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
className?: string;
|
|
||||||
tab: DockTab;
|
tab: DockTab;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,11 +86,15 @@ export class EditResource extends React.Component<Props> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onChange = (draft: string, error?: string) => {
|
onChange = (draft: string) => {
|
||||||
this.error = error;
|
this.error = ""; // reset first
|
||||||
this.saveDraft(draft);
|
this.saveDraft(draft);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onError = (error?: Error | string) => {
|
||||||
|
this.error = error.toString();
|
||||||
|
};
|
||||||
|
|
||||||
save = async () => {
|
save = async () => {
|
||||||
if (this.error) {
|
if (this.error) {
|
||||||
return null;
|
return null;
|
||||||
@ -114,14 +116,14 @@ export class EditResource extends React.Component<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { tabId, error, onChange, save, draft, isReadyForEditing, resource } = this;
|
const { tabId, error, onChange, onError, save, draft, isReadyForEditing, resource } = this;
|
||||||
|
|
||||||
if (!isReadyForEditing) {
|
if (!isReadyForEditing) {
|
||||||
return <Spinner center/>;
|
return <Spinner center/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cssNames("EditResource flex column", this.props.className)}>
|
<div className="EditResource flex column">
|
||||||
<InfoPanel
|
<InfoPanel
|
||||||
tabId={tabId}
|
tabId={tabId}
|
||||||
error={error}
|
error={error}
|
||||||
@ -140,6 +142,7 @@ export class EditResource extends React.Component<Props> {
|
|||||||
tabId={tabId}
|
tabId={tabId}
|
||||||
value={draft}
|
value={draft}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
|
onError={onError}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -19,8 +19,8 @@
|
|||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.PodDetailsAffinities {
|
.EditorPanel {
|
||||||
.ace-container {
|
position: relative;
|
||||||
height: 200px
|
flex: 1;
|
||||||
}
|
height: 100%;
|
||||||
}
|
}
|
||||||
@ -19,89 +19,65 @@
|
|||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import MonacoEditor, { monaco } from "react-monaco-editor";
|
import styles from "./editor-panel.module.css";
|
||||||
|
import throttle from "lodash/throttle";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import yaml from "js-yaml";
|
import { makeObservable, observable, reaction } from "mobx";
|
||||||
import { observable, makeObservable } from "mobx";
|
|
||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { disposeOnUnmount, observer } from "mobx-react";
|
||||||
import { dockStore, TabId } from "./dock.store";
|
import { dockStore, TabId } from "./dock.store";
|
||||||
import { monacoModelsManager } from "./monaco-model-manager";
|
import { cssNames } from "../../utils";
|
||||||
import { ThemeStore } from "../../theme.store";
|
import { MonacoEditor, MonacoEditorProps } from "../monaco-editor";
|
||||||
import { UserStore } from "../../../common/user-store";
|
|
||||||
|
|
||||||
import "monaco-editor";
|
export interface EditorPanelProps {
|
||||||
|
|
||||||
interface Props {
|
|
||||||
className?: string;
|
|
||||||
tabId: TabId;
|
tabId: TabId;
|
||||||
value?: string;
|
value: string;
|
||||||
onChange(value: string, error?: string): void;
|
className?: string;
|
||||||
|
autoFocus?: boolean; // default: true
|
||||||
|
onChange: MonacoEditorProps["onChange"];
|
||||||
|
onError?: MonacoEditorProps["onError"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const defaultProps: Partial<EditorPanelProps> = {
|
||||||
|
autoFocus: true,
|
||||||
|
};
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class EditorPanel extends React.Component<Props> {
|
export class EditorPanel extends React.Component<EditorPanelProps> {
|
||||||
model: monaco.editor.ITextModel;
|
static defaultProps = defaultProps as object;
|
||||||
public editor: monaco.editor.IStandaloneCodeEditor;
|
|
||||||
@observable yamlError = "";
|
|
||||||
|
|
||||||
constructor(props: Props) {
|
@observable.ref editor?: MonacoEditor;
|
||||||
|
|
||||||
|
constructor(props: EditorPanelProps) {
|
||||||
super(props);
|
super(props);
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
// validate and run callback with optional error
|
|
||||||
this.onChange(this.props.value || "");
|
|
||||||
|
|
||||||
disposeOnUnmount(this, [
|
disposeOnUnmount(this, [
|
||||||
dockStore.onTabChange(this.onTabChange, { delay: 250 }),
|
// keep focus on editor's area when <Dock/> just opened
|
||||||
dockStore.onResize(this.onResize, { delay: 250 }),
|
reaction(() => dockStore.isOpen, isOpen => isOpen && this.editor?.focus(), {
|
||||||
|
fireImmediately: true,
|
||||||
|
}),
|
||||||
|
|
||||||
|
// focus to editor on dock's resize or turning into fullscreen mode
|
||||||
|
dockStore.onResize(throttle(() => this.editor?.focus(), 250)),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
editorDidMount = (editor: monaco.editor.IStandaloneCodeEditor) => {
|
|
||||||
this.editor = editor;
|
|
||||||
const model = monacoModelsManager.getModel(this.props.tabId);
|
|
||||||
|
|
||||||
model.setValue(this.props.value ?? "");
|
|
||||||
this.editor.setModel(model);
|
|
||||||
};
|
|
||||||
|
|
||||||
validate(value: string) {
|
|
||||||
try {
|
|
||||||
yaml.loadAll(value);
|
|
||||||
this.yamlError = "";
|
|
||||||
} catch (err) {
|
|
||||||
this.yamlError = err.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onTabChange = () => {
|
|
||||||
this.editor.focus();
|
|
||||||
const model = monacoModelsManager.getModel(this.props.tabId);
|
|
||||||
|
|
||||||
model.setValue(this.props.value ?? "");
|
|
||||||
this.editor.setModel(model);
|
|
||||||
};
|
|
||||||
|
|
||||||
onResize = () => {
|
|
||||||
this.editor.focus();
|
|
||||||
};
|
|
||||||
|
|
||||||
onChange = (value: string) => {
|
|
||||||
this.validate(value);
|
|
||||||
this.props.onChange?.(value, this.yamlError);
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { className, autoFocus, tabId, value, onChange, onError } = this.props;
|
||||||
|
|
||||||
|
if (!tabId) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MonacoEditor
|
<MonacoEditor
|
||||||
options={{ model: null, ...UserStore.getInstance().getEditorOptions() }}
|
autoFocus={autoFocus}
|
||||||
theme={ThemeStore.getInstance().activeTheme.monacoTheme}
|
id={tabId}
|
||||||
language = "yaml"
|
value={value}
|
||||||
onChange = {this.onChange}
|
className={cssNames(styles.EditorPanel, className)}
|
||||||
editorDidMount={this.editorDidMount}
|
onChange={onChange}
|
||||||
|
onError={onError}
|
||||||
|
ref={monaco => this.editor = monaco}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,7 +25,6 @@ import { DockTabStore } from "./dock-tab.store";
|
|||||||
import { getChartDetails, getChartValues, HelmChart } from "../../../common/k8s-api/endpoints/helm-charts.api";
|
import { getChartDetails, getChartValues, HelmChart } from "../../../common/k8s-api/endpoints/helm-charts.api";
|
||||||
import type { IReleaseUpdateDetails } from "../../../common/k8s-api/endpoints/helm-releases.api";
|
import type { IReleaseUpdateDetails } from "../../../common/k8s-api/endpoints/helm-releases.api";
|
||||||
import { Notifications } from "../notifications";
|
import { Notifications } from "../notifications";
|
||||||
import { monacoModelsManager } from "./monaco-model-manager";
|
|
||||||
|
|
||||||
export interface IChartInstallData {
|
export interface IChartInstallData {
|
||||||
name: string;
|
name: string;
|
||||||
@ -91,7 +90,6 @@ export class InstallChartStore extends DockTabStore<IChartInstallData> {
|
|||||||
|
|
||||||
if (values) {
|
if (values) {
|
||||||
this.setData(tabId, { ...data, values });
|
this.setData(tabId, { ...data, values });
|
||||||
monacoModelsManager.getModel(tabId).setValue(values);
|
|
||||||
} else if (attempt < 4) {
|
} else if (attempt < 4) {
|
||||||
return this.loadValues(tabId, attempt + 1);
|
return this.loadValues(tabId, attempt + 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,13 +22,13 @@
|
|||||||
import "./install-chart.scss";
|
import "./install-chart.scss";
|
||||||
|
|
||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import { observable, makeObservable } from "mobx";
|
import { action, makeObservable, observable } from "mobx";
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import { dockStore, DockTab } from "./dock.store";
|
import { dockStore, DockTab } from "./dock.store";
|
||||||
import { InfoPanel } from "./info-panel";
|
import { InfoPanel } from "./info-panel";
|
||||||
import { Badge } from "../badge";
|
import { Badge } from "../badge";
|
||||||
import { NamespaceSelect } from "../+namespaces/namespace-select";
|
import { NamespaceSelect } from "../+namespaces/namespace-select";
|
||||||
import { boundMethod, prevDefault } from "../../utils";
|
import { prevDefault } from "../../utils";
|
||||||
import { IChartInstallData, installChartStore } from "./install-chart.store";
|
import { IChartInstallData, installChartStore } from "./install-chart.store";
|
||||||
import { Spinner } from "../spinner";
|
import { Spinner } from "../spinner";
|
||||||
import { Icon } from "../icon";
|
import { Icon } from "../icon";
|
||||||
@ -75,8 +75,7 @@ export class InstallChart extends Component<Props> {
|
|||||||
return installChartStore.details.getData(this.tabId);
|
return installChartStore.details.getData(this.tabId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@boundMethod
|
viewRelease = () => {
|
||||||
viewRelease() {
|
|
||||||
const { release } = this.releaseDetails;
|
const { release } = this.releaseDetails;
|
||||||
|
|
||||||
navigate(releaseURL({
|
navigate(releaseURL({
|
||||||
@ -86,38 +85,39 @@ export class InstallChart extends Component<Props> {
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
dockStore.closeTab(this.tabId);
|
dockStore.closeTab(this.tabId);
|
||||||
}
|
};
|
||||||
|
|
||||||
@boundMethod
|
|
||||||
save(data: Partial<IChartInstallData>) {
|
save(data: Partial<IChartInstallData>) {
|
||||||
const chart = { ...this.chartData, ...data };
|
const chart = { ...this.chartData, ...data };
|
||||||
|
|
||||||
installChartStore.setData(this.tabId, chart);
|
installChartStore.setData(this.tabId, chart);
|
||||||
}
|
}
|
||||||
|
|
||||||
@boundMethod
|
onVersionChange = (option: SelectOption) => {
|
||||||
onVersionChange(option: SelectOption) {
|
|
||||||
const version = option.value;
|
const version = option.value;
|
||||||
|
|
||||||
this.save({ version, values: "" });
|
this.save({ version, values: "" });
|
||||||
installChartStore.loadValues(this.tabId);
|
installChartStore.loadValues(this.tabId);
|
||||||
}
|
};
|
||||||
|
|
||||||
@boundMethod
|
@action
|
||||||
onValuesChange(values: string, error?: string) {
|
onChange = (values: string) => {
|
||||||
this.error = error;
|
this.error = "";
|
||||||
this.save({ values });
|
this.save({ values });
|
||||||
}
|
};
|
||||||
|
|
||||||
@boundMethod
|
@action
|
||||||
onNamespaceChange(opt: SelectOption) {
|
onError = (error: Error | string) => {
|
||||||
|
this.error = error.toString();
|
||||||
|
};
|
||||||
|
|
||||||
|
onNamespaceChange = (opt: SelectOption) => {
|
||||||
this.save({ namespace: opt.value });
|
this.save({ namespace: opt.value });
|
||||||
}
|
};
|
||||||
|
|
||||||
@boundMethod
|
onReleaseNameChange = (name: string) => {
|
||||||
onReleaseNameChange(name: string) {
|
|
||||||
this.save({ releaseName: name });
|
this.save({ releaseName: name });
|
||||||
}
|
};
|
||||||
|
|
||||||
install = async () => {
|
install = async () => {
|
||||||
const { repo, name, version, namespace, values, releaseName } = this.chartData;
|
const { repo, name, version, namespace, values, releaseName } = this.chartData;
|
||||||
@ -138,14 +138,14 @@ export class InstallChart extends Component<Props> {
|
|||||||
const { tabId, chartData, values, versions, install } = this;
|
const { tabId, chartData, values, versions, install } = this;
|
||||||
|
|
||||||
if (chartData?.values === undefined || !versions) {
|
if (chartData?.values === undefined || !versions) {
|
||||||
return <Spinner center />;
|
return <Spinner center/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.releaseDetails) {
|
if (this.releaseDetails) {
|
||||||
return (
|
return (
|
||||||
<div className="InstallChartDone flex column gaps align-center justify-center">
|
<div className="InstallChartDone flex column gaps align-center justify-center">
|
||||||
<p>
|
<p>
|
||||||
<Icon material="check" big sticker />
|
<Icon material="check" big sticker/>
|
||||||
</p>
|
</p>
|
||||||
<p>Installation complete!</p>
|
<p>Installation complete!</p>
|
||||||
<div className="flex gaps align-center">
|
<div className="flex gaps align-center">
|
||||||
@ -174,7 +174,7 @@ export class InstallChart extends Component<Props> {
|
|||||||
const panelControls = (
|
const panelControls = (
|
||||||
<div className="install-controls flex gaps align-center">
|
<div className="install-controls flex gaps align-center">
|
||||||
<span>Chart</span>
|
<span>Chart</span>
|
||||||
<Badge label={`${repo}/${name}`} title="Repo/Name" />
|
<Badge label={`${repo}/${name}`} title="Repo/Name"/>
|
||||||
<span>Version</span>
|
<span>Version</span>
|
||||||
<Select
|
<Select
|
||||||
className="chart-version"
|
className="chart-version"
|
||||||
@ -216,7 +216,8 @@ export class InstallChart extends Component<Props> {
|
|||||||
<EditorPanel
|
<EditorPanel
|
||||||
tabId={tabId}
|
tabId={tabId}
|
||||||
value={values}
|
value={values}
|
||||||
onChange={this.onValuesChange}
|
onChange={this.onChange}
|
||||||
|
onError={this.onError}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -22,11 +22,11 @@
|
|||||||
@import "~xterm";
|
@import "~xterm";
|
||||||
|
|
||||||
.TerminalWindow {
|
.TerminalWindow {
|
||||||
margin: $padding;
|
--spacing: calc(var(--unit) * 2);
|
||||||
margin-left: $padding * 2;
|
|
||||||
margin-top: $padding * 2;
|
|
||||||
|
|
||||||
> .xterm {
|
flex: 1;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
left: var(--spacing) !important;
|
||||||
|
top: var(--spacing) !important;
|
||||||
|
bottom: var(--spacing) !important;
|
||||||
}
|
}
|
||||||
@ -22,16 +22,14 @@
|
|||||||
import "./terminal-window.scss";
|
import "./terminal-window.scss";
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { reaction } from "mobx";
|
|
||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { disposeOnUnmount, observer } from "mobx-react";
|
||||||
import { cssNames } from "../../utils";
|
import { cssNames } from "../../utils";
|
||||||
import type { DockTab } from "./dock.store";
|
|
||||||
import type { Terminal } from "./terminal";
|
import type { Terminal } from "./terminal";
|
||||||
import { terminalStore } from "./terminal.store";
|
import { TerminalStore } from "./terminal.store";
|
||||||
import { ThemeStore } from "../../theme.store";
|
import { ThemeStore } from "../../theme.store";
|
||||||
|
import { dockStore, DockTab, TabKind, TabId } from "./dock.store";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
className?: string;
|
|
||||||
tab: DockTab;
|
tab: DockTab;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,25 +40,29 @@ export class TerminalWindow extends React.Component<Props> {
|
|||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
disposeOnUnmount(this, [
|
disposeOnUnmount(this, [
|
||||||
reaction(() => this.props.tab.id, tabId => this.activate(tabId), {
|
dockStore.onTabChange(({ tabId }) => this.activate(tabId), {
|
||||||
|
tabKind: TabKind.TERMINAL,
|
||||||
|
fireImmediately: true,
|
||||||
|
}),
|
||||||
|
|
||||||
|
// refresh terminal available space (cols/rows) when <Dock/> resized
|
||||||
|
dockStore.onResize(() => this.terminal?.fitLazy(), {
|
||||||
fireImmediately: true,
|
fireImmediately: true,
|
||||||
}),
|
}),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
activate(tabId = this.props.tab.id) {
|
activate(tabId: TabId) {
|
||||||
if (this.terminal) this.terminal.detach(); // detach previous
|
if (this.terminal) this.terminal.detach(); // detach previous
|
||||||
this.terminal = terminalStore.getTerminal(tabId);
|
this.terminal = TerminalStore.getInstance().getTerminal(tabId);
|
||||||
this.terminal.attachTo(this.elem);
|
this.terminal.attachTo(this.elem);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { className } = this.props;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cssNames("TerminalWindow", className, ThemeStore.getInstance().activeTheme.type)}
|
className={cssNames("TerminalWindow", ThemeStore.getInstance().activeTheme.type)}
|
||||||
ref={e => this.elem = e}
|
ref={elem => this.elem = elem}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,7 +25,6 @@ import { DockTabStore } from "./dock-tab.store";
|
|||||||
import { getReleaseValues, HelmRelease } from "../../../common/k8s-api/endpoints/helm-releases.api";
|
import { getReleaseValues, HelmRelease } from "../../../common/k8s-api/endpoints/helm-releases.api";
|
||||||
import { releaseStore } from "../+apps-releases/release.store";
|
import { releaseStore } from "../+apps-releases/release.store";
|
||||||
import { iter } from "../../utils";
|
import { iter } from "../../utils";
|
||||||
import { monacoModelsManager } from "./monaco-model-manager";
|
|
||||||
|
|
||||||
export interface IChartUpgradeData {
|
export interface IChartUpgradeData {
|
||||||
releaseName: string;
|
releaseName: string;
|
||||||
@ -119,7 +118,6 @@ export class UpgradeChartStore extends DockTabStore<IChartUpgradeData> {
|
|||||||
const values = await getReleaseValues(releaseName, releaseNamespace, true);
|
const values = await getReleaseValues(releaseName, releaseNamespace, true);
|
||||||
|
|
||||||
this.values.setData(tabId, values);
|
this.values.setData(tabId, values);
|
||||||
monacoModelsManager.getModel(tabId).setValue(values);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getTabByRelease(releaseName: string): DockTab {
|
getTabByRelease(releaseName: string): DockTab {
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
import "./upgrade-chart.scss";
|
import "./upgrade-chart.scss";
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { observable, reaction, makeObservable } from "mobx";
|
import { action, makeObservable, observable, reaction } from "mobx";
|
||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { disposeOnUnmount, observer } from "mobx-react";
|
||||||
import { cssNames } from "../../utils";
|
import { cssNames } from "../../utils";
|
||||||
import type { DockTab } from "./dock.store";
|
import type { DockTab } from "./dock.store";
|
||||||
@ -86,9 +86,15 @@ export class UpgradeChart extends React.Component<Props> {
|
|||||||
this.version = this.versions[0];
|
this.version = this.versions[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
onChange = (value: string, error?: string) => {
|
@action
|
||||||
|
onChange = (value: string) => {
|
||||||
|
this.error = "";
|
||||||
upgradeChartStore.values.setData(this.tabId, value);
|
upgradeChartStore.values.setData(this.tabId, value);
|
||||||
this.error = error;
|
};
|
||||||
|
|
||||||
|
@action
|
||||||
|
onError = (error: Error | string) => {
|
||||||
|
this.error = error.toString();
|
||||||
};
|
};
|
||||||
|
|
||||||
upgrade = async () => {
|
upgrade = async () => {
|
||||||
@ -118,7 +124,7 @@ export class UpgradeChart extends React.Component<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { tabId, release, value, error, onChange, upgrade, versions, version } = this;
|
const { tabId, release, value, error, onChange, onError, upgrade, versions, version } = this;
|
||||||
const { className } = this.props;
|
const { className } = this.props;
|
||||||
|
|
||||||
if (!release || upgradeChartStore.isLoading() || !version) {
|
if (!release || upgradeChartStore.isLoading() || !version) {
|
||||||
@ -157,6 +163,7 @@ export class UpgradeChart extends React.Component<Props> {
|
|||||||
tabId={tabId}
|
tabId={tabId}
|
||||||
value={value}
|
value={value}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
|
onError={onError}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -63,6 +63,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
input[type=number]::-webkit-inner-spin-button {
|
||||||
|
-webkit-appearance: none; // hide browser controls (top/bottom arrows)
|
||||||
|
}
|
||||||
|
|
||||||
input, textarea {
|
input, textarea {
|
||||||
background: none;
|
background: none;
|
||||||
color: inherit;
|
color: inherit;
|
||||||
|
|||||||
@ -20,22 +20,22 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
.KubeConfigDialog {
|
.KubeConfigDialog {
|
||||||
.theme-light & {
|
:global(.Wizard) {
|
||||||
.MonacoEditor {
|
|
||||||
border: 1px solid gainsboro;
|
|
||||||
border-radius: $radius;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.Wizard {
|
|
||||||
width: 50vw;
|
width: 50vw;
|
||||||
min-width: 600px;
|
min-width: 600px;
|
||||||
--wizard-content-height: 600px;
|
--wizard-content-height: 600px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.config-copy {
|
.configCopy {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:global(.theme-light) {
|
||||||
|
.editor {
|
||||||
|
border: 1px solid gainsboro;
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -19,23 +19,20 @@
|
|||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import "./kubeconfig-dialog.scss";
|
import styles from "./kubeconfig-dialog.module.css";
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { observable, makeObservable } from "mobx";
|
import { makeObservable, observable } from "mobx";
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import yaml from "js-yaml";
|
import yaml from "js-yaml";
|
||||||
import type { ServiceAccount } from "../../../common/k8s-api/endpoints";
|
import type { ServiceAccount } from "../../../common/k8s-api/endpoints";
|
||||||
import { copyToClipboard, cssNames, saveFileDialog } from "../../utils";
|
import { copyToClipboard, saveFileDialog } from "../../utils";
|
||||||
import { Button } from "../button";
|
import { Button } from "../button";
|
||||||
import { Dialog, DialogProps } from "../dialog";
|
import { Dialog, DialogProps } from "../dialog";
|
||||||
import { Icon } from "../icon";
|
import { Icon } from "../icon";
|
||||||
import { Notifications } from "../notifications";
|
import { Notifications } from "../notifications";
|
||||||
import { Wizard, WizardStep } from "../wizard";
|
import { Wizard, WizardStep } from "../wizard";
|
||||||
import { apiBase } from "../../api";
|
import { apiBase } from "../../api";
|
||||||
import MonacoEditor from "react-monaco-editor";
|
import { MonacoEditor } from "../monaco-editor";
|
||||||
import { ThemeStore } from "../../theme.store";
|
|
||||||
import { UserStore } from "../../../common/user-store";
|
|
||||||
|
|
||||||
interface IKubeconfigDialogData {
|
interface IKubeconfigDialogData {
|
||||||
title?: React.ReactNode;
|
title?: React.ReactNode;
|
||||||
@ -122,7 +119,7 @@ export class KubeConfigDialog extends React.Component<Props> {
|
|||||||
return (
|
return (
|
||||||
<Dialog
|
<Dialog
|
||||||
{...dialogProps}
|
{...dialogProps}
|
||||||
className={cssNames("KubeConfigDialog")}
|
className={styles.KubeConfigDialog}
|
||||||
isOpen={dialogState.isOpen}
|
isOpen={dialogState.isOpen}
|
||||||
onOpen={this.onOpen}
|
onOpen={this.onOpen}
|
||||||
close={this.close}
|
close={this.close}
|
||||||
@ -130,14 +127,12 @@ export class KubeConfigDialog extends React.Component<Props> {
|
|||||||
<Wizard header={header}>
|
<Wizard header={header}>
|
||||||
<WizardStep customButtons={buttons} prev={this.close}>
|
<WizardStep customButtons={buttons} prev={this.close}>
|
||||||
<MonacoEditor
|
<MonacoEditor
|
||||||
language="yaml"
|
readOnly
|
||||||
|
className={styles.editor}
|
||||||
value={yamlConfig}
|
value={yamlConfig}
|
||||||
theme={ThemeStore.getInstance().activeTheme.monacoTheme}
|
|
||||||
className={cssNames( "MonacoEditor")}
|
|
||||||
options={{ readOnly: true, ...UserStore.getInstance().getEditorOptions() }}
|
|
||||||
/>
|
/>
|
||||||
<textarea
|
<textarea
|
||||||
className="config-copy"
|
className={styles.configCopy}
|
||||||
readOnly defaultValue={yamlConfig}
|
readOnly defaultValue={yamlConfig}
|
||||||
ref={e => this.configTextArea = e}
|
ref={e => this.configTextArea = e}
|
||||||
/>
|
/>
|
||||||
|
|||||||
24
src/renderer/components/monaco-editor/index.ts
Normal file
24
src/renderer/components/monaco-editor/index.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 OpenLens Authors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export * from "./monaco-editor";
|
||||||
|
export * from "./monaco-validators";
|
||||||
|
export * from "./monaco-themes";
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 OpenLens Authors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
.MonacoEditor {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
299
src/renderer/components/monaco-editor/monaco-editor.tsx
Normal file
299
src/renderer/components/monaco-editor/monaco-editor.tsx
Normal file
@ -0,0 +1,299 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 OpenLens Authors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import styles from "./monaco-editor.module.css";
|
||||||
|
import React from "react";
|
||||||
|
import { observer } from "mobx-react";
|
||||||
|
import { action, computed, makeObservable, observable, reaction } from "mobx";
|
||||||
|
import { editor, Uri } from "monaco-editor";
|
||||||
|
import { MonacoTheme, MonacoValidator, monacoValidators } from "./index";
|
||||||
|
import { debounce, merge } from "lodash";
|
||||||
|
import { cssNames, disposer } from "../../utils";
|
||||||
|
import { UserStore } from "../../../common/user-store";
|
||||||
|
import { ThemeStore } from "../../theme.store";
|
||||||
|
|
||||||
|
export type MonacoEditorId = string;
|
||||||
|
|
||||||
|
export interface MonacoEditorProps {
|
||||||
|
id?: MonacoEditorId; // associating editor's ID with created model.uri
|
||||||
|
className?: string;
|
||||||
|
style?: React.CSSProperties;
|
||||||
|
autoFocus?: boolean;
|
||||||
|
readOnly?: boolean;
|
||||||
|
theme?: MonacoTheme;
|
||||||
|
language?: "yaml" | "json"; // supported list of languages, configure in `webpack.renderer.ts`
|
||||||
|
options?: Partial<editor.IStandaloneEditorConstructionOptions>; // customize editor's initialization options
|
||||||
|
value?: string;
|
||||||
|
onChange?(value: string, evt: editor.IModelContentChangedEvent): void; // catch latest value updates
|
||||||
|
onError?(error?: Error | unknown): void; // provide syntax validation error, etc.
|
||||||
|
onDidLayoutChange?(info: editor.EditorLayoutInfo): void;
|
||||||
|
onDidContentSizeChange?(evt: editor.IContentSizeChangedEvent): void;
|
||||||
|
onModelChange?(model: editor.ITextModel, prev?: editor.ITextModel): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const defaultEditorProps: Partial<MonacoEditorProps> = {
|
||||||
|
language: "yaml",
|
||||||
|
get theme(): MonacoTheme {
|
||||||
|
// theme for monaco-editor defined in `src/renderer/themes/lens-*.json`
|
||||||
|
return ThemeStore.getInstance().activeTheme.monacoTheme;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
@observer
|
||||||
|
export class MonacoEditor extends React.Component<MonacoEditorProps> {
|
||||||
|
static defaultProps = defaultEditorProps as object;
|
||||||
|
static viewStates = new WeakMap<Uri, editor.ICodeEditorViewState>();
|
||||||
|
|
||||||
|
static createUri(id: MonacoEditorId): Uri {
|
||||||
|
return Uri.file(`/monaco-editor/${id}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
public staticId = `editor-id#${Math.round(1e7 * Math.random())}`;
|
||||||
|
public dispose = disposer();
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
logger = console;
|
||||||
|
|
||||||
|
@observable.ref containerElem: HTMLElement;
|
||||||
|
@observable.ref editor: editor.IStandaloneCodeEditor;
|
||||||
|
@observable dimensions: { width?: number, height?: number } = {};
|
||||||
|
@observable unmounting = false;
|
||||||
|
|
||||||
|
constructor(props: MonacoEditorProps) {
|
||||||
|
super(props);
|
||||||
|
makeObservable(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@computed get id() {
|
||||||
|
return this.props.id ?? this.staticId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@computed get model(): editor.ITextModel {
|
||||||
|
const uri = MonacoEditor.createUri(this.id);
|
||||||
|
const model = editor.getModel(uri);
|
||||||
|
|
||||||
|
if (model) {
|
||||||
|
return model; // already exists
|
||||||
|
}
|
||||||
|
|
||||||
|
const { language, value } = this.props;
|
||||||
|
|
||||||
|
return editor.createModel(value, language, uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
@computed get options(): editor.IStandaloneEditorConstructionOptions {
|
||||||
|
return merge({},
|
||||||
|
UserStore.getInstance().editorConfiguration,
|
||||||
|
this.props.options,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@computed get logMetadata() {
|
||||||
|
return {
|
||||||
|
editorId: this.id,
|
||||||
|
model: this.model,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Monitor editor's dom container element box-size and sync with monaco's dimensions
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
private bindResizeObserver() {
|
||||||
|
const resizeObserver = new ResizeObserver(entries => {
|
||||||
|
for (const entry of entries) {
|
||||||
|
const { width, height } = entry.contentRect;
|
||||||
|
|
||||||
|
this.setDimensions(width, height);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const containerElem = this.editor.getContainerDomNode();
|
||||||
|
|
||||||
|
resizeObserver.observe(containerElem);
|
||||||
|
|
||||||
|
return () => resizeObserver.unobserve(containerElem);
|
||||||
|
}
|
||||||
|
|
||||||
|
onModelChange = (model: editor.ITextModel, oldModel?: editor.ITextModel) => {
|
||||||
|
this.logger?.info("[MONACO]: model change", { model, oldModel }, this.logMetadata);
|
||||||
|
|
||||||
|
if (oldModel) {
|
||||||
|
this.saveViewState(oldModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.editor.setModel(model);
|
||||||
|
this.restoreViewState(model);
|
||||||
|
this.editor.layout();
|
||||||
|
this.editor.focus(); // keep focus in editor, e.g. when clicking between dock-tabs
|
||||||
|
this.props.onModelChange?.(model, oldModel);
|
||||||
|
this.validateLazy();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save current view-model state in the editor.
|
||||||
|
* This will allow restore cursor position, selected text, etc.
|
||||||
|
* @param {editor.ITextModel} model
|
||||||
|
*/
|
||||||
|
private saveViewState(model: editor.ITextModel) {
|
||||||
|
MonacoEditor.viewStates.set(model.uri, this.editor.saveViewState());
|
||||||
|
}
|
||||||
|
|
||||||
|
private restoreViewState(model: editor.ITextModel) {
|
||||||
|
const viewState = MonacoEditor.viewStates.get(model.uri);
|
||||||
|
|
||||||
|
if (viewState) {
|
||||||
|
this.editor.restoreViewState(viewState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
try {
|
||||||
|
this.createEditor();
|
||||||
|
this.logger?.info(`[MONACO]: editor did mount`, this.logMetadata);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger?.error(`[MONACO]: mounting failed: ${error}`, this.logMetadata);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
this.unmounting = true;
|
||||||
|
this.saveViewState(this.model);
|
||||||
|
this.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
private createEditor() {
|
||||||
|
if (!this.containerElem || this.editor || this.unmounting) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { language, theme, readOnly, value: defaultValue } = this.props;
|
||||||
|
|
||||||
|
this.editor = editor.create(this.containerElem, {
|
||||||
|
model: this.model,
|
||||||
|
detectIndentation: false, // allow `option.tabSize` to use custom number of spaces for [Tab]
|
||||||
|
value: defaultValue,
|
||||||
|
language,
|
||||||
|
theme,
|
||||||
|
readOnly,
|
||||||
|
...this.options,
|
||||||
|
});
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
if (this.props.autoFocus) {
|
||||||
|
this.editor.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
const onDidLayoutChangeDisposer = this.editor.onDidLayoutChange(layoutInfo => {
|
||||||
|
this.props.onDidLayoutChange?.(layoutInfo);
|
||||||
|
});
|
||||||
|
|
||||||
|
const onValueChangeDisposer = this.editor.onDidChangeModelContent(event => {
|
||||||
|
const value = this.editor.getValue();
|
||||||
|
|
||||||
|
this.props.onChange?.(value, event);
|
||||||
|
this.validateLazy(value);
|
||||||
|
});
|
||||||
|
|
||||||
|
const onContentSizeChangeDisposer = this.editor.onDidContentSizeChange((params) => {
|
||||||
|
this.props.onDidContentSizeChange?.(params);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.dispose.push(
|
||||||
|
reaction(() => this.model, this.onModelChange),
|
||||||
|
reaction(() => this.props.theme, editor.setTheme),
|
||||||
|
reaction(() => this.props.value, value => this.setValue(value)),
|
||||||
|
reaction(() => this.options, opts => this.editor.updateOptions(opts)),
|
||||||
|
|
||||||
|
() => onDidLayoutChangeDisposer.dispose(),
|
||||||
|
() => onValueChangeDisposer.dispose(),
|
||||||
|
() => onContentSizeChangeDisposer.dispose(),
|
||||||
|
this.bindResizeObserver(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
destroy(): void {
|
||||||
|
if (!this.editor) return;
|
||||||
|
|
||||||
|
this.dispose();
|
||||||
|
this.editor.dispose();
|
||||||
|
this.editor = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
setDimensions(width: number, height: number) {
|
||||||
|
this.dimensions.width = width;
|
||||||
|
this.dimensions.height = height;
|
||||||
|
this.editor?.layout({ width, height });
|
||||||
|
}
|
||||||
|
|
||||||
|
setValue(value = ""): void {
|
||||||
|
if (value == this.getValue()) return;
|
||||||
|
|
||||||
|
this.editor.setValue(value);
|
||||||
|
this.validate(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
getValue(opts?: { preserveBOM: boolean; lineEnding: string; }): string {
|
||||||
|
return this.editor?.getValue(opts) ?? "";
|
||||||
|
}
|
||||||
|
|
||||||
|
focus() {
|
||||||
|
this.editor?.focus();
|
||||||
|
}
|
||||||
|
|
||||||
|
@action
|
||||||
|
validate = (value = this.getValue()) => {
|
||||||
|
const validators: MonacoValidator[] = [
|
||||||
|
monacoValidators[this.props.language], // parsing syntax check
|
||||||
|
].filter(Boolean);
|
||||||
|
|
||||||
|
for (const validate of validators) {
|
||||||
|
try {
|
||||||
|
validate(value);
|
||||||
|
} catch (error) {
|
||||||
|
this.props.onError?.(error); // emit error outside
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// avoid excessive validations during typing
|
||||||
|
validateLazy = debounce(this.validate, 250);
|
||||||
|
|
||||||
|
bindRef = (elem: HTMLElement) => this.containerElem = elem;
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { className, style } = this.props;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-test-component="monaco-editor"
|
||||||
|
className={cssNames(styles.MonacoEditor, className)}
|
||||||
|
style={style}
|
||||||
|
ref={this.bindRef}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
46
src/renderer/components/monaco-editor/monaco-themes.ts
Normal file
46
src/renderer/components/monaco-editor/monaco-themes.ts
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2021 OpenLens Authors
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Monaco editor themes customization
|
||||||
|
import { editor } from "monaco-editor";
|
||||||
|
import cloudsMidnight from "./monaco-themes/clouds-midnight.json";
|
||||||
|
|
||||||
|
export type MonacoTheme = "vs" | "vs-dark" | "hc-black" | MonacoCustomTheme;
|
||||||
|
export type MonacoCustomTheme = "clouds-midnight";
|
||||||
|
|
||||||
|
export interface MonacoThemeData extends editor.IStandaloneThemeData {
|
||||||
|
name?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Registered names could be then used in "themes/*.json" in "{monacoTheme: [name]}"
|
||||||
|
export const customThemes: Partial<Record<MonacoCustomTheme, MonacoThemeData>> = {
|
||||||
|
"clouds-midnight": cloudsMidnight as MonacoThemeData,
|
||||||
|
};
|
||||||
|
|
||||||
|
export function registerCustomThemes(): void {
|
||||||
|
Object.entries(customThemes).forEach(([name, theme]) => {
|
||||||
|
editor.defineTheme(name, theme);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function loadCustomTheme(name: string): Promise<MonacoThemeData> {
|
||||||
|
return import(`./monaco-themes/${name}.json`);
|
||||||
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"name": "clouds-midnight",
|
||||||
"base": "vs-dark",
|
"base": "vs-dark",
|
||||||
"inherit": true,
|
"inherit": true,
|
||||||
"rules": [
|
"rules": [
|
||||||
@ -18,44 +18,29 @@
|
|||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
import { monaco } from "react-monaco-editor";
|
import yaml, { YAMLException } from "js-yaml";
|
||||||
|
|
||||||
export type TabId = string;
|
export interface MonacoValidator {
|
||||||
|
(value: string): void;
|
||||||
|
}
|
||||||
|
|
||||||
interface ModelEntry {
|
export function yamlValidator(value: string) {
|
||||||
id?: TabId;
|
try {
|
||||||
modelUri?: monaco.Uri;
|
yaml.load(value);
|
||||||
lang?: string;
|
} catch (error) {
|
||||||
}
|
throw String(error as YAMLException);
|
||||||
|
|
||||||
export interface ModelsState {
|
|
||||||
models: ModelEntry[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export class MonacoModelsManager implements ModelsState {
|
|
||||||
models: ModelEntry[] = [];
|
|
||||||
|
|
||||||
addModel(tabId: string, { value = "", lang = "yaml" } = {}) {
|
|
||||||
const uri = this.getUri(tabId);
|
|
||||||
const model = monaco.editor.createModel(value, lang, uri);
|
|
||||||
|
|
||||||
if(!uri) this.models = this.models.concat({ id: tabId, modelUri: model.uri, lang });
|
|
||||||
}
|
|
||||||
|
|
||||||
getModel(tabId: string): monaco.editor.ITextModel {
|
|
||||||
return monaco.editor.getModel(this.getUri(tabId));
|
|
||||||
}
|
|
||||||
|
|
||||||
getUri(tabId: string): monaco.Uri {
|
|
||||||
return this.models.find(model => model.id == tabId)?.modelUri;
|
|
||||||
}
|
|
||||||
|
|
||||||
removeModel(tabId: string) {
|
|
||||||
const uri = this.getUri(tabId);
|
|
||||||
|
|
||||||
this.models = this.models.filter(v => v.id != tabId);
|
|
||||||
monaco.editor.getModel(uri)?.dispose();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const monacoModelsManager = new MonacoModelsManager();
|
export function jsonValidator(value: string) {
|
||||||
|
try {
|
||||||
|
JSON.parse(value);
|
||||||
|
} catch (error) {
|
||||||
|
throw String(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const monacoValidators = {
|
||||||
|
yaml: yamlValidator,
|
||||||
|
json: jsonValidator,
|
||||||
|
};
|
||||||
@ -19,37 +19,24 @@
|
|||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { computed, observable, reaction, makeObservable } from "mobx";
|
import { computed, makeObservable, observable, reaction } from "mobx";
|
||||||
import { autoBind, iter, Singleton } from "./utils";
|
import { autoBind, Singleton } from "./utils";
|
||||||
import { UserStore } from "../common/user-store";
|
import { UserStore } from "../common/user-store";
|
||||||
import logger from "../main/logger";
|
import logger from "../main/logger";
|
||||||
import darkTheme from "./themes/lens-dark.json";
|
import lensDarkThemeJson from "./themes/lens-dark.json";
|
||||||
import lightTheme from "./themes/lens-light.json";
|
import lensLightThemeJson from "./themes/lens-light.json";
|
||||||
import type { SelectOption } from "./components/select";
|
import type { SelectOption } from "./components/select";
|
||||||
|
import type { MonacoEditorProps } from "./components/monaco-editor";
|
||||||
|
|
||||||
export type ThemeId = string;
|
export type ThemeId = string;
|
||||||
|
|
||||||
export enum MonacoTheme {
|
|
||||||
DARK = "clouds-midnight",
|
|
||||||
LIGHT = "vs",
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum ThemeType {
|
|
||||||
DARK = "dark",
|
|
||||||
LIGHT = "light",
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Theme {
|
export interface Theme {
|
||||||
type: ThemeType;
|
|
||||||
name: string;
|
name: string;
|
||||||
|
type: "dark" | "light";
|
||||||
colors: Record<string, string>;
|
colors: Record<string, string>;
|
||||||
description: string;
|
description: string;
|
||||||
author: string;
|
author: string;
|
||||||
monacoTheme: string;
|
monacoTheme: MonacoEditorProps["theme"];
|
||||||
}
|
|
||||||
|
|
||||||
export interface ThemeItems extends Theme {
|
|
||||||
id: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ThemeStore extends Singleton {
|
export class ThemeStore extends Singleton {
|
||||||
@ -57,27 +44,23 @@ export class ThemeStore extends Singleton {
|
|||||||
protected styles: HTMLStyleElement;
|
protected styles: HTMLStyleElement;
|
||||||
|
|
||||||
// bundled themes from `themes/${themeId}.json`
|
// bundled themes from `themes/${themeId}.json`
|
||||||
private allThemes = observable.map<string, Theme>([
|
private themes = observable.map<ThemeId, Theme>({
|
||||||
["lens-dark", { ...darkTheme, type: ThemeType.DARK, monacoTheme: MonacoTheme.DARK }],
|
"lens-dark": lensDarkThemeJson as Theme,
|
||||||
["lens-light", { ...lightTheme, type: ThemeType.LIGHT, monacoTheme: MonacoTheme.LIGHT }],
|
"lens-light": lensLightThemeJson as Theme,
|
||||||
]);
|
});
|
||||||
|
|
||||||
@computed get themes(): ThemeItems[] {
|
|
||||||
return Array.from(iter.map(this.allThemes, ([id, theme]) => ({ id, ...theme })));
|
|
||||||
}
|
|
||||||
|
|
||||||
@computed get activeThemeId(): string {
|
@computed get activeThemeId(): string {
|
||||||
return UserStore.getInstance().colorTheme;
|
return UserStore.getInstance().colorTheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed get activeTheme(): Theme {
|
@computed get activeTheme(): Theme {
|
||||||
return this.allThemes.get(this.activeThemeId) ?? this.allThemes.get("lens-dark");
|
return this.themes.get(this.activeThemeId) ?? this.themes.get(ThemeStore.defaultTheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed get themeOptions(): SelectOption<string>[] {
|
@computed get themeOptions(): SelectOption<string>[] {
|
||||||
return this.themes.map(theme => ({
|
return Array.from(this.themes).map(([themeId, theme]) => ({
|
||||||
label: theme.name,
|
label: theme.name,
|
||||||
value: theme.id,
|
value: themeId,
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +84,7 @@ export class ThemeStore extends Singleton {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getThemeById(themeId: ThemeId): Theme {
|
getThemeById(themeId: ThemeId): Theme {
|
||||||
return this.allThemes.get(themeId);
|
return this.themes.get(themeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected applyTheme(theme: Theme) {
|
protected applyTheme(theme: Theme) {
|
||||||
@ -118,6 +101,6 @@ export class ThemeStore extends Singleton {
|
|||||||
// Adding universal theme flag which can be used in component styles
|
// Adding universal theme flag which can be used in component styles
|
||||||
const body = document.querySelector("body");
|
const body = document.querySelector("body");
|
||||||
|
|
||||||
body.classList.toggle("theme-light", theme.type === ThemeType.LIGHT);
|
body.classList.toggle("theme-light", theme.type === "light");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,6 +19,7 @@
|
|||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import * as vars from "./src/common/vars";
|
||||||
import { appName, buildDir, htmlTemplate, isDevelopment, isProduction, publicPath, rendererDir, sassCommonVars, webpackDevServerPort } from "./src/common/vars";
|
import { appName, buildDir, htmlTemplate, isDevelopment, isProduction, publicPath, rendererDir, sassCommonVars, webpackDevServerPort } from "./src/common/vars";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import webpack from "webpack";
|
import webpack from "webpack";
|
||||||
@ -27,7 +28,7 @@ import MiniCssExtractPlugin from "mini-css-extract-plugin";
|
|||||||
import ForkTsCheckerPlugin from "fork-ts-checker-webpack-plugin";
|
import ForkTsCheckerPlugin from "fork-ts-checker-webpack-plugin";
|
||||||
import ProgressBarPlugin from "progress-bar-webpack-plugin";
|
import ProgressBarPlugin from "progress-bar-webpack-plugin";
|
||||||
import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin";
|
import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin";
|
||||||
import * as vars from "./src/common/vars";
|
import MonacoWebpackPlugin from "monaco-editor-webpack-plugin";
|
||||||
import getTSLoader from "./src/common/getTSLoader";
|
import getTSLoader from "./src/common/getTSLoader";
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
@ -42,7 +43,7 @@ export function webpackLensRenderer({ showVars = true } = {}): webpack.Configura
|
|||||||
return {
|
return {
|
||||||
context: __dirname,
|
context: __dirname,
|
||||||
target: "electron-renderer",
|
target: "electron-renderer",
|
||||||
devtool: "source-map", // todo: optimize in dev-mode with webpack.SourceMapDevToolPlugin
|
devtool: isDevelopment ? "cheap-source-map" : "source-map",
|
||||||
devServer: {
|
devServer: {
|
||||||
contentBase: buildDir,
|
contentBase: buildDir,
|
||||||
port: webpackDevServerPort,
|
port: webpackDevServerPort,
|
||||||
@ -149,6 +150,14 @@ export function webpackLensRenderer({ showVars = true } = {}): webpack.Configura
|
|||||||
new ProgressBarPlugin(),
|
new ProgressBarPlugin(),
|
||||||
new ForkTsCheckerPlugin(),
|
new ForkTsCheckerPlugin(),
|
||||||
|
|
||||||
|
// see also: https://github.com/Microsoft/monaco-editor-webpack-plugin#options
|
||||||
|
new MonacoWebpackPlugin({
|
||||||
|
// publicPath: "/",
|
||||||
|
// filename: "[name].worker.js",
|
||||||
|
languages: ["json", "yaml"],
|
||||||
|
globalAPI: isDevelopment,
|
||||||
|
}),
|
||||||
|
|
||||||
// todo: fix remain warnings about circular dependencies
|
// todo: fix remain warnings about circular dependencies
|
||||||
// new CircularDependencyPlugin({
|
// new CircularDependencyPlugin({
|
||||||
// cwd: __dirname,
|
// cwd: __dirname,
|
||||||
|
|||||||
23
yarn.lock
23
yarn.lock
@ -9589,10 +9589,17 @@ moment-timezone@^0.5.33:
|
|||||||
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.1.tgz#b2be769fa31940be9eeea6469c075e35006fa3d3"
|
resolved "https://registry.yarnpkg.com/moment/-/moment-2.29.1.tgz#b2be769fa31940be9eeea6469c075e35006fa3d3"
|
||||||
integrity sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==
|
integrity sha512-kHmoybcPV8Sqy59DwNDY3Jefr64lK/by/da0ViFcuA4DH0vQg5Q6Ze5VimxkfQNSC+Mls/Kx53s7TjP1RhFEDQ==
|
||||||
|
|
||||||
monaco-editor@^0.26.1:
|
monaco-editor-webpack-plugin@^5.0.0:
|
||||||
version "0.26.1"
|
version "5.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/monaco-editor/-/monaco-editor-0.26.1.tgz#62bb5f658bc95379f8abb64b147632bd1c019d73"
|
resolved "https://registry.yarnpkg.com/monaco-editor-webpack-plugin/-/monaco-editor-webpack-plugin-5.0.0.tgz#796c50fb4ce3f75f45bf18dfa3c31f85dc9a05da"
|
||||||
integrity sha512-mm45nUrBDk0DgZKgbD7+bhDOtcAFNGPJJRAdS6Su1kTGl6XEgC7U3xOmDUW/0RrLf+jlvCGaqLvD4p2VjwuwwQ==
|
integrity sha512-KrUUTmMO3lDCNK4honZ6rrrKjOI7FFLeyCktPetIo5HlRqr5dfE6ewaA9qNLH96XY7CekE3Z+v/+I6ufAs3ObA==
|
||||||
|
dependencies:
|
||||||
|
loader-utils "^2.0.0"
|
||||||
|
|
||||||
|
monaco-editor@^0.29.1:
|
||||||
|
version "0.29.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/monaco-editor/-/monaco-editor-0.29.1.tgz#6ee93d8a5320704d48fd7058204deed72429c020"
|
||||||
|
integrity sha512-rguaEG/zrPQSaKzQB7IfX/PpNa0qxF1FY8ZXRkN4WIl8qZdTQRSRJCtRto7IMcSgrU6H53RXI+fTcywOBC4aVw==
|
||||||
|
|
||||||
moo-color@^1.0.2:
|
moo-color@^1.0.2:
|
||||||
version "1.0.2"
|
version "1.0.2"
|
||||||
@ -11505,14 +11512,6 @@ react-material-ui-carousel@^2.3.5:
|
|||||||
auto-bind "^2.1.1"
|
auto-bind "^2.1.1"
|
||||||
react-swipeable "^6.1.0"
|
react-swipeable "^6.1.0"
|
||||||
|
|
||||||
react-monaco-editor@^0.44.0:
|
|
||||||
version "0.44.0"
|
|
||||||
resolved "https://registry.yarnpkg.com/react-monaco-editor/-/react-monaco-editor-0.44.0.tgz#9f966fd00b6c30e8be8873a3fbc86f14a0da2ba4"
|
|
||||||
integrity sha512-GPheXTIpBXpwv857H7/jA8HX5yae4TJ7vFwDJ5iTvy05LxIQTsD3oofXznXGi66lVA93ST/G7wRptEf4CJ9dOg==
|
|
||||||
dependencies:
|
|
||||||
monaco-editor "^0.26.1"
|
|
||||||
prop-types "^15.7.2"
|
|
||||||
|
|
||||||
react-redux@^7.2.0:
|
react-redux@^7.2.0:
|
||||||
version "7.2.3"
|
version "7.2.3"
|
||||||
resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-7.2.3.tgz#4c084618600bb199012687da9e42123cca3f0be9"
|
resolved "https://registry.yarnpkg.com/react-redux/-/react-redux-7.2.3.tgz#4c084618600bb199012687da9e42123cca3f0be9"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user