@@ -12,19 +12,41 @@ import { GapAnalysisPathStart, OwaspTop10Comparison, SpecializedCheatsheetSectio
1212import { getDocumentDisplayName } from '../../utils' ;
1313import { getInternalUrl } from '../../utils/document' ;
1414
15- const GetSegmentText = ( segment , segmentID ) => {
16- const followsStart = segment . start . id && segment . start . id === segmentID ;
17- const followsEnd = segment . end . id && segment . end . id === segmentID ;
18- const defaultToEnd =
19- segment . start . doctype !== 'CRE' && segment . end . doctype === 'CRE' ;
15+ const documentsMatch = ( left , right ) => {
16+ if ( ! left || ! right ) return false ;
17+ if ( left . id && right . id ) return left . id === right . id ;
2018
19+ return (
20+ left . doctype === right . doctype &&
21+ left . name === right . name &&
22+ left . version === right . version &&
23+ left . sectionID === right . sectionID &&
24+ left . section === right . section &&
25+ left . subsection === right . subsection
26+ ) ;
27+ } ;
28+
29+ const GetSegmentText = ( segment , currentDocument ) => {
2130 let textPart = segment . end ;
22- let nextID = segment . end . id ;
31+ let nextDocument = segment . end ;
2332 let arrow = < Icon name = "arrow down" /> ;
2433
25- if ( followsEnd || ( ! followsStart && ! defaultToEnd ) ) {
34+ if ( documentsMatch ( currentDocument , segment . start ) ) {
35+ textPart = segment . end ;
36+ nextDocument = segment . end ;
37+ } else if ( documentsMatch ( currentDocument , segment . end ) ) {
38+ textPart = segment . start ;
39+ nextDocument = segment . start ;
40+ arrow = < Icon name = "arrow up" /> ;
41+ } else if ( currentDocument ?. doctype !== 'CRE' ) {
42+ if ( segment . start . doctype === 'CRE' && segment . end . doctype !== 'CRE' ) {
43+ textPart = segment . start ;
44+ nextDocument = segment . start ;
45+ arrow = < Icon name = "arrow up" /> ;
46+ }
47+ } else if ( segment . end . doctype === 'CRE' && segment . start . doctype !== 'CRE' ) {
2648 textPart = segment . start ;
27- nextID = segment . start . id ;
49+ nextDocument = segment . start ;
2850 arrow = < Icon name = "arrow up" /> ;
2951 }
3052
@@ -35,10 +57,10 @@ const GetSegmentText = (segment, segmentID) => {
3557 < span style = { { textTransform : 'capitalize' } } >
3658 { segment . relationship . replace ( '_' , ' ' ) . toLowerCase ( ) } { segment . score > 0 && < > (+{ segment . score } )</ > }
3759 </ span >
38- < br /> { getDocumentDisplayName ( textPart , true ) } { textPart . description ?? '' }
60+ < br /> { getDocumentDisplayName ( textPart , true ) } { textPart . doctype === 'CRE' ? textPart . description ?? '' : '' }
3961 </ >
4062 ) ;
41- return { text, nextID } ;
63+ return { text, nextDocument } ;
4264} ;
4365
4466function useQuery ( ) {
@@ -108,7 +130,7 @@ const formatCheatsheetLabel = (document, specializedCategory?: string) => {
108130} ;
109131
110132const GetResultLine = ( path , gapAnalysis , key , specializedCategory ?: string ) => {
111- let segmentID = gapAnalysis [ key ] . start . id ;
133+ let currentDocument = gapAnalysis [ key ] . start ;
112134 return (
113135 < div key = { path . end . id } style = { { marginBottom : '.25em' , fontWeight : 'bold' } } >
114136 < a href = { getInternalUrl ( path . end ) } target = "_blank" rel = "noopener noreferrer" >
@@ -123,8 +145,8 @@ const GetResultLine = (path, gapAnalysis, key, specializedCategory?: string) =>
123145 < Popup . Content >
124146 { getDocumentDisplayName ( gapAnalysis [ key ] . start , true ) }
125147 { path . path . map ( ( segment ) => {
126- const { text, nextID } = GetSegmentText ( segment , segmentID ) ;
127- segmentID = nextID ;
148+ const { text, nextDocument } = GetSegmentText ( segment , currentDocument ) ;
149+ currentDocument = nextDocument ;
128150 return text ;
129151 } ) }
130152 </ Popup . Content >
0 commit comments