Skip to content

Commit

Permalink
feat(core): add option to expand draft events
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin committed Nov 27, 2024
1 parent 7398e4d commit ddfa22a
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 383 deletions.
263 changes: 0 additions & 263 deletions packages/sanity/src/core/store/events/collapseDraftEvents.test.ts

This file was deleted.

43 changes: 0 additions & 43 deletions packages/sanity/src/core/store/events/collapseDraftEvents.ts

This file was deleted.

22 changes: 22 additions & 0 deletions packages/sanity/src/core/store/events/decorateEvents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import {
type DocumentGroupEvent,
isCreateDocumentVersionEvent,
isPublishDocumentVersionEvent,
} from './types'

/**
* This function adds additional
*/
export function decorateEvents(events: DocumentGroupEvent[]) {
events.forEach((event, index) => {
if (isPublishDocumentVersionEvent(event)) {
// Find the creation event for this published event
const creationEvent = events.slice(index + 1).find((e) => isCreateDocumentVersionEvent(e))
if (creationEvent) {
// If we found a creation event, we should add it to the publish event
event.creationEvent = creationEvent
creationEvent.parentId = event.id
}
}
})
}
12 changes: 8 additions & 4 deletions packages/sanity/src/core/store/events/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,11 @@ export interface CreateDocumentVersionEvent extends BaseEvent {
* This is undefined for versions and drafts. (will be present only in publish document?)
*/
revisionId?: string

/**
* This is present when this creation event is already published.
*/
parentId?: string
}

export interface DeleteDocumentVersionEvent extends BaseEvent {
Expand Down Expand Up @@ -332,11 +337,9 @@ export interface EditDocumentVersionEvent extends BaseEvent {
revisionId: string
}[]
/**
* This is added client side to enhance the UI.
* For draft documents, it indicates the event that created this document that was later published
* It will be used to expand the publish view.
* Present when an edit was already published, then the user decided to expand the event.
*/
// creationEvent?: CreateDocumentVersionEvent
parentId?: string
}

export interface EventsStoreRevision {
Expand All @@ -361,6 +364,7 @@ export interface EventsStore {
to: SanityDocument
since: SanityDocument | null
}) => Observable<{diff: ObjectDiff | null; loading: boolean}>
handleExpandEvent: (event: DocumentGroupEvent) => Promise<void>
}

/**
Expand Down
Loading

0 comments on commit ddfa22a

Please sign in to comment.