fix(peopleSearch): queryTypes are defined in config.js

This commit is contained in:
hristoterezov 2017-08-30 14:34:42 -05:00 committed by yanas
parent 328da08b3a
commit cd3dad956b
2 changed files with 43 additions and 12 deletions

View File

@ -14,6 +14,8 @@ import { invitePeople, searchPeople } from '../functions';
declare var interfaceConfig: Object;
const { PropTypes } = React;
/**
* The dialog that allows to invite people to the call.
*/
@ -27,32 +29,37 @@ class AddPeopleDialog extends Component {
/**
* The URL pointing to the service allowing for people invite.
*/
_inviteServiceUrl: React.PropTypes.string,
_inviteServiceUrl: PropTypes.string,
/**
* The url of the conference to invite people to.
*/
_inviteUrl: React.PropTypes.string,
_inviteUrl: PropTypes.string,
/**
* The JWT token.
*/
_jwt: React.PropTypes.string,
_jwt: PropTypes.string,
/**
* The query types used when searching people.
*/
_peopleSearchQueryTypes: PropTypes.arrayOf(PropTypes.string),
/**
* The URL pointing to the service allowing for people search.
*/
_peopleSearchUrl: React.PropTypes.string,
_peopleSearchUrl: PropTypes.string,
/**
* The function closing the dialog.
*/
hideDialog: React.PropTypes.func,
hideDialog: PropTypes.func,
/**
* Invoked to obtain translated strings.
*/
t: React.PropTypes.func
t: PropTypes.func
};
/**
@ -84,8 +91,20 @@ class AddPeopleDialog extends Component {
this._multiselect = null;
this._resourceClient = {
makeQuery: text => searchPeople(
this.props._peopleSearchUrl, this.props._jwt, text),
makeQuery: text => {
const {
_jwt,
_peopleSearchQueryTypes,
_peopleSearchUrl
} = this.props;
return searchPeople(
_peopleSearchUrl,
_jwt,
text,
_peopleSearchQueryTypes
);
},
parseResults: response => response.map(user => {
const avatar = ( // eslint-disable-line no-extra-parens
<Avatar
@ -299,12 +318,17 @@ class AddPeopleDialog extends Component {
* }}
*/
function _mapStateToProps(state) {
const { peopleSearchUrl, inviteServiceUrl } = state['features/base/config'];
const {
inviteServiceUrl,
peopleSearchQueryTypes,
peopleSearchUrl
} = state['features/base/config'];
return {
_jwt: state['features/jwt'].jwt,
_inviteUrl: getInviteURL(state),
_inviteServiceUrl: inviteServiceUrl,
_peopleSearchQueryTypes: peopleSearchQueryTypes,
_peopleSearchUrl: peopleSearchUrl
};
}

View File

@ -6,14 +6,21 @@ declare var $: Function;
* @param {string} serviceUrl - The service to query.
* @param {string} jwt - The jwt token to pass to the search service.
* @param {string} text - Text to search.
* @param {Array<string>} queryTypes - Array with the query types that will be
* executed - "conferenceRooms" | "user" | "room".
* @returns {Promise} - The promise created by the request.
*/
export function searchPeople(serviceUrl, jwt, text) {
const queryTypes = '["conferenceRooms","user","room"]';
export function searchPeople(// eslint-disable-line max-params
serviceUrl,
jwt,
text,
queryTypes = [ 'conferenceRooms', 'user', 'room' ]
) {
const queryTypesString = JSON.stringify(queryTypes);
return new Promise((resolve, reject) => {
$.getJSON(`${serviceUrl}?query=${encodeURIComponent(text)}`
+ `&queryTypes=${queryTypes}&jwt=${jwt}`,
+ `&queryTypes=${queryTypesString}&jwt=${jwt}`,
response => resolve(response)
).fail((jqxhr, textStatus, error) =>
reject(error)