feat: restore unmodified plot on cancel

This commit is contained in:
Sylvia Crowe 2024-05-16 13:42:49 -07:00
parent cddaff4f7e
commit e54f134770
2 changed files with 18 additions and 7 deletions

View File

@ -14,5 +14,6 @@
height: auto;
background-color: var(--panel-bg-color);
color: var(--main-text-color);
font: var(--fixed-font);
}
}

View File

@ -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>
)}