1- import React , { useState , useEffect } from "react" ;
1+ import { useMemo } from "react" ;
22import dayjs from "dayjs" ;
33import {
44 AddCircleRounded ,
@@ -13,26 +13,25 @@ import { Tooltip } from "@mui/material";
1313
1414import { useGithubInfo , useDataStore } from "store" ;
1515import { Author } from "components/@common/Author" ;
16- import { GithubIssueLink } from "components/@common/GithubIssueLink" ;
16+ import type { IssueLinkedMessage } from "components/@common/GithubIssueLink" ;
17+ import { renderIssueLinkedNodes } from "components/@common/GithubIssueLink" ;
1718
1819import { useCommitListHide } from "./Detail.hook" ;
1920import { getCommitListDetail } from "./Detail.util" ;
2021import { FIRST_SHOW_NUM } from "./Detail.const" ;
21- import type { DetailProps , DetailSummaryProps , DetailSummaryItem , CommitItemProps , LinkedMessage } from "./Detail.type" ;
22+ import type { DetailProps , DetailSummaryProps , DetailSummaryItem , CommitItemProps } from "./Detail.type" ;
2223
2324import "./Detail.scss" ;
2425
2526const Detail = ( { clusterId, authSrcMap } : DetailProps ) => {
2627 const selectedData = useDataStore ( ( state ) => state . selectedData ) ;
27- const [ linkedMessage , setLinkedMessage ] = useState < LinkedMessage > ( {
28- title : [ ] ,
29- body : null ,
30- } ) ;
31-
3228 const { owner, repo } = useGithubInfo ( ) ;
3329
34- const commitNodeListInCluster =
35- selectedData ?. filter ( ( selected ) => selected . commitNodeList [ 0 ] . clusterId === clusterId ) [ 0 ] . commitNodeList ?? [ ] ;
30+ const commitNodeListInCluster = useMemo (
31+ ( ) =>
32+ selectedData ?. filter ( ( selected ) => selected . commitNodeList [ 0 ] . clusterId === clusterId ) [ 0 ] . commitNodeList ?? [ ] ,
33+ [ selectedData , clusterId ]
34+ ) ;
3635 const { commitNodeList, toggle, handleToggle } = useCommitListHide ( commitNodeListInCluster ) ;
3736
3837 const isShow = commitNodeListInCluster . length > FIRST_SHOW_NUM ;
@@ -41,63 +40,17 @@ const Detail = ({ clusterId, authSrcMap }: DetailProps) => {
4140 navigator . clipboard . writeText ( id ) ;
4241 } ;
4342
44- useEffect ( ( ) => {
45- const processMessage = ( message : string ) => {
46- // GitHub 이슈 번호 패턴: #123 또는 (#123)
47- const regex = / (?: ^ | \s ) ( # \d + ) (?: \s | $ ) / g;
48- const parts : React . ReactNode [ ] = [ ] ;
49- let lastIndex = 0 ;
50- let match : RegExpExecArray | null ;
51-
52- while ( true ) {
53- match = regex . exec ( message ) ;
54- if ( match === null ) break ;
55-
56- // 이슈 번호 앞의 텍스트 추가
57- if ( match . index > lastIndex ) {
58- parts . push ( message . slice ( lastIndex , match . index ) ) ;
59- }
60-
61- const issueNumber = match [ 1 ] . substring ( 1 ) ;
43+ const issueLinkedMessage : IssueLinkedMessage = useMemo ( ( ) => {
44+ const message = commitNodeListInCluster ?. [ 0 ] ?. commit ?. message ;
45+ if ( ! message ) return { title : [ ] , body : null } ;
6246
63- parts . push (
64- < GithubIssueLink
65- key = { `issue-${ issueNumber } -${ match . index } ` }
66- owner = { owner }
67- repo = { repo }
68- issueNumber = { issueNumber }
69- />
70- ) ;
47+ const [ title , ...rest ] = message . split ( "\n" ) ;
48+ const body = rest . filter ( ( line ) => line . trim ( ) ) . join ( "\n" ) ;
7149
72- lastIndex = match . index + match [ 0 ] . length ;
73- }
74-
75- // 마지막 부분 추가
76- if ( lastIndex < message . length ) {
77- parts . push ( message . slice ( lastIndex ) ) ;
78- }
79-
80- return parts . length > 0 ? parts : [ message ] ;
50+ return {
51+ title : renderIssueLinkedNodes ( title , owner , repo ) ,
52+ body : body ? renderIssueLinkedNodes ( body , owner , repo ) : null ,
8153 } ;
82-
83- if ( commitNodeListInCluster ?. [ 0 ] ?. commit ?. message ) {
84- const { message } = commitNodeListInCluster [ 0 ] . commit ;
85- const messageLines = message . split ( "\n" ) ;
86- const title = messageLines [ 0 ] ;
87- const body = messageLines
88- . slice ( 1 )
89- . filter ( ( line : string ) => line . trim ( ) )
90- . join ( "\n" ) ;
91-
92- // 제목과 본문을 각각 처리
93- const processedTitle = processMessage ( title ) ;
94- const processedBody = body ? processMessage ( body ) : null ;
95-
96- setLinkedMessage ( {
97- title : processedTitle ,
98- body : processedBody ,
99- } ) ;
100- }
10154 } , [ commitNodeListInCluster , owner , repo ] ) ;
10255
10356 if ( ! selectedData || selectedData . length === 0 ) return null ;
@@ -114,7 +67,7 @@ const Detail = ({ clusterId, authSrcMap }: DetailProps) => {
11467 repo = { repo }
11568 authSrcMap = { authSrcMap }
11669 handleCommitIdCopy = { handleCommitIdCopy }
117- linkedMessage = { linkedMessage }
70+ linkedMessage = { issueLinkedMessage }
11871 />
11972 ) ) }
12073 </ ul >
0 commit comments