feat: Add ability to create docs from link editor (#1303)
* feat: Add ability to create docs from link editor * fix: Handling of paste and click events * fix: Filter untitled documents from search results * refactor: Move onCreateLink to DataLoader * bump rme
This commit is contained in:
parent
d25a9d56dc
commit
933bbdfb84
@ -1,5 +1,6 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
import invariant from 'invariant';
|
||||||
import { withRouter } from 'react-router-dom';
|
import { withRouter } from 'react-router-dom';
|
||||||
import type { Location, RouterHistory } from 'react-router-dom';
|
import type { Location, RouterHistory } from 'react-router-dom';
|
||||||
import { observable } from 'mobx';
|
import { observable } from 'mobx';
|
||||||
@ -73,12 +74,28 @@ class DataLoader extends React.Component<Props> {
|
|||||||
onSearchLink = async (term: string) => {
|
onSearchLink = async (term: string) => {
|
||||||
const results = await this.props.documents.search(term);
|
const results = await this.props.documents.search(term);
|
||||||
|
|
||||||
return results.map((result, index) => ({
|
return results
|
||||||
|
.filter(result => result.document.title)
|
||||||
|
.map((result, index) => ({
|
||||||
title: result.document.title,
|
title: result.document.title,
|
||||||
url: result.document.url,
|
url: result.document.url,
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onCreateLink = async (title: string) => {
|
||||||
|
const document = this.document;
|
||||||
|
invariant(document, 'document must be loaded to create link');
|
||||||
|
|
||||||
|
const newDocument = await this.props.documents.create({
|
||||||
|
collectionId: document.collectionId,
|
||||||
|
parentDocumentId: document.parentDocumentId,
|
||||||
|
title,
|
||||||
|
text: '',
|
||||||
|
});
|
||||||
|
|
||||||
|
return newDocument.url;
|
||||||
|
};
|
||||||
|
|
||||||
loadRevision = async () => {
|
loadRevision = async () => {
|
||||||
const { documentSlug, revisionId } = this.props.match.params;
|
const { documentSlug, revisionId } = this.props.match.params;
|
||||||
|
|
||||||
@ -165,6 +182,7 @@ class DataLoader extends React.Component<Props> {
|
|||||||
location={location}
|
location={location}
|
||||||
readOnly={!this.isEditing}
|
readOnly={!this.isEditing}
|
||||||
onSearchLink={this.onSearchLink}
|
onSearchLink={this.onSearchLink}
|
||||||
|
onCreateLink={this.onCreateLink}
|
||||||
/>
|
/>
|
||||||
</SocketPresence>
|
</SocketPresence>
|
||||||
);
|
);
|
||||||
|
@ -58,7 +58,8 @@ type Props = {
|
|||||||
document: Document,
|
document: Document,
|
||||||
revision: Revision,
|
revision: Revision,
|
||||||
readOnly: boolean,
|
readOnly: boolean,
|
||||||
onSearchLink: (term: string) => mixed,
|
onCreateLink: (title: string) => string,
|
||||||
|
onSearchLink: (term: string) => any,
|
||||||
theme: Object,
|
theme: Object,
|
||||||
auth: AuthStore,
|
auth: AuthStore,
|
||||||
ui: UiStore,
|
ui: UiStore,
|
||||||
@ -435,6 +436,7 @@ class DocumentScene extends React.Component<Props> {
|
|||||||
onImageUploadStart={this.onImageUploadStart}
|
onImageUploadStart={this.onImageUploadStart}
|
||||||
onImageUploadStop={this.onImageUploadStop}
|
onImageUploadStop={this.onImageUploadStop}
|
||||||
onSearchLink={this.props.onSearchLink}
|
onSearchLink={this.props.onSearchLink}
|
||||||
|
onCreateLink={this.props.onCreateLink}
|
||||||
onChangeTitle={this.onChangeTitle}
|
onChangeTitle={this.onChangeTitle}
|
||||||
onChange={this.onChange}
|
onChange={this.onChange}
|
||||||
onSave={this.onSave}
|
onSave={this.onSave}
|
||||||
@ -491,7 +493,5 @@ const MaxWidth = styled(Flex)`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export default withRouter(
|
export default withRouter(
|
||||||
inject('ui', 'auth', 'documents', 'policies', 'revisions')(
|
inject('ui', 'auth', 'policies', 'revisions')(withTheme(DocumentScene))
|
||||||
withTheme(DocumentScene)
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
@ -141,7 +141,7 @@
|
|||||||
"react-portal": "^4.0.0",
|
"react-portal": "^4.0.0",
|
||||||
"react-router-dom": "^5.1.2",
|
"react-router-dom": "^5.1.2",
|
||||||
"react-waypoint": "^9.0.2",
|
"react-waypoint": "^9.0.2",
|
||||||
"rich-markdown-editor": "^10.0.3-1",
|
"rich-markdown-editor": "^10.1.0-3",
|
||||||
"sequelize": "^5.21.1",
|
"sequelize": "^5.21.1",
|
||||||
"sequelize-cli": "^5.5.0",
|
"sequelize-cli": "^5.5.0",
|
||||||
"sequelize-encrypted": "^0.1.0",
|
"sequelize-encrypted": "^0.1.0",
|
||||||
|
@ -8595,10 +8595,10 @@ retry-as-promised@^3.2.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
any-promise "^1.3.0"
|
any-promise "^1.3.0"
|
||||||
|
|
||||||
rich-markdown-editor@^10.0.3-1:
|
rich-markdown-editor@^10.1.0-3:
|
||||||
version "10.0.3-1"
|
version "10.1.0-3"
|
||||||
resolved "https://registry.yarnpkg.com/rich-markdown-editor/-/rich-markdown-editor-10.0.3-1.tgz#a0a07900d2c4c37b4f017382c22a9937f7e90e2a"
|
resolved "https://registry.yarnpkg.com/rich-markdown-editor/-/rich-markdown-editor-10.1.0-3.tgz#e11cfb073419c9f8275d10d2d826e1421c8873c3"
|
||||||
integrity sha512-p59ydbcmQbz2coeDa1LMnZcm0UtAG3d5FExbmLFue85mBZKqrMyQMo0LokW7MZoXTw0KeIvUeFM8inKYc8qdaA==
|
integrity sha512-kFw8l/urOHbdjrMGKO/vp+46CY1hGy983fwJz8ZmiIo5LNRby2Mkgt7rYdiysujNclKJ9hVqcawxh3aK8GN7Xw==
|
||||||
dependencies:
|
dependencies:
|
||||||
copy-to-clipboard "^3.0.8"
|
copy-to-clipboard "^3.0.8"
|
||||||
lodash "^4.17.11"
|
lodash "^4.17.11"
|
||||||
|
Reference in New Issue
Block a user