-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update ShowPageMoreButton to open the command menu when clicked (#8565)
- Loading branch information
1 parent
e1a730a
commit 9810c5b
Showing
2 changed files
with
13 additions
and
130 deletions.
There are no files selected for viewing
136 changes: 12 additions & 124 deletions
136
packages/twenty-front/src/modules/ui/layout/show-page/components/ShowPageMoreButton.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 |
---|---|---|
@@ -1,130 +1,18 @@ | ||
import styled from '@emotion/styled'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import { useRecoilState, useRecoilValue } from 'recoil'; | ||
import { | ||
IconButton, | ||
IconDotsVertical, | ||
IconRestore, | ||
IconTrash, | ||
MenuItem, | ||
} from 'twenty-ui'; | ||
import { IconButton, IconDotsVertical } from 'twenty-ui'; | ||
|
||
import { useDeleteOneRecord } from '@/object-record/hooks/useDeleteOneRecord'; | ||
import { PageHotkeyScope } from '@/types/PageHotkeyScope'; | ||
import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer'; | ||
import { useDropdown } from '@/ui/layout/dropdown/hooks/useDropdown'; | ||
import { navigationMemorizedUrlState } from '@/ui/navigation/states/navigationMemorizedUrlState'; | ||
import { useCommandMenu } from '@/command-menu/hooks/useCommandMenu'; | ||
|
||
import { isObjectMetadataReadOnly } from '@/object-metadata/utils/isObjectMetadataReadOnly'; | ||
import { useDestroyOneRecord } from '@/object-record/hooks/useDestroyOneRecord'; | ||
import { useRestoreManyRecords } from '@/object-record/hooks/useRestoreManyRecords'; | ||
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState'; | ||
import { Dropdown } from '../../dropdown/components/Dropdown'; | ||
import { DropdownMenu } from '../../dropdown/components/DropdownMenu'; | ||
|
||
const StyledContainer = styled.div` | ||
z-index: 1; | ||
`; | ||
|
||
export const ShowPageMoreButton = ({ | ||
recordId, | ||
objectNameSingular, | ||
isRemote, | ||
}: { | ||
recordId: string; | ||
objectNameSingular: string; | ||
isRemote: boolean; | ||
}) => { | ||
const { closeDropdown, toggleDropdown } = useDropdown('more-show-page'); | ||
const navigationMemorizedUrl = useRecoilValue(navigationMemorizedUrlState); | ||
const navigate = useNavigate(); | ||
|
||
const { deleteOneRecord } = useDeleteOneRecord({ | ||
objectNameSingular, | ||
}); | ||
const { destroyOneRecord } = useDestroyOneRecord({ | ||
objectNameSingular, | ||
}); | ||
const { restoreManyRecords } = useRestoreManyRecords({ | ||
objectNameSingular, | ||
}); | ||
|
||
const handleDelete = () => { | ||
deleteOneRecord(recordId); | ||
closeDropdown(); | ||
}; | ||
|
||
const handleDestroy = () => { | ||
destroyOneRecord(recordId); | ||
closeDropdown(); | ||
navigate(navigationMemorizedUrl, { replace: true }); | ||
}; | ||
|
||
const handleRestore = () => { | ||
restoreManyRecords([recordId]); | ||
closeDropdown(); | ||
}; | ||
|
||
const [recordFromStore] = useRecoilState<any>( | ||
recordStoreFamilyState(recordId), | ||
); | ||
|
||
if ( | ||
isObjectMetadataReadOnly({ | ||
isRemote, | ||
nameSingular: objectNameSingular, | ||
}) | ||
) { | ||
return; | ||
} | ||
export const ShowPageMoreButton = () => { | ||
const { openCommandMenu } = useCommandMenu(); | ||
|
||
return ( | ||
<StyledContainer> | ||
<Dropdown | ||
dropdownId="more-show-page" | ||
clickableComponent={ | ||
<IconButton | ||
Icon={IconDotsVertical} | ||
size="medium" | ||
dataTestId="more-showpage-button" | ||
accent="default" | ||
variant="secondary" | ||
onClick={toggleDropdown} | ||
/> | ||
} | ||
dropdownComponents={ | ||
<DropdownMenu> | ||
<DropdownMenuItemsContainer> | ||
{recordFromStore && !recordFromStore.deletedAt && ( | ||
<MenuItem | ||
onClick={handleDelete} | ||
accent="danger" | ||
LeftIcon={IconTrash} | ||
text="Delete" | ||
/> | ||
)} | ||
{recordFromStore && recordFromStore.deletedAt && ( | ||
<> | ||
<MenuItem | ||
onClick={handleDestroy} | ||
accent="danger" | ||
LeftIcon={IconTrash} | ||
text="Destroy" | ||
/> | ||
<MenuItem | ||
onClick={handleRestore} | ||
LeftIcon={IconRestore} | ||
text="Restore" | ||
/> | ||
</> | ||
)} | ||
</DropdownMenuItemsContainer> | ||
</DropdownMenu> | ||
} | ||
dropdownHotkeyScope={{ | ||
scope: PageHotkeyScope.ShowPage, | ||
}} | ||
/> | ||
</StyledContainer> | ||
<IconButton | ||
Icon={IconDotsVertical} | ||
size="medium" | ||
dataTestId="more-showpage-button" | ||
accent="default" | ||
variant="secondary" | ||
onClick={openCommandMenu} | ||
/> | ||
); | ||
}; |
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