From 44d3c82ddc02704d45ca870dab4d7a288415e977 Mon Sep 17 00:00:00 2001 From: Adithya Thejas Date: Wed, 26 Jun 2024 12:18:19 +0530 Subject: [PATCH 1/3] hide delete button for selection over 100 --- .../record-action-bar/hooks/useRecordActionBar.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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..2f6120e7b288 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 @@ -138,7 +138,9 @@ export const useRecordActionBar = ({ ); const deletionActions: ContextMenuEntry[] = useMemo( - () => [ + () => + selectedRecordIds.length <= 100 + ? [ { label: 'Delete', Icon: IconTrash, @@ -161,7 +163,7 @@ export const useRecordActionBar = ({ /> ), }, - ], + ] : [], [ handleDeleteClick, selectedRecordIds, From cbd52c786543a4a0945cba17bba0b836b36c51d8 Mon Sep 17 00:00:00 2001 From: Adithya Thejas Date: Thu, 27 Jun 2024 11:09:26 +0530 Subject: [PATCH 2/3] configured maxRecords value from apiConfigState. --- .../record-action-bar/hooks/useRecordActionBar.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 2f6120e7b288..12f5a123ea96 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, useSetRecoilState, useRecoilValue } from 'recoil'; import { IconClick, IconFileExport, @@ -26,6 +26,7 @@ import { contextMenuEntriesState } from '@/ui/navigation/context-menu/states/con import { ContextMenuEntry } from '@/ui/navigation/context-menu/types/ContextMenuEntry'; import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled'; import { isDefined } from '~/utils/isDefined'; +import { apiConfigState } from '@/client-config/states/apiConfigState'; type useRecordActionBarProps = { objectMetadataItem: ObjectMetadataItem; @@ -53,6 +54,9 @@ export const useRecordActionBar = ({ objectNameSingular: objectMetadataItem.nameSingular, }); + const apiConfig = useRecoilValue(apiConfigState); + const maxRecords = apiConfig?.mutationMaximumAffectedRecords; + const handleFavoriteButtonClick = useRecoilCallback( ({ snapshot }) => () => { @@ -139,7 +143,7 @@ export const useRecordActionBar = ({ const deletionActions: ContextMenuEntry[] = useMemo( () => - selectedRecordIds.length <= 100 + maxRecords !== undefined && selectedRecordIds.length <= maxRecords ? [ { label: 'Delete', @@ -169,6 +173,7 @@ export const useRecordActionBar = ({ selectedRecordIds, isDeleteRecordsModalOpen, setIsDeleteRecordsModalOpen, + maxRecords, ], ); From 9c6376efeb53ef6c189ed5ef857059a3a626e81e Mon Sep 17 00:00:00 2001 From: Weiko Date: Thu, 27 Jun 2024 10:16:34 +0200 Subject: [PATCH 3/3] apply linter --- .../hooks/useRecordActionBar.tsx | 59 ++++++++++--------- 1 file changed, 31 insertions(+), 28 deletions(-) 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 12f5a123ea96..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, useRecoilValue } 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'; @@ -26,7 +27,6 @@ import { contextMenuEntriesState } from '@/ui/navigation/context-menu/states/con import { ContextMenuEntry } from '@/ui/navigation/context-menu/types/ContextMenuEntry'; import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled'; import { isDefined } from '~/utils/isDefined'; -import { apiConfigState } from '@/client-config/states/apiConfigState'; type useRecordActionBarProps = { objectMetadataItem: ObjectMetadataItem; @@ -142,32 +142,35 @@ export const useRecordActionBar = ({ ); const deletionActions: ContextMenuEntry[] = useMemo( - () => - maxRecords !== undefined && selectedRecordIds.length <= maxRecords - ? [ - { - 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,