-
Notifications
You must be signed in to change notification settings - Fork 261
feat(web): add git history view #1150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ca582b8
feat(web): show latest commit header in file browser
brendan-kellam ccab910
feat(web): support co-authors and commit body in commit header
brendan-kellam 45cc8ed
feat(web): add commits pathType and wire History button
brendan-kellam ec43d8d
feat(web): add commit history view
brendan-kellam d481ac8
feat(web): add GET /api/commits/authors endpoint
brendan-kellam 2001211
feat(web): add author filter to commit history view
brendan-kellam d8db399
feat(web): add date range filter to commit history view
brendan-kellam eafa01f
chore: add CHANGELOG entry for git history view
brendan-kellam f57f552
Merge branch 'main' into bkellam/git-history-SOU-131
brendan-kellam f40c691
feat(web): add History tab to bottom panel with latest-commit summary
brendan-kellam aa58cd3
fix(web): resolve path type for the commits view and tighten path han…
brendan-kellam 76464e4
feedback
brendan-kellam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
169 changes: 169 additions & 0 deletions
169
packages/web/src/app/(app)/browse/[...path]/components/authorFilter.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| 'use client'; | ||
|
|
||
| import { useCallback, useEffect, useMemo, useState } from "react"; | ||
| import { useRouter, usePathname, useSearchParams } from "next/navigation"; | ||
| import { Check, ChevronDown, Users } from "lucide-react"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { | ||
| Command, | ||
| CommandInput, | ||
| CommandItem, | ||
| CommandList, | ||
| CommandSeparator, | ||
| } from "@/components/ui/command"; | ||
| import { | ||
| Popover, | ||
| PopoverContent, | ||
| PopoverTrigger, | ||
| } from "@/components/ui/popover"; | ||
| import { UserAvatar } from "@/components/userAvatar"; | ||
| import { cn } from "@/lib/utils"; | ||
| import type { CommitAuthor } from "@/features/git"; | ||
|
|
||
| interface AuthorFilterProps { | ||
| authors: CommitAuthor[]; | ||
| selectedAuthor?: string; | ||
| } | ||
|
|
||
| export const AuthorFilter = ({ authors, selectedAuthor }: AuthorFilterProps) => { | ||
| const router = useRouter(); | ||
| const pathname = usePathname(); | ||
| const searchParams = useSearchParams(); | ||
|
|
||
| const [isOpen, setIsOpen] = useState(false); | ||
| const [search, setSearch] = useState(''); | ||
|
|
||
| // Reset the search input when the popover (re)opens, so stale text from a | ||
| // prior session doesn't appear. Intentionally does NOT fire on close — | ||
| // mid-close re-renders race with Radix's close animation and cause the | ||
| // flash-open-then-close behavior. | ||
| useEffect(() => { | ||
| if (isOpen) { | ||
| setSearch(''); | ||
| } | ||
| }, [isOpen]); | ||
|
|
||
| const selectedAuthorDisplay = useMemo(() => { | ||
| if (!selectedAuthor) { | ||
| return undefined; | ||
| } | ||
| const key = selectedAuthor.toLowerCase(); | ||
| return authors.find((a) => a.email.toLowerCase() === key); | ||
| }, [authors, selectedAuthor]); | ||
|
|
||
| const filteredAuthors = useMemo(() => { | ||
| const term = search.trim().toLowerCase(); | ||
| if (term.length === 0) { | ||
| return authors; | ||
| } | ||
| return authors.filter( | ||
| (a) => | ||
| a.name.toLowerCase().includes(term) || | ||
| a.email.toLowerCase().includes(term), | ||
| ); | ||
| }, [authors, search]); | ||
|
|
||
| const navigateWithAuthor = useCallback((author: string | null) => { | ||
| const params = new URLSearchParams(searchParams); | ||
| if (author === null) { | ||
| params.delete('author'); | ||
| } else { | ||
| params.set('author', author); | ||
| } | ||
| params.delete('page'); | ||
| const query = params.toString(); | ||
| // Close the popover before kicking off navigation so the close render | ||
| // commits cleanly; the search reset is deferred to the next open. | ||
| setIsOpen(false); | ||
| router.push(`${pathname}${query ? `?${query}` : ''}`); | ||
| }, [pathname, router, searchParams]); | ||
|
|
||
| const buttonLabel = selectedAuthor | ||
| ? selectedAuthorDisplay?.name ?? selectedAuthor | ||
| : 'All users'; | ||
|
|
||
| return ( | ||
| <Popover open={isOpen} onOpenChange={setIsOpen}> | ||
| <PopoverTrigger asChild> | ||
| <Button | ||
| variant="outline" | ||
| size="sm" | ||
| className="h-8 gap-2 flex-shrink-0" | ||
| aria-label="Filter by author" | ||
| > | ||
| {selectedAuthorDisplay ? ( | ||
| <UserAvatar | ||
| email={selectedAuthorDisplay.email} | ||
| className="h-5 w-5 flex-shrink-0" | ||
| /> | ||
| ) : ( | ||
| <Users className="h-4 w-4 flex-shrink-0" /> | ||
| )} | ||
| <span className="text-sm truncate max-w-[160px]">{buttonLabel}</span> | ||
| <ChevronDown className="h-3 w-3 flex-shrink-0 text-muted-foreground" /> | ||
| </Button> | ||
| </PopoverTrigger> | ||
| <PopoverContent className="w-[320px] p-0" align="start"> | ||
| <Command shouldFilter={false}> | ||
| <CommandInput | ||
| placeholder="Find a user..." | ||
| value={search} | ||
| onValueChange={setSearch} | ||
| /> | ||
| <CommandList> | ||
| {search.trim().length > 0 && ( | ||
| <CommandItem | ||
| value={`__filter_${search}`} | ||
| onSelect={() => navigateWithAuthor(search.trim())} | ||
| className="cursor-pointer" | ||
| > | ||
| <span> | ||
| Filter on author <strong>{search.trim()}</strong> | ||
| </span> | ||
| </CommandItem> | ||
| )} | ||
| {filteredAuthors.map((a) => { | ||
| const isSelected = | ||
| !!selectedAuthor && | ||
| a.email.toLowerCase() === selectedAuthor.toLowerCase(); | ||
| return ( | ||
| <CommandItem | ||
| key={a.email} | ||
| value={a.email} | ||
| onSelect={() => navigateWithAuthor(a.email)} | ||
| className="cursor-pointer" | ||
| > | ||
| <Check | ||
| className={cn( | ||
| "h-4 w-4 flex-shrink-0", | ||
| isSelected ? "opacity-100" : "opacity-0", | ||
| )} | ||
| /> | ||
| <UserAvatar | ||
| email={a.email} | ||
| className="h-5 w-5 flex-shrink-0" | ||
| /> | ||
| <span className="truncate font-medium">{a.name}</span> | ||
| </CommandItem> | ||
| ); | ||
| })} | ||
| </CommandList> | ||
| {selectedAuthor && ( | ||
| <> | ||
| <CommandSeparator /> | ||
| <div className="p-1"> | ||
| <CommandItem | ||
| value="__clear" | ||
| onSelect={() => navigateWithAuthor(null)} | ||
| className="cursor-pointer justify-center text-primary" | ||
| > | ||
| View commits for all users | ||
| </CommandItem> | ||
| </div> | ||
| </> | ||
| )} | ||
| </Command> | ||
| </PopoverContent> | ||
| </Popover> | ||
| ); | ||
| }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.