From e7f5becff53e0782138492642b44afec74d53f17 Mon Sep 17 00:00:00 2001 From: jin-Pro Date: Sat, 3 Sep 2022 14:04:55 +0900 Subject: [PATCH] enhance(view): add Commit Type Message Property closed [#70] enhance(view): CommitNode Type add taskId Property feat(view): Detail Component --- .../view/src/components/Detail/Detail.tsx | 30 ++++++++++++++-- .../view/src/components/Detail/Detail.util.ts | 34 +++++++++++++++++++ packages/view/src/types/NodeTypes.temp.ts | 4 +-- 3 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 packages/view/src/components/Detail/Detail.util.ts diff --git a/packages/view/src/components/Detail/Detail.tsx b/packages/view/src/components/Detail/Detail.tsx index 8bf44855..ea6cbd28 100644 --- a/packages/view/src/components/Detail/Detail.tsx +++ b/packages/view/src/components/Detail/Detail.tsx @@ -1,8 +1,34 @@ +/* eslint-disable react/no-array-index-key */ import type { GlobalProps } from "types/global"; +import { getTargetCommit, getTime } from "./Detail.util"; + +const TARGET_ID = "2a7a93cde9c9f74d5f05c1d0fb1da8e96da7057b"; + const Detail = ({ data }: GlobalProps) => { - console.log(data); - return <>Detail; + const commit = getTargetCommit({ data, id: TARGET_ID }); + if (!commit) return null; + const { authorDate, message, committer } = commit; + const time = getTime(authorDate); + return ( + <> +
작성 날짜
+

{time}

+ +
메세지
+

{message}

+ +
Committer Name
+ {committer.names.map((name: string, i: number) => ( +

{name}

+ ))} + +
Committer Email
+ {committer.emails.map((email: string, i: number) => ( +

{email}

+ ))} + + ); }; export default Detail; diff --git a/packages/view/src/components/Detail/Detail.util.ts b/packages/view/src/components/Detail/Detail.util.ts new file mode 100644 index 00000000..872d83d1 --- /dev/null +++ b/packages/view/src/components/Detail/Detail.util.ts @@ -0,0 +1,34 @@ +import type { GlobalProps } from "types/global"; + +import type { CommitNode } from "types/NodeTypes.temp"; + +type GetTargetCommit = GlobalProps & { id: string }; + +export const getTargetCommit = ({ data, id }: GetTargetCommit) => { + if (data?.length === 0) return undefined; + const flatCommitNode: CommitNode[] = data + .map((clusterNode) => clusterNode.commitNodeList) + .flat(); + const [target] = flatCommitNode.filter( + (commitNode) => commitNode.commit.id === id + ); + + // parent Commit 추출하기 + // const parentCommitId = target.commit.parentIds; + // console.log(parentCommitId); + // const parentCommits = parentCommitId.map((parentId) => + // flatCommitNode.filter(commitNode => commitNode.commit.id === parentId) + // ); + // console.log(parentCommits); + + // 동일한 Cluster Commit 추출하기 + // const { taskId: ClusterId } = target; + // const clusterCommits = flatCommitNode.filter( + // (commitNode) => commitNode.taskId === ClusterId + // ); + // console.log(clusterCommits); + return target?.commit; +}; + +export const getTime = (date: Date) => + String(date).split(".")[0].replace("T", " "); diff --git a/packages/view/src/types/NodeTypes.temp.ts b/packages/view/src/types/NodeTypes.temp.ts index 91366fcc..aec1b960 100644 --- a/packages/view/src/types/NodeTypes.temp.ts +++ b/packages/view/src/types/NodeTypes.temp.ts @@ -41,7 +41,7 @@ export type Commit = { authorDate: Date; commitDate: Date; diffStatistics: DiffStatistics; - + message: string; // fill necessary properties... }; @@ -63,7 +63,7 @@ export type CommitNode = NodeBase & { nodeTypeName: "COMMIT"; commit: Commit; seq: number; - + taskId: number; // 동일한 Cluster 내부 commit 참조 id hasMajorTag: boolean; hasMinorTag: boolean; isMergeCommit: boolean;