Skip to content

Commit 332472f

Browse files
authored
Make search results more visible (#853)
* Move API promotion at the bottom of results * Jump to filters to highlight search results * Add component filters to entity results * Don't focus search input when there's a hash
1 parent 7dcbfc0 commit 332472f

5 files changed

Lines changed: 46 additions & 11 deletions

File tree

app/views/onestring.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414

1515
// We have no error, display results
1616
$page_descr = $entity;
17-
18-
// Promote API view
19-
include VIEWS . 'templates/api_promotion.php';
2017
?>
2118

2219
<table>
@@ -44,3 +41,7 @@
4441
}
4542
?>
4643
</table>
44+
45+
<?php
46+
// Promote API view
47+
include VIEWS . 'templates/api_promotion.php';

app/views/results_entities.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<?php
22
namespace Transvision;
33

4-
// Promote API view
5-
include VIEWS . 'templates/api_promotion.php';
6-
74
$table = "
85
<table class='collapsable'>
96
<thead>
@@ -19,8 +16,11 @@
1916
$current_repo = $search->getRepository();
2017
$extra_locale = $url['path'] == '3locales';
2118

19+
$components = [];
2220
// Display results
2321
foreach ($entities as $entity) {
22+
$component = explode('/', $entity)[0];
23+
$components[] = $component;
2424
if (in_array($current_repo, ['firefox_ios', 'mozilla_org'])) {
2525
$path_locale1 = VersionControl::gitPath($source_locale, $current_repo, $entity);
2626
$path_locale2 = VersionControl::gitPath($locale, $current_repo, $entity);
@@ -164,7 +164,7 @@
164164
}
165165

166166
$table .= "
167-
<tr>
167+
<tr class='{$component}'>
168168
<td>
169169
<span class='celltitle'>Entity</span>
170170
<a class='resultpermalink tag' id='{$anchor_name}' href='#{$anchor_name}' title='Permalink to this result'>#</a>
@@ -198,7 +198,29 @@
198198
</tr>\n";
199199
}
200200

201+
// Remove duplicated components
202+
$components = array_unique($components);
203+
if (Project::isDesktopRepository($search->getRepository())) {
204+
// Build logic to filter components
205+
$filter_block = '';
206+
foreach ($components as $value) {
207+
$filter_block .= " <a href='#{$value}' id='{$value}' class='filter'>{$value}</a>";
208+
}
209+
}
210+
if (isset($filter_block)):
211+
?>
212+
<div id="filters">
213+
<h4>Filter by folder:</h4>
214+
<a href="#showall" id="showall" class="filter">Show all results</a>
215+
<?=$filter_block;?>
216+
</div>
217+
<?php
218+
endif;
219+
201220
$table .= "</tbody>\n</table>\n\n";
202221
if ($entities) {
203222
print $table;
204223
}
224+
225+
// Promote API view
226+
include VIEWS . 'templates/api_promotion.php';

app/views/results_strings.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
<?php
1010
endif;
1111

12-
// Promote API view
13-
include VIEWS . 'templates/api_promotion.php';
14-
1512
foreach ($output as $results_table) {
1613
print $results_table;
1714
}
15+
16+
// Promote API view
17+
include VIEWS . 'templates/api_promotion.php';

web/js/base.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,7 @@ $(document).ready(function() {
6565
}
6666

6767
// Focus on the main search field.
68-
$('#recherche').focus();
68+
if (window.location.hash === '') {
69+
$('#recherche').focus();
70+
}
6971
});

web/js/main_search.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,14 @@ $(document).ready(function() {
197197
$(this).remove();
198198
});
199199
});
200+
201+
/*
202+
Jump to filters if there's not an hash already defined, e.g. to
203+
jump to a specific row.
204+
*/
205+
if (window.location.hash === '' && $('#filters').length) {
206+
$('body,html').animate({
207+
scrollTop: $('#filters').offset().top
208+
}, 500);
209+
}
200210
});

0 commit comments

Comments
 (0)