Skip to content

Commit 6d61e94

Browse files
authoredFeb 29, 2024
feat(structure): support closing first collapsed DocumentPanel (#5867)
1 parent 84a0c90 commit 6d61e94

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed
 

‎packages/sanity/src/structure/components/paneRouter/PaneRouterProvider.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ export function PaneRouterProvider(props: {
149149
ChildLink,
150150

151151
// Curried StateLink that pops off the last pane group
152-
BackLink,
152+
// Only pass if this is not the first pane
153+
BackLink: flatIndex ? BackLink : undefined,
153154

154155
// A specialized `ChildLink` that takes in the needed props to open a
155156
// referenced document to the right

‎packages/sanity/src/structure/components/paneRouter/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export interface PaneRouterContextValue {
101101
/**
102102
* Curried StateLink that pops off the last pane group
103103
*/
104-
BackLink: React.ComponentType<BackLinkProps>
104+
BackLink?: React.ComponentType<BackLinkProps>
105105

106106
/**
107107
* A specialized `ChildLink` that takes in the needed props to open a

‎packages/sanity/src/structure/panes/document/documentPanel/header/DocumentPanelHeader.tsx

+9-4
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,17 @@ export const DocumentPanelHeader = memo(
7878
// and there is more than one split pane open (aka has-siblings)
7979
const showSplitPaneCloseButton = showSplitPaneButton && hasGroupSiblings
8080

81+
// show the back button if both the feature is enabled and the current pane
82+
// is not the first
83+
const showBackButton = features.backButton && index > 0
84+
8185
// show the pane group close button if the `showSplitPaneCloseButton` is
8286
// _not_ showing (the split pane button replaces the group close button)
8387
// and if the back button is not showing (the back button and the close
84-
// button) do the same thing and shouldn't be shown at the same time)
85-
const showPaneGroupCloseButton = !showSplitPaneCloseButton && !features.backButton
88+
// button do the same thing and shouldn't be shown at the same time)
89+
// and if a BackLink component was provided
90+
const showPaneGroupCloseButton = !showSplitPaneCloseButton && !showBackButton && !!BackLink
91+
8692
const {t} = useTranslation(structureLocaleNamespace)
8793

8894
return (
@@ -95,8 +101,7 @@ export const DocumentPanelHeader = memo(
95101
tabs={showTabs && <DocumentHeaderTabs />}
96102
tabIndex={tabIndex}
97103
backButton={
98-
features.backButton &&
99-
index > 0 && (
104+
showBackButton && (
100105
<Button
101106
as={BackLink}
102107
data-as="a"

0 commit comments

Comments
 (0)
Please sign in to comment.