Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Advancedsearch][FacetBox] missing assignment in Initial state #1395

Merged
merged 2 commits into from
Jul 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 38 additions & 34 deletions src/search/facet-box/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import React from 'react';
import builder from 'focus-core/component/builder';
import type from 'focus-core/component/types';
import {translate} from 'focus-core/translation';

let assign = require('object-assign');
let omit = require('lodash/object/omit');
import { translate } from 'focus-core/translation';
import assign from 'object-assign';
import omit from 'lodash/object/omit';

// Components
let Facet = require('./facet').component;

import { component as Facet } from './facet';
// Mixins
let stylable = require('../../mixin/stylable');
import stylable from '../../mixin/stylable';

let FacetBox = {
const FacetBox = {
/**
* Component's mixins
*/
Expand All @@ -25,7 +23,7 @@ let FacetBox = {
* Init the default properties
* @returns {object} Initial properties.
*/
getDefaultProps: function () {
getDefaultProps() {
return {
facetList: {},
selectedFacetList: {},
Expand All @@ -47,32 +45,30 @@ let FacetBox = {
* Init the state of the component.
* @returns {object} Iitial state.
*/
getInitialState: function () {
let openedFacetList = this.props.openedFacetList;
if (Object.keys(openedFacetList).length == 0) {
this._generateOpenedFacetList(this.props.facetList);
}
getInitialState() {
const openedFacetList = this._generateOpenedFacetList(this.props.openedFacetList, this.props.facetList);
return {
isExpanded: true,
openedFacetList
};
},
/**
* New properties set event handle
* @param {Object} nextProps
* @param {Object} nextProps nextProps
*/
componentWillReceiveProps(nextProps) {
let openedFacetList = nextProps.openedFacetList;
if (Object.keys(openedFacetList).length == 0) {
openedFacetList = this._generateOpenedFacetList(nextProps.facetList);
}
this.setState({openedFacetList});
const openedFacetList = this._generateOpenedFacetList(nextProps.openedFacetList, nextProps.facetList);
this.setState({ openedFacetList });
},
_generateOpenedFacetList(facetList) {
return Object.keys(facetList).reduce(function (list, facetKey) {
list[facetKey] = true;
return list;
}, {});
_generateOpenedFacetList(openedFacetList, facetList) {
if (openedFacetList.length === 0) {
return Object.keys(facetList).reduce((list, facetKey) => {
list[facetKey] = true;
return list;
}, {});
} else {
return openedFacetList;
}
},
/**
* Render the component.
Expand Down Expand Up @@ -100,7 +96,7 @@ let FacetBox = {
let title = this.state.isExpanded ? translate('live.filter.title') : '';
//TODO onClick={this._facetBoxTitleClickHandler} (le repli doit aussi etre porté par le data-focus=advanced-search
return (
<div data-focus="facet-box-heading" onClick={this._facetBoxTitleClickHandler}>
<div data-focus='facet-box-heading' onClick={this._facetBoxTitleClickHandler}>
<h2>{title}</h2>
</div>
);
Expand All @@ -114,7 +110,7 @@ let FacetBox = {
return '';
}
return (
<div data-focus="facet-box-body">
<div data-focus='facet-box-body'>
{Object.keys(this.props.facetList).map((facetKey) => {
let facet = this.props.facetList[facetKey];
let selectedDataKey = this.props.selectedFacetList[facetKey] ? this.props.selectedFacetList[facetKey].key : undefined;
Expand All @@ -127,18 +123,19 @@ let FacetBox = {
expandHandler={this._facetExpansionHandler}
selectHandler={this._facetSelectionHandler}
type={this.props.config[facetKey]}
/>
/>
);
}
})}
</div>);
</div>
);
},
/**
* Action on title click.
* Hide / Expand the component.
*/
_facetBoxTitleClickHandler() {
this.setState({isExpanded: !this.state.isExpanded});
this.setState({ isExpanded: !this.state.isExpanded });
},
/**
* Facet selection action handler.
Expand All @@ -147,11 +144,11 @@ let FacetBox = {
* @param {object} data Content of the selected data facet.
*/
_facetSelectionHandler(facetKey, dataKey, data) {
let result = {openedFacetList: this.state.openedFacetList};
let result = { openedFacetList: this.state.openedFacetList };
if (dataKey == undefined) {
result.selectedFacetList = omit(this.props.selectedFacetList, facetKey);
} else {
result.selectedFacetList = assign(this.props.selectedFacetList, {[facetKey]: {key: dataKey, data: data}});
result.selectedFacetList = assign(this.props.selectedFacetList, { [facetKey]: { key: dataKey, data: data } });
}
this.props.dataSelectionHandler(result);
},
Expand All @@ -163,8 +160,15 @@ let FacetBox = {
_facetExpansionHandler(facetKey, isExpanded) {
let openedFacetList = this.state.openedFacetList;
openedFacetList[facetKey] = isExpanded;
this.setState({openedFacetList: openedFacetList});
this.setState({ openedFacetList: openedFacetList });
}
};

module.exports = builder(FacetBox);
const builtComp = builder(FacetBox);
const { component, mixin } = builtComp;

export {
component,
mixin
}
export default builtComp;