-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed column order in status view and improved UI of approval dialog (
#888)
- Loading branch information
Showing
3 changed files
with
98 additions
and
75 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
159 changes: 85 additions & 74 deletions
159
...-configurationserver-ui/src/components/views/promotion/dialogs/PromotionApprovalDialog.js
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,93 +1,104 @@ | ||
import React from 'react'; | ||
import React, { useEffect, useState, useRef } from 'react'; | ||
import { Dialog } from 'primereact/dialog'; | ||
import { Button } from 'primereact/button'; | ||
import { ProgressBar } from 'primereact/progressbar'; | ||
import { InputText } from 'primereact/inputtext'; | ||
import _ from 'lodash'; | ||
|
||
/** | ||
* Dialog for showing the currently approved files before promoting them. | ||
*/ | ||
class PromotionApprovalDialog extends React.Component { | ||
state = { | ||
/** The promotion message to be send to the backend. */ | ||
promotionMessage: '', | ||
}; | ||
input = React.createRef(); | ||
render() { | ||
const { visible, onHide, isLoading, approvedFiles = [] } = this.props; | ||
const { promotionMessage } = this.state; | ||
const footer = ( | ||
<div> | ||
<Button label="Promote" onClick={this.promote} disabled={isLoading || !promotionMessage} /> | ||
<Button label="Cancel" className="p-button-secondary" onClick={onHide} disabled={isLoading} /> | ||
</div> | ||
); | ||
|
||
return ( | ||
<> | ||
<style jsx> | ||
{` | ||
.list li { | ||
font-family: monospace; | ||
} | ||
const PromotionApprovalDialog = ({ visible, onHide, onPromote, isLoading, approvedFiles = [] }) => { | ||
// state variables | ||
const [message, setMessage] = useState(''); | ||
|
||
.content :global(.p-progressbar) { | ||
height: 0.5rem; | ||
} | ||
`} | ||
</style> | ||
// ref variables | ||
const messageInput = useRef(null); | ||
|
||
<Dialog | ||
header="Promote Configurations" | ||
focusOnShow={false} | ||
visible={visible} | ||
style={{ width: '50vw' }} | ||
modal={true} | ||
onHide={onHide} | ||
footer={footer} | ||
> | ||
<div className="content"> | ||
<span>The following files have been approved and will be promoted:</span> | ||
<ul className="list"> | ||
{approvedFiles.map((file) => ( | ||
<li key={file}>{file}</li> | ||
))} | ||
</ul> | ||
// derived variables | ||
const isValidMessage = !_.isEmpty(message); | ||
|
||
{isLoading && <ProgressBar mode="indeterminate" />} | ||
</div> | ||
<InputText | ||
ref={this.input} | ||
style={{ width: '100%' }} | ||
placeholder="Describe change..." | ||
onKeyPress={this.onKeyPress} | ||
value={promotionMessage} | ||
onChange={(e) => this.setState({ promotionMessage: e.target.value })} | ||
/> | ||
</Dialog> | ||
</> | ||
); | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
if (!prevProps.visible && this.props.visible) { | ||
/**Timeout is needed for .focus() to be triggered correctly. */ | ||
setTimeout(() => { | ||
this.input.current.element.focus(); | ||
}, 0); | ||
this.setState({ promotionMessage: '' }); | ||
// clear message when dialog gets visible | ||
useEffect(() => { | ||
if (visible) { | ||
setMessage(''); | ||
} | ||
} | ||
}, [visible]); | ||
|
||
// invoke the promotion | ||
const promote = () => onPromote(message); | ||
|
||
onKeyPress = (e) => { | ||
if (e.key === 'Enter' && !this.props.isLoading && this.state.promotionMessage) { | ||
this.promote(); | ||
// promote when enter is pressed | ||
const onKeyPress = (event) => { | ||
if (event.key === 'Enter' && !isLoading && isValidMessage) { | ||
promote(); | ||
} | ||
}; | ||
|
||
promote = () => { | ||
this.props.onPromote(this.state.promotionMessage); | ||
// set the focus to the input field after the dialog is shown | ||
const onShow = () => { | ||
messageInput.current.element.focus(); | ||
}; | ||
} | ||
|
||
const footer = ( | ||
<div> | ||
<Button label="Promote" onClick={promote} disabled={isLoading || !isValidMessage} /> | ||
<Button label="Cancel" className="p-button-secondary" onClick={onHide} disabled={isLoading} /> | ||
</div> | ||
); | ||
|
||
return ( | ||
<> | ||
<style jsx> | ||
{` | ||
.list li { | ||
font-family: monospace; | ||
} | ||
.content :global(.p-progressbar) { | ||
height: 0.5rem; | ||
} | ||
.content :global(.message-input) { | ||
width: 100%; | ||
margin: 0.5rem 0 1rem; | ||
} | ||
`} | ||
</style> | ||
|
||
<Dialog | ||
header="Promote Configurations" | ||
focusOnShow={false} | ||
visible={visible} | ||
style={{ width: '50vw' }} | ||
modal={true} | ||
onHide={onHide} | ||
onShow={onShow} | ||
footer={footer} | ||
> | ||
<div className="content"> | ||
<span>The following files have been approved and will be promoted:</span> | ||
<ul className="list"> | ||
{approvedFiles.map((file) => ( | ||
<li key={file}>{file}</li> | ||
))} | ||
</ul> | ||
|
||
<span>Please add a message to describe the configuration promotion:</span> | ||
|
||
<InputText | ||
ref={messageInput} | ||
className="message-input" | ||
placeholder="Promotion message..." | ||
onKeyPress={onKeyPress} | ||
value={message} | ||
onChange={(e) => setMessage(e.target.value)} | ||
disabled={isLoading} | ||
/> | ||
|
||
{isLoading && <ProgressBar mode="indeterminate" />} | ||
</div> | ||
</Dialog> | ||
</> | ||
); | ||
}; | ||
|
||
export default PromotionApprovalDialog; |
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