hide delete button for selection over 100 - issue #6023 (#6030)

hide the "Delete" Button when more than 100 records are Selected

---------

Co-authored-by: Weiko <corentin@twenty.com>
This commit is contained in:
ADITHYA THEJAS S 2024-06-27 14:51:45 +05:30 committed by GitHub
parent 97822533db
commit dcb709feee
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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: (
<ConfirmationModal
isOpen={isDeleteRecordsModalOpen}
setIsOpen={setIsDeleteRecordsModalOpen}
title={`Delete ${selectedRecordIds.length} ${
selectedRecordIds.length === 1 ? `record` : 'records'
}`}
subtitle={`This action cannot be undone. This will permanently delete ${
selectedRecordIds.length === 1 ? 'this record' : 'these records'
}`}
onConfirmClick={() => handleDeleteClick()}
deleteButtonText={`Delete ${
selectedRecordIds.length > 1 ? 'Records' : 'Record'
}`}
/>
),
},
],
() =>
maxRecords !== undefined && selectedRecordIds.length <= maxRecords
? [
{
label: 'Delete',
Icon: IconTrash,
accent: 'danger',
onClick: () => setIsDeleteRecordsModalOpen(true),
ConfirmationModal: (
<ConfirmationModal
isOpen={isDeleteRecordsModalOpen}
setIsOpen={setIsDeleteRecordsModalOpen}
title={`Delete ${selectedRecordIds.length} ${
selectedRecordIds.length === 1 ? `record` : 'records'
}`}
subtitle={`This action cannot be undone. This will permanently delete ${
selectedRecordIds.length === 1
? 'this record'
: 'these records'
}`}
onConfirmClick={() => handleDeleteClick()}
deleteButtonText={`Delete ${
selectedRecordIds.length > 1 ? 'Records' : 'Record'
}`}
/>
),
},
]
: [],
[
handleDeleteClick,
selectedRecordIds,
isDeleteRecordsModalOpen,
setIsDeleteRecordsModalOpen,
maxRecords,
],
);