Skip to content

Commit

Permalink
[desk-tool] Resolve and populate diff components
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Oct 6, 2020
1 parent 1508cb1 commit f31ec7b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
SchemaType,
Diff
} from '@sanity/field/diff'
import {resolveDiffComponent} from '../../../diffs/resolveDiffComponent'
import {ChangeNode, ChangeTitlePath} from './types'
import {getArrayDiffItemType} from './helpers'

Expand All @@ -24,22 +25,25 @@ export function buildChangeList(
path: Path = [],
titlePath: ChangeTitlePath = []
): ChangeNode[] {
if (schemaType.jsonType === 'object' && diff.type === 'object') {
const diffComponent = resolveDiffComponent(schemaType)

if (!diffComponent && schemaType.jsonType === 'object' && diff.type === 'object') {
return buildObjectChangeList(schemaType, diff, path, titlePath)
}

if (schemaType.jsonType === 'array' && diff.type === 'array') {
if (!diffComponent && schemaType.jsonType === 'array' && diff.type === 'array') {
return buildArrayChangeList(schemaType, diff, path, titlePath)
}

return [
{
type: 'field',
diff: diff,
diff,
path,
titlePath,
schemaType,
key: pathToString(path),
path: path,
titlePath: titlePath,
schemaType: schemaType
diffComponent
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import React, {useCallback, Fragment, useContext} from 'react'
import {useDocumentOperation} from '@sanity/react-hooks'
import {ObjectDiff, SchemaType, ObjectSchemaType} from '@sanity/field/diff'
import {FallbackDiff} from '../../../diffs/_fallback/FallbackDiff'
import {resolveDiffComponent} from '../../../diffs/resolveDiffComponent'
import {useDocumentHistory} from '../documentHistory'
import {buildDocumentChangeList} from './buildChangeList'
import {DiffErrorBoundary} from './diffErrorBoundary'
Expand Down Expand Up @@ -94,7 +93,7 @@ function ChangeHeader({change, titlePath}: {change: FieldChangeNode; titlePath:
}

function FieldChange({change}: {change: FieldChangeNode}) {
const DiffComponent = resolveDiffComponent(change.schemaType) || FallbackDiff
const DiffComponent = change.diffComponent || FallbackDiff

return (
<div className={styles.fieldChange}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Diff, Path, SchemaType} from '@sanity/field/diff'
import {Diff, Path, SchemaType, DiffComponent} from '@sanity/field/diff'

export interface OperationsAPI {
patch: {
Expand Down Expand Up @@ -41,6 +41,7 @@ export interface FieldChangeNode {
path: Path
titlePath: ChangeTitlePath
schemaType: SchemaType
diffComponent?: DiffComponent
}

export type ChangeNode = GroupChangeNode | FieldChangeNode
Expand Down

0 comments on commit f31ec7b

Please sign in to comment.