mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Kludge editing of kube resources to work again
Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
parent
d8c62fff82
commit
44db4a3cd9
@ -4,11 +4,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { autorun, makeObservable, observable } from "mobx";
|
import { autorun, computed, makeObservable, observable } from "mobx";
|
||||||
import { disposeOnUnmount, observer } from "mobx-react";
|
import { disposeOnUnmount, observer } from "mobx-react";
|
||||||
import yaml from "js-yaml";
|
import yaml from "js-yaml";
|
||||||
import type { DockTab, TabId } from "../dock/store";
|
import type { DockTab, TabId } from "../dock/store";
|
||||||
import type { EditingResource, EditResourceTabStore } from "./store";
|
import type { EditResourceTabStore } from "./store";
|
||||||
import { InfoPanel } from "../info-panel";
|
import { InfoPanel } from "../info-panel";
|
||||||
import { Badge } from "../../badge";
|
import { Badge } from "../../badge";
|
||||||
import { EditorPanel } from "../editor-panel";
|
import { EditorPanel } from "../editor-panel";
|
||||||
@ -31,7 +31,6 @@ interface Dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface SaveDraftArgs {
|
interface SaveDraftArgs {
|
||||||
tabData: EditingResource;
|
|
||||||
resource: KubeObject;
|
resource: KubeObject;
|
||||||
store: KubeObjectStore;
|
store: KubeObjectStore;
|
||||||
}
|
}
|
||||||
@ -39,7 +38,7 @@ interface SaveDraftArgs {
|
|||||||
@observer
|
@observer
|
||||||
class NonInjectedEditResource extends React.Component<EditResourceProps & Dependencies> {
|
class NonInjectedEditResource extends React.Component<EditResourceProps & Dependencies> {
|
||||||
@observable error = "";
|
@observable error = "";
|
||||||
@observable draft = "";
|
@observable configurationWhenOpened = "";
|
||||||
|
|
||||||
constructor(props: EditResourceProps & Dependencies) {
|
constructor(props: EditResourceProps & Dependencies) {
|
||||||
super(props);
|
super(props);
|
||||||
@ -61,9 +60,9 @@ class NonInjectedEditResource extends React.Component<EditResourceProps & Depend
|
|||||||
},
|
},
|
||||||
({ tabData, resource }) => {
|
({ tabData, resource }) => {
|
||||||
if (typeof tabData.draft === "string") {
|
if (typeof tabData.draft === "string") {
|
||||||
this.draft = tabData.draft;
|
this.configurationWhenOpened = tabData.draft;
|
||||||
} else {
|
} else {
|
||||||
this.draft = tabData.firstDraft = yaml.dump(resource.toPlainObject());
|
this.configurationWhenOpened = tabData.firstDraft = yaml.dump(resource.toPlainObject());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -101,14 +100,15 @@ class NonInjectedEditResource extends React.Component<EditResourceProps & Depend
|
|||||||
return this.props.editResourceStore.getData(this.tabId);
|
return this.props.editResourceStore.getData(this.tabId);
|
||||||
}
|
}
|
||||||
|
|
||||||
async save({ resource, store, tabData }: SaveDraftArgs) {
|
async save({ resource, store }: SaveDraftArgs) {
|
||||||
if (this.error) {
|
if (this.error) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentVersion = yaml.load(this.draft);
|
const currentVersion = yaml.load(this.configurationWhenOpened);
|
||||||
const firstVersion = yaml.load(tabData.firstDraft ?? this.draft);
|
const firstVersion = yaml.load(this.configurationInView ?? this.configurationWhenOpened);
|
||||||
const patches = createPatch(firstVersion, currentVersion);
|
const patches = createPatch(currentVersion, firstVersion);
|
||||||
|
|
||||||
const updatedResource = await store.patch(resource, patches);
|
const updatedResource = await store.patch(resource, patches);
|
||||||
|
|
||||||
this.props.editResourceStore.clearInitialDraft(this.tabId);
|
this.props.editResourceStore.clearInitialDraft(this.tabId);
|
||||||
@ -123,8 +123,12 @@ class NonInjectedEditResource extends React.Component<EditResourceProps & Depend
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@computed get configurationInView() {
|
||||||
|
return this.props.editResourceStore.getData(this.tabId)?.draft;
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { tabId, error, draft, tabData, resource, store } = this;
|
const { tabId, error, configurationWhenOpened, tabData, resource, store } = this;
|
||||||
|
|
||||||
if (!tabData || !resource || !store) {
|
if (!tabData || !resource || !store) {
|
||||||
return <Spinner center />;
|
return <Spinner center />;
|
||||||
@ -135,7 +139,7 @@ class NonInjectedEditResource extends React.Component<EditResourceProps & Depend
|
|||||||
<InfoPanel
|
<InfoPanel
|
||||||
tabId={tabId}
|
tabId={tabId}
|
||||||
error={error}
|
error={error}
|
||||||
submit={() => this.save({ resource, store, tabData })}
|
submit={() => this.save({ resource, store })}
|
||||||
submitLabel="Save"
|
submitLabel="Save"
|
||||||
submittingMessage="Applying.."
|
submittingMessage="Applying.."
|
||||||
controls={(
|
controls={(
|
||||||
@ -151,7 +155,7 @@ class NonInjectedEditResource extends React.Component<EditResourceProps & Depend
|
|||||||
/>
|
/>
|
||||||
<EditorPanel
|
<EditorPanel
|
||||||
tabId={tabId}
|
tabId={tabId}
|
||||||
value={draft}
|
value={configurationWhenOpened}
|
||||||
onChange={draft => {
|
onChange={draft => {
|
||||||
this.error = "";
|
this.error = "";
|
||||||
tabData.draft = draft;
|
tabData.draft = draft;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user