-
Notifications
You must be signed in to change notification settings - Fork 5
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
Filter connectors
better and make connector search page safer
#699
Changes from 9 commits
cc2be2d
6a27129
846abaa
9cb8e67
0767e8e
3d53bc8
987b1ae
ed2e00d
396d323
33ff29c
b228685
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import ChevronRight from '@mui/icons-material/ChevronRight'; | ||
import { graphql, Link, useStaticQuery } from 'gatsby'; | ||
import { graphql, useStaticQuery, Link } from 'gatsby'; | ||
import { GatsbyImage, StaticImage } from 'gatsby-plugin-image'; | ||
import { useMemo, useState } from 'react'; | ||
import { useLunr } from 'react-lunr'; | ||
|
@@ -65,48 +65,66 @@ const ConnectorCard = ({ | |
slug, | ||
type, | ||
showType = false, | ||
}: ReturnType<typeof normalizeConnector> & { showType?: boolean }) => ( | ||
<Link to={`${slug}`}> | ||
<div className={connectorCard}> | ||
<div className={connectorCardTop}> | ||
<GatsbyImage | ||
image={logo?.childImageSharp?.gatsbyImageData} | ||
alt={`${title} Logo`} | ||
className={clsx(connectorPostCardImage, 'icon-wrapper')} | ||
loading="eager" | ||
/> | ||
{recommended || showType ? ( | ||
<div style={{ flexGrow: 1 }} /> | ||
) : null} | ||
{recommended ? ( | ||
<div> | ||
<p className={connectorPostCardRecommended}> | ||
RECOMMENDED | ||
</p> | ||
</div> | ||
) : null} | ||
{showType ? ( | ||
<> | ||
{recommended ? <div style={{ flexBasis: 4 }} /> : null} | ||
}: ReturnType<typeof normalizeConnector> & { showType?: boolean }) => { | ||
return ( | ||
<Link to={`${slug}`}> | ||
<div className={connectorCard}> | ||
<div className={connectorCardTop}> | ||
{!logo?.childImageSharp?.gatsbyImageData ? ( | ||
<div | ||
className={clsx( | ||
connectorPostCardImage, | ||
'icon-wrapper' | ||
)} | ||
/> | ||
) : ( | ||
Comment on lines
+73
to
+80
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. This logo was 100% missing while running a quick search. So making this safer. Eventually we might want to add a placeholder or something while this is loading. |
||
<GatsbyImage | ||
image={logo.childImageSharp.gatsbyImageData} | ||
alt={`${title} Logo`} | ||
className={clsx( | ||
connectorPostCardImage, | ||
'icon-wrapper' | ||
)} | ||
loading="eager" | ||
/> | ||
)} | ||
{recommended || showType ? ( | ||
<div style={{ flexGrow: 1 }} /> | ||
) : null} | ||
{recommended ? ( | ||
<div> | ||
<p className={connectorPostCardRecommended}> | ||
{type === 'capture' ? 'SOURCE' : 'DESTINATION'} | ||
RECOMMENDED | ||
</p> | ||
</div> | ||
</> | ||
) : null} | ||
{showType ? ( | ||
<> | ||
{recommended ? ( | ||
<div style={{ flexBasis: 4 }} /> | ||
) : null} | ||
<div> | ||
<p className={connectorPostCardRecommended}> | ||
{type === 'capture' | ||
? 'SOURCE' | ||
: 'DESTINATION'} | ||
</p> | ||
</div> | ||
</> | ||
) : null} | ||
</div> | ||
<h4>{title}</h4> | ||
{shortDescription?.length > 0 ? ( | ||
<p>{truncate(shortDescription || '', 100)}</p> | ||
) : null} | ||
<div style={{ flexGrow: 1 }} /> | ||
<span className={connectorCardReadMore}> | ||
Read More <ChevronRight /> | ||
</span> | ||
</div> | ||
<h4>{title}</h4> | ||
{shortDescription?.length > 0 ? ( | ||
<p>{truncate(shortDescription || '', 100)}</p> | ||
) : null} | ||
<div style={{ flexGrow: 1 }} /> | ||
<span className={connectorCardReadMore}> | ||
Read More <ChevronRight /> | ||
</span> | ||
</div> | ||
</Link> | ||
); | ||
</Link> | ||
); | ||
}; | ||
|
||
export const Connectors = ({ | ||
connectorType, | ||
|
@@ -158,10 +176,6 @@ export const Connectors = ({ | |
const mappedConnectors = useMemo( | ||
() => | ||
postgres.allConnectors.nodes | ||
.filter( | ||
(connector) => | ||
connector?.connectorTagsByConnectorIdList?.length > 0 | ||
) | ||
.map(normalizeConnector) | ||
.filter( | ||
(connector) => | ||
|
@@ -193,14 +207,12 @@ export const Connectors = ({ | |
[postgres] | ||
); | ||
|
||
const logosByConnectorId = useMemo( | ||
() => | ||
Object.assign( | ||
{}, | ||
...mappedConnectors.map((con) => ({ [con.id]: con.logo })) | ||
), | ||
[mappedConnectors] | ||
); | ||
const logosByConnectorId = useMemo(() => { | ||
return Object.assign( | ||
{}, | ||
...mappedConnectors.map((con) => ({ [con.id]: con.logo })) | ||
); | ||
}, [mappedConnectors]); | ||
|
||
const [query, setQuery] = useState(''); | ||
const results = useLunr( | ||
|
@@ -240,14 +252,16 @@ export const Connectors = ({ | |
</div> | ||
<div className={connectorCards}> | ||
{(query.length > 0 ? results : mappedConnectors).map( | ||
(connector) => ( | ||
<ConnectorCard | ||
key={connector.id} | ||
{...connector} | ||
logo={logosByConnectorId[connector.id]} | ||
showType={showAllConnectors} | ||
/> | ||
) | ||
(connector) => { | ||
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. another explicit |
||
return ( | ||
<ConnectorCard | ||
key={connector.id} | ||
{...connector} | ||
logo={logosByConnectorId[connector.id]} | ||
showType={showAllConnectors} | ||
/> | ||
); | ||
} | ||
)} | ||
</div> | ||
</div> | ||
|
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. We now check this in |
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. This should never happen - but being safe |
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. We need to add all the filter into the normalizer so that things like search results do not get fed wrong connectors |
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.
This didn't change much but looks like it did because I added a explicit
return
.