Skip to content

Commit

Permalink
fix(structure): expand parent timeline item on initial load if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin committed Nov 7, 2024
1 parent bd8f436 commit 6334224
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/sanity/src/structure/panes/document/timeline/timeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ export const Timeline = ({
return new Set()
})

useEffect(() => {
// This effect ensures that when we reload the timeline with a selected draft, we expand its parent.
if (selectedChunkId) {
const selected = chunksWithMetadata.find((chunk) => chunk.id === selectedChunkId)
if (selected && isNonPublishChunk(selected) && selected.parentId) {
const parentId = selected.parentId
setExpandedParents((prev) => {
if (prev.has(parentId)) return prev
const next = new Set(prev)
next.add(parentId)
return next
})
}
}
}, [chunksWithMetadata, selectedChunkId])

const filteredChunks = useMemo(() => {
return chunksWithMetadata.filter((chunk) => {
if (isPublishChunk(chunk) || !chunk.parentId) return true
Expand Down

0 comments on commit 6334224

Please sign in to comment.