diff --git a/packages/twenty-front/src/modules/object-record/record-action-bar/hooks/useRecordActionBar.tsx b/packages/twenty-front/src/modules/object-record/record-action-bar/hooks/useRecordActionBar.tsx index 3333ead34719..70e35b0a5955 100644 --- a/packages/twenty-front/src/modules/object-record/record-action-bar/hooks/useRecordActionBar.tsx +++ b/packages/twenty-front/src/modules/object-record/record-action-bar/hooks/useRecordActionBar.tsx @@ -1,6 +1,6 @@ import { useCallback, useMemo, useState } from 'react'; import { isNonEmptyString } from '@sniptt/guards'; -import { useRecoilCallback, useSetRecoilState } from 'recoil'; +import { useRecoilCallback, useRecoilValue, useSetRecoilState } from 'recoil'; import { IconClick, IconFileExport, @@ -11,6 +11,7 @@ import { IconTrash, } from 'twenty-ui'; +import { apiConfigState } from '@/client-config/states/apiConfigState'; import { useFavorites } from '@/favorites/hooks/useFavorites'; import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem'; import { useDeleteManyRecords } from '@/object-record/hooks/useDeleteManyRecords'; @@ -53,6 +54,9 @@ export const useRecordActionBar = ({ objectNameSingular: objectMetadataItem.nameSingular, }); + const apiConfig = useRecoilValue(apiConfigState); + const maxRecords = apiConfig?.mutationMaximumAffectedRecords; + const handleFavoriteButtonClick = useRecoilCallback( ({ snapshot }) => () => { @@ -138,35 +142,41 @@ export const useRecordActionBar = ({ ); const deletionActions: ContextMenuEntry[] = useMemo( - () => [ - { - label: 'Delete', - Icon: IconTrash, - accent: 'danger', - onClick: () => setIsDeleteRecordsModalOpen(true), - ConfirmationModal: ( - handleDeleteClick()} - deleteButtonText={`Delete ${ - selectedRecordIds.length > 1 ? 'Records' : 'Record' - }`} - /> - ), - }, - ], + () => + maxRecords !== undefined && selectedRecordIds.length <= maxRecords + ? [ + { + label: 'Delete', + Icon: IconTrash, + accent: 'danger', + onClick: () => setIsDeleteRecordsModalOpen(true), + ConfirmationModal: ( + handleDeleteClick()} + deleteButtonText={`Delete ${ + selectedRecordIds.length > 1 ? 'Records' : 'Record' + }`} + /> + ), + }, + ] + : [], [ handleDeleteClick, selectedRecordIds, isDeleteRecordsModalOpen, setIsDeleteRecordsModalOpen, + maxRecords, ], );