DocumentScene improvements
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { toJS } from 'mobx';
|
import { toJS } from 'mobx';
|
||||||
import _isEqual from 'lodash/isEqual';
|
import { Link, browserHistory } from 'react-router';
|
||||||
import { Link } from 'react-router';
|
|
||||||
import { observer } from 'mobx-react';
|
import { observer } from 'mobx-react';
|
||||||
|
|
||||||
import store from './DocumentSceneStore';
|
import store from './DocumentSceneStore';
|
||||||
@@ -52,6 +51,11 @@ class DocumentScene extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onEdit = () => {
|
||||||
|
const url = `/documents/${store.document.id}/edit`;
|
||||||
|
browserHistory.push(url);
|
||||||
|
}
|
||||||
|
|
||||||
onDelete = () => {
|
onDelete = () => {
|
||||||
if (confirm("Are you sure you want to delete this document?")) {
|
if (confirm("Are you sure you want to delete this document?")) {
|
||||||
store.deleteDocument();
|
store.deleteDocument();
|
||||||
@@ -67,14 +71,13 @@ class DocumentScene extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleChange = (tree) => {
|
handleChange = (tree) => {
|
||||||
// Only update when tree changes, otherwise link clicks toggle tree handleChanges changes
|
|
||||||
if (!_isEqual(toJS(tree), toJS(store.document.atlas.navigationTree))) {
|
|
||||||
store.updateNavigationTree(tree);
|
store.updateNavigationTree(tree);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const doc = store.document;
|
const doc = store.document;
|
||||||
|
const allowDelete = doc && doc.atlas.type === 'atlas' &&
|
||||||
|
doc.id !== doc.atlas.navigationTree.id;
|
||||||
let title;
|
let title;
|
||||||
let titleText;
|
let titleText;
|
||||||
let actions;
|
let actions;
|
||||||
@@ -86,11 +89,9 @@ class DocumentScene extends React.Component {
|
|||||||
<Link to={ `/documents/${doc.id}/new` }>New document</Link>
|
<Link to={ `/documents/${doc.id}/new` }>New document</Link>
|
||||||
</HeaderAction>
|
</HeaderAction>
|
||||||
) : null }
|
) : null }
|
||||||
<HeaderAction>
|
|
||||||
<Link to={ `/documents/${doc.id}/edit` }>Edit</Link>
|
|
||||||
</HeaderAction>
|
|
||||||
<DropdownMenu label="More">
|
<DropdownMenu label="More">
|
||||||
<MenuItem onClick={ this.onDelete }>Delete</MenuItem>
|
<MenuItem onClick={ this.onEdit }>Edit</MenuItem>
|
||||||
|
{ allowDelete && <MenuItem onClick={ this.onDelete }>Delete</MenuItem> }
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import _isEqual from 'lodash/isEqual';
|
||||||
import { observable, action, computed } from 'mobx';
|
import { observable, action, computed } from 'mobx';
|
||||||
import { client } from 'utils/ApiClient';
|
import { client } from 'utils/ApiClient';
|
||||||
import { browserHistory } from 'react-router';
|
import { browserHistory } from 'react-router';
|
||||||
@@ -44,6 +45,11 @@ const store = new class DocumentSceneStore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@action updateNavigationTree = async (tree) => {
|
@action updateNavigationTree = async (tree) => {
|
||||||
|
// Only update when tree changes
|
||||||
|
if (_isEqual(toJS(tree), toJS(this.document.atlas.navigationTree))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
this.isFetching = true;
|
this.isFetching = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user