Skip to content

Commit

Permalink
fix(core): update return tye of useEventsStore
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin committed Dec 2, 2024
1 parent ccd45ca commit c970cdf
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {type Path} from '@sanity/types'
import {Card, Flex, Inline, Stack, Text} from '@sanity/ui'
import {type ReactElement, type ReactNode} from 'react'
import {getDocumentVariantType} from 'sanity'

import {Tooltip, type TooltipProps} from '../../../../ui-components'
import {LegacyLayerProvider, UserAvatar} from '../../../components'
Expand Down Expand Up @@ -81,11 +80,7 @@ function AnnotationItem({annotation}: {annotation: AnnotationDetails}) {
{annotation.event ? (
<>
<Card borderBottom marginBottom={2} />
<Event
documentVariantType={getDocumentVariantType(annotation.event.documentId)}
event={annotation.event}
showChangesBy="inline"
/>
<Event event={annotation.event} showChangesBy="inline" />
</>
) : (
<Inline space={2}>
Expand Down
6 changes: 3 additions & 3 deletions packages/sanity/src/core/field/diff/components/Event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import {css, styled} from 'styled-components'

import {Tooltip} from '../../../../ui-components'
import {type DocumentVariantType} from '../../../util/getDocumentVariantType'
import {getDocumentVariantType} from '../../../util/getDocumentVariantType'
import {
TIMELINE_ICON_COMPONENTS,
TIMELINE_ITEM_EVENT_TONE,
Expand Down Expand Up @@ -119,14 +119,14 @@ const ChangesBy = ({collaborators}: {collaborators: string[]}) => {

interface TimelineItemProps {
event: DocumentGroupEvent
documentVariantType: DocumentVariantType
showChangesBy: 'tooltip' | 'inline' | 'hidden'
}
/**
* @internal
*/
export function Event({event, showChangesBy = 'tooltip', documentVariantType}: TimelineItemProps) {
export function Event({event, showChangesBy = 'tooltip'}: TimelineItemProps) {
const {t} = useTranslation('studio')
const documentVariantType = getDocumentVariantType(event.id)
const {type, timestamp} = event

const iconComponent = TIMELINE_ICON_COMPONENTS[type]
Expand Down
3 changes: 0 additions & 3 deletions packages/sanity/src/core/store/events/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ import {type SanityDocument} from '@sanity/types'
import {type Observable} from 'rxjs'

import {type ObjectDiff} from '../../field'
import {type DocumentVariantType} from '../../util/getDocumentVariantType'

/**
* Events relevant for the whole document group.
Expand Down Expand Up @@ -445,8 +444,6 @@ export interface EventsStoreRevision {
* @internal
* */
export interface EventsStore {
enabled: true
documentVariantType: DocumentVariantType
events: DocumentGroupEvent[]
nextCursor: string | null
loading: boolean
Expand Down
2 changes: 0 additions & 2 deletions packages/sanity/src/core/store/events/useEventsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ export function useEventsStore({
)

return {
documentVariantType,
enabled: true as const,
events,
nextCursor,
loading,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export function EventsSelector({showList}: {showList: boolean}) {
loading,
error,
revision,
documentVariantType,
loadMoreEvents,
findRangeForRevision,
expandEvent,
Expand Down Expand Up @@ -97,7 +96,6 @@ export function EventsSelector({showList}: {showList: boolean}) {
onLoadMore={loadMoreEvents}
onSelect={selectRev}
listMaxHeight={`${listHeight}px`}
documentVariantType={documentVariantType}
/>
) : null}
{loading && <LoadingBlock />}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Card, Flex} from '@sanity/ui'
import {type MouseEvent, useCallback} from 'react'
import {type DocumentGroupEvent, type DocumentVariantType, Event} from 'sanity'
import {type DocumentGroupEvent, Event} from 'sanity'

import {Tooltip} from '../../../../../ui-components'

Expand All @@ -9,7 +9,6 @@ export interface TimelineItemProps {
isSelected: boolean
onSelect: (chunk: DocumentGroupEvent) => void
optionsMenu?: React.ReactNode
documentVariantType: DocumentVariantType
}

const getIsSelectable = (event: DocumentGroupEvent) => {
Expand All @@ -23,15 +22,8 @@ const getIsSelectable = (event: DocumentGroupEvent) => {
)
}

export function EventTimelineItem({
event,
isSelected,
onSelect,
optionsMenu,
documentVariantType,
}: TimelineItemProps) {
export function EventTimelineItem({event, isSelected, onSelect, optionsMenu}: TimelineItemProps) {
const isSelectable = getIsSelectable(event)

const handleClick = useCallback(
(evt: MouseEvent<HTMLDivElement>) => {
evt.preventDefault()
Expand Down Expand Up @@ -69,7 +61,7 @@ export function EventTimelineItem({
cursor: isSelectable ? 'pointer' : 'default',
}}
>
<Event event={event} showChangesBy="tooltip" documentVariantType={documentVariantType} />
<Event event={event} showChangesBy="tooltip" />
</Card>
{optionsMenu}
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
CommandList,
type CommandListRenderItemCallback,
type DocumentGroupEvent,
type DocumentVariantType,
getDocumentVariantType,
isCreateDocumentVersionEvent,
isEditDocumentVersionEvent,
LoadingBlock,
Expand All @@ -28,7 +28,6 @@ interface TimelineProps {
* The list needs a predefined max height for the scroller to work.
*/
listMaxHeight?: string
documentVariantType: DocumentVariantType
}

const TimelineItemWrapper = motion(Box)
Expand All @@ -54,7 +53,6 @@ export const EventsTimeline = ({
selectedEventId,
onLoadMore,
onSelect,
documentVariantType,
listMaxHeight = 'calc(100vh - 280px)',
onExpand,
}: TimelineProps) => {
Expand Down Expand Up @@ -120,6 +118,7 @@ export const EventsTimeline = ({

const renderOptionsMenu = useCallback(
(event: DocumentGroupEvent) => {
const documentVariantType = getDocumentVariantType(event.id)
if (event.type === 'PublishDocumentVersion' && documentVariantType === 'published') {
return <PublishedEventMenu event={event} />
}
Expand All @@ -137,7 +136,7 @@ export const EventsTimeline = ({
}
return null
},
[documentVariantType, expandedParents, handleExpandParent],
[expandedParents, handleExpandParent],
)

const renderItem = useCallback<CommandListRenderItemCallback<DocumentGroupEvent[][number]>>(
Expand Down Expand Up @@ -189,7 +188,6 @@ export const EventsTimeline = ({
isSelected={event.id === selectedEventId}
onSelect={handleSelectChunk}
optionsMenu={renderOptionsMenu(event)}
documentVariantType={documentVariantType}
/>

{isLastEvent && hasMoreEvents && <LoadingBlock />}
Expand All @@ -201,7 +199,6 @@ export const EventsTimeline = ({
selectedEventId,
handleSelectChunk,
renderOptionsMenu,
documentVariantType,
events.length,
hasMoreEvents,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export function EventsTimelineMenu({event, events, mode, placement}: TimelineMen
findRangeForRevision,
findRangeForSince,
loadMoreEvents,
documentVariantType,
expandEvent,
} = useEvents()

Expand Down Expand Up @@ -142,7 +141,6 @@ export function EventsTimelineMenu({event, events, mode, placement}: TimelineMen
selectedEventId={event?.id}
onLoadMore={handleLoadMore}
onSelect={mode === 'rev' ? selectRev : selectSince}
documentVariantType={documentVariantType}
/>
)
}, [
Expand All @@ -154,7 +152,6 @@ export function EventsTimelineMenu({event, events, mode, placement}: TimelineMen
event?.id,
handleLoadMore,
selectSince,
documentVariantType,
selectRev,
])

Expand Down

0 comments on commit c970cdf

Please sign in to comment.