Fix infinite loop on sign in

This commit is contained in:
Charles Bochet 2023-12-08 13:00:59 +01:00
parent e89546466c
commit d4613c87f6
6 changed files with 24 additions and 19 deletions

View File

@ -37,5 +37,6 @@ export const useOpenCreateActivityDrawerForSelectedRowIds = () => {
targetableEntities: activityTargetableEntityArray, targetableEntities: activityTargetableEntityArray,
}); });
}, },
[openCreateActivityDrawer],
); );
}; };

View File

@ -1,16 +1,19 @@
import { useRecoilValue, useSetRecoilState } from 'recoil'; import { useRecoilValue, useSetRecoilState } from 'recoil';
import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem'; import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { useObjectNameSingularFromPlural } from '@/object-metadata/hooks/useObjectNameSingularFromPlural'; import { useObjectNameSingularFromPlural } from '@/object-metadata/hooks/useObjectNameSingularFromPlural';
import { turnFiltersIntoWhereClause } from '@/object-record/object-filter-dropdown/utils/turnFiltersIntoWhereClause'; import { turnFiltersIntoWhereClause } from '@/object-record/object-filter-dropdown/utils/turnFiltersIntoWhereClause';
import { turnSortsIntoOrderBy } from '@/object-record/object-sort-dropdown/utils/turnSortsIntoOrderBy'; import { turnSortsIntoOrderBy } from '@/object-record/object-sort-dropdown/utils/turnSortsIntoOrderBy';
import { useRecordTableScopedStates } from '@/object-record/record-table/hooks/internal/useRecordTableScopedStates'; import { useRecordTableScopedStates } from '@/object-record/record-table/hooks/internal/useRecordTableScopedStates';
import { useRecordTable } from '@/object-record/record-table/hooks/useRecordTable'; import { useRecordTable } from '@/object-record/record-table/hooks/useRecordTable';
import { signInBackgroundMockCompanies } from '@/sign-in-background-mock/constants/signInBackgroundMockCompanies';
import { useFindManyRecords } from './useFindManyRecords'; import { useFindManyRecords } from './useFindManyRecords';
export const useObjectRecordTable = () => { export const useObjectRecordTable = () => {
const { scopeId: objectNamePlural, setRecordTableData } = useRecordTable(); const { scopeId: objectNamePlural, setRecordTableData } = useRecordTable();
const currentWorkspace = useRecoilValue(currentWorkspaceState);
const { objectNameSingular } = useObjectNameSingularFromPlural({ const { objectNameSingular } = useObjectNameSingularFromPlural({
objectNamePlural, objectNamePlural,
@ -48,7 +51,7 @@ export const useObjectRecordTable = () => {
}); });
return { return {
records, records: currentWorkspace ? records : signInBackgroundMockCompanies,
loading, loading,
fetchMoreRecords, fetchMoreRecords,
queryStateIdentifier, queryStateIdentifier,

View File

@ -68,7 +68,9 @@ export const useRecordTableContextMenuEntries = (
objectNameSingular, objectNameSingular,
}); });
const handleDeleteClick = useRecoilCallback(({ snapshot }) => async () => { const handleDeleteClick = useRecoilCallback(
({ snapshot }) =>
async () => {
const rowIdsToDelete = snapshot const rowIdsToDelete = snapshot
.getLoadable(selectedRowIdsSelector) .getLoadable(selectedRowIdsSelector)
.getValue(); .getValue();
@ -79,7 +81,9 @@ export const useRecordTableContextMenuEntries = (
await deleteOneRecord(rowId); await deleteOneRecord(rowId);
}), }),
); );
}); },
[deleteOneRecord, resetTableRowSelection],
);
return { return {
setContextMenuEntries: useCallback(() => { setContextMenuEntries: useCallback(() => {

View File

@ -20,7 +20,7 @@ export const RecordTableBody = () => {
return ( return (
<> <>
{tableRowIds.slice().map((rowId, rowIndex) => ( {tableRowIds.map((rowId, rowIndex) => (
<RowIdContext.Provider value={rowId} key={rowId}> <RowIdContext.Provider value={rowId} key={rowId}>
<RowIndexContext.Provider value={rowIndex}> <RowIndexContext.Provider value={rowIndex}>
<RecordTableRow key={rowId} rowId={rowId} /> <RecordTableRow key={rowId} rowId={rowId} />

View File

@ -1,14 +1,13 @@
import { useRecoilCallback } from 'recoil'; import { useRecoilCallback } from 'recoil';
import { entityFieldsFamilyState } from '@/object-record/field/states/entityFieldsFamilyState'; 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 { isDeeplyEqual } from '~/utils/isDeeplyEqual';
import { isFetchingRecordTableDataState } from '../../states/isFetchingRecordTableDataState';
import { numberOfTableRowsState } from '../../states/numberOfTableRowsState';
import { tableRowIdsState } from '../../states/tableRowIdsState'; import { tableRowIdsState } from '../../states/tableRowIdsState';
import { useResetTableRowSelection } from './useResetTableRowSelection';
type useSetRecordTableDataProps = { type useSetRecordTableDataProps = {
onEntityCountChange: (entityCount: number) => void; onEntityCountChange: (entityCount: number) => void;
}; };

View File

@ -5,7 +5,6 @@ import { useObjectNameSingularFromPlural } from '@/object-metadata/hooks/useObje
import { useRecordTableContextMenuEntries } from '@/object-record/hooks/useRecordTableContextMenuEntries'; import { useRecordTableContextMenuEntries } from '@/object-record/hooks/useRecordTableContextMenuEntries';
import { useRecordTable } from '@/object-record/record-table/hooks/useRecordTable'; import { useRecordTable } from '@/object-record/record-table/hooks/useRecordTable';
import { filterAvailableTableColumns } from '@/object-record/utils/filterAvailableTableColumns'; import { filterAvailableTableColumns } from '@/object-record/utils/filterAvailableTableColumns';
import { signInBackgroundMockCompanies } from '@/sign-in-background-mock/constants/signInBackgroundMockCompanies';
import { import {
signInBackgroundMockColumnDefinitions, signInBackgroundMockColumnDefinitions,
signInBackgroundMockFilterDefinitions, signInBackgroundMockFilterDefinitions,
@ -66,7 +65,6 @@ export const SignInBackgroundMockContainerEffect = ({
); );
setAvailableTableColumns(availableTableColumns); setAvailableTableColumns(availableTableColumns);
setRecordTableData(signInBackgroundMockCompanies);
setTableColumns( setTableColumns(
mapViewFieldsToColumnDefinitions( mapViewFieldsToColumnDefinitions(