Skip to content

Commit d86def3

Browse files
author
Adam Tomaszczyk
committed
Fix Back button on GA category view and tests
1 parent 0a50bb5 commit d86def3

File tree

7 files changed

+32
-33
lines changed

7 files changed

+32
-33
lines changed

govtool/frontend/src/App.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ export default () => {
8181
enable(walletName);
8282
return;
8383
}
84-
await new Promise(resolve => setTimeout(resolve, interval));
84+
// eslint-disable-next-line no-await-in-loop
85+
await new Promise((resolve) => {
86+
setTimeout(resolve, interval);
87+
});
8588
}
8689

8790
if (!isOnAllowedPage) {

govtool/frontend/src/components/atoms/types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ChangeEvent } from "react";
2+
import { LinkProps } from "react-router-dom";
23
import {
34
ButtonProps as MUIButtonProps,
45
CheckboxProps as MUICheckboxProps,
@@ -13,6 +14,10 @@ export type ButtonProps = Omit<MUIButtonProps, "size"> & {
1314
isLoading?: boolean;
1415
size?: "small" | "medium" | "large" | "extraLarge";
1516
dataTestId?: string;
17+
to?: LinkProps["to"];
18+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
19+
state?: any;
20+
component?: React.ElementType;
1621
};
1722

1823
export type LoadingButtonProps = ButtonProps & {

govtool/frontend/src/components/molecules/GovernanceActionCard.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const GovernanceActionCard: FC<ActionTypeProps> = ({
4040
inProgress = false,
4141
expiryDate,
4242
expiryEpochNo,
43+
onClick,
4344
createdDate,
4445
createdEpochNo,
4546
txHash,
@@ -58,7 +59,8 @@ export const GovernanceActionCard: FC<ActionTypeProps> = ({
5859
bech32Prefix: "gov_action",
5960
});
6061

61-
const location = useLocation();
62+
const pathname = useLocation().pathname.replace(/governance_actions.*/g, "governance_actions");
63+
const isCategoryView = useLocation().pathname.includes("category");
6264

6365
return (
6466
<Box
@@ -152,8 +154,23 @@ export const GovernanceActionCard: FC<ActionTypeProps> = ({
152154
<Skeleton width="100%" height="40px" sx={{ borderRadius: "20px" }} />
153155
) : (
154156
<Button
157+
onClick={onClick}
155158
component={Link}
156-
to={`${location.pathname}/${govActionId}`}
159+
to={`${pathname}/${govActionId}`}
160+
state={{
161+
proposal: {
162+
abstract,
163+
type,
164+
expiryDate,
165+
expiryEpochNo,
166+
createdDate,
167+
createdEpochNo,
168+
txHash,
169+
index,
170+
title,
171+
},
172+
openedFromCategoryPage: isCategoryView
173+
}}
157174
variant={inProgress ? "outlined" : "contained"}
158175
size="large"
159176
sx={{

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { useState, useEffect } from "react";
22

3+
import { GovernanceActionCard } from "@molecules";
34
import { useValidateMutation } from "@/hooks/mutations";
45
import { MetadataStandard, ProposalData } from "@/models";
5-
import { GovernanceActionCard } from "@molecules";
66

77
type ActionTypeProps = Omit<
88
ProposalData,
@@ -14,6 +14,7 @@ type ActionTypeProps = Omit<
1414
| "rationale"
1515
| "motivation"
1616
> & {
17+
onClick?: () => void;
1718
inProgress?: boolean;
1819
};
1920
export const ValidatedGovernanceActionCard = (props: ActionTypeProps) => {

govtool/frontend/src/pages/DashboardGovernanceActionsCategory.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useMemo, useRef } from "react";
2-
import { generatePath, useNavigate, useParams } from "react-router-dom";
2+
import { useNavigate, useParams } from "react-router-dom";
33
import { Box, CircularProgress, Link } from "@mui/material";
44

55
import { Background, Typography } from "@atoms";
@@ -18,7 +18,6 @@ import {
1818
useTranslation,
1919
} from "@hooks";
2020
import {
21-
getFullGovActionId,
2221
getProposalTypeLabel,
2322
removeDuplicatedProposals,
2423
} from "@utils";
@@ -141,18 +140,6 @@ export const DashboardGovernanceActionsCategory = () => {
141140
}
142141
onClick={() => {
143142
saveScrollPosition();
144-
145-
navigate(
146-
generatePath(PATHS.dashboardGovernanceActionsAction, {
147-
proposalId: getFullGovActionId(item.txHash, item.index),
148-
}),
149-
{
150-
state: {
151-
proposal: item,
152-
openedFromCategoryPage: true,
153-
},
154-
},
155-
);
156143
}}
157144
txHash={item.txHash}
158145
/>

govtool/frontend/src/pages/GovernanceActionsCategory.tsx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
} from "@hooks";
2121
import {
2222
WALLET_LS_KEY,
23-
getFullGovActionId,
2423
getItemFromLocalStorage,
2524
getProposalTypeLabel,
2625
removeDuplicatedProposals,
@@ -142,19 +141,6 @@ export const GovernanceActionsCategory = () => {
142141
{...item}
143142
onClick={() => {
144143
saveScrollPosition();
145-
146-
navigate(
147-
PATHS.governanceActionsAction.replace(
148-
":proposalId",
149-
getFullGovActionId(item.txHash, item.index),
150-
),
151-
{
152-
state: {
153-
proposal: item,
154-
openedFromCategoryPage: true,
155-
},
156-
},
157-
);
158144
}}
159145
/>
160146
</Box>

govtool/frontend/src/stories/Slider.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ export const SliderComponentOverflow: Story = {
5858
await expect(canvas.getByText("Slider title")).toBeInTheDocument();
5959
await expect(canvas.getAllByTestId("slider")).toHaveLength(6);
6060

61-
await expect(canvas.getByRole("button")).toBeEnabled();
61+
await expect(canvas.getByRole("link")).toBeEnabled();
6262
},
6363
};

0 commit comments

Comments
 (0)