From d4613c87f6b8852ed421afa52cc0ce657f8f0672 Mon Sep 17 00:00:00 2001 From: Charles Bochet Date: Fri, 8 Dec 2023 13:00:59 +0100 Subject: [PATCH] Fix infinite loop on sign in --- ...enCreateActivityDrawerForSelectedRowIds.ts | 1 + .../hooks/useObjectRecordTable.ts | 5 +++- .../useRecordTableContextMenuEntries.tsx | 26 +++++++++++-------- .../components/RecordTableBody.tsx | 2 +- .../hooks/internal/useSetRecordTableData.ts | 7 +++-- .../SignInBackgroundMockContainerEffect.tsx | 2 -- 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/front/src/modules/activities/hooks/useOpenCreateActivityDrawerForSelectedRowIds.ts b/front/src/modules/activities/hooks/useOpenCreateActivityDrawerForSelectedRowIds.ts index 6ffe64ca58..372cb84c55 100644 --- a/front/src/modules/activities/hooks/useOpenCreateActivityDrawerForSelectedRowIds.ts +++ b/front/src/modules/activities/hooks/useOpenCreateActivityDrawerForSelectedRowIds.ts @@ -37,5 +37,6 @@ export const useOpenCreateActivityDrawerForSelectedRowIds = () => { targetableEntities: activityTargetableEntityArray, }); }, + [openCreateActivityDrawer], ); }; diff --git a/front/src/modules/object-record/hooks/useObjectRecordTable.ts b/front/src/modules/object-record/hooks/useObjectRecordTable.ts index 32eb43d7c0..45a45bc68f 100644 --- a/front/src/modules/object-record/hooks/useObjectRecordTable.ts +++ b/front/src/modules/object-record/hooks/useObjectRecordTable.ts @@ -1,16 +1,19 @@ import { useRecoilValue, useSetRecoilState } from 'recoil'; +import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState'; import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem'; import { useObjectNameSingularFromPlural } from '@/object-metadata/hooks/useObjectNameSingularFromPlural'; import { turnFiltersIntoWhereClause } from '@/object-record/object-filter-dropdown/utils/turnFiltersIntoWhereClause'; import { turnSortsIntoOrderBy } from '@/object-record/object-sort-dropdown/utils/turnSortsIntoOrderBy'; import { useRecordTableScopedStates } from '@/object-record/record-table/hooks/internal/useRecordTableScopedStates'; import { useRecordTable } from '@/object-record/record-table/hooks/useRecordTable'; +import { signInBackgroundMockCompanies } from '@/sign-in-background-mock/constants/signInBackgroundMockCompanies'; import { useFindManyRecords } from './useFindManyRecords'; export const useObjectRecordTable = () => { const { scopeId: objectNamePlural, setRecordTableData } = useRecordTable(); + const currentWorkspace = useRecoilValue(currentWorkspaceState); const { objectNameSingular } = useObjectNameSingularFromPlural({ objectNamePlural, @@ -48,7 +51,7 @@ export const useObjectRecordTable = () => { }); return { - records, + records: currentWorkspace ? records : signInBackgroundMockCompanies, loading, fetchMoreRecords, queryStateIdentifier, diff --git a/front/src/modules/object-record/hooks/useRecordTableContextMenuEntries.tsx b/front/src/modules/object-record/hooks/useRecordTableContextMenuEntries.tsx index e82a3bc0ad..ba3eee0050 100644 --- a/front/src/modules/object-record/hooks/useRecordTableContextMenuEntries.tsx +++ b/front/src/modules/object-record/hooks/useRecordTableContextMenuEntries.tsx @@ -68,18 +68,22 @@ export const useRecordTableContextMenuEntries = ( objectNameSingular, }); - const handleDeleteClick = useRecoilCallback(({ snapshot }) => async () => { - const rowIdsToDelete = snapshot - .getLoadable(selectedRowIdsSelector) - .getValue(); + const handleDeleteClick = useRecoilCallback( + ({ snapshot }) => + async () => { + const rowIdsToDelete = snapshot + .getLoadable(selectedRowIdsSelector) + .getValue(); - resetTableRowSelection(); - await Promise.all( - rowIdsToDelete.map(async (rowId) => { - await deleteOneRecord(rowId); - }), - ); - }); + resetTableRowSelection(); + await Promise.all( + rowIdsToDelete.map(async (rowId) => { + await deleteOneRecord(rowId); + }), + ); + }, + [deleteOneRecord, resetTableRowSelection], + ); return { setContextMenuEntries: useCallback(() => { diff --git a/front/src/modules/object-record/record-table/components/RecordTableBody.tsx b/front/src/modules/object-record/record-table/components/RecordTableBody.tsx index ea0cdc7db3..0e2031af08 100644 --- a/front/src/modules/object-record/record-table/components/RecordTableBody.tsx +++ b/front/src/modules/object-record/record-table/components/RecordTableBody.tsx @@ -20,7 +20,7 @@ export const RecordTableBody = () => { return ( <> - {tableRowIds.slice().map((rowId, rowIndex) => ( + {tableRowIds.map((rowId, rowIndex) => ( diff --git a/front/src/modules/object-record/record-table/hooks/internal/useSetRecordTableData.ts b/front/src/modules/object-record/record-table/hooks/internal/useSetRecordTableData.ts index d1a17d2935..ba87f983ab 100644 --- a/front/src/modules/object-record/record-table/hooks/internal/useSetRecordTableData.ts +++ b/front/src/modules/object-record/record-table/hooks/internal/useSetRecordTableData.ts @@ -1,14 +1,13 @@ import { useRecoilCallback } from 'recoil'; import { entityFieldsFamilyState } from '@/object-record/field/states/entityFieldsFamilyState'; +import { useResetTableRowSelection } from '@/object-record/record-table/hooks/internal/useResetTableRowSelection'; +import { isFetchingRecordTableDataState } from '@/object-record/record-table/states/isFetchingRecordTableDataState'; +import { numberOfTableRowsState } from '@/object-record/record-table/states/numberOfTableRowsState'; import { isDeeplyEqual } from '~/utils/isDeeplyEqual'; -import { isFetchingRecordTableDataState } from '../../states/isFetchingRecordTableDataState'; -import { numberOfTableRowsState } from '../../states/numberOfTableRowsState'; import { tableRowIdsState } from '../../states/tableRowIdsState'; -import { useResetTableRowSelection } from './useResetTableRowSelection'; - type useSetRecordTableDataProps = { onEntityCountChange: (entityCount: number) => void; }; diff --git a/front/src/modules/sign-in-background-mock/components/SignInBackgroundMockContainerEffect.tsx b/front/src/modules/sign-in-background-mock/components/SignInBackgroundMockContainerEffect.tsx index f56a4067fa..9be294d11c 100644 --- a/front/src/modules/sign-in-background-mock/components/SignInBackgroundMockContainerEffect.tsx +++ b/front/src/modules/sign-in-background-mock/components/SignInBackgroundMockContainerEffect.tsx @@ -5,7 +5,6 @@ import { useObjectNameSingularFromPlural } from '@/object-metadata/hooks/useObje import { useRecordTableContextMenuEntries } from '@/object-record/hooks/useRecordTableContextMenuEntries'; import { useRecordTable } from '@/object-record/record-table/hooks/useRecordTable'; import { filterAvailableTableColumns } from '@/object-record/utils/filterAvailableTableColumns'; -import { signInBackgroundMockCompanies } from '@/sign-in-background-mock/constants/signInBackgroundMockCompanies'; import { signInBackgroundMockColumnDefinitions, signInBackgroundMockFilterDefinitions, @@ -66,7 +65,6 @@ export const SignInBackgroundMockContainerEffect = ({ ); setAvailableTableColumns(availableTableColumns); - setRecordTableData(signInBackgroundMockCompanies); setTableColumns( mapViewFieldsToColumnDefinitions(