Skip to content

Commit

Permalink
[desk-tool] Add button for diffing against latest published version
Browse files Browse the repository at this point in the history
  • Loading branch information
judofyr authored and rexxars committed Oct 6, 2020
1 parent 8785a26 commit 1900fd4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/@sanity/desk-tool/src/panes/documentPane/DocumentPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ function DocumentPane(props: Props) {
<div className={styles.container}>
{isHistoryOpen && (
<div className={styles.historyTimelineContainer}>
<SelectPublishedButton timeId={timeline.publishedTimeId()} onSelect={toggleHistory} />
<SelectHistoryDisplayed value={historyDisplayed} onChange={toggleHistoryDisplayed} />
<HistoryTimelinePanel
timeline={timeline}
Expand Down Expand Up @@ -500,4 +501,24 @@ function SelectHistoryDisplayed({
)
}

function SelectPublishedButton({
timeId,
onSelect
}: {
timeId: string | null
onSelect: (timeId: string) => void
}) {
return (
<button
type="button"
disabled={timeId === null}
onClick={() => {
if (timeId) onSelect(timeId)
}}
>
Compare against latest published
</button>
)
}

export default DocumentPane
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,17 @@ export class Timeline {
return this.createTimeRef(chunkIdx, chunk).id
}

publishedTimeId(): string | null {
for (let chunkIdx = this._chunks.lastIdx; chunkIdx >= this._chunks.firstIdx; chunkIdx--) {
const chunk = this._chunks.get(chunkIdx)
if (chunk.type === 'publish') {
return this.createTimeId(chunkIdx, chunk)
}
}

return null
}

/** Creates a time reference from a chunk. */
private createTimeRef(chunkIdx: number, chunk = this._chunks.get(chunkIdx)): TimeRef {
const timestamp = Math.round(
Expand Down

0 comments on commit 1900fd4

Please sign in to comment.