Skip to content

Commit a19cffb

Browse files
committed
fix(search): update to only link title in search results
Signed-off-by: Jonathan Sundquist <jonathan.sundquist@factset.com>
1 parent 50b941c commit a19cffb

File tree

6 files changed

+67
-44
lines changed

6 files changed

+67
-44
lines changed

.changeset/old-tips-cough.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@backstage/plugin-adr': patch
3+
'@backstage/plugin-catalog': patch
4+
'@backstage/plugin-search-react': patch
5+
'@backstage/plugin-stack-overflow': patch
6+
'@backstage/plugin-techdocs': patch
7+
---
8+
9+
Update search links to only have header as linkable text

plugins/adr/src/search/AdrSearchResultListItem.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,24 @@ export function AdrSearchResultListItem(props: {
6464
};
6565

6666
return (
67-
<Link noTrack to={result.location} onClick={handleClick}>
67+
<>
6868
<ListItem alignItems="flex-start" className={classes.flexContainer}>
6969
<ListItemText
7070
className={classes.itemText}
7171
primaryTypographyProps={{ variant: 'h6' }}
7272
primary={
7373
highlight?.fields.title ? (
74-
<HighlightedSearchResultText
75-
text={highlight.fields.title}
76-
preTag={highlight.preTag}
77-
postTag={highlight.postTag}
78-
/>
74+
<Link noTrack to={result.location} onClick={handleClick}>
75+
<HighlightedSearchResultText
76+
text={highlight.fields.title}
77+
preTag={highlight.preTag}
78+
postTag={highlight.postTag}
79+
/>
80+
</Link>
7981
) : (
80-
result.title
82+
<Link noTrack to={result.location} onClick={handleClick}>
83+
{result.title}
84+
</Link>
8185
)
8286
}
8387
secondary={
@@ -116,6 +120,6 @@ export function AdrSearchResultListItem(props: {
116120
</Box>
117121
</ListItem>
118122
<Divider component="li" />
119-
</Link>
123+
</>
120124
);
121125
}

plugins/catalog/src/components/CatalogSearchResultListItem/CatalogSearchResultListItem.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export function CatalogSearchResultListItem(
7171
};
7272

7373
return (
74-
<Link noTrack to={result.location} onClick={handleClick}>
74+
<>
7575
<ListItem alignItems="flex-start">
7676
{props.icon && <ListItemIcon>{props.icon}</ListItemIcon>}
7777
<div className={classes.flexContainer}>
@@ -80,13 +80,17 @@ export function CatalogSearchResultListItem(
8080
primaryTypographyProps={{ variant: 'h6' }}
8181
primary={
8282
props.highlight?.fields.title ? (
83-
<HighlightedSearchResultText
84-
text={props.highlight.fields.title}
85-
preTag={props.highlight.preTag}
86-
postTag={props.highlight.postTag}
87-
/>
83+
<Link noTrack to={result.location} onClick={handleClick}>
84+
<HighlightedSearchResultText
85+
text={props.highlight.fields.title}
86+
preTag={props.highlight.preTag}
87+
postTag={props.highlight.postTag}
88+
/>
89+
</Link>
8890
) : (
89-
result.title
91+
<Link noTrack to={result.location} onClick={handleClick}>
92+
{result.title}
93+
</Link>
9094
)
9195
}
9296
secondary={
@@ -112,6 +116,6 @@ export function CatalogSearchResultListItem(
112116
</div>
113117
</ListItem>
114118
<Divider component="li" />
115-
</Link>
119+
</>
116120
);
117121
}

plugins/search-react/src/components/DefaultResultListItem/DefaultResultListItem.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,24 @@ export const DefaultResultListItemComponent = ({
6666
};
6767

6868
return (
69-
<Link noTrack to={result.location} onClick={handleClick}>
69+
<>
7070
<ListItem alignItems="center">
7171
{icon && <ListItemIcon>{icon}</ListItemIcon>}
7272
<ListItemText
7373
primaryTypographyProps={{ variant: 'h6' }}
7474
primary={
7575
highlight?.fields.title ? (
76-
<HighlightedSearchResultText
77-
text={highlight.fields.title}
78-
preTag={highlight.preTag}
79-
postTag={highlight.postTag}
80-
/>
76+
<Link noTrack to={result.location} onClick={handleClick}>
77+
<HighlightedSearchResultText
78+
text={highlight.fields.title}
79+
preTag={highlight.preTag}
80+
postTag={highlight.postTag}
81+
/>
82+
</Link>
8183
) : (
82-
result.title
84+
<Link noTrack to={result.location} onClick={handleClick}>
85+
{result.title}
86+
</Link>
8387
)
8488
}
8589
secondary={
@@ -106,7 +110,7 @@ export const DefaultResultListItemComponent = ({
106110
{secondaryAction && <Box alignItems="flex-end">{secondaryAction}</Box>}
107111
</ListItem>
108112
<Divider />
109-
</Link>
113+
</>
110114
);
111115
};
112116

plugins/stack-overflow/src/search/StackOverflowSearchResultListItem/StackOverflowSearchResultListItem.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,17 @@ export const StackOverflowSearchResultListItem = (
4747
};
4848

4949
return (
50-
<Link to={location} noTrack onClick={handleClick}>
50+
<>
5151
<ListItem alignItems="center">
5252
{props.icon && <ListItemIcon>{props.icon}</ListItemIcon>}
5353
<Box flexWrap="wrap">
5454
<ListItemText
5555
primaryTypographyProps={{ variant: 'h6' }}
56-
primary={_unescape(title)}
56+
primary={
57+
<Link to={location} noTrack onClick={handleClick}>
58+
{_unescape(title)}
59+
</Link>
60+
}
5761
secondary={`Author: ${text}`}
5862
/>
5963
<Chip label={`Answer(s): ${answers}`} size="small" />
@@ -64,6 +68,6 @@ export const StackOverflowSearchResultListItem = (
6468
</Box>
6569
</ListItem>
6670
<Divider />
67-
</Link>
71+
</>
6872
);
6973
};

plugins/techdocs/src/search/components/TechDocsSearchResultListItem.tsx

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ export const TechDocsSearchResultListItem = (
8181
});
8282
};
8383

84+
const LinkWrapper = ({ children }: PropsWithChildren<{}>) =>
85+
asLink ? (
86+
<Link noTrack to={result.location} onClick={handleClick}>
87+
{children}
88+
</Link>
89+
) : (
90+
<>{children}</>
91+
);
92+
8493
const TextItem = () => {
8594
const resultTitle = highlight?.fields.title ? (
8695
<HighlightedSearchResultText
@@ -118,11 +127,11 @@ export const TechDocsSearchResultListItem = (
118127
primaryTypographyProps={{ variant: 'h6' }}
119128
primary={
120129
title ? (
121-
title
130+
<LinkWrapper>{title}</LinkWrapper>
122131
) : (
123-
<>
132+
<LinkWrapper>
124133
{resultTitle} | {entityTitle ?? resultName} docs
125-
</>
134+
</LinkWrapper>
126135
)
127136
}
128137
secondary={
@@ -149,15 +158,6 @@ export const TechDocsSearchResultListItem = (
149158
);
150159
};
151160

152-
const LinkWrapper = ({ children }: PropsWithChildren<{}>) =>
153-
asLink ? (
154-
<Link noTrack to={result.location} onClick={handleClick}>
155-
{children}
156-
</Link>
157-
) : (
158-
<>{children}</>
159-
);
160-
161161
const ListItemWrapper = ({ children }: PropsWithChildren<{}>) =>
162162
asListItem ? (
163163
<>
@@ -172,10 +172,8 @@ export const TechDocsSearchResultListItem = (
172172
);
173173

174174
return (
175-
<LinkWrapper>
176-
<ListItemWrapper>
177-
<TextItem />
178-
</ListItemWrapper>
179-
</LinkWrapper>
175+
<ListItemWrapper>
176+
<TextItem />
177+
</ListItemWrapper>
180178
);
181179
};

0 commit comments

Comments
 (0)