-
Notifications
You must be signed in to change notification settings - Fork 4
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
Refactor: restructure component layers for kebab button on groupcard #389
Merged
ShoeheyOt
merged 9 commits into
develop
from
refactor/385-restructure-component-layers-for-kebab-button-on-groupcard
Apr 6, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9dfe8ef
refactor: move DialogRoot
ShoeheyOt 4ae3ec7
refactor: change the name of components
ShoeheyOt 48a24a3
docs: add to interfaces
ShoeheyOt 5cff28b
refactor: restructure the directories
ShoeheyOt 5d133a7
refactor: delete unnecessary code
ShoeheyOt 9c52daf
feat: focust kebab button using useAutoFocus
ShoeheyOt ae0435c
docs: add docs to interface
ShoeheyOt 9f11fc4
docs: doc:fix the TSDoc
ShoeheyOt a594a87
fix: typo
ShoeheyOt 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
46 changes: 46 additions & 0 deletions
46
...ardList/GroupCard/GroupCardContent/GroupCardDropdownMenu/GroupCardDropdownMenuContent.tsx
This file contains 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,46 @@ | ||
import { IconDelete, IconPen } from '@/assets/images/icons'; | ||
import { | ||
DropdownMenuButton, | ||
DropdownMenuButtonIcon, | ||
DropdownMenuButtonText, | ||
DropdownMenuContent, | ||
DropdownMenuItem, | ||
Icon, | ||
} from '@/components/ui'; | ||
|
||
interface IGroupCardDropdownMenuContentProps { | ||
/** | ||
* Function to handle the rename button click. | ||
*/ | ||
handleRenameClick: () => void; | ||
/** | ||
* The function to close the dropdown menu. | ||
*/ | ||
handleDeleteClick: () => void; | ||
} | ||
|
||
export const GroupCardDropdownMenuContent = ({ | ||
handleRenameClick, | ||
handleDeleteClick, | ||
}: IGroupCardDropdownMenuContentProps) => { | ||
return ( | ||
<DropdownMenuContent> | ||
<DropdownMenuItem asChild> | ||
<DropdownMenuButton onClick={handleRenameClick}> | ||
<DropdownMenuButtonIcon> | ||
<Icon icon={IconPen} size={5} color="primary" /> | ||
</DropdownMenuButtonIcon> | ||
<DropdownMenuButtonText>Rename</DropdownMenuButtonText> | ||
</DropdownMenuButton> | ||
</DropdownMenuItem> | ||
<DropdownMenuItem asChild> | ||
<DropdownMenuButton onClick={handleDeleteClick}> | ||
<DropdownMenuButtonIcon> | ||
<Icon icon={IconDelete} size={5} color="danger" /> | ||
</DropdownMenuButtonIcon> | ||
<DropdownMenuButtonText>Delete</DropdownMenuButtonText> | ||
</DropdownMenuButton> | ||
</DropdownMenuItem> | ||
</DropdownMenuContent> | ||
); | ||
}; |
63 changes: 63 additions & 0 deletions
63
...roups/components/GroupCardList/GroupCard/GroupCardContent/GroupCardDropdownMenu/index.tsx
This file contains 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,63 @@ | ||
'use client'; | ||
import { IconMenuKebab } from '@/assets/images/icons'; | ||
import { Button, DialogRoot, DropdownMenu, DropdownMenuTrigger, Icon } from '@/components/ui'; | ||
import { DeleteGroupDialogContent } from '@/features/groups/components/DeleteGroupDialogContent'; | ||
import { useAutoFocus } from '@/hooks'; | ||
import { IGroup } from '@/types/definition'; | ||
|
||
import { useState } from 'react'; | ||
|
||
import { GroupCardDropdownMenuContent } from './GroupCardDropdownMenuContent'; | ||
|
||
interface IGroupCardMenuButtonProps { | ||
/** | ||
* The ID of the group to be deleted. | ||
*/ | ||
groupId: IGroup['id']; | ||
/** | ||
* Function to handle the rename button click. | ||
*/ | ||
handleRenameClick: () => void; | ||
/** | ||
* A state of renaming input field to be opened (=true) or closed(=false) | ||
*/ | ||
isRenameFormOpen: boolean; | ||
} | ||
|
||
export const GroupCardDropdownMenu = ({ | ||
groupId, | ||
handleRenameClick, | ||
isRenameFormOpen, | ||
}: IGroupCardMenuButtonProps) => { | ||
const [isDropdownMenuOpen, setIsDropdownMenuOpen] = useState(false); | ||
const [isDeleteGroupDialogOpen, setIsDeleteGroupDialogOpen] = useState(false); | ||
|
||
const kebabRef = useAutoFocus<HTMLButtonElement>(!isDeleteGroupDialogOpen && !isRenameFormOpen); | ||
|
||
const handleDeleteClick = () => { | ||
setIsDropdownMenuOpen(false); | ||
setIsDeleteGroupDialogOpen(true); | ||
}; | ||
return ( | ||
<> | ||
<DropdownMenu open={isDropdownMenuOpen} onOpenChange={setIsDropdownMenuOpen}> | ||
<DropdownMenuTrigger asChild> | ||
<Button variant="ghost" className="w-12" ref={kebabRef}> | ||
<Icon icon={IconMenuKebab} size={4.5} /> | ||
</Button> | ||
</DropdownMenuTrigger> | ||
<GroupCardDropdownMenuContent | ||
handleRenameClick={handleRenameClick} | ||
handleDeleteClick={handleDeleteClick} | ||
/> | ||
</DropdownMenu> | ||
<DialogRoot open={isDeleteGroupDialogOpen} onOpenChange={setIsDeleteGroupDialogOpen}> | ||
<DeleteGroupDialogContent | ||
groupId={groupId} | ||
onParentClose={() => setIsDropdownMenuOpen(false)} | ||
onDialogClose={() => setIsDeleteGroupDialogOpen(false)} | ||
/> | ||
</DialogRoot> | ||
</> | ||
); | ||
}; |
51 changes: 0 additions & 51 deletions
51
...wnMenuTriggerButton/GroupCardDropdownMenuContent/DeleteGroupDialogTriggerButton/index.tsx
This file was deleted.
Oops, something went wrong.
66 changes: 0 additions & 66 deletions
66
...roupCardContent/GroupCardDropdownMenuTriggerButton/GroupCardDropdownMenuContent/index.tsx
This file was deleted.
Oops, something went wrong.
40 changes: 0 additions & 40 deletions
40
...nts/GroupCardList/GroupCard/GroupCardContent/GroupCardDropdownMenuTriggerButton/index.tsx
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,18 +1,31 @@ | ||
'use client'; | ||
import { Card } from '@/components/ui'; | ||
import { IGroup } from '@/types/definition'; | ||
|
||
import Link from 'next/link'; | ||
import { FC, useState } from 'react'; | ||
|
||
import { ContainerCount } from './ContainerCount'; | ||
import { GroupCardDropdownMenuTriggerButton } from './GroupCardDropdownMenuTriggerButton'; | ||
import { GroupCardDropdownMenu } from './GroupCardDropdownMenu'; | ||
import { RenameGroupForm } from './RenameGroupForm'; | ||
import { UserCount } from './UserCount'; | ||
|
||
interface IGroupCardContentProps { | ||
groupId: string; | ||
groupName: string; | ||
/** | ||
* the identifier of a group | ||
*/ | ||
groupId: IGroup['id']; | ||
/** | ||
* a group name used to display on each card | ||
*/ | ||
groupName: IGroup['name']; | ||
/** | ||
* the number of container which belongs to a group | ||
*/ | ||
containerCount: number; | ||
/** | ||
* the number of user who belongs to a group | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
userCount: number; | ||
} | ||
|
||
|
@@ -50,7 +63,11 @@ export const GroupCardContent: FC<IGroupCardContentProps> = ({ | |
<UserCount userCount={userCount} /> | ||
</div> | ||
</Link> | ||
<GroupCardDropdownMenuTriggerButton groupId={groupId} handleRenameClick={handleRenameClick} /> | ||
<GroupCardDropdownMenu | ||
groupId={groupId} | ||
handleRenameClick={handleRenameClick} | ||
isRenameFormOpen={isRenameFormOpen} | ||
/> | ||
</Card> | ||
); | ||
}; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for adding this!