How to use the @sanity/base/initial-value-templates.getTemplatesBySchemaType function in @sanity/base

To help you get started, we’ve selected a few @sanity/base 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 / desk-tool / src / utils / withInitialValue.js View on Github external
}

  const payload = paneContext.payload || {}
  const urlTemplate = (paneContext.params || {}).template
  const definedTemplate = props.options.template

  if (urlTemplate && definedTemplate && definedTemplate !== urlTemplate) {
    // eslint-disable-next-line no-console
    console.warn(
      `Conflicting templates: URL says "${urlTemplate}", structure node says "${definedTemplate}". Using "${definedTemplate}".`
    )
  }

  const {options = {}} = props
  const template = definedTemplate || urlTemplate
  const typeTemplates = getTemplatesBySchemaType(options.type)

  const parameters = {...options.templateParameters, ...payload}
  let templateName = template

  // If we have not specified a specific template, and we only have a single
  // template available for a schema type, use it
  if (!template && typeTemplates.length === 1) {
    templateName = typeTemplates[0].id
  }

  return {templateName, parameters}
}