Skip to content

Commit

Permalink
Merge branch 'main' of github.com:twentyhq/twenty into fix-re-render-…
Browse files Browse the repository at this point in the history
…view-groups
  • Loading branch information
ijreilly committed Dec 19, 2024
2 parents a8d97b5 + 5357624 commit e5d2c12
Show file tree
Hide file tree
Showing 40 changed files with 1,631 additions and 1,070 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ import { useFavorites } from '@/favorites/hooks/useFavorites';
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
import { DELETE_MAX_COUNT } from '@/object-record/constants/DeleteMaxCount';
import { useDeleteManyRecords } from '@/object-record/hooks/useDeleteManyRecords';
import { useFetchAllRecordIds } from '@/object-record/hooks/useFetchAllRecordIds';
import { useRecordTable } from '@/object-record/record-table/hooks/useRecordTable';
import { ConfirmationModal } from '@/ui/layout/modal/components/ConfirmationModal';
import { useRightDrawer } from '@/ui/layout/right-drawer/hooks/useRightDrawer';
import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';
import { useCallback, useContext, useState } from 'react';
import { IconTrash, isDefined } from 'twenty-ui';
import { useLazyFetchAllRecords } from '@/object-record/hooks/useLazyFetchAllRecords';
import { DEFAULT_QUERY_PAGE_SIZE } from '@/object-record/constants/DefaultQueryPageSize';

export const useDeleteMultipleRecordsAction = ({
objectMetadataItem,
Expand Down Expand Up @@ -60,15 +61,18 @@ export const useDeleteMultipleRecordsAction = ({
objectMetadataItem,
);

const { fetchAllRecordIds } = useFetchAllRecordIds({
const { fetchAllRecords: fetchAllRecordIds } = useLazyFetchAllRecords({
objectNameSingular: objectMetadataItem.nameSingular,
filter: graphqlFilter,
limit: DEFAULT_QUERY_PAGE_SIZE,
recordGqlFields: { id: true },
});

const { closeRightDrawer } = useRightDrawer();

const handleDeleteClick = useCallback(async () => {
const recordIdsToDelete = await fetchAllRecordIds();
const recordsToDelete = await fetchAllRecordIds();
const recordIdsToDelete = recordsToDelete.map((record) => record.id);

resetTableRowSelection();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ export const CurrentWorkspaceMemberFavorites = ({
itemComponent={
<NavigationDrawerSubItem
label={favorite.labelIdentifier}
objectName={favorite.objectNameSingular}
Icon={() => <FavoriteIcon favorite={favorite} />}
to={favorite.link}
active={index === selectedFavoriteIndex}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const CurrentWorkspaceMemberOrphanFavorites = () => {
accent="tertiary"
/>
}
objectName={favorite.objectNameSingular}
isDragging={isDragging}
/>
</StyledOrphanFavoritesContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ import {
NavigationDrawerProps,
} from '@/ui/navigation/navigation-drawer/components/NavigationDrawer';
import { isAdvancedModeEnabledState } from '@/ui/navigation/navigation-drawer/states/isAdvancedModeEnabledState';
import { getImageAbsoluteURI } from 'twenty-shared';
import { REACT_APP_SERVER_BASE_URL } from '~/config';

import { useIsSettingsDrawer } from '@/navigation/hooks/useIsSettingsDrawer';

import { MainNavigationDrawerItems } from '@/navigation/components/MainNavigationDrawerItems';
import { isNonEmptyString } from '@sniptt/guards';
import { AdvancedSettingsToggle } from 'twenty-ui';

export type AppNavigationDrawerProps = {
Expand All @@ -41,15 +38,11 @@ export const AppNavigationDrawer = ({
setIsAdvancedModeEnabled={setIsAdvancedModeEnabled}
/>
),
logo: '',
}
: {
logo: isNonEmptyString(currentWorkspace?.logo)
? getImageAbsoluteURI({
imageUrl: currentWorkspace.logo,
baseUrl: REACT_APP_SERVER_BASE_URL,
})
: undefined,
title: currentWorkspace?.displayName ?? undefined,
logo: currentWorkspace?.logo ?? '',
title: currentWorkspace?.displayName ?? '',
children: <MainNavigationDrawerItems />,
footer: <SupportDropdown />,
};
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
import { generatedMockObjectMetadataItems } from '~/testing/mock-data/generatedMockObjectMetadataItems';
import { act, renderHook, waitFor } from '@testing-library/react';
import { expect } from '@storybook/test';
import { useLazyFetchAllRecords } from '@/object-record/hooks/useLazyFetchAllRecords';
import { MockedResponse } from '@apollo/client/testing';
import gql from 'graphql-tag';
import { PERSON_FRAGMENT_WITH_DEPTH_ZERO_RELATIONS } from '@/object-record/hooks/__mocks__/personFragments';
import { getJestMetadataAndApolloMocksAndActionMenuWrapper } from '~/testing/jest/getJestMetadataAndApolloMocksAndContextStoreWrapper';

const defaultResponseData = {
pageInfo: {
hasNextPage: false,
hasPreviousPage: false,
startCursor: '',
endCursor: '',
},
totalCount: 2,
};

const mockPerson = {
__typename: 'Person',
updatedAt: '2021-08-03T19:20:06.000Z',
whatsapp: {
primaryPhoneNumber: '+1',
primaryPhoneCountryCode: '234-567-890',
additionalPhones: [],
},
linkedinLink: {
primaryLinkUrl: 'https://www.linkedin.com',
primaryLinkLabel: 'linkedin',
secondaryLinks: ['https://www.linkedin.com'],
},
name: {
firstName: 'firstName',
lastName: 'lastName',
},
emails: {
primaryEmail: 'email',
additionalEmails: [],
},
position: 'position',
createdBy: {
source: 'source',
workspaceMemberId: '1',
name: 'name',
},
avatarUrl: 'avatarUrl',
jobTitle: 'jobTitle',
xLink: {
primaryLinkUrl: 'https://www.linkedin.com',
primaryLinkLabel: 'linkedin',
secondaryLinks: ['https://www.linkedin.com'],
},
performanceRating: 1,
createdAt: '2021-08-03T19:20:06.000Z',
phones: {
primaryPhoneNumber: '+1',
primaryPhoneCountryCode: '234-567-890',
additionalPhones: [],
},
id: '123',
city: 'city',
companyId: '1',
intro: 'intro',
deletedAt: null,
workPreference: 'workPreference',
};

const mock: MockedResponse = {
request: {
query: gql`
query FindManyPeople(
$filter: PersonFilterInput
$orderBy: [PersonOrderByInput]
$lastCursor: String
$limit: Int
) {
people(
filter: $filter
orderBy: $orderBy
first: $limit
after: $lastCursor
) {
edges {
node {
${PERSON_FRAGMENT_WITH_DEPTH_ZERO_RELATIONS}
}
cursor
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
totalCount
}
}
`,
variables: {
limit: 30,
},
},
result: jest.fn(() => ({
data: {
people: {
...defaultResponseData,
edges: [
{
node: mockPerson,
cursor: '1',
},
{
node: mockPerson,
cursor: '2',
},
],
},
},
})),
};

const Wrapper = getJestMetadataAndApolloMocksAndActionMenuWrapper({
apolloMocks: [mock],
componentInstanceId: 'recordIndexId',
contextStoreTargetedRecordsRule: {
mode: 'selection',
selectedRecordIds: [],
},
contextStoreCurrentObjectMetadataNameSingular: 'person',
});

describe('useLazyFetchAllRecords', () => {
const objectNameSingular = 'person';
const objectMetadataItem = generatedMockObjectMetadataItems.find(
(item) => item.nameSingular === objectNameSingular,
);
if (!objectMetadataItem) {
throw new Error('Object metadata item not found');
}

it('should handle one single page', async () => {
const { result } = renderHook(
() =>
useLazyFetchAllRecords({
objectNameSingular,
limit: 30,
}),
{
wrapper: Wrapper,
},
);

let res: any;

act(() => {
res = result.current.fetchAllRecords();
});

expect(result.current.isDownloading).toBe(true);

await waitFor(() => {
expect(result.current.isDownloading).toBe(false);
expect(result.current.progress).toEqual({ displayType: 'number' });
});

expect(result.current.progress).toEqual({ displayType: 'number' });

const finalResult = await res;

expect(finalResult).toEqual([mockPerson, mockPerson]);
});
});
Loading

0 comments on commit e5d2c12

Please sign in to comment.