-
Notifications
You must be signed in to change notification settings - Fork 70
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
feat: init the insight page #731
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9f0456f
feat: add the insight page
xingwanying 122fe14
fix(assistant): fix the build
xingwanying c97fe4a
feat: init the insight pager
xingwanying 033eaab
feat: add the contributor
xingwanying bb298ee
style: twaak the style for the insight page
xingwanying 0b13b73
feat: add the overview insight
xingwanying 76dc8b6
chore: fix build
xingwanying File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { | ||
getIssueStatistics, | ||
getIssueResolutionDuration, | ||
getPrStatistics, | ||
getCodeFrequency, | ||
getActivityStatistics, | ||
getActivityDatesAndTimes, | ||
getContributorStatistics, | ||
} from '../services/InsightController'; | ||
|
||
export function useIssueStatistics(repoName: string) { | ||
return useQuery({ | ||
queryKey: [`insight.issue.statistics`, repoName], | ||
queryFn: async () => getIssueStatistics(repoName), | ||
enabled: repoName !== undefined, | ||
}); | ||
} | ||
|
||
export function useContributorStatistics(repoName: string) { | ||
return useQuery({ | ||
queryKey: [`insight.contributor.statistics`, repoName], | ||
queryFn: async () => getContributorStatistics(repoName), | ||
enabled: repoName !== undefined, | ||
}); | ||
} | ||
|
||
export function useIssueResolutionDuration(repoName: string) { | ||
return useQuery({ | ||
queryKey: [`insight.issue.resolution_duration`, repoName], | ||
queryFn: async () => getIssueResolutionDuration(repoName), | ||
enabled: repoName !== undefined, | ||
}); | ||
} | ||
|
||
export function usePrStatistics(repoName: string) { | ||
return useQuery({ | ||
queryKey: [`insight.pr.statistics`, repoName], | ||
queryFn: async () => getPrStatistics(repoName), | ||
enabled: repoName !== undefined, | ||
}); | ||
} | ||
|
||
export function useCodeFrequency(repoName: string) { | ||
return useQuery({ | ||
queryKey: [`insight.pr.code_frequency`, repoName], | ||
queryFn: async () => getCodeFrequency(repoName), | ||
enabled: repoName !== undefined, | ||
}); | ||
} | ||
|
||
export function useActivityStatistics(repoName: string) { | ||
return useQuery({ | ||
queryKey: [`insight.activity.statistics`, repoName], | ||
queryFn: async () => getActivityStatistics(repoName), | ||
enabled: repoName !== undefined, | ||
}); | ||
} | ||
|
||
export function useActivityDatesAndTimes(repoName: string) { | ||
return useQuery({ | ||
queryKey: [`insight.activity.dates_and_times`, repoName], | ||
queryFn: async () => getActivityDatesAndTimes(repoName), | ||
enabled: repoName !== undefined, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
'use client'; | ||
import React, { Suspense } from 'react'; | ||
import { Tables } from '@/types/database.types'; | ||
import HomeIcon from '@/public/icons/HomeIcon'; | ||
import { | ||
AreaChart, | ||
LineChart, | ||
Heatmap, | ||
BoxChart, | ||
RankChart, | ||
} from '@petercatai/assistant'; | ||
import { useSearchParams } from 'next/navigation'; | ||
import { Skeleton } from '@nextui-org/react'; | ||
import { | ||
useIssueStatistics, | ||
useIssueResolutionDuration, | ||
usePrStatistics, | ||
useCodeFrequency, | ||
useActivityStatistics, | ||
useActivityDatesAndTimes, | ||
useContributorStatistics, | ||
} from '../hooks/useInsight'; | ||
|
||
export default function Insight() { | ||
const searchParams = useSearchParams(); | ||
const repoName = searchParams.get('repo') || ''; | ||
const botName = searchParams.get('name') || ''; | ||
const { data: issueStatistic } = useIssueStatistics(repoName); | ||
const { data: issueResolutionDuration } = | ||
useIssueResolutionDuration(repoName); | ||
const { data: prStatistic } = usePrStatistics(repoName); | ||
const { data: codeFrequency } = useCodeFrequency(repoName); | ||
const { data: activityStatistics } = useActivityStatistics(repoName); | ||
const { data: activityDatesAndTimes } = useActivityDatesAndTimes(repoName); | ||
const { data: contributors } = useContributorStatistics(repoName); | ||
return ( | ||
<div className="flex w-full h-full flex-col bg-[#F3F4F6] min-h-screen"> | ||
<div className="relative flex h-[72px] w-full items-center justify-between gap-2 px-6 flex-shrink-0"> | ||
<div className="flex items-center gap-2"> | ||
<span | ||
className="flex items-center gap-2 cursor-pointer" | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
window.history.back(); | ||
}} | ||
> | ||
<HomeIcon /> | ||
<span className="text-gray-400">{botName}</span> | ||
</span> | ||
<span className="text-gray-400">/</span> | ||
<span>Insight</span> | ||
</div> | ||
<div className="flex items-center gap-2 text-gray-400 text-sm"> | ||
Powered by | ||
<a | ||
className="text-gray-500" | ||
href="https://open-digger.cn/docs/user_docs/intro" | ||
> | ||
HyperCRX | ||
</a> | ||
</div> | ||
</div> | ||
<div className="pb-[42px] px-[40px] overflow-y-auto"> | ||
<div className="grid grid-cols-2 gap-2"> | ||
<div className="bg-white rounded h-[607px] p-[24px]"> | ||
<Suspense fallback={<Skeleton className="rounded-lg" />}> | ||
{contributors && ( | ||
<AreaChart | ||
data={contributors} | ||
height={500} | ||
title="Contributors" | ||
/> | ||
)} | ||
</Suspense> | ||
</div> | ||
<div className="bg-white rounded h-[607px] p-[24px]"> | ||
<Suspense fallback={<Skeleton className="rounded-lg" />}> | ||
{codeFrequency && ( | ||
<AreaChart | ||
data={codeFrequency} | ||
height={500} | ||
title="Code Frequency" | ||
/> | ||
)} | ||
</Suspense> | ||
</div> | ||
<div className="bg-white rounded h-[579px] p-[24px]"> | ||
<Suspense fallback={<Skeleton className="rounded-lg" />}> | ||
{prStatistic && ( | ||
<LineChart data={prStatistic} height={450} title="PR History" /> | ||
)} | ||
</Suspense> | ||
</div> | ||
<div className="bg-white rounded h-[579px] p-[24px]"> | ||
<Suspense fallback={<Skeleton className="rounded-lg" />}> | ||
{issueStatistic && ( | ||
<LineChart | ||
data={issueStatistic} | ||
height={450} | ||
title="Issue History" | ||
/> | ||
)} | ||
</Suspense> | ||
</div> | ||
<div className="bg-white rounded h-[400px] p-[24px]"> | ||
<Suspense fallback={<Skeleton className="rounded-lg" />}> | ||
{issueResolutionDuration && ( | ||
<BoxChart | ||
data={issueResolutionDuration} | ||
height={300} | ||
title="Average Time To Issue Close" | ||
/> | ||
)} | ||
</Suspense> | ||
</div> | ||
<div className="bg-white rounded h-[400px] p-[24px]"> | ||
<Suspense fallback={<Skeleton className="rounded-lg" />}> | ||
{activityDatesAndTimes && ( | ||
<Heatmap | ||
data={activityDatesAndTimes} | ||
height={300} | ||
title="Repository Activity" | ||
/> | ||
)} | ||
</Suspense> | ||
</div> | ||
|
||
<div className="bg-white rounded h-[500px] col-span-2 p-[24px]"> | ||
<Suspense fallback={<Skeleton className="rounded-lg" />}> | ||
{activityStatistics && ( | ||
<RankChart | ||
data={activityStatistics} | ||
height={408} | ||
title="Contributor Rankings Top 10" | ||
/> | ||
)} | ||
</Suspense> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import axios from 'axios'; | ||
|
||
const apiDomain = process.env.NEXT_PUBLIC_API_DOMAIN; | ||
axios.defaults.withCredentials = true; | ||
|
||
export async function getIssueStatistics(repoName: string) { | ||
const response = await axios.get( | ||
`${apiDomain}/api/insight/issue/statistics?repo_name=${repoName}`, | ||
); | ||
return response.data.data; | ||
} | ||
|
||
export async function getIssueResolutionDuration(repoName: string) { | ||
const response = await axios.get( | ||
`${apiDomain}/api/insight/issue/resolution_duration?repo_name=${repoName}`, | ||
); | ||
return response.data.data; | ||
} | ||
|
||
export async function getContributorStatistics(repoName: string) { | ||
const response = await axios.get( | ||
`${apiDomain}/api/insight/contributor/statistics?repo_name=${repoName}`, | ||
); | ||
return response.data.data; | ||
} | ||
|
||
export async function getPrStatistics(repoName: string) { | ||
const response = await axios.get( | ||
`${apiDomain}/api/insight/pr/statistics?repo_name=${repoName}`, | ||
); | ||
return response.data.data; | ||
} | ||
|
||
export async function getCodeFrequency(repoName: string) { | ||
const response = await axios.get( | ||
`${apiDomain}/api/insight/pr/code_frequency?repo_name=${repoName}`, | ||
); | ||
return response.data.data; | ||
} | ||
|
||
export async function getActivityStatistics(repoName: string) { | ||
const response = await axios.get( | ||
`${apiDomain}/api/insight/activity/statistics?repo_name=${repoName}`, | ||
); | ||
return response.data.data; | ||
} | ||
|
||
export async function getActivityDatesAndTimes(repoName: string) { | ||
const response = await axios.get( | ||
`${apiDomain}/api/insight/activity/dates_and_times?repo_name=${repoName}`, | ||
); | ||
return response.data.data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that
NEXT_PUBLIC_API_DOMAIN
is defined in the environment variables to avoid runtime errors when making API requests.