Select Git revision
window_actions.test.js
WindowList.js 1.99 KiB
import React, { Component } from 'react';
import Button from '@material-ui/core/Button';
import Menu from '@material-ui/core/Menu';
import MenuItem from '@material-ui/core/MenuItem';
import ListSubheader from '@material-ui/core/ListSubheader';
import PropTypes from 'prop-types';
/**
*/
class WindowList extends Component {
/**
* Get the title for a window from its manifest title
* @private
*/
titleContent(window) {
const { manifests, t } = this.props;
if (window.manifestId
&& manifests[window.manifestId]
&& manifests[window.manifestId].manifestation) {
return manifests[window.manifestId].manifestation.getLabel().map(label => label.value)[0];
}
return t('untitled');
}
/**
* render
* @return
*/
render() {
const {
handleClose, anchorEl, windows, focusWindow, t,
} = this.props;
return (
<Menu id="window-list-menu" anchorEl={anchorEl} open={Boolean(anchorEl)} onClose={handleClose}>
<ListSubheader>
<Button color="inherit" aria-label={t('closeMenu')} onClick={handleClose} align="right" style={{ float: 'right' }}>×</Button>
{t('openWindows')}
</ListSubheader>
{
Object.values(windows).map(window => (
<MenuItem
key={window.id}
onClick={(e) => { focusWindow(window.id); handleClose(e); }}
>
{
this.titleContent(window)
}
</MenuItem>
))
}
</Menu>
);
}
}
WindowList.propTypes = {
focusWindow: PropTypes.func.isRequired,
handleClose: PropTypes.func.isRequired,
anchorEl: PropTypes.object, // eslint-disable-line react/forbid-prop-types
windows: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
manifests: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
t: PropTypes.func,
};
WindowList.defaultProps = {
anchorEl: null,
t: key => key,
};
export default WindowList;