-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add simple editor (#382) * add downloading (#382) * rename * add editor panel (#382) * remove caching of charts * deepsource
- Loading branch information
Showing
16 changed files
with
15,710 additions
and
10,453 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/WrapperApp/components/InputEditor/InputEditorPanel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Box, Button } from '@mui/material'; | ||
import { useState } from 'react'; | ||
import { InputFiles, useShSimulation } from '../../../services/ShSimulatorService'; | ||
import { useStore } from '../../../services/StoreService'; | ||
import { InputFilesEditor } from './InputFilesEditor'; | ||
|
||
interface InputEditorPanelProps { | ||
goToRun?: () => void; | ||
} | ||
|
||
export default function InputEditorPanel(props: InputEditorPanelProps) { | ||
const { editorRef } = useStore(); | ||
const { convertToInputFiles, sendRun } = useShSimulation(); | ||
|
||
const [isInProgress, setInProgress] = useState(false); | ||
const [inputFiles, setInputFiles] = useState<InputFiles>(); | ||
|
||
const [controller] = useState(new AbortController()); | ||
|
||
const onClickGenerate = () => { | ||
setInProgress(true); | ||
convertToInputFiles(editorRef.current?.toJSON(), controller.signal) | ||
.then(res => { | ||
setInputFiles({ ...res.content.input_files }); | ||
}) | ||
.catch() | ||
.finally(() => { | ||
setInProgress(false); | ||
}); | ||
}; | ||
|
||
const runSimulation = (inputFiles: InputFiles) => { | ||
setInProgress(true); | ||
const input = { inputFiles }; | ||
sendRun(input, controller.signal) | ||
.then() | ||
.catch() | ||
.finally(() => { | ||
setInProgress(false); | ||
props.goToRun?.call(null); | ||
}); | ||
}; | ||
return ( | ||
<Box | ||
sx={{ | ||
margin: '0 auto', | ||
width: '100%', | ||
padding: '3rem', | ||
gap: '1.5rem', | ||
height: 'min-content' | ||
}}> | ||
<Button | ||
variant='contained' | ||
onClick={onClickGenerate} | ||
disabled={isInProgress} | ||
sx={{ | ||
marginBottom: '2rem' | ||
}}> | ||
Generate from Editor | ||
</Button> | ||
<InputFilesEditor inputFiles={inputFiles} runSimulation={runSimulation} /> | ||
</Box> | ||
); | ||
} |
93 changes: 93 additions & 0 deletions
93
src/WrapperApp/components/InputEditor/InputFilesEditor.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { Box, Button, Card, CardActions, CardContent } from '@mui/material'; | ||
import React, { useState, useEffect } from 'react'; | ||
import { InputFiles } from '../../../services/ShSimulatorService'; | ||
import CodeEditor from '@uiw/react-textarea-code-editor'; | ||
import { saveString } from '../../../util/File'; | ||
|
||
interface InputFilesEditorProps { | ||
inputFiles?: InputFiles; | ||
runSimulation?: (inputFiles: InputFiles) => void; | ||
saveAndExit?: (inputFiles: InputFiles) => void; | ||
closeEditor?: () => void; | ||
innerState?: boolean; | ||
} | ||
|
||
const _emptyInputFiles: InputFiles = { | ||
'geo.dat': '', | ||
'beam.dat': '', | ||
'detect.dat': '', | ||
'mat.dat': '' | ||
}; | ||
export function InputFilesEditor(props: InputFilesEditorProps) { | ||
const [inputFiles, setInputFiles] = useState<InputFiles>( | ||
props.inputFiles ?? { ..._emptyInputFiles } | ||
); | ||
|
||
useEffect(() => { | ||
if (!props.innerState) setInputFiles({ ...(props.inputFiles ?? _emptyInputFiles) }); | ||
}, [props.innerState, props.inputFiles]); | ||
|
||
|
||
return ( | ||
<Card sx={{ minHeight: '100%' }}> | ||
<CardActions sx={{ justifyContent: 'flex-end' }}> | ||
{props.runSimulation && ( | ||
<Button | ||
color='success' | ||
variant='contained' | ||
onClick={() => props.runSimulation?.call(null, inputFiles)}> | ||
Run input files | ||
</Button> | ||
)} | ||
<Button | ||
onClick={() => | ||
Object.entries(inputFiles).map(([name, value]) => saveString(value, name)) | ||
}> | ||
Download all | ||
</Button> | ||
{props.saveAndExit && ( | ||
<Button onClick={() => props.saveAndExit?.call(null, inputFiles)}> | ||
Save and exit | ||
</Button> | ||
)} | ||
{props.closeEditor && ( | ||
<Button onClick={() => props.closeEditor?.call(null)}>Close</Button> | ||
)} | ||
</CardActions> | ||
<CardContent> | ||
{Object.entries(inputFiles).map(([name, value]) => { | ||
return ( | ||
<Box key={name}> | ||
<h2> | ||
{name} | ||
<Button | ||
onClick={() => { | ||
saveString(value, name); | ||
}}> | ||
Download | ||
</Button> | ||
</h2> | ||
<CodeEditor | ||
value={value} | ||
language='sql' | ||
placeholder={`Please enter ${name} content.`} | ||
onChange={evn => | ||
setInputFiles(old => { | ||
return { ...old, [name]: evn.target.value }; | ||
}) | ||
} | ||
padding={15} | ||
style={{ | ||
fontSize: 12, | ||
backgroundColor: '#f5f5f5', | ||
fontFamily: | ||
'ui-monospace,SFMono-Regular,SF Mono,Consolas,Liberation Mono,Menlo,monospace' | ||
}} | ||
/> | ||
</Box> | ||
); | ||
})} | ||
</CardContent> | ||
</Card> | ||
); | ||
} |
Oops, something went wrong.