Merge pull request #3687 from jrsupplee/issue-1667

Fix bug in My Cards and Global Search
This commit is contained in:
Lauri Ojansivu 2021-03-31 14:21:48 +03:00 committed by GitHub
commit 04a8d85836
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 20 deletions

View file

@ -96,7 +96,7 @@ class GlobalSearchComponent extends CardSearchPagedComponent {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
// console.log('params:', query.getParams()); // console.log('params:', query.getParams());
this.queryParams = query.getParams(); this.queryParams = query.getQueryParams().getParams();
if (query.hasErrors()) { if (query.hasErrors()) {
this.searching.set(false); this.searching.set(false);
@ -106,7 +106,7 @@ class GlobalSearchComponent extends CardSearchPagedComponent {
return; return;
} }
this.runGlobalSearch(query.getParams()); this.runGlobalSearch(query.getQueryParams());
} }
searchInstructions() { searchInstructions() {

View file

@ -99,13 +99,14 @@ export class CardSearchPagedComponent extends BlazeComponent {
} }
} }
runGlobalSearch(params) { runGlobalSearch(queryParams) {
this.searching.set(true); this.searching.set(true);
this.stopSubscription(); this.stopSubscription();
this.subscriptionHandle = Meteor.subscribe( this.subscriptionHandle = Meteor.subscribe(
'globalSearch', 'globalSearch',
this.sessionId, this.sessionId,
params, queryParams.params,
queryParams.text,
this.subscriptionCallbacks, this.subscriptionCallbacks,
); );
} }

View file

@ -45,12 +45,15 @@ import moment from 'moment';
export class QueryParams { export class QueryParams {
text = ''; text = '';
constructor(params = {}) { constructor(params = {}, text = '') {
this.params = params; this.params = params;
this.text = text;
} }
hasOperator(operator) { hasOperator(operator) {
return this.params[operator]; return (
this.params[operator] !== undefined && this.params[operator].length > 0
);
} }
addPredicate(operator, predicate) { addPredicate(operator, predicate) {
@ -189,8 +192,8 @@ export class Query {
return this._errors.errorMessages(); return this._errors.errorMessages();
} }
getParams() { getQueryParams() {
return this.queryParams.getParams(); return this.queryParams;
} }
addPredicate(operator, predicate) { addPredicate(operator, predicate) {

View file

@ -80,14 +80,15 @@ Meteor.publish('myCards', function(sessionId) {
// return buildQuery(sessionId, queryParams); // return buildQuery(sessionId, queryParams);
// }); // });
Meteor.publish('globalSearch', function(sessionId, params) { Meteor.publish('globalSearch', function(sessionId, params, text) {
check(sessionId, String); check(sessionId, String);
check(params, Object); check(params, Object);
check(text, String);
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
// console.log('queryParams:', params); // console.log('queryParams:', params);
return findCards(sessionId, buildQuery(new QueryParams(params))); return findCards(sessionId, buildQuery(new QueryParams(params, text)));
}); });
function buildSelector(queryParams) { function buildSelector(queryParams) {
@ -97,6 +98,9 @@ function buildSelector(queryParams) {
let selector = {}; let selector = {};
// eslint-disable-next-line no-console
// console.log('queryParams:', queryParams);
if (queryParams.selector) { if (queryParams.selector) {
selector = queryParams.selector; selector = queryParams.selector;
} else { } else {
@ -249,17 +253,13 @@ function buildSelector(queryParams) {
queryUsers[OPERATOR_MEMBER] = []; queryUsers[OPERATOR_MEMBER] = [];
if (queryParams.hasOperator(OPERATOR_USER)) { if (queryParams.hasOperator(OPERATOR_USER)) {
queryParams.getPredicates(OPERATOR_USER).forEach(query => { queryParams.getPredicates(OPERATOR_USER).forEach(username => {
const users = Users.find({ const user = Users.findOne({ username });
username: query, if (user) {
}); queryUsers[OPERATOR_MEMBER].push(user._id);
if (users.count()) { queryUsers[OPERATOR_ASSIGNEE].push(user._id);
users.forEach(user => {
queryUsers[OPERATOR_MEMBER].push(user._id);
queryUsers[OPERATOR_ASSIGNEE].push(user._id);
});
} else { } else {
errors.addNotFound(OPERATOR_USER, query); errors.addNotFound(OPERATOR_USER, username);
} }
}); });
} }