Skip to content

Commit

Permalink
Merge pull request #192 from searchkit/container-component-fix
Browse files Browse the repository at this point in the history
Fix containerComponent props for CheckboxFilter and InputFilter
  • Loading branch information
ssetem committed Mar 24, 2016
2 parents 8a30cdb + dd5d041 commit b3fbdea
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
12 changes: 5 additions & 7 deletions src/components/search/filters/checkbox-filter/CheckboxFilter.tsx
Expand Up @@ -4,7 +4,8 @@ import {
SearchkitComponent,
SearchkitComponentProps,
CheckboxFilterAccessor,
ReactComponentType
ReactComponentType,
renderComponent
} from "../../../../core";

import {
Expand All @@ -21,7 +22,6 @@ export interface CheckboxFilterProps extends SearchkitComponentProps {
label: string
containerComponent?: ReactComponentType<any>
listComponent?: ReactComponentType<any>
collapsable?: boolean
showCount?: boolean
}

Expand All @@ -36,7 +36,6 @@ export class CheckboxFilter extends SearchkitComponent<CheckboxFilterProps, any>
translations: SearchkitComponent.translationsPropType(
CheckboxFilterAccessor.translations
),
collapsable: React.PropTypes.bool,
showCount: React.PropTypes.bool,
}, SearchkitComponent.propTypes)

Expand Down Expand Up @@ -78,14 +77,13 @@ export class CheckboxFilter extends SearchkitComponent<CheckboxFilterProps, any>
}

render() {
const { listComponent, containerComponent, showCount, title, id, collapsable, label } = this.props
const { listComponent, containerComponent, showCount, title, id, label } = this.props


return React.createElement(containerComponent, {
return renderComponent(containerComponent, {
title,
className: id ? `filter--${id}` : undefined,
disabled: false,
collapsable
disabled: false
},
React.createElement(listComponent, {
items: [{ key: label, doc_count: this.accessor.getDocCount() }],
Expand Down
11 changes: 5 additions & 6 deletions src/components/search/filters/input-filter/InputFilter.tsx
Expand Up @@ -4,7 +4,8 @@ import {
QueryAccessor,
SearchkitComponent,
SearchkitComponentProps,
ReactComponentType
ReactComponentType,
renderComponent
} from "../../../../core";

import { SearchBox } from "../../search-box/src/SearchBox"
Expand All @@ -28,7 +29,6 @@ export interface InputFilterProps extends SearchkitComponentProps {
queryOptions?:any
placeholder?: string
containerComponent?: ReactComponentType<any>
collapsable?: boolean
}

export class InputFilter extends SearchkitComponent<InputFilterProps, any> {
Expand Down Expand Up @@ -132,14 +132,13 @@ export class InputFilter extends SearchkitComponent<InputFilterProps, any> {
}

render() {
const { containerComponent, title, id, collapsable } = this.props
const { containerComponent, title, id } = this.props
const block = this.bemBlocks.container
const value = this.getValue()
return React.createElement(containerComponent, {
return renderComponent(containerComponent, {
title,
className: id ? `filter--${id}` : undefined,
disabled: (this.searchkit.getHitsCount() == 0) && (this.getValue() == ""),
collapsable
disabled: (this.searchkit.getHitsCount() == 0) && (this.getValue() == "")
},
<div className={block().state({focused:this.state.focused})}>
<form onSubmit={this.onSubmit.bind(this)}>
Expand Down
10 changes: 10 additions & 0 deletions src/components/search/filters/input-filter/InputFilter.unit.tsx
Expand Up @@ -7,6 +7,10 @@ import {
fastClick, hasClass, jsxToHTML, printPrettyHtml
} from "../../../__test__/TestHelpers"

import {
Panel
} from "../../../ui"

import * as sinon from "sinon";

describe("Searchbox tests", () => {
Expand Down Expand Up @@ -211,7 +215,13 @@ describe("Searchbox tests", () => {
prefixQueryFields:["prefix"],
"queryOptions": {}
})
})

it("should accept Panel elements as containerComponent", ()=> {
this.createWrapper(true, ["title"], ["prefix"], {
containerComponent: <Panel collapsable={true} />
})
expect(hasClass(this.wrapper.find(".sk-panel__header"), "is-collapsable")).toBe(true)
})


Expand Down
Expand Up @@ -38,7 +38,6 @@ export interface RangeFilterProps extends SearchkitComponentProps {
showHistogram?:boolean
containerComponent?: RenderComponentType<any>
rangeComponent?: RenderComponentType<RangeProps>
collapsable?: boolean
}


Expand Down Expand Up @@ -113,7 +112,7 @@ export class RangeFilter extends SearchkitComponent<RangeFilterProps, any> {
}

render() {
const { id, title, containerComponent, collapsable } = this.props
const { id, title, containerComponent } = this.props

const maxValue = computeMaxValue(this.accessor.getBuckets(), "doc_count")

Expand Down

0 comments on commit b3fbdea

Please sign in to comment.