Skip to content

Commit

Permalink
feat: calculation of completion_rate on client side (#307)
Browse files Browse the repository at this point in the history
* feat: move completion_rate calculation to client side

* chore: remove debugging code

* chore: move unit test

* chore: fix import paths for moved test

* Update lib/calculateCompletionRate.ts

Co-authored-by: Nishant Arora <[email protected]>

---------

Co-authored-by: Nishant Arora <[email protected]>
  • Loading branch information
SgtPooki and whizzzkid authored Feb 8, 2023
1 parent 6cd1639 commit 92086c8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
5 changes: 2 additions & 3 deletions lib/backend/addToChildren.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { getDueDate } from '../parser';
import { GithubIssueDataWithGroupAndChildren, IssueData } from '../types';
import { calculateCompletionRate } from './calculateCompletionRate';
import { ErrorManager } from './errorManager';

export function addToChildren(
Expand All @@ -22,12 +21,12 @@ export function addToChildren(
html_url: parent.html_url,
labels: parent.labels,
node_id: parent.node_id,
completion_rate: calculateCompletionRate(parent),
completion_rate: 0, // calculated on the client-side once all issues are loaded
due_date: parentDueDate,
};
return data.map((item: GithubIssueDataWithGroupAndChildren): IssueData => ({
labels: item.labels ?? [],
completion_rate: calculateCompletionRate(item),
completion_rate: 0, // calculated on the client-side once all issues are loaded
due_date: getDueDate(item, errorManager).eta,
html_url: item.html_url,
group: item.group,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IssueStates } from '../enums';
import { IssueData } from '../types';
import { State } from '@hookstate/core';
import { IssueStates } from './enums';
import { IssueData } from './types';

export type CalculateCompletionRateOptions = Pick<IssueData, 'html_url' | 'state'> & { children: CalculateCompletionRateOptions[] };

Expand Down Expand Up @@ -48,3 +49,16 @@ export function calculateCompletionRate (issue: CalculateCompletionRateOptions):
const { percentClosed } = getIssueCounts(issueStatesMap);
return percentClosed;
};

export function assignCompletionRateToIssues (issue: State<IssueData> | State<IssueData | null>): void {
if (issue.ornull === null) {
return
}
const completion_rate = calculateCompletionRate({
html_url: issue.ornull.html_url.value,
state: issue.ornull.state.value,
children: issue.ornull.children.value
});
issue.merge((issue) => ({ ...issue, completion_rate })) // = completionRate
issue.ornull.children.forEach(assignCompletionRateToIssues)
}
2 changes: 2 additions & 0 deletions pages/roadmap/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { BASE_PROTOCOL } from '../../config/constants';
import { setDateGranularity } from '../../hooks/useDateGranularity';
import { useGlobalLoadingState } from '../../hooks/useGlobalLoadingState';
import { setViewMode } from '../../hooks/useViewMode';
import { assignCompletionRateToIssues } from '../../lib/calculateCompletionRate';
import { DateGranularityState, RoadmapMode, ViewMode } from '../../lib/enums';
import { findIssueDataByUrl } from '../../lib/findIssueDataByUrl';
import { mergeStarMapsErrorGroups } from '../../lib/mergeStarMapsErrorGroups';
Expand Down Expand Up @@ -201,6 +202,7 @@ export default function RoadmapPage(props: InferGetServerSidePropsType<typeof ge
*/
useEffect(() => {
if (!isRootIssueLoading && pendingChildrenState.length === 0 && asyncIssueDataState.length === 0) {
assignCompletionRateToIssues(issueDataState)
globalLoadingState.stop();
} else {
globalLoadingState.start();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { calculateCompletionRate, CalculateCompletionRateOptions } from '../../../lib/backend/calculateCompletionRate'
import { IssueStates } from '../../../lib/enums';
import { IssueData } from '../../../lib/types';
import { calculateCompletionRate, CalculateCompletionRateOptions } from '../../lib/calculateCompletionRate'
import { IssueStates } from '../../lib/enums';
import { IssueData } from '../../lib/types';

const closed = IssueStates.CLOSED;
const open = IssueStates.OPEN;
Expand Down

1 comment on commit 92086c8

@vercel
Copy link

@vercel vercel bot commented on 92086c8 Feb 8, 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.