Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KARMA-GAP] Small fixes on the grants completion badge #3722

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/grant-explorer/src/features/api/gap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface IGapGrant {
isGrantUpdate?: boolean;
}[];
updates: IGrantStatus[];
completed?: IGrantStatus;
}

export interface IGapImpact {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { IGapGrant } from "../../api/gap";
import { Flex } from "@chakra-ui/react";

interface CompletionBadgeProps {
completed: IGapGrant["completed"];
milestones: IGapGrant["milestones"];
}

export const GrantCompletionBadge: React.FC<CompletionBadgeProps> = ({
completed,
milestones,
}) => {
const filteredMilestones = milestones.filter(
Expand All @@ -18,10 +20,15 @@ export const GrantCompletionBadge: React.FC<CompletionBadgeProps> = ({
0
);

const percent =
filteredMilestones.length > 0
? Math.floor((completedCount / filteredMilestones.length) * 100)
: 0;
let percent = 0;
if (milestones.length === 0) {
percent = completed ? 100 : 0;
} else {
percent =
filteredMilestones.length > 0
? Math.floor((completedCount / filteredMilestones.length) * 100)
: 0;
}

return (
<Flex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ export const GrantItem: React.FC<GrantItemProps> = ({ grant, url }) => {
{dateFromMs(grant.createdAtMs)}
</small>
</Box>
<GrantCompletionBadge milestones={grant.milestones} />
<GrantCompletionBadge
completed={grant?.completed}
milestones={grant.milestones}
/>
</Flex>
</Flex>
<Box>
Expand Down