@@ -14,6 +14,8 @@ import { Row } from './Row';
1414import { useQueryScopeHandler } from '../hooks/useQueryScope' ;
1515import { IconButton } from './IconButton/IconButton' ;
1616import { useNavigateWithTransition } from '../hooks/useNavigateWithTransition' ;
17+ import { useSettings } from '../helpers/AppSettings' ;
18+ import { Button } from './Button' ;
1719
1820type ParentProps = {
1921 resource : Resource ;
@@ -31,7 +33,11 @@ function Parent({ resource }: ParentProps): JSX.Element {
3133 return (
3234 < ParentWrapper aria-label = 'Breadcrumbs' >
3335 < Row fullWidth center gap = 'initial' >
34- { parent && < NestedParent subject = { parent } depth = { 0 } /> }
36+ { parent ? (
37+ < NestedParent subject = { parent } depth = { 0 } />
38+ ) : (
39+ < DriveMismatch subject = { resource . getSubject ( ) } />
40+ ) }
3541 { canEdit ? (
3642 < BreadCrumbInputWrapper >
3743 < BreadCrumbInput
@@ -78,6 +84,24 @@ type NestedParentProps = {
7884
7985const MAX_BREADCRUMB_DEPTH = 4 ;
8086
87+ /** Shows a "Set drive" button if the current drive is different from the Subject */
88+ function DriveMismatch ( { subject } : { subject : string } ) {
89+ const { drive, setDrive } = useSettings ( ) ;
90+
91+ const handleSetDrive = ( ) => {
92+ setDrive ( subject ) ;
93+ } ;
94+
95+ const mismatch = subject && subject !== drive ;
96+
97+ if ( mismatch )
98+ return (
99+ < Button onClick = { handleSetDrive } title = 'Set Drive' >
100+ Set Drive
101+ </ Button >
102+ ) ;
103+ }
104+
81105/** The actually recursive part */
82106function NestedParent ( { subject, depth } : NestedParentProps ) : JSX . Element {
83107 const resource = useResource ( subject , { allowIncomplete : true } ) ;
@@ -87,7 +111,7 @@ function NestedParent({ subject, depth }: NestedParentProps): JSX.Element {
87111
88112 // Prevent infinite recursion, set a limit to parent breadcrumbs
89113 if ( depth > MAX_BREADCRUMB_DEPTH ) {
90- return < Breadcrumb > ... </ Breadcrumb > ;
114+ return < Breadcrumb > Set as drive </ Breadcrumb > ;
91115 }
92116
93117 function handleClick ( e ) {
@@ -97,7 +121,11 @@ function NestedParent({ subject, depth }: NestedParentProps): JSX.Element {
97121
98122 return (
99123 < >
100- { parent && < NestedParent subject = { parent } depth = { depth + 1 } /> }
124+ { parent ? (
125+ < NestedParent subject = { parent } depth = { depth + 1 } />
126+ ) : (
127+ < DriveMismatch subject = { subject } />
128+ ) }
101129 < Breadcrumb href = { subject } onClick = { handleClick } >
102130 { title }
103131 </ Breadcrumb >
0 commit comments