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; height: auto;
background-color: var(--panel-bg-color); background-color: var(--panel-bg-color);
color: var(--main-text-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() { function PlotView() {
const containerRef = React.useRef<HTMLInputElement>(); const containerRef = React.useRef<HTMLInputElement>();
const [plotDef, setPlotDef] = React.useState<string>(); const [plotDef, setPlotDef] = React.useState<string>();
const [tempDef, setTempDef] = React.useState<string>();
const [savedDef, setSavedDef] = React.useState<string>(); const [savedDef, setSavedDef] = React.useState<string>();
const [modalUp, setModalUp] = React.useState(false); const [modalUp, setModalUp] = React.useState(false);
/* /*
@ -97,22 +96,33 @@ function PlotView() {
}; };
}, [plotDef]); }, [plotDef]);
const handleOpen = React.useCallback(() => {
setSavedDef(plotDef);
setModalUp(true);
}, []);
const handleCancel = React.useCallback(() => {
setPlotDef(savedDef);
setModalUp(false);
}, []);
const handleSave = React.useCallback(() => {
setModalUp(false);
}, []);
return ( return (
<div className="plot-view"> <div className="plot-view">
<Button onClick={() => setModalUp(true)}>Edit</Button> <Button onClick={handleOpen}>Edit</Button>
<div className="plot-window" ref={containerRef} /> <div className="plot-window" ref={containerRef} />
{modalUp && ( {modalUp && (
<WaveModal <WaveModal title="Plot Definition" onCancel={handleCancel} onSubmit={handleSave} buttonLabel={"Save"}>
title="Plot Definition"
onCancel={() => setModalUp(false)}
onSubmit={() => setModalUp(false)}
>
<textarea <textarea
className="plot-config" className="plot-config"
rows={5} rows={5}
onChange={(e) => setPlotDef(e.target.value)} onChange={(e) => setPlotDef(e.target.value)}
spellCheck={false} spellCheck={false}
defaultValue={plotDef} defaultValue={plotDef}
wrap={"off"}
/> />
</WaveModal> </WaveModal>
)} )}