From da30652db040758adaa209a541d49a67c25ea7d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Sat, 16 Aug 2025 16:14:33 -0400 Subject: [PATCH] add component for searching for teams to add to a group --- web_src/js/features/comp/SearchTeamBox.ts | 36 +++++++++++++++++++++++ web_src/js/index.ts | 2 ++ 2 files changed, 38 insertions(+) create mode 100644 web_src/js/features/comp/SearchTeamBox.ts diff --git a/web_src/js/features/comp/SearchTeamBox.ts b/web_src/js/features/comp/SearchTeamBox.ts new file mode 100644 index 0000000000..417621bd19 --- /dev/null +++ b/web_src/js/features/comp/SearchTeamBox.ts @@ -0,0 +1,36 @@ +import {fomanticQuery} from '../../modules/fomantic/base.ts'; +import {html} from '../../utils/html.ts'; + +const {appSubUrl} = window.config; + +export function initCompSearchTeamBox() { + const searchTeamBox = document.querySelector('#search-team-box'); + if (!searchTeamBox) return; + + fomanticQuery(searchTeamBox).search({ + minCharacters: 2, + apiSettings: { + url: `${appSubUrl}${searchTeamBox.getAttribute('data-search-url')}`, + onResponse(response: {data: any[]}) { + const resultItems = []; + const searchQuery = searchTeamBox.querySelector('input').value; + const searchQueryUppercase = searchQuery.toUpperCase(); + for (const item of response.data) { + const resultItem = { + title: item.name, + description: html`${item.description}`, + }; + if (searchQueryUppercase === item.name.toUpperCase()) { + resultItems.unshift(resultItem); // add the exact match to the top + } else { + resultItems.push(resultItem); + } + } + + return {results: resultItems}; + }, + }, + searchFields: ['login', 'full_name'], + showNoResults: false, + }); +} diff --git a/web_src/js/index.ts b/web_src/js/index.ts index aa21ccdc06..798f6117c6 100644 --- a/web_src/js/index.ts +++ b/web_src/js/index.ts @@ -37,6 +37,7 @@ import {initRepoReleaseNew} from './features/repo-release.ts'; import {initRepoEditor} from './features/repo-editor.ts'; import {initCompSearchUserBox} from './features/comp/SearchUserBox.ts'; import {initInstall} from './features/install.ts'; +import {initCompSearchTeamBox} from './features/comp/SearchTeamBox.ts' import {initCompWebHookEditor} from './features/comp/WebHookEditor.ts'; import {initRepoBranchButton} from './features/repo-branch.ts'; import {initCommonOrganization} from './features/common-organization.ts'; @@ -93,6 +94,7 @@ const initPerformanceTracer = callInitFunctions([ initCompSearchUserBox, initCompWebHookEditor, + initCompSearchTeamBox, initInstall,