-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Display collections in search results [PT-188117039]
Splits out collections from resources and displays them at the top of the page.
- Loading branch information
1 parent
a52d137
commit 664a439
Showing
5 changed files
with
128 additions
and
14 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
rails/react-components/src/library/components/collections.scss
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,22 @@ | ||
@import '../../shared/styles/variables/_variables.scss'; | ||
|
||
.finderResultsCollections { | ||
margin-bottom: 30px; | ||
|
||
.finderResultsCollectionsHeader { | ||
margin-bottom: 10px; | ||
|
||
.finderResultsCollectionsCount { | ||
display: flex; | ||
justify-content: space-between; | ||
} | ||
} | ||
|
||
.findResultsCollectionsShowMore { | ||
background: $col-orange; | ||
color: $white; | ||
padding: 5px 10px; | ||
display: inline-block; | ||
border-radius: 4px; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
rails/react-components/src/library/components/collections.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,60 @@ | ||
import React from "react"; | ||
import StemFinderResult from "./stem-finder-result"; | ||
import pluralize from "../helpers/pluralize"; | ||
|
||
import css from "./collections.scss"; | ||
|
||
interface Props { | ||
collections: any[] | ||
numTotalCollections: number; | ||
} | ||
|
||
interface State { | ||
displayCount: number | ||
} | ||
|
||
export default class Collections extends React.Component<Props, State> { | ||
constructor (props: Props) { | ||
super(props); | ||
|
||
this.state = { | ||
displayCount: Math.min(2, props.numTotalCollections) | ||
}; | ||
} | ||
|
||
UNSAFE_componentWillReceiveProps (nextProps: any) { | ||
this.setState((prev) => ({displayCount: Math.min(prev.displayCount, nextProps.numTotalCollections)})); | ||
} | ||
|
||
handleShowMore = () => { | ||
this.setState((prev) => ({displayCount: Math.min(prev.displayCount + 2, this.props.numTotalCollections)})); | ||
}; | ||
|
||
render () { | ||
const { displayCount } = this.state; | ||
const { collections, numTotalCollections } = this.props; | ||
const showingAll = displayCount >= numTotalCollections; | ||
const collectionCount = showingAll ? numTotalCollections : displayCount + " of " + numTotalCollections; | ||
|
||
const displayCollections = collections.slice(0, displayCount); | ||
|
||
return ( | ||
<div className={css.finderResultsCollections}> | ||
<div className={css.finderResultsCollectionsHeader}> | ||
<h2>Collections</h2> | ||
<div className={css.finderResultsCollectionsCount}> | ||
<div> | ||
Showing <strong>{ collectionCount + " " + pluralize(collectionCount, "Collection", "Collections") }</strong> matching your search | ||
</div> | ||
</div> | ||
</div> | ||
<div className={css.finderResultsContainer}> | ||
{ displayCollections.map((collection: any, index: any) => { | ||
return <StemFinderResult key={`${collection.external_url}-${index}`} resource={collection} index={index} opacity={1} />; | ||
}) } | ||
</div> | ||
{!showingAll && <button className={css.findResultsCollectionsShowMore} onClick={this.handleShowMore}>Show More</button>} | ||
</div> | ||
); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -230,7 +230,7 @@ | |
} | ||
} | ||
.previewLink { | ||
width: 130px; | ||
width: 140px; | ||
|
||
.previewLinkButton { | ||
background: #fff; | ||
|
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
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