@@ -14,6 +14,8 @@ import { Row } from './Row';
14
14
import { useQueryScopeHandler } from '../hooks/useQueryScope' ;
15
15
import { IconButton } from './IconButton/IconButton' ;
16
16
import { useNavigateWithTransition } from '../hooks/useNavigateWithTransition' ;
17
+ import { useSettings } from '../helpers/AppSettings' ;
18
+ import { Button } from './Button' ;
17
19
18
20
type ParentProps = {
19
21
resource : Resource ;
@@ -31,7 +33,11 @@ function Parent({ resource }: ParentProps): JSX.Element {
31
33
return (
32
34
< ParentWrapper aria-label = 'Breadcrumbs' >
33
35
< 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
+ ) }
35
41
{ canEdit ? (
36
42
< BreadCrumbInputWrapper >
37
43
< BreadCrumbInput
@@ -78,6 +84,24 @@ type NestedParentProps = {
78
84
79
85
const MAX_BREADCRUMB_DEPTH = 4 ;
80
86
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
+
81
105
/** The actually recursive part */
82
106
function NestedParent ( { subject, depth } : NestedParentProps ) : JSX . Element {
83
107
const resource = useResource ( subject , { allowIncomplete : true } ) ;
@@ -87,7 +111,7 @@ function NestedParent({ subject, depth }: NestedParentProps): JSX.Element {
87
111
88
112
// Prevent infinite recursion, set a limit to parent breadcrumbs
89
113
if ( depth > MAX_BREADCRUMB_DEPTH ) {
90
- return < Breadcrumb > ... </ Breadcrumb > ;
114
+ return < Breadcrumb > Set as drive </ Breadcrumb > ;
91
115
}
92
116
93
117
function handleClick ( e ) {
@@ -97,7 +121,11 @@ function NestedParent({ subject, depth }: NestedParentProps): JSX.Element {
97
121
98
122
return (
99
123
< >
100
- { parent && < NestedParent subject = { parent } depth = { depth + 1 } /> }
124
+ { parent ? (
125
+ < NestedParent subject = { parent } depth = { depth + 1 } />
126
+ ) : (
127
+ < DriveMismatch subject = { subject } />
128
+ ) }
101
129
< Breadcrumb href = { subject } onClick = { handleClick } >
102
130
{ title }
103
131
</ Breadcrumb >
0 commit comments