Skip to content

Commit 35e38b1

Browse files
add component for searching for teams to add to a group
1 parent 9d650e6 commit 35e38b1

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import {fomanticQuery} from '../../modules/fomantic/base.ts';
2+
import {html} from '../../utils/html.ts';
3+
4+
const {appSubUrl} = window.config;
5+
6+
export function initCompSearchTeamBox() {
7+
const searchTeamBox = document.querySelector('#search-team-box');
8+
if (!searchTeamBox) return;
9+
10+
fomanticQuery(searchTeamBox).search({
11+
minCharacters: 2,
12+
apiSettings: {
13+
url: `${appSubUrl}${searchTeamBox.getAttribute('data-search-url')}`,
14+
onResponse(response: {data: any[]}) {
15+
const resultItems = [];
16+
const searchQuery = searchTeamBox.querySelector('input').value;
17+
const searchQueryUppercase = searchQuery.toUpperCase();
18+
for (const item of response.data) {
19+
const resultItem = {
20+
title: item.name,
21+
description: html`${item.description}`,
22+
};
23+
if (searchQueryUppercase === item.name.toUpperCase()) {
24+
resultItems.unshift(resultItem); // add the exact match to the top
25+
} else {
26+
resultItems.push(resultItem);
27+
}
28+
}
29+
30+
return {results: resultItems};
31+
},
32+
},
33+
searchFields: ['login', 'full_name'],
34+
showNoResults: false,
35+
});
36+
}

web_src/js/index-domready.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {initUserAuthWebAuthn, initUserAuthWebAuthnRegister} from './features/use
3737
import {initRepoRelease, initRepoReleaseNew} from './features/repo-release.ts';
3838
import {initRepoEditor} from './features/repo-editor.ts';
3939
import {initCompSearchUserBox} from './features/comp/SearchUserBox.ts';
40+
import {initCompSearchTeamBox} from './features/comp/SearchTeamBox.ts';
4041
import {initInstall} from './features/install.ts';
4142
import {initCompWebHookEditor} from './features/comp/WebHookEditor.ts';
4243
import {initRepoBranchButton} from './features/repo-branch.ts';
@@ -92,6 +93,7 @@ const initPerformanceTracer = callInitFunctions([
9293
initCommonIssueListQuickGoto,
9394

9495
initCompSearchUserBox,
96+
initCompSearchTeamBox,
9597
initCompWebHookEditor,
9698

9799
initInstall,

0 commit comments

Comments
 (0)