diff --git a/packages/@sanity/vision/src/components/ResultView.tsx b/packages/@sanity/vision/src/components/ResultView.tsx index 989e2fc2ec8..b6a1e4913ed 100644 --- a/packages/@sanity/vision/src/components/ResultView.tsx +++ b/packages/@sanity/vision/src/components/ResultView.tsx @@ -1,13 +1,17 @@ import JSONInspector from '@rexxars/react-json-inspector' +import {LinkIcon} from '@sanity/icons' import {Code} from '@sanity/ui' import LRU from 'quick-lru' +import {useDataset} from 'sanity' +import {IntentLink} from 'sanity/router' import {ResultViewWrapper} from './ResultView.styled' const lru = new LRU({maxSize: 50000}) -export function ResultView(props: {data: unknown}) { - const {data} = props +export function ResultView(props: {data: unknown; datasetName: string}): JSX.Element { + const {data, datasetName} = props + const workspaceDataset = useDataset() if (isRecord(data) || Array.isArray(data)) { return ( @@ -17,6 +21,7 @@ export function ResultView(props: {data: unknown}) { search={false} isExpanded={isExpanded} onClick={toggleExpanded} + interactiveLabel={workspaceDataset === datasetName ? DocumentEditLabel : undefined} /> ) @@ -25,6 +30,18 @@ export function ResultView(props: {data: unknown}) { return {JSON.stringify(data)} } +function DocumentEditLabel(props: {value: string; isKey: boolean; keypath: string}) { + if (props.isKey || (!props.keypath.endsWith('_id') && !props.keypath.endsWith('_ref'))) { + return null + } + + return ( + + + + ) +} + function isExpanded(keyPath: string, value: unknown): boolean { const depthLimit = 4 const cached = lru.get(keyPath) as boolean | undefined diff --git a/packages/@sanity/vision/src/components/VisionGui.tsx b/packages/@sanity/vision/src/components/VisionGui.tsx index 033ec675b36..985baa4437d 100644 --- a/packages/@sanity/vision/src/components/VisionGui.tsx +++ b/packages/@sanity/vision/src/components/VisionGui.tsx @@ -954,9 +954,9 @@ export class VisionGui extends PureComponent { )} {error && } - {hasResult && } + {hasResult && } {listenInProgress && listenMutations.length > 0 && ( - + )}