Skip to content

Commit

Permalink
feat: add initial workflow status in config
Browse files Browse the repository at this point in the history
  • Loading branch information
RomainOliva committed May 11, 2022
1 parent 19d569d commit e89358a
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/netlify-cms-core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ declare module 'netlify-cms-core' {

export type CmsPublishMode = 'simple' | 'editorial_workflow';

export type CmsPublishWorkflowStatus = 'draft' | 'pending_review' | 'pending_publish';

export type CmsSlugEncoding = 'unicode' | 'ascii';

export interface CmsI18nConfig {
Expand Down Expand Up @@ -394,6 +396,7 @@ declare module 'netlify-cms-core' {
media_folder_relative?: boolean;
media_library?: CmsMediaLibrary;
publish_mode?: CmsPublishMode;
default_workflow_status?: CmsPublishWorkflowStatus;
load_config_file?: boolean;
integrations?: {
hooks: string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('config', () => {
local_backend: true
site_url: https://www.netlifycms.org
publish_mode: editorial_workflow
default_workflow_status: pending_publish
media_folder: website/static/img
public_folder: img
docs_collection: &docs_collection
Expand All @@ -69,6 +70,7 @@ describe('config', () => {
local_backend: true,
site_url: 'https://www.netlifycms.org',
publish_mode: 'editorial_workflow',
default_workflow_status: 'pending_publish',
media_folder: 'website/static/img',
public_folder: 'img',
docs_collection: {
Expand Down
5 changes: 2 additions & 3 deletions packages/netlify-cms-core/src/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { basename, join, extname, dirname } from 'path';
import { stringTemplate } from 'netlify-cms-lib-widgets';

import { resolveFormat } from './formats/formats';
import { selectUseWorkflow } from './reducers/config';
import { selectUseWorkflow, selectDefaultWorkflowStatus } from './reducers/config';
import { selectMediaFilePath, selectEntry } from './reducers/entries';
import { selectIntegration } from './reducers/integrations';
import {
Expand All @@ -33,7 +33,6 @@ import { createEntry } from './valueObjects/Entry';
import { sanitizeChar } from './lib/urlHelper';
import { getBackend, invokeEvent } from './lib/registry';
import { commitMessageFormatter, slugFormatter, previewUrlFormatter } from './lib/formatters';
import { status } from './constants/publishModes';
import { FOLDER, FILES } from './constants/collectionTypes';
import { selectCustomPath } from './reducers/entryDraft';
import {
Expand Down Expand Up @@ -322,7 +321,7 @@ export class Backend {
this.implementation = implementation.init(this.config, {
useWorkflow: selectUseWorkflow(this.config),
updateUserCredentials: this.updateUserCredentials,
initialWorkflowStatus: status.first(),
initialWorkflowStatus: selectDefaultWorkflowStatus(this.config),
});
this.backendName = backendName;
this.authStore = authStore;
Expand Down
6 changes: 6 additions & 0 deletions packages/netlify-cms-core/src/constants/configSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import ajvErrors from 'ajv-errors';
import uuid from 'uuid/v4';

import { Statues } from './publishModes';
import { formatExtensions, frontmatterFormats, extensionFormatters } from '../formats/formats';
import { getWidgets } from '../lib/registry';
import { I18N_STRUCTURE, I18N_FIELD } from '../lib/i18n';
Expand Down Expand Up @@ -178,6 +179,11 @@ function getConfigSchema() {
enum: ['simple', 'editorial_workflow'],
examples: ['editorial_workflow'],
},
default_workflow_status: {
type: 'string',
enum: Object.values(Statues),
examples: [Statues.PENDING_PUBLISH],
},
slug: {
type: 'object',
properties: {
Expand Down
6 changes: 5 additions & 1 deletion packages/netlify-cms-core/src/reducers/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { produce } from 'immer';

import { CONFIG_REQUEST, CONFIG_SUCCESS, CONFIG_FAILURE } from '../actions/config';
import { EDITORIAL_WORKFLOW } from '../constants/publishModes';
import { EDITORIAL_WORKFLOW, status } from '../constants/publishModes';

import type { ConfigAction } from '../actions/config';
import type { CmsConfig } from '../types/redux';
Expand Down Expand Up @@ -35,4 +35,8 @@ export function selectUseWorkflow(state: CmsConfig) {
return state.publish_mode === EDITORIAL_WORKFLOW;
}

export function selectDefaultWorkflowStatus(state: CmsConfig) {
return state.default_workflow_status || status.first();
}

export default config;
3 changes: 3 additions & 0 deletions packages/netlify-cms-core/src/types/redux.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +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 { MediaFile as BackendMediaFile } from '../backend';
import type { Auth } from '../reducers/auth';
import type { Status } from '../reducers/status';
Expand Down Expand Up @@ -400,6 +401,7 @@ export interface CmsConfig {
media_folder_relative?: boolean;
media_library?: CmsMediaLibrary;
publish_mode?: CmsPublishMode;
default_workflow_status?: PublishStatus;
load_config_file?: boolean;
integrations?: {
hooks: string[];
Expand Down Expand Up @@ -455,6 +457,7 @@ export type Config = StaticallyTypedRecord<{
media_folder: string;
public_folder: string;
publish_mode?: string;
default_workflow_status?: string;
media_library: StaticallyTypedRecord<{ name: string }> & { name: string };
locale?: string;
slug: SlugConfig;
Expand Down
9 changes: 9 additions & 0 deletions website/content/docs/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ You can enable the Editorial Workflow with the following line in your Netlify CM
publish_mode: editorial_workflow
```
You can select the initial status with the following line in your Netlify CMS `config.yml` file:

```yaml
# /admin/config.yml
default_workflow_status: 'draft'
```

There is the 3 available status: `'draft' | 'pending_review' | 'pending_publish'`

From a technical perspective, the workflow translates editor UI actions into common Git commands:

| Actions in Netlify UI | Perform these Git actions |
Expand Down

0 comments on commit e89358a

Please sign in to comment.