mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
fix: provide validation error to <InfoPanel/> via MonacoEditor.props.onError()
Signed-off-by: Roman <ixrock@gmail.com>
This commit is contained in:
parent
091ef1f11a
commit
118d07cfb9
@ -1,23 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
.CreateResource {
|
|
||||||
}
|
|
||||||
@ -19,22 +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 "./create-resource.scss";
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { GroupSelectOption, Select, SelectOption } from "../select";
|
import { GroupSelectOption, Select, SelectOption } from "../select";
|
||||||
import jsYaml from "js-yaml";
|
import jsYaml from "js-yaml";
|
||||||
import { computed, makeObservable } from "mobx";
|
import { computed, makeObservable } from "mobx";
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import { createResourceStore } from "./create-resource.store";
|
import { createResourceStore } from "./create-resource.store";
|
||||||
import { InfoPanel } from "./info-panel";
|
import { InfoPanel, InfoPanelProps } from "./info-panel";
|
||||||
import { resourceApplierApi } from "../../../common/k8s-api/endpoints/resource-applier.api";
|
import { resourceApplierApi } from "../../../common/k8s-api/endpoints/resource-applier.api";
|
||||||
import type { JsonApiErrorParsed } from "../../../common/k8s-api/json-api";
|
import type { JsonApiErrorParsed } from "../../../common/k8s-api/json-api";
|
||||||
import { Notifications } from "../notifications";
|
import { Notifications } from "../notifications";
|
||||||
import { TabKind } from "./dock.store";
|
import { TabKind } from "./dock.store";
|
||||||
import type { DockTabContentProps } from "./dock-tab-content";
|
|
||||||
import { dockViewsManager } from "./dock.views-manager";
|
import { dockViewsManager } from "./dock.views-manager";
|
||||||
|
|
||||||
interface Props extends DockTabContentProps {
|
interface Props extends InfoPanelProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
type SelectOptionTemplate = SelectOption<SelectOptionTemplateValue>;
|
type SelectOptionTemplate = SelectOption<SelectOptionTemplateValue>;
|
||||||
@ -46,14 +44,14 @@ interface SelectOptionTemplateValue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class CreateResource extends React.Component<Props> {
|
export class CreateResourceInfoPanel extends React.Component<Props> {
|
||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
super(props);
|
super(props);
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
get tabId() {
|
get tabId() {
|
||||||
return this.props.tab.id;
|
return this.props.tabId;
|
||||||
}
|
}
|
||||||
|
|
||||||
get draft() {
|
get draft() {
|
||||||
@ -136,21 +134,19 @@ export class CreateResource extends React.Component<Props> {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="CreateResource">
|
|
||||||
<InfoPanel
|
<InfoPanel
|
||||||
tabId={this.tabId}
|
{...this.props}
|
||||||
controls={this.renderControls()}
|
controls={this.renderControls()}
|
||||||
submit={this.create}
|
submit={this.create}
|
||||||
submitLabel="Create"
|
submitLabel="Create"
|
||||||
showNotifications={false}
|
showNotifications={false}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dockViewsManager.register(TabKind.CREATE_RESOURCE, {
|
dockViewsManager.register(TabKind.CREATE_RESOURCE, {
|
||||||
Content: CreateResource,
|
InfoPanel: CreateResourceInfoPanel,
|
||||||
editor: {
|
editor: {
|
||||||
getValue(tabId) {
|
getValue(tabId) {
|
||||||
return createResourceStore.getData(tabId);
|
return createResourceStore.getData(tabId);
|
||||||
|
|||||||
@ -21,12 +21,12 @@
|
|||||||
|
|
||||||
import "./dock-tab-content.scss";
|
import "./dock-tab-content.scss";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { observer } from "mobx-react";
|
import { disposeOnUnmount, observer } from "mobx-react";
|
||||||
import { computed, makeObservable } from "mobx";
|
import { computed, makeObservable, observable, reaction } from "mobx";
|
||||||
import type { DockTab, TabId } from "./dock.store";
|
import type { DockTab, TabId } from "./dock.store";
|
||||||
import { cssNames } from "../../utils";
|
import { cssNames } from "../../utils";
|
||||||
import { DockTabComponents, dockViewsManager } from "./dock.views-manager";
|
import { DockTabComponents, dockViewsManager } from "./dock.views-manager";
|
||||||
import { MonacoEditor, onMonacoContentChangeCallback } from "../monaco-editor";
|
import { MonacoEditor } from "../monaco-editor";
|
||||||
|
|
||||||
export interface DockTabContentProps extends React.HTMLAttributes<any> {
|
export interface DockTabContentProps extends React.HTMLAttributes<any> {
|
||||||
className?: string;
|
className?: string;
|
||||||
@ -39,6 +39,10 @@ export class DockTabContent extends React.Component<DockTabContentProps> {
|
|||||||
constructor(props: DockTabContentProps) {
|
constructor(props: DockTabContentProps) {
|
||||||
super(props);
|
super(props);
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
|
|
||||||
|
disposeOnUnmount(this, [
|
||||||
|
reaction(() => this.tabId, () => this.error = ""), // reset
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed get tabId(): TabId {
|
@computed get tabId(): TabId {
|
||||||
@ -49,46 +53,45 @@ export class DockTabContent extends React.Component<DockTabContentProps> {
|
|||||||
return dockViewsManager.get(this.props.tab.kind);
|
return dockViewsManager.get(this.props.tab.kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@observable error = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Always keep editor in DOM while (while <Dock/> is open/rendered).
|
* Always keep editor in DOM while (while <Dock/> is open/rendered).
|
||||||
* This allows to restore editor's model-view state (cursor pos, selection, etc.)
|
* This allows to restore editor's model-view state (cursor pos, selection, etc.)
|
||||||
* while switching between different tab.kind-s (e.g. "terminal" tab doesn't have editor)
|
* while switching between different tab.kind-s (e.g. "terminal" tab doesn't have editor)
|
||||||
*/
|
*/
|
||||||
renderEditor() {
|
renderEditor() {
|
||||||
const { tabId, tabComponents } = this;
|
const { tabId, tabComponents: { editor } } = this;
|
||||||
const isHidden = !tabComponents.editor;
|
const isHidden = !editor;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MonacoEditor
|
<MonacoEditor
|
||||||
id={tabId}
|
id={tabId}
|
||||||
className={cssNames({ hidden: isHidden })}
|
className={cssNames({ hidden: isHidden })}
|
||||||
value={tabComponents.editor?.getValue(tabId)}
|
value={editor?.getValue(tabId) ?? ""}
|
||||||
onChange={this.onEditorChange}
|
onChange={value => {
|
||||||
onError={this.onEditorError}
|
this.error = "";
|
||||||
|
editor?.setValue(tabId, value);
|
||||||
|
}}
|
||||||
|
onError={error => {
|
||||||
|
this.error = isHidden ? "" : error;
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
onEditorChange: onMonacoContentChangeCallback = (value) => {
|
|
||||||
this.tabComponents.editor?.setValue(this.tabId, value);
|
|
||||||
};
|
|
||||||
|
|
||||||
onEditorError = (error: string) => {
|
|
||||||
this.tabComponents.editor?.onError?.(this.tabId, error);
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: provide error to dock's info-panel
|
|
||||||
render() {
|
render() {
|
||||||
const { children: bottomContent, bindContainerRef, className, tab } = this.props;
|
const { bindContainerRef, className, tab } = this.props;
|
||||||
|
|
||||||
if (!tab) return null;
|
if (!tab) return null;
|
||||||
const { Content } = this.tabComponents;
|
const { InfoPanel, Content } = this.tabComponents;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cssNames("DockTabContent flex column", className)} ref={bindContainerRef}>
|
<div className={cssNames("DockTabContent flex column", className)} ref={bindContainerRef}>
|
||||||
|
{InfoPanel && <InfoPanel tabId={this.tabId} error={this.error}/>}
|
||||||
{Content && <Content {...this.props}/>}
|
{Content && <Content {...this.props}/>}
|
||||||
{this.renderEditor()}
|
{this.renderEditor()}
|
||||||
{bottomContent}
|
{this.props.children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,13 +23,14 @@ import type React from "react";
|
|||||||
import { observable } from "mobx";
|
import { observable } from "mobx";
|
||||||
import type { TabId, TabKind } from "./dock.store";
|
import type { TabId, TabKind } from "./dock.store";
|
||||||
import type { DockTabContentProps } from "./dock-tab-content";
|
import type { DockTabContentProps } from "./dock-tab-content";
|
||||||
|
import type { InfoPanelProps } from "./info-panel";
|
||||||
|
|
||||||
export interface DockTabComponents {
|
export interface DockTabComponents {
|
||||||
|
InfoPanel?: React.ComponentType<InfoPanelProps>;
|
||||||
Content?: React.ComponentType<DockTabContentProps>;
|
Content?: React.ComponentType<DockTabContentProps>;
|
||||||
editor?: {
|
editor?: {
|
||||||
getValue(tabId: TabId): string | undefined;
|
getValue(tabId: TabId): string | undefined;
|
||||||
setValue(tabId: TabId, value: string): void;
|
setValue(tabId: TabId, value: string): void;
|
||||||
onError?(tabId: TabId, error: string | Error): void;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,23 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
.EditResource {
|
|
||||||
}
|
|
||||||
@ -19,27 +19,23 @@
|
|||||||
* 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 "./edit-resource.scss";
|
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import jsYaml from "js-yaml";
|
import jsYaml from "js-yaml";
|
||||||
import { editResourceStore } from "./edit-resource.store";
|
import { editResourceStore } from "./edit-resource.store";
|
||||||
import { InfoPanel } from "./info-panel";
|
import { InfoPanel, InfoPanelProps } from "./info-panel";
|
||||||
import { Badge } from "../badge";
|
import { Badge } from "../badge";
|
||||||
import { Spinner } from "../spinner";
|
|
||||||
import type { KubeObject } from "../../../common/k8s-api/kube-object";
|
import type { KubeObject } from "../../../common/k8s-api/kube-object";
|
||||||
import type { DockTabContentProps } from "./dock-tab-content";
|
|
||||||
import { TabKind } from "./dock.store";
|
import { TabKind } from "./dock.store";
|
||||||
import { dockViewsManager } from "./dock.views-manager";
|
import { dockViewsManager } from "./dock.views-manager";
|
||||||
|
|
||||||
interface Props extends DockTabContentProps {
|
interface Props extends InfoPanelProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class EditResource extends React.Component<Props> {
|
export class EditResourceInfoPanel extends React.Component<Props> {
|
||||||
get tabId() {
|
get tabId() {
|
||||||
return this.props.tab.id;
|
return this.props.tabId;
|
||||||
}
|
}
|
||||||
|
|
||||||
get resource(): KubeObject | undefined {
|
get resource(): KubeObject | undefined {
|
||||||
@ -74,16 +70,13 @@ export class EditResource extends React.Component<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { tabId, resource } = this;
|
const { resource } = this;
|
||||||
|
|
||||||
if (!editResourceStore.dataReady || !resource) {
|
if (!resource) return null;
|
||||||
return <Spinner center/>;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="EditResource">
|
|
||||||
<InfoPanel
|
<InfoPanel
|
||||||
tabId={tabId}
|
{...this.props}
|
||||||
submit={this.save}
|
submit={this.save}
|
||||||
submitLabel="Save"
|
submitLabel="Save"
|
||||||
submittingMessage="Applying.."
|
submittingMessage="Applying.."
|
||||||
@ -95,13 +88,12 @@ export class EditResource extends React.Component<Props> {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dockViewsManager.register(TabKind.EDIT_RESOURCE, {
|
dockViewsManager.register(TabKind.EDIT_RESOURCE, {
|
||||||
Content: EditResource,
|
InfoPanel: EditResourceInfoPanel,
|
||||||
editor: {
|
editor: {
|
||||||
getValue(tabId) {
|
getValue(tabId) {
|
||||||
return editResourceStore.getData(tabId).draft;
|
return editResourceStore.getData(tabId).draft;
|
||||||
|
|||||||
@ -20,9 +20,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import "./info-panel.scss";
|
import "./info-panel.scss";
|
||||||
|
|
||||||
import React, { Component, ReactNode } from "react";
|
import React, { Component, ReactNode } from "react";
|
||||||
import { computed, observable, reaction, makeObservable } from "mobx";
|
import { 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 { Button } from "../button";
|
import { Button } from "../button";
|
||||||
@ -31,14 +30,11 @@ import { Spinner } from "../spinner";
|
|||||||
import { dockStore, TabId } from "./dock.store";
|
import { dockStore, TabId } from "./dock.store";
|
||||||
import { Notifications } from "../notifications";
|
import { Notifications } from "../notifications";
|
||||||
|
|
||||||
interface Props extends OptionalProps {
|
export interface InfoPanelProps {
|
||||||
tabId: TabId;
|
tabId: TabId;
|
||||||
submit?: () => Promise<ReactNode | string>;
|
submit?: () => Promise<ReactNode | string>;
|
||||||
}
|
|
||||||
|
|
||||||
interface OptionalProps {
|
|
||||||
className?: string;
|
className?: string;
|
||||||
error?: string;
|
error?: React.ReactNode;
|
||||||
controls?: ReactNode;
|
controls?: ReactNode;
|
||||||
submitLabel?: ReactNode;
|
submitLabel?: ReactNode;
|
||||||
submittingMessage?: ReactNode;
|
submittingMessage?: ReactNode;
|
||||||
@ -50,9 +46,7 @@ interface OptionalProps {
|
|||||||
showStatusPanel?: boolean;
|
showStatusPanel?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
const defaultProps: Partial<InfoPanelProps> = {
|
||||||
export class InfoPanel extends Component<Props> {
|
|
||||||
static defaultProps: OptionalProps = {
|
|
||||||
submitLabel: "Submit",
|
submitLabel: "Submit",
|
||||||
submittingMessage: "Submitting..",
|
submittingMessage: "Submitting..",
|
||||||
showButtons: true,
|
showButtons: true,
|
||||||
@ -62,10 +56,13 @@ export class InfoPanel extends Component<Props> {
|
|||||||
showStatusPanel: true,
|
showStatusPanel: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
@observable error = "";
|
@observer
|
||||||
|
export class InfoPanel extends Component<InfoPanelProps> {
|
||||||
|
static defaultProps = defaultProps as object;
|
||||||
|
|
||||||
@observable waiting = false;
|
@observable waiting = false;
|
||||||
|
|
||||||
constructor(props: Props) {
|
constructor(props: InfoPanelProps) {
|
||||||
super(props);
|
super(props);
|
||||||
makeObservable(this);
|
makeObservable(this);
|
||||||
}
|
}
|
||||||
@ -78,10 +75,6 @@ export class InfoPanel extends Component<Props> {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed get errorInfo() {
|
|
||||||
return this.props.error;
|
|
||||||
}
|
|
||||||
|
|
||||||
submit = async () => {
|
submit = async () => {
|
||||||
const { showNotifications } = this.props;
|
const { showNotifications } = this.props;
|
||||||
|
|
||||||
@ -107,14 +100,16 @@ export class InfoPanel extends Component<Props> {
|
|||||||
dockStore.closeTab(this.props.tabId);
|
dockStore.closeTab(this.props.tabId);
|
||||||
};
|
};
|
||||||
|
|
||||||
renderErrorIcon() {
|
renderErrorIcon(): React.ReactNode {
|
||||||
if (!this.props.showInlineInfo || !this.errorInfo) {
|
const { error } = this.props;
|
||||||
|
|
||||||
|
if (!error || !this.props.showInlineInfo) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="error">
|
<div className="error">
|
||||||
<Icon material="error_outline" tooltip={this.errorInfo}/>
|
<Icon material="error_outline" tooltip={error}/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,7 +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.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.InstallChart {
|
.InstallChartInfoPanel {
|
||||||
.Select {
|
.Select {
|
||||||
&.NamespaceSelect {
|
&.NamespaceSelect {
|
||||||
min-width: 130px;
|
min-width: 130px;
|
||||||
|
|||||||
@ -25,7 +25,7 @@ import React, { Component } from "react";
|
|||||||
import { computed, makeObservable, observable } from "mobx";
|
import { computed, makeObservable, observable } from "mobx";
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import { dockStore, TabKind } from "./dock.store";
|
import { dockStore, TabKind } from "./dock.store";
|
||||||
import { InfoPanel } from "./info-panel";
|
import { InfoPanel, InfoPanelProps } from "./info-panel";
|
||||||
import { Badge } from "../badge";
|
import { Badge } from "../badge";
|
||||||
import { NamespaceSelect } from "../+namespaces/namespace-select";
|
import { NamespaceSelect } from "../+namespaces/namespace-select";
|
||||||
import { prevDefault } from "../../utils";
|
import { prevDefault } from "../../utils";
|
||||||
@ -39,14 +39,13 @@ 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 type { DockTabContentProps } from "./dock-tab-content";
|
|
||||||
import { dockViewsManager } from "./dock.views-manager";
|
import { dockViewsManager } from "./dock.views-manager";
|
||||||
|
|
||||||
interface Props extends DockTabContentProps {
|
interface Props extends InfoPanelProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class InstallChart extends Component<Props> {
|
export class InstallChartInfoPanel extends Component<Props> {
|
||||||
@observable showNotes = false;
|
@observable showNotes = false;
|
||||||
|
|
||||||
constructor(props: Props) {
|
constructor(props: Props) {
|
||||||
@ -55,7 +54,7 @@ export class InstallChart extends Component<Props> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get tabId() {
|
get tabId() {
|
||||||
return this.props.tab.id;
|
return this.props.tabId;
|
||||||
}
|
}
|
||||||
|
|
||||||
get chartData(): IChartInstallData | undefined {
|
get chartData(): IChartInstallData | undefined {
|
||||||
@ -160,7 +159,7 @@ export class InstallChart extends Component<Props> {
|
|||||||
return this.renderReleaseDetails();
|
return this.renderReleaseDetails();
|
||||||
}
|
}
|
||||||
|
|
||||||
const { tabId, chartData, install, versions } = this;
|
const { chartData, install, versions } = this;
|
||||||
const { repo, name, version, namespace, releaseName } = chartData;
|
const { repo, name, version, namespace, releaseName } = chartData;
|
||||||
|
|
||||||
const panelControls = (
|
const panelControls = (
|
||||||
@ -195,22 +194,21 @@ export class InstallChart extends Component<Props> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="InstallChart">
|
|
||||||
<InfoPanel
|
<InfoPanel
|
||||||
tabId={tabId}
|
{...this.props}
|
||||||
|
className="InstallChartInfoPanel"
|
||||||
controls={panelControls}
|
controls={panelControls}
|
||||||
submit={install}
|
submit={install}
|
||||||
submitLabel="Install"
|
submitLabel="Install"
|
||||||
submittingMessage="Installing..."
|
submittingMessage="Installing..."
|
||||||
showSubmitClose={false}
|
showSubmitClose={false}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dockViewsManager.register(TabKind.INSTALL_CHART, {
|
dockViewsManager.register(TabKind.INSTALL_CHART, {
|
||||||
Content: InstallChart,
|
InfoPanel: InstallChartInfoPanel,
|
||||||
editor: {
|
editor: {
|
||||||
getValue(tabId) {
|
getValue(tabId) {
|
||||||
return installChartStore.getData(tabId).values;
|
return installChartStore.getData(tabId).values;
|
||||||
|
|||||||
@ -125,7 +125,7 @@ export class Logs extends React.Component<Props> {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<InfoPanel
|
<InfoPanel
|
||||||
tabId={this.props.tab.id}
|
tabId={this.tabId}
|
||||||
controls={controls}
|
controls={controls}
|
||||||
showSubmitClose={false}
|
showSubmitClose={false}
|
||||||
showButtons={false}
|
showButtons={false}
|
||||||
|
|||||||
@ -1,23 +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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
.UpgradeChart {
|
|
||||||
}
|
|
||||||
@ -19,24 +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 "./upgrade-chart.scss";
|
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { computed, makeObservable, observable } from "mobx";
|
import { computed, makeObservable, observable } from "mobx";
|
||||||
import { observer } from "mobx-react";
|
import { observer } from "mobx-react";
|
||||||
import { InfoPanel } from "./info-panel";
|
import { InfoPanel, InfoPanelProps } from "./info-panel";
|
||||||
import { upgradeChartStore } from "./upgrade-chart.store";
|
import { upgradeChartStore } from "./upgrade-chart.store";
|
||||||
import { releaseStore } from "../+apps-releases/release.store";
|
import { releaseStore } from "../+apps-releases/release.store";
|
||||||
import { Badge } from "../badge";
|
import { Badge } from "../badge";
|
||||||
import { Select, SelectOption } from "../select";
|
import { Select, SelectOption } from "../select";
|
||||||
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 type { DockTabContentProps } from "./dock-tab-content";
|
|
||||||
import { TabKind } from "./dock.store";
|
import { TabKind } from "./dock.store";
|
||||||
import { dockViewsManager } from "./dock.views-manager";
|
import { dockViewsManager } from "./dock.views-manager";
|
||||||
import { Spinner } from "../spinner";
|
|
||||||
|
|
||||||
interface Props extends DockTabContentProps {
|
interface Props extends InfoPanelProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
@ -49,7 +45,7 @@ export class UpgradeChart extends React.Component<Props> {
|
|||||||
@observable selectedVersion: IChartVersion;
|
@observable selectedVersion: IChartVersion;
|
||||||
|
|
||||||
get tabId() {
|
get tabId() {
|
||||||
return this.props.tab.id;
|
return this.props.tabId;
|
||||||
}
|
}
|
||||||
|
|
||||||
get release(): HelmRelease | null {
|
get release(): HelmRelease | null {
|
||||||
@ -90,18 +86,12 @@ export class UpgradeChart extends React.Component<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { tabId, release, versions, selectedVersion } = this;
|
const { release, versions, selectedVersion } = this;
|
||||||
|
|
||||||
if (!release) {
|
|
||||||
return <Spinner center/>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentVersion = release.getVersion();
|
const currentVersion = release.getVersion();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="UpgradeChart">
|
|
||||||
<InfoPanel
|
<InfoPanel
|
||||||
tabId={tabId}
|
{...this.props}
|
||||||
submit={this.upgrade}
|
submit={this.upgrade}
|
||||||
submitLabel="Upgrade"
|
submitLabel="Upgrade"
|
||||||
submittingMessage="Updating.."
|
submittingMessage="Updating.."
|
||||||
@ -123,13 +113,12 @@ export class UpgradeChart extends React.Component<Props> {
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dockViewsManager.register(TabKind.UPGRADE_CHART, {
|
dockViewsManager.register(TabKind.UPGRADE_CHART, {
|
||||||
Content: UpgradeChart,
|
InfoPanel: UpgradeChart,
|
||||||
editor: {
|
editor: {
|
||||||
getValue(tabId): string {
|
getValue(tabId): string {
|
||||||
return upgradeChartStore.values.get(tabId);
|
return upgradeChartStore.values.get(tabId);
|
||||||
|
|||||||
@ -39,24 +39,12 @@ export interface MonacoEditorProps {
|
|||||||
theme?: "vs" /* default, light theme */ | "vs-dark" | "hc-black" | string;
|
theme?: "vs" /* default, light theme */ | "vs-dark" | "hc-black" | string;
|
||||||
language?: "yaml" | "json"; // configure bundled list of languages in via MonacoWebpackPlugin({languages: []})
|
language?: "yaml" | "json"; // configure bundled list of languages in via MonacoWebpackPlugin({languages: []})
|
||||||
options?: Partial<editor.IStandaloneEditorConstructionOptions>; // customize editor's initialization options
|
options?: Partial<editor.IStandaloneEditorConstructionOptions>; // customize editor's initialization options
|
||||||
onChange?: onMonacoContentChangeCallback;
|
onChange?(value: string, evt: editor.IModelContentChangedEvent): void; // catch latest value updates
|
||||||
onError?: onMonacoErrorCallback; // provide syntax validation errors, etc.
|
onError?(error?: string): void; // provide syntax validation errors, etc.
|
||||||
onDidLayoutChange?(info: editor.EditorLayoutInfo): void;
|
onDidLayoutChange?(info: editor.EditorLayoutInfo): void;
|
||||||
onDidContentSizeChange?(evt: editor.IContentSizeChangedEvent): void;
|
onDidContentSizeChange?(evt: editor.IContentSizeChangedEvent): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
// `props.onChange` called via editor's api value changes / user input, but when `props.value` changes
|
|
||||||
export interface onMonacoContentChangeCallback {
|
|
||||||
(value: string, data: {
|
|
||||||
model: editor.ITextModel, // current model
|
|
||||||
event: editor.IModelContentChangedEvent;
|
|
||||||
}): void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface onMonacoErrorCallback {
|
|
||||||
(error: string): void; // TODO: provide validation or some another occurred error
|
|
||||||
}
|
|
||||||
|
|
||||||
export const defaultEditorProps: Partial<MonacoEditorProps> = {
|
export const defaultEditorProps: Partial<MonacoEditorProps> = {
|
||||||
language: "yaml",
|
language: "yaml",
|
||||||
get theme(): MonacoEditorProps["theme"] {
|
get theme(): MonacoEditorProps["theme"] {
|
||||||
@ -119,6 +107,7 @@ export class MonacoEditor extends React.Component<MonacoEditorProps> {
|
|||||||
this.editor.restoreViewState(this.getViewState(model)); // restore cursor position, selection, etc.
|
this.editor.restoreViewState(this.getViewState(model)); // restore cursor position, selection, etc.
|
||||||
this.editor.layout();
|
this.editor.layout();
|
||||||
this.editor.focus(); // keep focus in editor, e.g. when clicking between dock-tabs
|
this.editor.focus(); // keep focus in editor, e.g. when clicking between dock-tabs
|
||||||
|
this.validateLazy();
|
||||||
};
|
};
|
||||||
|
|
||||||
@computed get editorId(): string {
|
@computed get editorId(): string {
|
||||||
@ -132,13 +121,9 @@ export class MonacoEditor extends React.Component<MonacoEditorProps> {
|
|||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
try {
|
try {
|
||||||
this.createEditor();
|
this.createEditor();
|
||||||
|
|
||||||
if (this.props.autoFocus) {
|
|
||||||
this.editor.focus();
|
|
||||||
}
|
|
||||||
console.info(`[MONACO]: editor did mounted`);
|
console.info(`[MONACO]: editor did mounted`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`[MONACO]: mounting failed`, { error, editor, component: this });
|
console.error(`[MONACO]: mounting failed: ${error}`, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,6 +147,11 @@ export class MonacoEditor extends React.Component<MonacoEditorProps> {
|
|||||||
...this.options,
|
...this.options,
|
||||||
});
|
});
|
||||||
console.info(`[MONACO]: editor created for language=${language}, theme=${theme}`);
|
console.info(`[MONACO]: editor created for language=${language}, theme=${theme}`);
|
||||||
|
this.validateLazy(); // validate initial value
|
||||||
|
|
||||||
|
if (this.props.autoFocus) {
|
||||||
|
this.editor.focus();
|
||||||
|
}
|
||||||
|
|
||||||
const onDidLayoutChangeDisposer = this.editor.onDidLayoutChange(layoutInfo => {
|
const onDidLayoutChangeDisposer = this.editor.onDidLayoutChange(layoutInfo => {
|
||||||
this.props.onDidLayoutChange?.(layoutInfo);
|
this.props.onDidLayoutChange?.(layoutInfo);
|
||||||
@ -172,11 +162,8 @@ export class MonacoEditor extends React.Component<MonacoEditorProps> {
|
|||||||
const value = this.editor.getValue();
|
const value = this.editor.getValue();
|
||||||
// console.info("[MONACO]: value changed", { value, event });
|
// console.info("[MONACO]: value changed", { value, event });
|
||||||
|
|
||||||
|
this.props.onChange?.(value, event);
|
||||||
this.validateLazy(value);
|
this.validateLazy(value);
|
||||||
this.props.onChange?.(value, {
|
|
||||||
model: this.model,
|
|
||||||
event,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const onContentSizeChangeDisposer = this.editor.onDidContentSizeChange((params) => {
|
const onContentSizeChangeDisposer = this.editor.onDidContentSizeChange((params) => {
|
||||||
@ -244,18 +231,15 @@ export class MonacoEditor extends React.Component<MonacoEditorProps> {
|
|||||||
if (value == this.getValue()) return;
|
if (value == this.getValue()) return;
|
||||||
|
|
||||||
this.editor.setValue(value);
|
this.editor.setValue(value);
|
||||||
this.validateLazy(value);
|
this.validate(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
getValue(opts?: { preserveBOM: boolean; lineEnding: string; }): string {
|
getValue(opts?: { preserveBOM: boolean; lineEnding: string; }): string {
|
||||||
return this.editor?.getValue(opts) ?? "";
|
return this.editor?.getValue(opts) ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// avoid excessive validations during typing
|
|
||||||
validateLazy = debounce((value: string) => this.validate(value), 250);
|
|
||||||
|
|
||||||
@action
|
@action
|
||||||
async validate(value: string = this.getValue()): Promise<void> {
|
validate = async (value = this.getValue()): Promise<void> => {
|
||||||
const { language } = this.props;
|
const { language } = this.props;
|
||||||
const validators: MonacoValidator[] = [];
|
const validators: MonacoValidator[] = [];
|
||||||
const syntaxValidator: MonacoValidator = monacoValidators[language];
|
const syntaxValidator: MonacoValidator = monacoValidators[language];
|
||||||
@ -264,7 +248,8 @@ export class MonacoEditor extends React.Component<MonacoEditorProps> {
|
|||||||
validators.push(syntaxValidator);
|
validators.push(syntaxValidator);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.validationErrors.clear();
|
// console.info('[MONACO]: validating', { value, validators });
|
||||||
|
this.validationErrors.clear(); // reset first
|
||||||
|
|
||||||
for (const validate of validators) {
|
for (const validate of validators) {
|
||||||
try {
|
try {
|
||||||
@ -275,7 +260,10 @@ export class MonacoEditor extends React.Component<MonacoEditorProps> {
|
|||||||
this.props.onError?.(error); // emit error outside via callback
|
this.props.onError?.(error); // emit error outside via callback
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
// avoid excessive validations during typing
|
||||||
|
validateLazy = debounce(this.validate, 250);
|
||||||
|
|
||||||
bindRef = (elem: HTMLElement) => this.containerElem = elem;
|
bindRef = (elem: HTMLElement) => this.containerElem = elem;
|
||||||
|
|
||||||
|
|||||||
@ -24,21 +24,21 @@ export interface MonacoValidator {
|
|||||||
(value: string): Promise<void>;
|
(value: string): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const yamlValidator: MonacoValidator = async (value: string) => {
|
export async function yamlValidator(value: string) {
|
||||||
try {
|
try {
|
||||||
await yaml.safeLoad(value);
|
await yaml.load(value);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw String(error as YAMLException);
|
throw String(error as YAMLException);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export const jsonValidator: MonacoValidator = async (value: string) => {
|
export async function jsonValidator(value: string) {
|
||||||
try {
|
try {
|
||||||
await yaml.safeLoad(value, { json: true });
|
JSON.parse(value);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw String(error);
|
throw String(error);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export const monacoValidators = {
|
export const monacoValidators = {
|
||||||
yaml: yamlValidator,
|
yaml: yamlValidator,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user