How to use the @sanity/util/paths.get function in @sanity/util

To help you get started, we’ve selected a few @sanity/util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sanity-io / sanity / packages / @sanity / form-builder / src / inputs / Slug / SlugInput.tsx View on Github external
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}))
github sanity-io / sanity / packages / @sanity / form-builder / src / inputs / ReferenceInput / ReferenceInput.tsx View on Github external
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) => {
github sanity-io / sanity / packages / @sanity / form-builder / src / inputs / Slug / SlugInput.tsx View on Github external
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() {
github sanity-io / sanity / packages / @sanity / form-builder / src / inputs / Slug / SlugInput.tsx View on Github external
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() {
github sanity-io / sanity / packages / @sanity / form-builder / src / inputs / Slug / SlugInput.tsx View on Github external
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) {
github sanity-io / sanity / packages / @sanity / form-builder / src / inputs / Slug / SlugInput.tsx View on Github external
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() {