From 47f3bc05b9e3765ac7d6edec899591fe4c8d9fde Mon Sep 17 00:00:00 2001 From: pedrobonamin Date: Mon, 2 Dec 2024 12:23:17 +0100 Subject: [PATCH] fix: various fixes after PR review --- .../src/core/field/diff/components/Event.tsx | 1 - packages/sanity/src/core/i18n/bundles/studio.ts | 2 ++ .../src/core/releases/hooks/usePerspective.tsx | 3 ++- .../ReleasePublishAllButton.tsx | 7 ++----- .../src/core/releases/util/getReleaseTone.ts | 2 +- .../core/store/events/getDocumentAtRevision.ts | 2 -- .../core/store/events/getDocumentTransactions.ts | 3 --- .../sanity/src/core/store/events/getEditEvents.ts | 2 -- .../core/store/events/getInitialFetchEvents.ts | 3 --- packages/sanity/src/core/store/events/utils.ts | 1 - packages/sanity/src/structure/i18n/resources.ts | 4 +++- .../panes/document/DocumentPaneEvents.tsx | 3 --- .../panes/document/DocumentPaneLegacyTimeline.tsx | 7 ------- .../banners/ArchivedReleaseDocumentBanner.tsx | 7 +------ .../inspectors/changes/EventsInspector.tsx | 6 ++---- .../timeline/events/EventTimelineItem.tsx | 15 +++------------ .../timeline/events/PublishedEventMenu.tsx | 3 ++- 17 files changed, 18 insertions(+), 53 deletions(-) diff --git a/packages/sanity/src/core/field/diff/components/Event.tsx b/packages/sanity/src/core/field/diff/components/Event.tsx index daedac4d6816..368288a7c286 100644 --- a/packages/sanity/src/core/field/diff/components/Event.tsx +++ b/packages/sanity/src/core/field/diff/components/Event.tsx @@ -32,7 +32,6 @@ interface UserAvatarStackProps { function UserAvatarStack({maxLength, userIds, size, withTooltip = true}: UserAvatarStackProps) { return ( - // eslint-disable-next-line react/jsx-no-undef {userIds.map((userId) => ( diff --git a/packages/sanity/src/core/i18n/bundles/studio.ts b/packages/sanity/src/core/i18n/bundles/studio.ts index e1eb3350addb..6b6e28430b82 100644 --- a/packages/sanity/src/core/i18n/bundles/studio.ts +++ b/packages/sanity/src/core/i18n/bundles/studio.ts @@ -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 */ diff --git a/packages/sanity/src/core/releases/hooks/usePerspective.tsx b/packages/sanity/src/core/releases/hooks/usePerspective.tsx index 67d39cd2858e..47248b456b0f 100644 --- a/packages/sanity/src/core/releases/hooks/usePerspective.tsx +++ b/packages/sanity/src/core/releases/hooks/usePerspective.tsx @@ -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') { diff --git a/packages/sanity/src/core/releases/tool/components/ReleasePublishAllButton/ReleasePublishAllButton.tsx b/packages/sanity/src/core/releases/tool/components/ReleasePublishAllButton/ReleasePublishAllButton.tsx index 9c53bbd0b7f2..a2f2479412de 100644 --- a/packages/sanity/src/core/releases/tool/components/ReleasePublishAllButton/ReleasePublishAllButton.tsx +++ b/packages/sanity/src/core/releases/tool/components/ReleasePublishAllButton/ReleasePublishAllButton.tsx @@ -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' @@ -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) @@ -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, @@ -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 diff --git a/packages/sanity/src/core/releases/util/getReleaseTone.ts b/packages/sanity/src/core/releases/util/getReleaseTone.ts index 58f18c1a3ed8..6747b91cf58f 100644 --- a/packages/sanity/src/core/releases/util/getReleaseTone.ts +++ b/packages/sanity/src/core/releases/util/getReleaseTone.ts @@ -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') { diff --git a/packages/sanity/src/core/store/events/getDocumentAtRevision.ts b/packages/sanity/src/core/store/events/getDocumentAtRevision.ts index 79dbeeec3be4..a9d0fca424c9 100644 --- a/packages/sanity/src/core/store/events/getDocumentAtRevision.ts +++ b/packages/sanity/src/core/store/events/getDocumentAtRevision.ts @@ -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' diff --git a/packages/sanity/src/core/store/events/getDocumentTransactions.ts b/packages/sanity/src/core/store/events/getDocumentTransactions.ts index 4768a82cc1bc..9c431a377760 100644 --- a/packages/sanity/src/core/store/events/getDocumentTransactions.ts +++ b/packages/sanity/src/core/store/events/getDocumentTransactions.ts @@ -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) } diff --git a/packages/sanity/src/core/store/events/getEditEvents.ts b/packages/sanity/src/core/store/events/getEditEvents.ts index edbed5ad84fb..c05fe26f1477 100644 --- a/packages/sanity/src/core/store/events/getEditEvents.ts +++ b/packages/sanity/src/core/store/events/getEditEvents.ts @@ -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) { diff --git a/packages/sanity/src/core/store/events/getInitialFetchEvents.ts b/packages/sanity/src/core/store/events/getInitialFetchEvents.ts index 1be5065f30d2..55f21cfa31aa 100644 --- a/packages/sanity/src/core/store/events/getInitialFetchEvents.ts +++ b/packages/sanity/src/core/store/events/getInitialFetchEvents.ts @@ -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' @@ -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) { diff --git a/packages/sanity/src/core/store/events/utils.ts b/packages/sanity/src/core/store/events/utils.ts index ace3f5b04319..993f25fc74c8 100644 --- a/packages/sanity/src/core/store/events/utils.ts +++ b/packages/sanity/src/core/store/events/utils.ts @@ -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, }, diff --git a/packages/sanity/src/structure/i18n/resources.ts b/packages/sanity/src/structure/i18n/resources.ts index 68f7efa3d969..1b8d7b1a5063 100644 --- a/packages/sanity/src/structure/i18n/resources.ts +++ b/packages/sanity/src/structure/i18n/resources.ts @@ -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 */ diff --git a/packages/sanity/src/structure/panes/document/DocumentPaneEvents.tsx b/packages/sanity/src/structure/panes/document/DocumentPaneEvents.tsx index 56a06c44d68d..c8f2f1bed7e7 100644 --- a/packages/sanity/src/structure/panes/document/DocumentPaneEvents.tsx +++ b/packages/sanity/src/structure/panes/document/DocumentPaneEvents.tsx @@ -1,5 +1,3 @@ -/* eslint-disable camelcase */ - import {useEffect, useMemo, useRef} from 'react' import { EventsProvider, @@ -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]) diff --git a/packages/sanity/src/structure/panes/document/DocumentPaneLegacyTimeline.tsx b/packages/sanity/src/structure/panes/document/DocumentPaneLegacyTimeline.tsx index 79d197b9a9f5..faedd653b231 100644 --- a/packages/sanity/src/structure/panes/document/DocumentPaneLegacyTimeline.tsx +++ b/packages/sanity/src/structure/panes/document/DocumentPaneLegacyTimeline.tsx @@ -26,11 +26,6 @@ export const DocumentPaneWithLegacyTimelineStore = (props: DocumentPaneProviderP const [timelineError, setTimelineError] = useState(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, @@ -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( diff --git a/packages/sanity/src/structure/panes/document/documentPanel/banners/ArchivedReleaseDocumentBanner.tsx b/packages/sanity/src/structure/panes/document/documentPanel/banners/ArchivedReleaseDocumentBanner.tsx index 8ef3c2316580..2bb4d4156ffb 100644 --- a/packages/sanity/src/structure/panes/document/documentPanel/banners/ArchivedReleaseDocumentBanner.tsx +++ b/packages/sanity/src/structure/panes/document/documentPanel/banners/ArchivedReleaseDocumentBanner.tsx @@ -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 = () => { @@ -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 ( - {text} + {t('banners.archived-release.description')} } action={{ diff --git a/packages/sanity/src/structure/panes/document/inspectors/changes/EventsInspector.tsx b/packages/sanity/src/structure/panes/document/inspectors/changes/EventsInspector.tsx index 0ba6e7e7f00b..fdbec4469a3b 100644 --- a/packages/sanity/src/structure/panes/document/inspectors/changes/EventsInspector.tsx +++ b/packages/sanity/src/structure/panes/document/inspectors/changes/EventsInspector.tsx @@ -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) @@ -93,7 +91,7 @@ export function EventsInspector({showChanges}: {showChanges: boolean}): ReactEle - {structureT('changes.from.label')} + {t('changes.inspector.from-label')} - {structureT('changes.to.label')} + {t('changes.inspector.to-label')} { } export function EventTimelineItem({event, isSelected, onSelect, optionsMenu}: TimelineItemProps) { + const {t} = useTranslation('studio') const isSelectable = getIsSelectable(event) const handleClick = useCallback( (evt: MouseEvent) => { @@ -35,18 +36,8 @@ export function EventTimelineItem({event, isSelected, onSelect, optionsMenu}: Ti }, [onSelect, event, isSelectable], ) - return ( - + { - // 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])