Skip to content

Commit

Permalink
feat: add PullRequestSocialCard component to design system (#774)
Browse files Browse the repository at this point in the history
Closes #716
  • Loading branch information
OgDev-01 authored Jan 24, 2023
1 parent ce7c061 commit 04600c2
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ export interface LanguageObject {

interface CardHorizontalBarChartProps {
languageList: LanguageObject[];
withDescription: boolean;
}

const languageToColor: AllSimpleColors = colors as AllSimpleColors;

const CardHorizontalBarChart = ({ languageList }: CardHorizontalBarChartProps): JSX.Element => {
const CardHorizontalBarChart = ({ languageList, withDescription }: CardHorizontalBarChartProps): JSX.Element => {
const sortedLangArray = languageList.sort((a, b) => b.percentageUsed - a.percentageUsed);
// used this state to calculate thte percentage of each language
const [percentage, setPercentage] = useState<any>(0);
Expand All @@ -34,39 +35,51 @@ const CardHorizontalBarChart = ({ languageList }: CardHorizontalBarChartProps):
setDescriptText(descriptText);
};

useEffect(() =>{
useEffect(() => {
const totalSumOfFirstFivePercentage = sortedLangArray
.slice(0,4)
.map(lang => lang.percentageUsed)
.slice(0, 4)
.map((lang) => lang.percentageUsed)
.reduce((prev: number, next: number) => prev + next); // need some help fixing this type error, used any to bypass 🙏
setPercentage(totalSumOfFirstFivePercentage);
},[percentage, sortedLangArray]);
}, [percentage, sortedLangArray]);

return (
<div className="flex flex-col gap-1 min-w-[120px]">
{/* Progress Bar */}
<div className="flex items-center w-full justify-end rounded-full gap-0.5 overflow-hidden">
{sortedLangArray.map(({ languageName, percentageUsed }, index) =>
{

return index < 5 && ( <div
key={index}
onMouseOver={() => handleChangeDescriptText(languageName)}
className="h-2 transition-all duration-500 ease-in-out"
style={{ width: `${percentageUsed < 20 ? percentageUsed / percentage * 100 : percentageUsed}%`, backgroundColor: languageToColor[languageName] ? languageToColor[languageName].color as string : NOTSUPPORTED }}
/>);
}

)}
</div>
<div className="flex gap-2 w-32 items-baseline">
<div className={"w-2 h-2 rounded-full"} style={{ backgroundColor: languageToColor[descriptText] ? languageToColor[descriptText].color as string : NOTSUPPORTED }}/>
<Tooltip className="max-w-[100px]" content={descriptText}>
<Text className="!text-xs !truncate !font-semibold !text-light-slate-11">
{descriptText}
</Text>
</Tooltip>
{sortedLangArray.map(({ languageName, percentageUsed }, index) => {
return (
index < 5 && (
<div
key={index}
onMouseOver={() => handleChangeDescriptText(languageName)}
className="h-2 transition-all duration-500 ease-in-out"
style={{
width: `${percentageUsed < 20 ? (percentageUsed / percentage) * 100 : percentageUsed}%`,
backgroundColor: languageToColor[languageName]
? (languageToColor[languageName].color as string)
: NOTSUPPORTED
}}
/>
)
);
})}
</div>
{withDescription && (
<div className="flex gap-2 w-32 items-baseline">
<div
className={"w-2 h-2 rounded-full"}
style={{
backgroundColor: languageToColor[descriptText]
? (languageToColor[descriptText].color as string)
: NOTSUPPORTED
}}
/>
<Tooltip className="max-w-[100px]" content={descriptText}>
<Text className="!text-xs !truncate !font-semibold !text-light-slate-11">{descriptText}</Text>
</Tooltip>
</div>
)}
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { IconContext } from "react-icons";
import { VscGitPullRequest } from "react-icons/vsc";
import { FaRegCommentAlt } from "react-icons/fa";

import CardHorizontalBarChart, { LanguageObject } from "../CardHorizontalBarChart/card-horizontal-bar-chart";
import Text from "components/atoms/Typography/text";
import Avatar from "components/atoms/Avatar/avatar";

interface PullRequestSocialCardProps {
orgName: string;
repoName: string;
languageList: LanguageObject[];
prTicketId: string;
prTitle: string;
commentsCount?: number;
avatar?: string;
linesAdded?: number;
linesRemoved?: number;
}
const PullRequestSocialCard = ({
orgName,
repoName,
prTitle,
avatar,
languageList,
prTicketId,
commentsCount,
linesAdded,
linesRemoved
}: PullRequestSocialCardProps) => {
return (
<div className="w-[26.375rem] cursor-pointer border rounded-xl px-5 py-4">
<div className="flex gap-2 items-center ">
<Avatar alt="" avatarURL={avatar} initials="" size="sm" />
<Text className="!text-sm !text-light-slate-11">
{orgName}/<span className="text-light-slate-11">{repoName}</span>
</Text>
</div>
<div className="flex gap-2 items-start mt-2">
<IconContext.Provider value={{ color: "green", style: { width: 18, height: 18, marginTop: 4 } }}>
<VscGitPullRequest title="Open Pull Request" />
</IconContext.Provider>
<Text className="!text-lg ">
<span className="text-light-slate-10 ">{prTicketId}</span> {prTitle}
</Text>
</div>

{/* Language list section */}
<div className="mt-6">
<CardHorizontalBarChart withDescription={false} languageList={languageList} />
</div>

<div className="flex items-center gap-5 text-light-slate-10 mt-3">
<div className="flex justify-between gap-2">
<span title="lines added" className="text-green-600">
+{linesAdded || 0}
</span>

<span title="lines removed" className="text-red-600">
-{linesRemoved || 0}
</span>
</div>
<div className="flex gap-0.5">
<div className="w-3 h-3 bg-green-600 rounded"></div>
<div className="w-3 h-3 bg-green-600 rounded"></div>
<div className="w-3 h-3 bg-green-600 rounded"></div>
<div className="w-3 h-3 bg-green-600 rounded"></div>
<div className="w-3 h-3 bg-light-slate-8 rounded"></div>
</div>
{commentsCount && (
<div className="flex text-light-slate-10 items-center gap-2">
{`${commentsCount} comment${commentsCount > 1 ? "s" : ""}`} <FaRegCommentAlt size={16} />
</div>
)}
</div>
</div>
);
};

export default PullRequestSocialCard;
2 changes: 1 addition & 1 deletion components/organisms/ContributorCard/contributor-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const ContributorCard = ({ className, contributor, topic, repositories }: Contri
<div className="flex w-full justify-between items-center gap-2">
<CardProfile {...profile} />
<div>
<CardHorizontalBarChart languageList={languageList} />
<CardHorizontalBarChart withDescription={false} languageList={languageList} />
</div>
</div>
<div className="h-[110px] overflow-hidden">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import { IconContext } from "react-icons";
import { BsFillArrowUpCircleFill } from "react-icons/bs";
import { FaCheckCircle } from "react-icons/fa";
import { VscGitMerge, VscRepo } from "react-icons/vsc";

import Title from "components/atoms/Typography/title";
import Text from "components/atoms/Typography/text";
import CardHorizontalBarChart from "components/molecules/CardHorizontalBarChart/card-horizontal-bar-chart";
Expand Down Expand Up @@ -95,7 +90,7 @@ const ContributorProfilePage = ({
</div>
<div>
<p className="mb-4">Languages</p>
<CardHorizontalBarChart languageList={languageList} />
<CardHorizontalBarChart withDescription={false} languageList={languageList} />
</div>
</div>
<div className="flex-1">
Expand Down
2 changes: 1 addition & 1 deletion stories/molecules/card-horizontal-bar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const storyConfig = {

export default storyConfig;

const testLanguageList = [
export const testLanguageList = [
{
languageName: "TypeScript",
percentageUsed: 50
Expand Down
31 changes: 31 additions & 0 deletions stories/molecules/pull-request-social-card.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ComponentStory } from "@storybook/react";
import PullRequestSocialCard from "components/molecules/PullRequestSocialCard/pull-request-social-card";
import { testLanguageList } from "./card-horizontal-bar.stories";
import { TooltipProvider } from "@radix-ui/react-tooltip";

const StoryConfig = {
title: "Design System/Molecules/PullRequestSocialCard"
};
export default StoryConfig;

const PullRequestSocialCardTemplate: ComponentStory<typeof PullRequestSocialCard> = (args) => (
<TooltipProvider>
<PullRequestSocialCard {...args} />
</TooltipProvider>
);

export const PullRequestSocialCardStory = PullRequestSocialCardTemplate.bind({});

PullRequestSocialCardStory.args = {
prTitle: "Add support for Swift Package Manager",
orgName: "open-sauced",
repoName: "insights",
avatar:
"https://images.unsplash.com/photo-1534528741775-53994a69daeb?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1064&q=80",

languageList: testLanguageList,
prTicketId: "#223",
commentsCount: 5,
linesAdded: 12,
linesRemoved: 4
};

0 comments on commit 04600c2

Please sign in to comment.