-
-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add repository rename functionality #23
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
10 commits
Select commit
Hold shift + click to select a range
6a7db08
feat: implement repository rename feature
wiiiimm c48bcea
fix: change rename keyboard shortcut to Ctrl+R
wiiiimm 7d701d7
fix: prevent Ctrl+R from triggering refresh
wiiiimm 4c703b9
fix: resolve client.mutate error and update RenameModal UI
wiiiimm 6187466
fix: improve RenameModal input field layout
wiiiimm d0efbbe
fix: complete RenameModal redesign with proper key handling
wiiiimm 233e313
test: add comprehensive test coverage for rename feature
wiiiimm 69fc530
test: improve RenameModal test coverage to 70%
wiiiimm 854e20e
fix: use makeApolloClient instead of undefined getApolloClient
wiiiimm a1cb28b
fix: address code review comments
wiiiimm 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| import React, { useState, useEffect } from 'react'; | ||
| import { Box, Text, useInput } from 'ink'; | ||
| import TextInput from 'ink-text-input'; | ||
| import chalk from 'chalk'; | ||
| import type { RepoNode } from '../../../types'; | ||
| import { SlowSpinner } from '../common'; | ||
|
|
||
| interface RenameModalProps { | ||
| repo: RepoNode | null; | ||
| onRename: (repo: RepoNode, newName: string) => Promise<void>; | ||
| onCancel: () => void; | ||
| } | ||
|
|
||
| export default function RenameModal({ repo, onRename, onCancel }: RenameModalProps) { | ||
| const [newName, setNewName] = useState(''); | ||
| const [renaming, setRenaming] = useState(false); | ||
| const [renameError, setRenameError] = useState<string | null>(null); | ||
|
|
||
| // Initialize with current repo name when modal opens | ||
| useEffect(() => { | ||
| if (repo) { | ||
| setNewName(repo.name); | ||
| setRenameError(null); | ||
| } | ||
| }, [repo]); | ||
|
|
||
| // Handle keyboard input for submit/cancel | ||
| useInput((input, key) => { | ||
| if (renaming) return; // Ignore input while renaming | ||
|
|
||
| if (key.escape) { | ||
| onCancel(); | ||
| return; | ||
| } | ||
|
|
||
| if (key.return) { | ||
| if (newName.trim() && newName !== repo?.name) { | ||
| handleRenameConfirm(); | ||
| } | ||
| return; | ||
| } | ||
| }); | ||
|
|
||
| // Handle the rename confirmation | ||
| const handleRenameConfirm = async () => { | ||
| if (!repo || renaming || !newName.trim() || newName === repo.name) return; | ||
|
|
||
| try { | ||
| setRenaming(true); | ||
| setRenameError(null); | ||
| await onRename(repo, newName.trim()); | ||
| } catch (e: any) { | ||
| setRenameError(e.message || 'Failed to rename repository'); | ||
| setRenaming(false); | ||
| } | ||
| }; | ||
|
|
||
| // Validate GitHub repository name (alphanumeric, hyphens, underscores, periods) | ||
| const handleNameChange = (value: string) => { | ||
| // GitHub repo names allow: alphanumeric, hyphen, underscore, period | ||
| // Filter out invalid characters | ||
| const filtered = value.replace(/[^a-zA-Z0-9\-_.]/g, ''); | ||
| setNewName(filtered); | ||
| }; | ||
|
|
||
| if (!repo) return null; | ||
|
|
||
| const owner = repo.nameWithOwner.split('/')[0]; | ||
| const isDisabled = !newName.trim() || newName === repo.name; | ||
|
|
||
| return ( | ||
| <Box | ||
| flexDirection="column" | ||
| borderStyle="round" | ||
| borderColor="cyan" | ||
| paddingX={3} | ||
| paddingY={2} | ||
| width={80} | ||
| > | ||
| <Text bold color="cyan">Rename Repository</Text> | ||
| <Box height={1}><Text> </Text></Box> | ||
|
|
||
| <Text color="gray">Current: {repo.nameWithOwner}</Text> | ||
| <Box height={1}><Text> </Text></Box> | ||
|
|
||
| <Text>New name:</Text> | ||
| <Box flexDirection="row" alignItems="center"> | ||
| <Text>{owner}/</Text> | ||
| <TextInput | ||
| value={newName} | ||
| onChange={handleNameChange} | ||
| placeholder={repo.name} | ||
| focus={!renaming} | ||
| /> | ||
| </Box> | ||
|
|
||
| {renaming ? ( | ||
| <Box marginTop={2} justifyContent="center"> | ||
| <Box flexDirection="row"> | ||
| <Box marginRight={1}> | ||
| <SlowSpinner /> | ||
| </Box> | ||
| <Text color="cyan">Renaming repository...</Text> | ||
| </Box> | ||
| </Box> | ||
| ) : ( | ||
| <> | ||
| <Box marginTop={2}> | ||
| <Text color="gray"> | ||
| {isDisabled ? | ||
| 'Enter a different name to rename' : | ||
| `Press Enter to rename to "${newName}"` | ||
| } | ||
| </Text> | ||
| </Box> | ||
| <Box marginTop={1}> | ||
| <Text color="gray">Press Esc to cancel</Text> | ||
| </Box> | ||
| </> | ||
| )} | ||
|
|
||
| {renameError && ( | ||
| <Box marginTop={1}> | ||
| <Text color="red">{renameError}</Text> | ||
| </Box> | ||
| )} | ||
| </Box> | ||
| ); | ||
| } |
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
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.