Skip to content

Commit c3f3680

Browse files
authored
Fix dashboard navigation (codesandbox#3184)
1 parent dc3934e commit c3f3680

File tree

3 files changed

+60
-30
lines changed

3 files changed

+60
-30
lines changed

packages/app/src/app/pages/Dashboard/Content/routes/PathedSandboxes/Navigation/NavigationLink.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,30 @@ import { NavigationLink as StyledLink } from './elements';
88

99
interface ICollectedProps {
1010
connectDropTarget: ConnectDropTarget;
11+
isOver: boolean;
1112
}
1213

1314
interface IOwnProps {
1415
teamId?: string;
1516
name: string;
1617
path: string;
18+
splittedPath: string[];
19+
i: number;
20+
// We need this to make drag & drop work
21+
selectedSandboxes: string[];
1722
}
1823

1924
type Props = ICollectedProps & IOwnProps;
2025

21-
const Link: React.FC<Props> = ({ teamId, name, path, connectDropTarget }) =>
26+
const Link: React.FC<Props> = ({
27+
teamId,
28+
name,
29+
path,
30+
isOver,
31+
splittedPath,
32+
i,
33+
connectDropTarget,
34+
}) =>
2235
connectDropTarget(
2336
<div>
2437
<StyledLink
@@ -27,6 +40,9 @@ const Link: React.FC<Props> = ({ teamId, name, path, connectDropTarget }) =>
2740
? `/dashboard/teams/${teamId}/sandboxes${path}`
2841
: `/dashboard/sandboxes${path}`
2942
}
43+
last={i === splittedPath.length - 1 ? 'true' : undefined}
44+
first={i === 0 ? 'true' : undefined}
45+
style={isOver ? { color: 'white' } : {}}
3046
>
3147
{name}
3248
</StyledLink>
Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import styled from 'styled-components';
1+
import styled, { css } from 'styled-components';
22
import { Link } from 'react-router-dom';
33

44
export const Container = styled.div`
@@ -9,7 +9,7 @@ export const Container = styled.div`
99

1010
// TODO: Use withoutProps utility from common once Follow Templates is merged
1111
// to remove the DOM error for teamId prop
12-
export const NavigationLink = styled(Link)`
12+
export const NavigationLink = styled(Link)<{ first?: string; last?: string }>`
1313
transition: 0.3s ease color;
1414
margin-right: 0.5rem;
1515
text-decoration: none;
@@ -23,19 +23,24 @@ export const NavigationLink = styled(Link)`
2323
margin-right: 0;
2424
}
2525
26-
margin-left: 0.5rem;
27-
&:first-of-type {
28-
margin-left: 0;
29-
}
30-
31-
&:last-of-type {
32-
color: white;
33-
}
26+
${props =>
27+
props.first
28+
? css`
29+
margin-left: 0;
30+
`
31+
: css`
32+
margin-left: 0.5rem;
33+
`};
3434
35-
&::after {
36-
content: '›';
37-
}
38-
&:last-of-type::after {
39-
content: none;
40-
}
35+
${props =>
36+
props.last
37+
? css`
38+
color: white;
39+
`
40+
: css`
41+
&::after {
42+
content: '›';
43+
margin-left: 0.5rem;
44+
}
45+
`};
4146
`;

packages/app/src/app/pages/Dashboard/Content/routes/PathedSandboxes/Navigation/index.tsx

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { join } from 'path';
33

4+
import { useOvermind } from 'app/overmind';
45
import { Container } from './elements';
56
import { NavigationLink } from './NavigationLink';
67

@@ -10,25 +11,33 @@ interface INavigationProps {
1011
}
1112

1213
export const Navigation: React.FC<INavigationProps> = ({ path, teamId }) => {
14+
const { state } = useOvermind();
15+
1316
const splittedPath = path === '/' ? [''] : path.split('/');
1417

15-
const paths: Array<{ url: string; name: string }> = splittedPath.reduce(
16-
(bases, next) => {
17-
if (next === '') {
18-
return [{ url: '/', name: teamId ? 'Team Sandboxes' : 'My Sandboxes' }];
19-
}
18+
const paths = splittedPath.reduce((bases, next) => {
19+
if (next === '') {
20+
return [{ url: '/', name: teamId ? 'Team Sandboxes' : 'My Sandboxes' }];
21+
}
2022

21-
const baseUrl = bases[bases.length - 1].url;
22-
bases.push({ url: join(baseUrl, next), name: next });
23-
return bases;
24-
},
25-
[]
26-
);
23+
const baseUrl = bases[bases.length - 1].url;
24+
bases.push({ url: join(baseUrl, next), name: next });
25+
return bases;
26+
}, []);
2727

2828
return (
2929
<Container>
30-
{paths.map(({ name, url }) => (
31-
<NavigationLink teamId={teamId} name={name} path={url} key={url} />
30+
{paths.map(({ name, url }, i) => (
31+
<NavigationLink
32+
teamId={teamId}
33+
name={name}
34+
path={url}
35+
splittedPath={splittedPath}
36+
i={i}
37+
key={url}
38+
// Give this prop to make drag & drop work
39+
selectedSandboxes={state.dashboard.selectedSandboxes}
40+
/>
3241
))}
3342
</Container>
3443
);

0 commit comments

Comments
 (0)