Skip to content

Commit

Permalink
feat: community report data filter (#232)
Browse files Browse the repository at this point in the history
Signed-off-by: laixingyou <[email protected]>
  • Loading branch information
coder-sett authored Sep 13, 2023
1 parent 9328dcd commit 91efe56
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
27 changes: 22 additions & 5 deletions apps/web/src/modules/analyze/context/ChartsDataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, {
useRef,
createContext,
} from 'react';
import { proxy } from 'valtio';
import { proxy, useSnapshot } from 'valtio';
import useQueryDateRange from '@modules/analyze/hooks/useQueryDateRange';
import useCompareItems from '@modules/analyze/hooks/useCompareItems';
import usePageLoadHashScroll from '@common/hooks/usePageLoadHashScroll';
Expand All @@ -17,7 +17,7 @@ import {
} from '@oss-compass/graphql';
import client from '@common/gqlClient';
import { Level } from '@modules/analyze/constant';

import { chartUserSettingState } from '@modules/analyze/store';
interface Store {
loading: boolean;
items: {
Expand All @@ -41,14 +41,21 @@ export const ChartsDataContext = createContext<typeof dataState>(dataState);

const ChartsDataProvider: React.FC<PropsWithChildren> = ({ children }) => {
const proxyState = useRef(dataState).current;

const snap = useSnapshot(chartUserSettingState);
const repoType = snap.repoType;
const queryClient = useQueryClient();
const { timeStart, timeEnd } = useQueryDateRange();
const { compareItems } = useCompareItems();

useQueries({
queries: compareItems.map(({ label, level }) => {
const variables = { label, level, start: timeStart, end: timeEnd };
const variables = {
label,
level,
start: timeStart,
end: timeEnd,
repoType: repoType,
};
return {
queryKey: useMetricQuery.getKey(variables),
queryFn: useMetricQuery.fetcher(client, variables),
Expand All @@ -68,7 +75,13 @@ const ChartsDataProvider: React.FC<PropsWithChildren> = ({ children }) => {

const items = compareItems
.map(({ label, level }) => {
const variables = { label, level, start: timeStart, end: timeEnd };
const variables = {
label,
level,
start: timeStart,
end: timeEnd,
repoType: repoType,
};
const key = useMetricQuery.getKey(variables);
return {
label,
Expand All @@ -91,6 +104,10 @@ const ChartsDataProvider: React.FC<PropsWithChildren> = ({ children }) => {
}
}, [isLoading, items, proxyState]);

// useEffect(() => {
// rType = ;
// }, [snap.repoType]);

return (
<ChartsDataContext.Provider value={proxyState}>
{children}
Expand Down
25 changes: 22 additions & 3 deletions packages/graphql/src/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1408,27 +1408,31 @@ export type QueryMetricActivityArgs = {
endDate?: InputMaybe<Scalars['ISO8601DateTime']>;
label: Scalars['String'];
level?: InputMaybe<Scalars['String']>;
repoType?: InputMaybe<Scalars['String']>;
};

export type QueryMetricCodequalityArgs = {
beginDate?: InputMaybe<Scalars['ISO8601DateTime']>;
endDate?: InputMaybe<Scalars['ISO8601DateTime']>;
label: Scalars['String'];
level?: InputMaybe<Scalars['String']>;
repoType?: InputMaybe<Scalars['String']>;
};

export type QueryMetricCommunityArgs = {
beginDate?: InputMaybe<Scalars['ISO8601DateTime']>;
endDate?: InputMaybe<Scalars['ISO8601DateTime']>;
label: Scalars['String'];
level?: InputMaybe<Scalars['String']>;
repoType?: InputMaybe<Scalars['String']>;
};

export type QueryMetricGroupActivityArgs = {
beginDate?: InputMaybe<Scalars['ISO8601DateTime']>;
endDate?: InputMaybe<Scalars['ISO8601DateTime']>;
label: Scalars['String'];
level?: InputMaybe<Scalars['String']>;
repoType?: InputMaybe<Scalars['String']>;
};

export type QueryMetricStarterProjectHealthArgs = {
Expand Down Expand Up @@ -3421,6 +3425,7 @@ export type MetricQueryVariables = Exact<{
level?: InputMaybe<Scalars['String']>;
start?: InputMaybe<Scalars['ISO8601DateTime']>;
end?: InputMaybe<Scalars['ISO8601DateTime']>;
repoType?: InputMaybe<Scalars['String']>;
}>;

export type MetricQuery = {
Expand Down Expand Up @@ -6448,12 +6453,13 @@ useCommunityReposQuery.fetcher = (
headers
);
export const MetricDocument = /*#__PURE__*/ `
query metric($label: String!, $level: String = "repo", $start: ISO8601DateTime, $end: ISO8601DateTime) {
query metric($label: String!, $level: String = "repo", $start: ISO8601DateTime, $end: ISO8601DateTime, $repoType: String) {
metricCodequality(
label: $label
level: $level
beginDate: $start
endDate: $end
repoType: $repoType
) {
activeC1PrCommentsContributorCount
activeC1PrCreateContributorCount
Expand Down Expand Up @@ -6482,7 +6488,13 @@ export const MetricDocument = /*#__PURE__*/ `
prIssueLinkedCount
prIssueLinkedRatio
}
metricCommunity(label: $label, level: $level, beginDate: $start, endDate: $end) {
metricCommunity(
label: $label
level: $level
beginDate: $start
endDate: $end
repoType: $repoType
) {
bugIssueOpenTimeAvg
bugIssueOpenTimeMid
closedPrsCount
Expand All @@ -6502,7 +6514,13 @@ export const MetricDocument = /*#__PURE__*/ `
prOpenTimeMid
updatedIssuesCount
}
metricActivity(label: $label, level: $level, beginDate: $start, endDate: $end) {
metricActivity(
label: $label
level: $level
beginDate: $start
endDate: $end
repoType: $repoType
) {
activeC1IssueCommentsContributorCount
activeC1IssueCreateContributorCount
activeC1PrCommentsContributorCount
Expand All @@ -6529,6 +6547,7 @@ export const MetricDocument = /*#__PURE__*/ `
level: $level
beginDate: $start
endDate: $end
repoType: $repoType
) {
commitFrequency
contributionLast
Expand Down
5 changes: 5 additions & 0 deletions packages/graphql/src/gql/query.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,14 @@ query metric(
$level: String = "repo"
$start: ISO8601DateTime
$end: ISO8601DateTime
$repoType: String
) {
metricCodequality(
label: $label
level: $level
beginDate: $start
endDate: $end
repoType: $repoType
) {
activeC1PrCommentsContributorCount
activeC1PrCreateContributorCount
Expand Down Expand Up @@ -141,6 +143,7 @@ query metric(
level: $level
beginDate: $start
endDate: $end
repoType: $repoType
) {
bugIssueOpenTimeAvg
bugIssueOpenTimeMid
Expand All @@ -166,6 +169,7 @@ query metric(
level: $level
beginDate: $start
endDate: $end
repoType: $repoType
) {
activeC1IssueCommentsContributorCount
activeC1IssueCreateContributorCount
Expand Down Expand Up @@ -193,6 +197,7 @@ query metric(
level: $level
beginDate: $start
endDate: $end
repoType: $repoType
) {
commitFrequency
# commitFrequencyOrg
Expand Down

2 comments on commit 91efe56

@vercel
Copy link

@vercel vercel bot commented on 91efe56 Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 91efe56 Sep 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.