mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
feat: restore unmodified plot on cancel
This commit is contained in:
parent
cddaff4f7e
commit
e54f134770
@ -14,5 +14,6 @@
|
||||
height: auto;
|
||||
background-color: var(--panel-bg-color);
|
||||
color: var(--main-text-color);
|
||||
font: var(--fixed-font);
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,6 @@ function evalAsync(Plot: any, d3: any, funcText: string): Promise<unknown> {
|
||||
function PlotView() {
|
||||
const containerRef = React.useRef<HTMLInputElement>();
|
||||
const [plotDef, setPlotDef] = React.useState<string>();
|
||||
const [tempDef, setTempDef] = React.useState<string>();
|
||||
const [savedDef, setSavedDef] = React.useState<string>();
|
||||
const [modalUp, setModalUp] = React.useState(false);
|
||||
/*
|
||||
@ -97,22 +96,33 @@ function PlotView() {
|
||||
};
|
||||
}, [plotDef]);
|
||||
|
||||
const handleOpen = React.useCallback(() => {
|
||||
setSavedDef(plotDef);
|
||||
setModalUp(true);
|
||||
}, []);
|
||||
|
||||
const handleCancel = React.useCallback(() => {
|
||||
setPlotDef(savedDef);
|
||||
setModalUp(false);
|
||||
}, []);
|
||||
|
||||
const handleSave = React.useCallback(() => {
|
||||
setModalUp(false);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="plot-view">
|
||||
<Button onClick={() => setModalUp(true)}>Edit</Button>
|
||||
<Button onClick={handleOpen}>Edit</Button>
|
||||
<div className="plot-window" ref={containerRef} />
|
||||
{modalUp && (
|
||||
<WaveModal
|
||||
title="Plot Definition"
|
||||
onCancel={() => setModalUp(false)}
|
||||
onSubmit={() => setModalUp(false)}
|
||||
>
|
||||
<WaveModal title="Plot Definition" onCancel={handleCancel} onSubmit={handleSave} buttonLabel={"Save"}>
|
||||
<textarea
|
||||
className="plot-config"
|
||||
rows={5}
|
||||
onChange={(e) => setPlotDef(e.target.value)}
|
||||
spellCheck={false}
|
||||
defaultValue={plotDef}
|
||||
wrap={"off"}
|
||||
/>
|
||||
</WaveModal>
|
||||
)}
|
||||
|
Loading…
Reference in New Issue
Block a user