UNPKG

decap-cms-core

Version:

Decap CMS core application, see decap-cms package for the main distribution.

92 lines (91 loc) 3.62 kB
import { List, Set } from 'immutable'; import auth from './auth'; import config from './config'; import collections, * as fromCollections from './collections'; import integrations, * as fromIntegrations from './integrations'; import entries, * as fromEntries from './entries'; import cursors from './cursors'; import editorialWorkflow, * as fromEditorialWorkflow from './editorialWorkflow'; import entryDraft from './entryDraft'; import medias from './medias'; import mediaLibrary from './mediaLibrary'; import deploys, * as fromDeploys from './deploys'; import globalUI from './globalUI'; import search from './search'; import status from './status'; import notifications from './notifications'; import { FOLDER } from '../constants/collectionTypes'; import { EDITORIAL_WORKFLOW } from '../constants/publishModes'; const reducers = { auth, config, collections, search, integrations, entries, cursors, editorialWorkflow, entryDraft, medias, mediaLibrary, deploys, globalUI, status, notifications }; export default reducers; /* * Selectors */ export function selectEntry(state, collectionName, slug) { return fromEntries.selectEntry(state.entries, collectionName, slug); } export function selectEntries(state, collection) { return fromEntries.selectEntries(state.entries, collection); } export function selectPublishedSlugs(state, collection) { return fromEntries.selectPublishedSlugs(state.entries, collection); } export function selectSearchedEntries(state, availableCollections) { // only return search results for actually available collections return List(state.search.entryIds).filter(entryId => availableCollections.indexOf(entryId.collection) !== -1).map(entryId => fromEntries.selectEntry(state.entries, entryId.collection, entryId.slug)); } export function selectDeployPreview(state, collection, slug) { return fromDeploys.selectDeployPreview(state.deploys, collection, slug); } export function selectUnpublishedEntry(state, collection, slug) { return fromEditorialWorkflow.selectUnpublishedEntry(state.editorialWorkflow, collection, slug); } export function selectUnpublishedEntriesByStatus(state, status) { return fromEditorialWorkflow.selectUnpublishedEntriesByStatus(state.editorialWorkflow, status); } export function selectUnpublishedSlugs(state, collection) { return fromEditorialWorkflow.selectUnpublishedSlugs(state.editorialWorkflow, collection); } export function selectCanCreateNewEntry(state, collectionName) { const collection = state.collections.get(collectionName); if (!collection || !collection.get('create')) { return false; } if (collection.get('type') !== FOLDER) { return fromCollections.selectAllowNewEntries(collection); } const limit = collection.get('limit'); if (limit === undefined || limit === null) { return true; } const isFetching = state.entries.getIn(['pages', collectionName, 'isFetching'], false); const publishedIds = state.entries.getIn(['pages', collectionName, 'ids']); if (isFetching && !publishedIds) { return false; } let entrySlugs = Set(fromEntries.selectPublishedSlugs(state.entries, collectionName)); const unpublishedSlugs = state.config?.publish_mode === EDITORIAL_WORKFLOW && state.editorialWorkflow ? fromEditorialWorkflow.selectUnpublishedSlugs(state.editorialWorkflow, collectionName) : null; if (unpublishedSlugs) { entrySlugs = entrySlugs.union(unpublishedSlugs.toArray()); } return entrySlugs.size < limit; } export function selectIntegration(state, collection, hook) { return fromIntegrations.selectIntegration(state.integrations, collection, hook); }