Skip to content
This repository has been archived by the owner on Jan 5, 2019. It is now read-only.

Commit

Permalink
store Blacklight results in app state (#108)
Browse files Browse the repository at this point in the history
馃憤
  • Loading branch information
adam malantonio authored and James R. Griffin III committed Jan 13, 2017
1 parent 3dab435 commit ebf22ee
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 152 deletions.
34 changes: 23 additions & 11 deletions lib/facet-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export function createFacetNameMap (arr, field) {
return out
}


export function getBreadcrumbList (pool, selected) {
const hasOwnProperty = Object.prototype.hasOwnProperty
let out = []

if (!selected)
Expand All @@ -23,31 +25,41 @@ export function getBreadcrumbList (pool, selected) {
if (!selKeys.length)
return out

// loop through the pool of potential facets
// (these are the responses returned w/ a search query)
for (let p = 0; p < pool.length; p++) {
if (!selKeys.length)
break

let group = pool[p]
const group = pool[p]

// loop through the keys of the selected facets
// and find our matching group (which should exist
// because it's part of our search)
for (let s = 0; s < selKeys.length; s++) {
let name = selKeys[s]
const name = selKeys[s]

if (group.name === name) {

// we're going to append our collection (`out`) with data
// for each of the selected facets. this will allow us to
// display a breadcrumb like 'Facet Group > Facet Value'
// using label values (for cleaner values) + retain the
// values used by the back-end
out = out.concat(selected[name].map(sk => {
const selVal = hasOwnProperty.call(sk, 'value') ? sk.value : sk
const selLabel = hasOwnProperty.call(sk, 'label') ? sk.label : sk
return {
group: {
name: pool[p].name,
label: pool[p].label
name: group.name,
label: group.label
},
facet: {
value: sk.value,
label: sk.label,
value: selVal,
label: selLabel,
}
}
}))

selKeys.splice(s, 1)
break
// selKeys.splice(s, 1)
// break
}
}
}
Expand Down
18 changes: 4 additions & 14 deletions src/actions/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ import {
SEARCHING,
} from '../constants'

const REQUIRED_OPTS = {
search_field: 'search',
}

const DEFAULT_OPTS = {
per_page: 10,
}

const hasOwnProperty = Object.prototype.hasOwnProperty

function conductSearch (dispatch, query, facets, options, queryString) {
Expand Down Expand Up @@ -57,7 +49,7 @@ function conductSearch (dispatch, query, facets, options, queryString) {

export const searchCatalog = (query, facets, opts) => dispatch => {
// save ourselves the hassle of keeping track of these defaults
const options = assign({}, REQUIRED_OPTS, opts)
const options = assign({}, opts)

if (!facets)
facets = {}
Expand Down Expand Up @@ -96,7 +88,7 @@ export const setSearchOption = (field, value) => (dispatch, getState) => {

const query = search.query || ''
const facets = assign({}, search.facets)
const options = assign({}, DEFAULT_OPTS, REQUIRED_OPTS, search.options)
const options = assign({}, search.options)

// we'll pass null to remove the option
if (value === null) {
Expand All @@ -114,11 +106,11 @@ export const toggleSearchFacet = (field, facet, checked) => (dispatch, getState)

// recycling the previous search info
const query = search.query || ''
const options = assign({}, DEFAULT_OPTS, REQUIRED_OPTS, search.options)
const options = assign({}, search.options)
const facets = assign({}, search.facets)

let dirty = false
let idx
let idx = -1

if (facets[field]) {
idx = findIndex(facets[field], f => {
Expand All @@ -129,8 +121,6 @@ export const toggleSearchFacet = (field, facet, checked) => (dispatch, getState)
})
}

else idx = -1

// add to selected-facets
if (checked) {
if (idx === -1) {
Expand Down
39 changes: 16 additions & 23 deletions src/components/catalog/SearchBreadcrumbTrail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@ const T = React.PropTypes
const SearchBreadcrumbTrail = React.createClass({
propTypes: {
onRemoveBreadcrumb: T.func.isRequired,
facets: T.object,

breadcrumbs: T.array,
query: T.string,
},

renderGroupBreadcrumbs: function (key) {
const group = this.props.facets[key]

return group.map((facet, index) => {
const props = {
key: key + index + facet.value,
group: key,
value: facet.label,
onRemove: this.props.onRemoveBreadcrumb.bind(null, key, facet),
}

return React.createElement(SearchBreadcrumb, props)
})
renderGroupBreadcrumbs: function (breadcrumb, index) {
const props = {
key: `bc${index}`,
group: breadcrumb.group.label,
value: breadcrumb.facet.label,
onRemove: this.props.onRemoveBreadcrumb.bind(null,
breadcrumb.group.name,
breadcrumb.facet,
),
}

return <SearchBreadcrumb {...props} />
},

renderQuery: function () {
Expand All @@ -40,19 +39,13 @@ const SearchBreadcrumbTrail = React.createClass({
},

render: function () {
if (!this.props.facets)
return null

const keys = Object.keys(this.props.facets)

if (!keys.length)
return null
const bc = this.props.breadcrumbs

return (
<div>
{this.renderQuery()}

{keys.map(this.renderGroupBreadcrumbs)}
{!!bc.length && bc.map(this.renderGroupBreadcrumbs)}
</div>
)
}
Expand Down

0 comments on commit ebf22ee

Please sign in to comment.