Skip to content

Commit 501b9cf

Browse files
committed
#681 Switch to current drive button
1 parent 0734dae commit 501b9cf

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

browser/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This changelog covers all three packages, as they are (for now) updated as a who
1111
- Show resource usage (incoming links) in data view.
1212
- New resource selector that uses searchbox #677
1313
- Sidebar redesign
14+
- Switch to current drive button #681
1415

1516
### @tomic/lib
1617

browser/data-browser/src/components/Parent.tsx

+31-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { Row } from './Row';
1414
import { useQueryScopeHandler } from '../hooks/useQueryScope';
1515
import { IconButton } from './IconButton/IconButton';
1616
import { useNavigateWithTransition } from '../hooks/useNavigateWithTransition';
17+
import { useSettings } from '../helpers/AppSettings';
18+
import { Button } from './Button';
1719

1820
type 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

7985
const 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 */
82106
function 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

Comments
 (0)