This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
outline/app/menus/NewChildDocumentMenu.js

58 lines
1.5 KiB
JavaScript
Raw Normal View History

// @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';
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
class NewChildDocumentMenu extends React.Component<Props> {
2019-01-19 08:23:39 +00:00
@observable redirectTo: ?string;
componentDidUpdate() {
this.redirectTo = undefined;
}
handleNewDocument = () => {
2019-01-19 08:23:39 +00:00
this.redirectTo = newDocumentUrl(this.props.document.collection);
};
handleNewChild = () => {
2019-01-19 08:23:39 +00:00
const { document } = this.props;
this.redirectTo = `${document.collection.url}/new?parentDocument=${
document.id
}`;
};
render() {
if (this.redirectTo) return <Redirect to={this.redirectTo} push />;
2019-01-19 08:23:39 +00:00
const { label, document, ...rest } = this.props;
const { collection } = document;
return (
<DropdownMenu label={label || <MoreIcon />} {...rest}>
<DropdownMenuItem onClick={this.handleNewDocument}>
<span>
New document in <strong>{collection.name}</strong>
</span>
</DropdownMenuItem>
<DropdownMenuItem onClick={this.handleNewChild}>
New child document
</DropdownMenuItem>
</DropdownMenu>
);
}
}
2019-01-19 08:23:39 +00:00
export default NewChildDocumentMenu;