Merge lp:~cjwatson/launchpad/picker-truncate-large-results into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18189
Proposed branch: lp:~cjwatson/launchpad/picker-truncate-large-results
Merge into: lp:launchpad
Diff against target: 94 lines (+26/-27)
2 files modified
lib/lp/app/javascript/picker/picker_patcher.js (+19/-20)
lib/lp/app/javascript/picker/tests/test_picker_patcher.js (+7/-7)
To merge this branch: bzr merge lp:~cjwatson/launchpad/picker-truncate-large-results
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+305528@code.launchpad.net

Commit message

Truncate large picker search results rather than refusing to display anything.

Description of the change

Truncate large picker search results rather than refusing to display anything.

It really doesn't make much sense to show nothing but an error message when we have at least some perfectly good results, especially now that the package picker is moving towards doing a better job at showing more relevant matches first.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) wrote :

wtf this was client-side all along?

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/app/javascript/picker/picker_patcher.js'
2--- lib/lp/app/javascript/picker/picker_patcher.js 2016-07-21 15:13:12 +0000
3+++ lib/lp/app/javascript/picker/picker_patcher.js 2016-09-12 19:55:47 +0000
4@@ -534,29 +534,28 @@
5 var display_vocabulary = function(results, total_size, start) {
6 var max_size = MAX_BATCHES * BATCH_SIZE;
7 if (show_search_box && total_size > max_size) {
8- picker.set('error',
9- 'Too many matches. Please try to narrow your search.');
10- // Display a single empty result item so that the picker
11- // doesn't say that no items matched, which is contradictory.
12- picker.set('results', [{}]);
13- picker.set('batches', []);
14- } else {
15- picker.set('results', results);
16+ picker.set(
17+ 'error',
18+ 'Only displaying first ' + max_size + ' of ' +
19+ total_size + ' matches.');
20+ results.length = max_size;
21+ total_size = max_size;
22+ }
23+ picker.set('results', results);
24
25- // Update the batches only if it's a new search.
26- if (e.details[1] === undefined) {
27- var batches = [];
28- var stop = Math.ceil(total_size / BATCH_SIZE);
29- if (stop > 1) {
30- for (batch = 0; batch < stop; batch++) {
31- batches.push({
32- name: batch+1,
33- value: batch
34- });
35- }
36+ // Update the batches only if it's a new search.
37+ if (e.details[1] === undefined) {
38+ var batches = [];
39+ var stop = Math.ceil(total_size / BATCH_SIZE);
40+ if (stop > 1) {
41+ for (batch = 0; batch < stop; batch++) {
42+ batches.push({
43+ name: batch+1,
44+ value: batch
45+ });
46 }
47- picker.set('batches', batches);
48 }
49+ picker.set('batches', batches);
50 }
51 };
52
53
54=== modified file 'lib/lp/app/javascript/picker/tests/test_picker_patcher.js'
55--- lib/lp/app/javascript/picker/tests/test_picker_patcher.js 2016-07-21 15:13:12 +0000
56+++ lib/lp/app/javascript/picker/tests/test_picker_patcher.js 2016-09-12 19:55:47 +0000
57@@ -460,15 +460,15 @@
58 ['a', 'b', 'c'], this.picker.get('filter_options'));
59 },
60
61- test_picker_displays_empty_list: function() {
62- // With too many results, the results will be empty.
63+ test_picker_displays_truncated_list: function() {
64+ // With too many results, the results will be truncated.
65 this.create_picker(true);
66 this.picker.render();
67 this.picker.set('min_search_chars', 0);
68 this.picker.fire('search', '');
69- var result_text = this.picker.get('contentBox')
70- .one('.yui3-picker-results').get('text');
71- Assert.areEqual('', result_text);
72+ var results = this.picker.get('contentBox')
73+ .one('.yui3-picker-results');
74+ Assert.areEqual(120, results.get('children').size());
75 },
76
77 test_picker_displays_warning: function() {
78@@ -478,7 +478,7 @@
79 this.picker.set('min_search_chars', 0);
80 this.picker.fire('search', '');
81 Assert.areEqual(
82- 'Too many matches. Please try to narrow your search.',
83+ 'Only displaying first 120 of 121 matches.',
84 this.picker.get('error'));
85 },
86
87@@ -490,7 +490,7 @@
88 this.picker.set('min_search_chars', 0);
89 this.picker.fire('search', '');
90 Assert.areEqual(
91- 'Too many matches. Please try to narrow your search.',
92+ 'Only displaying first 120 of 121 matches.',
93 this.picker.get('error'));
94 },
95