Skip to content

Commit

Permalink
[field] Shift indexes in headers by one (human readable)
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Oct 6, 2020
1 parent f0ebeec commit a9645fd
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/@sanity/field/src/diff/changes/ChangeTitleSegment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,38 @@ export function ChangeTitleSegment({segment}: {segment: string | FromToIndex}) {
const deleted = typeof toIndex === 'undefined'
if (created) {
// Item was created
const description = `Added in position ${(toIndex || 0) + 1} by`
const readableIndex = (toIndex || 0) + 1
const description = `Added in position ${readableIndex} by`
return (
<DiffAnnotation
annotation={annotation || null}
className={styles.indexGroup}
as="ins"
description={description}
>
#{toIndex}
#{readableIndex}
</DiffAnnotation>
)
}

if (deleted) {
const description = `Removed from position ${(fromIndex || 0) + 1} by`
// Item was deleted
const readableIndex = (fromIndex || 0) + 1
const description = `Removed from position ${readableIndex} by`
return (
<DiffAnnotation
annotation={annotation || null}
className={styles.indexGroup}
as="del"
description={description}
>
#{fromIndex}
#{readableIndex}
</DiffAnnotation>
)
}

if (hasMoved && typeof toIndex !== 'undefined' && typeof fromIndex !== 'undefined') {
// Item was moved
const indexDiff = toIndex - fromIndex
const indexSymbol = indexDiff < 0 ? '↑' : '↓'
const description = `Moved ${Math.abs(indexDiff)} position ${indexDiff < 0 ? 'up' : 'down'} by`
Expand All @@ -64,5 +68,7 @@ export function ChangeTitleSegment({segment}: {segment: string | FromToIndex}) {
)
}

return <span className={styles.indexGroup}>#{toIndex}</span>
// Changed/unchanged
const readableIndex = (toIndex || 0) + 1
return <span className={styles.indexGroup}>#{readableIndex}</span>
}

0 comments on commit a9645fd

Please sign in to comment.