Skip to content

Commit

Permalink
fix: various fixes after PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin committed Dec 2, 2024
1 parent c970cdf commit ebac782
Show file tree
Hide file tree
Showing 17 changed files with 18 additions and 53 deletions.
1 change: 0 additions & 1 deletion packages/sanity/src/core/field/diff/components/Event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ interface UserAvatarStackProps {

function UserAvatarStack({maxLength, userIds, size, withTooltip = true}: UserAvatarStackProps) {
return (
// eslint-disable-next-line react/jsx-no-undef
<AvatarStack maxLength={maxLength} size={size}>
{userIds.map((userId) => (
<UserAvatar key={userId} user={userId} withTooltip={withTooltip} />
Expand Down
2 changes: 2 additions & 0 deletions packages/sanity/src/core/i18n/bundles/studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ export const studioLocaleStrings = defineLocalesResources('studio', {
'Edit the document or select an older version in the timeline to see a list of changes appear in this panel.',
/** No Changes title in the Review Changes pane */
'changes.no-changes-title': 'There are no changes',
/* Label for the tooltip that shows when an action is not selectable*/
'changes.not-selectable': 'It is not possible to select this event',
/** Portable Text diff: An annotation was added */
'changes.portable-text.annotation_added': 'Added annotation',
/** Portable Text diff: An annotation was changed */
Expand Down
3 changes: 2 additions & 1 deletion packages/sanity/src/core/releases/hooks/usePerspective.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ export function usePerspective(): PerspectiveValue {
[router.stickyParams.excludedPerspectives],
)

// TODO: Should it be possible to set the perspective within a pane, rather than globally?
const setPerspective = useCallback(
(releaseId: 'published' | 'drafts' | string | undefined) => {
(releaseId: string | undefined) => {
let perspectiveParam = ''

if (releaseId === 'published') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {ToneIcon} from '../../../../../ui-components/toneIcon/ToneIcon'
import {Translate, useTranslation} from '../../../../i18n'
import {PublishedRelease} from '../../../__telemetry__/releases.telemetry'
import {releasesLocaleNamespace} from '../../../i18n'
import {type ReleaseDocument, usePerspective} from '../../../index'
import {type ReleaseDocument} from '../../../index'
import {useReleaseOperations} from '../../../store/useReleaseOperations'
import {type DocumentInRelease} from '../../../tool/detail/useBundleDocuments'

Expand All @@ -32,7 +32,6 @@ export const ReleasePublishAllButton = ({
const [publishBundleStatus, setPublishBundleStatus] = useState<'idle' | 'confirm' | 'publishing'>(
'idle',
)
const {setPerspective} = usePerspective()

const isValidatingDocuments = documents.some(({validation}) => validation.isValidating)
const hasDocumentValidationErrors = documents.some(({validation}) => validation.hasError)
Expand All @@ -45,8 +44,6 @@ export const ReleasePublishAllButton = ({
try {
setPublishBundleStatus('publishing')
await publishRelease(release._id)
// Reset to the drafts perspective, the just published release will not be visible.
setPerspective('drafts')
telemetry.log(PublishedRelease)
toast.push({
closable: true,
Expand Down Expand Up @@ -80,7 +77,7 @@ export const ReleasePublishAllButton = ({
} finally {
setPublishBundleStatus('idle')
}
}, [release, publishRelease, setPerspective, telemetry, toast, t, router])
}, [release, publishRelease, telemetry, toast, t, router])

const confirmPublishDialog = useMemo(() => {
if (publishBundleStatus === 'idle') return null
Expand Down
2 changes: 1 addition & 1 deletion packages/sanity/src/core/releases/util/getReleaseTone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function getReleaseTone(release: ReleaseDocument | 'published' | typeof L
}

if (release?.metadata?.releaseType === 'undecided') {
return 'default' // was "explore", but that is not a valid badgeTone?
return 'explore'
}

if (release?.metadata?.releaseType === 'scheduled') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-console */
/* eslint-disable max-nested-callbacks */
import {type Observable, of} from 'rxjs'
import {catchError, map, startWith, tap} from 'rxjs/operators'
import {type SanityClient, type SanityDocument} from 'sanity'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@ export async function getDocumentTransactions({
effectFormat: 'mendoza',
excludeContent: 'true',
includeIdentifiedDocumentsOnly: 'true',
// reverse: 'true',
limit: TRANSLOG_ENTRY_LIMIT.toString(),
// https://www.sanity.io/docs/history-api#fromTransaction-db53ef83c809
fromTransaction: fromTransaction,
})

// fromTransaction,
if (toTransaction) {
queryParams.append('toTransaction', toTransaction)
}
Expand Down
2 changes: 0 additions & 2 deletions packages/sanity/src/core/store/events/getEditEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ export function getEditEvents(
contributors: [transaction.author],
releaseId: getVersionFromId(documentId),
revisionId: transaction.id,

// TODO: Do we need the transactions? It could be useful to avoid refetching the transactions
transactions: [getEditTransaction(transaction)],
} satisfies EditDocumentVersionEvent)
if (result.length === 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable no-console */
/* eslint-disable max-nested-callbacks */
import {BehaviorSubject, from, of} from 'rxjs'
import {catchError, map, scan, shareReplay, startWith, switchMap, tap} from 'rxjs/operators'
import {type SanityClient} from 'sanity'
Expand Down Expand Up @@ -39,7 +37,6 @@ export function getInitialFetchEvents({client, documentId}: InitialFetchEventsOp

const fetchEvents = ({limit, nextCursor}: {limit: number; nextCursor: string | null}) => {
const params = new URLSearchParams({
// This is not working yet, CL needs to fix it.
limit: limit.toString(),
})
if (nextCursor) {
Expand Down
1 change: 0 additions & 1 deletion packages/sanity/src/core/store/events/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ export function remoteMutationToTransaction(
timestamp: event.timestamp.toISOString(),
effects: {
[event.head._id]: {
// TODO: Find a way to validate that is a MendozaPatch
apply: event.effects.apply as MendozaPatch,
revert: event.effects.revert as MendozaPatch,
},
Expand Down
4 changes: 3 additions & 1 deletion packages/sanity/src/structure/i18n/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ const structureLocaleStrings = defineLocalesResources('structure', {
/** Fallback tooltip for the Unpublish document action when publish is invoked for a document with live edit enabled.*/
'action.unpublish.live-edit.disabled':
'This document has live edit enabled and cannot be unpublished',

/** Description for the archived release banner, rendered when viewing the history of a version document from the publihed view */
'banners.archived-release.description':
"You are viewing a read-only document that was published in a release. It can't be edited",
/** The text for the restore button on the deleted document banner */
'banners.deleted-document-banner.restore-button.text': 'Restore most recent revision',
/** The text content for the deleted document banner */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable camelcase */

import {useEffect, useMemo, useRef} from 'react'
import {
EventsProvider,
Expand Down Expand Up @@ -65,7 +63,6 @@ export const DocumentPaneEvents = (props: DocumentPaneProviderProps) => {
} else {
isMounted.current = true
}
// https://react.dev/learn/separating-events-from-effects#declaring-an-effect-event
// TODO: Remove `updateHistoryParams` as a dependency when react eslint plugin is updated
}, [perspective, updateHistoryParams])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ export const DocumentPaneWithLegacyTimelineStore = (props: DocumentPaneProviderP

const [timelineError, setTimelineError] = useState<Error | null>(null)

/**
* Create an intermediate store which handles document Timeline + TimelineController
* creation, and also fetches pre-requsite document snapshots. Compatible with `useSyncExternalStore`
* and made available to child components via DocumentPaneContext.
*/
const timelineStore = useTimelineStore({
documentId: getPublishedId(options.id),
documentType: options.type,
Expand All @@ -45,8 +40,6 @@ export const DocumentPaneWithLegacyTimelineStore = (props: DocumentPaneProviderP
const onOlderRevision = useTimelineSelector(timelineStore, (state) => state.onOlderRevision)
const timelineDisplayed = useTimelineSelector(timelineStore, (state) => state.timelineDisplayed)
const sinceAttributes = useTimelineSelector(timelineStore, (state) => state.sinceAttributes)

// Subscribe to external timeline state changes
const timelineReady = useTimelineSelector(timelineStore, (state) => state.timelineReady)
const isPristine = useTimelineSelector(timelineStore, (state) => state.isPristine)
const lastNonDeletedRevId = useTimelineSelector(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {Banner} from './Banner'

export function ArchivedReleaseDocumentBanner(): JSX.Element {
const {t} = useTranslation(structureLocaleNamespace)
const {t: tCore} = useTranslation()

const {params, setParams} = usePaneRouter()
const handleGoBack = () => {
Expand All @@ -18,17 +17,13 @@ export function ArchivedReleaseDocumentBanner(): JSX.Element {
})
}

// TODO: i18n this
const text =
"You are viewing a read-only document that was published in a release. It can't be edited"

return (
<Banner
tone="caution"
paddingY={2}
content={
<Flex align="center" justify="space-between" gap={1} flex={1}>
<Text size={1}>{text}</Text>
<Text size={1}>{t('banners.archived-release.description')}</Text>
</Flex>
}
action={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ export function EventsInspector({showChanges}: {showChanges: boolean}): ReactEle
const changesList$ = useMemo(() => getChangesList(), [getChangesList])
const {diff, loading: diffLoading} = useObservable(changesList$, DIFF_INITIAL_VALUE)

// Note that we are using the studio core namespace here, as changes theoretically should
// be part of Sanity core (needs to be moved from structure at some point)
const {t} = useTranslation('studio')
const {t: structureT} = useTranslation(structureLocaleNamespace)

Expand Down Expand Up @@ -93,7 +91,7 @@ export function EventsInspector({showChanges}: {showChanges: boolean}): ReactEle
<Box padding={3} style={{position: 'relative'}}>
<Grid paddingX={2} paddingBottom={2}>
<Text size={1} muted>
{structureT('changes.from.label')}
{t('changes.inspector.from-label')}
</Text>
<EventsTimelineMenu
event={sinceEvent || null}
Expand All @@ -102,7 +100,7 @@ export function EventsInspector({showChanges}: {showChanges: boolean}): ReactEle
placement="bottom-start"
/>
<Text size={1} muted>
{structureT('changes.to.label')}
{t('changes.inspector.to-label')}
</Text>
<EventsTimelineMenu
event={toEvent || null}
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, Event} from 'sanity'
import {type DocumentGroupEvent, Event, useTranslation} from 'sanity'

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

Expand All @@ -23,6 +23,7 @@ const getIsSelectable = (event: DocumentGroupEvent) => {
}

export function EventTimelineItem({event, isSelected, onSelect, optionsMenu}: TimelineItemProps) {
const {t} = useTranslation('studio')
const isSelectable = getIsSelectable(event)
const handleClick = useCallback(
(evt: MouseEvent<HTMLDivElement>) => {
Expand All @@ -35,18 +36,8 @@ export function EventTimelineItem({event, isSelected, onSelect, optionsMenu}: Ti
},
[onSelect, event, isSelectable],
)

return (
<Tooltip
content={
isSelectable
? ''
: // TODO: Confirm this and translate it
// eslint-disable-next-line @sanity/i18n/no-attribute-string-literals
'It is not possible to select this event'
}
disabled={isSelectable}
>
<Tooltip content={isSelectable ? '' : t('changes.not.selectable')} disabled={isSelectable}>
<Flex gap={1}>
<Card
as={isSelectable ? 'button' : 'div'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export function PublishedEventMenu({event}: {event: PublishDocumentVersionEvent}
since: undefined,
})
setTimeout(() => {
// A bug is produced when we change the perspective and the params at the same time
// A bug is generated when we change the perspective and the params at the same time
// Resetting the params to the value it had before, because the paneRouter uses the previous value
setPerspective('drafts')
}, 100)
}, [setParams, params, event.versionRevisionId, setPerspective])
Expand Down

0 comments on commit ebac782

Please sign in to comment.