-
Notifications
You must be signed in to change notification settings - Fork 1
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
DEVXT-1941 GitHub Discussions Search #191
Draft
minkimcello
wants to merge
7
commits into
bcgov:main
Choose a base branch
from
guidanti:DEVXT-1941
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,737
−122
Draft
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
53fb196
DROP - Install search module from tar
minkimcello d673df4
Add search module to backend and configure repo url
minkimcello ff79225
Create search list item component for discussions with links to backs…
minkimcello c1c2cf8
Use SearchDocument for UI component
minkimcello 3368042
Destructure lineClamp too
minkimcello 2221270
DROP upgrade collator with 0.6.0
minkimcello 3de490a
Add divider and icon to discussions list item
minkimcello File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
packages/app/src/components/search/GithubDiscussionsSearchResultListItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import React, { ReactNode } from 'react'; | ||
import Box from '@material-ui/core/Box'; | ||
import Chip from '@material-ui/core/Chip'; | ||
import ListItemIcon from '@material-ui/core/ListItemIcon'; | ||
import ListItemText from '@material-ui/core/ListItemText'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import { makeStyles } from '@material-ui/core/styles'; | ||
import { Link } from '@backstage/core-components'; | ||
import { ResultHighlight } from '@backstage/plugin-search-common'; | ||
import { HighlightedSearchResultText } from '@backstage/plugin-search-react'; | ||
import { IndexableDocument } from '@backstage/plugin-search-common'; | ||
import { EntityRefLink } from '@backstage/plugin-catalog-react'; | ||
|
||
export interface GithubDiscussionsDocument extends IndexableDocument { | ||
author: string; | ||
category: string; | ||
labels: { | ||
name: string; | ||
color: string; | ||
}[]; | ||
comments: { | ||
author: string; | ||
bodyText: string; | ||
replies: { | ||
author: string; | ||
bodyText: string; | ||
}[]; | ||
}[]; | ||
} | ||
|
||
const useStyles = makeStyles(theme => ({ | ||
item: { | ||
display: 'flex', | ||
}, | ||
flexContainer: { | ||
flexWrap: 'wrap', | ||
}, | ||
itemText: { | ||
width: '100%', | ||
wordBreak: 'break-all', | ||
marginBottom: '1rem', | ||
}, | ||
user: { | ||
display: 'inline-flex', | ||
margin: theme.spacing(1), | ||
}, | ||
})); | ||
|
||
/** | ||
* Props for {@link GithubDiscussionsSearchResultListItem}. | ||
* | ||
* @public | ||
*/ | ||
export interface GithubDiscussionsSearchResultListItemProps { | ||
icon?: ReactNode; | ||
result?: GithubDiscussionsDocument; | ||
highlight?: ResultHighlight; | ||
lineClamp?: number; | ||
} | ||
|
||
/** @public */ | ||
export function GithubDiscussionsSearchResultListItem( | ||
props: GithubDiscussionsSearchResultListItemProps, | ||
) { | ||
const { result, highlight, icon } = props; | ||
const classes = useStyles(); | ||
if (!result) return null; | ||
|
||
return ( | ||
<div className={classes.item}> | ||
{icon && <ListItemIcon>{icon}</ListItemIcon>} | ||
<div className={classes.flexContainer}> | ||
<ListItemText | ||
className={classes.itemText} | ||
primaryTypographyProps={{ variant: 'h6' }} | ||
primary={ | ||
<Link noTrack to={result.location}> | ||
{highlight?.fields.title ? ( | ||
<HighlightedSearchResultText | ||
text={highlight.fields.title} | ||
preTag={highlight.preTag} | ||
postTag={highlight.postTag} | ||
/> | ||
) : ( | ||
result.title | ||
)} | ||
</Link> | ||
} | ||
secondary={ | ||
<Typography | ||
component="span" | ||
style={{ | ||
display: '-webkit-box', | ||
WebkitBoxOrient: 'vertical', | ||
WebkitLineClamp: props.lineClamp, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add lineClamp as part of the props destructure above? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done 👍 |
||
overflow: 'hidden', | ||
}} | ||
color="textSecondary" | ||
variant="body2" | ||
> | ||
{highlight?.fields.text ? ( | ||
<HighlightedSearchResultText | ||
text={highlight.fields.text} | ||
preTag={highlight.preTag} | ||
postTag={highlight.postTag} | ||
/> | ||
) : ( | ||
result.text | ||
)} | ||
</Typography> | ||
} | ||
/> | ||
<Box> | ||
{result.author && ( | ||
<div className={classes.user}> | ||
<EntityRefLink entityRef={`user:default/${result.author}`} /> | ||
MonicaG marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</div> | ||
)} | ||
{result.category && <Chip label={result.category} size="small" />} | ||
{result.labels.length > 0 && | ||
result.labels.map(({ name }) => { | ||
return <Chip key={name} label={name} size="small" />; | ||
})} | ||
</Box> | ||
</div> | ||
</div> | ||
); | ||
} |
125 changes: 71 additions & 54 deletions
125
packages/app/src/components/search/SearchResultCustomList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,81 @@ | ||
import React from 'react'; | ||
|
||
import { List } from '@material-ui/core'; | ||
import { SearchResult, DefaultResultListItem } from '@backstage/plugin-search-react'; | ||
import { | ||
SearchResult, | ||
DefaultResultListItem, | ||
} from '@backstage/plugin-search-react'; | ||
|
||
import { CatalogSearchResultListItem } from '@backstage/plugin-catalog'; | ||
import { StackOverflowSearchResultListItem, StackOverflowIcon } from '@backstage-community/plugin-stack-overflow'; | ||
import { | ||
StackOverflowSearchResultListItem, | ||
StackOverflowIcon, | ||
} from '@backstage-community/plugin-stack-overflow'; | ||
import { CatalogIcon, DocsIcon } from '@backstage/core-components'; | ||
import { TechDocsSearchResultCustomListItem } from './TechDocsSearchResultCustomListItem'; | ||
import { | ||
GithubDiscussionsSearchResultListItem, | ||
GithubDiscussionsDocument, | ||
} from './GithubDiscussionsSearchResultListItem'; | ||
|
||
const SearchResultCustomList = () => { | ||
return ( | ||
<SearchResult> | ||
{({ results }) => ( | ||
<List> | ||
{results.map(({ type, document, highlight, rank }) => { | ||
switch (type) { | ||
case 'software-catalog': | ||
return ( | ||
<CatalogSearchResultListItem | ||
key={document.location} | ||
result={document} | ||
highlight={highlight} | ||
rank={rank} | ||
icon={<CatalogIcon />} | ||
/> | ||
); | ||
case 'techdocs': | ||
return ( | ||
<TechDocsSearchResultCustomListItem | ||
key={document.location} | ||
result={document} | ||
highlight={highlight} | ||
rank={rank} | ||
asListItem={true} | ||
icon={<DocsIcon />} | ||
/> | ||
); | ||
case 'stack-overflow': | ||
return ( | ||
<StackOverflowSearchResultListItem | ||
key={document.location} | ||
result={document} | ||
icon={<StackOverflowIcon />} | ||
/> | ||
); | ||
default: | ||
return ( | ||
<DefaultResultListItem | ||
key={document.location} | ||
result={document} | ||
highlight={highlight} | ||
rank={rank} | ||
/> | ||
); | ||
} | ||
})} | ||
</List> | ||
)} | ||
</SearchResult> | ||
) | ||
} | ||
return ( | ||
<SearchResult> | ||
{({ results }) => ( | ||
<List> | ||
{results.map(({ type, document, highlight, rank }) => { | ||
switch (type) { | ||
case 'software-catalog': | ||
return ( | ||
<CatalogSearchResultListItem | ||
key={document.location} | ||
result={document} | ||
highlight={highlight} | ||
rank={rank} | ||
icon={<CatalogIcon />} | ||
/> | ||
); | ||
case 'techdocs': | ||
return ( | ||
<TechDocsSearchResultCustomListItem | ||
key={document.location} | ||
result={document} | ||
highlight={highlight} | ||
rank={rank} | ||
asListItem | ||
icon={<DocsIcon />} | ||
/> | ||
); | ||
case 'stack-overflow': | ||
return ( | ||
<StackOverflowSearchResultListItem | ||
key={document.location} | ||
result={document} | ||
icon={<StackOverflowIcon />} | ||
/> | ||
); | ||
case 'github-discussions': | ||
return ( | ||
<GithubDiscussionsSearchResultListItem | ||
result={document as GithubDiscussionsDocument} | ||
highlight={highlight} | ||
/> | ||
); | ||
default: | ||
return ( | ||
<DefaultResultListItem | ||
key={document.location} | ||
result={document} | ||
highlight={highlight} | ||
rank={rank} | ||
/> | ||
); | ||
} | ||
})} | ||
</List> | ||
)} | ||
</SearchResult> | ||
); | ||
}; | ||
|
||
export const searchResultCustomList = <SearchResultCustomList />; | ||
export const searchResultCustomList = <SearchResultCustomList />; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious about using IndexableDocument vs SearchDocument as per the documentation's comment about:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good catch; we should use
SearchDocument
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed the changes to use
SearchDocument
and also made the changes in my PR in community-plugins (see commit). So once that gets merged and the packages get published we'll be able to import the interface directly from the common package.