Skip to content

Commit

Permalink
Merge pull request #2520 from IntersectMBO/fix/2511-typeerror-cannot-…
Browse files Browse the repository at this point in the history
…read-properties-of-undefined-reading-length

fix(#2511): fix app crash on governance action details page
  • Loading branch information
MSzalowski authored Dec 13, 2024
2 parents 44d2ca0 + 579c2e9 commit f6d4f67
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ changes.
- Fix mzero parsing error on fetching the /proposal/list [Issue 2446](https://github.com/IntersectMBO/govtool/issues/2446)
- Fix scaling gov action votes on lower resolutions
- Fix storing url missing length validation [Issue 2044](https://github.com/IntersectMBO/govtool/issues/2044)
- Fix governance action details page crash on missing data [Issue 2511](https://github.com/IntersectMBO/govtool/issues/2511)

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ export const GovernanceActionDetailsCardLinks = ({
>
{t("govActions.supportingLinks")}
</Typography>
{links.map(({ uri, label }) => (
<Box display="flex" flexDirection="column" overflow="hidden">
{links?.map(({ uri, label }) => (
<Box
key={`${label}-${uri}-label`}
display="flex"
flexDirection="column"
overflow="hidden"
>
{label && (
<Typography
data-testid={`${label}-${uri}-label`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type GovernanceActionCardVotesProps = {
isDashboard?: boolean;
isInProgress?: boolean;
isVoter?: boolean;
vote?: ProposalVote;
vote?: ProposalVote | null;
proposal: ProposalData;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ export const GovernanceVotedOnCard = ({ votedProposal, inProgress }: Props) => {
isCopyButton
isSliderCard
/>
<GovernanceActionCardMyVote voteTxHash={vote.txHash} vote={vote.vote} />
{vote && (
<GovernanceActionCardMyVote
voteTxHash={vote.txHash}
vote={vote.vote}
/>
)}
</Box>
<Box
bgcolor="white"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { VoteContextModalState, SubmittedVotesModalState } from "../organisms";
type VoteActionFormProps = {
setIsVoteSubmitted: Dispatch<SetStateAction<boolean>>;
isInProgress?: boolean;
previousVote?: ProposalVote;
previousVote?: ProposalVote | null;
proposal: ProposalData;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const DashboardGovernanceActionsVotedOn = ({
.includes(searchPhrase.toLowerCase()),
),
}))
.filter((entry) => entry.actions.length > 0);
.filter((entry) => entry.actions?.length > 0);
}
return data;
}, [data, searchPhrase, pendingTransaction.vote]);
Expand Down Expand Up @@ -70,12 +70,12 @@ export const DashboardGovernanceActionsVotedOn = ({
title={getProposalTypeLabel(item.title)}
navigateKey={item.title}
searchPhrase={searchPhrase}
dataLength={item.actions.slice(0, 6).length}
dataLength={item.actions.slice(0, 6)?.length}
onDashboard
data={item.actions.map((action) => (
<div
className="keen-slider__slide"
key={`${action?.proposal.id}${action.vote.vote}`}
key={`${action?.proposal.id}${action.vote?.vote}`}
style={{ overflow: "visible", width: "auto" }}
>
<GovernanceVotedOnCard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type GovernanceActionDetailsCardProps = {
isDataMissing: null | MetadataValidationStatus;
isInProgress?: boolean;
isVoter?: boolean;
vote?: ProposalVote;
vote?: ProposalVote | null;
proposal: ProposalData;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export const GovernanceActionDetailsCardData = ({
textVariant={screenWidth > 1600 ? "longText" : "oneLine"}
/>

{tabs.length === 1 ? (
{tabs?.length === 1 ? (
tabs[0].content
) : (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const GovernanceActionsToVote = ({

return (
<>
{!proposals.length ? (
{!proposals?.length ? (
<Typography fontWeight={300} sx={{ py: 4 }}>
{t("govActions.noResultsForTheSearch")}
</Typography>
Expand Down Expand Up @@ -91,10 +91,10 @@ export const GovernanceActionsToVote = ({
/>
</div>
))}
dataLength={item.actions.slice(0, 6).length}
dataLength={item.actions.slice(0, 6)?.length}
filters={filters}
navigateKey={item.title}
notSlicedDataLength={item.actions.length}
notSlicedDataLength={item.actions?.length}
onDashboard={onDashboard}
searchPhrase={searchPhrase}
sorting={sorting}
Expand Down
2 changes: 1 addition & 1 deletion govtool/frontend/src/hooks/forms/useVoteActionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const useVoteActionFormController = () => {
};

type Props = {
previousVote?: ProposalVote;
previousVote?: ProposalVote | null;
voteContextHash?: string;
voteContextUrl?: string;
};
Expand Down
4 changes: 2 additions & 2 deletions govtool/frontend/src/models/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,12 @@ export type NewConstitutionAnchor = {
};

export type VotedProposalDTO = {
vote: ProposalVote;
vote: ProposalVote | null;
proposal: ProposalDataDTO;
};

export type VotedProposal = {
vote: ProposalVote;
vote: ProposalVote | null;
proposal: ProposalData;
};

Expand Down

0 comments on commit f6d4f67

Please sign in to comment.