diff --git a/packages/netlify-cms-core/src/components/Editor/Editor.js b/packages/netlify-cms-core/src/components/Editor/Editor.js index 907f7d38..6dc5e8c1 100644 --- a/packages/netlify-cms-core/src/components/Editor/Editor.js +++ b/packages/netlify-cms-core/src/components/Editor/Editor.js @@ -368,6 +368,7 @@ export class Editor extends React.Component { draftKey, slug, t, + editorBackLink, } = this.props; const isPublished = !newEntry && !unpublishedEntry; @@ -416,6 +417,7 @@ export class Editor extends React.Component { onLogoutClick={logoutUser} deployPreview={deployPreview} loadDeployPreview={opts => loadDeployPreview(collection, slug, entry, isPublished, opts)} + editorBackLink={editorBackLink} /> ); } @@ -442,6 +444,13 @@ function mapStateToProps(state, ownProps) { const deployPreview = selectDeployPreview(state, collectionName, slug); const localBackup = entryDraft.get('localBackup'); const draftKey = entryDraft.get('key'); + let editorBackLink = `/collections/${collectionName}`; + if (collection.has('nested') && slug) { + const pathParts = slug.split('/'); + if (pathParts.length > 2) { + editorBackLink = `${editorBackLink}/filter/${pathParts.slice(0, -2).join('/')}`; + } + } return { collection, @@ -464,6 +473,7 @@ function mapStateToProps(state, ownProps) { draftKey, publishedEntry, unPublishedEntry, + editorBackLink, }; } diff --git a/packages/netlify-cms-core/src/components/Editor/EditorInterface.js b/packages/netlify-cms-core/src/components/Editor/EditorInterface.js index 78347804..53bab723 100644 --- a/packages/netlify-cms-core/src/components/Editor/EditorInterface.js +++ b/packages/netlify-cms-core/src/components/Editor/EditorInterface.js @@ -185,6 +185,7 @@ class EditorInterface extends Component { loadDeployPreview, deployPreview, draftKey, + editorBackLink, } = this.props; const { previewVisible, scrollSyncEnabled, showEventBlocker } = this.state; @@ -263,6 +264,7 @@ class EditorInterface extends Component { onLogoutClick={onLogoutClick} loadDeployPreview={loadDeployPreview} deployPreview={deployPreview} + editorBackLink={editorBackLink} /> diff --git a/packages/netlify-cms-core/src/components/Editor/EditorToolbar.js b/packages/netlify-cms-core/src/components/Editor/EditorToolbar.js index 7239bd82..08e8dfec 100644 --- a/packages/netlify-cms-core/src/components/Editor/EditorToolbar.js +++ b/packages/netlify-cms-core/src/components/Editor/EditorToolbar.js @@ -5,7 +5,7 @@ import { css } from '@emotion/core'; import styled from '@emotion/styled'; import { translate } from 'react-polyglot'; import { Map } from 'immutable'; -import history from 'Routing/history'; +import { Link } from 'react-router-dom'; import { Icon, Dropdown, @@ -80,7 +80,7 @@ const ToolbarSubSectionLast = styled(ToolbarSubSectionFirst)` justify-content: flex-end; `; -const ToolbarSectionBackLink = styled.a` +const ToolbarSectionBackLink = styled(Link)` ${styles.toolbarSection}; border-right-width: 1px; font-weight: normal; @@ -247,6 +247,7 @@ class EditorToolbar extends React.Component { deployPreview: ImmutablePropTypes.map, loadDeployPreview: PropTypes.func.isRequired, t: PropTypes.func.isRequired, + editorBackLink: PropTypes.string.isRequired, }; componentDidMount() { @@ -564,19 +565,20 @@ class EditorToolbar extends React.Component { }; render() { - const { user, hasChanged, displayUrl, collection, hasWorkflow, onLogoutClick, t } = this.props; + const { + user, + hasChanged, + displayUrl, + collection, + hasWorkflow, + onLogoutClick, + t, + editorBackLink, + } = this.props; return ( - { - if (history.length > 2) { - history.goBack(); - } else { - history.push(`/collections/${collection.get('name')}`); - } - }} - > +