Skip to content

Commit 870f0ec

Browse files
authored
Merge pull request #3756 from IntersectMBO/staging
v2.0.25.1
2 parents b9d1aac + 21e4314 commit 870f0ec

File tree

6 files changed

+301
-111
lines changed

6 files changed

+301
-111
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ changes.
2222
- Fix adding two link input fields when editing the dRep form when no links are present initially [Issue 3709](https://github.com/IntersectMBO/govtool/issues/3709)
2323

2424
### Changed
25+
- Adjust top menu (navbar) layout when wallet is not connected [Issue-3682](https://github.com/IntersectMBO/govtool/issues/3682)
2526

2627
### Removed
2728

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,59 @@
1-
import { FC } from "react";
1+
import { forwardRef, MouseEvent } from "react";
22
import { NavLink } from "react-router-dom";
33
import { Typography } from "@mui/material";
44
import { useCardano } from "@context";
55

66
type LinkProps = {
77
dataTestId?: string;
88
isConnectWallet?: boolean;
9-
label: string;
9+
label: React.ReactNode;
1010
navTo: string;
11-
onClick?: () => void;
11+
onClick?: (event: MouseEvent<HTMLAnchorElement>) => void;
1212
size?: "small" | "big";
1313
};
1414

15-
export const Link: FC<LinkProps> = ({ ...props }) => {
16-
const {
17-
dataTestId,
18-
isConnectWallet,
19-
label,
20-
navTo,
21-
size = "small",
22-
onClick,
23-
} = props;
24-
const { disconnectWallet } = useCardano();
15+
export const Link = forwardRef<HTMLAnchorElement, LinkProps>(
16+
({ ...props }, ref) => {
17+
const {
18+
dataTestId,
19+
isConnectWallet,
20+
label,
21+
navTo,
22+
size = "small",
23+
onClick,
24+
} = props;
25+
const { disconnectWallet } = useCardano();
2526

26-
const fontSize = {
27-
small: 14,
28-
big: 22,
29-
}[size];
27+
const fontSize = {
28+
small: 14,
29+
big: 22,
30+
}[size];
3031

31-
return (
32-
<NavLink
33-
data-testid={dataTestId}
34-
to={navTo}
35-
style={{
36-
textDecoration: "none",
37-
}}
38-
onClick={() => {
39-
if (!isConnectWallet) disconnectWallet();
40-
if (onClick) onClick();
41-
}}
42-
>
43-
{({ isActive }) => (
44-
<Typography
45-
sx={{
46-
fontSize,
47-
fontWeight: isActive && navTo !== "" ? 600 : 500,
48-
color: isActive && navTo !== "" ? "#FF640A" : "textBlack",
49-
}}
50-
>
51-
{label}
52-
</Typography>
53-
)}
54-
</NavLink>
55-
);
56-
};
32+
return (
33+
<NavLink
34+
data-testid={dataTestId}
35+
to={navTo}
36+
style={{
37+
textDecoration: "none",
38+
}}
39+
onClick={(e) => {
40+
if (!isConnectWallet) disconnectWallet();
41+
if (onClick) onClick(e);
42+
}}
43+
ref={ref}
44+
>
45+
{({ isActive }) => (
46+
<Typography
47+
sx={{
48+
fontSize,
49+
fontWeight: isActive && navTo !== "" ? 600 : 500,
50+
color: isActive && navTo !== "" ? "#FF640A" : "textBlack",
51+
}}
52+
>
53+
{label}
54+
</Typography>
55+
)}
56+
</NavLink>
57+
);
58+
},
59+
);

govtool/frontend/src/components/organisms/DrawerMobile.tsx

Lines changed: 69 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import { FC } from "react";
12
import { NavLink } from "react-router-dom";
23
import { Box, Grid, IconButton, SwipeableDrawer } from "@mui/material";
34

45
import { Background, Button, Link, Typography } from "@atoms";
5-
import { ICONS, IMAGES, NAV_ITEMS, PATHS } from "@consts";
6+
import { ICONS, IMAGES, NAV_ITEMS, NavMenuItem, NavItem, PATHS } from "@consts";
67
import { useScreenDimension, useTranslation } from "@hooks";
78
import { useFeatureFlag, useModal } from "@context";
89
import { openInNewTab } from "@utils";
@@ -13,15 +14,14 @@ import { LINKS } from "@/consts/links";
1314
const DRAWER_PADDING = 2;
1415
const CALCULATED_DRAWER_PADDING = DRAWER_PADDING * 8 * 2;
1516

17+
const isNavMenuItem = (item: NavItem | NavMenuItem): item is NavMenuItem =>
18+
"childNavItems" in item;
19+
1620
export const DrawerMobile = ({
1721
isConnectButton,
1822
isDrawerOpen,
1923
setIsDrawerOpen,
2024
}: DrawerMobileProps) => {
21-
const {
22-
isProposalDiscussionForumEnabled,
23-
isGovernanceOutcomesPillarEnabled,
24-
} = useFeatureFlag();
2525
const { screenWidth } = useScreenDimension();
2626
const { openModal } = useModal();
2727
const { t } = useTranslation();
@@ -85,18 +85,13 @@ export const DrawerMobile = ({
8585
<Box sx={{ display: "flex", flex: 1, flexDirection: "column" }}>
8686
<Grid container direction="column" mt={6} rowGap={4}>
8787
{NAV_ITEMS.map((navItem) => {
88-
if (
89-
!isProposalDiscussionForumEnabled &&
90-
navItem.dataTestId === "proposed-governance-actions-link"
91-
) {
92-
return null;
93-
}
94-
95-
if (
96-
!isGovernanceOutcomesPillarEnabled &&
97-
navItem.dataTestId === "governance-actions-outcomes-link"
98-
) {
99-
return null;
88+
if (isNavMenuItem(navItem)) {
89+
return (
90+
<MenuNavItem
91+
closeDrawer={() => setIsDrawerOpen(false)}
92+
navItem={navItem}
93+
/>
94+
);
10095
}
10196
return (
10297
<Grid item key={navItem.label}>
@@ -129,3 +124,60 @@ export const DrawerMobile = ({
129124
</SwipeableDrawer>
130125
);
131126
};
127+
128+
const MenuNavItem: FC<{
129+
navItem: NavMenuItem;
130+
closeDrawer: () => void;
131+
}> = ({ closeDrawer, navItem }) => {
132+
const {
133+
isProposalDiscussionForumEnabled,
134+
isGovernanceOutcomesPillarEnabled,
135+
} = useFeatureFlag();
136+
137+
const filterChildNavItems = () => {
138+
if (navItem.dataTestId === "governance-actions") {
139+
return (navItem.childNavItems || []).filter((item) => {
140+
if (
141+
!isProposalDiscussionForumEnabled &&
142+
item.dataTestId === "proposed-governance-actions-link"
143+
)
144+
return false;
145+
if (
146+
!isGovernanceOutcomesPillarEnabled &&
147+
item.dataTestId === "governance-actions-outcomes-link"
148+
)
149+
return false;
150+
return true;
151+
});
152+
}
153+
return navItem.childNavItems;
154+
};
155+
return (
156+
<>
157+
<Grid item key={navItem.label}>
158+
<Link
159+
navTo=""
160+
data-testid={navItem.dataTestId}
161+
label={navItem.label}
162+
size="big"
163+
/>
164+
</Grid>
165+
{filterChildNavItems()?.map((childNavItem) => (
166+
<Grid item key={childNavItem.label} ml={3}>
167+
<Link
168+
{...childNavItem}
169+
data-testid={childNavItem.dataTestId}
170+
onClick={() => {
171+
if (childNavItem.newTabLink) {
172+
openInNewTab(childNavItem.newTabLink);
173+
}
174+
closeDrawer();
175+
}}
176+
label={childNavItem.label}
177+
size="big"
178+
/>
179+
</Grid>
180+
))}
181+
</>
182+
);
183+
};

0 commit comments

Comments
 (0)