fix(editor): pass back link to editor toolbar (#4000)

This commit is contained in:
Erez Rokah 2020-07-09 18:26:55 +03:00 committed by GitHub
parent 100b0645a1
commit c3a680ff52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 12 deletions

View File

@ -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,
};
}

View File

@ -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}
/>
<Editor key={draftKey}>
<ViewControls>

View File

@ -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 (
<ToolbarContainer>
<ToolbarSectionBackLink
onClick={() => {
if (history.length > 2) {
history.goBack();
} else {
history.push(`/collections/${collection.get('name')}`);
}
}}
>
<ToolbarSectionBackLink to={editorBackLink}>
<BackArrow></BackArrow>
<div>
<BackCollection>