mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-27 09:45:52 +02:00
Drops the 1565-line vendored Fomantic UI search jQuery plugin in favor of a small first-party TypeScript module covering the three call sites (repo, user, and team autocomplete). Adds an e2e regression suite that exercises each search box. Also fixes input/button vertical alignment in the four forms that wrap a search box: the fomantic-era `tw-align-middle` workaround is replaced by `flex-text-block` on the form, which is the codebase's standard flex helper for this layout. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
44 lines
1.6 KiB
TypeScript
44 lines
1.6 KiB
TypeScript
import {htmlEscape} from '../../utils/html.ts';
|
|
import {initSearchBox} from '../../modules/fomantic/search.ts';
|
|
|
|
const {appSubUrl} = window.config;
|
|
const looksLikeEmailAddressCheck = /^\S+@\S+$/;
|
|
|
|
export function initCompSearchUserBox() {
|
|
const searchUserBox = document.querySelector<HTMLElement>('#search-user-box');
|
|
if (!searchUserBox) return;
|
|
|
|
const allowEmailInput = searchUserBox.getAttribute('data-allow-email') === 'true';
|
|
const allowEmailDescription = searchUserBox.getAttribute('data-allow-email-description') ?? undefined;
|
|
const includeOrgs = searchUserBox.getAttribute('data-include-orgs') === 'true';
|
|
initSearchBox(searchUserBox, {
|
|
apiUrl: `${appSubUrl}/user/search_candidates?q={query}&orgs=${includeOrgs}`,
|
|
onResponse(response: any, searchQuery: string) {
|
|
const resultItems = [];
|
|
const searchQueryUppercase = searchQuery.toUpperCase();
|
|
for (const item of response.data) {
|
|
const resultItem = {
|
|
title: item.login,
|
|
image: item.avatar_url,
|
|
description: htmlEscape(item.full_name),
|
|
};
|
|
if (searchQueryUppercase === item.login.toUpperCase()) {
|
|
resultItems.unshift(resultItem); // add the exact match to the top
|
|
} else {
|
|
resultItems.push(resultItem);
|
|
}
|
|
}
|
|
|
|
if (allowEmailInput && !resultItems.length && looksLikeEmailAddressCheck.test(searchQuery)) {
|
|
const resultItem = {
|
|
title: searchQuery,
|
|
description: allowEmailDescription,
|
|
};
|
|
resultItems.push(resultItem);
|
|
}
|
|
|
|
return {results: resultItems};
|
|
},
|
|
});
|
|
}
|