-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(netlify-cms-widget-list): add variable type definitions to list …
…widget (#1857)
- Loading branch information
Showing
6 changed files
with
268 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
export const TYPES_KEY = 'types'; | ||
export const TYPE_KEY = 'typeKey'; | ||
export const DEFAULT_TYPE_KEY = 'type'; | ||
|
||
export function getTypedFieldForValue(field, value) { | ||
const typeKey = resolveFieldKeyType(field); | ||
const types = field.get(TYPES_KEY); | ||
const valueType = value.get(typeKey); | ||
return types.find(type => type.get('name') === valueType); | ||
} | ||
|
||
export function resolveFunctionForTypedField(field) { | ||
const typeKey = resolveFieldKeyType(field); | ||
const types = field.get(TYPES_KEY); | ||
return value => { | ||
const valueType = value.get(typeKey); | ||
return types.find(type => type.get('name') === valueType); | ||
}; | ||
} | ||
|
||
export function resolveFieldKeyType(field) { | ||
return field.get(TYPE_KEY, DEFAULT_TYPE_KEY); | ||
} | ||
|
||
export function getErrorMessageForTypedFieldAndValue(field, value) { | ||
const keyType = resolveFieldKeyType(field); | ||
const type = value.get(keyType); | ||
let errorMessage; | ||
if (!type) { | ||
errorMessage = `Error: item has no '${keyType}' property`; | ||
} else { | ||
errorMessage = `Error: item has illegal '${keyType}' property: '${type}'`; | ||
} | ||
return errorMessage; | ||
} |
Oops, something went wrong.