Handle formats better
This commit is contained in:
commit
42853f2af8
@ -3,7 +3,9 @@ import { EDITORIAL_WORKFLOW } from '../constants/publishModes';
|
|||||||
/*
|
/*
|
||||||
* Contant Declarations
|
* Contant Declarations
|
||||||
*/
|
*/
|
||||||
export const INIT = 'init';
|
export const UNPUBLISHED_ENTRY_REQUEST = 'UNPUBLISHED_ENTRY_REQUEST';
|
||||||
|
export const UNPUBLISHED_ENTRY_SUCCESS = 'UNPUBLISHED_ENTRY_SUCCESS';
|
||||||
|
|
||||||
export const UNPUBLISHED_ENTRIES_REQUEST = 'UNPUBLISHED_ENTRIES_REQUEST';
|
export const UNPUBLISHED_ENTRIES_REQUEST = 'UNPUBLISHED_ENTRIES_REQUEST';
|
||||||
export const UNPUBLISHED_ENTRIES_SUCCESS = 'UNPUBLISHED_ENTRIES_SUCCESS';
|
export const UNPUBLISHED_ENTRIES_SUCCESS = 'UNPUBLISHED_ENTRIES_SUCCESS';
|
||||||
export const UNPUBLISHED_ENTRIES_FAILURE = 'UNPUBLISHED_ENTRIES_FAILURE';
|
export const UNPUBLISHED_ENTRIES_FAILURE = 'UNPUBLISHED_ENTRIES_FAILURE';
|
||||||
@ -12,6 +14,21 @@ export const UNPUBLISHED_ENTRIES_FAILURE = 'UNPUBLISHED_ENTRIES_FAILURE';
|
|||||||
/*
|
/*
|
||||||
* Simple Action Creators (Internal)
|
* Simple Action Creators (Internal)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
function unpublishedEntryLoading(status, slug) {
|
||||||
|
return {
|
||||||
|
type: UNPUBLISHED_ENTRY_REQUEST,
|
||||||
|
payload: { status, slug }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function unpublishedEntryLoaded(status, entry) {
|
||||||
|
return {
|
||||||
|
type: UNPUBLISHED_ENTRY_SUCCESS,
|
||||||
|
payload: { status, entry }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function unpublishedEntriesLoading() {
|
function unpublishedEntriesLoading() {
|
||||||
return {
|
return {
|
||||||
type: UNPUBLISHED_ENTRIES_REQUEST
|
type: UNPUBLISHED_ENTRIES_REQUEST
|
||||||
@ -37,18 +54,19 @@ function unpublishedEntriesFailed(error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Exported simple Action Creators
|
* Exported Thunk Action Creators
|
||||||
*/
|
*/
|
||||||
export function init() {
|
|
||||||
return {
|
export function loadUnpublishedEntry(collection, status, slug) {
|
||||||
type: INIT
|
return (dispatch, getState) => {
|
||||||
|
const state = getState();
|
||||||
|
const backend = currentBackend(state.config);
|
||||||
|
dispatch(unpublishedEntryLoading(status, slug));
|
||||||
|
backend.unpublishedEntry(collection, slug)
|
||||||
|
.then((entry) => dispatch(unpublishedEntryLoaded(status, entry)));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Exported Thunk Action Creators
|
|
||||||
*/
|
|
||||||
export function loadUnpublishedEntries() {
|
export function loadUnpublishedEntries() {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
const state = getState();
|
const state = getState();
|
||||||
|
@ -83,6 +83,10 @@ class Backend {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unpublishedEntry(collection, slug) {
|
||||||
|
return this.implementation.unpublishedEntry(collection, slug).then(this.entryWithFormat(collection));
|
||||||
|
}
|
||||||
|
|
||||||
slugFormatter(template, entry) {
|
slugFormatter(template, entry) {
|
||||||
var date = new Date();
|
var date = new Date();
|
||||||
return template.replace(/\{\{([^\}]+)\}\}/g, function(_, name) {
|
return template.replace(/\{\{([^\}]+)\}\}/g, function(_, name) {
|
||||||
|
@ -90,4 +90,12 @@ export default class GitHub {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unpublishedEntry(collection, slug) {
|
||||||
|
return this.unpublishedEntries().then((response) => (
|
||||||
|
response.entries.filter((entry) => (
|
||||||
|
entry.metaData && entry.metaData.collection === collection.get('name') && entry.slug === slug
|
||||||
|
))[0]
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ export default class API {
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkMetadataRef() {
|
checkMetadataRef() {
|
||||||
return this.request(`${this.repoURL}/git/refs/meta/_netlify_cms?${Date.now()}`, {
|
return this.request(`${this.repoURL}/refs/meta/_netlify_cms?${Date.now()}`, {
|
||||||
cache: 'no-store',
|
cache: 'no-store',
|
||||||
})
|
})
|
||||||
.then(response => response.object)
|
.then(response => response.object)
|
||||||
@ -66,7 +66,7 @@ export default class API {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return this.uploadBlob(readme)
|
return this.uploadBlob(readme)
|
||||||
.then(item => this.request(`${this.repoURL}/git/trees`, {
|
.then(item => this.request(`${this.repoURL}/trees`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ tree: [{ path: 'README.md', mode: '100644', type: 'blob', sha: item.sha }] })
|
body: JSON.stringify({ tree: [{ path: 'README.md', mode: '100644', type: 'blob', sha: item.sha }] })
|
||||||
}))
|
}))
|
||||||
@ -173,7 +173,7 @@ export default class API {
|
|||||||
}
|
}
|
||||||
|
|
||||||
createRef(type, name, sha) {
|
createRef(type, name, sha) {
|
||||||
return this.request(`${this.repoURL}/git/refs`, {
|
return this.request(`${this.repoURL}/refs`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ ref: `refs/${type}/${name}`, sha }),
|
body: JSON.stringify({ ref: `refs/${type}/${name}`, sha }),
|
||||||
});
|
});
|
||||||
@ -184,7 +184,7 @@ export default class API {
|
|||||||
}
|
}
|
||||||
|
|
||||||
patchRef(type, name, sha) {
|
patchRef(type, name, sha) {
|
||||||
return this.request(`${this.repoURL}/git/refs/${type}/${name}`, {
|
return this.request(`${this.repoURL}/refs/${type}/${name}`, {
|
||||||
method: 'PATCH',
|
method: 'PATCH',
|
||||||
body: JSON.stringify({ sha })
|
body: JSON.stringify({ sha })
|
||||||
});
|
});
|
||||||
@ -195,7 +195,7 @@ export default class API {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getBranch() {
|
getBranch() {
|
||||||
return this.request(`${this.repoURL}/branches/${this.branch}`);
|
return this.request(`${this.repoURL}/refs/heads/${this.branch}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
createPR(title, head, base = 'master') {
|
createPR(title, head, base = 'master') {
|
||||||
@ -207,7 +207,7 @@ export default class API {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getTree(sha) {
|
getTree(sha) {
|
||||||
return sha ? this.request(`${this.repoURL}/git/trees/${sha}`) : Promise.resolve({ tree: [] });
|
return sha ? this.request(`${this.repoURL}/trees/${sha}`) : Promise.resolve({ tree: [] });
|
||||||
}
|
}
|
||||||
|
|
||||||
toBase64(str) {
|
toBase64(str) {
|
||||||
@ -220,7 +220,7 @@ export default class API {
|
|||||||
const content = item instanceof MediaProxy ? item.toBase64() : this.toBase64(item.raw);
|
const content = item instanceof MediaProxy ? item.toBase64() : this.toBase64(item.raw);
|
||||||
|
|
||||||
return content.then((contentBase64) => {
|
return content.then((contentBase64) => {
|
||||||
return this.request(`${this.repoURL}/git/blobs`, {
|
return this.request(`${this.repoURL}/blobs`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
content: contentBase64,
|
content: contentBase64,
|
||||||
@ -263,7 +263,7 @@ export default class API {
|
|||||||
}
|
}
|
||||||
return Promise.all(updates)
|
return Promise.all(updates)
|
||||||
.then((updates) => {
|
.then((updates) => {
|
||||||
return this.request(`${this.repoURL}/git/trees`, {
|
return this.request(`${this.repoURL}/trees`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ base_tree: sha, tree: updates })
|
body: JSON.stringify({ base_tree: sha, tree: updates })
|
||||||
});
|
});
|
||||||
@ -276,7 +276,7 @@ export default class API {
|
|||||||
commit(message, changeTree) {
|
commit(message, changeTree) {
|
||||||
const tree = changeTree.sha;
|
const tree = changeTree.sha;
|
||||||
const parents = changeTree.parentSha ? [changeTree.parentSha] : [];
|
const parents = changeTree.parentSha ? [changeTree.parentSha] : [];
|
||||||
return this.request(`${this.repoURL}/git/commits`, {
|
return this.request(`${this.repoURL}/commits`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ message, tree, parents })
|
body: JSON.stringify({ message, tree, parents })
|
||||||
});
|
});
|
||||||
|
@ -2,6 +2,7 @@ import React from 'react';
|
|||||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { Card } from './UI';
|
import { Card } from './UI';
|
||||||
|
import { Link } from 'react-router'
|
||||||
import { statusDescriptions } from '../constants/publishModes';
|
import { statusDescriptions } from '../constants/publishModes';
|
||||||
import styles from './UnpublishedListing.css';
|
import styles from './UnpublishedListing.css';
|
||||||
|
|
||||||
@ -22,9 +23,10 @@ export default class UnpublishedListing extends React.Component {
|
|||||||
// Look for an "author" field. Fallback to username on backend implementation;
|
// Look for an "author" field. Fallback to username on backend implementation;
|
||||||
const author = entry.getIn(['data', 'author'], entry.getIn(['metaData', 'user']));
|
const author = entry.getIn(['data', 'author'], entry.getIn(['metaData', 'user']));
|
||||||
const timeStamp = moment(entry.getIn(['metaData', 'timeStamp'])).formate('llll');
|
const timeStamp = moment(entry.getIn(['metaData', 'timeStamp'])).formate('llll');
|
||||||
|
const link = `/editorialworkflow/${entry.getIn(['metaData', 'collection'])}/${entry.getIn(['metaData', 'status'])}/${entry.get('slug')}`;
|
||||||
return (
|
return (
|
||||||
<Card key={entry.get('slug')} className={styles.card}>
|
<Card key={entry.get('slug')} className={styles.card}>
|
||||||
<h1>{entry.getIn(['data', 'title'])} <small>by {author}</small></h1>
|
<h1><Link to={link}>{entry.getIn(['data', 'title'])}</Link> <small>by {author}</small></h1>
|
||||||
<p>Last updated: {timeStamp} by {entry.getIn(['metaData', 'user'])}</p>
|
<p>Last updated: {timeStamp} by {entry.getIn(['metaData', 'user'])}</p>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
|
@ -6,7 +6,7 @@ import { selectEntries } from '../reducers';
|
|||||||
import { Loader } from '../components/UI';
|
import { Loader } from '../components/UI';
|
||||||
import EntryListing from '../components/EntryListing';
|
import EntryListing from '../components/EntryListing';
|
||||||
import styles from './CollectionPage.css';
|
import styles from './CollectionPage.css';
|
||||||
import EditorialWorkflow from './EditorialWorkflowHoC';
|
import CollectionPageHOC from './editorialWorkflow/CollectionPageHOC';
|
||||||
|
|
||||||
class DashboardPage extends React.Component {
|
class DashboardPage extends React.Component {
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -50,7 +50,7 @@ DashboardPage.propTypes = {
|
|||||||
* Instead of checking the publish mode everywhere to dispatch & render the additional editorial workflow stuff,
|
* Instead of checking the publish mode everywhere to dispatch & render the additional editorial workflow stuff,
|
||||||
* We delegate it to a Higher Order Component
|
* We delegate it to a Higher Order Component
|
||||||
*/
|
*/
|
||||||
DashboardPage = EditorialWorkflow(DashboardPage);
|
DashboardPage = CollectionPageHOC(DashboardPage);
|
||||||
|
|
||||||
|
|
||||||
function mapStateToProps(state, ownProps) {
|
function mapStateToProps(state, ownProps) {
|
||||||
|
@ -12,6 +12,7 @@ import {
|
|||||||
import { addMedia, removeMedia } from '../actions/media';
|
import { addMedia, removeMedia } from '../actions/media';
|
||||||
import { selectEntry, getMedia } from '../reducers';
|
import { selectEntry, getMedia } from '../reducers';
|
||||||
import EntryEditor from '../components/EntryEditor';
|
import EntryEditor from '../components/EntryEditor';
|
||||||
|
import EntryPageHOC from './editorialWorkflow/EntryPageHOC';
|
||||||
|
|
||||||
class EntryPage extends React.Component {
|
class EntryPage extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@ -56,6 +57,7 @@ class EntryPage extends React.Component {
|
|||||||
const {
|
const {
|
||||||
entry, entryDraft, boundGetMedia, collection, changeDraft, addMedia, removeMedia
|
entry, entryDraft, boundGetMedia, collection, changeDraft, addMedia, removeMedia
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
if (entryDraft == null || entryDraft.get('entry') == undefined || entry && entry.get('isFetching')) {
|
if (entryDraft == null || entryDraft.get('entry') == undefined || entry && entry.get('isFetching')) {
|
||||||
return <div>Loading...</div>;
|
return <div>Loading...</div>;
|
||||||
}
|
}
|
||||||
@ -100,6 +102,12 @@ function mapStateToProps(state, ownProps) {
|
|||||||
return { collection, collections, newEntry, entryDraft, boundGetMedia, slug, entry };
|
return { collection, collections, newEntry, entryDraft, boundGetMedia, slug, entry };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Instead of checking the publish mode everywhere to dispatch & render the additional editorial workflow stuff,
|
||||||
|
* We delegate it to a Higher Order Component
|
||||||
|
*/
|
||||||
|
EntryPage = EntryPageHOC(EntryPage);
|
||||||
|
|
||||||
export default connect(
|
export default connect(
|
||||||
mapStateToProps,
|
mapStateToProps,
|
||||||
{
|
{
|
||||||
|
@ -1,19 +1,18 @@
|
|||||||
import React, { PropTypes } from 'react';
|
import React, { PropTypes } from 'react';
|
||||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||||
import { OrderedMap } from 'immutable';
|
import { OrderedMap } from 'immutable';
|
||||||
import { init, loadUnpublishedEntries } from '../actions/editorialWorkflow';
|
import { loadUnpublishedEntries } from '../../actions/editorialWorkflow';
|
||||||
import { selectUnpublishedEntries } from '../reducers';
|
import { selectUnpublishedEntries } from '../../reducers';
|
||||||
import { EDITORIAL_WORKFLOW, status } from '../constants/publishModes';
|
import { EDITORIAL_WORKFLOW, status } from '../../constants/publishModes';
|
||||||
import UnpublishedListing from '../components/UnpublishedListing';
|
import UnpublishedListing from '../../components/UnpublishedListing';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
export default function EditorialWorkflow(WrappedComponent) {
|
export default function CollectionPageHOC(CollectionPage) {
|
||||||
class EditorialWorkflow extends WrappedComponent {
|
class CollectionPageHOC extends CollectionPage {
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const { dispatch, isEditorialWorkflow } = this.props;
|
const { dispatch, isEditorialWorkflow } = this.props;
|
||||||
if (isEditorialWorkflow) {
|
if (isEditorialWorkflow) {
|
||||||
dispatch(init());
|
|
||||||
dispatch(loadUnpublishedEntries());
|
dispatch(loadUnpublishedEntries());
|
||||||
}
|
}
|
||||||
super.componentDidMount();
|
super.componentDidMount();
|
||||||
@ -32,7 +31,7 @@ export default function EditorialWorkflow(WrappedComponent) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorialWorkflow.propTypes = {
|
CollectionPageHOC.propTypes = {
|
||||||
dispatch: PropTypes.func.isRequired,
|
dispatch: PropTypes.func.isRequired,
|
||||||
isEditorialWorkflow: PropTypes.bool.isRequired,
|
isEditorialWorkflow: PropTypes.bool.isRequired,
|
||||||
unpublishedEntries: ImmutablePropTypes.map,
|
unpublishedEntries: ImmutablePropTypes.map,
|
||||||
@ -56,5 +55,5 @@ export default function EditorialWorkflow(WrappedComponent) {
|
|||||||
return returnObj;
|
return returnObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
return connect(mapStateToProps)(EditorialWorkflow);
|
return connect(mapStateToProps)(CollectionPageHOC);
|
||||||
}
|
}
|
47
src/containers/editorialWorkflow/EntryPageHOC.js
Normal file
47
src/containers/editorialWorkflow/EntryPageHOC.js
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { EDITORIAL_WORKFLOW } from '../../constants/publishModes';
|
||||||
|
import { selectUnpublishedEntry } from '../../reducers';
|
||||||
|
import { loadUnpublishedEntry } from '../../actions/editorialWorkflow';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
|
export default function EntryPageHOC(EntryPage) {
|
||||||
|
class EntryPageHOC extends React.Component {
|
||||||
|
render() {
|
||||||
|
return <EntryPage {...this.props}/>;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function mapStateToProps(state, ownProps) {
|
||||||
|
const publish_mode = state.config.get('publish_mode');
|
||||||
|
const isEditorialWorkflow = (publish_mode === EDITORIAL_WORKFLOW);
|
||||||
|
const unpublishedEntry = ownProps.route && ownProps.route.unpublishedEntry === true;
|
||||||
|
|
||||||
|
const returnObj = {};
|
||||||
|
if (isEditorialWorkflow && unpublishedEntry) {
|
||||||
|
const status = ownProps.params.status;
|
||||||
|
const slug = ownProps.params.slug;
|
||||||
|
const entry = selectUnpublishedEntry(state, status, slug);
|
||||||
|
returnObj.entry = entry;
|
||||||
|
|
||||||
|
returnObj.persistEntry = () => {
|
||||||
|
// TODO - for now, simply ignore
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return returnObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mapDispatchToProps(dispatch, ownProps) {
|
||||||
|
const unpublishedEntry = ownProps.route && ownProps.route.unpublishedEntry === true;
|
||||||
|
const returnObj = {};
|
||||||
|
if (unpublishedEntry) {
|
||||||
|
// Overwrite loadEntry to loadUnpublishedEntry
|
||||||
|
const status = ownProps.params.status;
|
||||||
|
returnObj.loadEntry = (collection, slug) => {
|
||||||
|
dispatch(loadUnpublishedEntry(collection, status, slug));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return returnObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
return connect(mapStateToProps, mapDispatchToProps)(EntryPageHOC);
|
||||||
|
}
|
@ -4,12 +4,34 @@ import YAMLFrontmatter from './yaml-frontmatter';
|
|||||||
const yamlFormatter = new YAML();
|
const yamlFormatter = new YAML();
|
||||||
const YamlFrontmatterFormatter = new YAMLFrontmatter();
|
const YamlFrontmatterFormatter = new YAMLFrontmatter();
|
||||||
|
|
||||||
export function resolveFormat(collectionOrEntity, entry) {
|
function formatByType(type) {
|
||||||
const extension = entry.path.split('.').pop();
|
// Right now the only type is "editorialWorkflow" and
|
||||||
switch (extension) {
|
// we always returns the same format
|
||||||
case 'yml':
|
|
||||||
return yamlFormatter;
|
|
||||||
default:
|
|
||||||
return YamlFrontmatterFormatter;
|
return YamlFrontmatterFormatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatByExtension(extension) {
|
||||||
|
return {
|
||||||
|
'yml': yamlFormatter,
|
||||||
|
'md': YamlFrontmatterFormatter,
|
||||||
|
'markdown': YamlFrontmatterFormatter,
|
||||||
|
'html': YamlFrontmatterFormatter
|
||||||
|
}[extension] || YamlFrontmatterFormatter;
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatByName(name) {
|
||||||
|
return {
|
||||||
|
'yaml': yamlFormatter,
|
||||||
|
'frontmatter': YamlFrontmatterFormatter
|
||||||
|
}[name] || YamlFrontmatterFormatter;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function resolveFormat(collectionOrEntity, entry) {
|
||||||
|
if (typeof collectionOrEntity === 'string') {
|
||||||
|
return formatByType(collectionOrEntity);
|
||||||
|
}
|
||||||
|
if (entry && entry.path) {
|
||||||
|
return formatByExtension(entry.path.split('.').pop());
|
||||||
|
}
|
||||||
|
return formatByName(collectionOrEntity.get('format'));
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,30 @@
|
|||||||
import { Map, List, fromJS } from 'immutable';
|
import { Map, List, fromJS } from 'immutable';
|
||||||
|
import { EDITORIAL_WORKFLOW } from '../constants/publishModes';
|
||||||
import {
|
import {
|
||||||
INIT, UNPUBLISHED_ENTRIES_REQUEST, UNPUBLISHED_ENTRIES_SUCCESS
|
UNPUBLISHED_ENTRY_REQUEST, UNPUBLISHED_ENTRY_SUCCESS, UNPUBLISHED_ENTRIES_REQUEST, UNPUBLISHED_ENTRIES_SUCCESS
|
||||||
} from '../actions/editorialWorkflow';
|
} from '../actions/editorialWorkflow';
|
||||||
|
import { CONFIG_SUCCESS } from '../actions/config';
|
||||||
|
|
||||||
const unpublishedEntries = (state = null, action) => {
|
const unpublishedEntries = (state = null, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case INIT:
|
case CONFIG_SUCCESS:
|
||||||
// Editorial workflow must be explicitly initiated.
|
const publish_mode = action.payload && action.payload.publish_mode;
|
||||||
|
if (publish_mode === EDITORIAL_WORKFLOW) {
|
||||||
|
// Editorial workflow state is explicetelly initiated after the config.
|
||||||
return Map({ entities: Map(), pages: Map() });
|
return Map({ entities: Map(), pages: Map() });
|
||||||
|
} else {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
case UNPUBLISHED_ENTRY_REQUEST:
|
||||||
|
return state.setIn(['entities', `${action.payload.status}.${action.payload.slug}`, 'isFetching'], true);
|
||||||
|
|
||||||
|
case UNPUBLISHED_ENTRY_SUCCESS:
|
||||||
|
return state.setIn(
|
||||||
|
['entities', `${action.payload.status}.${action.payload.entry.slug}`],
|
||||||
|
fromJS(action.payload.entry)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
case UNPUBLISHED_ENTRIES_REQUEST:
|
case UNPUBLISHED_ENTRIES_REQUEST:
|
||||||
return state.setIn(['pages', 'isFetching'], true);
|
return state.setIn(['pages', 'isFetching'], true);
|
||||||
|
|
||||||
@ -27,9 +44,9 @@ const unpublishedEntries = (state = null, action) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const selectUnpublishedEntry = (state, status, slug) => (
|
export const selectUnpublishedEntry = (state, status, slug) => {
|
||||||
state.getIn(['entities', `${status}.${slug}`])
|
return state && state.getIn(['entities', `${status}.${slug}`]);
|
||||||
);
|
};
|
||||||
|
|
||||||
export const selectUnpublishedEntries = (state, status) => {
|
export const selectUnpublishedEntries = (state, status) => {
|
||||||
if (!state) return;
|
if (!state) return;
|
||||||
|
@ -12,6 +12,7 @@ export default (
|
|||||||
<Route path="/collections/:name" component={CollectionPage}/>
|
<Route path="/collections/:name" component={CollectionPage}/>
|
||||||
<Route path="/collections/:name/entries/new" component={EntryPage} newRecord />
|
<Route path="/collections/:name/entries/new" component={EntryPage} newRecord />
|
||||||
<Route path="/collections/:name/entries/:slug" component={EntryPage} />
|
<Route path="/collections/:name/entries/:slug" component={EntryPage} />
|
||||||
|
<Route path="/editorialworkflow/:name/:status/:slug" component={EntryPage} unpublishedEntry />
|
||||||
<Route path="/search" component={SearchPage}/>
|
<Route path="/search" component={SearchPage}/>
|
||||||
<Route path="*" component={NotFoundPage}/>
|
<Route path="*" component={NotFoundPage}/>
|
||||||
</Route>
|
</Route>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user