Skip to content

Commit 4798191

Browse files
committed
fixup! feat: add initial workflow status in config
1 parent 049c87a commit 4798191

6 files changed

Lines changed: 135 additions & 4 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
backend:
2+
name: git-gateway
3+
branch: master
4+
5+
publish_mode: editorial_workflow
6+
default_workflow_status: pending_publish
7+
media_folder: static/media
8+
public_folder: /media
9+
collections:
10+
- name: posts
11+
label: Posts
12+
label_singular: 'Post'
13+
folder: content/posts
14+
create: true
15+
slug: '{{year}}-{{month}}-{{day}}-{{slug}}'
16+
fields:
17+
- label: Template
18+
name: template
19+
widget: hidden
20+
default: post
21+
- label: Title
22+
name: title
23+
widget: string
24+
- label: 'Cover Image'
25+
name: 'image'
26+
widget: 'image'
27+
required: false
28+
- label: Publish Date
29+
name: date
30+
widget: datetime
31+
- label: Description
32+
name: description
33+
widget: text
34+
- label: Category
35+
name: category
36+
widget: string
37+
- label: Body
38+
name: body
39+
widget: markdown
40+
- label: Tags
41+
name: tags
42+
widget: list
43+
- name: pages
44+
label: Pages
45+
label_singular: 'Page'
46+
folder: content/pages
47+
create: true
48+
slug: '{{slug}}'
49+
fields:
50+
- label: Template
51+
name: template
52+
widget: hidden
53+
default: page
54+
- label: Title
55+
name: title
56+
widget: string
57+
- label: Draft
58+
name: draft
59+
widget: boolean
60+
default: true
61+
- label: Body
62+
name: body
63+
widget: markdown
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
6+
<title>Netlify CMS Development Test</title>
7+
</head>
8+
<body>
9+
<script src="dist/netlify-cms.js"></script>
10+
<script>
11+
var PostPreview = createClass({
12+
render: function() {
13+
var entry = this.props.entry;
14+
return h(
15+
'div',
16+
{},
17+
h('div', { className: 'cover' }, h('h1', {}, entry.getIn(['data', 'title']))),
18+
h('p', {}, h('small', {}, 'Written ' + entry.getIn(['data', 'date']))),
19+
h('div', { className: 'text' }, this.props.widgetFor('body')),
20+
);
21+
},
22+
});
23+
24+
var PagePreview = createClass({
25+
render: function() {
26+
var entry = this.props.entry;
27+
return h(
28+
'div',
29+
{},
30+
h('div', { className: 'cover' }, h('h1', {}, entry.getIn(['data', 'title']))),
31+
h('p', {}, h('small', {}, 'Written ' + entry.getIn(['data', 'date']))),
32+
h('div', { className: 'text' }, this.props.widgetFor('body')),
33+
);
34+
},
35+
});
36+
37+
CMS.registerPreviewTemplate('posts', PostPreview);
38+
CMS.registerPreviewTemplate('pages', PagePreview);
39+
</script>
40+
</body>
41+
</html>

packages/netlify-cms-core/src/actions/__tests__/config.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
detectProxyServer,
1010
handleLocalBackend,
1111
} from '../config';
12+
import { Statues } from '../../constants/publishModes';
1213

1314
jest.spyOn(console, 'log').mockImplementation(() => {});
1415
jest.spyOn(console, 'warn').mockImplementation(() => {});
@@ -122,6 +123,23 @@ describe('config', () => {
122123
});
123124
});
124125

126+
describe('default_workflow_status', () => {
127+
it('should set default_workflow_status to "draft" by default if publish_mode is "editorial_workflow"', () => {
128+
const config = {
129+
publish_mode: 'editorial_workflow',
130+
};
131+
expect(applyDefaults(config).default_workflow_status).toEqual(Statues.DRAFT);
132+
});
133+
134+
it('should set default_workflow_status from config', () => {
135+
const config = {
136+
publish_mode: 'editorial_workflow',
137+
default_workflow_status: Statues.PENDING_REVIEW,
138+
};
139+
expect(applyDefaults(config).default_workflow_status).toEqual(Statues.PENDING_REVIEW);
140+
});
141+
});
142+
125143
describe('public_folder', () => {
126144
it('should set public_folder based on media_folder if not set', () => {
127145
expect(

packages/netlify-cms-core/src/actions/config.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import deepmerge from 'deepmerge';
44
import { produce } from 'immer';
55
import { trimStart, trim, isEmpty } from 'lodash';
66

7-
import { SIMPLE as SIMPLE_PUBLISH_MODE } from '../constants/publishModes';
7+
import {
8+
EDITORIAL_WORKFLOW,
9+
SIMPLE as SIMPLE_PUBLISH_MODE,
10+
Statues,
11+
} from '../constants/publishModes';
812
import { validateConfig } from '../constants/configSchema';
913
import { selectDefaultSortableFields } from '../reducers/collections';
1014
import { getIntegrations, selectIntegration } from '../reducers/integrations';
@@ -210,8 +214,12 @@ export function applyDefaults(originalConfig: CmsConfig) {
210214
config.slug = config.slug || {};
211215
config.collections = config.collections || [];
212216

213-
// Use `site_url` as default `display_url`.
217+
if (config.publish_mode === EDITORIAL_WORKFLOW) {
218+
config.default_workflow_status = config.default_workflow_status || Statues.DRAFT;
219+
}
220+
214221
if (!config.display_url && config.site_url) {
222+
// Use `site_url` as default `display_url`.
215223
config.display_url = config.site_url;
216224
}
217225

packages/netlify-cms-core/src/constants/publishModes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ export const statusDescriptions = Map({
2020
});
2121

2222
export type Status = keyof typeof Statues;
23+
export type StatusValues = typeof Statues[Status];

packages/netlify-cms-core/src/types/redux.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Action } from 'redux';
22
import type { StaticallyTypedRecord } from './immutable';
33
import type { Map, List, OrderedMap, Set } from 'immutable';
44
import type { FILES, FOLDER } from '../constants/collectionTypes';
5-
import type { Status as PublishStatus } from '../constants/publishModes';
5+
import type { StatusValues as PublishStatusValues } from '../constants/publishModes';
66
import type { MediaFile as BackendMediaFile } from '../backend';
77
import type { Auth } from '../reducers/auth';
88
import type { Status } from '../reducers/status';
@@ -401,7 +401,7 @@ export interface CmsConfig {
401401
media_folder_relative?: boolean;
402402
media_library?: CmsMediaLibrary;
403403
publish_mode?: CmsPublishMode;
404-
default_workflow_status?: PublishStatus;
404+
default_workflow_status?: PublishStatusValues;
405405
load_config_file?: boolean;
406406
integrations?: {
407407
hooks: string[];

0 commit comments

Comments
 (0)