Skip to content

Commit

Permalink
Merge pull request #1252 from open-sauced/beta
Browse files Browse the repository at this point in the history
v1.51.0-beta.2 -> production
  • Loading branch information
brandonroberts committed Jun 6, 2023
2 parents fbd85f1 + ee8521e commit 3edec79
Show file tree
Hide file tree
Showing 17 changed files with 131 additions and 62 deletions.
41 changes: 41 additions & 0 deletions CHANGELOG.md
Expand Up @@ -5,6 +5,47 @@

> All notable changes to this project will be documented in this file
## [1.51.0-beta.2](https://github.com/open-sauced/insights/compare/v1.51.0-beta.1...v1.51.0-beta.2) (2023-06-06)


### 🍕 Features

* add share tracking ([#1250](https://github.com/open-sauced/insights/issues/1250)) ([5b7d331](https://github.com/open-sauced/insights/commit/5b7d3317d4670d46611ed6bb1439e24974f7ddc4))


### 🐛 Bug Fixes

* update hook for Posthog ([cd4f32c](https://github.com/open-sauced/insights/commit/cd4f32c506dc370a88fa2fa451995704f4818994))
* update medium activity threshold for repositories ([#1251](https://github.com/open-sauced/insights/issues/1251)) ([4730533](https://github.com/open-sauced/insights/commit/4730533c2426a58f39bbc4d6b06cd7291d96652f)), closes [#1224](https://github.com/open-sauced/insights/issues/1224)

## [1.51.0-beta.1](https://github.com/open-sauced/insights/compare/v1.50.1-beta.3...v1.51.0-beta.1) (2023-06-06)


### 🍕 Features

* implement dynamic redirect on auth ([#1240](https://github.com/open-sauced/insights/issues/1240)) ([548cc4d](https://github.com/open-sauced/insights/commit/548cc4df7c4758c9fbe45054ab4b889b7180f011))

### [1.50.1-beta.3](https://github.com/open-sauced/insights/compare/v1.50.1-beta.2...v1.50.1-beta.3) (2023-06-06)


### 🐛 Bug Fixes

* reports select issue ([#1239](https://github.com/open-sauced/insights/issues/1239)) ([a48bc87](https://github.com/open-sauced/insights/commit/a48bc879b23bf9bfe43164b4377a607741a58d2a))

### [1.50.1-beta.2](https://github.com/open-sauced/insights/compare/v1.50.1-beta.1...v1.50.1-beta.2) (2023-06-05)


### 🐛 Bug Fixes

* Footer Location on Smaller Screens ([#1242](https://github.com/open-sauced/insights/issues/1242)) ([8b2356a](https://github.com/open-sauced/insights/commit/8b2356ab0b28a3582c32a28985356110e405448e))

### [1.50.1-beta.1](https://github.com/open-sauced/insights/compare/v1.50.0...v1.50.1-beta.1) (2023-06-01)


### 🐛 Bug Fixes

* update contributors hook to use contributor API endpoint ([#1238](https://github.com/open-sauced/insights/issues/1238)) ([eff01c0](https://github.com/open-sauced/insights/commit/eff01c0f88c05f57925a0ec021e78676ba9d915f))

## [1.50.0](https://github.com/open-sauced/insights/compare/v1.49.0...v1.50.0) (2023-06-01)


Expand Down
17 changes: 16 additions & 1 deletion components/molecules/AuthSection/auth-section.tsx
@@ -1,5 +1,6 @@
import { useEffect, useState } from "react";
import Image from "next/image";
import { useRouter } from "next/router";
import Link from "next/link";

import { IoNotifications } from "react-icons/io5";
Expand All @@ -26,11 +27,20 @@ import { authSession } from "lib/hooks/authSession";
import { Spinner } from "components/atoms/SpinLoader/spin-loader";

const AuthSection: React.FC = ({}) => {
const router = useRouter();
const currentPath = router.asPath;

const { signIn, signOut, user, sessionToken } = useSupabaseAuth();
const { onboarded } = useSession();
const [notifications, setNotifications] = useState<DbUserNotification[]>([]);
const [loading, setLoading] = useState(false);
const [userInfo, setUserInfo] = useState<DbUser | undefined>(undefined);
const [host, setHost] = useState<string>("");
useEffect(() => {
if (typeof window !== "undefined") {
setHost(window.location.origin as string);
}
}, []);

// Fetch user notifications
const fetchNotifications = async () => {
Expand Down Expand Up @@ -158,7 +168,12 @@ const AuthSection: React.FC = ({}) => {
</DropdownList>
</>
) : (
<Button variant="primary" onClick={async () => await signIn({ provider: "github" })}>
<Button
variant="primary"
onClick={async () =>
await signIn({ provider: "github", options: { redirectTo: `${host}/${currentPath}` } })
}
>
Connect with GitHub <Icon IconImage={GitHubIcon} className="ml-2" />
</Button>
)}
Expand Down
Expand Up @@ -14,7 +14,7 @@ import useRepoList from "lib/hooks/useRepoList";
import { useFetchUser } from "lib/hooks/useFetchUser";

interface ContributorListTableRow {
contributor: DbRepoPR;
contributor: DbPRContributor;
topic: string;
}

Expand Down Expand Up @@ -50,7 +50,7 @@ const ContributorListTableRow = ({ contributor, topic }: ContributorListTableRow
const totalPrs = data.length;
const last30days = [
{
id: `last30-${contributor.repo_id}`,
id: `last30-${contributor.author_login}`,
color: "hsl(63, 70%, 50%)",
data: days,
},
Expand Down
Expand Up @@ -8,6 +8,7 @@ import { MarkGithubIcon } from "@primer/octicons-react";
import { User } from "@supabase/supabase-js";
import { FiCopy } from "react-icons/fi";
import { useToast } from "lib/hooks/useToast";
import { usePostHog } from "posthog-js/react";

interface ContributorProfileHeaderProps {
avatarUrl?: string;
Expand All @@ -31,8 +32,9 @@ const ContributorProfileHeader = ({
username,
user,
handleSignIn,
isOwner
isOwner,
}: ContributorProfileHeaderProps) => {
const posthog = usePostHog();
const { toast } = useToast();
const [host, setHost] = useState("");
const handleFollowClick = () => {
Expand All @@ -45,6 +47,10 @@ const ContributorProfileHeader = ({

const handleCopyToClipboard = async (content: string) => {
const url = new URL(content).toString();
posthog!.capture("clicked: profile copied", {
profile: user?.user_metadata.user_name,
});

try {
await navigator.clipboard.writeText(url);
toast({ description: "Copied to clipboard", variant: "success" });
Expand Down Expand Up @@ -92,7 +98,11 @@ const ContributorProfileHeader = ({
</div>
{isConnected && (
<div className="flex flex-col items-center gap-3 md:translate-y-0 translate-y-28 md:flex-row">
<Button onClick={() => handleCopyToClipboard(`${host}/user/${user?.user_metadata.user_name}`)} className="px-10 py-2 mb-10 bg-white md:mb-6 " variant="text">
<Button
onClick={() => handleCopyToClipboard(`${host}/user/${user?.user_metadata.user_name}`)}
className="px-10 py-2 mb-10 bg-white md:mb-6 "
variant="text"
>
<FiCopy className="mr-1 mt-1" /> Share
</Button>
{user ? (
Expand Down
2 changes: 1 addition & 1 deletion components/molecules/RepoRow/repo-row.tsx
Expand Up @@ -43,7 +43,7 @@ export const getActivity = (total?: number, loading?: boolean) => {
return <Pill icon={<ArrowTrendingUpIcon color="green" className="w-4 h-4" />} text="High" color="green" />;
}

if (total >= 20 && total <= 80) {
if (total >= 5 && total <= 80) {
return <Pill icon={<MinusSmallIcon color="black" className="w-4 h-4" />} text="Medium" color="yellow" />;
}

Expand Down
Expand Up @@ -6,7 +6,7 @@ import { FilterOptions } from "interfaces/filter-object-types";
import { useState } from "react";

interface SelectReportsFilterProps {
filterList?: FilterOptions[];
filterList: FilterOptions[];
callback: (selectedValue: string) => any;
}

Expand All @@ -23,13 +23,15 @@ const SelectReportsFilter = ({ filterList, callback }: SelectReportsFilterProps)
return (
<div className="flex flex-col gap-2 min-h-20">
<Title level={4}>Select a Filter</Title>
<Text>
Download the filtered pull requests from the filtered repositories for the last 30 days as a CSV.
</Text>
<Text>Download the filtered pull requests from the filtered repositories for the last 30 days as a CSV.</Text>
<div className="flex flex-col gap-2 md:flex-row">
<Select>
<Select onValueChange={(value) => setSelectedValue(value)}>
<SelectTrigger>
<SelectValue>{selectedValue ? selectedValue : "Select a Filter"}</SelectValue>
<SelectValue className="!capitalize">
{selectedValue
? filterList.find((filter) => filter.filterValue === selectedValue)?.filterName
: "Select a Filter"}
</SelectValue>
</SelectTrigger>
<SelectContent>
{filterList?.map(({ filterName, filterValue }, index) => (
Expand Down
4 changes: 1 addition & 3 deletions components/organisms/Contributors/contributors.tsx
Expand Up @@ -34,7 +34,7 @@ const Contributors = ({ repositories }: ContributorProps): JSX.Element => {
const contributors = data.map((pr) => {
return {
host_login: pr.author_login,
first_commit_time: pr.created_at,
first_commit_time: pr.updated_at,
};
});

Expand All @@ -52,8 +52,6 @@ const Contributors = ({ repositories }: ContributorProps): JSX.Element => {
};
});

// console.log(data);

return (
<>
{/* Table section */}
Expand Down
Expand Up @@ -3,7 +3,7 @@ import ContributorListTableRow from "components/molecules/ContributorListTableRo
import React from "react";

export interface ContributorTableProps {
contributors: DbRepoPR[];
contributors: DbPRContributor[];
topic: string;
loading?: boolean;
}
Expand Down
14 changes: 7 additions & 7 deletions components/organisms/Dashboard/dashboard.tsx
Expand Up @@ -12,7 +12,7 @@ import { getInsights, useInsights } from "lib/hooks/api/useInsights";
import { calcDaysFromToday } from "lib/utils/date-utils";
import roundedImage from "lib/utils/roundedImages";
import usePullRequests from "lib/hooks/api/usePullRequests";
import getPullRequestsContributors from "lib/utils/get-pr-contributors";
import useContributors from "lib/hooks/api/useContributors";

type ContributorPrMap = { [contributor: string]: DbRepoPR };
export type PrStatusFilter = "open" | "closed" | "all";
Expand All @@ -23,11 +23,11 @@ interface DashboardProps {

const Dashboard = ({ repositories }: DashboardProps): JSX.Element => {
const { data: insightsData, isLoading } = useInsights(repositories);
const { data: prData, meta: prMeta, isError: prError } = usePullRequests(undefined, repositories);
const { data: prData, isError: prError } = usePullRequests(undefined, repositories);
const { data: contributorData, meta: contributorMeta } = useContributors(undefined, repositories);
const [showBots, setShowBots] = useState(false);
const isMobile = useMediaQuery("(max-width:720px)");
const [prStateFilter, setPrStateFilter] = useState<PrStatusFilter>("all");
const contributorData = getPullRequestsContributors(prData);

const handleSetPrFilter = (state: PrStatusFilter) => {
setPrStateFilter(state);
Expand All @@ -37,7 +37,7 @@ const Dashboard = ({ repositories }: DashboardProps): JSX.Element => {
let metadata: ScatterChartMetadata = {
allPrs: prData.length,
openPrs: prData.filter((pr) => pr.state.toLowerCase() === "open").length,
closedPrs: prData.filter((pr) => pr.state.toLowerCase() === "closed" || pr.state.toLowerCase() === "merged").length
closedPrs: prData.filter((pr) => pr.state.toLowerCase() === "closed" || pr.state.toLowerCase() === "merged").length,
};

const uniqueContributors: ContributorPrMap = prData.reduce((prs, curr) => {
Expand Down Expand Up @@ -73,7 +73,7 @@ const Dashboard = ({ repositories }: DashboardProps): JSX.Element => {
x: calcDaysFromToday(new Date(updated_at)),
y: linesCount,
contributor: author_login,
image: roundedImage(`https://www.github.com/${author_image}.png?size=60`, process.env.NEXT_PUBLIC_CLOUD_NAME)
image: roundedImage(`https://www.github.com/${author_image}.png?size=60`, process.env.NEXT_PUBLIC_CLOUD_NAME),
};
return data;
});
Expand All @@ -99,8 +99,8 @@ const Dashboard = ({ repositories }: DashboardProps): JSX.Element => {
metricIncreases={compare1.allPrsTotal - compare2.allPrsTotal >= 0}
increased={compare1.allPrsTotal - compare2.allPrsTotal >= 0}
numChanged={humanizeNumber(Math.abs(compare1.allPrsTotal - compare2.allPrsTotal), "abbreviation")}
value={humanizeNumber(prMeta.itemCount, "comma")}
contributors={contributorData}
value={humanizeNumber(contributorMeta.itemCount, "comma")}
contributors={contributorData.map((contributor) => ({ host_login: contributor.author_login }))}
isLoading={isLoading}
/>
<HighlightCard
Expand Down
2 changes: 1 addition & 1 deletion components/organisms/Footer/footer.tsx
Expand Up @@ -59,7 +59,7 @@ const footerContext = [

const Footer = (): JSX.Element => {
return (
<footer className=" h-24 w-full bg-light-slate-2 transition">
<footer className="h-24 w-full transition">
<div className=" container mx-auto px-2 md:px-16 lg:border-t lg:py-8 lg:items-center lg:justify-between lg:gap-x-4 flex flex-col gap-y-4 lg:flex-row py-2 w-full">
<div className="text-center lg:text-left justify-center gap-1 flex items-center">
<div className="w-6 h-6 relative !min-w-[24px] min-h-[24px]">
Expand Down
17 changes: 8 additions & 9 deletions lib/hooks/api/useContributors.ts
Expand Up @@ -6,18 +6,17 @@ import publicApiFetcher from "lib/utils/public-api-fetcher";
import getFilterQuery from "lib/utils/get-filter-query";

interface PaginatedResponse {
readonly data: DbRepoPR[];
readonly data: DbPRContributor[];
readonly meta: Meta;
}

/**
* Fetch contributors based on pull requests.
* Replace with contributors API endpoint when available.
*
* @param intialLimit
* @param repoIds
* @param range
* @returns
*
* @param intialLimit
* @param repoIds
* @param range
* @returns
*/
const useContributors = (intialLimit = 10, repoIds: number[] = [], range = 30) => {
const router = useRouter();
Expand Down Expand Up @@ -51,7 +50,7 @@ const useContributors = (intialLimit = 10, repoIds: number[] = [], range = 30) =

query.set("range", `${range}`);

const baseEndpoint = "prs/search";
const baseEndpoint = "contributors/search";
const endpointString = `${baseEndpoint}?${query.toString()}`;

const { data, error, mutate } = useSWR<PaginatedResponse, Error>(
Expand All @@ -67,7 +66,7 @@ const useContributors = (intialLimit = 10, repoIds: number[] = [], range = 30) =
mutate,
page,
setPage,
setLimit
setLimit,
};
};

Expand Down
27 changes: 15 additions & 12 deletions lib/hooks/useSupabaseAuth.ts
Expand Up @@ -6,10 +6,10 @@ import { supabase } from "../utils/supabase";

const useSupabaseAuth = (loadSession = false) => {
const store = useStore();
const user = useStore(state => state.user);
const sessionToken = useStore(state => state.sessionToken);
const providerToken = useStore(state => state.providerToken);
const userId = useStore(state => state.userId);
const user = useStore((state) => state.user);
const sessionToken = useStore((state) => state.sessionToken);
const providerToken = useStore((state) => state.providerToken);
const userId = useStore((state) => state.userId);

useEffect(() => {
async function getUserSession() {
Expand All @@ -24,7 +24,9 @@ const useSupabaseAuth = (loadSession = false) => {
getUserSession();
}

const { data: { subscription: listener } } = supabase.auth.onAuthStateChange((_, session) => {
const {
data: { subscription: listener },
} = supabase.auth.onAuthStateChange((_, session) => {
store.setUser(session?.user ?? null);
store.setSessionToken(session?.access_token);
store.setProviderToken(session?.provider_token);
Expand All @@ -37,17 +39,18 @@ const useSupabaseAuth = (loadSession = false) => {
}, []);

return {
signIn: (data: SignInWithOAuthCredentials) => supabase.auth.signInWithOAuth({
...data,
options: {
redirectTo: process.env.NEXT_PUBLIC_BASE_URL ?? "/"
}
}),
signIn: (data: SignInWithOAuthCredentials) =>
supabase.auth.signInWithOAuth({
...data,
options: data.options ?? {
redirectTo: process.env.NEXT_PUBLIC_BASE_URL ?? "/",
},
}),
signOut: () => supabase.auth.signOut(),
user,
sessionToken,
providerToken,
userId
userId,
};
};

Expand Down
5 changes: 5 additions & 0 deletions next-types.d.ts
Expand Up @@ -41,6 +41,11 @@ interface DbRepoPR {
readonly last_updated_at: string;
}

interface DbPRContributor {
readonly author_login: string;
readonly updated_at: string;
}

interface DbFollowUser {
readonly id: number;
readonly user_id: number;
Expand Down
4 changes: 2 additions & 2 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3edec79

Please sign in to comment.