From 3ea6316cb43809d3ab51ee063f1f31b4eb87a1b2 Mon Sep 17 00:00:00 2001 From: Leon Date: Thu, 12 May 2022 13:52:21 +0200 Subject: [PATCH 1/4] optional icon for catalog and techdocs results Signed-off-by: Leon --- .../app/src/components/search/SearchModal.tsx | 9 ++- .../app/src/components/search/SearchPage.tsx | 2 + .../CatalogSearchResultListItem.tsx | 75 ++++++++++--------- .../TechDocsSearchResultListItem.tsx | 17 ++++- 4 files changed, 64 insertions(+), 39 deletions(-) diff --git a/packages/app/src/components/search/SearchModal.tsx b/packages/app/src/components/search/SearchModal.tsx index 3fdacf08b6..4af5511443 100644 --- a/packages/app/src/components/search/SearchModal.tsx +++ b/packages/app/src/components/search/SearchModal.tsx @@ -26,7 +26,12 @@ import { useTheme, } from '@material-ui/core'; import LaunchIcon from '@material-ui/icons/Launch'; -import { Link, useContent } from '@backstage/core-components'; +import { + CatalogIcon, + DocsIcon, + Link, + useContent, +} from '@backstage/core-components'; import { useApi, useRouteRef } from '@backstage/core-plugin-api'; import { CatalogSearchResultListItem } from '@backstage/plugin-catalog'; import { @@ -186,6 +191,7 @@ export const SearchModal = ({ toggleModal }: { toggleModal: () => void }) => { case 'software-catalog': resultItem = ( } key={document.location} result={document} highlight={highlight} @@ -195,6 +201,7 @@ export const SearchModal = ({ toggleModal }: { toggleModal: () => void }) => { case 'techdocs': resultItem = ( } key={document.location} result={document} highlight={highlight} diff --git a/packages/app/src/components/search/SearchPage.tsx b/packages/app/src/components/search/SearchPage.tsx index d1b56bbaf0..558a564b66 100644 --- a/packages/app/src/components/search/SearchPage.tsx +++ b/packages/app/src/components/search/SearchPage.tsx @@ -137,6 +137,7 @@ const SearchPage = () => { case 'software-catalog': return ( } key={document.location} result={document} highlight={highlight} @@ -145,6 +146,7 @@ const SearchPage = () => { case 'techdocs': return ( } key={document.location} result={document} highlight={highlight} diff --git a/plugins/catalog/src/components/CatalogSearchResultListItem/CatalogSearchResultListItem.tsx b/plugins/catalog/src/components/CatalogSearchResultListItem/CatalogSearchResultListItem.tsx index 5ba9d09949..993e34fbf6 100644 --- a/plugins/catalog/src/components/CatalogSearchResultListItem/CatalogSearchResultListItem.tsx +++ b/plugins/catalog/src/components/CatalogSearchResultListItem/CatalogSearchResultListItem.tsx @@ -14,12 +14,13 @@ * limitations under the License. */ -import React from 'react'; +import React, { ReactNode } from 'react'; import { Box, Chip, Divider, ListItem, + ListItemIcon, ListItemText, makeStyles, } from '@material-ui/core'; @@ -47,6 +48,7 @@ const useStyles = makeStyles({ * @public */ export interface CatalogSearchResultListItemProps { + icon?: ReactNode; result: IndexableDocument; highlight?: ResultHighlight; } @@ -60,39 +62,44 @@ export function CatalogSearchResultListItem( const classes = useStyles(); return ( - - - ) : ( - result.title - ) - } - secondary={ - props.highlight?.fields.text ? ( - - ) : ( - result.text - ) - } - /> - - {result.kind && } - {result.lifecycle && ( - - )} - + + {props.icon && {props.icon}} +
+ + ) : ( + result.title + ) + } + secondary={ + props.highlight?.fields.text ? ( + + ) : ( + result.text + ) + } + /> + + {result.kind && ( + + )} + {result.lifecycle && ( + + )} + +
diff --git a/plugins/techdocs/src/search/components/TechDocsSearchResultListItem.tsx b/plugins/techdocs/src/search/components/TechDocsSearchResultListItem.tsx index 6181e05235..9843443c7a 100644 --- a/plugins/techdocs/src/search/components/TechDocsSearchResultListItem.tsx +++ b/plugins/techdocs/src/search/components/TechDocsSearchResultListItem.tsx @@ -14,8 +14,14 @@ * limitations under the License. */ -import React, { PropsWithChildren } from 'react'; -import { Divider, ListItem, ListItemText, makeStyles } from '@material-ui/core'; +import React, { PropsWithChildren, ReactNode } from 'react'; +import { + Divider, + ListItem, + ListItemIcon, + ListItemText, + makeStyles, +} from '@material-ui/core'; import { Link } from '@backstage/core-components'; import { ResultHighlight } from '@backstage/plugin-search-common'; import { HighlightedSearchResultText } from '@backstage/plugin-search-react'; @@ -36,6 +42,7 @@ const useStyles = makeStyles({ * @public */ export type TechDocsSearchResultListItemProps = { + icon?: ReactNode; result: any; highlight?: ResultHighlight; lineClamp?: number; @@ -59,6 +66,7 @@ export const TechDocsSearchResultListItem = ( asListItem = true, asLink = true, title, + icon, } = props; const classes = useStyles(); const TextItem = () => { @@ -135,8 +143,9 @@ export const TechDocsSearchResultListItem = ( const ListItemWrapper = ({ children }: PropsWithChildren<{}>) => asListItem ? ( <> - - {children} + + {icon && {icon}} +
{children}
From fe7614ea54f2253fafd88483c36db1371bebfd24 Mon Sep 17 00:00:00 2001 From: Leon Date: Thu, 12 May 2022 14:01:54 +0200 Subject: [PATCH 2/4] changeset Signed-off-by: Leon --- .changeset/big-bears-fold.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/big-bears-fold.md diff --git a/.changeset/big-bears-fold.md b/.changeset/big-bears-fold.md new file mode 100644 index 0000000000..ab654729fa --- /dev/null +++ b/.changeset/big-bears-fold.md @@ -0,0 +1,7 @@ +--- +'example-app': minor +'@backstage/plugin-catalog': minor +'@backstage/plugin-techdocs': minor +--- + +Add an optional icon to the Catalog and TechDocs search results From 7fd90bf916a4ebc5193a23bb2338743f9093aa67 Mon Sep 17 00:00:00 2001 From: Leon Date: Thu, 12 May 2022 14:54:40 +0200 Subject: [PATCH 3/4] api-report update Signed-off-by: Leon --- plugins/catalog/api-report.md | 2 ++ plugins/techdocs/api-report.md | 1 + 2 files changed, 3 insertions(+) diff --git a/plugins/catalog/api-report.md b/plugins/catalog/api-report.md index 556016941a..268287e34e 100644 --- a/plugins/catalog/api-report.md +++ b/plugins/catalog/api-report.md @@ -112,6 +112,8 @@ export interface CatalogSearchResultListItemProps { // (undocumented) highlight?: ResultHighlight; // (undocumented) + icon?: ReactNode; + // (undocumented) result: IndexableDocument; } diff --git a/plugins/techdocs/api-report.md b/plugins/techdocs/api-report.md index a8204bc9af..b5f471ae50 100644 --- a/plugins/techdocs/api-report.md +++ b/plugins/techdocs/api-report.md @@ -388,6 +388,7 @@ export const TechDocsSearchResultListItem: ( // @public export type TechDocsSearchResultListItemProps = { + icon?: ReactNode; result: any; highlight?: ResultHighlight; lineClamp?: number; From b046466e3c6c1f0936b072aae2a23021fd921207 Mon Sep 17 00:00:00 2001 From: Leon Date: Thu, 12 May 2022 15:06:22 +0200 Subject: [PATCH 4/4] remove example-app from changeset Signed-off-by: Leon --- .changeset/big-bears-fold.md | 1 - 1 file changed, 1 deletion(-) diff --git a/.changeset/big-bears-fold.md b/.changeset/big-bears-fold.md index ab654729fa..b3bf51787a 100644 --- a/.changeset/big-bears-fold.md +++ b/.changeset/big-bears-fold.md @@ -1,5 +1,4 @@ --- -'example-app': minor '@backstage/plugin-catalog': minor '@backstage/plugin-techdocs': minor ---