From ee4d935622edd98c2b12e05e20a453473561b0cd Mon Sep 17 00:00:00 2001 From: "Felix T.J. Dietrich" Date: Wed, 18 Sep 2024 14:32:10 +0200 Subject: [PATCH] fix leaderboard story --- .../home/leaderboard/leaderboard.component.ts | 5 --- .../home/leaderboard/leaderboard.stories.ts | 37 +++++++++++++------ 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/webapp/src/app/home/leaderboard/leaderboard.component.ts b/webapp/src/app/home/leaderboard/leaderboard.component.ts index dd01ba24..3feb3dc8 100644 --- a/webapp/src/app/home/leaderboard/leaderboard.component.ts +++ b/webapp/src/app/home/leaderboard/leaderboard.component.ts @@ -39,9 +39,4 @@ export class LeaderboardComponent { protected octComment = octComment; leaderboard = input(); - - // run on leaderboard changes - ngOnChanges() { - console.log('Leaderboard changes: ', this.leaderboard()); - } } diff --git a/webapp/src/app/home/leaderboard/leaderboard.stories.ts b/webapp/src/app/home/leaderboard/leaderboard.stories.ts index c3047a25..9432bb67 100644 --- a/webapp/src/app/home/leaderboard/leaderboard.stories.ts +++ b/webapp/src/app/home/leaderboard/leaderboard.stories.ts @@ -1,6 +1,19 @@ import { argsToTemplate, type Meta, type StoryObj } from '@storybook/angular'; import { LeaderboardComponent } from './leaderboard.component'; import { LeaderboardEntry } from 'app/core/modules/openapi/model/leaderboard-entry'; +import { PullRequestReviewDTO } from 'app/core/modules/openapi/model/pull-request-review-dto'; + +let reviewIdCounter = 1; + +const generateReviews = (count: number, state: PullRequestReviewDTO.StateEnum): PullRequestReviewDTO[] => { + return Array.from({ length: count }, () => ({ + id: reviewIdCounter++, + createdAt: new Date().toISOString(), + updatedAt: new Date().toISOString(), + submittedAt: new Date().toISOString(), + state + })); +}; const leaderboardEntries: LeaderboardEntry[] = [ { @@ -9,9 +22,9 @@ const leaderboardEntries: LeaderboardEntry[] = [ type: LeaderboardEntry.TypeEnum.User, name: 'Armin Stanitzok', score: 100, - changesRequested: 3, - approvals: 5, - comments: 1, + changesRequested: generateReviews(3, PullRequestReviewDTO.StateEnum.ChangesRequested), + approvals: generateReviews(5, PullRequestReviewDTO.StateEnum.Approved), + comments: generateReviews(1, PullRequestReviewDTO.StateEnum.Commented), rank: 1 }, { @@ -20,9 +33,9 @@ const leaderboardEntries: LeaderboardEntry[] = [ type: LeaderboardEntry.TypeEnum.User, name: 'Felix T.J. Dietrich', score: 90, - changesRequested: 1, - approvals: 1, - comments: 14, + changesRequested: generateReviews(1, PullRequestReviewDTO.StateEnum.ChangesRequested), + approvals: generateReviews(1, PullRequestReviewDTO.StateEnum.Approved), + comments: generateReviews(14, PullRequestReviewDTO.StateEnum.Commented), rank: 2 }, { @@ -31,9 +44,9 @@ const leaderboardEntries: LeaderboardEntry[] = [ type: LeaderboardEntry.TypeEnum.User, name: 'Stephan Krusche', score: 50, - changesRequested: 0, - approvals: 3, - comments: 1, + changesRequested: [], + approvals: generateReviews(3, PullRequestReviewDTO.StateEnum.Approved), + comments: generateReviews(1, PullRequestReviewDTO.StateEnum.Commented), rank: 3 }, { @@ -42,9 +55,9 @@ const leaderboardEntries: LeaderboardEntry[] = [ type: LeaderboardEntry.TypeEnum.User, name: 'shadcn', score: 20, - changesRequested: 0, - approvals: 0, - comments: 1, + changesRequested: [], + approvals: [], + comments: generateReviews(1, PullRequestReviewDTO.StateEnum.Commented), rank: 4 } ];