Skip to content

Commit

Permalink
EZP-31680: Added UDW Search language filter (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 authored Jun 19, 2020
1 parent 568e7a2 commit ce8decc
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class SearchComponent extends Component {
this.onRequireItemsCount = this.onRequireItemsCount.bind(this);
this.toggleSubmitButtonState = this.toggleSubmitButtonState.bind(this);
this.setSearchInputRef = this.setSearchInputRef.bind(this);
this.setSearchLanguageRef = this.setSearchLanguageRef.bind(this);
}

/**
Expand All @@ -37,6 +38,7 @@ export default class SearchComponent extends Component {
}

const searchText = this._refSearchInput.value;
const languageCode = this._refSearchLanguage.value;
const query = {
FullTextCriterion: searchText,
};
Expand All @@ -49,7 +51,7 @@ export default class SearchComponent extends Component {
() => ({ isSearching: true, lastSearchText: searchText }),
() => {
const promise = new Promise((resolve) =>
this.props.findContentBySearchQuery(this.props.restInfo, query, resolve, this.props.searchResultsLimit)
this.props.findContentBySearchQuery(this.props.restInfo, query, resolve, this.props.searchResultsLimit, languageCode)
);

promise
Expand Down Expand Up @@ -86,6 +88,32 @@ export default class SearchComponent extends Component {
}
}

/**
* Renders the language filter
*
* @method renderLanguageFilter
*/
renderLanguageFilter() {
const { languages } = this.props;
const selectAttrs = {
className: 'form-control',
ref: this.setSearchLanguageRef
};
const options = languages.priority.map((value) => {
const language = languages.mappings[value];

return <option value={language.languageCode}>{language.name}</option>;
});

return (
<div className="c-search__language-wrapper">
<select {...selectAttrs}>
{options}
</select>
</div>
);
}

/**
* Renders the submit button
*
Expand Down Expand Up @@ -136,6 +164,16 @@ export default class SearchComponent extends Component {
this._refSearchInput = ref;
}

/**
* Set a reference to the language filter HTMLElement node
*
* @method setSearchLanguageRef
* @param {HTMLElement} ref
*/
setSearchLanguageRef(ref) {
this._refSearchLanguage = ref;
}

renderSearchTips() {
const { items } = this.state;

Expand Down Expand Up @@ -200,7 +238,7 @@ export default class SearchComponent extends Component {
{ query: lastSearchText },
'search'
);

return (
<ContentTableComponent
items={items}
Expand Down Expand Up @@ -235,6 +273,7 @@ export default class SearchComponent extends Component {
onKeyUp={this.searchContent}
onChange={this.toggleSubmitButtonState}
/>
{this.renderLanguageFilter()}
{this.renderSubmitBtn()}
</div>
{this.renderResultsTable()}
Expand All @@ -261,4 +300,5 @@ SearchComponent.propTypes = {
onItemRemove: PropTypes.func.isRequired,
multiple: PropTypes.bool.isRequired,
allowedContentTypes: PropTypes.array.isRequired,
languages: PropTypes.object.isRequired,
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const SearchPanelComponent = (props) => {
canSelectContent,
allowedContentTypes,
onItemRemove,
languages,
} = props;
const searchAttrs = Object.assign(
{},
Expand All @@ -37,6 +38,7 @@ const SearchPanelComponent = (props) => {
canSelectContent,
allowedContentTypes,
onItemRemove,
languages,
}
);

Expand Down Expand Up @@ -71,6 +73,7 @@ SearchPanelComponent.propTypes = {
canSelectContent: PropTypes.func.isRequired,
onItemRemove: PropTypes.func.isRequired,
allowedContentTypes: PropTypes.array.isRequired,
languages: PropTypes.object.isRequired,
};

export default SearchPanelComponent;
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,15 @@ export const findLocationsByParentLocationId = (
* @param {Object} query Object containing query criterions
* @param {Function} callback
* @param {Number} limit
* @param {String} LanguageCode
*/
export const findContentBySearchQuery = ({ token, siteaccess }, query, callback, limit = QUERY_LIMIT) => {
export const findContentBySearchQuery = ({ token, siteaccess }, query, callback, limit = QUERY_LIMIT, languageCode = null) => {
const useAlwaysAvailable = true;
const body = JSON.stringify({
ViewInput: {
identifier: `udw-locations-by-search-query-${query.FullTextCriterion}`,
languageCode,
useAlwaysAvailable,
public: false,
LocationQuery: {
Criteria: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ export default class UniversalDiscoveryModule extends Component {
} = this.props;
const { userBookmarksItems, userBookmarksCount, contentTypesMap } = this.state;
const browsePanelConfig = { id: TAB_BROWSE, panel: FinderPanelComponent, attrs: { sortFieldMappings, sortOrderMappings } };
const searchPanelConfig = { id: TAB_SEARCH, panel: SearchPanelComponent };
const searchPanelConfig = { id: TAB_SEARCH, panel: SearchPanelComponent, attrs: { languages } };
const bookmarksPanelConfig = {
id: TAB_BOOKMARKS,
panel: BookmarksPanelComponent,
Expand Down

0 comments on commit ce8decc

Please # to comment.