-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #498 from mlibrary/LIBSEARCH-801-part-3
[LIBSEARCH-801] Implement "clear active filters" designs for advanced search (Part 3)
- Loading branch information
Showing
11 changed files
with
248 additions
and
258 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
src/modules/advanced/components/ActiveAdvancedFilters/index.js
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,74 @@ | ||
import './styles.css'; | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
const ActiveAdvancedFilters = ({ activeFilters, filters }) => { | ||
// Remove properties that have undefined values | ||
Object.keys(activeFilters).forEach((option) => { | ||
if (!activeFilters[option]) { | ||
delete activeFilters[option]; | ||
} | ||
}); | ||
|
||
const filterGroups = {}; | ||
filters.forEach((filterGroup) => { | ||
filterGroups[filterGroup.uid] = { ...filterGroup }; | ||
}); | ||
|
||
const items = Object.keys(activeFilters).reduce((acc, group) => { | ||
// Just don't show the checkbox filters as active filter items. | ||
if (!filterGroups[group] || filterGroups[group].type !== 'checkbox') { | ||
const activeFiltersToAdd = activeFilters[group].map((value) => { | ||
return { group, value }; | ||
}); | ||
return [...acc, ...activeFiltersToAdd]; | ||
} | ||
return acc; | ||
}, []); | ||
|
||
if (!items.length) { | ||
return null; | ||
} | ||
|
||
const titleCase = (string) => { | ||
return string.toLowerCase().split('_').map((word) => { | ||
return word.replace(word[0], word[0].toUpperCase()); | ||
}).join(' '); | ||
}; | ||
|
||
return ( | ||
<section aria-label='active-filters'> | ||
<h2 | ||
id='active-filters' | ||
className='u-margin-top-none margin-bottom__xs h4' | ||
> | ||
Active filters | ||
{' '} | ||
<span className='text-grey__light padding-right__xs'> | ||
({items.length}) | ||
</span> | ||
</h2> | ||
|
||
<p className='font-small u-margin-top-none'> | ||
Unselect active filters through the options below. | ||
</p> | ||
|
||
<ul className='margin-top__none active-filter-list'> | ||
{items.map((item, index) => { | ||
return ( | ||
<li key={index + item.group + item.value}> | ||
<span className='strong'>{filterGroups[item.group]?.name || titleCase(item.group)}:</span> {item.value} | ||
</li> | ||
); | ||
})} | ||
</ul> | ||
</section> | ||
); | ||
}; | ||
|
||
ActiveAdvancedFilters.propTypes = { | ||
activeFilters: PropTypes.object, | ||
filters: PropTypes.array | ||
}; | ||
|
||
export default ActiveAdvancedFilters; |
File renamed without changes.
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
15 changes: 15 additions & 0 deletions
15
src/modules/advanced/components/AdvancedSearchSubmit/index.js
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,15 @@ | ||
import { Icon } from '../../../reusable'; | ||
import React from 'react'; | ||
|
||
const AdvancedSearchSubmit = () => { | ||
return ( | ||
<button | ||
className='btn btn--primary margin-top__m' | ||
type='submit' | ||
> | ||
<Icon icon='search' size={24} /> Advanced Search | ||
</button> | ||
); | ||
}; | ||
|
||
export default AdvancedSearchSubmit; |
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
Oops, something went wrong.