-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor equipment maintenance components
- Loading branch information
Showing
9 changed files
with
229 additions
and
452 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import { Button } from 'react-bootstrap'; | ||
|
||
function ActionButton(props) { | ||
const { label, disabled, onSend } = props; | ||
return ( | ||
<Button | ||
className="me-2" | ||
size="sm" | ||
variant="outline-secondary" | ||
disabled={disabled} | ||
onClick={() => onSend()} | ||
> | ||
{label} | ||
</Button> | ||
); | ||
} | ||
|
||
export default ActionButton; |
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,51 @@ | ||
import React, { useState } from 'react'; | ||
import { Button, Card, Form, InputGroup } from 'react-bootstrap'; | ||
|
||
function ActionField(props) { | ||
const { headerMsg, label, inputType = 'text', btnLabel, onSubmit } = props; | ||
|
||
const [inputValue, setInputValue] = useState(''); | ||
|
||
function handleInputChange(evt) { | ||
const { value } = evt.target; | ||
|
||
if (inputType === 'number') { | ||
setInputValue(value && Number(value)); | ||
} else { | ||
setInputValue(value); | ||
} | ||
} | ||
|
||
return ( | ||
<Card className="mb-2"> | ||
<Card.Header>{headerMsg}</Card.Header> | ||
<Card.Body> | ||
<Form | ||
onSubmit={(evt) => { | ||
evt.preventDefault(); | ||
onSubmit(inputValue); | ||
}} | ||
> | ||
<Form.Group> | ||
<Form.Label>{label}</Form.Label> | ||
<InputGroup> | ||
<Form.Control | ||
type={inputType} | ||
value={inputValue} | ||
required | ||
size="sm" | ||
style={{ width: '13em', flex: 'none' }} | ||
onChange={(e) => handleInputChange(e)} | ||
/> | ||
<Button type="submit" variant="outline-secondary"> | ||
{btnLabel} | ||
</Button> | ||
</InputGroup> | ||
</Form.Group> | ||
</Form> | ||
</Card.Body> | ||
</Card> | ||
); | ||
} | ||
|
||
export default ActionField; |
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 |
---|---|---|
@@ -1,91 +1,16 @@ | ||
import React, { useState } from 'react'; | ||
import { Button, InputGroup, ButtonGroup, Card, Form } from 'react-bootstrap'; | ||
import React from 'react'; | ||
import { ButtonGroup, Card } from 'react-bootstrap'; | ||
|
||
export function ActionGroup(props) { | ||
function ActionGroup(props) { | ||
const { label, children } = props; | ||
return ( | ||
<Card className="mb-2"> | ||
<Card.Header>{props.name}</Card.Header> | ||
<Card.Header>{label}</Card.Header> | ||
<Card.Body> | ||
<ButtonGroup>{props.buttons}</ButtonGroup> | ||
<ButtonGroup>{children}</ButtonGroup> | ||
</Card.Body> | ||
</Card> | ||
); | ||
} | ||
|
||
export function ActionButton(props) { | ||
let disabled; | ||
|
||
if (props.enabled === true) { | ||
disabled = false; | ||
} else { | ||
disabled = true; | ||
} | ||
|
||
return ( | ||
<Button | ||
disabled={disabled} | ||
onClick={() => props.sendCommand(props.cmd, props.args)} | ||
size="sm" | ||
className="me-2" | ||
variant={props.variant || 'outline-secondary'} | ||
> | ||
{props.label} | ||
</Button> | ||
); | ||
} | ||
|
||
export function ActionField(props) { | ||
const [inputValue, setInputValue] = useState(null); | ||
|
||
function handleInputChange(e) { | ||
if (props.inputType === 'number') { | ||
setInputValue(Number(e.target.value)); | ||
} else { | ||
setInputValue(e.target.value); | ||
} | ||
} | ||
|
||
function actionComponent() { | ||
return ( | ||
<span> | ||
<Form | ||
onSubmit={(e) => { | ||
e.preventDefault(); | ||
props.sendCommand(props.cmd, inputValue); | ||
}} | ||
> | ||
<Form.Group size="sm"> | ||
<Form.Label>{props.label}</Form.Label> | ||
<br /> | ||
<InputGroup> | ||
<Form.Control | ||
size="sm" | ||
required | ||
value={inputValue} | ||
style={{ | ||
maxWidth: '13em', | ||
minWidth: '13em', | ||
marginRight: '0.2em', | ||
}} | ||
type={props.inputType} | ||
onChange={(e) => { | ||
handleInputChange(e); | ||
}} | ||
/> | ||
<Button type="submit" size="sm"> | ||
{props.btn_label} | ||
</Button> | ||
</InputGroup> | ||
</Form.Group> | ||
</Form> | ||
</span> | ||
); | ||
} | ||
|
||
return ( | ||
<ActionGroup | ||
name={`${props.header_msg} : ${props.value}`} | ||
buttons={actionComponent()} | ||
/> | ||
); | ||
} | ||
export default ActionGroup; |
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
Oops, something went wrong.