chore: update and document edit route (#2619)

* chore: update and document edit route

* fix formatting
This commit is contained in:
Shawn Erquhart
2019-09-03 20:37:31 -04:00
committed by GitHub
parent 211577e263
commit 1aff33e158
2 changed files with 28 additions and 33 deletions

View File

@ -23,8 +23,6 @@ import Workflow from 'Workflow/Workflow';
import Editor from 'Editor/Editor';
import NotFoundPage from './NotFoundPage';
import Header from './Header';
import { selectEntrySlug } from 'Reducers/collections';
import { FILES, FOLDER } from 'Constants/collectionTypes';
TopBarProgress.config({
barColors: {
@ -160,36 +158,6 @@ class App extends React.Component {
const defaultPath = `/collections/${collections.first().get('name')}`;
const hasWorkflow = publishMode === EDITORIAL_WORKFLOW;
const getCustomEditRoute = props => {
const { folder, filename } = props.match.params;
let redirect = null;
const collections = config.get('collections');
const setTypeOnCollection = collection => {
if (collection.has('folder')) return collection.set('type', FOLDER);
if (collection.has('files')) return collection.set('type', FILES);
};
collections.forEach(collection => {
const typedCollection = setTypeOnCollection(collection);
if (typedCollection.has('files')) {
const files = typedCollection.get('files');
files.forEach(file => {
if (file.get('file').includes(`${folder}/${filename}`)) {
redirect = `/collections/${filename}`;
}
});
} else if (typedCollection.has('folder') && folder === typedCollection.get('folder')) {
const slug = selectEntrySlug(typedCollection, filename);
redirect = `/collections/${typedCollection.get('name')}/entries/${slug}`;
}
});
if (redirect !== null) {
return <Redirect to={redirect} />;
}
return <NotFoundPage />;
};
return (
<>
<Notifs CustomComponent={Toast} />
@ -226,7 +194,13 @@ class App extends React.Component {
path="/search/:searchTerm"
render={props => <Collection {...props} isSearchResults />}
/>
<Route path="/edit/:folder/:filename" render={props => getCustomEditRoute(props)} />
<Route
path="/edit/:collectionName/:entryName"
render={({ match }) => {
const { collectionName, entryName } = match.params;
return <Redirect to={`/collections/${collectionName}/entries/${entryName}`} />;
}}
/>
<Route component={NotFoundPage} />
</Switch>
{useMediaLibrary ? <MediaLibrary /> : null}