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

clean up / responding to comments

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2021-11-03 12:18:26 +02:00
parent 1f6560e190
commit a4914cd987
6 changed files with 53 additions and 34 deletions

View File

@ -377,10 +377,13 @@ 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" });
await frame.waitForSelector(".Drawer .drawer-title .Icon >> text=subject").then(button => button.click());
await frame.waitForSelector(".Dock.isOpen"); const showPodLogsIcon = await frame.waitForSelector(".Drawer .drawer-title .Icon >> text=subject");
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");

View File

@ -198,7 +198,6 @@
"electron-window-state": "^5.0.3", "electron-window-state": "^5.0.3",
"filehound": "^1.17.5", "filehound": "^1.17.5",
"fs-extra": "^9.0.1", "fs-extra": "^9.0.1",
"glob": "^7.2.0",
"glob-to-regexp": "^0.4.1", "glob-to-regexp": "^0.4.1",
"got": "^11.8.2", "got": "^11.8.2",
"grapheme-splitter": "^1.0.4", "grapheme-splitter": "^1.0.4",

View File

@ -48,12 +48,14 @@ 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 { 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

View File

@ -95,8 +95,14 @@ export interface DockTabChangeEvent {
} }
export interface DockTabChangeEventOptions extends IReactionOptions { export interface DockTabChangeEventOptions extends IReactionOptions {
tabKind?: TabKind; // filter: by dockStore.selectedTab.kind == tabKind /**
dockIsVisible?: boolean; // filter: dock and selected tab should be visible (default: true) * filter: by dockStore.selectedTab.kind == tabKind
*/
tabKind?: TabKind;
/**
* filter: dock and selected tab should be visible (default: true)
*/
dockIsVisible?: boolean;
} }
export interface DockTabCloseEvent { export interface DockTabCloseEvent {

View File

@ -105,7 +105,7 @@ export class Dock extends React.Component<Props> {
if (!isOpen || !selectedTab) return null; if (!isOpen || !selectedTab) return null;
return ( return (
<div className="tab-content" style={{ flexBasis: isOpen ? height : 0 }}> <div className="tab-content" style={{ flexBasis: height }}>
{this.renderTab(selectedTab)} {this.renderTab(selectedTab)}
</div> </div>
); );

View File

@ -21,17 +21,14 @@
import styles from "./monaco-editor.module.css"; import styles from "./monaco-editor.module.css";
import React from "react"; import React from "react";
import { action, computed, makeObservable, observable, reaction } from "mobx";
import { observer } from "mobx-react"; import { observer } from "mobx-react";
import { action, computed, makeObservable, observable, reaction } from "mobx";
import { editor, Uri } from "monaco-editor"; import { editor, Uri } from "monaco-editor";
import { MonacoTheme, registerCustomThemes } from "./monaco-themes"; import { MonacoTheme, MonacoValidator, monacoValidators } from "./index";
import { MonacoValidator, monacoValidators } from "./monaco-validators"; import { debounce, merge } from "lodash";
import { cssNames, disposer, toJS } from "../../utils"; import { cssNames, disposer } from "../../utils";
import { UserStore } from "../../../common/user-store"; import { UserStore } from "../../../common/user-store";
import { ThemeStore } from "../../theme.store"; import { ThemeStore } from "../../theme.store";
import debounce from "lodash/debounce";
registerCustomThemes(); // setup
export type MonacoEditorId = string; export type MonacoEditorId = string;
@ -87,9 +84,13 @@ export class MonacoEditor extends React.Component<MonacoEditorProps> {
makeObservable(this); makeObservable(this);
} }
@computed get id() {
return this.props.id ?? this.staticId;
}
@computed get model(): editor.ITextModel { @computed get model(): editor.ITextModel {
const uri = MonacoEditor.createUri(this.props.id ?? this.staticId); const uri = MonacoEditor.createUri(this.id);
const model = editor.getModels().find(model => model.uri.toString() == uri.toString()); const model = editor.getModel(uri);
if (model) { if (model) {
return model; // already exists return model; // already exists
@ -101,10 +102,17 @@ export class MonacoEditor extends React.Component<MonacoEditorProps> {
} }
@computed get options(): editor.IStandaloneEditorConstructionOptions { @computed get options(): editor.IStandaloneEditorConstructionOptions {
return toJS({ return merge({},
...UserStore.getInstance().editorConfiguration, UserStore.getInstance().editorConfiguration,
...(this.props.options ?? {}), this.props.options
}); );
}
@computed get logMetadata() {
return {
editorId: this.id,
model: this.model,
};
} }
/** /**
@ -128,9 +136,12 @@ export class MonacoEditor extends React.Component<MonacoEditorProps> {
} }
onModelChange = (model: editor.ITextModel, oldModel?: editor.ITextModel) => { onModelChange = (model: editor.ITextModel, oldModel?: editor.ITextModel) => {
this.logger?.info("[MONACO]: model change", { model, oldModel }); this.logger?.info("[MONACO]: model change", { model, oldModel }, this.logMetadata);
if (oldModel) {
this.saveViewState(oldModel);
}
this.saveViewState(oldModel);
this.editor.setModel(model); this.editor.setModel(model);
this.restoreViewState(model); this.restoreViewState(model);
this.editor.layout(); this.editor.layout();
@ -144,32 +155,30 @@ export class MonacoEditor extends React.Component<MonacoEditorProps> {
* This will allow restore cursor position, selected text, etc. * This will allow restore cursor position, selected text, etc.
* @param {editor.ITextModel} model * @param {editor.ITextModel} model
*/ */
saveViewState(model = this.model) { private saveViewState(model: editor.ITextModel) {
if (!model) return;
MonacoEditor.viewStates.set(model.uri, this.editor.saveViewState()); MonacoEditor.viewStates.set(model.uri, this.editor.saveViewState());
} }
restoreViewState(model = this.model) { private restoreViewState(model: editor.ITextModel) {
if (!model) return;
const viewState = MonacoEditor.viewStates.get(model.uri); const viewState = MonacoEditor.viewStates.get(model.uri);
this.editor.restoreViewState(viewState); if (viewState) {
this.editor.restoreViewState(viewState);
}
} }
componentDidMount() { componentDidMount() {
try { try {
this.createEditor(); this.createEditor();
this.logger?.info(`[MONACO]: editor did mount`); this.logger?.info(`[MONACO]: editor did mount`, this.logMetadata);
} catch (error) { } catch (error) {
this.logger?.error(`[MONACO]: mounting failed: ${error}`, this); this.logger?.error(`[MONACO]: mounting failed: ${error}`, this.logMetadata);
} }
} }
componentWillUnmount() { componentWillUnmount() {
this.unmounting = true; this.unmounting = true;
this.saveViewState(); this.saveViewState(this.model);
this.destroy(); this.destroy();
} }
@ -189,9 +198,9 @@ export class MonacoEditor extends React.Component<MonacoEditorProps> {
...this.options, ...this.options,
}); });
this.logger?.info(`[MONACO]: editor created for language=${language}, theme=${theme}`); this.logger?.info(`[MONACO]: editor created for language=${language}, theme=${theme}`, this.logMetadata);
this.validateLazy(); // validate initial value this.validateLazy(); // validate initial value
this.restoreViewState(); // restore previous state if any this.restoreViewState(this.model); // restore previous state if any
if (this.props.autoFocus) { if (this.props.autoFocus) {
this.editor.focus(); this.editor.focus();