Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(structure): use correct loading messages while resolving panes #6093

Merged
merged 1 commit into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/sanity/src/structure/__workshop__/LoadingPaneStory.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {Card, Stack, Text} from '@sanity/ui'

import {PaneLayout} from '../components'
import {LoadingPane} from '../panes'

export default function LoadingPaneStory() {
return (
<Stack space={3}>
<Card padding={4} tone="positive">
<Text align="center">
Note: This is <em>intentionally</em> not resolving. We're testing the loading pane!
</Text>
</Card>
<PaneLayout height="fill">
<LoadingPane paneKey="loading" />
</PaneLayout>
</Stack>
)
}
5 changes: 5 additions & 0 deletions packages/sanity/src/structure/__workshop__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,10 @@ export default defineScope({
title: 'Document state',
component: lazy(() => import('./DocumentStateStory')),
},
{
name: 'loading-pane',
title: 'Loading pane',
component: lazy(() => import('./LoadingPaneStory')),
},
],
})
4 changes: 2 additions & 2 deletions packages/sanity/src/structure/panes/loading/LoadingPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ export const LoadingPane = memo((props: LoadingPaneProps) => {

const [currentMessage, setCurrentMessage] = useState<string | null>(() => {
if (typeof resolvedMessage === 'string') return resolvedMessage
return DEFAULT_MESSAGE_KEY
return t(DEFAULT_MESSAGE_KEY)
})

useEffect(() => {
if (typeof resolvedMessage !== 'object') return undefined
if (typeof resolvedMessage.subscribe === 'function') return undefined
if (typeof resolvedMessage.subscribe !== 'function') return undefined

const sub = resolvedMessage.subscribe((message) => {
setCurrentMessage('messageKey' in message ? t(message.messageKey) : message.message)
Expand Down
Loading