Skip to content

Commit

Permalink
[field] Use Sanity preview component for fallback diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Oct 6, 2020
1 parent 0bd7850 commit 3e96d6b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 32 deletions.
3 changes: 1 addition & 2 deletions packages/@sanity/field/src/diff/changes/FieldChange.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {useDocumentOperation} from '@sanity/react-hooks'
import React, {useCallback, useContext} from 'react'
import {FieldChangeNode, OperationsAPI} from '../../types'
import {FallbackDiff} from '../fallback/FallbackDiff'
import {ChangeHeader} from './ChangeHeader'
import {DiffErrorBoundary} from './DiffErrorBoundary'
import {DocumentChangeContext} from './DocumentChangeContext'
Expand All @@ -10,8 +11,6 @@ import {undoChange} from './undoChange'
import styles from './FieldChange.css'
import {ValueError} from './ValueError'

const FallbackDiff = () => <div>Missing diff</div>

export function FieldChange({change}: {change: FieldChangeNode}): React.ReactElement {
const DiffComponent = change.diffComponent || FallbackDiff
const {documentId, schemaType} = useContext(DocumentChangeContext)
Expand Down
6 changes: 0 additions & 6 deletions packages/@sanity/field/src/diff/fallback/FallbackDiff.css

This file was deleted.

37 changes: 13 additions & 24 deletions packages/@sanity/field/src/diff/fallback/FallbackDiff.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
import * as React from 'react'
import React from 'react'
import Preview from 'part:@sanity/base/preview'
import {DiffComponent} from '../../types'
import {Change} from '../components'

import styles from './FallbackDiff.css'
function FallbackPreview({value, schemaType}) {
return <Preview type={schemaType} value={value} layout="default" />
}

export const FallbackDiff: DiffComponent = ({diff}) => {
export const FallbackDiff: DiffComponent<any> = ({diff, schemaType}) => {
return (
<div className={styles.root}>
<div>
<strong>
Missing diff component (<code>{diff.type}</code>)
</strong>
</div>

<details>
<summary>JSON</summary>

<h2>From</h2>
<pre>
<code>{JSON.stringify(diff.fromValue, null, 2)}</code>
</pre>

<h2>To</h2>
<pre>
<code>{JSON.stringify(diff.toValue, null, 2)}</code>
</pre>
</details>
</div>
<Change
diff={diff}
schemaType={schemaType}
previewComponent={FallbackPreview}
layout="inline"
/>
)
}

0 comments on commit 3e96d6b

Please sign in to comment.