Skip to content

Commit

Permalink
fix: duplicate numbers on repo-activity-racing-bar (#751)
Browse files Browse the repository at this point in the history
  • Loading branch information
wxharry authored Oct 16, 2023
1 parent 578ada3 commit 6cd8f0a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/pages/ContentScripts/features/repo-activity-racing-bar/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,25 @@ export interface RepoActivityDetails {
[key: string]: [string, number][];
}

/**
* Filter and extract monthly data from the given data structure, which includes various date formats such as "yyyy", "yyyy-Qq", and "yyyy-mm".
* This function extracts and returns only the monthly data in the "yyyy-mm" format.
*
* @param data: RepoActivityDetails
* @returns RepoActivityDetails
*/
export function getMonthlyData(data: RepoActivityDetails) {
const monthlyData: RepoActivityDetails = {};

for (const key in data) {
// Check if the key matches the yyyy-mm format (e.g., "2020-05")
if (/^\d{4}-\d{2}$/.test(key)) {
monthlyData[key] = data[key];
}
}
return monthlyData;
}

/**
* Count the number of unique contributors in the data
* @returns [number of long term contributors, contributors' names]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import optionsStorage, {
defaults,
} from '../../../../options-storage';
import RacingBar, { MediaControlers } from './RacingBar';
import { RepoActivityDetails } from './data';
import { RepoActivityDetails, getMonthlyData } from './data';
import { PlayerButton } from './PlayerButton';
import { SpeedController } from './SpeedController';

Expand Down Expand Up @@ -91,7 +91,7 @@ const View = ({ currentRepo, repoActivityDetails }: Props): JSX.Element => {
<RacingBar
ref={mediaControlersRef}
speed={speed}
data={repoActivityDetails}
data={getMonthlyData(repoActivityDetails)}
setPlaying={setPlaying}
/>
</div>
Expand Down

0 comments on commit 6cd8f0a

Please sign in to comment.