fix: Nested document menu item appears where it shouldnt (#1193)

This commit is contained in:
Tom Moor
2020-02-26 21:10:10 -08:00
committed by GitHub
parent 148affb52e
commit d06ec5ce0c
4 changed files with 33 additions and 11 deletions

View File

@@ -185,7 +185,7 @@ class DocumentMenu extends React.Component<Props> {
</DropdownMenuItem>
</React.Fragment>
)}
{can.update && (
{can.createChildDocument && (
<DropdownMenuItem
onClick={this.handleNewChild}
title="Create a nested document inside the current document"

View File

@@ -65,7 +65,7 @@ type Props = {
@observer
class DocumentScene extends React.Component<Props> {
getEditorText: () => string;
getEditorText: () => string = () => this.props.document.text;
@observable editorComponent = EditorImport;
@observable isUploading: boolean = false;
@@ -80,6 +80,10 @@ class DocumentScene extends React.Component<Props> {
this.loadEditor();
}
componentDidMount() {
this.updateIsDirty();
}
@keydown('m')
goToMove(ev) {
ev.preventDefault();
@@ -179,14 +183,16 @@ class DocumentScene extends React.Component<Props> {
this.onSave({ done: false, autosave: true });
}, AUTOSAVE_DELAY);
updateIsDirty = debounce(() => {
updateIsDirty = () => {
const { document } = this.props;
const editorText = this.getEditorText().trim();
// a single hash is a doc with just an empty title
this.isEmpty = editorText === '#';
this.isEmpty = !editorText || editorText === '#';
this.isDirty = !!document && editorText !== document.text.trim();
}, IS_DIRTY_DELAY);
};
updateIsDirtyDebounced = debounce(this.updateIsDirty, IS_DIRTY_DELAY);
onImageUploadStart = () => {
this.isUploading = true;
@@ -198,7 +204,7 @@ class DocumentScene extends React.Component<Props> {
onChange = getEditorText => {
this.getEditorText = getEditorText;
this.updateIsDirty();
this.updateIsDirtyDebounced();
this.autosave();
};

View File

@@ -230,7 +230,7 @@ class Header extends React.Component<Props> {
</Action>
)}
{canEdit &&
!isDraft && (
can.createChildDocument && (
<Action>
<NewChildDocumentMenu
document={document}

View File

@@ -43,26 +43,42 @@ allow(User, ['star', 'unstar'], Document, (user, document) => {
});
allow(User, 'update', Document, (user, document) => {
if (document.archivedAt) return false;
if (document.deletedAt) return false;
invariant(
document.collection,
'collection is missing, did you forget to include in the query scope?'
);
if (cannot(user, 'update', document.collection)) return false;
return user.teamId === document.teamId;
});
allow(User, 'createChildDocument', Document, (user, document) => {
if (document.archivedAt) return false;
if (document.deletedAt) return false;
if (document.archivedAt) return false;
if (!document.publishedAt) return false;
invariant(
document.collection,
'collection is missing, did you forget to include in the query scope?'
);
if (cannot(user, 'update', document.collection)) return false;
return user.teamId === document.teamId;
});
allow(User, ['move', 'pin', 'unpin'], Document, (user, document) => {
if (document.archivedAt) return false;
if (document.deletedAt) return false;
if (!document.publishedAt) return false;
invariant(
document.collection,
'collection is missing, did you forget to include in the query scope?'
);
if (cannot(user, 'update', document.collection)) return false;
if (document.archivedAt) return false;
if (document.deletedAt) return false;
if (!document.publishedAt) return false;
return user.teamId === document.teamId;
});