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 1be43b9
Show file tree
Hide file tree
Showing 5 changed files with 18 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
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;
2 changes: 2 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

0 comments on commit 1be43b9

Please sign in to comment.