chore: update and document edit route (#2619)
* chore: update and document edit route * fix formatting
This commit is contained in:
@ -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}
|
||||
|
Reference in New Issue
Block a user