Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
315 additions
and
39 deletions.
There are no files selected for viewing
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
38 changes: 38 additions & 0 deletions
38
src/components/search/filters/facet-filter/CheckboxFilter.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,38 @@ | ||
import * as React from "react"; | ||
|
||
import { FacetAccessor} from '../../../../core' | ||
import { ItemList} from "../../../ui" | ||
import { FacetFilter} from "./FacetFilter" | ||
|
||
const defaults = require("lodash/defaults") | ||
const map = require("lodash/map") | ||
const concat = require("lodash/concat") | ||
const assign = require("lodash/assign") | ||
|
||
import {FacetFilterProps, FacetFilterPropTypes} from "./FacetFilterProps" | ||
|
||
export interface CheckboxFilterProps extends FacetFilterProps{ | ||
value:string | ||
} | ||
export class CheckboxFilter extends FacetFilter<CheckboxFilterProps> { | ||
|
||
static propTypes = defaults({ | ||
value:React.PropTypes.string.isRequired | ||
},FacetFilterPropTypes.propTypes) | ||
|
||
static defaultProps = defaults({ | ||
size:1, | ||
showMore:false | ||
}, FacetFilter.defaultProps) | ||
|
||
getAccessorOptions(){ | ||
let options = super.getAccessorOptions() | ||
return assign(options, {include:[this.props.value]}) | ||
} | ||
|
||
getItems(){ | ||
let key = this.props.value | ||
return [this.accessor.getBuckets()[0] || {key, doc_count:0}] | ||
} | ||
|
||
} |
127 changes: 127 additions & 0 deletions
127
src/components/search/filters/facet-filter/FacetFilter.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,127 @@ | ||
import * as React from "react"; | ||
|
||
import {FacetFilterProps, FacetFilterPropTypes} from "./FacetFilterProps" | ||
|
||
import { | ||
FacetAccessor, SearchkitComponent, ISizeOption, | ||
FastClick | ||
} from "../../../../core" | ||
|
||
import { | ||
CheckboxItemList, Panel | ||
} from "../../../ui" | ||
|
||
const defaults = require("lodash/defaults") | ||
|
||
export class FacetFilter<T extends FacetFilterProps> extends SearchkitComponent<T, any> { | ||
accessor: FacetAccessor | ||
|
||
static propTypes = FacetFilterPropTypes | ||
|
||
static defaultProps = { | ||
listComponent: CheckboxItemList, | ||
containerComponent: Panel, | ||
size: 50, | ||
collapsable: false, | ||
showCount: true, | ||
showMore: true | ||
} | ||
|
||
constructor(props){ | ||
super(props) | ||
this.toggleViewMoreOption = this.toggleViewMoreOption.bind(this) | ||
} | ||
getAccessorOptions(){ | ||
const { | ||
field, id, operator, title, include, exclude, | ||
size, translations, orderKey, orderDirection | ||
} = this.props | ||
return { | ||
id, operator, title, size, include, exclude, | ||
translations, orderKey, orderDirection | ||
} | ||
} | ||
defineAccessor() { | ||
return new FacetAccessor( | ||
this.props.field, this.getAccessorOptions()) | ||
} | ||
|
||
defineBEMBlocks() { | ||
var blockName = this.props.mod || "sk-refinement-list" | ||
return { | ||
container: blockName, | ||
option: `${blockName}-option` | ||
} | ||
} | ||
|
||
componentDidUpdate(prevProps) { | ||
if (prevProps.operator != this.props.operator) { | ||
this.accessor.options.operator = this.props.operator | ||
this.searchkit.performSearch() | ||
} | ||
} | ||
|
||
toggleFilter(key) { | ||
this.accessor.state = this.accessor.state.toggle(key) | ||
this.searchkit.performSearch() | ||
} | ||
|
||
setFilters(keys) { | ||
this.accessor.state = this.accessor.state.setValue(keys) | ||
this.searchkit.performSearch() | ||
} | ||
|
||
toggleViewMoreOption(option: ISizeOption) { | ||
this.accessor.setViewMoreOption(option); | ||
this.searchkit.performSearch() | ||
} | ||
|
||
hasOptions(): boolean { | ||
return this.accessor.getBuckets().length != 0 | ||
} | ||
|
||
getSelectedItems(){ | ||
return this.accessor.state.getValue() | ||
} | ||
|
||
getItems(){ | ||
return this.accessor.getBuckets() | ||
} | ||
|
||
render() { | ||
const { listComponent, containerComponent, showCount, title, id, collapsable } = this.props | ||
return React.createElement(containerComponent, { | ||
title, | ||
className: id ? `filter--${id}` : undefined, | ||
disabled: !this.hasOptions(), | ||
collapsable | ||
}, [ | ||
React.createElement(listComponent, { | ||
key:"listComponent", | ||
items: this.getItems(), | ||
selectedItems: this.getSelectedItems(), | ||
toggleItem: this.toggleFilter.bind(this), | ||
setItems: this.setFilters.bind(this), | ||
showCount, | ||
translate:this.translate | ||
}), | ||
this.renderShowMore() | ||
]); | ||
} | ||
|
||
renderShowMore() { | ||
const option = this.accessor.getMoreSizeOption() | ||
|
||
if (!option || !this.props.showMore) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<FastClick handler={() => this.toggleViewMoreOption(option) } key="showMore"> | ||
<div data-qa="show-more" className={this.bemBlocks.container("view-more-action") }> | ||
{this.translate(option.label) } | ||
</div> | ||
</FastClick> | ||
) | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/components/search/filters/facet-filter/FacetFilterProps.ts
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,51 @@ | ||
import * as React from "react"; | ||
|
||
import { | ||
ReactComponentType, SearchkitComponentProps, | ||
SearchkitComponent, FacetAccessor | ||
} from "../../../../core" | ||
|
||
import { | ||
ItemProps, ListProps | ||
} from "../../../" | ||
|
||
const defaults = require("lodash/defaults") | ||
export interface FacetFilterProps extends SearchkitComponentProps { | ||
field: string | ||
operator?: string | ||
size?: number | ||
title: string | ||
id: string | ||
containerComponent?: ReactComponentType<any> | ||
itemComponent?: ReactComponentType<ItemProps> | ||
listComponent?: ReactComponentType<ListProps> | ||
orderKey?: string | ||
orderDirection?: string | ||
include?: Array<string> | string | ||
exclude?: Array<string> | string | ||
collapsable?: boolean | ||
showCount?: boolean | ||
showMore?:boolean | ||
} | ||
|
||
export const FacetFilterPropTypes = defaults({ | ||
field: React.PropTypes.string.isRequired, | ||
operator: React.PropTypes.oneOf(["AND", "OR"]), | ||
size: React.PropTypes.number, | ||
title: React.PropTypes.string.isRequired, | ||
id: React.PropTypes.string.isRequired, | ||
translations: SearchkitComponent.translationsPropType( | ||
FacetAccessor.translations | ||
), | ||
orderKey: React.PropTypes.string, | ||
orderDirection: React.PropTypes.oneOf(["asc", "desc"]), | ||
include: React.PropTypes.oneOfType([ | ||
React.PropTypes.string, React.PropTypes.array | ||
]), | ||
exclude: React.PropTypes.oneOfType([ | ||
React.PropTypes.string, React.PropTypes.array | ||
]), | ||
collapsable: React.PropTypes.bool, | ||
showCount: React.PropTypes.bool, | ||
showMore: React.PropTypes.bool | ||
},SearchkitComponent.propTypes) |
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,48 @@ | ||
import * as React from "react"; | ||
|
||
import { ItemList } from '../../../../' | ||
import { FacetFilter} from "./FacetFilter" | ||
|
||
const defaults = require("lodash/defaults") | ||
const map = require("lodash/map") | ||
const concat = require("lodash/concat") | ||
|
||
import {FacetFilterProps, FacetFilterPropTypes} from "./FacetFilterProps" | ||
|
||
export class MenuFilter2 extends FacetFilter<FacetFilterProps> { | ||
|
||
static propTypes = defaults({ | ||
},FacetFilterPropTypes.propTypes) | ||
|
||
static defaultProps = defaults({ | ||
listComponent: ItemList, | ||
operator:"OR" | ||
}, FacetFilter.defaultProps) | ||
|
||
static AllItem = { | ||
key:"All" | ||
} | ||
|
||
toggleFilter(option) { | ||
if (option === MenuFilter2.AllItem.key || this.accessor.state.contains(option)){ | ||
this.accessor.state = this.accessor.state.clear() | ||
} else { | ||
this.accessor.state = this.accessor.state.setValue([option]); | ||
} | ||
this.searchkit.performSearch() | ||
} | ||
|
||
setFilters(options){ | ||
this.toggleFilter(options[0]) | ||
} | ||
|
||
getSelectedItems() { | ||
return [this.accessor.state.getValue()[0] || MenuFilter2.AllItem.key] | ||
} | ||
|
||
getItems(){ | ||
return concat(this.accessor.getBuckets(), MenuFilter2.AllItem) | ||
} | ||
|
||
|
||
} |
6 changes: 6 additions & 0 deletions
6
src/components/search/filters/facet-filter/RefinementListFilter.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,6 @@ | ||
import {FacetFilter} from "./FacetFilter" | ||
import {FacetFilterProps, FacetFilterPropTypes} from "./FacetFilterProps" | ||
|
||
export class RefinementListFilter2 extends FacetFilter<FacetFilterProps> { | ||
|
||
} |
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,3 @@ | ||
export * from "./CheckboxFilter" | ||
export * from "./MenuFilter" | ||
export * from "./RefinementListFilter" |
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
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
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.