diff --git a/src/components/JobSubmitForm.tsx b/src/components/JobSubmitForm.tsx index ca1693a..d51525a 100755 --- a/src/components/JobSubmitForm.tsx +++ b/src/components/JobSubmitForm.tsx @@ -9,6 +9,8 @@ import { ToggleButton, ToggleButtonGroup } from 'react-bootstrap'; +import { AccordionEventKey } from 'react-bootstrap/AccordionContext'; +import { useAccordionButton } from 'react-bootstrap/AccordionButton'; import { BsCaretDownFill, BsCaretRightFill } from 'react-icons/bs'; import { FileBrowser } from '@jupyterlab/filebrowser'; @@ -23,7 +25,7 @@ namespace types { export type State = { filebrowser: FileBrowser; - fileitems: JSX.Element[]; + fileitems: React.ReactElement[]; inputType: string; inputPathSelectType: string; filepath: string; @@ -32,6 +34,15 @@ namespace types { }; } +interface ICustomToggleProps { + children: React.ReactNode; + eventKey: string; +} +function CustomToggle({ children, eventKey }: ICustomToggleProps) { + const decoratedOnClick = useAccordionButton(eventKey); + return
{children}
; +} + export default class JobSubmitForm extends React.Component< types.Props, types.State @@ -49,6 +60,7 @@ export default class JobSubmitForm extends React.Component< }; this.updateFilepath = this.updateFilepath.bind(this); + this.handleFileToggle = this.handleFileToggle.bind(this); } /* @@ -69,22 +81,22 @@ export default class JobSubmitForm extends React.Component< * and creates an array of ; }); } else { - fileItems = []; + fileItems = []; } return fileItems; @@ -166,8 +178,18 @@ export default class JobSubmitForm extends React.Component< this.props.addAlert('Job submitted', variant); } + handleFileToggle(eventKey: AccordionEventKey): void { + if (eventKey === '0') { + this.setState({ inputPathSelectType: 'textfield' }); + } else if (eventKey === '1') { + this.setState({ inputPathSelectType: 'dropdown' }); + } else { + this.setState({ inputPathSelectType: '' }); + } + } + render(): React.ReactNode { - const inputType = this.state.inputType; + const { inputType, filepath, fileitems } = this.state; return ( <> @@ -182,10 +204,18 @@ export default class JobSubmitForm extends React.Component< value={inputType} onChange={this.handleInputType.bind(this)} > - + Submit a File - + Submit Text @@ -193,29 +223,28 @@ export default class JobSubmitForm extends React.Component< {inputType === 'path' && ( - + - { - this.setState({ inputPathSelectType: 'textfield' }); - }} - > - {this.state.inputPathSelectType === 'textfield' && ( - - )} - {this.state.inputPathSelectType === 'dropdown' && ( - - )} - Type in the path to your slurm script - + + + {this.state.inputPathSelectType === 'textfield' && ( + + )} + {this.state.inputPathSelectType !== 'textfield' && ( + + )} + Type in the path to your slurm script + + { const timeout = setTimeout(() => { this.updateFilepath(e.target.value); @@ -238,21 +267,17 @@ export default class JobSubmitForm extends React.Component< - { - this.setState({ inputPathSelectType: 'dropdown' }); - }} - > - {this.state.inputPathSelectType === 'dropdown' && ( - - )} - {this.state.inputPathSelectType === 'textfield' && ( - - )} - Choose a slurm script from your current directory - + + + {this.state.inputPathSelectType === 'dropdown' && ( + + )} + {this.state.inputPathSelectType !== 'dropdown' && ( + + )} + Choose a slurm script from your current directory + + @@ -260,11 +285,11 @@ export default class JobSubmitForm extends React.Component< as="select" id={'fileselect-dropdown'} placeholder={'Select a file'} - value={this.state.filepath} + value={filepath} onChange={this.handleFileSelect.bind(this)} disabled={this.props.disabled} > - {this.state.fileitems} + {fileitems}