refactor: replace Fomantic search module with first-party code#37443
Conversation
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>
Three boxes (repo/user/team) all share the same first-party module, so one happy-path test on the user box is sufficient as a regression gate. Drops the org/team helpers in tests/e2e/utils.ts that only those extra tests motivated. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
Move web_src/js/modules/fomantic/search.ts to web_src/js/modules/search.ts
(no Fomantic dependency anymore). Replace the imperative
initSearchBox(el, opts) with chooseFromApi(el, url, parse) that returns
a Promise<SearchResult> resolving with the user's chosen item; callers
loop with `while (box.isConnected) { const pick = await ...; ... }` and
own writing back to whatever input/state they manage.
Cleanup is via a single AbortController whose signal is passed to all
listeners; the in-flight fetch has its own controller so a new keystroke
can cancel just the request without tearing down listeners.
Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
- chooseFromApi is now generic over the response shape; each caller declares a typed *SearchResponse, removing four `any` annotations - e2e test prefix: rc- → repo-collab- for legibility in the test DB - web_src/css/modules/search.css: drop the stale leading comment Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
wxiaoguang
left a comment
There was a problem hiding this comment.
AI slop, do you agree?
Why you force every caller to write a while loop?
|
You mean the callback on |
Why a framework "component" forces the caller to handle the value update and event dispatch by themselves and copy & paste the code again and again? |
|
The main problem is that every consumer needs a different response, but the fetching logic is shared. I guess I can just deliver a generic response to each consumer. |
|
That's why Gitea's frontend was totally a mess, I had to spend plenty of time to refactor almost every line. |
- attachSearchBox(el, url, parse) replaces the await-style chooseFromApi - The component handles input update + change-event dispatch on selection, so callers don't loop or write back the value themselves - Each caller is now a single statement; response shape is conveyed via the parse callback's parameter annotation (T inferred) Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
After clicking the search result, the test now also clicks Add Collaborator and asserts the username appears in the page body (i.e., in the collaborator list after the redirect), proving the chosen result drives the form submission end-to-end. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
Signed-off-by: silverwind <me@silverwind.io>
|
Now using callback, similar to what was with fomantic. The |
- collapse the render/keydown/select helpers (replaceChildren with mapped array, inline ArrowUp/Down branch, drop the move() helper) - abort the in-flight fetch from hide() so Escape/blur/outside-click cancel the request, and gate the post-await render on ctrl.signal.aborted to suppress responses that settle after hide() - rename idx → index - restore the leading comment in web_src/css/modules/search.css that an earlier commit on this branch dropped Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
Mirrors errorMessage in web_src/js/modules/errors.ts. Migrates the only two existing `(err as Error).name !== 'AbortError'` sites (modules/search.ts, features/common-fetch-action.ts). Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
Regression coverage for the team-members page (org/team/members.tmpl), whose DOM wraps the input in an extra div.ui.input and was the source of the user-visible report on PR go-gitea#37443. Adds apiCreateOrg and apiCreateTeam helpers to tests/e2e/utils.ts. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
- search is no longer typed as nullable; the closure's hide() no longer
references search, so `const search = debounce(...)` is reachable
after `const hide`. The two dismiss paths (Escape, outside-click)
cancel the debounce explicitly via a local `dismiss` helper, and the
blur handler keeps its own inline cancel+deferred-hide.
- The per-call `document.addEventListener('click', ...)` is replaced by
a single module-level delegated handler that iterates a registry of
{container, dismiss} entries. Avoids accumulating one handler per
attached box.
Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
* main: fix(deps): update dependency mermaid to v11.15.0 [security], add e2e test (go-gitea#37662) ci: Also lint json5 files (go-gitea#37659) fix(templates): avoid misleading compare message when branches lack merge base (go-gitea#37651) fix(deps): update npm dependencies (go-gitea#37647) refactor: routing info middleware (go-gitea#37653) chore(deps): update action dependencies (major) (go-gitea#37638) fix(deps): update go dependencies (major) (go-gitea#37639) ci(renovate): update Go import paths on major bumps (go-gitea#37641) fix(packages): Add label for private and internal package and fix composor package source permission check (go-gitea#37610) refactor: replace Fomantic search module with first-party code (go-gitea#37443) fix(deps): update npm dependencies (go-gitea#37636) fix(deps): update module code.gitea.io/sdk/gitea to v0.25.0 (go-gitea#37637) feat(api): add last_sync to repository API (go-gitea#37566) test(e2e): run playwright via container (go-gitea#37300) feat(editor): broaden language detection in web code editor (go-gitea#37619) refactor(log): replace log.Critical with log.Error (go-gitea#37624) fix: "run as root" check (go-gitea#37622) fix: improve actions status icons and texts (go-gitea#37206) # Conflicts: # pnpm-workspace.yaml



searchcode with minimal first-party codeerrorNamehelper, similar toerrorMessage.This PR was written with the help of Claude Opus 4.7