update workflow

This commit is contained in:
Tom Moor committed 2020-08-08 00:42:21 -07:00
1 parent f88d2e8acc
commit 399507d441
5 files changed
+26 -33

No files matched your search

+2 -29
View File
@@ -1,13 +1,9 @@
// @flow
import * as React from "react";
import { observable } from "mobx";
import { observer, inject } from "mobx-react";
import { Redirect } from "react-router-dom";
import { DocumentIcon } from "outline-icons";
import styled from "styled-components";
import DocumentsStore from "stores/DocumentsStore";
import { newDocumentUrl } from "utils/routeHelpers";
import Document from "models/Document";
import Button from "components/Button";
import { DropdownMenu, DropdownMenuItem } from "components/DropdownMenu";
@@ -19,27 +15,8 @@ type Props = {
@observer
class TemplatesMenu extends React.Component<Props> {
@observable redirectTo: ?string;
componentDidUpdate() {
this.redirectTo = undefined;
}
handleNewDocument = (
collectionId: string,
options?: {
templateId?: string,
parentDocumentId?: string,
template?: boolean,
}
) => {
this.redirectTo = newDocumentUrl(collectionId, options);
};
render() {
if (this.redirectTo) return <Redirect to={this.redirectTo} push />;
const { collection, documents, document, label, ...rest } = this.props;
const { documents, document, ...rest } = this.props;
const templates = documents.templatesInCollection(document.collectionId);
return (
@@ -55,11 +32,7 @@ class TemplatesMenu extends React.Component<Props> {
{templates.map(template => (
<DropdownMenuItem
key={template.id}
onClick={() =>
this.handleNewDocument(document.collectionId, {
templateId: template.id,
})
}
onClick={() => document.updateFromTemplate(template)}
>
<DocumentIcon />
<div>
+10
View File
@@ -19,6 +19,7 @@ type SaveOptions = {
export default class Document extends BaseModel {
@observable isSaving: boolean = false;
@observable embedsDisabled: boolean = false;
@observable injectTemplate: boolean = false;
store: DocumentsStore;
collaborators: User[];
@@ -205,6 +206,14 @@ export default class Document extends BaseModel {
return this.store.templatize(this.id);
};
@action
updateFromTemplate = async (template: Document) => {
this.templateId = template.id;
this.title = template.title;
this.text = template.text;
this.injectTemplate = true;
};
@action
save = async (options: SaveOptions) => {
if (this.isSaving) return this;
@@ -228,6 +237,7 @@ export default class Document extends BaseModel {
id: this.id,
title: this.title,
text: this.text,
templateId: this.templateId,
lastRevision: options.lastRevision,
...options,
});
+9 -3
View File
@@ -69,8 +69,6 @@ type Props = {
@observer
class DocumentScene extends React.Component<Props> {
@observable editor: ?any;
getEditorText: () => string = () => this.props.document.text;
@observable editorComponent = EditorImport;
@observable isUploading: boolean = false;
@observable isSaving: boolean = false;
@@ -80,6 +78,7 @@ class DocumentScene extends React.Component<Props> {
@observable moveModalOpen: boolean = false;
@observable lastRevision: number;
@observable title: string;
getEditorText: () => string = () => this.props.document.text;
constructor(props) {
super();
@@ -115,6 +114,12 @@ class DocumentScene extends React.Component<Props> {
}
}
if (document.injectTemplate) {
this.isDirty = true;
this.title = document.title;
document.injectTemplate = false;
}
this.updateBackground();
}
@@ -343,6 +348,7 @@ class DocumentScene extends React.Component<Props> {
}
const value = revision ? revision.text : document.text;
const injectTemplate = document.injectTemplate;
const disableEmbeds =
(team && team.documentEmbeds === false) || document.embedsDisabled;
@@ -448,7 +454,7 @@ class DocumentScene extends React.Component<Props> {
isShare={isShare}
isDraft={document.isDraft}
template={document.isTemplate}
key={disableEmbeds ? "embeds-disabled" : "embeds-enabled"}
key={[injectTemplate, disableEmbeds].join("-")}
title={revision ? revision.title : this.title}
document={document}
value={readOnly ? value : undefined}
+3 -1
View File
@@ -134,6 +134,7 @@ class Header extends React.Component<Props> {
const share = shares.getByDocumentId(document.id);
const isPubliclyShared = share && share.published;
const isNew = document.isNew;
const isTemplate = document.isTemplate;
const can = policies.abilities(document.id);
const canShareDocuments = auth.team && auth.team.sharing && can.share;
@@ -207,7 +208,8 @@ class Header extends React.Component<Props> {
/>
</Fade>
{isEditing &&
!isTemplate && (
!isTemplate &&
isNew && (
<Action>
<Fade>
<TemplatesMenu document={document} />
+2
View File
@@ -835,6 +835,7 @@ router.post("documents.update", auth(), async ctx => {
autosave,
done,
lastRevision,
templateId,
append,
} = ctx.body;
const editorVersion = ctx.headers["x-editor-version"];
@@ -854,6 +855,7 @@ router.post("documents.update", auth(), async ctx => {
// Update document
if (title) document.title = title;
if (editorVersion) document.editorVersion = editorVersion;
if (templateId) document.templateId = templateId;
if (append) {
document.text += text;