Skip to content

Commit

Permalink
[schema] Deprecate slugifyFn (now called slugify)
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Feb 28, 2018
1 parent 03b7d93 commit 1c857ac
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/@sanity/schema/src/sanity/validateSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import traverseSchema from './traverseSchema'
import object from './validation/types/object'
import reference from './validation/types/reference'
import array from './validation/types/array'
import slug from './validation/types/slug'
import common from './validation/types/common'
import rootType from './validation/types/rootType'

const typeVisitors = {
array,
object,
slug,
document: object,
reference: reference
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export const HELP_IDS = {
ARRAY_OF_INVALID: 'schema-array-of-invalid',
ARRAY_OF_NOT_UNIQUE: 'schema-array-of-invalid',
REFERENCE_TO_INVALID: 'schema-reference-to-invalid',
REFERENCE_TO_NOT_UNIQUE: 'schema-reference-to-invalid'
REFERENCE_TO_NOT_UNIQUE: 'schema-reference-to-invalid',
SLUG_SLUGIFY_FN_RENAMED: 'slug-slugifyfn-renamed'
}

function createValidationResult(
Expand Down
21 changes: 21 additions & 0 deletions packages/@sanity/schema/src/sanity/validation/types/slug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {warning, HELP_IDS} from '../createValidationResult'

export default (typeDef, visitorContext) => {
const problems = []

if (typeDef.options && typeDef.options.slugifyFn) {
problems.push(
warning(
'Heads up! The "slugifyFn" option has been renamed to "slugify".',
HELP_IDS.SLUG_SLUGIFY_FN_RENAMED
)
)

typeDef.options.slugify = typeDef.options.slugifyFn
}

return {
...typeDef,
_problems: problems
}
}
16 changes: 16 additions & 0 deletions packages/test-studio/schemas/slugs.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ export default {
checkUnique: value => /^hei/i.test(value)
}
},
{
name: 'deprecatedSlugifyFnField',
type: 'slug',
title: 'Slug field using deprecated "slugifyFn" option',
description: 'Should warn the developer about deprecated field',
options: {
source: 'title',
slugifyFn: value =>
value
.toLocaleLowerCase()
.split('')
.reverse()
.join('')
.replace(/\s+/g, '-')
}
},
{
name: 'nested',
type: 'object',
Expand Down

0 comments on commit 1c857ac

Please sign in to comment.