Base model refactor (#810)
* Big upgrades * WIP: Stash * Stash, 30 flow errors left * Downgrade mobx * WIP * When I understand the difference between class and instance methods * 💚 * Fixes: File import Model saving edge cases pinning and starring docs Collection editing Upgrade mobx devtools * Notification settings saving works * Disabled settings * Document mailer * Working notifications * Colletion created notification Ensure not notified for own actions * Tidy up * Document updated event only for document creation Add indexes Notification setting on user creation * Commentary * Fixed: Notification setting on signup * Fix document move / duplicate stale data Add BaseModel.refresh method * Fixes: Title in sidebar not updated after editing document * 💚 * Improve / restore error handling Better handle offline errors * 👕
This commit is contained in:
@@ -3,10 +3,9 @@ import * as React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { observable, computed } from 'mobx';
|
||||
import { observer, inject } from 'mobx-react';
|
||||
import { withRouter } from 'react-router-dom';
|
||||
import { Search } from 'js-search';
|
||||
import { first, last } from 'lodash';
|
||||
import ArrowKeyNavigation from 'boundless-arrow-key-navigation';
|
||||
import _ from 'lodash';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import Modal from 'components/Modal';
|
||||
@@ -20,11 +19,10 @@ import DocumentsStore from 'stores/DocumentsStore';
|
||||
import CollectionsStore, { type DocumentPath } from 'stores/CollectionsStore';
|
||||
|
||||
type Props = {
|
||||
match: Object,
|
||||
history: Object,
|
||||
document: Document,
|
||||
documents: DocumentsStore,
|
||||
collections: CollectionsStore,
|
||||
onRequestClose: *,
|
||||
};
|
||||
|
||||
@observer
|
||||
@@ -44,7 +42,7 @@ class DocumentMove extends React.Component<Props> {
|
||||
const indexeableDocuments = [];
|
||||
paths.forEach(path => {
|
||||
// TMP: For now, exclude paths to other collections
|
||||
if (_.first(path.path).id !== document.collection.id) return;
|
||||
if (first(path.path).id !== document.collection.id) return;
|
||||
|
||||
indexeableDocuments.push(path);
|
||||
});
|
||||
@@ -91,7 +89,7 @@ class DocumentMove extends React.Component<Props> {
|
||||
results = results.filter(
|
||||
result =>
|
||||
!result.path.map(doc => doc.id).includes(document.id) &&
|
||||
_.last(result.path.map(doc => doc.id)) !== document.parentDocumentId
|
||||
last(result.path.map(doc => doc.id)) !== document.parentDocumentId
|
||||
);
|
||||
|
||||
return results;
|
||||
@@ -108,12 +106,8 @@ class DocumentMove extends React.Component<Props> {
|
||||
}
|
||||
};
|
||||
|
||||
handleClose = () => {
|
||||
this.props.history.push(this.props.document.url);
|
||||
};
|
||||
|
||||
handleFilter = (e: SyntheticInputEvent<*>) => {
|
||||
this.searchTerm = e.target.value;
|
||||
handleFilter = (ev: SyntheticInputEvent<*>) => {
|
||||
this.searchTerm = ev.target.value;
|
||||
};
|
||||
|
||||
setFirstDocumentRef = ref => {
|
||||
@@ -123,16 +117,17 @@ class DocumentMove extends React.Component<Props> {
|
||||
renderPathToCurrentDocument() {
|
||||
const { collections, document } = this.props;
|
||||
const result = collections.getPathForDocument(document.id);
|
||||
|
||||
if (result) {
|
||||
return <PathToDocument result={result} />;
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const { document, collections } = this.props;
|
||||
const { document, collections, onRequestClose } = this.props;
|
||||
|
||||
return (
|
||||
<Modal isOpen onRequestClose={this.handleClose} title="Move document">
|
||||
<Modal isOpen onRequestClose={onRequestClose} title="Move document">
|
||||
{document &&
|
||||
collections.isLoaded && (
|
||||
<Flex column>
|
||||
@@ -166,7 +161,7 @@ class DocumentMove extends React.Component<Props> {
|
||||
ref={ref =>
|
||||
index === 0 && this.setFirstDocumentRef(ref)
|
||||
}
|
||||
onSuccess={this.handleClose}
|
||||
onSuccess={onRequestClose}
|
||||
/>
|
||||
))}
|
||||
</StyledArrowKeyNavigation>
|
||||
@@ -189,4 +184,4 @@ const StyledArrowKeyNavigation = styled(ArrowKeyNavigation)`
|
||||
flex: 1;
|
||||
`;
|
||||
|
||||
export default withRouter(inject('documents', 'collections')(DocumentMove));
|
||||
export default inject('documents', 'collections')(DocumentMove);
|
||||
|
||||
Reference in New Issue
Block a user