Skip to content

Commit cd4800e

Browse files
Fix exception handling on messaging + optimistic on object delete (#14894)
## What In this PR, we are fixing two issues: - while deleting an object, the views are not properly refreshed leading to FE bug. This is due to the fact that we were refetching **views associated to the object** which has been deleted. As views are properly deleted in the BE, the FE gets no views from this call and cannot optimistically react. In this case, I'm triggering a complete view refetch - messaging error handling had a hole
1 parent 888bf45 commit cd4800e

File tree

5 files changed

+33
-15
lines changed

5 files changed

+33
-15
lines changed

packages/twenty-front/src/modules/object-metadata/hooks/__tests__/useDeleteOneObjectMetadataItem.test.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ import {
1212
} from '../__mocks__/useDeleteOneObjectMetadataItem';
1313

1414
import { GET_CURRENT_USER } from '@/users/graphql/queries/getCurrentUser';
15+
import { FIND_ALL_CORE_VIEWS } from '@/views/graphql/queries/findAllCoreViews';
16+
import { mockedUserData } from '~/testing/mock-data/users';
17+
import { mockedCoreViewsData } from '~/testing/mock-data/views';
1518
import {
1619
query as findManyObjectMetadataItemsQuery,
1720
responseData as findManyObjectMetadataItemsResponseData,
1821
} from '../__mocks__/useFindManyObjectMetadataItems';
19-
import { mockedUserData } from '~/testing/mock-data/users';
2022

2123
const mocks = [
2224
{
@@ -41,6 +43,17 @@ const mocks = [
4143
},
4244
})),
4345
},
46+
{
47+
request: {
48+
query: FIND_ALL_CORE_VIEWS,
49+
variables: {},
50+
},
51+
result: jest.fn(() => ({
52+
data: {
53+
getCoreViews: mockedCoreViewsData,
54+
},
55+
})),
56+
},
4457
{
4558
request: {
4659
query: findManyObjectMetadataItemsQuery,

packages/twenty-front/src/modules/object-metadata/hooks/useDeleteOneObjectMetadataItem.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
import { DELETE_ONE_OBJECT_METADATA_ITEM } from '../graphql/mutations';
99

1010
import { useRefreshObjectMetadataItems } from '@/object-metadata/hooks/useRefreshObjectMetadataItems';
11-
import { useRefreshCoreViewsByObjectMetadataId } from '@/views/hooks/useRefreshCoreViewsByObjectMetadataId';
11+
import { useRefreshAllCoreViews } from '@/views/hooks/useRefreshAllCoreViews';
1212

1313
export const useDeleteOneObjectMetadataItem = () => {
1414
const [mutate] = useMutation<
@@ -19,8 +19,7 @@ export const useDeleteOneObjectMetadataItem = () => {
1919
const { refreshObjectMetadataItems } =
2020
useRefreshObjectMetadataItems('network-only');
2121

22-
const { refreshCoreViewsByObjectMetadataId } =
23-
useRefreshCoreViewsByObjectMetadataId();
22+
const { refreshAllCoreViews } = useRefreshAllCoreViews();
2423

2524
const deleteOneObjectMetadataItem = async (
2625
idToDelete: DeleteOneObjectMetadataItemMutationVariables['idToDelete'],
@@ -32,7 +31,7 @@ export const useDeleteOneObjectMetadataItem = () => {
3231
});
3332

3433
await refreshObjectMetadataItems();
35-
await refreshCoreViewsByObjectMetadataId(idToDelete);
34+
await refreshAllCoreViews();
3635

3736
return result;
3837
};

packages/twenty-front/src/modules/views/hooks/useRefreshAllCoreViews.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
import { FIND_ALL_CORE_VIEWS } from '@/views/graphql/queries/findAllCoreViews';
12
import { coreViewsState } from '@/views/states/coreViewState';
23
import { type FetchPolicy, useApolloClient } from '@apollo/client';
34
import { useRecoilCallback } from 'recoil';
45
import { isDefined } from 'twenty-shared/utils';
5-
import { type FindManyCoreViewsQuery } from '~/generated/graphql';
6+
import { type FindAllCoreViewsQuery } from '~/generated/graphql';
67
import { isDeeplyEqual } from '~/utils/isDeeplyEqual';
7-
import { FIND_MANY_CORE_VIEWS } from '../graphql/queries/findManyCoreViews';
88

99
export const useRefreshAllCoreViews = (
1010
fetchPolicy: FetchPolicy = 'network-only',
@@ -14,8 +14,8 @@ export const useRefreshAllCoreViews = (
1414
const refreshAllCoreViews = useRecoilCallback(
1515
({ snapshot, set }) =>
1616
async () => {
17-
const result = await client.query<FindManyCoreViewsQuery>({
18-
query: FIND_MANY_CORE_VIEWS,
17+
const result = await client.query<FindAllCoreViewsQuery>({
18+
query: FIND_ALL_CORE_VIEWS,
1919
variables: {},
2020
fetchPolicy,
2121
});

packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-import-exception-handler.service.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from 'src/modules/messaging/common/standard-objects/message-channel.workspace-entity';
1616
import { MESSAGING_THROTTLE_MAX_ATTEMPTS } from 'src/modules/messaging/message-import-manager/constants/messaging-throttle-max-attempts';
1717
import {
18-
type MessageImportDriverException,
18+
MessageImportDriverException,
1919
MessageImportDriverExceptionCode,
2020
} from 'src/modules/messaging/message-import-manager/drivers/exceptions/message-import-driver.exception';
2121
import { MessageNetworkExceptionCode } from 'src/modules/messaging/message-import-manager/drivers/exceptions/message-network.exception';
@@ -25,7 +25,6 @@ import {
2525
} from 'src/modules/messaging/message-import-manager/exceptions/message-import.exception';
2626

2727
export enum MessageImportSyncStep {
28-
FULL_MESSAGE_LIST_FETCH = 'FULL_MESSAGE_LIST_FETCH', // TODO: deprecate to only use MESSAGE_LIST_FETCH
2928
MESSAGE_LIST_FETCH = 'MESSAGE_LIST_FETCH',
3029
MESSAGES_IMPORT_PENDING = 'MESSAGES_IMPORT_PENDING',
3130
MESSAGES_IMPORT_ONGOING = 'MESSAGES_IMPORT_ONGOING',
@@ -150,7 +149,7 @@ export class MessageImportExceptionHandlerService {
150149
);
151150

152151
switch (syncStep) {
153-
case MessageImportSyncStep.FULL_MESSAGE_LIST_FETCH:
152+
case MessageImportSyncStep.MESSAGE_LIST_FETCH:
154153
await this.messageChannelSyncStatusService.scheduleMessageListFetch([
155154
messageChannel.id,
156155
]);
@@ -230,8 +229,15 @@ export class MessageImportExceptionHandlerService {
230229
messageChannel: Pick<MessageChannelWorkspaceEntity, 'id'>,
231230
workspaceId: string,
232231
): Promise<void> {
233-
if (syncStep === MessageImportSyncStep.FULL_MESSAGE_LIST_FETCH) {
234-
return;
232+
if (syncStep === MessageImportSyncStep.MESSAGE_LIST_FETCH) {
233+
await this.handleUnknownException(
234+
new MessageImportDriverException(
235+
'Not Found exception occurred while fetching message list, which should never happen',
236+
MessageImportDriverExceptionCode.UNKNOWN,
237+
),
238+
messageChannel,
239+
workspaceId,
240+
);
235241
}
236242

237243
await this.messageChannelSyncStatusService.resetAndScheduleMessageListFetch(

packages/twenty-server/src/modules/messaging/message-import-manager/services/messaging-message-list-fetch.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ export class MessagingMessageListFetchService {
257257
} catch (error) {
258258
await this.messageImportErrorHandlerService.handleDriverException(
259259
error,
260-
MessageImportSyncStep.FULL_MESSAGE_LIST_FETCH,
260+
MessageImportSyncStep.MESSAGE_LIST_FETCH,
261261
messageChannel,
262262
workspaceId,
263263
);

0 commit comments

Comments
 (0)