Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(view) add Summary in VerticalClusterList Component #63

Merged
merged 10 commits into from
Sep 4, 2022
20 changes: 19 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/view/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"npm": ">=8"
},
"scripts": {
"start": "react-scripts start",
"start": "npm run build && react-scripts start",
"build": "npm run build:react && npm run build:bundle",
"build:react": "react-scripts build",
"build:bundle": "webpack --config webpack.config.js",
Expand Down Expand Up @@ -84,6 +84,7 @@
"@testing-library/react": "^13.3.0",
"@testing-library/user-event": "^13.5.0",
"d3": "^7.6.1",
"nanoid": "^4.0.0",
Copy link
Contributor

@wherehows wherehows Sep 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nanoid 추가 댔군요!!

다른분들도 알고 계시면 좋을 듯 하네용. 이미 논의된 내용이라면 죄송합니다. 🙏

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 uuid가 익숙해서 왜 nanoId를 사용하셨을까 궁금해서 nanoid vs uuid 키워드로 구글링해봤는데

https://blog.bitsrc.io/why-is-nanoid-replacing-uuid-1b5100e62ed2

여기에 설명이 나와있네요!

star 수가 uuid보다 nanoid가 더욱 많고,
뿐만아니라, nanoid에서 더 작은 데이터로 uuid를 대체할 수 있으며,
nanoid가 uuid보다 크기가 적다고하네요!

"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-scripts": "5.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export function getGraphHeight(commitCounts: number[]) {
(sum: number, commit: number) => sum + commit,
0
);
return totalCommit * COMMIT_HEIGHT + (commitCounts.length - 1) * NODE_GAP;
return totalCommit * COMMIT_HEIGHT + commitCounts.length * NODE_GAP;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
@import "../../../styles/pallete";

@mixin animation {
-webkit-transition: bottom .3s ease-in-out, opacity .3s ease-in-out;
-moz-transition: bottom .3s ease-in-out, opacity .3s ease-in-out;
transition: bottom .3s ease-in-out, opacity .3s ease-in-out;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ㅎㅎ 훌륭하십니다!


@mixin shadow {
-webkit-box-shadow: 0px 0px 3px 1px rgba(50, 50, 50, 0.4);
-moz-box-shadow: 0px 0px 3px 1px rgba(50, 50, 50, 0.4);
box-shadow: 0px 0px 3px 1px rgba(50, 50, 50, 0.4);
}

@mixin border($border--radius) {
-webkit-border-radius: $border--radius;
-moz-border-radius: $border--radius;
border-radius: $border--radius;
}

body {
background-color: #fff;
color: #222
}

.entire {
width: 85%;
margin-left: 20px;
}

.cluster {
align-items: center;
width: 85%;
padding-top: 10px;
padding-bottom: 10px;
}

.commit {
display: flex;
align-items: center;
flex-direction: row;
padding-top: 10px;
padding-bottom: 10px;
}

.nameBox {
display: flex;
justify-content: center;
}

.name {
@include border(50px);

display: flex;
width: 30px;
height: 30px;
font-weight: bold;
background-color: $blue-light-A700;
color: white;
justify-content: center;
align-items: center;
text-align: center;
font-size: 15pt;

&::after {
@include animation()
}

&:hover {
background-color: $blue-light-A200;
}
}

[data-tooltip-text] {
&:hover {
position: relative;
}

&::after {
@include animation();

@include shadow();

@include border(5px);

content: attr(data-tooltip-text);

position: absolute;
bottom: 30%;
left: -9999px;

color: #FFFFFF;
font-size: 12px;
padding: 7px 12px;
margin-bottom: 10px;
width: auto;
min-width: max-content;
word-wrap: break-word;

opacity: 0;
z-index: 9999;
}

&:hover::after {
left: 100%;
background-color: rgba(0, 119, 170, 0.8);
opacity: 1;
}
}

.message {
width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin-left: 15px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import "./Summary.scss";
import type { GlobalProps } from "types/global";

import type { Commit, Author, Cluster } from ".";
import { getInitData } from ".";

const Summary = ({ data }: GlobalProps) => {
const info = getInitData({ data });

return (
<div className="entire">
{info.map((cluster: Cluster) => {
return (
<div className="cluster" key={cluster.id}>
{cluster.commits.map((commit: Commit) => {
return (
<p className="commit" key={commit.commitId}>
<span className="nameBox">
{commit.authorNames.map((authorName: Author) => {
return (
<span
key={authorName.id}
className="name"
data-tooltip-text={authorName.name}
>
{authorName.name.slice(0, 1)}
</span>
);
})}
</span>
<span className="message">{commit.message}</span>
</p>
);
})}
</div>
);
})}
</div>
);
};

export default Summary;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export type Author = {
id: string;
name: string;
};

export type Commit = {
commitId: string;
authorNames: Array<Author>;
message: string;
};

export type Cluster = {
id: string;
commits: Array<Commit>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { nanoid } from "nanoid";
import type { GlobalProps } from "types/global";

import type { CommitNode } from "types/NodeTypes.temp";

import type { Cluster, Commit } from ".";

export function getInitData({ data }: GlobalProps) {
const clusters: Cluster[] = [];

data.map((clusterNode) => {
const cluster: Cluster = {
id: nanoid(),
commits: [],
};

const commitArray: Commit[] = [];

clusterNode.commitNodeList.map((commitNode: CommitNode) => {
const temp = {
commitId: commitNode.commit.id,
authorNames: commitNode.commit.author.names.map((name) => ({
id: nanoid(),
name: name.trim(),
})),
message: commitNode.commit.message,
};

commitArray.push(temp);

cluster.commits = commitArray;

return temp;
});

clusters.push(cluster);
return cluster;
});

return clusters;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

js에서 선언형 프로그래밍 대신 명령형 프로그래밍을 작성하기 위해 사용되는 방법 중 하나가 고차함수라고 생각합니다.
고차함수는 순수함수라는 특징으로 새로운 객체를 반환해주는 불변성을 유지하는 함수라는 특징이 있는 것으로 기억하는데요,

현재 코드는 고차함수를 사용하지만 선언형 코드로 작성되어있으며, 새로운 객체를 반환해주는 값을 사용하지 않는 것 같아서
좀 어색하다는 느낌이 듭니다!

오히려 고차함수보다는 for문을 사용하거나

commitNode.commit.author.names.map((name) => {
        const author: Author = {
          id: nanoid(),
          name: name.trim(),
        };
        authors.push(author);

        return author;
      });

      const temp = {
        commitId: commitNode.commit.id,
        authorNames: authors,
        message: commitNode.commit.message,
      };

위 로직을

      const temp = {
        commitId: commitNode.commit.id,
        authorNames: commitNode.commit.author.names.map((name) => ({
          id: nanoid(),
          name: name.trim(),
        });
        message: commitNode.commit.message,
      };

와 같이 고차함수를 사용해 반환되는 객체를 사용하는 건 어떨찌 의견을 내봅니다.

다른 분들 의견도 궁금합니다!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아래 코드가 매우 간결하고 직관적인 것 같습니다 :-) 👍
map이 주는 return을 사용하는게 좋은 것 같아요.

고차함수가 뭔지 기억이 잘 안나서 ^^; 찾아봤는데,
https://en.wikipedia.org/wiki/Higher-order_function

고차함수는 순수함수라는 특징으로 새로운 객체를 반환해주는 불변성을 유지하는 함수라는 특징이 있는 것으로 기억하는데요,

함수를 인자로 받고, return이 가능하다고는 있지만, 불변성 보장에 대한 내용은 없는 것 같은데용.
고차함수가 Functional Programming(FP)를 지향을 하는 방법 중 하나일 수는 있지만, 직접적인 인과관계가 있다라고 보기에는 좀 어렵지 않나 싶은데요.
개인적으로는 js 자체가 불변성과 FP와 친한 언어도 아니라고 보긴 합니다;;
(array의 sort만 봐도 parameter로 들어온 배열을 막 맘대로 바꾸니까요 ㅜ.)

심도있는 comment들 덕분에 오늘도 많이 배워 갑니다 ㅎㅎ

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export { default as Summary } from "./Summary";
export type { Commit, Cluster, Author } from "./Summary.type";
export { getInitData } from "./Summary.util";
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import "./VerticalClusterList.scss";

import { ClusterGraph } from "components/VerticalClusterList/ClusterGraph";

import { Summary } from "./Summary";

const VerticalClusterList = ({ data }: GlobalProps) => {
return (
<div className="vertical-cluster-list">
<ClusterGraph data={data} />
<Summary data={data} />
</div>
);
};
Expand Down