Fixes: No redirect after doc import
This commit is contained in:
@ -2,7 +2,7 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { observable } from 'mobx';
|
import { observable } from 'mobx';
|
||||||
import { observer, inject } from 'mobx-react';
|
import { observer, inject } from 'mobx-react';
|
||||||
import { Redirect } from 'react-router-dom';
|
import { withRouter } from 'react-router-dom';
|
||||||
import { createGlobalStyle } from 'styled-components';
|
import { createGlobalStyle } from 'styled-components';
|
||||||
import invariant from 'invariant';
|
import invariant from 'invariant';
|
||||||
import importFile from 'utils/importFile';
|
import importFile from 'utils/importFile';
|
||||||
@ -10,6 +10,8 @@ import Dropzone from 'react-dropzone';
|
|||||||
import DocumentsStore from 'stores/DocumentsStore';
|
import DocumentsStore from 'stores/DocumentsStore';
|
||||||
import LoadingIndicator from 'components/LoadingIndicator';
|
import LoadingIndicator from 'components/LoadingIndicator';
|
||||||
|
|
||||||
|
const EMPTY_OBJECT = {};
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
children: React.Node,
|
children: React.Node,
|
||||||
collectionId: string,
|
collectionId: string,
|
||||||
@ -18,6 +20,7 @@ type Props = {
|
|||||||
rejectClassName?: string,
|
rejectClassName?: string,
|
||||||
documents: DocumentsStore,
|
documents: DocumentsStore,
|
||||||
disabled: boolean,
|
disabled: boolean,
|
||||||
|
history: Object,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const GlobalStyles = createGlobalStyle`
|
export const GlobalStyles = createGlobalStyle`
|
||||||
@ -35,7 +38,6 @@ export const GlobalStyles = createGlobalStyle`
|
|||||||
@observer
|
@observer
|
||||||
class DropToImport extends React.Component<Props> {
|
class DropToImport extends React.Component<Props> {
|
||||||
@observable isImporting: boolean = false;
|
@observable isImporting: boolean = false;
|
||||||
@observable redirectTo: ?string;
|
|
||||||
|
|
||||||
onDropAccepted = async (files = []) => {
|
onDropAccepted = async (files = []) => {
|
||||||
this.isImporting = true;
|
this.isImporting = true;
|
||||||
@ -60,7 +62,7 @@ class DropToImport extends React.Component<Props> {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (redirect) {
|
if (redirect) {
|
||||||
this.redirectTo = doc.url;
|
this.props.history.push(doc.url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@ -77,14 +79,13 @@ class DropToImport extends React.Component<Props> {
|
|||||||
...rest
|
...rest
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
if (this.redirectTo) return <Redirect to={this.redirectTo} push />;
|
|
||||||
if (this.props.disabled) return this.props.children;
|
if (this.props.disabled) return this.props.children;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dropzone
|
<Dropzone
|
||||||
accept="text/markdown, text/plain"
|
accept="text/markdown, text/plain"
|
||||||
onDropAccepted={this.onDropAccepted}
|
onDropAccepted={this.onDropAccepted}
|
||||||
style={{}}
|
style={EMPTY_OBJECT}
|
||||||
disableClick
|
disableClick
|
||||||
disablePreview
|
disablePreview
|
||||||
multiple
|
multiple
|
||||||
@ -97,4 +98,4 @@ class DropToImport extends React.Component<Props> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default inject('documents')(DropToImport);
|
export default inject('documents')(withRouter(DropToImport));
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { observable } from 'mobx';
|
import { observable } from 'mobx';
|
||||||
import { inject, observer } from 'mobx-react';
|
import { inject, observer } from 'mobx-react';
|
||||||
import { Redirect } from 'react-router-dom';
|
import { withRouter } from 'react-router-dom';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import { MoreIcon } from 'outline-icons';
|
import { MoreIcon } from 'outline-icons';
|
||||||
import Modal from 'components/Modal';
|
import Modal from 'components/Modal';
|
||||||
@ -22,6 +22,7 @@ type Props = {
|
|||||||
ui: UiStore,
|
ui: UiStore,
|
||||||
documents: DocumentsStore,
|
documents: DocumentsStore,
|
||||||
collection: Collection,
|
collection: Collection,
|
||||||
|
history: Object,
|
||||||
};
|
};
|
||||||
|
|
||||||
@observer
|
@observer
|
||||||
@ -30,14 +31,10 @@ class CollectionMenu extends React.Component<Props> {
|
|||||||
@observable permissionsModalOpen: boolean = false;
|
@observable permissionsModalOpen: boolean = false;
|
||||||
@observable redirectTo: ?string;
|
@observable redirectTo: ?string;
|
||||||
|
|
||||||
componentDidUpdate() {
|
|
||||||
this.redirectTo = undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
onNewDocument = (ev: SyntheticEvent<*>) => {
|
onNewDocument = (ev: SyntheticEvent<*>) => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
const { collection } = this.props;
|
const { collection } = this.props;
|
||||||
this.redirectTo = `${collection.url}/new`;
|
this.props.history.push(`${collection.url}/new`);
|
||||||
};
|
};
|
||||||
|
|
||||||
onImportDocument = (ev: SyntheticEvent<*>) => {
|
onImportDocument = (ev: SyntheticEvent<*>) => {
|
||||||
@ -56,7 +53,7 @@ class CollectionMenu extends React.Component<Props> {
|
|||||||
documents: this.props.documents,
|
documents: this.props.documents,
|
||||||
collectionId: this.props.collection.id,
|
collectionId: this.props.collection.id,
|
||||||
});
|
});
|
||||||
this.redirectTo = document.url;
|
this.props.history.push(document.url);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.props.ui.showToast(err.message);
|
this.props.ui.showToast(err.message);
|
||||||
}
|
}
|
||||||
@ -90,8 +87,6 @@ class CollectionMenu extends React.Component<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (this.redirectTo) return <Redirect to={this.redirectTo} push />;
|
|
||||||
|
|
||||||
const { collection, label, onOpen, onClose } = this.props;
|
const { collection, label, onOpen, onClose } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -149,4 +144,4 @@ const HiddenInput = styled.input`
|
|||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export default inject('ui', 'documents')(CollectionMenu);
|
export default inject('ui', 'documents')(withRouter(CollectionMenu));
|
||||||
|
@ -27,9 +27,9 @@ const importFile = async ({
|
|||||||
|
|
||||||
if (documentId) data.parentDocument = documentId;
|
if (documentId) data.parentDocument = documentId;
|
||||||
|
|
||||||
const document = new Document(data, documents);
|
let document = new Document(data, documents);
|
||||||
try {
|
try {
|
||||||
await document.save({ publish: true });
|
document = await document.save({ publish: true });
|
||||||
resolve(document);
|
resolve(document);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
reject(err);
|
reject(err);
|
||||||
|
Reference in New Issue
Block a user