From 2cf1acebf679cd3def55a5a184441b1ccf94db11 Mon Sep 17 00:00:00 2001 From: Hayden Cleary <5160414+haydencleary@users.noreply.github.com> Date: Thu, 14 Nov 2024 08:40:08 +0100 Subject: [PATCH] Jfeat: github comment block (#636) --- .../models/contribution-activity-model.ts | 8 +++---- core/domain/user/models/applicant-model.ts | 17 ++++++++++++++ .../_features/description/description.tsx | 2 +- .../github-comment/github-comment.tsx | 22 +++++++++++++++++++ .../github-comment/github-comment.types.ts | 3 +++ .../contributions-sidepanel.en.json | 6 +++-- .../contributions-sidepanel.hooks.tsx | 14 +++++++++++- .../project-description.tsx | 2 +- .../project-sidepanel.en.json | 3 --- .../translations/common/common.en.json | 3 ++- 10 files changed, 67 insertions(+), 13 deletions(-) create mode 100644 core/domain/user/models/applicant-model.ts create mode 100644 shared/panels/contribution-sidepanel/_features/github-comment/github-comment.tsx create mode 100644 shared/panels/contribution-sidepanel/_features/github-comment/github-comment.types.ts diff --git a/core/domain/contribution/models/contribution-activity-model.ts b/core/domain/contribution/models/contribution-activity-model.ts index 5d7520b10..fbda29fb2 100644 --- a/core/domain/contribution/models/contribution-activity-model.ts +++ b/core/domain/contribution/models/contribution-activity-model.ts @@ -1,12 +1,12 @@ import { ContributionItemDto } from "@/core/domain/contribution/dto/contribution-item-dto"; -import { GithubUser, GithubUserInterface } from "@/core/domain/github/models/github-user-model"; +import { Applicant, ApplicantInterface } from "@/core/domain/user/models/applicant-model"; import { components } from "@/core/infrastructure/marketplace-api-client-adapter/__generated/api"; export type ContributionActivityResponse = components["schemas"]["ContributionActivityPageItemResponse"]; export interface ContributionActivityInterface extends Omit { - applicants: GithubUserInterface[]; + applicants: ApplicantInterface[]; contributors: NonNullable; isNotAssigned(): boolean; isInProgress(): boolean; @@ -23,7 +23,7 @@ export interface ContributionActivityInterface export class ContributionActivity implements ContributionActivityInterface { activityStatus!: ContributionActivityResponse["activityStatus"]; - applicants!: GithubUserInterface[]; + applicants!: ApplicantInterface[]; completedAt!: ContributionActivityResponse["completedAt"]; contributors!: NonNullable; createdAt!: ContributionActivityResponse["createdAt"]; @@ -46,7 +46,7 @@ export class ContributionActivity implements ContributionActivityInterface { constructor(props: ContributionActivityResponse) { Object.assign(this, props); - this.applicants = (props.applicants ?? []).map(applicant => new GithubUser(applicant)); + this.applicants = (props.applicants ?? []).map(applicant => new Applicant(applicant)); this.contributors = props.contributors ?? []; this.id = props.uuid; } diff --git a/core/domain/user/models/applicant-model.ts b/core/domain/user/models/applicant-model.ts new file mode 100644 index 000000000..3815cf927 --- /dev/null +++ b/core/domain/user/models/applicant-model.ts @@ -0,0 +1,17 @@ +import { components } from "@/core/infrastructure/marketplace-api-client-adapter/__generated/api"; + +export type ApplicantResponse = components["schemas"]["ApplicantResponse"]; + +export interface ApplicantInterface extends ApplicantResponse {} + +export class Applicant implements ApplicantInterface { + applicationId!: ApplicantResponse["applicationId"]; + avatarUrl!: ApplicantResponse["avatarUrl"]; + githubUserId!: ApplicantResponse["githubUserId"]; + login!: ApplicantResponse["login"]; + since!: ApplicantResponse["since"]; + + constructor(props: ApplicantResponse) { + Object.assign(this, props); + } +} diff --git a/shared/panels/contribution-sidepanel/_features/description/description.tsx b/shared/panels/contribution-sidepanel/_features/description/description.tsx index e96c6d947..2bed29d2a 100644 --- a/shared/panels/contribution-sidepanel/_features/description/description.tsx +++ b/shared/panels/contribution-sidepanel/_features/description/description.tsx @@ -12,7 +12,7 @@ export function Description({ description }: DescriptionProps) { return ( - + {description} diff --git a/shared/panels/contribution-sidepanel/_features/github-comment/github-comment.tsx b/shared/panels/contribution-sidepanel/_features/github-comment/github-comment.tsx new file mode 100644 index 000000000..ba5ec0250 --- /dev/null +++ b/shared/panels/contribution-sidepanel/_features/github-comment/github-comment.tsx @@ -0,0 +1,22 @@ +import dynamic from "next/dynamic"; + +import { Paper } from "@/design-system/atoms/paper"; +import { Typo } from "@/design-system/atoms/typo"; + +import { GithubCommentProps } from "@/shared/panels/contribution-sidepanel/_features/github-comment/github-comment.types"; + +const Emoji = dynamic(() => import("react-emoji-render")); + +export function GithubComment({ comment }: GithubCommentProps) { + if (!comment) return null; + + return ( + + + + + {comment} + + + ); +} diff --git a/shared/panels/contribution-sidepanel/_features/github-comment/github-comment.types.ts b/shared/panels/contribution-sidepanel/_features/github-comment/github-comment.types.ts new file mode 100644 index 000000000..8a392cf7a --- /dev/null +++ b/shared/panels/contribution-sidepanel/_features/github-comment/github-comment.types.ts @@ -0,0 +1,3 @@ +export interface GithubCommentProps { + comment?: string; +} diff --git a/shared/panels/contribution-sidepanel/contributions-sidepanel.en.json b/shared/panels/contribution-sidepanel/contributions-sidepanel.en.json index c5811a4ad..16bc30d0c 100644 --- a/shared/panels/contribution-sidepanel/contributions-sidepanel.en.json +++ b/shared/panels/contribution-sidepanel/contributions-sidepanel.en.json @@ -78,11 +78,13 @@ } }, "rewardedCard": { - "title": "Rewarded", - "status": "Rewarded" + "title": "Rewarded" }, "userCard": { "assignedBy": "Assigned by", "mergedBy": "Merged by" + }, + "githubComment": { + "title": "Github comment" } } diff --git a/shared/panels/contribution-sidepanel/contributions-sidepanel.hooks.tsx b/shared/panels/contribution-sidepanel/contributions-sidepanel.hooks.tsx index cb94b31d8..1e6fe14a9 100644 --- a/shared/panels/contribution-sidepanel/contributions-sidepanel.hooks.tsx +++ b/shared/panels/contribution-sidepanel/contributions-sidepanel.hooks.tsx @@ -1,3 +1,4 @@ +import { ApplicationReactQueryAdapter } from "@/core/application/react-query-adapter/application"; import { bootstrap } from "@/core/bootstrap"; import { ContributionActivityInterface } from "@/core/domain/contribution/models/contribution-activity-model"; import { ContributionAs, ContributionAsUnion } from "@/core/domain/contribution/models/contribution.types"; @@ -7,6 +8,7 @@ import { useAuthUser } from "@/shared/hooks/auth/use-auth-user"; import { AssignContributors } from "@/shared/panels/contribution-sidepanel/_features/assign-contributors/assign-contributors"; import { Assignees } from "@/shared/panels/contribution-sidepanel/_features/assignees/assignees"; import { Description } from "@/shared/panels/contribution-sidepanel/_features/description/description"; +import { GithubComment } from "@/shared/panels/contribution-sidepanel/_features/github-comment/github-comment"; import { IssueAppliedKpi } from "@/shared/panels/contribution-sidepanel/_features/issue-applied-kpi/issue-applied-kpi"; import { IssueOverview } from "@/shared/panels/contribution-sidepanel/_features/issue-overview/issue-overview"; import { LinkedIssues } from "@/shared/panels/contribution-sidepanel/_features/linked-issues/linked-issues"; @@ -96,6 +98,16 @@ function useContributionBlocksAsContributor({ contribution }: UseContributionBlo const recipientIds = githubUserId ? [githubUserId] : undefined; const dateKernelPort = bootstrap.getDateKernelPort(); + const contributorApplicationId = + contribution?.applicants.find(applicant => applicant.githubUserId === githubUserId)?.applicationId ?? ""; + + const { data: application } = ApplicationReactQueryAdapter.client.useGetApplicationById({ + pathParams: { applicationId: contributorApplicationId }, + options: { + enabled: !!contributorApplicationId, + }, + }); + if (!contribution) { return null; } @@ -112,7 +124,7 @@ function useContributionBlocksAsContributor({ contribution }: UseContributionBlo openSince={parseInt(dateKernelPort.formatDistanceToNow(new Date(contribution.createdAt), { unit: "day" }))} /> - {/*// GithubComment*/} + ); } diff --git a/shared/panels/project-sidepanel/_components/project-description/project-description.tsx b/shared/panels/project-sidepanel/_components/project-description/project-description.tsx index 698dd1996..8daba590b 100644 --- a/shared/panels/project-sidepanel/_components/project-description/project-description.tsx +++ b/shared/panels/project-sidepanel/_components/project-description/project-description.tsx @@ -8,7 +8,7 @@ import { ProjectDescriptionProps } from "./project-description.types"; export function ProjectDescription({ description, moreInfo }: ProjectDescriptionProps) { return ( - + {description} diff --git a/shared/panels/project-sidepanel/project-sidepanel.en.json b/shared/panels/project-sidepanel/project-sidepanel.en.json index 0062a55b5..8c2ba0997 100644 --- a/shared/panels/project-sidepanel/project-sidepanel.en.json +++ b/shared/panels/project-sidepanel/project-sidepanel.en.json @@ -4,9 +4,6 @@ "information": { "title": "Information" }, - "description": { - "title": "Description" - }, "languages": { "title": "Languages" }, diff --git a/shared/translation/translations/common/common.en.json b/shared/translation/translations/common/common.en.json index 6cb4aae36..7282454be 100644 --- a/shared/translation/translations/common/common.en.json +++ b/shared/translation/translations/common/common.en.json @@ -85,5 +85,6 @@ "form": { "reset": "Reset", "save": "Save" - } + }, + "description": "Description" }