Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
handleGenerateSlug = () => {
const {type} = this.props
const source = get(type, ['options', 'source'])
if (!source) {
// eslint-disable-next-line no-console
console.error(`Source is missing. Check source on type "${type.name}" in schema`)
return
}
const newFromSource = this.getNewFromSource()
this.setState({loading: true})
this.slugify(newFromSource || '')
.then(newSlug => this.updateCurrent(newSlug))
.catch(err => {
// eslint-disable-next-line no-console
console.error(
`An error occured while slugifying "${newFromSource}":\n${err.message}\n${err.stack}`
)
})
.then(() => this._isMounted && this.setState({loading: false}))
resolveUserDefinedFilter = (): SearchOptions => {
const {type, document, getValuePath} = this.props
const options = type.options
if (!options) {
return {}
}
const {filter, filterParams: params} = options
if (typeof filter === 'function') {
const parentPath = getValuePath().slice(0, -1)
const parent = get(document, parentPath)
return filter({document, parentPath, parent})
}
return {filter, params}
}
search = (query: string) => {
getNewFromSource = () => {
const {getValuePath, type, document} = this.props
const parentPath = getValuePath().slice(0, -1)
const parent = get(document, parentPath)
const source = get(type, ['options', 'source'], [])
return typeof source === 'function'
? source(document, {parentPath, parent})
: get(document, source)
}
render() {
getNewFromSource = () => {
const {getValuePath, type, document} = this.props
const parentPath = getValuePath().slice(0, -1)
const parent = get(document, parentPath)
const source = get(type, ['options', 'source'], [])
return typeof source === 'function'
? source(document, {parentPath, parent})
: get(document, source)
}
render() {
slugify(sourceValue) {
if (!sourceValue) {
return Promise.resolve(sourceValue)
}
const {type} = this.props
const slugify = get(type, ['options', 'slugify'], defaultSlugify)
return Promise.resolve(slugify(sourceValue, type))
}
UNSAFE_componentWillReceiveProps(nextProps) {
getNewFromSource = () => {
const {getValuePath, type, document} = this.props
const parentPath = getValuePath().slice(0, -1)
const parent = get(document, parentPath)
const source = get(type, ['options', 'source'], [])
return typeof source === 'function'
? source(document, {parentPath, parent})
: get(document, source)
}
render() {