diff --git a/dev-test/backends/default-workflow-status/config.yml b/dev-test/backends/default-workflow-status/config.yml new file mode 100644 index 000000000000..18d686453409 --- /dev/null +++ b/dev-test/backends/default-workflow-status/config.yml @@ -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 diff --git a/dev-test/backends/default-workflow-status/index.html b/dev-test/backends/default-workflow-status/index.html new file mode 100644 index 000000000000..103dbb272d68 --- /dev/null +++ b/dev-test/backends/default-workflow-status/index.html @@ -0,0 +1,41 @@ + + + + + + Netlify CMS Development Test + + + + + + diff --git a/packages/netlify-cms-core/src/actions/__tests__/config.spec.js b/packages/netlify-cms-core/src/actions/__tests__/config.spec.js index 586d4e83c178..107a4188c0c5 100644 --- a/packages/netlify-cms-core/src/actions/__tests__/config.spec.js +++ b/packages/netlify-cms-core/src/actions/__tests__/config.spec.js @@ -9,6 +9,7 @@ import { detectProxyServer, handleLocalBackend, } from '../config'; +import { Statues } from '../../constants/publishModes'; jest.spyOn(console, 'log').mockImplementation(() => {}); jest.spyOn(console, 'warn').mockImplementation(() => {}); @@ -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( diff --git a/packages/netlify-cms-core/src/actions/config.ts b/packages/netlify-cms-core/src/actions/config.ts index 3bb3a1cb937b..f45ef865fccf 100644 --- a/packages/netlify-cms-core/src/actions/config.ts +++ b/packages/netlify-cms-core/src/actions/config.ts @@ -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'; @@ -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; diff --git a/packages/netlify-cms-core/src/constants/publishModes.ts b/packages/netlify-cms-core/src/constants/publishModes.ts index 56fba78ffb3d..49c1faf1a481 100644 --- a/packages/netlify-cms-core/src/constants/publishModes.ts +++ b/packages/netlify-cms-core/src/constants/publishModes.ts @@ -20,3 +20,4 @@ export const statusDescriptions = Map({ }); export type Status = keyof typeof Statues; +export type StatusValues = typeof Statues[Status]; diff --git a/packages/netlify-cms-core/src/types/redux.ts b/packages/netlify-cms-core/src/types/redux.ts index 90ad23a27183..b587cd797cce 100644 --- a/packages/netlify-cms-core/src/types/redux.ts +++ b/packages/netlify-cms-core/src/types/redux.ts @@ -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'; @@ -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[];