fix: duplicate merge button bug (#15284)
Fixes - https://github.com/twentyhq/twenty/issues/15263 - Replaced `useLoadSelectedRecordsInContextStore` with `useLoadMergeRecords` in `useOpenMergeRecordsPageInCommandMenu` for improved functionality. - Updated `useMergePreview`, `useMergeRecordsActions`, and `useMergeRecordsSettings` to utilize `mergeRecordsState` instead of the deprecated context store hook. - Cleaned up imports and ensured consistency across merge-related hooks. https://github.com/user-attachments/assets/453539c9-7f2b-4e8c-bfa1-3ceebca07081 --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
-74
@@ -1,74 +0,0 @@
|
||||
import { MAIN_CONTEXT_STORE_INSTANCE_ID } from '@/context-store/constants/MainContextStoreInstanceId';
|
||||
import { contextStoreCurrentObjectMetadataItemIdComponentState } from '@/context-store/states/contextStoreCurrentObjectMetadataItemIdComponentState';
|
||||
import { contextStoreNumberOfSelectedRecordsComponentState } from '@/context-store/states/contextStoreNumberOfSelectedRecordsComponentState';
|
||||
import { contextStoreTargetedRecordsRuleComponentState } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState';
|
||||
import { useLazyFindManyRecords } from '@/object-record/hooks/useLazyFindManyRecords';
|
||||
import { useUpsertRecordsInStore } from '@/object-record/record-store/hooks/useUpsertRecordsInStore';
|
||||
import { useRecoilCallback } from 'recoil';
|
||||
|
||||
type UseLoadSelectedRecordsInContextStoreProps = {
|
||||
objectNameSingular: string;
|
||||
objectRecordIds: string[];
|
||||
objectMetadataItemId: string;
|
||||
};
|
||||
|
||||
export const useLoadSelectedRecordsInContextStore = ({
|
||||
objectNameSingular,
|
||||
objectRecordIds,
|
||||
objectMetadataItemId,
|
||||
}: UseLoadSelectedRecordsInContextStoreProps) => {
|
||||
const { upsertRecordsInStore } = useUpsertRecordsInStore();
|
||||
|
||||
const { findManyRecordsLazy } = useLazyFindManyRecords({
|
||||
objectNameSingular,
|
||||
filter: {
|
||||
id: {
|
||||
in: objectRecordIds,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const loadSelectedRecordsInContextStore = useRecoilCallback(
|
||||
({ set }) => {
|
||||
return async () => {
|
||||
set(
|
||||
contextStoreCurrentObjectMetadataItemIdComponentState.atomFamily({
|
||||
instanceId: MAIN_CONTEXT_STORE_INSTANCE_ID,
|
||||
}),
|
||||
objectMetadataItemId,
|
||||
);
|
||||
|
||||
set(
|
||||
contextStoreTargetedRecordsRuleComponentState.atomFamily({
|
||||
instanceId: MAIN_CONTEXT_STORE_INSTANCE_ID,
|
||||
}),
|
||||
{
|
||||
mode: 'selection',
|
||||
selectedRecordIds: objectRecordIds,
|
||||
},
|
||||
);
|
||||
|
||||
set(
|
||||
contextStoreNumberOfSelectedRecordsComponentState.atomFamily({
|
||||
instanceId: MAIN_CONTEXT_STORE_INSTANCE_ID,
|
||||
}),
|
||||
objectRecordIds.length,
|
||||
);
|
||||
|
||||
const { records } = await findManyRecordsLazy();
|
||||
|
||||
upsertRecordsInStore(records ?? []);
|
||||
};
|
||||
},
|
||||
[
|
||||
objectRecordIds,
|
||||
objectMetadataItemId,
|
||||
findManyRecordsLazy,
|
||||
upsertRecordsInStore,
|
||||
],
|
||||
);
|
||||
|
||||
return {
|
||||
loadSelectedRecordsInContextStore,
|
||||
};
|
||||
};
|
||||
@@ -103,12 +103,11 @@ export const useMergeManyRecords = <
|
||||
|
||||
if (!preview) {
|
||||
await refetchAggregateQueries();
|
||||
registerObjectOperation(objectNameSingular, {
|
||||
type: 'merge-records',
|
||||
});
|
||||
}
|
||||
|
||||
registerObjectOperation(objectNameSingular, {
|
||||
type: 'merge-records',
|
||||
});
|
||||
|
||||
return mergedObject.data?.[mutationResponseField] ?? null;
|
||||
} catch (error) {
|
||||
setLoading(false);
|
||||
|
||||
Reference in New Issue
Block a user