See Sanity in action 👀 Join us for a live product demo + Q&A →

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.io – build remarkable experiences at scale

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

Categorized in