Skip to content

Commit

Permalink
chore(core): move events story to structure
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin committed Oct 14, 2024
1 parent f2d28d8 commit 3a42123
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const mergeEvents = (
}
}

/**
* @internal
* Decides whether to merge two chunks or not according to their type and timestamp
*/
export function mergeChunk(left: Chunk, right: Chunk): Chunk | [Chunk, Chunk] {
if (left.end !== right.start) throw new Error('chunks are not next to each other')
if (
Expand All @@ -42,6 +46,10 @@ export function mergeChunk(left: Chunk, right: Chunk): Chunk | [Chunk, Chunk] {
return [left, right]
}

/**
* @internal
* Creates a chunk for the timeline from a transaction.
*/
export function chunkFromTransaction(
publishedId: string,
transaction: Transaction,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './chunker'
export * from './Timeline'
export * from './TimelineController'
export * from './types'
14 changes: 0 additions & 14 deletions packages/sanity/src/core/store/events/__workshop__/index.ts

This file was deleted.

14 changes: 13 additions & 1 deletion packages/sanity/src/core/store/events/getDocumentEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ function isDeletePatch(patch: MendozaPatch): boolean {
return patch[0] === 0 && patch[1] === null
}

// This assumes the view is from the publishedDocument having only drafts. (Versions are not yet supported here)
/**
* @internal
* @beta
* This might change, don't use.
* This function receives a transaction and returns a document group event.
* Assumes the user is viewing the published document with only drafts. (Versions are not yet supported here)
*/
export function getEventFromTransaction(
documentId: string,
transaction: Transaction,
Expand Down Expand Up @@ -312,6 +318,12 @@ const isDocumentGroupEvent = (event: unknown): event is DocumentGroupEvent => {
return eventType ? documentVersionEventTypes.includes(eventType) : false
}

/**
*
* @internal
* @beta
* This function receives a transaction and returns a transaction with the draft and published effects.
*/
export const addTransactionEffect = (
documentId: string,
transaction: TransactionLogEventWithEffects,
Expand Down
1 change: 1 addition & 0 deletions packages/sanity/src/core/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './_legacy'
export * from './events/getDocumentEvents'
export * from './user'
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ import {useString} from '@sanity/ui-workshop'
import {useMemo, useState} from 'react'
import {useObservable} from 'react-rx'
import {catchError, map, type Observable, of, startWith, Subject, switchMap} from 'rxjs'
import {type Chunk, getDraftId, getPublishedId, useClient} from 'sanity'
import {
addTransactionEffect,
type Chunk,
chunkFromTransaction,
getDocumentEvents,
getDraftId,
getPublishedId,
mergeChunk,
useClient,
} from 'sanity'

import {Timeline} from '../../../../structure/panes/document/timeline/timeline'
import {Button} from '../../../../ui-components'
import {chunkFromTransaction, mergeChunk} from '../../_legacy/history/history/chunker'
import {addTransactionEffect, getDocumentEvents} from '../getDocumentEvents'
import {Button} from '../../../../../ui-components'
import {Timeline} from '../timeline'

const query = {
excludeContent: 'true',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,10 @@ export default defineScope({
title: 'Default',
component: lazy(() => import('./DefaultStory')),
},
{
name: 'get-document-events',
title: 'Document group events',
component: lazy(() => import('./DocumentGroupEvent')),
},
],
})

0 comments on commit 3a42123

Please sign in to comment.