2016-10-11 10:46:24 +02:00
|
|
|
import React, { PropTypes } from 'react';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
2016-09-15 18:56:08 +02:00
|
|
|
import pluralize from 'pluralize';
|
|
|
|
import { IndexLink } from 'react-router';
|
2016-10-05 18:55:35 +02:00
|
|
|
import { Menu, MenuItem } from 'react-toolbox';
|
2016-09-15 18:56:08 +02:00
|
|
|
import AppBar from 'react-toolbox/lib/app_bar';
|
2016-09-16 12:54:26 +02:00
|
|
|
import FindBar from '../FindBar/FindBar';
|
2016-09-15 18:56:08 +02:00
|
|
|
import styles from './AppHeader.css';
|
|
|
|
|
|
|
|
export default class AppHeader extends React.Component {
|
|
|
|
|
2016-10-11 10:46:24 +02:00
|
|
|
static propTypes = {
|
|
|
|
collections: ImmutablePropTypes.list.isRequired,
|
|
|
|
commands: PropTypes.array.isRequired, // eslint-disable-line
|
|
|
|
defaultCommands: PropTypes.array.isRequired, // eslint-disable-line
|
|
|
|
runCommand: PropTypes.func.isRequired,
|
|
|
|
toggleNavDrawer: PropTypes.func.isRequired,
|
|
|
|
onCreateEntryClick: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
2016-09-15 18:56:08 +02:00
|
|
|
state = {
|
2016-10-11 10:46:24 +02:00
|
|
|
createMenuActive: false,
|
2016-10-03 16:37:11 +02:00
|
|
|
};
|
2016-09-15 18:56:08 +02:00
|
|
|
|
2016-10-11 10:46:24 +02:00
|
|
|
handleCreatePostClick = (collectionName) => {
|
2016-09-15 18:56:08 +02:00
|
|
|
const { onCreateEntryClick } = this.props;
|
|
|
|
if (onCreateEntryClick) {
|
|
|
|
onCreateEntryClick(collectionName);
|
|
|
|
}
|
2016-10-03 16:37:11 +02:00
|
|
|
};
|
2016-09-15 18:56:08 +02:00
|
|
|
|
2016-09-16 15:01:19 +02:00
|
|
|
handleCreateButtonClick = () => {
|
2016-09-15 18:56:08 +02:00
|
|
|
this.setState({
|
2016-10-11 10:46:24 +02:00
|
|
|
createMenuActive: true,
|
2016-09-15 18:56:08 +02:00
|
|
|
});
|
2016-10-03 16:37:11 +02:00
|
|
|
};
|
2016-09-15 18:56:08 +02:00
|
|
|
|
2016-09-16 15:01:19 +02:00
|
|
|
handleCreateMenuHide = () => {
|
2016-09-15 18:56:08 +02:00
|
|
|
this.setState({
|
2016-10-11 10:46:24 +02:00
|
|
|
createMenuActive: false,
|
2016-09-15 18:56:08 +02:00
|
|
|
});
|
2016-10-03 16:37:11 +02:00
|
|
|
};
|
2016-09-15 18:56:08 +02:00
|
|
|
|
|
|
|
render() {
|
2016-09-16 15:01:19 +02:00
|
|
|
const {
|
|
|
|
collections,
|
|
|
|
commands,
|
|
|
|
defaultCommands,
|
|
|
|
runCommand,
|
2016-10-11 10:46:24 +02:00
|
|
|
toggleNavDrawer,
|
2016-09-16 15:01:19 +02:00
|
|
|
} = this.props;
|
2016-09-15 18:56:08 +02:00
|
|
|
const { createMenuActive } = this.state;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<AppBar
|
2016-10-03 16:57:48 +02:00
|
|
|
fixed
|
|
|
|
theme={styles}
|
2016-10-11 10:41:51 +02:00
|
|
|
leftIcon="menu"
|
|
|
|
rightIcon="create"
|
|
|
|
onLeftIconClick={toggleNavDrawer}
|
|
|
|
onRightIconClick={this.handleCreateButtonClick}
|
2016-09-15 18:56:08 +02:00
|
|
|
>
|
|
|
|
<IndexLink to="/">
|
|
|
|
Dashboard
|
|
|
|
</IndexLink>
|
2016-10-06 15:13:31 +02:00
|
|
|
|
2016-09-15 18:56:08 +02:00
|
|
|
<FindBar
|
2016-10-03 16:57:48 +02:00
|
|
|
commands={commands}
|
|
|
|
defaultCommands={defaultCommands}
|
|
|
|
runCommand={runCommand}
|
2016-09-15 18:56:08 +02:00
|
|
|
/>
|
2016-10-05 18:55:35 +02:00
|
|
|
<Menu
|
2016-10-11 10:41:51 +02:00
|
|
|
active={createMenuActive}
|
|
|
|
position="topRight"
|
|
|
|
onHide={this.handleCreateMenuHide}
|
2016-09-15 18:56:08 +02:00
|
|
|
>
|
2016-10-05 18:55:35 +02:00
|
|
|
{
|
|
|
|
collections.valueSeq().map(collection =>
|
|
|
|
<MenuItem
|
2016-10-11 10:41:51 +02:00
|
|
|
key={collection.get('name')}
|
|
|
|
value={collection.get('name')}
|
2016-10-11 10:46:24 +02:00
|
|
|
onClick={this.handleCreatePostClick.bind(this, collection.get('name'))} // eslint-disable-line
|
2016-10-11 10:41:51 +02:00
|
|
|
caption={pluralize(collection.get('label'), 1)}
|
2016-10-05 18:55:35 +02:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</Menu>
|
2016-09-15 18:56:08 +02:00
|
|
|
</AppBar>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|