-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a basic UI to monitor the metadata retrieval process
- Loading branch information
Showing
8 changed files
with
218 additions
and
45 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,104 @@ | ||
import cx from 'classnames'; | ||
import { Fragment, useCallback, memo, useEffect } from 'react'; | ||
import { Button, Icon } from 'web-common/components'; | ||
import { useDispatch, useSelector, shallowEqual } from 'react-redux'; | ||
import { usePrevious } from 'web-common/hooks'; | ||
|
||
import Modal from '../ui/modal'; | ||
import { METADATA_RETRIEVAL } from '../../constants/modals'; | ||
import { currentRetrieveMetadata, toggleModal } from '../../actions'; | ||
|
||
|
||
const MetadataRetrievalModal = () => { | ||
const dispatch = useDispatch(); | ||
const isTouchOrSmall = useSelector(state => state.device.isTouchOrSmall); | ||
const isOpen = useSelector(state => state.modal.id === METADATA_RETRIEVAL); | ||
const wasOpen = usePrevious(isOpen); | ||
const recognizeProgress = useSelector(state => state.recognize.progress); | ||
const recognizeEntries = useSelector(state => state.recognize.entries, shallowEqual); | ||
|
||
const handleCancel = useCallback(() => { | ||
dispatch(toggleModal()); | ||
}, [dispatch]); | ||
|
||
useEffect(() => { | ||
if(isOpen && !wasOpen) { | ||
dispatch(currentRetrieveMetadata()); | ||
} | ||
}, [dispatch, isOpen, wasOpen]); | ||
|
||
return ( | ||
<Modal | ||
className={ "recognize-modal" } | ||
contentLabel="Metadata Retrieval" | ||
isOpen={ isOpen } | ||
onRequestClose={ handleCancel } | ||
overlayClassName={ cx({ 'modal-centered modal-slide': isTouchOrSmall }) } | ||
> | ||
<div className="modal-header"> | ||
{ | ||
isTouchOrSmall ? ( | ||
<Fragment> | ||
<div className="modal-header-center"> | ||
<h4 className="modal-title truncate"> | ||
Metadata Retrieval | ||
</h4> | ||
</div> | ||
<div className="modal-header-right"> | ||
<Button | ||
className="btn-link" | ||
onClick={ handleCancel } | ||
> | ||
Close | ||
</Button> | ||
</div> | ||
</Fragment> | ||
) : ( | ||
<Fragment> | ||
<h4 className="modal-title truncate"> | ||
Metadata Retrieval | ||
</h4> | ||
<Button | ||
icon | ||
className="close" | ||
onClick={ handleCancel } | ||
> | ||
<Icon type={ '16/close' } width="16" height="16" /> | ||
</Button> | ||
</Fragment> | ||
) | ||
} | ||
</div> | ||
<div | ||
className="modal-body" | ||
tabIndex={ !isTouchOrSmall ? 0 : null } | ||
> | ||
<div className="recognize-progress"> | ||
<progress value={ recognizeProgress } max="1" /> | ||
</div> | ||
<div className="recognize-table"> | ||
{recognizeEntries.map(recognize => { | ||
const { itemKey, libraryKey, error, completed, itemTitle, parentItemTitle } = recognize; //error, completed, parentItemKey | ||
const key = `${itemKey}-${libraryKey}`; | ||
|
||
return ( | ||
<div | ||
key={ key } | ||
className={ cx('recognize-row') } | ||
> | ||
<div className="recognize-row-left"> | ||
{itemTitle } | ||
</div> | ||
<div className="recognize-row-right"> | ||
{completed ? parentItemTitle : error ? `Error: ${error}` : "Processing" } | ||
</div> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
</Modal> | ||
); | ||
} | ||
|
||
export default memo(MetadataRetrievalModal); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.recognize-progress { | ||
progress { | ||
width: 100%; | ||
} | ||
} | ||
|
||
.recognize-table { | ||
margin-top: 1em; | ||
|
||
.recognize-row { | ||
display: flex; | ||
padding: 0.33em 0; | ||
} | ||
|
||
.recognize-row-left, .recognize-row-right { | ||
@include text-truncate; | ||
} | ||
|
||
.recognize-row-left { | ||
flex: 0 0 100px; | ||
padding-right: 24px; | ||
} | ||
|
||
.recognize-row-right { | ||
flex: 1 1 auto; | ||
} | ||
} |
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