improvement(validation): use config schema definition for validation (#1363)
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
import { List } from 'immutable';
|
||||
import { escapeRegExp } from 'lodash';
|
||||
import { get, escapeRegExp } from 'lodash';
|
||||
import consoleError from 'Lib/consoleError';
|
||||
import { CONFIG_SUCCESS } from 'Actions/config';
|
||||
import { FILES, FOLDER } from 'Constants/collectionTypes';
|
||||
import { INFERABLE_FIELDS, IDENTIFIER_FIELDS } from 'Constants/fieldInference';
|
||||
import { formatToExtension } from 'Formats/formats';
|
||||
import { formatExtensions } from 'Formats/formats';
|
||||
|
||||
const collections = (state = null, action) => {
|
||||
switch (action.type) {
|
||||
@ -30,7 +30,7 @@ const collections = (state = null, action) => {
|
||||
const selectors = {
|
||||
[FOLDER]: {
|
||||
entryExtension(collection) {
|
||||
return (collection.get('extension') || formatToExtension(collection.get('format') || 'frontmatter')).replace(/^\./, '');
|
||||
return (collection.get('extension') || get(formatExtensions, (collection.get('format') || 'frontmatter'))).replace(/^\./, '');
|
||||
},
|
||||
fields(collection) {
|
||||
return collection.get('fields');
|
||||
@ -97,6 +97,7 @@ export const selectTemplateName = (collection, slug) => selectors[collection.get
|
||||
export const selectIdentifier = collection => {
|
||||
const fieldNames = collection.get('fields').map(field => field.get('name'));
|
||||
return IDENTIFIER_FIELDS.find(id => fieldNames.find(name => name.toLowerCase().trim() === id));
|
||||
// There must be a field whose `name` matches one of the IDENTIFIER_FIELDS.
|
||||
};
|
||||
export const selectInferedField = (collection, fieldName) => {
|
||||
const inferableField = INFERABLE_FIELDS[fieldName];
|
||||
|
Reference in New Issue
Block a user