2018-08-08 05:08:44 +00:00
|
|
|
// @flow
|
|
|
|
import * as React from 'react';
|
2019-01-19 08:23:39 +00:00
|
|
|
import { Redirect } from 'react-router-dom';
|
|
|
|
import { observable } from 'mobx';
|
|
|
|
import { observer } from 'mobx-react';
|
2018-08-08 05:08:44 +00:00
|
|
|
import { MoreIcon } from 'outline-icons';
|
|
|
|
|
|
|
|
import { newDocumentUrl } from 'utils/routeHelpers';
|
|
|
|
import Document from 'models/Document';
|
|
|
|
import { DropdownMenu, DropdownMenuItem } from 'components/DropdownMenu';
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
label?: React.Node,
|
|
|
|
document: Document,
|
|
|
|
};
|
|
|
|
|
2019-01-19 08:23:39 +00:00
|
|
|
@observer
|
2018-08-08 05:08:44 +00:00
|
|
|
class NewChildDocumentMenu extends React.Component<Props> {
|
2019-01-19 08:23:39 +00:00
|
|
|
@observable redirectTo: ?string;
|
|
|
|
|
2018-08-08 05:08:44 +00:00
|
|
|
handleNewDocument = () => {
|
2019-01-19 08:23:39 +00:00
|
|
|
this.redirectTo = newDocumentUrl(this.props.document.collection);
|
2018-08-08 05:08:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
handleNewChild = () => {
|
2019-01-19 08:23:39 +00:00
|
|
|
const { document } = this.props;
|
|
|
|
this.redirectTo = `${document.collection.url}/new?parentDocument=${
|
|
|
|
document.id
|
|
|
|
}`;
|
2018-08-08 05:08:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2019-01-19 08:23:39 +00:00
|
|
|
if (this.redirectTo) return <Redirect to={this.redirectTo} />;
|
|
|
|
|
|
|
|
const { label, document, ...rest } = this.props;
|
2018-08-08 05:08:44 +00:00
|
|
|
const { collection } = document;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<DropdownMenu label={label || <MoreIcon />} {...rest}>
|
|
|
|
<DropdownMenuItem onClick={this.handleNewChild}>
|
|
|
|
New child document
|
|
|
|
</DropdownMenuItem>
|
|
|
|
<DropdownMenuItem onClick={this.handleNewDocument}>
|
|
|
|
<span>
|
|
|
|
New document in <strong>{collection.name}</strong>
|
|
|
|
</span>
|
|
|
|
</DropdownMenuItem>
|
|
|
|
</DropdownMenu>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-19 08:23:39 +00:00
|
|
|
export default NewChildDocumentMenu;
|