šŸ‘€ Our most exciting product launch yet šŸš€ Join us May 8th for Sanity Connect

Troubleshooting Netlify deploy plugin with Sanity V3

6 replies
Last updated: Feb 21, 2023
Hello šŸ‘‹ Iā€™m using structure builder to build a custom document view. Iā€™d like to render a list of documents that reference the current one Iā€™m editing. Is it possible to somehow render a ā€œdocument listā€ like with S.list().title(ā€˜Baseā€™).items(ā€¦ inside the custom view?
Feb 21, 2023, 1:21 PM
perhaps a custom document view would work for you?
So like instead of the JSON here in the image, since itā€™s a custom React component, you can query the document references and display them nicely.

Well, yeah, I donā€™t think this is what youā€™re looking for but Iā€™m just throwing here an idea.
Feb 21, 2023, 1:46 PM
yeah thatā€™s exactly my idea ā€¦ but instead of re-implementing the component of a ā€œdocument listā€ Iā€™m wondering if thereā€™s a way I can use the existing one ā€¦ if that makes sense
Feb 21, 2023, 1:47 PM
or at the very least, if there were a utility to modify the URL to open the referenced documents that would make life easier
Feb 21, 2023, 1:49 PM
really interesting use case but Iā€™m afraid I donā€™t know if thatā€™s possible. probably the Sanity folks would have more idea with this
Feb 21, 2023, 1:49 PM
Managed to hack it together
Feb 21, 2023, 2:17 PM
essentially borrowed ā€œDocumentLinkā€ from the sanity internals
import {Button, Card, Text, Flex} from '@sanity/ui'
import {IntentLink} from 'sanity/router'
import React, {useCallback} from 'react'
import {Asset as AssetType, SanityDocument} from '@sanity/types'

import {useSchema, Preview} from 'sanity'
const DocumentLink = ({document}: {document: SanityDocument}) => {
  const schema = useSchema()

  const LinkComponent = useCallback(
    (linkProps: Omit<React.HTMLProps<HTMLAnchorElement>, 'ref'>) => (
      <IntentLink {...linkProps} params={{id: document._id, type: document._type}} intent="edit" />
    ),

    [document]
  )

  return (
    <Card
      as={LinkComponent}
      paddingY={2}
      paddingX={1}
      radius={2}
      key={document._id}
      data-as="a"
      tabIndex={0}
    >
      <Flex align="center" gap={2}>
        <Preview
          layout="default"
          value={{_type: 'reference', _ref: document._id}}
          schemaType={schema.get(document._type)!}
        />
      </Flex>
    </Card>
  )
}
Feb 21, 2023, 2:18 PM

Sanityā€“ build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?