Skip to content

Commit

Permalink
fixup! feat: add initial workflow status in config
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainOliva committed Jun 2, 2022
1 parent 049c87a commit 78cc7e0
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 3 deletions.
63 changes: 63 additions & 0 deletions dev-test/backends/default-workflow-status/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
backend:
name: git-gateway
branch: master

publish_mode: editorial_workflow
default_workflow_status: pending_publish
media_folder: static/media
public_folder: /media
collections:
- name: posts
label: Posts
label_singular: 'Post'
folder: content/posts
create: true
slug: '{{year}}-{{month}}-{{day}}-{{slug}}'
fields:
- label: Template
name: template
widget: hidden
default: post
- label: Title
name: title
widget: string
- label: 'Cover Image'
name: 'image'
widget: 'image'
required: false
- label: Publish Date
name: date
widget: datetime
- label: Description
name: description
widget: text
- label: Category
name: category
widget: string
- label: Body
name: body
widget: markdown
- label: Tags
name: tags
widget: list
- name: pages
label: Pages
label_singular: 'Page'
folder: content/pages
create: true
slug: '{{slug}}'
fields:
- label: Template
name: template
widget: hidden
default: page
- label: Title
name: title
widget: string
- label: Draft
name: draft
widget: boolean
default: true
- label: Body
name: body
widget: markdown
41 changes: 41 additions & 0 deletions dev-test/backends/default-workflow-status/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />

<title>Netlify CMS Development Test</title>
</head>
<body>
<script src="dist/netlify-cms.js"></script>
<script>
var PostPreview = createClass({
render: function() {
var entry = this.props.entry;
return h(
'div',
{},
h('div', { className: 'cover' }, h('h1', {}, entry.getIn(['data', 'title']))),
h('p', {}, h('small', {}, 'Written ' + entry.getIn(['data', 'date']))),
h('div', { className: 'text' }, this.props.widgetFor('body')),
);
},
});

var PagePreview = createClass({
render: function() {
var entry = this.props.entry;
return h(
'div',
{},
h('div', { className: 'cover' }, h('h1', {}, entry.getIn(['data', 'title']))),
h('p', {}, h('small', {}, 'Written ' + entry.getIn(['data', 'date']))),
h('div', { className: 'text' }, this.props.widgetFor('body')),
);
},
});

CMS.registerPreviewTemplate('posts', PostPreview);
CMS.registerPreviewTemplate('pages', PagePreview);
</script>
</body>
</html>
18 changes: 18 additions & 0 deletions packages/netlify-cms-core/src/actions/__tests__/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
detectProxyServer,
handleLocalBackend,
} from '../config';
import { Statues } from '../../constants/publishModes';

jest.spyOn(console, 'log').mockImplementation(() => {});
jest.spyOn(console, 'warn').mockImplementation(() => {});
Expand Down Expand Up @@ -122,6 +123,23 @@ describe('config', () => {
});
});

describe('default_workflow_status', () => {
it('should set default_workflow_status to "draft" by default if publish_mode is "editorial_workflow"', () => {
const config = {
publish_mode: 'editorial_workflow',
};
expect(applyDefaults(config).default_workflow_status).toEqual(Statues.DRAFT);
});

it('should set default_workflow_status from config', () => {
const config = {
publish_mode: 'editorial_workflow',
default_workflow_status: Statues.PENDING_REVIEW,
};
expect(applyDefaults(config).default_workflow_status).toEqual(Statues.PENDING_REVIEW);
});
});

describe('public_folder', () => {
it('should set public_folder based on media_folder if not set', () => {
expect(
Expand Down
10 changes: 9 additions & 1 deletion packages/netlify-cms-core/src/actions/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import deepmerge from 'deepmerge';
import { produce } from 'immer';
import { trimStart, trim, isEmpty } from 'lodash';

import { SIMPLE as SIMPLE_PUBLISH_MODE } from '../constants/publishModes';
import {
EDITORIAL_WORKFLOW,
SIMPLE as SIMPLE_PUBLISH_MODE,
Statues,
} from '../constants/publishModes';
import { validateConfig } from '../constants/configSchema';
import { selectDefaultSortableFields } from '../reducers/collections';
import { getIntegrations, selectIntegration } from '../reducers/integrations';
Expand Down Expand Up @@ -210,6 +214,10 @@ export function applyDefaults(originalConfig: CmsConfig) {
config.slug = config.slug || {};
config.collections = config.collections || [];

if (config.publish_mode === EDITORIAL_WORKFLOW) {
config.default_workflow_status = config.default_workflow_status || Statues.DRAFT;
}

// Use `site_url` as default `display_url`.
if (!config.display_url && config.site_url) {
config.display_url = config.site_url;
Expand Down
1 change: 1 addition & 0 deletions packages/netlify-cms-core/src/constants/publishModes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export const statusDescriptions = Map({
});

export type Status = keyof typeof Statues;
export type StatusValues = typeof Statues[Status];
4 changes: 2 additions & 2 deletions packages/netlify-cms-core/src/types/redux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Action } from 'redux';
import type { StaticallyTypedRecord } from './immutable';
import type { Map, List, OrderedMap, Set } from 'immutable';
import type { FILES, FOLDER } from '../constants/collectionTypes';
import type { Status as PublishStatus } from '../constants/publishModes';
import type { StatusValues as PublishStatusValues } from '../constants/publishModes';
import type { MediaFile as BackendMediaFile } from '../backend';
import type { Auth } from '../reducers/auth';
import type { Status } from '../reducers/status';
Expand Down Expand Up @@ -401,7 +401,7 @@ export interface CmsConfig {
media_folder_relative?: boolean;
media_library?: CmsMediaLibrary;
publish_mode?: CmsPublishMode;
default_workflow_status?: PublishStatus;
default_workflow_status?: PublishStatusValues;
load_config_file?: boolean;
integrations?: {
hooks: string[];
Expand Down

0 comments on commit 78cc7e0

Please sign in to comment.