Skip to content

Commit

Permalink
Add timelines (#681)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbeno authored Nov 20, 2024
1 parent c5e42cb commit 7292209
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 88 deletions.
34 changes: 8 additions & 26 deletions core/domain/contribution/models/contribution-event-model.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,24 @@
import { ContributionEventType } from "@/core/domain/contribution/models/contribution.types";
import { ContributionEventTypeUnion } from "@/core/domain/contribution/models/contribution.types";
import { components } from "@/core/infrastructure/marketplace-api-client-adapter/__generated/api";

export type ContributionEventResponse = components["schemas"]["ContributionEventResponse"];

export interface ContributionEventInterface extends ContributionEventResponse {
getEventType(): ContributionEventType | undefined;
getEventType(): ContributionEventTypeUnion | undefined;
}

export class ContributionEvent implements ContributionEventInterface {
timestamp!: ContributionEventResponse["timestamp"];
assigneeAdded!: ContributionEventResponse["assigneeAdded"];
assigneeRemoved!: ContributionEventResponse["assigneeRemoved"];
opened!: ContributionEventResponse["opened"];
merged!: ContributionEventResponse["merged"];
closed!: ContributionEventResponse["closed"];
issueLinked!: ContributionEventResponse["issueLinked"];
issueUnlinked!: ContributionEventResponse["issueUnlinked"];
type!: ContributionEventResponse["type"];
assignee!: ContributionEventResponse["assignee"];
mergedBy!: ContributionEventResponse["mergedBy"];
linkedIssueContributionUuid!: ContributionEventResponse["linkedIssueContributionUuid"];

constructor(props: ContributionEventResponse) {
Object.assign(this, props);
}

getEventType(): ContributionEventType | undefined {
switch (true) {
case !!this.assigneeAdded:
return ContributionEventType.CONTRIBUTOR_ASSIGNED;
case !!this.assigneeRemoved:
return ContributionEventType.CONTRIBUTOR_REMOVED;
case !!this.opened:
return ContributionEventType.PR_CREATED;
case !!this.merged:
return ContributionEventType.TO_REVIEW;
case !!this.closed:
return ContributionEventType.CLOSED;
case !!this.issueLinked:
return ContributionEventType.ISSUE_CREATED;
default:
return undefined;
}
getEventType(): ContributionEventTypeUnion | undefined {
return this.type;
}
}
16 changes: 10 additions & 6 deletions core/domain/contribution/models/contribution.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GetContributionsResponse } from "@/core/domain/contribution/contribution-contract.types";
import { ContributionEventResponse } from "@/core/domain/contribution/models/contribution-event-model";

type status = GetContributionsResponse["contributions"][0]["activityStatus"];

Expand All @@ -15,14 +16,17 @@ export type ContributionActivityStatusUnion = keyof typeof ContributionActivityS
export type ContributionGithubStatusUnion = GetContributionsResponse["contributions"][0]["githubStatus"];
export type ContributionTypeUnion = GetContributionsResponse["contributions"][0]["type"];

export type ContributionEventTypeUnion = ContributionEventResponse["type"];

export enum ContributionEventType {
PR_CREATED = "PR_CREATED",
CONTRIBUTOR_ASSIGNED = "CONTRIBUTOR_ASSIGNED",
CONTRIBUTOR_REMOVED = "CONTRIBUTOR_REMOVED",
ISSUE_CREATED = "ISSUE_CREATED",
TO_REVIEW = "TO_REVIEW",
CLOSED = "CLOSED",
REWARDED = "REWARDED",
PR_CREATED = "PR_CREATED",
ISSUE_ASSIGNED = "ISSUE_ASSIGNED",
PR_MERGED = "PR_MERGED",
ISSUE_CLOSED = "ISSUE_CLOSED",
LINKED_ISSUE_CREATED = "LINKED_ISSUE_CREATED",
LINKED_ISSUE_ASSIGNED = "LINKED_ISSUE_ASSIGNED",
LINKED_ISSUE_CLOSED = "LINKED_ISSUE_CLOSED",
}

export enum ContributionAs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class ContributionClientAdapter implements ContributionStoragePort {
routes = {
getContributions: "contributions",
getContributionById: "contributions/:contributionUuid",
getContributionEvent: "contributions/:contributionId/events",
getContributionEvent: "contributions/:contributionUuid/events",
} as const;

getContributions = ({ queryParams }: FirstParameter<ContributionStoragePort["getContributions"]>) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CircleCheck, CircleDashed, CircleDollarSign, CircleDotDashed, UserRoundPlus, UserX } from "lucide-react";
import { CircleCheck, CircleDashed, GitMerge, UserRoundPlus } from "lucide-react";
import { useMemo } from "react";

import { ContributionReactQueryAdapter } from "@/core/application/react-query-adapter/contribution";
Expand All @@ -12,56 +12,35 @@ import { Typo } from "@/design-system/atoms/typo";
import { Timeline as TimelineComponent, TimelinePort } from "@/design-system/organisms/timeline";

import { Translate } from "@/shared/translation/components/translate/translate";
import { TranslateProps } from "@/shared/translation/components/translate/translate.types";

import { TimelineProps } from "./timeline.types";

export function Timeline({ id }: TimelineProps) {
const dateKernelPort = bootstrap.getDateKernelPort();

const { data: events } = ContributionReactQueryAdapter.client.useGetContributionEvents({
pathParams: { contributionId: id },
pathParams: { contributionUuid: id },
});

function getTranslate(event: ContributionEventInterface): TranslateProps | undefined {
const type = event.getEventType();
switch (type) {
case ContributionEventType.CONTRIBUTOR_ASSIGNED:
return { token: "panels:contribution.timeline.items.contributorAssigned" };
case ContributionEventType.PR_CREATED:
return { token: "panels:contribution.timeline.items.prCreated" };
case ContributionEventType.CONTRIBUTOR_REMOVED:
return { token: "panels:contribution.timeline.items.contributorRemoved" };
case ContributionEventType.ISSUE_CREATED:
return { token: "panels:contribution.timeline.items.issueCreated" };
case ContributionEventType.TO_REVIEW:
return { token: "panels:contribution.timeline.items.toReview" };
case ContributionEventType.CLOSED:
return { token: "panels:contribution.timeline.items.closed" };
case ContributionEventType.REWARDED:
return { token: "panels:contribution.timeline.items.rewarded" };
default:
return undefined;
}
}

function getIcon(event: ContributionEventInterface) {
const type = event.getEventType();
switch (type) {
case ContributionEventType.CONTRIBUTOR_ASSIGNED:
return { component: UserRoundPlus };
case ContributionEventType.PR_CREATED:
return { component: CircleDashed };
case ContributionEventType.CONTRIBUTOR_REMOVED:
return { component: UserX };
case ContributionEventType.ISSUE_CREATED:
return { component: CircleDashed };
case ContributionEventType.TO_REVIEW:
return { component: CircleDotDashed };
case ContributionEventType.CLOSED:
case ContributionEventType.LINKED_ISSUE_CREATED:
return { component: CircleDashed };
case ContributionEventType.ISSUE_ASSIGNED:
return { component: UserRoundPlus };
case ContributionEventType.LINKED_ISSUE_ASSIGNED:
return { component: UserRoundPlus };
case ContributionEventType.ISSUE_CLOSED:
return { component: CircleCheck };
case ContributionEventType.LINKED_ISSUE_CLOSED:
return { component: CircleCheck };
case ContributionEventType.REWARDED:
return { component: CircleDollarSign };
case ContributionEventType.PR_CREATED:
return { component: CircleDashed };
case ContributionEventType.PR_MERGED:
return { component: GitMerge };
default:
return undefined;
}
Expand All @@ -70,12 +49,12 @@ export function Timeline({ id }: TimelineProps) {
const timelineItems: TimelinePort<AnyType>["items"] = useMemo(() => {
return (events || [])
.map(event => {
const translate = getTranslate(event);
const eventType = event?.getEventType();
const icon = getIcon(event);
if (!translate?.token || !icon) return null;
if (!eventType || !icon) return null;

return {
label: translate?.token ? <Translate token={translate.token} /> : undefined,
label: <Translate token={`panels:contribution.timeline.items.${eventType}`} />,
icon,
endContent: dateKernelPort.format(new Date(event.timestamp), "dd MMM yyyy"),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
"timeline": {
"title": "Timeline",
"items": {
"prCreated": "PR Created",
"contributorAssigned": "Contributor assigned",
"contributorRemoved": "Contributor removed",
"issueCreated": "Issue Created",
"toReview": "To review",
"closed": "Closed",
"rewarded": "Rewarded"
"ISSUE_CREATED": "Issue created",
"PR_CREATED": "PR Created",
"ISSUE_ASSIGNED": "Issue assigned",
"PR_MERGED": "PR Merged",
"ISSUE_CLOSED": "Issue closed",
"LINKED_ISSUE_CREATED": "Linked issue created",
"LINKED_ISSUE_ASSIGNED": "Linked issue assigned",
"LINKED_ISSUE_CLOSED": "Linked issue closed"
}
},
"contributors": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ContributionsPanelData } from "@/shared/panels/contribution-sidepanel/c

import { Helper } from "./_features/helper/helper";
import { RewardedCardWrapper } from "./_features/rewarded-card-wrapper/rewarded-card-wrapper";
import { Timeline } from "./_features/timeline/timeline";

export function useContributionsSidepanel() {
return useSinglePanelContext<ContributionsPanelData>("contribution-details");
Expand Down Expand Up @@ -57,8 +58,7 @@ function useContributionBlocksAsMaintainer({ contribution, helperState }: UseCon
<IssueOverview contribution={contribution} />
<RewardedCardWrapper contribution={contribution} />
<Assignees showRemove={true} contribution={contribution} />
{/* KEEP THIS */}
{/*<Timeline id={contribution.id} />*/}
<Timeline id={contribution.id} />
</>
);
}
Expand All @@ -75,8 +75,7 @@ function useContributionBlocksAsMaintainer({ contribution, helperState }: UseCon
<RewardedCardWrapper contribution={contribution} />
<LinkedIssues issues={contribution.linkedIssues} />
<Assignees contribution={contribution} />
{/* KEEP THIS */}
{/*<Timeline id={contribution.id} />*/}
<Timeline id={contribution.id} />
</>
);
}
Expand All @@ -87,8 +86,7 @@ function useContributionBlocksAsMaintainer({ contribution, helperState }: UseCon
<IssueOverview contribution={contribution} />
<RewardedCardWrapper contribution={contribution} />
<Assignees contribution={contribution} />
{/* KEEP THIS */}
{/*<Timeline id={contribution.id} />*/}
<Timeline id={contribution.id} />
</>
);
}
Expand Down Expand Up @@ -142,7 +140,7 @@ function useContributionBlocksAsContributor({ contribution }: UseContributionBlo
<RewardedCardWrapper contribution={contribution} recipientIds={recipientIds} />
<UserCard title={{ translate: { token: "panels:contribution.userCard.assignedBy" } }} user={assignedBy} />
<Description description={contribution.githubBody} />
{/*// Timeline*/}
<Timeline id={contribution.id} />
</>
);
}
Expand All @@ -155,7 +153,7 @@ function useContributionBlocksAsContributor({ contribution }: UseContributionBlo
<LinkedIssues issues={contribution.linkedIssues} />
<RewardedCardWrapper contribution={contribution} recipientIds={recipientIds} />
<Description description={contribution.githubBody} />
{/*// Timeline*/}
<Timeline id={contribution.id} />
</>
);
}
Expand All @@ -172,7 +170,7 @@ function useContributionBlocksAsContributor({ contribution }: UseContributionBlo
user={contribution.mergedBy}
/>
<Description description={contribution.githubBody} />
{/*// Timeline*/}
<Timeline id={contribution.id} />
</>
);
}
Expand Down

0 comments on commit 7292209

Please sign in to comment.