Skip to content

Commit d279998

Browse files
authored
Add repo presets (#5)
1 parent 602b6d7 commit d279998

File tree

3 files changed

+114
-5
lines changed

3 files changed

+114
-5
lines changed

web/htdocs/assets/css/codesearch.css

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,61 @@ a:hover {
279279
}
280280

281281
.search-options {
282-
width: 250px;
283-
max-width: 250px;
282+
width: 280px;
283+
max-width: 280px;
284284
margin: 0;
285285
font-size: 12px;
286-
line-height: 20px;
286+
display: flex;
287+
flex-direction: column;
288+
gap: 3px;
287289
}
288290

289291
.search-option {
290292
white-space: nowrap;
293+
line-height: 24px;
294+
}
295+
296+
.search-option input[type="radio"],
297+
.search-option input[type="checkbox"] {
298+
appearance: none;
299+
width: 14px;
300+
height: 14px;
301+
border: 1.5px solid var(--color-border-subtle);
302+
background: var(--color-background);
303+
vertical-align: middle;
304+
margin: 0 2px 0 0;
305+
cursor: pointer;
306+
transition: border-color 150ms, background 150ms;
307+
}
308+
309+
.search-option input[type="radio"] {
310+
border-radius: 50%;
311+
}
312+
313+
.search-option input[type="checkbox"] {
314+
border-radius: 3px;
315+
}
316+
317+
.search-option input[type="radio"]:checked {
318+
border-color: var(--color-foreground-accent);
319+
background: var(--color-foreground-accent);
320+
box-shadow: inset 0 0 0 2.5px var(--color-background);
321+
}
322+
323+
.search-option input[type="checkbox"]:checked {
324+
border-color: var(--color-foreground-accent);
325+
background: var(--color-foreground-accent);
326+
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 14 14' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3.5 7.5L6 10L10.5 4.5' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
327+
}
328+
329+
.search-option input[type="radio"]:hover,
330+
.search-option input[type="checkbox"]:hover {
331+
border-color: var(--color-foreground-accent);
332+
}
333+
334+
.search-option label {
335+
cursor: pointer;
336+
margin-right: 6px;
291337
}
292338

293339
#regex-error {
@@ -913,3 +959,28 @@ div.example {
913959
.token.bold {
914960
font-weight: bold;
915961
}
962+
963+
/* Repo preset buttons */
964+
.repo-presets {
965+
display: flex;
966+
flex-wrap: wrap;
967+
gap: 5px;
968+
margin-top: 2px;
969+
padding-left: 2px;
970+
}
971+
972+
.repo-preset-btn {
973+
background: var(--color-background-subtle);
974+
border: 1px solid var(--color-border-default);
975+
border-radius: 4px;
976+
color: var(--color-foreground-muted);
977+
cursor: pointer;
978+
font-size: 11px;
979+
padding: 3px 10px;
980+
transition: background 150ms, color 150ms;
981+
}
982+
983+
.repo-preset-btn:hover {
984+
background: var(--color-background-hover);
985+
color: var(--color-foreground);
986+
}

web/src/codesearch/codesearch_ui.js

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,12 +515,14 @@ var SearchState = Backbone.Model.extend({
515515
return '/search';
516516
var base = '/search';
517517

518+
if (current.repo && current.repo.length) {
519+
q.repo = current.repo;
520+
}
518521
if (current.q !== "") {
519522
q.q = current.q;
520523
q.fold_case = current.fold_case;
521524
q.regex = current.regex;
522525
q.context = this.get('context');
523-
q.repo = current.repo;
524526
}
525527

526528
if (current.backend) {
@@ -910,6 +912,7 @@ var CodesearchUI = function() {
910912
setTimeout(function() {
911913
RepoSelector.init();
912914
CodesearchUI.update_repo_options();
915+
CodesearchUI.render_repo_presets();
913916
CodesearchUI.init_query();
914917
}, 0);
915918

@@ -1108,6 +1111,21 @@ var CodesearchUI = function() {
11081111
search_done: function(search, time, search_type, why) {
11091112
CodesearchUI.state.handle_done(search, time, search_type, why);
11101113
},
1114+
render_repo_presets: function() {
1115+
var presets = CodesearchUI.repoPresets;
1116+
if (!presets || !presets.length) return;
1117+
1118+
var container = $('<div class="repo-presets"></div>');
1119+
presets.forEach(function(preset) {
1120+
var btn = $('<button class="repo-preset-btn"></button>').text(preset.name);
1121+
btn.on('click', function() {
1122+
RepoSelector.updateSelected(preset.repos);
1123+
CodesearchUI.newsearch();
1124+
});
1125+
container.append(btn);
1126+
});
1127+
$('#repos').closest('.search-option').append(container);
1128+
},
11111129
repo_urls: {}
11121130
};
11131131
}();
@@ -1117,6 +1135,26 @@ var ivr = {};
11171135
initData.internal_view_repos.forEach(function(name) { ivr[name] = true; });
11181136
CodesearchUI.internalViewRepos = ivr;
11191137
CodesearchUI.defaultSearchRepos = initData.default_search_repos;
1138+
1139+
// Repo presets: each entry adds a button that selects a predefined set of repos.
1140+
// Edit this array to add/remove/rename presets.
1141+
CodesearchUI.repoPresets = [
1142+
{name: 'SDKs', repos: [
1143+
'getsentry/sentry-cocoa', 'getsentry/sentry-python', 'getsentry/sentry-ruby',
1144+
'getsentry/sentry-rust', 'getsentry/sentry-dotnet', 'getsentry/sentry-java',
1145+
'getsentry/sentry-javascript', 'getsentry/sentry-go', 'getsentry/sentry-php',
1146+
'getsentry/sentry-native', 'getsentry/sentry-react-native', 'getsentry/sentry-dart',
1147+
'getsentry/sentry-unity', 'getsentry/sentry-elixir', 'getsentry/sentry-laravel',
1148+
]},
1149+
{name: 'Fullstack', repos: [
1150+
'getsentry/sentry', 'getsentry/relay', 'getsentry/snuba',
1151+
'getsentry/arroyo', 'getsentry/symbolicator', 'getsentry/objectstore',
1152+
]},
1153+
{name: 'Tools', repos: [
1154+
'getsentry/sentry-cli', 'getsentry/sentry-mcp', 'getsentry/craft',
1155+
'getsentry/self-hosted',
1156+
]},
1157+
];
11201158
CodesearchUI.linkConfigs = (initData.link_configs || []).map(function(link_config) {
11211159
if (link_config.whitelist_pattern) {
11221160
link_config.whitelist_pattern = new RegExp(link_config.whitelist_pattern);

web/src/codesearch/repo_selector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function updateOptions(newOptions) {
6060
var parts = newOptions[i].split('/');
6161
var group = parts.slice(0, parts.length - 1).join('/') + '/';
6262
var option = parts[parts.length - 1];
63-
var value = group + option;
63+
var value = group === '/' ? option : group + option;
6464

6565
if (group !== '/' && group !== currentGroup) {
6666
if (currentGroup !== null && currentGroup !== '/') {

0 commit comments

Comments
 (0)