Skip to content

Commit

Permalink
fix(core): release events types are lowercase (#8024)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin authored Dec 12, 2024
1 parent 1a6483d commit ea86580
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 84 deletions.
6 changes: 4 additions & 2 deletions packages/sanity/src/core/field/diff/components/Event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {createElement, useMemo} from 'react'
import {
type DocumentGroupEvent,
getReleaseTone,
isEditDocumentVersionEvent,
isPublishDocumentVersionEvent,
type RelativeTimeOptions,
useDateTimeFormat,
UserAvatar,
Expand Down Expand Up @@ -143,7 +145,7 @@ export function Event({event, showChangesBy = 'tooltip'}: TimelineItemProps) {
return formattedDate
}, [timestamp, dateFormat])

const userIds = event.type === 'EditDocumentVersion' ? event.contributors : [event.author]
const userIds = isEditDocumentVersionEvent(event) ? event.contributors : [event.author]

return (
<>
Expand All @@ -157,7 +159,7 @@ export function Event({event, showChangesBy = 'tooltip'}: TimelineItemProps) {
<Stack space={2}>
<Text size={1} weight="medium">
{t(TIMELINE_ITEM_I18N_KEY_MAPPING[type])}
{event.type === 'PublishDocumentVersion' && documentVariantType === 'published' && (
{isPublishDocumentVersionEvent(event) && documentVariantType === 'published' && (
<>
{' '}
{event.release ? (
Expand Down
60 changes: 30 additions & 30 deletions packages/sanity/src/core/field/diff/components/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@ import {type ThemeColorAvatarColorKey} from '@sanity/ui/theme'
import {type DocumentVersionEventType, type StudioLocaleResourceKeys} from 'sanity'

export const TIMELINE_ICON_COMPONENTS: Record<DocumentVersionEventType, IconComponent> = {
CreateDocumentVersion: AddCircleIcon,
CreateLiveDocument: AddCircleIcon,
DeleteDocumentGroup: TrashIcon,
DeleteDocumentVersion: CloseIcon,
EditDocumentVersion: EditIcon,
UpdateLiveDocument: EditIcon,
PublishDocumentVersion: PublishIcon,
UnpublishDocument: UnpublishIcon,
ScheduleDocumentVersion: CalendarIcon,
UnscheduleDocumentVersion: CircleIcon,
createDocumentVersion: AddCircleIcon,
createLiveDocument: AddCircleIcon,
deleteDocumentGroup: TrashIcon,
deleteDocumentVersion: CloseIcon,
editDocumentVersion: EditIcon,
updateLiveDocument: EditIcon,
publishDocumentVersion: PublishIcon,
unpublishDocument: UnpublishIcon,
scheduleDocumentVersion: CalendarIcon,
unscheduleDocumentVersion: CircleIcon,
}

export const TIMELINE_ITEM_EVENT_TONE: Record<DocumentVersionEventType, ThemeColorAvatarColorKey> =
{
CreateDocumentVersion: 'green',
CreateLiveDocument: 'blue',
UpdateLiveDocument: 'green',
EditDocumentVersion: 'yellow',
UnpublishDocument: 'orange',
DeleteDocumentVersion: 'orange',
DeleteDocumentGroup: 'orange',
ScheduleDocumentVersion: 'cyan',
UnscheduleDocumentVersion: 'cyan',
PublishDocumentVersion: 'green',
createDocumentVersion: 'green',
createLiveDocument: 'blue',
updateLiveDocument: 'green',
editDocumentVersion: 'yellow',
unpublishDocument: 'orange',
deleteDocumentVersion: 'orange',
deleteDocumentGroup: 'orange',
scheduleDocumentVersion: 'cyan',
unscheduleDocumentVersion: 'cyan',
publishDocumentVersion: 'green',
}

/**
Expand All @@ -47,14 +47,14 @@ export const TIMELINE_ITEM_I18N_KEY_MAPPING: Record<
DocumentVersionEventType,
StudioLocaleResourceKeys
> = {
CreateDocumentVersion: 'timeline.operation.created',
PublishDocumentVersion: 'timeline.operation.published',
UpdateLiveDocument: 'timeline.operation.edited-live',
EditDocumentVersion: 'timeline.operation.edited-draft',
UnpublishDocument: 'timeline.operation.unpublished',
DeleteDocumentVersion: 'timeline.operation.draft-discarded',
DeleteDocumentGroup: 'timeline.operation.deleted',
ScheduleDocumentVersion: 'timeline.operation.published',
UnscheduleDocumentVersion: 'timeline.operation.published',
CreateLiveDocument: 'timeline.operation.created',
createDocumentVersion: 'timeline.operation.created',
publishDocumentVersion: 'timeline.operation.published',
updateLiveDocument: 'timeline.operation.edited-live',
editDocumentVersion: 'timeline.operation.edited-draft',
unpublishDocument: 'timeline.operation.unpublished',
deleteDocumentVersion: 'timeline.operation.draft-discarded',
deleteDocumentGroup: 'timeline.operation.deleted',
scheduleDocumentVersion: 'timeline.operation.published',
unscheduleDocumentVersion: 'timeline.operation.published',
createLiveDocument: 'timeline.operation.created',
}
3 changes: 2 additions & 1 deletion packages/sanity/src/core/store/events/getDocumentChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
type DocumentGroupEvent,
type EventsStoreRevision,
isCreateDocumentVersionEvent,
isEditDocumentVersionEvent,
} from './types'
import {type EventsObservableValue} from './useEventsStore'

Expand Down Expand Up @@ -133,7 +134,7 @@ function calculateDiff({
transactionIndex: index,
event: events.find(
(event) =>
event.type !== 'EditDocumentVersion' &&
!isEditDocumentVersionEvent(event) &&
'revisionId' in event &&
event.revisionId === transaction.id,
),
Expand Down
14 changes: 7 additions & 7 deletions packages/sanity/src/core/store/events/getEditEvents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('getEditEvents()', () => {
]
describe('when the document is not liveEdit', () => {
const expectedEvent: EditDocumentVersionEvent = {
type: 'EditDocumentVersion',
type: 'editDocumentVersion',
id: 'edit-tx-2',
documentId: 'versions.rkaihDvC1.f8dece19-c458-4cff-bf76-732b00617183',
timestamp: '2024-11-19T08:27:33.251404Z',
Expand All @@ -62,13 +62,13 @@ describe('getEditEvents()', () => {
revisionId: 'edit-tx-2',
transactions: [
{
type: 'EditTransaction',
type: 'editTransaction',
author: 'p8xDvUMxC',
timestamp: '2024-11-19T08:27:33.251404Z',
revisionId: 'edit-tx-2',
},
{
type: 'EditTransaction',
type: 'editTransaction',
author: 'p8xDvUMxC',
timestamp: '2024-11-19T08:27:27.753746Z',
revisionId: 'edit-tx-1',
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('getEditEvents()', () => {
},
}
const newEvent: EditDocumentVersionEvent = {
type: 'EditDocumentVersion',
type: 'editDocumentVersion',
documentId: 'versions.rkaihDvC1.f8dece19-c458-4cff-bf76-732b00617183',
timestamp: '2024-11-19T08:35:27.753746Z',
id: 'new-tx',
Expand All @@ -109,7 +109,7 @@ describe('getEditEvents()', () => {
revisionId: 'new-tx',
transactions: [
{
type: 'EditTransaction',
type: 'editTransaction',
author: 'p8xDvUMxC',
timestamp: '2024-11-19T08:35:27.753746Z',
revisionId: 'new-tx',
Expand Down Expand Up @@ -170,7 +170,7 @@ describe('getEditEvents()', () => {
})
describe('when the document is liveEdit', () => {
const expectedEvent: UpdateLiveDocumentEvent = {
type: 'UpdateLiveDocument',
type: 'updateLiveDocument',
id: 'edit-tx-2',
documentId: 'versions.rkaihDvC1.f8dece19-c458-4cff-bf76-732b00617183',
timestamp: '2024-11-19T08:27:33.251404Z',
Expand Down Expand Up @@ -200,7 +200,7 @@ describe('getEditEvents()', () => {
},
}
const newEvent: UpdateLiveDocumentEvent = {
type: 'UpdateLiveDocument',
type: 'updateLiveDocument',
documentId: 'versions.rkaihDvC1.f8dece19-c458-4cff-bf76-732b00617183',
timestamp: '2024-11-19T08:35:27.753746Z',
id: 'new-tx',
Expand Down
6 changes: 3 additions & 3 deletions packages/sanity/src/core/store/events/getEditEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const getEditTransaction = (
transaction: TransactionLogEventWithEffects,
): EditDocumentVersionEvent['transactions'][number] => {
return {
type: 'EditTransaction',
type: 'editTransaction',
author: transaction.author,
timestamp: transaction.timestamp,
revisionId: transaction.id,
Expand Down Expand Up @@ -86,13 +86,13 @@ export function getEditEvents(
? ({
id: transaction.id,
timestamp: transaction.timestamp,
type: 'UpdateLiveDocument',
type: 'updateLiveDocument',
documentId: documentId,
revisionId: transaction.id,
author: transaction.author,
} satisfies UpdateLiveDocumentEvent)
: ({
type: 'EditDocumentVersion',
type: 'editDocumentVersion',
documentId: documentId,
id: transaction.id,
timestamp: transaction.timestamp,
Expand Down
42 changes: 21 additions & 21 deletions packages/sanity/src/core/store/events/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,79 +161,79 @@ export type DocumentGroupEvent =
*/
export const isCreateDocumentVersionEvent = (
event: Partial<DocumentGroupEvent>,
): event is CreateDocumentVersionEvent => event.type === 'CreateDocumentVersion'
): event is CreateDocumentVersionEvent => event.type === 'createDocumentVersion'

/**
* @hidden
* @beta
*/
export const isDeleteDocumentVersionEvent = (
event: Partial<DocumentGroupEvent>,
): event is DeleteDocumentVersionEvent => event.type === 'DeleteDocumentVersion'
): event is DeleteDocumentVersionEvent => event.type === 'deleteDocumentVersion'

/**
* @hidden
* @beta
*/
export const isPublishDocumentVersionEvent = (
event: Partial<DocumentGroupEvent>,
): event is PublishDocumentVersionEvent => event.type === 'PublishDocumentVersion'
): event is PublishDocumentVersionEvent => event.type === 'publishDocumentVersion'

/**
* @hidden
* @beta
*/
export const isUnpublishDocumentEvent = (
event: Partial<DocumentGroupEvent>,
): event is UnpublishDocumentEvent => event.type === 'UnpublishDocument'
): event is UnpublishDocumentEvent => event.type === 'unpublishDocument'

/**
* @hidden
* @beta
*/
export const isScheduleDocumentVersionEvent = (
event: Partial<DocumentGroupEvent>,
): event is ScheduleDocumentVersionEvent => event.type === 'ScheduleDocumentVersion'
): event is ScheduleDocumentVersionEvent => event.type === 'scheduleDocumentVersion'

/**
* @hidden
* @beta
*/
export const isUnscheduleDocumentVersionEvent = (
event: Partial<DocumentGroupEvent>,
): event is UnscheduleDocumentVersionEvent => event.type === 'UnscheduleDocumentVersion'
): event is UnscheduleDocumentVersionEvent => event.type === 'unscheduleDocumentVersion'

/**
* @hidden
* @beta
*/
export const isDeleteDocumentGroupEvent = (
event: Partial<DocumentGroupEvent>,
): event is DeleteDocumentGroupEvent => event.type === 'DeleteDocumentGroup'
): event is DeleteDocumentGroupEvent => event.type === 'deleteDocumentGroup'

/**
* @hidden
* @beta
*/
export const isCreateLiveDocumentEvent = (
event: Partial<DocumentGroupEvent>,
): event is CreateLiveDocumentEvent => event.type === 'CreateLiveDocument'
): event is CreateLiveDocumentEvent => event.type === 'createLiveDocument'

/**
* @hidden
* @beta
*/
export const isUpdateLiveDocumentEvent = (
event: Partial<DocumentGroupEvent>,
): event is UpdateLiveDocumentEvent => event.type === 'UpdateLiveDocument'
): event is UpdateLiveDocumentEvent => event.type === 'updateLiveDocument'

/**
* @hidden
* @beta
*/
export const isEditDocumentVersionEvent = (
event: Partial<DocumentGroupEvent>,
): event is EditDocumentVersionEvent => event.type === 'EditDocumentVersion'
): event is EditDocumentVersionEvent => event.type === 'editDocumentVersion'

/**
* A generic event with a type and a timestamp.
Expand All @@ -251,7 +251,7 @@ export interface BaseEvent {
* @beta
*/
export interface CreateDocumentVersionEvent extends BaseEvent {
type: 'CreateDocumentVersion'
type: 'createDocumentVersion'
documentId: string

releaseId?: string
Expand All @@ -274,7 +274,7 @@ export interface CreateDocumentVersionEvent extends BaseEvent {
* @beta
*/
export interface DeleteDocumentVersionEvent extends BaseEvent {
type: 'DeleteDocumentVersion'
type: 'deleteDocumentVersion'
documentId: string

releaseId?: string
Expand All @@ -287,7 +287,7 @@ export interface DeleteDocumentVersionEvent extends BaseEvent {
* @beta
*/
export interface PublishDocumentVersionEvent extends BaseEvent {
type: 'PublishDocumentVersion'
type: 'publishDocumentVersion'
documentId: string
revisionId: string

Expand Down Expand Up @@ -320,7 +320,7 @@ export interface PublishDocumentVersionEvent extends BaseEvent {
* @beta
*/
export interface UnpublishDocumentEvent extends BaseEvent {
type: 'UnpublishDocument'
type: 'unpublishDocument'
documentId: string

/** The version that was created based on it */
Expand All @@ -336,7 +336,7 @@ export interface UnpublishDocumentEvent extends BaseEvent {
* @beta
*/
export interface ScheduleDocumentVersionEvent extends BaseEvent {
type: 'ScheduleDocumentVersion'
type: 'scheduleDocumentVersion'
documentId: string

releaseId: string
Expand All @@ -355,7 +355,7 @@ export interface ScheduleDocumentVersionEvent extends BaseEvent {
* @beta
*/
export interface UnscheduleDocumentVersionEvent extends BaseEvent {
type: 'UnscheduleDocumentVersion'
type: 'unscheduleDocumentVersion'
documentId: string

releaseId: string
Expand All @@ -370,7 +370,7 @@ export interface UnscheduleDocumentVersionEvent extends BaseEvent {
* @beta
*/
export interface DeleteDocumentGroupEvent extends BaseEvent {
type: 'DeleteDocumentGroup'
type: 'deleteDocumentGroup'
documentId: string

author: string
Expand All @@ -381,7 +381,7 @@ export interface DeleteDocumentGroupEvent extends BaseEvent {
* @beta
*/
export interface CreateLiveDocumentEvent extends BaseEvent {
type: 'CreateLiveDocument'
type: 'createLiveDocument'
documentId: string
revisionId: string

Expand All @@ -393,7 +393,7 @@ export interface CreateLiveDocumentEvent extends BaseEvent {
* @beta
*/
export interface UpdateLiveDocumentEvent extends BaseEvent {
type: 'UpdateLiveDocument'
type: 'updateLiveDocument'
documentId: string
revisionId: string

Expand All @@ -408,7 +408,7 @@ export interface UpdateLiveDocumentEvent extends BaseEvent {
* Or a create event and a publish event.
*/
export interface EditDocumentVersionEvent extends BaseEvent {
type: 'EditDocumentVersion'
type: 'editDocumentVersion'
documentId: string
// Given this event could be a result of multiple edits, we could have more than one author.
contributors: string[]
Expand All @@ -419,7 +419,7 @@ export interface EditDocumentVersionEvent extends BaseEvent {
*/
revisionId: string
transactions: {
type: 'EditTransaction'
type: 'editTransaction'
author: string
timestamp: string
revisionId: string
Expand Down
Loading

0 comments on commit ea86580

Please sign in to comment.