-
Notifications
You must be signed in to change notification settings - Fork 966
feat(desktop): v2 sidebar changes tab improvements #3246
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
744f1ff
diff icons
Kitenite 6a9077c
Handle changes
Kitenite 7821fda
debounce
Kitenite 06487e2
Lint
Kitenite a9d33eb
fix: clear debounce timer on workspaceId change
Kitenite c471205
Refactor
Kitenite 5c4626a
memoize
Kitenite 68aee02
Lint
Kitenite f491ec9
Update colors
Kitenite b9ec2ef
clean up
Kitenite 9124028
Sidebar scroll
Kitenite 6da13ea
Unstaged and staged
Kitenite 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
171 changes: 171 additions & 0 deletions
171
...omponents/WorkspaceSidebar/hooks/useChangesTab/components/ChangesHeader/ChangesHeader.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,171 @@ | ||
| import { GitBranch, Pencil } from "lucide-react"; | ||
| import { useRef, useState } from "react"; | ||
| import type { ChangesFilter } from "renderer/routes/_authenticated/providers/CollectionsProvider/dashboardSidebarLocal/schema"; | ||
| import type { Branch, Commit } from "../../types"; | ||
| import { BaseBranchSelector } from "../BaseBranchSelector"; | ||
| import { CommitFilterDropdown } from "../CommitFilterDropdown"; | ||
|
|
||
| interface ChangesHeaderProps { | ||
| currentBranch: { name: string; aheadCount: number; behindCount: number }; | ||
| defaultBranchName: string; | ||
| commitCount: number; | ||
| totalFiles: number; | ||
| totalAdditions: number; | ||
| totalDeletions: number; | ||
| filter: ChangesFilter; | ||
| onFilterChange: (filter: ChangesFilter) => void; | ||
| commits: Commit[]; | ||
| uncommittedCount: number; | ||
| branches: Branch[]; | ||
| onBaseBranchChange: (branchName: string) => void; | ||
| onRenameBranch: (newName: string) => void; | ||
| canRename: boolean; | ||
| } | ||
|
|
||
| export function ChangesHeader({ | ||
| currentBranch, | ||
| defaultBranchName, | ||
| commitCount, | ||
| totalFiles, | ||
| totalAdditions, | ||
| totalDeletions, | ||
| onRenameBranch, | ||
| canRename, | ||
| filter, | ||
| onFilterChange, | ||
| commits, | ||
| uncommittedCount, | ||
| branches, | ||
| onBaseBranchChange, | ||
| }: ChangesHeaderProps) { | ||
| const [isEditing, setIsEditing] = useState(false); | ||
| const [editValue, setEditValue] = useState(currentBranch.name); | ||
| const inputRef = useRef<HTMLInputElement>(null); | ||
| const skipBlurRef = useRef(false); | ||
|
|
||
| const startEditing = () => { | ||
| setEditValue(currentBranch.name); | ||
| setIsEditing(true); | ||
| skipBlurRef.current = false; | ||
| requestAnimationFrame(() => inputRef.current?.select()); | ||
| }; | ||
|
|
||
| const handleSubmit = () => { | ||
| const trimmed = editValue.trim(); | ||
| if (trimmed && trimmed !== currentBranch.name) { | ||
| onRenameBranch(trimmed); | ||
| } | ||
| setIsEditing(false); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="border-b border-border bg-muted/30 px-3 py-2.5 space-y-1.5"> | ||
| <div className="group flex items-center gap-1.5 text-xs"> | ||
| <GitBranch className="size-3.5 shrink-0 text-muted-foreground" /> | ||
| {isEditing ? ( | ||
| <input | ||
| ref={inputRef} | ||
| value={editValue} | ||
| onChange={(e) => setEditValue(e.target.value)} | ||
| onKeyDown={(e) => { | ||
| if (e.key === "Enter") { | ||
| skipBlurRef.current = true; | ||
| handleSubmit(); | ||
| } | ||
| if (e.key === "Escape") { | ||
| skipBlurRef.current = true; | ||
| setIsEditing(false); | ||
| } | ||
| }} | ||
| onBlur={() => { | ||
| if (skipBlurRef.current) return; | ||
| handleSubmit(); | ||
| }} | ||
| className="min-w-0 flex-1 truncate bg-transparent font-medium outline-none ring-1 ring-ring rounded-sm px-1" | ||
| /> | ||
| ) : ( | ||
| <> | ||
| <span className="truncate font-medium">{currentBranch.name}</span> | ||
| {canRename && ( | ||
| <button | ||
| type="button" | ||
| onClick={startEditing} | ||
| className="shrink-0 opacity-0 group-hover:opacity-100 transition-opacity text-muted-foreground hover:text-foreground" | ||
| > | ||
| <Pencil className="size-3" /> | ||
| </button> | ||
|
Kitenite marked this conversation as resolved.
|
||
| )} | ||
| </> | ||
| )} | ||
| </div> | ||
|
|
||
| <div className="text-[11px] text-muted-foreground"> | ||
| {commitCount} {commitCount === 1 ? "commit" : "commits"} from{" "} | ||
| <BaseBranchSelector | ||
| branches={branches} | ||
| currentValue={defaultBranchName} | ||
| onChange={onBaseBranchChange} | ||
| /> | ||
| </div> | ||
|
|
||
| {currentBranch.aheadCount > 0 && currentBranch.behindCount > 0 && ( | ||
| <div className="text-[11px] text-muted-foreground"> | ||
| <div>Your branch and</div> | ||
| <div className="font-medium text-foreground"> | ||
| origin/{currentBranch.name} | ||
| </div> | ||
| <div>have diverged</div> | ||
| <div> | ||
| {currentBranch.aheadCount} local not pushed,{" "} | ||
| {currentBranch.behindCount} remote to pull | ||
| </div> | ||
| </div> | ||
| )} | ||
| {currentBranch.aheadCount > 0 && currentBranch.behindCount === 0 && ( | ||
| <div className="text-[11px] text-muted-foreground"> | ||
| <div> | ||
| {currentBranch.aheadCount}{" "} | ||
| {currentBranch.aheadCount === 1 ? "commit" : "commits"} ahead of | ||
| </div> | ||
| <div className="font-medium text-foreground"> | ||
| origin/{currentBranch.name} | ||
| </div> | ||
| </div> | ||
| )} | ||
| {currentBranch.behindCount > 0 && currentBranch.aheadCount === 0 && ( | ||
| <div className="text-[11px] text-muted-foreground"> | ||
| <div> | ||
| {currentBranch.behindCount}{" "} | ||
| {currentBranch.behindCount === 1 ? "commit" : "commits"} behind | ||
| </div> | ||
| <div className="font-medium text-foreground"> | ||
| origin/{currentBranch.name} | ||
| </div> | ||
| </div> | ||
| )} | ||
|
|
||
| <div className="flex items-center justify-between pt-0.5"> | ||
| <CommitFilterDropdown | ||
| filter={filter} | ||
| onFilterChange={onFilterChange} | ||
| commits={commits} | ||
| uncommittedCount={uncommittedCount} | ||
| /> | ||
| <div className="flex items-center gap-1.5 text-xs text-muted-foreground"> | ||
| <span>{totalFiles} files changed</span> | ||
| {(totalAdditions > 0 || totalDeletions > 0) && ( | ||
| <span> | ||
| {totalAdditions > 0 && ( | ||
| <span className="text-green-400">+{totalAdditions}</span> | ||
| )} | ||
| {totalAdditions > 0 && totalDeletions > 0 && " "} | ||
| {totalDeletions > 0 && ( | ||
| <span className="text-red-400">-{totalDeletions}</span> | ||
| )} | ||
| </span> | ||
| )} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
1 change: 1 addition & 0 deletions
1
...spaceId/components/WorkspaceSidebar/hooks/useChangesTab/components/ChangesHeader/index.ts
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 @@ | ||
| export { ChangesHeader } from "./ChangesHeader"; |
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.