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

revived EditorPanel / usages of editor per dock-tab separately

Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
Roman 2021-10-27 12:13:37 +03:00
parent a02538999a
commit f276207860
11 changed files with 70 additions and 120 deletions

View File

@ -29,9 +29,9 @@ 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 { TabKind } from "./dock.store"; import { TabKind } from "./dock.store";
import { dockViewsManager } from "./dock.views-manager"; import { DockTabContentProps, dockViewsManager } from "./dock.views-manager";
import logger from "../../../common/logger"; import logger from "../../../common/logger";
import { DockTabContent, DockTabContentProps } from "./dock-tab-content"; import { EditorPanel } from "./editor-panel";
interface Props extends DockTabContentProps { interface Props extends DockTabContentProps {
} }
@ -135,12 +135,7 @@ export class CreateResource extends React.Component<Props> {
const { tabId } = this; const { tabId } = this;
return ( return (
<DockTabContent <div className="CreateResource">
tabId={tabId}
withEditor
editorValue={createResourceStore.getData(tabId)}
editorOnChange={value => createResourceStore.setData(tabId, value)}
>
<InfoPanel <InfoPanel
tabId={tabId} tabId={tabId}
controls={this.renderControls()} controls={this.renderControls()}
@ -148,7 +143,12 @@ export class CreateResource extends React.Component<Props> {
submitLabel="Create" submitLabel="Create"
showNotifications={false} showNotifications={false}
/> />
</DockTabContent> <EditorPanel
tabId={tabId}
value={createResourceStore.getData(tabId)}
onChange={value => createResourceStore.setData(tabId, value)}
/>
</div>
); );
} }
} }

View File

@ -1,28 +0,0 @@
/**
* 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 React from "react";
export const DockTabContext = React.createContext<DockTabContextValue>({});
export interface DockTabContextValue {
error?: string;
}

View File

@ -21,8 +21,12 @@
import type React from "react"; import type React from "react";
import { observable } from "mobx"; import { observable } from "mobx";
import type { TabKind } from "./dock.store"; import type { TabId, TabKind } from "./dock.store";
import type { DockTabContentProps } from "./dock-tab-content";
export interface DockTabContentProps {
tabId: TabId;
className?: string;
}
export interface DockTabComponents { export interface DockTabComponents {
Content?: React.ComponentType<DockTabContentProps>; Content?: React.ComponentType<DockTabContentProps>;

View File

@ -28,9 +28,9 @@ import { InfoPanel } from "./info-panel";
import { Badge } from "../badge"; import { Badge } from "../badge";
import type { KubeObject } from "../../../common/k8s-api/kube-object"; import type { KubeObject } from "../../../common/k8s-api/kube-object";
import { TabKind } from "./dock.store"; import { TabKind } from "./dock.store";
import { dockViewsManager } from "./dock.views-manager"; import { DockTabContentProps, dockViewsManager } from "./dock.views-manager";
import { createPatch } from "rfc6902"; import { createPatch } from "rfc6902";
import { DockTabContent, DockTabContentProps } from "./dock-tab-content"; import { EditorPanel } from "./editor-panel";
interface Props extends DockTabContentProps { interface Props extends DockTabContentProps {
} }
@ -111,12 +111,7 @@ export class EditResource extends React.Component<Props> {
if (!resource) return null; if (!resource) return null;
return ( return (
<DockTabContent <div className="EditResource">
tabId={tabId}
withEditor
editorValue={tabData?.draft}
editorOnChange={v => tabData.draft = v}
>
<InfoPanel <InfoPanel
tabId={tabId} tabId={tabId}
submit={this.save} submit={this.save}
@ -130,7 +125,12 @@ export class EditResource extends React.Component<Props> {
</div> </div>
)} )}
/> />
</DockTabContent> <EditorPanel
tabId={tabId}
value={tabData?.draft}
onChange={v => tabData.draft = v}
/>
</div>
); );
} }
} }

View File

@ -19,14 +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.
*/ */
.DockTabContent { .EditorPanel {
position: relative; position: relative;
flex: 1; flex: 1;
height: 100%; height: 100%;
display: flex;
flex-direction: column;
.editor {
flex: 1;
}
} }

View File

@ -19,69 +19,54 @@
* 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 styles from "./dock-tab-content.module.css"; import styles from "./editor-panel.module.css";
import throttle from "lodash/throttle"; import throttle from "lodash/throttle";
import React from "react"; import React from "react";
import { action, makeObservable, observable, reaction } from "mobx"; import { makeObservable, observable, reaction } from "mobx";
import { disposeOnUnmount, observer } from "mobx-react"; import { disposeOnUnmount, observer } from "mobx-react";
import { dockStore, TabId } from "./dock.store"; import { dockStore } from "./dock.store";
import { cssNames } from "../../utils"; import { cssNames } from "../../utils";
import { MonacoEditor, MonacoEditorProps } from "../monaco-editor"; import { MonacoEditor, MonacoEditorProps } from "../monaco-editor";
import { DockTabContext } from "./dock-tab-context"; import type { DockTabContentProps } from "./dock.views-manager";
export interface DockTabContentProps extends React.HTMLAttributes<any> { export interface EditorPanelProps extends DockTabContentProps {
tabId: TabId; value: string;
className?: string; onChange: MonacoEditorProps["onChange"];
withEditor?: boolean; onError?: MonacoEditorProps["onError"];
editorValue?: MonacoEditorProps["value"];
editorOnChange?: MonacoEditorProps["onChange"];
} }
@observer @observer
export class DockTabContent extends React.Component<DockTabContentProps> { export class EditorPanel extends React.Component<EditorPanelProps> {
@observable.ref editor?: MonacoEditor; @observable.ref editor: MonacoEditor;
@observable error = "";
constructor(props: DockTabContentProps) { constructor(props: EditorPanelProps) {
super(props); super(props);
makeObservable(this); makeObservable(this);
disposeOnUnmount(this, [ disposeOnUnmount(this, [
// keep focus on editor's area when <Dock/> just opened // keep focus on editor's area when <Dock/> just opened
reaction(() => dockStore.isOpen, isOpen => isOpen && this.editor?.focus()), reaction(() => dockStore.isOpen, isOpen => isOpen && this.editor.focus()),
// focus to editor on dock's resize or turning into fullscreen mode // focus to editor on dock's resize or turning into fullscreen mode
dockStore.onResize(throttle(() => this.editor?.focus(), 250)), dockStore.onResize(throttle(() => this.editor.focus(), 250)),
]); ]);
} }
render() { render() {
const { className, tabId, withEditor, editorValue, editorOnChange } = this.props; const { className, tabId, value, onChange, onError } = this.props;
const { error } = this;
if (!tabId) return null; if (!tabId) return null;
return ( return (
<div className={cssNames(styles.DockTabContent, className)}>
<DockTabContext.Provider value={{ error }}>
{this.props.children}
{withEditor && (
<MonacoEditor <MonacoEditor
autoFocus autoFocus
id={tabId} id={tabId}
className={styles.editor} value={value}
value={editorValue ?? ""} className={cssNames(styles.EditorPanel, className)}
onChange={action((value, evt) => { onChange={onChange}
this.error = ""; // reset first onError={onError}
editorOnChange?.(value, evt); ref={monaco => this.editor = monaco}
})} />
onError={error => this.error = String(error)}
onModelChange={() => this.error = ""}
ref={monaco => this.editor = monaco}></MonacoEditor>
)}
</DockTabContext.Provider>
</div>
); );
} }
} }

View File

@ -29,7 +29,6 @@ import { Icon } from "../icon";
import { Spinner } from "../spinner"; import { Spinner } from "../spinner";
import { dockStore, TabId } from "./dock.store"; import { dockStore, TabId } from "./dock.store";
import { Notifications } from "../notifications"; import { Notifications } from "../notifications";
import { DockTabContext, DockTabContextValue } from "./dock-tab-context";
export interface InfoPanelProps { export interface InfoPanelProps {
tabId: TabId; tabId: TabId;
@ -60,11 +59,9 @@ const defaultProps: Partial<InfoPanelProps> = {
@observer @observer
export class InfoPanel extends Component<InfoPanelProps> { export class InfoPanel extends Component<InfoPanelProps> {
static defaultProps = defaultProps as object; static defaultProps = defaultProps as object;
static contextType = DockTabContext;
declare context: DockTabContextValue;
get error() { get error(): React.ReactNode {
return this.props.error ?? this.context.error; return this.props.error;
} }
@observable waiting = false; @observable waiting = false;

View File

@ -39,8 +39,8 @@ import { Select, SelectOption } from "../select";
import { Input } from "../input"; import { Input } from "../input";
import { navigate } from "../../navigation"; import { navigate } from "../../navigation";
import { releaseURL } from "../../../common/routes"; import { releaseURL } from "../../../common/routes";
import { dockViewsManager } from "./dock.views-manager"; import { DockTabContentProps, dockViewsManager } from "./dock.views-manager";
import { DockTabContent, DockTabContentProps } from "./dock-tab-content"; import { EditorPanel } from "./editor-panel";
interface Props extends DockTabContentProps { interface Props extends DockTabContentProps {
} }
@ -195,12 +195,7 @@ export class InstallChart extends Component<Props> {
); );
return ( return (
<DockTabContent <div className="InstallChart">
tabId={tabId}
withEditor
editorValue={installChartStore.getData(tabId).values}
editorOnChange={v => installChartStore.getData(tabId).values = v}
>
<InfoPanel <InfoPanel
tabId={tabId} tabId={tabId}
className="InstallChartInfoPanel" className="InstallChartInfoPanel"
@ -210,7 +205,12 @@ export class InstallChart extends Component<Props> {
submittingMessage="Installing..." submittingMessage="Installing..."
showSubmitClose={false} showSubmitClose={false}
/> />
</DockTabContent> <EditorPanel
tabId={tabId}
value={installChartStore.getData(tabId).values}
onChange={v => installChartStore.getData(tabId).values = v}
/>
</div>
); );
} }
} }

View File

@ -33,8 +33,7 @@ import { LogSearch } from "./log-search";
import { LogControls } from "./log-controls"; import { LogControls } from "./log-controls";
import { LogTabData, logTabStore } from "./log-tab.store"; import { LogTabData, logTabStore } from "./log-tab.store";
import { TabKind } from "./dock.store"; import { TabKind } from "./dock.store";
import { dockViewsManager } from "./dock.views-manager"; import { DockTabContentProps, dockViewsManager } from "./dock.views-manager";
import type { DockTabContentProps } from "./dock-tab-content";
interface Props extends DockTabContentProps { interface Props extends DockTabContentProps {
} }

View File

@ -28,8 +28,7 @@ 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, TabId, TabKind } from "./dock.store"; import { dockStore, TabId, TabKind } from "./dock.store";
import { dockViewsManager } from "./dock.views-manager"; import { DockTabContentProps, dockViewsManager } from "./dock.views-manager";
import type { DockTabContentProps } from "./dock-tab-content";
interface Props extends DockTabContentProps { interface Props extends DockTabContentProps {
} }

View File

@ -29,8 +29,8 @@ import { dockStore, TabId, TabKind } from "./dock.store";
import type { IChartVersion } from "../+apps-helm-charts/helm-chart.store"; import type { IChartVersion } from "../+apps-helm-charts/helm-chart.store";
import type { HelmRelease } from "../../../common/k8s-api/endpoints/helm-releases.api"; import type { HelmRelease } from "../../../common/k8s-api/endpoints/helm-releases.api";
import { upgradeChartStore } from "./upgrade-chart.store"; import { upgradeChartStore } from "./upgrade-chart.store";
import { dockViewsManager } from "./dock.views-manager"; import { DockTabContentProps, dockViewsManager } from "./dock.views-manager";
import { DockTabContent, DockTabContentProps } from "./dock-tab-content"; import { EditorPanel } from "./editor-panel";
import { Spinner } from "../spinner"; import { Spinner } from "../spinner";
interface Props extends DockTabContentProps { interface Props extends DockTabContentProps {
@ -96,12 +96,7 @@ export class UpgradeChart extends React.Component<Props> {
const { release, selectedVersion, chartVersions, tabId } = this; const { release, selectedVersion, chartVersions, tabId } = this;
return ( return (
<DockTabContent <div className="UpgradeChart">
tabId={tabId}
withEditor
editorValue={upgradeChartStore.values.get(tabId)}
editorOnChange={v => upgradeChartStore.values.set(tabId, v)}
>
<InfoPanel <InfoPanel
tabId={this.tabId} tabId={this.tabId}
submit={this.upgrade} submit={this.upgrade}
@ -124,7 +119,12 @@ export class UpgradeChart extends React.Component<Props> {
</div> </div>
} }
/> />
</DockTabContent> <EditorPanel
tabId={tabId}
value={upgradeChartStore.values.get(tabId)}
onChange={v => upgradeChartStore.values.set(tabId, v)}
/>
</div>
); );
} }
} }