mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-25 21:13:01 +03:00
hide the "Delete" Button when more than 100 records are Selected --------- Co-authored-by: Weiko <corentin@twenty.com>
This commit is contained in:
parent
97822533db
commit
dcb709feee
@ -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,
|
||||
],
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user