diff --git a/apps/app/components/workspace/activity-graph.tsx b/apps/app/components/workspace/activity-graph.tsx index ec8e1dfd4..1f9db203d 100644 --- a/apps/app/components/workspace/activity-graph.tsx +++ b/apps/app/components/workspace/activity-graph.tsx @@ -1,34 +1,141 @@ +import { useEffect, useRef, useState } from "react"; + // ui -import { CalendarGraph } from "components/ui"; +import { Tooltip } from "components/ui"; // helpers -import { renderShortDateWithYearFormat } from "helpers/date-time.helper"; +import { renderDateFormat, renderShortNumericDateFormat } from "helpers/date-time.helper"; // types import { IUserActivity } from "types"; +// constants +import { DAYS, MONTHS } from "constants/project"; type Props = { activities: IUserActivity[] | undefined; }; -export const ActivityGraph: React.FC = ({ activities }) => ( - ({ - day: activity.created_date, - value: activity.activity_count, - })) ?? [] +export const ActivityGraph: React.FC = ({ activities }) => { + const ref = useRef(null); + + const [width, setWidth] = useState(0); + + const today = new Date(); + const lastMonth = new Date(today.getFullYear(), today.getMonth() - 1, 1); + const twoMonthsAgo = new Date(today.getFullYear(), today.getMonth() - 2, 1); + const threeMonthsAgo = new Date(today.getFullYear(), today.getMonth() - 3, 1); + const fourMonthsAgo = new Date(today.getFullYear(), today.getMonth() - 4, 1); + const fiveMonthsAgo = new Date(today.getFullYear(), today.getMonth() - 5, 1); + + const recentMonths = [ + fiveMonthsAgo, + fourMonthsAgo, + threeMonthsAgo, + twoMonthsAgo, + lastMonth, + today, + ]; + + const getDatesOfMonth = (dateOfMonth: Date) => { + const month = dateOfMonth.getMonth(); + const year = dateOfMonth.getFullYear(); + + const dates = []; + const date = new Date(year, month, 1); + + while (date.getMonth() === month && date < new Date()) { + dates.push(renderDateFormat(new Date(date))); + date.setDate(date.getDate() + 1); } - from={activities?.length ? activities[0].created_date : new Date()} - to={activities?.length ? activities[activities.length - 1].created_date : new Date()} - height="200px" - margin={{ bottom: 0, left: 10, right: 10, top: 0 }} - tooltip={(datum) => ( -
- {renderShortDateWithYearFormat(datum.day)}:{" "} - {datum.value} + + return dates; + }; + + const recentDates = [ + ...getDatesOfMonth(recentMonths[0]), + ...getDatesOfMonth(recentMonths[1]), + ...getDatesOfMonth(recentMonths[2]), + ...getDatesOfMonth(recentMonths[3]), + ...getDatesOfMonth(recentMonths[4]), + ...getDatesOfMonth(recentMonths[5]), + ]; + + const activitiesIntensity = (activityCount: number) => { + if (activityCount <= 3) return "opacity-20"; + else if (activityCount > 3 && activityCount <= 6) return "opacity-40"; + else if (activityCount > 6 && activityCount <= 9) return "opacity-80"; + else return ""; + }; + + const addPaddingTiles = () => { + const firstDateDay = new Date(recentDates[0]).getDay(); + + for (let i = 0; i < firstDateDay; i++) recentDates.unshift(""); + }; + addPaddingTiles(); + + useEffect(() => { + if (!ref.current) return; + + setWidth(ref.current.offsetWidth); + }, [ref]); + + return ( +
+
+
+ {DAYS.map((day, index) => ( +
+ {index % 2 === 0 && day.substring(0, 3)} +
+ ))} +
+
+
+ {recentMonths.map((month, index) => ( +
+ {MONTHS[month.getMonth()].substring(0, 3)} +
+ ))} +
+
+ {recentDates.map((date, index) => { + const isActive = activities?.find((a) => a.created_date === date); + + return ( + +
+ + ); + })} +
+
+ Less + + + + + + More +
+
- )} - theme={{ - background: "rgb(var(--color-bg-base))", - }} - /> -); +
+ ); +}; diff --git a/apps/app/components/workspace/issues-stats.tsx b/apps/app/components/workspace/issues-stats.tsx index bc7f0364f..8e108a676 100644 --- a/apps/app/components/workspace/issues-stats.tsx +++ b/apps/app/components/workspace/issues-stats.tsx @@ -1,7 +1,9 @@ // components import { ActivityGraph } from "components/workspace"; // ui -import { Loader } from "components/ui"; +import { Loader, Tooltip } from "components/ui"; +// icons +import { InformationCircleIcon } from "@heroicons/react/24/outline"; // types import { IUserWorkspaceDashboard } from "types"; @@ -66,7 +68,15 @@ export const IssuesStats: React.FC = ({ data }) => (
-

Activity Graph

+

+ Activity Graph + + + +