refactor: convert function expressions to declarations (#4926)
This commit is contained in:
committed by
GitHub
parent
c0236536dd
commit
141a2eba56
@ -460,7 +460,9 @@ describe('collections', () => {
|
||||
],
|
||||
});
|
||||
|
||||
const updater = field => field.set('default', 'default');
|
||||
function updater(field) {
|
||||
return field.set('default', 'default');
|
||||
}
|
||||
|
||||
expect(updateFieldByKey(collection, 'non-existent', updater)).toBe(collection);
|
||||
expect(updateFieldByKey(collection, 'title', updater)).toEqual(
|
||||
|
@ -22,7 +22,7 @@ import { Backend } from '../backend';
|
||||
|
||||
const { keyToPathArray } = stringTemplate;
|
||||
|
||||
const collections = (state = null, action: CollectionsAction) => {
|
||||
function collections(state = null, action: CollectionsAction) {
|
||||
switch (action.type) {
|
||||
case CONFIG_SUCCESS: {
|
||||
const configCollections = action.payload
|
||||
@ -49,7 +49,7 @@ const collections = (state = null, action: CollectionsAction) => {
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const selectors = {
|
||||
[FOLDER]: {
|
||||
@ -120,7 +120,7 @@ const selectors = {
|
||||
},
|
||||
};
|
||||
|
||||
const getFieldsWithMediaFolders = (fields: EntryField[]) => {
|
||||
function getFieldsWithMediaFolders(fields: EntryField[]) {
|
||||
const fieldsWithMediaFolders = fields.reduce((acc, f) => {
|
||||
if (f.has('media_folder')) {
|
||||
acc = [...acc, f];
|
||||
@ -141,16 +141,16 @@ const getFieldsWithMediaFolders = (fields: EntryField[]) => {
|
||||
}, [] as EntryField[]);
|
||||
|
||||
return fieldsWithMediaFolders;
|
||||
};
|
||||
}
|
||||
|
||||
export const getFileFromSlug = (collection: Collection, slug: string) => {
|
||||
export function getFileFromSlug(collection: Collection, slug: string) {
|
||||
return collection
|
||||
.get('files')
|
||||
?.toArray()
|
||||
.find(f => f.get('name') === slug);
|
||||
};
|
||||
}
|
||||
|
||||
export const selectFieldsWithMediaFolders = (collection: Collection, slug: string) => {
|
||||
export function selectFieldsWithMediaFolders(collection: Collection, slug: string) {
|
||||
if (collection.has('folder')) {
|
||||
const fields = collection.get('fields').toArray();
|
||||
return getFieldsWithMediaFolders(fields);
|
||||
@ -163,9 +163,9 @@ export const selectFieldsWithMediaFolders = (collection: Collection, slug: strin
|
||||
}
|
||||
|
||||
return [];
|
||||
};
|
||||
}
|
||||
|
||||
export const selectMediaFolders = (state: State, collection: Collection, entry: EntryMap) => {
|
||||
export function selectMediaFolders(state: State, collection: Collection, entry: EntryMap) {
|
||||
const fields = selectFieldsWithMediaFolders(collection, entry.get('slug'));
|
||||
const folders = fields.map(f => selectMediaFolder(state.config, collection, entry, f));
|
||||
if (collection.has('files')) {
|
||||
@ -181,26 +181,41 @@ export const selectMediaFolders = (state: State, collection: Collection, entry:
|
||||
}
|
||||
|
||||
return Set(folders).toArray();
|
||||
};
|
||||
}
|
||||
|
||||
export const selectFields = (collection: Collection, slug: string) =>
|
||||
selectors[collection.get('type')].fields(collection, slug);
|
||||
export const selectFolderEntryExtension = (collection: Collection) =>
|
||||
selectors[FOLDER].entryExtension(collection);
|
||||
export const selectFileEntryLabel = (collection: Collection, slug: string) =>
|
||||
selectors[FILES].entryLabel(collection, slug);
|
||||
export const selectEntryPath = (collection: Collection, slug: string) =>
|
||||
selectors[collection.get('type')].entryPath(collection, slug);
|
||||
export const selectEntrySlug = (collection: Collection, path: string) =>
|
||||
selectors[collection.get('type')].entrySlug(collection, path);
|
||||
export const selectAllowNewEntries = (collection: Collection) =>
|
||||
selectors[collection.get('type')].allowNewEntries(collection);
|
||||
export const selectAllowDeletion = (collection: Collection) =>
|
||||
selectors[collection.get('type')].allowDeletion(collection);
|
||||
export const selectTemplateName = (collection: Collection, slug: string) =>
|
||||
selectors[collection.get('type')].templateName(collection, slug);
|
||||
export function selectFields(collection: Collection, slug: string) {
|
||||
return selectors[collection.get('type')].fields(collection, slug);
|
||||
}
|
||||
|
||||
export const getFieldsNames = (fields: EntryField[], prefix = '') => {
|
||||
export function selectFolderEntryExtension(collection: Collection) {
|
||||
return selectors[FOLDER].entryExtension(collection);
|
||||
}
|
||||
|
||||
export function selectFileEntryLabel(collection: Collection, slug: string) {
|
||||
return selectors[FILES].entryLabel(collection, slug);
|
||||
}
|
||||
|
||||
export function selectEntryPath(collection: Collection, slug: string) {
|
||||
return selectors[collection.get('type')].entryPath(collection, slug);
|
||||
}
|
||||
|
||||
export function selectEntrySlug(collection: Collection, path: string) {
|
||||
return selectors[collection.get('type')].entrySlug(collection, path);
|
||||
}
|
||||
|
||||
export function selectAllowNewEntries(collection: Collection) {
|
||||
return selectors[collection.get('type')].allowNewEntries(collection);
|
||||
}
|
||||
|
||||
export function selectAllowDeletion(collection: Collection) {
|
||||
return selectors[collection.get('type')].allowDeletion(collection);
|
||||
}
|
||||
|
||||
export function selectTemplateName(collection: Collection, slug: string) {
|
||||
return selectors[collection.get('type')].templateName(collection, slug);
|
||||
}
|
||||
|
||||
export function getFieldsNames(fields: EntryField[], prefix = '') {
|
||||
let names = fields.map(f => `${prefix}${f.get('name')}`);
|
||||
|
||||
fields.forEach((f, index) => {
|
||||
@ -217,9 +232,9 @@ export const getFieldsNames = (fields: EntryField[], prefix = '') => {
|
||||
});
|
||||
|
||||
return names;
|
||||
};
|
||||
}
|
||||
|
||||
export const selectField = (collection: Collection, key: string) => {
|
||||
export function selectField(collection: Collection, key: string) {
|
||||
const array = keyToPathArray(key);
|
||||
let name: string | undefined;
|
||||
let field;
|
||||
@ -236,13 +251,13 @@ export const selectField = (collection: Collection, key: string) => {
|
||||
}
|
||||
|
||||
return field;
|
||||
};
|
||||
}
|
||||
|
||||
export const traverseFields = (
|
||||
export function traverseFields(
|
||||
fields: List<EntryField>,
|
||||
updater: (field: EntryField) => EntryField,
|
||||
done = () => false,
|
||||
) => {
|
||||
) {
|
||||
if (done()) {
|
||||
return fields;
|
||||
}
|
||||
@ -268,20 +283,21 @@ export const traverseFields = (
|
||||
.toList() as List<EntryField>;
|
||||
|
||||
return fields;
|
||||
};
|
||||
}
|
||||
|
||||
export const updateFieldByKey = (
|
||||
export function updateFieldByKey(
|
||||
collection: Collection,
|
||||
key: string,
|
||||
updater: (field: EntryField) => EntryField,
|
||||
) => {
|
||||
) {
|
||||
const selected = selectField(collection, key);
|
||||
if (!selected) {
|
||||
return collection;
|
||||
}
|
||||
|
||||
let updated = false;
|
||||
const updateAndBreak = (f: EntryField) => {
|
||||
|
||||
function updateAndBreak(f: EntryField) {
|
||||
const field = f as EntryField;
|
||||
if (field === selected) {
|
||||
updated = true;
|
||||
@ -289,7 +305,7 @@ export const updateFieldByKey = (
|
||||
} else {
|
||||
return field;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
collection = collection.set(
|
||||
'fields',
|
||||
@ -297,18 +313,18 @@ export const updateFieldByKey = (
|
||||
);
|
||||
|
||||
return collection;
|
||||
};
|
||||
}
|
||||
|
||||
export const selectIdentifier = (collection: Collection) => {
|
||||
export function selectIdentifier(collection: Collection) {
|
||||
const identifier = collection.get('identifier_field');
|
||||
const identifierFields = identifier ? [identifier, ...IDENTIFIER_FIELDS] : IDENTIFIER_FIELDS;
|
||||
const fieldNames = getFieldsNames(collection.get('fields', List<EntryField>()).toArray());
|
||||
return identifierFields.find(id =>
|
||||
fieldNames.find(name => name?.toLowerCase().trim() === id.toLowerCase().trim()),
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export const selectInferedField = (collection: Collection, fieldName: string) => {
|
||||
export function selectInferedField(collection: Collection, fieldName: string) {
|
||||
if (fieldName === 'title' && collection.get('identifier_field')) {
|
||||
return selectIdentifier(collection);
|
||||
}
|
||||
@ -355,9 +371,9 @@ export const selectInferedField = (collection: Collection, fieldName: string) =>
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
export const selectEntryCollectionTitle = (collection: Collection, entry: EntryMap) => {
|
||||
export function selectEntryCollectionTitle(collection: Collection, entry: EntryMap) {
|
||||
// prefer formatted summary over everything else
|
||||
const summaryTemplate = collection.get('summary');
|
||||
if (summaryTemplate) return summaryFormatter(summaryTemplate, entry, collection);
|
||||
@ -372,16 +388,16 @@ export const selectEntryCollectionTitle = (collection: Collection, entry: EntryM
|
||||
const entryData = entry.get('data');
|
||||
const titleField = selectInferedField(collection, 'title');
|
||||
return titleField && entryData.getIn(keyToPathArray(titleField));
|
||||
};
|
||||
}
|
||||
|
||||
export const COMMIT_AUTHOR = 'commit_author';
|
||||
export const COMMIT_DATE = 'commit_date';
|
||||
|
||||
export const selectDefaultSortableFields = (
|
||||
export function selectDefaultSortableFields(
|
||||
collection: Collection,
|
||||
backend: Backend,
|
||||
hasIntegration: boolean,
|
||||
) => {
|
||||
) {
|
||||
let defaultSortable = SORTABLE_FIELDS.map((type: string) => {
|
||||
const field = selectInferedField(collection, type);
|
||||
if (backend.isGitBackend() && type === 'author' && !field && !hasIntegration) {
|
||||
@ -397,9 +413,9 @@ export const selectDefaultSortableFields = (
|
||||
}
|
||||
|
||||
return defaultSortable as string[];
|
||||
};
|
||||
}
|
||||
|
||||
export const selectSortableFields = (collection: Collection, t: (key: string) => string) => {
|
||||
export function selectSortableFields(collection: Collection, t: (key: string) => string) {
|
||||
const fields = collection
|
||||
.get('sortable_fields')
|
||||
.toArray()
|
||||
@ -418,9 +434,9 @@ export const selectSortableFields = (collection: Collection, t: (key: string) =>
|
||||
.map(item => ({ ...item.field, key: item.key }));
|
||||
|
||||
return fields;
|
||||
};
|
||||
}
|
||||
|
||||
export const selectSortDataPath = (collection: Collection, key: string) => {
|
||||
export function selectSortDataPath(collection: Collection, key: string) {
|
||||
if (key === COMMIT_DATE) {
|
||||
return 'updatedOn';
|
||||
} else if (key === COMMIT_AUTHOR && !selectField(collection, key)) {
|
||||
@ -428,19 +444,19 @@ export const selectSortDataPath = (collection: Collection, key: string) => {
|
||||
} else {
|
||||
return `data.${key}`;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const selectViewFilters = (collection: Collection) => {
|
||||
export function selectViewFilters(collection: Collection) {
|
||||
const viewFilters = collection.get('view_filters').toJS() as ViewFilter[];
|
||||
return viewFilters;
|
||||
};
|
||||
}
|
||||
|
||||
export const selectViewGroups = (collection: Collection) => {
|
||||
export function selectViewGroups(collection: Collection) {
|
||||
const viewGroups = collection.get('view_groups').toJS() as ViewGroup[];
|
||||
return viewGroups;
|
||||
};
|
||||
}
|
||||
|
||||
export const selectFieldsComments = (collection: Collection, entryMap: EntryMap) => {
|
||||
export function selectFieldsComments(collection: Collection, entryMap: EntryMap) {
|
||||
let fields: EntryField[] = [];
|
||||
if (collection.has('folder')) {
|
||||
fields = collection.get('fields').toArray();
|
||||
@ -458,15 +474,15 @@ export const selectFieldsComments = (collection: Collection, entryMap: EntryMap)
|
||||
});
|
||||
|
||||
return comments;
|
||||
};
|
||||
}
|
||||
|
||||
export const selectHasMetaPath = (collection: Collection) => {
|
||||
export function selectHasMetaPath(collection: Collection) {
|
||||
return (
|
||||
collection.has('folder') &&
|
||||
collection.get('type') === FOLDER &&
|
||||
collection.has('meta') &&
|
||||
collection.get('meta')?.has('path')
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export default collections;
|
||||
|
@ -3,12 +3,12 @@ import { connectRouter } from 'connected-react-router';
|
||||
import { reducer as notifReducer } from 'redux-notifications';
|
||||
import reducers from './index';
|
||||
|
||||
const createRootReducer = history => {
|
||||
function createRootReducer(history) {
|
||||
return combineReducers({
|
||||
...reducers,
|
||||
notifs: notifReducer,
|
||||
router: connectRouter(history),
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export default createRootReducer;
|
||||
|
@ -5,7 +5,7 @@ import { EDITORIAL_WORKFLOW } from '../constants/publishModes';
|
||||
|
||||
const defaultState: Map<string, boolean | string> = Map({ isFetching: true });
|
||||
|
||||
const config = (state = defaultState, action: ConfigAction) => {
|
||||
function config(state = defaultState, action: ConfigAction) {
|
||||
switch (action.type) {
|
||||
case CONFIG_REQUEST:
|
||||
return state.set('isFetching', true);
|
||||
@ -24,11 +24,14 @@ const config = (state = defaultState, action: ConfigAction) => {
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const selectLocale = (state: Config) => state.get('locale', 'en') as string;
|
||||
export function selectLocale(state: Config) {
|
||||
return state.get('locale', 'en') as string;
|
||||
}
|
||||
|
||||
export const selectUseWorkflow = (state: Config) =>
|
||||
state.get('publish_mode') === EDITORIAL_WORKFLOW;
|
||||
export function selectUseWorkflow(state: Config) {
|
||||
return state.get('publish_mode') === EDITORIAL_WORKFLOW;
|
||||
}
|
||||
|
||||
export default config;
|
||||
|
@ -10,10 +10,11 @@ import {
|
||||
// Since pagination can be used for a variety of views (collections
|
||||
// and searches are the most common examples), we namespace cursors by
|
||||
// their type before storing them in the state.
|
||||
export const selectCollectionEntriesCursor = (state, collectionName) =>
|
||||
new Cursor(state.getIn(['cursorsByType', 'collectionEntries', collectionName]));
|
||||
export function selectCollectionEntriesCursor(state, collectionName) {
|
||||
return new Cursor(state.getIn(['cursorsByType', 'collectionEntries', collectionName]));
|
||||
}
|
||||
|
||||
const cursors = (state = fromJS({ cursorsByType: { collectionEntries: {} } }), action) => {
|
||||
function cursors(state = fromJS({ cursorsByType: { collectionEntries: {} } }), action) {
|
||||
switch (action.type) {
|
||||
case ENTRIES_SUCCESS: {
|
||||
return state.setIn(
|
||||
@ -29,6 +30,6 @@ const cursors = (state = fromJS({ cursorsByType: { collectionEntries: {} } }), a
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default cursors;
|
||||
|
@ -5,7 +5,7 @@ import {
|
||||
DEPLOY_PREVIEW_FAILURE,
|
||||
} from 'Actions/deploys';
|
||||
|
||||
const deploys = (state = Map({ deploys: Map() }), action) => {
|
||||
function deploys(state = Map({ deploys: Map() }), action) {
|
||||
switch (action.type) {
|
||||
case DEPLOY_PREVIEW_REQUEST: {
|
||||
const { collection, slug } = action.payload;
|
||||
@ -37,9 +37,10 @@ const deploys = (state = Map({ deploys: Map() }), action) => {
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const selectDeployPreview = (state, collection, slug) =>
|
||||
state.getIn(['deploys', `${collection}.${slug}`]);
|
||||
export function selectDeployPreview(state, collection, slug) {
|
||||
return state.getIn(['deploys', `${collection}.${slug}`]);
|
||||
}
|
||||
|
||||
export default deploys;
|
||||
|
@ -21,7 +21,7 @@ import {
|
||||
import { CONFIG_SUCCESS } from '../actions/config';
|
||||
import { EditorialWorkflowAction, EditorialWorkflow, Entities } from '../types/redux';
|
||||
|
||||
const unpublishedEntries = (state = Map(), action: EditorialWorkflowAction) => {
|
||||
function unpublishedEntries(state = Map(), action: EditorialWorkflowAction) {
|
||||
switch (action.type) {
|
||||
case CONFIG_SUCCESS: {
|
||||
const publishMode = action.payload && action.payload.get('publish_mode');
|
||||
@ -137,27 +137,25 @@ const unpublishedEntries = (state = Map(), action: EditorialWorkflowAction) => {
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const selectUnpublishedEntry = (
|
||||
state: EditorialWorkflow,
|
||||
collection: string,
|
||||
slug: string,
|
||||
) => state && state.getIn(['entities', `${collection}.${slug}`]);
|
||||
export function selectUnpublishedEntry(state: EditorialWorkflow, collection: string, slug: string) {
|
||||
return state && state.getIn(['entities', `${collection}.${slug}`]);
|
||||
}
|
||||
|
||||
export const selectUnpublishedEntriesByStatus = (state: EditorialWorkflow, status: string) => {
|
||||
export function selectUnpublishedEntriesByStatus(state: EditorialWorkflow, status: string) {
|
||||
if (!state) return null;
|
||||
const entities = state.get('entities') as Entities;
|
||||
return entities.filter(entry => entry.get('status') === status).valueSeq();
|
||||
};
|
||||
}
|
||||
|
||||
export const selectUnpublishedSlugs = (state: EditorialWorkflow, collection: string) => {
|
||||
export function selectUnpublishedSlugs(state: EditorialWorkflow, collection: string) {
|
||||
if (!state.get('entities')) return null;
|
||||
const entities = state.get('entities') as Entities;
|
||||
return entities
|
||||
.filter((_v, k) => startsWith(k as string, `${collection}.`))
|
||||
.map(entry => entry.get('slug'))
|
||||
.valueSeq();
|
||||
};
|
||||
}
|
||||
|
||||
export default unpublishedEntries;
|
||||
|
@ -95,11 +95,11 @@ const loadSort = once(() => {
|
||||
return Map() as Sort;
|
||||
});
|
||||
|
||||
const clearSort = () => {
|
||||
function clearSort() {
|
||||
localStorage.removeItem(storageSortKey);
|
||||
};
|
||||
}
|
||||
|
||||
const persistSort = (sort: Sort | undefined) => {
|
||||
function persistSort(sort: Sort | undefined) {
|
||||
if (sort) {
|
||||
const storageSort: StorageSort = {};
|
||||
sort.keySeq().forEach(key => {
|
||||
@ -117,7 +117,7 @@ const persistSort = (sort: Sort | undefined) => {
|
||||
} else {
|
||||
clearSort();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const loadViewStyle = once(() => {
|
||||
const viewStyle = localStorage.getItem(viewStyleKey);
|
||||
@ -129,22 +129,22 @@ const loadViewStyle = once(() => {
|
||||
return VIEW_STYLE_LIST;
|
||||
});
|
||||
|
||||
const clearViewStyle = () => {
|
||||
function clearViewStyle() {
|
||||
localStorage.removeItem(viewStyleKey);
|
||||
};
|
||||
}
|
||||
|
||||
const persistViewStyle = (viewStyle: string | undefined) => {
|
||||
function persistViewStyle(viewStyle: string | undefined) {
|
||||
if (viewStyle) {
|
||||
localStorage.setItem(viewStyleKey, viewStyle);
|
||||
} else {
|
||||
clearViewStyle();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const entries = (
|
||||
function entries(
|
||||
state = Map({ entities: Map(), pages: Map(), sort: loadSort(), viewStyle: loadViewStyle() }),
|
||||
action: EntriesAction,
|
||||
) => {
|
||||
) {
|
||||
switch (action.type) {
|
||||
case ENTRY_REQUEST: {
|
||||
const payload = action.payload as EntryRequestPayload;
|
||||
@ -344,30 +344,30 @@ const entries = (
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const selectEntriesSort = (entries: Entries, collection: string) => {
|
||||
export function selectEntriesSort(entries: Entries, collection: string) {
|
||||
const sort = entries.get('sort') as Sort | undefined;
|
||||
return sort?.get(collection);
|
||||
};
|
||||
}
|
||||
|
||||
export const selectEntriesFilter = (entries: Entries, collection: string) => {
|
||||
export function selectEntriesFilter(entries: Entries, collection: string) {
|
||||
const filter = entries.get('filter') as Filter | undefined;
|
||||
return filter?.get(collection) || Map();
|
||||
};
|
||||
}
|
||||
|
||||
export const selectEntriesGroup = (entries: Entries, collection: string) => {
|
||||
export function selectEntriesGroup(entries: Entries, collection: string) {
|
||||
const group = entries.get('group') as Group | undefined;
|
||||
return group?.get(collection) || Map();
|
||||
};
|
||||
}
|
||||
|
||||
export const selectEntriesGroupField = (entries: Entries, collection: string) => {
|
||||
export function selectEntriesGroupField(entries: Entries, collection: string) {
|
||||
const groups = selectEntriesGroup(entries, collection);
|
||||
const value = groups?.valueSeq().find(v => v?.get('active') === true);
|
||||
return value;
|
||||
};
|
||||
}
|
||||
|
||||
export const selectEntriesSortFields = (entries: Entries, collection: string) => {
|
||||
export function selectEntriesSortFields(entries: Entries, collection: string) {
|
||||
const sort = selectEntriesSort(entries, collection);
|
||||
const values =
|
||||
sort
|
||||
@ -376,9 +376,9 @@ export const selectEntriesSortFields = (entries: Entries, collection: string) =>
|
||||
.toArray() || [];
|
||||
|
||||
return values;
|
||||
};
|
||||
}
|
||||
|
||||
export const selectEntriesFilterFields = (entries: Entries, collection: string) => {
|
||||
export function selectEntriesFilterFields(entries: Entries, collection: string) {
|
||||
const filter = selectEntriesFilter(entries, collection);
|
||||
const values =
|
||||
filter
|
||||
@ -386,27 +386,29 @@ export const selectEntriesFilterFields = (entries: Entries, collection: string)
|
||||
.filter(v => v?.get('active') === true)
|
||||
.toArray() || [];
|
||||
return values;
|
||||
};
|
||||
}
|
||||
|
||||
export const selectViewStyle = (entries: Entries) => {
|
||||
export function selectViewStyle(entries: Entries) {
|
||||
return entries.get('viewStyle');
|
||||
};
|
||||
}
|
||||
|
||||
export const selectEntry = (state: Entries, collection: string, slug: string) =>
|
||||
state.getIn(['entities', `${collection}.${slug}`]);
|
||||
export function selectEntry(state: Entries, collection: string, slug: string) {
|
||||
return state.getIn(['entities', `${collection}.${slug}`]);
|
||||
}
|
||||
|
||||
export const selectPublishedSlugs = (state: Entries, collection: string) =>
|
||||
state.getIn(['pages', collection, 'ids'], List<string>());
|
||||
export function selectPublishedSlugs(state: Entries, collection: string) {
|
||||
return state.getIn(['pages', collection, 'ids'], List<string>());
|
||||
}
|
||||
|
||||
const getPublishedEntries = (state: Entries, collectionName: string) => {
|
||||
function getPublishedEntries(state: Entries, collectionName: string) {
|
||||
const slugs = selectPublishedSlugs(state, collectionName);
|
||||
const entries =
|
||||
slugs &&
|
||||
(slugs.map(slug => selectEntry(state, collectionName, slug as string)) as List<EntryMap>);
|
||||
return entries;
|
||||
};
|
||||
}
|
||||
|
||||
export const selectEntries = (state: Entries, collection: Collection) => {
|
||||
export function selectEntries(state: Entries, collection: Collection) {
|
||||
const collectionName = collection.get('name');
|
||||
let entries = getPublishedEntries(state, collectionName);
|
||||
|
||||
@ -438,9 +440,9 @@ export const selectEntries = (state: Entries, collection: Collection) => {
|
||||
}
|
||||
|
||||
return entries;
|
||||
};
|
||||
}
|
||||
|
||||
const getGroup = (entry: EntryMap, selectedGroup: GroupMap) => {
|
||||
function getGroup(entry: EntryMap, selectedGroup: GroupMap) {
|
||||
const label = selectedGroup.get('label');
|
||||
const field = selectedGroup.get('field');
|
||||
|
||||
@ -478,9 +480,9 @@ const getGroup = (entry: EntryMap, selectedGroup: GroupMap) => {
|
||||
label,
|
||||
value: typeof fieldData === 'boolean' ? fieldData : dataAsString,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export const selectGroups = (state: Entries, collection: Collection) => {
|
||||
export function selectGroups(state: Entries, collection: Collection) {
|
||||
const collectionName = collection.get('name');
|
||||
const entries = getPublishedEntries(state, collectionName);
|
||||
|
||||
@ -507,37 +509,37 @@ export const selectGroups = (state: Entries, collection: Collection) => {
|
||||
});
|
||||
|
||||
return groupsArray;
|
||||
};
|
||||
}
|
||||
|
||||
export const selectEntryByPath = (state: Entries, collection: string, path: string) => {
|
||||
export function selectEntryByPath(state: Entries, collection: string, path: string) {
|
||||
const slugs = selectPublishedSlugs(state, collection);
|
||||
const entries =
|
||||
slugs && (slugs.map(slug => selectEntry(state, collection, slug as string)) as List<EntryMap>);
|
||||
|
||||
return entries && entries.find(e => e?.get('path') === path);
|
||||
};
|
||||
}
|
||||
|
||||
export const selectEntriesLoaded = (state: Entries, collection: string) => {
|
||||
export function selectEntriesLoaded(state: Entries, collection: string) {
|
||||
return !!state.getIn(['pages', collection]);
|
||||
};
|
||||
}
|
||||
|
||||
export const selectIsFetching = (state: Entries, collection: string) => {
|
||||
export function selectIsFetching(state: Entries, collection: string) {
|
||||
return state.getIn(['pages', collection, 'isFetching'], false);
|
||||
};
|
||||
}
|
||||
|
||||
const DRAFT_MEDIA_FILES = 'DRAFT_MEDIA_FILES';
|
||||
|
||||
const getFileField = (collectionFiles: CollectionFiles, slug: string | undefined) => {
|
||||
function getFileField(collectionFiles: CollectionFiles, slug: string | undefined) {
|
||||
const file = collectionFiles.find(f => f?.get('name') === slug);
|
||||
return file;
|
||||
};
|
||||
}
|
||||
|
||||
const hasCustomFolder = (
|
||||
function hasCustomFolder(
|
||||
folderKey: 'media_folder' | 'public_folder',
|
||||
collection: Collection | null,
|
||||
slug: string | undefined,
|
||||
field: EntryField | undefined,
|
||||
) => {
|
||||
) {
|
||||
if (!collection) {
|
||||
return false;
|
||||
}
|
||||
@ -558,9 +560,9 @@ const hasCustomFolder = (
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
const traverseFields = (
|
||||
function traverseFields(
|
||||
folderKey: 'media_folder' | 'public_folder',
|
||||
config: Config,
|
||||
collection: Collection,
|
||||
@ -568,7 +570,7 @@ const traverseFields = (
|
||||
field: EntryField,
|
||||
fields: EntryField[],
|
||||
currentFolder: string,
|
||||
): string | null => {
|
||||
): string | null {
|
||||
const matchedField = fields.filter(f => f === field)[0];
|
||||
if (matchedField) {
|
||||
return folderFormatter(
|
||||
@ -632,15 +634,15 @@ const traverseFields = (
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
const evaluateFolder = (
|
||||
function evaluateFolder(
|
||||
folderKey: 'media_folder' | 'public_folder',
|
||||
config: Config,
|
||||
collection: Collection,
|
||||
entryMap: EntryMap | undefined,
|
||||
field: EntryField | undefined,
|
||||
) => {
|
||||
) {
|
||||
let currentFolder = config.get(folderKey);
|
||||
|
||||
// add identity template if doesn't exist
|
||||
@ -723,14 +725,14 @@ const evaluateFolder = (
|
||||
}
|
||||
|
||||
return currentFolder;
|
||||
};
|
||||
}
|
||||
|
||||
export const selectMediaFolder = (
|
||||
export function selectMediaFolder(
|
||||
config: Config,
|
||||
collection: Collection | null,
|
||||
entryMap: EntryMap | undefined,
|
||||
field: EntryField | undefined,
|
||||
) => {
|
||||
) {
|
||||
const name = 'media_folder';
|
||||
let mediaFolder = config.get(name);
|
||||
|
||||
@ -750,15 +752,15 @@ export const selectMediaFolder = (
|
||||
}
|
||||
|
||||
return trim(mediaFolder, '/');
|
||||
};
|
||||
}
|
||||
|
||||
export const selectMediaFilePath = (
|
||||
export function selectMediaFilePath(
|
||||
config: Config,
|
||||
collection: Collection | null,
|
||||
entryMap: EntryMap | undefined,
|
||||
mediaPath: string,
|
||||
field: EntryField | undefined,
|
||||
) => {
|
||||
) {
|
||||
if (isAbsolutePath(mediaPath)) {
|
||||
return mediaPath;
|
||||
}
|
||||
@ -766,15 +768,15 @@ export const selectMediaFilePath = (
|
||||
const mediaFolder = selectMediaFolder(config, collection, entryMap, field);
|
||||
|
||||
return join(mediaFolder, basename(mediaPath));
|
||||
};
|
||||
}
|
||||
|
||||
export const selectMediaFilePublicPath = (
|
||||
export function selectMediaFilePublicPath(
|
||||
config: Config,
|
||||
collection: Collection | null,
|
||||
mediaPath: string,
|
||||
entryMap: EntryMap | undefined,
|
||||
field: EntryField | undefined,
|
||||
) => {
|
||||
) {
|
||||
if (isAbsolutePath(mediaPath)) {
|
||||
return mediaPath;
|
||||
}
|
||||
@ -789,12 +791,12 @@ export const selectMediaFilePublicPath = (
|
||||
}
|
||||
|
||||
return join(publicFolder, basename(mediaPath));
|
||||
};
|
||||
}
|
||||
|
||||
export const selectEditingDraft = (state: EntryDraft) => {
|
||||
export function selectEditingDraft(state: EntryDraft) {
|
||||
const entry = state.get('entry');
|
||||
const workflowDraft = entry && !entry.isEmpty();
|
||||
return workflowDraft;
|
||||
};
|
||||
}
|
||||
|
||||
export default entries;
|
||||
|
@ -35,7 +35,7 @@ const initialState = Map({
|
||||
key: '',
|
||||
});
|
||||
|
||||
const entryDraftReducer = (state = Map(), action) => {
|
||||
function entryDraftReducer(state = Map(), action) {
|
||||
switch (action.type) {
|
||||
case DRAFT_CREATE_FROM_ENTRY:
|
||||
// Existing Entry
|
||||
@ -180,9 +180,9 @@ const entryDraftReducer = (state = Map(), action) => {
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const selectCustomPath = (collection, entryDraft) => {
|
||||
export function selectCustomPath(collection, entryDraft) {
|
||||
if (!selectHasMetaPath(collection)) {
|
||||
return;
|
||||
}
|
||||
@ -192,6 +192,6 @@ export const selectCustomPath = (collection, entryDraft) => {
|
||||
const extension = selectFolderEntryExtension(collection);
|
||||
const customPath = path && join(collection.get('folder'), path, `${indexFile}.${extension}`);
|
||||
return customPath;
|
||||
};
|
||||
}
|
||||
|
||||
export default entryDraftReducer;
|
||||
|
@ -8,12 +8,14 @@ const LOADING_IGNORE_LIST = [
|
||||
'STATUS_FAILURE',
|
||||
];
|
||||
|
||||
const ignoreWhenLoading = action => LOADING_IGNORE_LIST.some(type => action.type.includes(type));
|
||||
function ignoreWhenLoading(action) {
|
||||
return LOADING_IGNORE_LIST.some(type => action.type.includes(type));
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Reducer for some global UI state that we want to share between components
|
||||
* */
|
||||
const globalUI = (state = Map({ isFetching: false, useOpenAuthoring: false }), action) => {
|
||||
*/
|
||||
function globalUI(state = Map({ isFetching: false, useOpenAuthoring: false }), action) {
|
||||
// Generic, global loading indicator
|
||||
if (!ignoreWhenLoading(action) && action.type.includes('REQUEST')) {
|
||||
return state.set('isFetching', true);
|
||||
@ -26,6 +28,6 @@ const globalUI = (state = Map({ isFetching: false, useOpenAuthoring: false }), a
|
||||
return state.set('useOpenAuthoring', true);
|
||||
}
|
||||
return state;
|
||||
};
|
||||
}
|
||||
|
||||
export default globalUI;
|
||||
|
@ -37,16 +37,19 @@ export default reducers;
|
||||
/*
|
||||
* Selectors
|
||||
*/
|
||||
export const selectEntry = (state: State, collection: string, slug: string) =>
|
||||
fromEntries.selectEntry(state.entries, collection, slug);
|
||||
export function selectEntry(state: State, collection: string, slug: string) {
|
||||
return fromEntries.selectEntry(state.entries, collection, slug);
|
||||
}
|
||||
|
||||
export const selectEntries = (state: State, collection: Collection) =>
|
||||
fromEntries.selectEntries(state.entries, collection);
|
||||
export function selectEntries(state: State, collection: Collection) {
|
||||
return fromEntries.selectEntries(state.entries, collection);
|
||||
}
|
||||
|
||||
export const selectPublishedSlugs = (state: State, collection: string) =>
|
||||
fromEntries.selectPublishedSlugs(state.entries, collection);
|
||||
export function selectPublishedSlugs(state: State, collection: string) {
|
||||
return fromEntries.selectPublishedSlugs(state.entries, collection);
|
||||
}
|
||||
|
||||
export const selectSearchedEntries = (state: State, availableCollections: string[]) => {
|
||||
export function selectSearchedEntries(state: State, availableCollections: string[]) {
|
||||
const searchItems = state.search.get('entryIds');
|
||||
// only return search results for actually available collections
|
||||
return (
|
||||
@ -55,19 +58,24 @@ export const selectSearchedEntries = (state: State, availableCollections: string
|
||||
.filter(({ collection }) => availableCollections.indexOf(collection) !== -1)
|
||||
.map(({ collection, slug }) => fromEntries.selectEntry(state.entries, collection, slug))
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export const selectDeployPreview = (state: State, collection: string, slug: string) =>
|
||||
fromDeploys.selectDeployPreview(state.deploys, collection, slug);
|
||||
export function selectDeployPreview(state: State, collection: string, slug: string) {
|
||||
return fromDeploys.selectDeployPreview(state.deploys, collection, slug);
|
||||
}
|
||||
|
||||
export const selectUnpublishedEntry = (state: State, collection: string, slug: string) =>
|
||||
fromEditorialWorkflow.selectUnpublishedEntry(state.editorialWorkflow, collection, slug);
|
||||
export function selectUnpublishedEntry(state: State, collection: string, slug: string) {
|
||||
return fromEditorialWorkflow.selectUnpublishedEntry(state.editorialWorkflow, collection, slug);
|
||||
}
|
||||
|
||||
export const selectUnpublishedEntriesByStatus = (state: State, status: Status) =>
|
||||
fromEditorialWorkflow.selectUnpublishedEntriesByStatus(state.editorialWorkflow, status);
|
||||
export function selectUnpublishedEntriesByStatus(state: State, status: Status) {
|
||||
return fromEditorialWorkflow.selectUnpublishedEntriesByStatus(state.editorialWorkflow, status);
|
||||
}
|
||||
|
||||
export const selectUnpublishedSlugs = (state: State, collection: string) =>
|
||||
fromEditorialWorkflow.selectUnpublishedSlugs(state.editorialWorkflow, collection);
|
||||
export function selectUnpublishedSlugs(state: State, collection: string) {
|
||||
return fromEditorialWorkflow.selectUnpublishedSlugs(state.editorialWorkflow, collection);
|
||||
}
|
||||
|
||||
export const selectIntegration = (state: State, collection: string | null, hook: string) =>
|
||||
fromIntegrations.selectIntegration(state.integrations, collection, hook);
|
||||
export function selectIntegration(state: State, collection: string | null, hook: string) {
|
||||
return fromIntegrations.selectIntegration(state.integrations, collection, hook);
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ interface Acc {
|
||||
hooks: Record<string, string | Record<string, string>>;
|
||||
}
|
||||
|
||||
export const getIntegrations = (config: Config) => {
|
||||
export function getIntegrations(config: Config) {
|
||||
const integrations: Integration[] = config.get('integrations', List()).toJS() || [];
|
||||
const newState = integrations.reduce(
|
||||
(acc, integration) => {
|
||||
@ -38,9 +38,9 @@ export const getIntegrations = (config: Config) => {
|
||||
{ providers: {}, hooks: {} } as Acc,
|
||||
);
|
||||
return fromJS(newState);
|
||||
};
|
||||
}
|
||||
|
||||
const integrations = (state = null, action: IntegrationsAction): Integrations | null => {
|
||||
function integrations(state = null, action: IntegrationsAction): Integrations | null {
|
||||
switch (action.type) {
|
||||
case CONFIG_SUCCESS: {
|
||||
return getIntegrations(action.payload);
|
||||
@ -48,11 +48,12 @@ const integrations = (state = null, action: IntegrationsAction): Integrations |
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const selectIntegration = (state: Integrations, collection: string | null, hook: string) =>
|
||||
collection
|
||||
export function selectIntegration(state: Integrations, collection: string | null, hook: string) {
|
||||
return collection
|
||||
? state.getIn(['hooks', collection, hook], false)
|
||||
: state.getIn(['hooks', hook], false);
|
||||
}
|
||||
|
||||
export default integrations;
|
||||
|
@ -51,7 +51,7 @@ const defaultState: {
|
||||
config: Map(),
|
||||
};
|
||||
|
||||
const mediaLibrary = (state = Map(defaultState), action: MediaLibraryAction) => {
|
||||
function mediaLibrary(state = Map(defaultState), action: MediaLibraryAction) {
|
||||
switch (action.type) {
|
||||
case MEDIA_LIBRARY_CREATE:
|
||||
return state.withMutations(map => {
|
||||
@ -213,7 +213,7 @@ const mediaLibrary = (state = Map(defaultState), action: MediaLibraryAction) =>
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function selectMediaFiles(state: State, field?: EntryField) {
|
||||
const { mediaLibrary, entryDraft } = state;
|
||||
|
@ -57,7 +57,8 @@ const medias = produce((state: Medias, action: MediasAction) => {
|
||||
}
|
||||
}, defaultState);
|
||||
|
||||
export const selectIsLoadingAsset = (state: Medias) =>
|
||||
Object.values(state).some(state => state.isLoading);
|
||||
export function selectIsLoadingAsset(state: Medias) {
|
||||
return Object.values(state).some(state => state.isLoading);
|
||||
}
|
||||
|
||||
export default medias;
|
||||
|
@ -23,7 +23,7 @@ const defaultState = Map({
|
||||
queryHits: Map({}),
|
||||
});
|
||||
|
||||
const entries = (state = defaultState, action) => {
|
||||
function entries(state = defaultState, action) {
|
||||
switch (action.type) {
|
||||
case SEARCH_CLEAR:
|
||||
return defaultState;
|
||||
@ -84,6 +84,6 @@ const entries = (state = defaultState, action) => {
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export default entries;
|
||||
|
Reference in New Issue
Block a user