From 3b777cdca34c5314b899122c875d5e007c374a09 Mon Sep 17 00:00:00 2001 From: RitaDias Date: Fri, 20 Sep 2024 09:23:54 +0200 Subject: [PATCH] refactor(structure): send in useDocumentPane info as props vs fetching them again --- .../document/documentPanel/DocumentPanel.tsx | 8 ++++++- .../banners/DraftLiveEditBanner.tsx | 23 +++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/packages/sanity/src/structure/panes/document/documentPanel/DocumentPanel.tsx b/packages/sanity/src/structure/panes/document/documentPanel/DocumentPanel.tsx index dc88a2ded8f..dac52251855 100644 --- a/packages/sanity/src/structure/panes/document/documentPanel/DocumentPanel.tsx +++ b/packages/sanity/src/structure/panes/document/documentPanel/DocumentPanel.tsx @@ -154,7 +154,13 @@ export const DocumentPanel = function DocumentPanel(props: DocumentPanelProps) { scrollElement={documentScrollElement} containerElement={formContainerElement} > - {activeView.type === 'form' && isLiveEdit && ready && } + {activeView.type === 'form' && isLiveEdit && ready && ( + + )} {activeView.type === 'form' && !isPermissionsLoading && ready && ( <> diff --git a/packages/sanity/src/structure/panes/document/documentPanel/banners/DraftLiveEditBanner.tsx b/packages/sanity/src/structure/panes/document/documentPanel/banners/DraftLiveEditBanner.tsx index e368b852330..d14e71c9a4b 100644 --- a/packages/sanity/src/structure/panes/document/documentPanel/banners/DraftLiveEditBanner.tsx +++ b/packages/sanity/src/structure/panes/document/documentPanel/banners/DraftLiveEditBanner.tsx @@ -1,20 +1,35 @@ +import {type SanityDocument} from '@sanity/client' import {ErrorOutlineIcon} from '@sanity/icons' import {useTelemetry} from '@sanity/telemetry/react' import {Flex, Text} from '@sanity/ui' import {useCallback, useEffect, useState} from 'react' -import {isDraftId, Translate, useDocumentOperation, useTranslation} from 'sanity' +import { + isDraftId, + type ObjectSchemaType, + Translate, + useDocumentOperation, + useTranslation, +} from 'sanity' import {Button} from '../../../../../ui-components' import {structureLocaleNamespace} from '../../../../i18n' -import {useDocumentPane} from '../../useDocumentPane' import { DiscardedLiveEditDraft, PublishedLiveEditDraft, } from './__telemetry__/DraftLiveEditBanner.telemetry' import {Banner} from './Banner' -export function DraftLiveEditBanner(): JSX.Element | null { - const {displayed, documentId, schemaType} = useDocumentPane() +interface DraftLiveEditBannerProps { + displayed: Partial | null + documentId: string + schemaType: ObjectSchemaType +} + +export function DraftLiveEditBanner({ + displayed, + documentId, + schemaType, +}: DraftLiveEditBannerProps): JSX.Element | null { const {t} = useTranslation(structureLocaleNamespace) const [isPublishing, setPublishing] = useState(false) const [isDiscarding, setDiscarding] = useState(false)