Skip to content

Commit

Permalink
[TEAMMATES#11302] Increase search result limit with message prompt wh…
Browse files Browse the repository at this point in the history
…en limit is reached (TEAMMATES#11324)

* Increase search result limit with message prompt when limit is reached

* Fix linting errors

* Update snapshots to match UI changes

* Reduce if-statement nesting

* Fix linting issues

* Fix typo in message prompt

* Shift query size value to backend and show individual prompts for instructor and student search

* Fix linting errors

* Rename query size limit constant

* Clean up code to reduce repetition

* Update failing snapshots for admin search page

* Clean up code for search limit message
  • Loading branch information
tjtanjin authored Nov 4, 2021
1 parent fb9c5d5 commit edc10ac
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/main/java/teammates/common/util/Const.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public final class Const {
public static final Duration FEEDBACK_SESSIONS_SEARCH_WINDOW = Duration.ofDays(30);
public static final Duration LOGS_RETENTION_PERIOD = Duration.ofDays(30);

public static final int SEARCH_QUERY_SIZE_LIMIT = 50;

// These constants are used as variable values to mean that the variable is in a 'special' state.

public static final int INT_UNINITIALIZED = -9999;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/teammates/storage/search/SearchManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import teammates.common.datatransfer.attributes.EntityAttributes;
import teammates.common.exception.SearchServiceException;
import teammates.common.util.Config;
import teammates.common.util.Const;
import teammates.common.util.Logger;
import teammates.common.util.StringHelper;

Expand All @@ -43,7 +44,7 @@ abstract class SearchManager<T extends EntityAttributes<?>> {
"Failed to reset collections. Root cause: %s ";

private static final int START_INDEX = 0;
private static final int NUM_OF_RESULTS = 20;
private static final int NUM_OF_RESULTS = Const.SEARCH_QUERY_SIZE_LIMIT;

private final HttpSolrClient client;
private final boolean isResetAllowed;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/teammates/ui/constants/ApiConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public enum ApiConst {
RANK_OPTIONS_ANSWER_NOT_SUBMITTED(Const.POINTS_NOT_SUBMITTED),
RANK_RECIPIENTS_ANSWER_NOT_SUBMITTED(Const.POINTS_NOT_SUBMITTED),
NO_VALUE(Const.POINTS_NO_VALUE),
LOGS_RETENTION_PERIOD(Const.LOGS_RETENTION_PERIOD.toDays());
LOGS_RETENTION_PERIOD(Const.LOGS_RETENTION_PERIOD.toDays()),
SEARCH_QUERY_SIZE_LIMIT(Const.SEARCH_QUERY_SIZE_LIMIT);
// CHECKSTYLE.ON:JavadocVariable

private final Object value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import { SimpleModalService } from '../../../services/simple-modal.service';
import { StatusMessageService } from '../../../services/status-message.service';
import { StudentService } from '../../../services/student.service';
import { ApiConst } from '../../../types/api-const';
import { Email, RegenerateKey } from '../../../types/api-output';
import { SimpleModalType } from '../../components/simple-modal/simple-modal-type';
import { collapseAnim } from '../../components/teammates-common/collapse-anim';
Expand Down Expand Up @@ -61,12 +62,28 @@ export class AdminSearchPageComponent {
this.statusMessageService.showWarningToast('No results found.');
this.instructors = [];
this.students = [];
} else {
this.instructors = resp.instructors;
this.students = resp.students;
this.hideAllInstructorsLinks();
this.hideAllStudentsLinks();
return;
}

this.instructors = resp.instructors;
this.students = resp.students;
this.hideAllInstructorsLinks();
this.hideAllStudentsLinks();

// prompt user to use more specific terms if search results limit reached
const limit: number = ApiConst.SEARCH_QUERY_SIZE_LIMIT;
const limitsReached: string[] = [];
if (this.students.length >= limit) {
limitsReached.push(`${limit} student results`);
}
if (this.instructors.length >= limit) {
limitsReached.push(`${limit} instructor results`);
}
if (limitsReached.length) {
this.statusMessageService.showWarningToast(`${limitsReached.join(' and ')} have been shown on this page
but there may be more results not shown. Consider searching with more specific terms.`);
}

}, (resp: ErrorMessageOutput) => {
this.instructors = [];
this.students = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { finalize, map, mergeMap } from 'rxjs/operators';
import { CourseService } from '../../../services/course.service';
import { InstructorSearchResult, SearchService } from '../../../services/search.service';
import { StatusMessageService } from '../../../services/status-message.service';
import { ApiConst } from '../../../types/api-const';
import {
InstructorPrivilege,
Student,
Expand Down Expand Up @@ -64,6 +65,10 @@ export class InstructorSearchPageComponent implements OnInit {

if (hasStudents) {
this.studentsListRowTables = searchStudentsTable;
if (searchStudentsTable.length >= ApiConst.SEARCH_QUERY_SIZE_LIMIT) {
this.statusMessageService.showWarningToast(`${ApiConst.SEARCH_QUERY_SIZE_LIMIT} results have been shown on this page
but there may be more results not shown. Consider searching with more specific terms.`);
}
} else {
this.studentsListRowTables = [];
}
Expand Down

0 comments on commit edc10ac

Please sign in to comment.