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

Fix edit-resource by correctly saving first draft

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2021-11-15 10:25:00 -05:00
parent 3214d8dfd5
commit 6959fa7a53

View File

@ -22,7 +22,7 @@
import "./edit-resource.scss"; import "./edit-resource.scss";
import React from "react"; import React from "react";
import { action, computed, makeObservable, observable } from "mobx"; import { 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";
@ -64,26 +64,19 @@ export class EditResource extends React.Component<Props> {
return ""; // wait until tab's data and kube-object resource are loaded return ""; // wait until tab's data and kube-object resource are loaded
} }
const { draft } = editResourceStore.getData(this.tabId); const editData = editResourceStore.getData(this.tabId);
if (typeof draft === "string") { if (typeof editData.draft === "string") {
return draft; return editData.draft;
} }
return yaml.dump(this.resource.toPlainObject()); // dump resource first time const firstDraft = yaml.dump(this.resource.toPlainObject()); // dump resource first time
return editData.firstDraft = firstDraft;
} }
@action saveDraft(draft: string) {
saveDraft(draft: string | object) { editResourceStore.getData(this.tabId).draft = draft;
if (typeof draft === "object") {
draft = draft ? yaml.dump(draft) : undefined;
}
editResourceStore.setData(this.tabId, {
firstDraft: draft, // this must be before the next line
...editResourceStore.getData(this.tabId),
draft,
});
} }
onChange = (draft: string) => { onChange = (draft: string) => {