Troubleshooting Netlify deploy plugin with Sanity V3
6 replies
Last updated: Feb 21, 2023
P
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
D
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.
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
P
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
P
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
D
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
P
Managed to hack it together
Feb 21, 2023, 2:17āÆPM
P
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.