Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

☑️ Refacto "Select All/Unselect all" on indexes #5320

Merged
merged 49 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
0655efd
☑️ Refacto "Select All/Unselect all" on indexes
gitstart-twenty May 7, 2024
e056193
Merge commit '005045c596d8b080539ec180c83aa75d301bf770' of https://gi…
gitstart-twenty May 8, 2024
40faff3
Fix jest
gitstart-twenty May 8, 2024
1cf0db6
Refactor according to self review
gitstart-twenty May 8, 2024
d6f0675
Merge commit 'fdf10f17e2fa91da60336140fb859ae56e8acfb9' of https://gi…
gitstart-twenty May 16, 2024
29dd4f6
Refactor according to review
gitstart-twenty May 16, 2024
7de431d
Merge main
gitstart-twenty May 23, 2024
c0ca3bd
Merge main
gitstart-twenty May 23, 2024
5a52f64
Merge main
gitstart-twenty May 23, 2024
bd8c53e
Merge main
gitstart-twenty Jun 11, 2024
fb13ca2
Merge branch 'main' into TWNTY-4397
FelixMalfait Jun 14, 2024
7acce56
Merge branch 'main' into TWNTY-4397
lucasbordeau Jun 17, 2024
2477b14
Fixed typing problem
lucasbordeau Jun 17, 2024
856fa81
Fix
lucasbordeau Jun 17, 2024
cb51287
Merge branch 'main' into TWNTY-4397
lucasbordeau Jun 19, 2024
9d7d570
Change download predicate
gitstart-twenty Jun 21, 2024
de563bf
Merge main
gitstart-twenty Jun 21, 2024
52a64c7
Merge commit 'd126b148a19bc32a7cb52e7ed04d2470bf8be6b5' of https://gi…
gitstart-twenty Jun 21, 2024
a43bf6b
Fix Select All checkbox
gitstart-twenty Jun 21, 2024
dfe033d
Merge branch 'main' into TWNTY-4397
lucasbordeau Jun 24, 2024
fe9c465
Fixed bug
lucasbordeau Jun 24, 2024
72a4e70
Refactor according to review
gitstart-twenty Jun 28, 2024
922942d
Revert temporary changes
gitstart-twenty Jun 28, 2024
db93173
Fix linter issues
gitstart-twenty Jun 28, 2024
72aa58c
Fix records count
gitstart-twenty Jun 28, 2024
cf1ac0e
Fix linter
gitstart-twenty Jun 28, 2024
079a412
Merge branch 'main' into TWNTY-4397
lucasbordeau Jul 1, 2024
d91482d
Merge commit '5df0ea6466be885ce85dcb2bb849b8493698ce52' of https://gi…
gitstart-twenty Jul 4, 2024
d5011b3
Fix click outside table
gitstart-twenty Jul 4, 2024
e1343a3
Merge branch 'main' into TWNTY-4397
lucasbordeau Jul 5, 2024
7c7edaa
WIP
lucasbordeau Jul 5, 2024
0c76416
Fix
lucasbordeau Jul 5, 2024
4cefd9c
Fix
lucasbordeau Jul 5, 2024
1bb1d27
removed refetch queries
lucasbordeau Jul 5, 2024
968046d
WIP
lucasbordeau Jul 9, 2024
d5f863a
WIP
lucasbordeau Jul 9, 2024
6e6c7f6
WIP
lucasbordeau Jul 9, 2024
ec1b8be
Merge branch 'main' into TWNTY-4397
lucasbordeau Jul 9, 2024
b676c8b
WIP
lucasbordeau Jul 9, 2024
1ae7a4f
Fixed bug
lucasbordeau Jul 9, 2024
5cf6444
Cleaned
lucasbordeau Jul 9, 2024
c04d308
Fixed favorites
lucasbordeau Jul 9, 2024
e4bd470
Naming fix
lucasbordeau Jul 9, 2024
9714cd6
Fixed typo
lucasbordeau Jul 9, 2024
1156e08
Fxed naming
lucasbordeau Jul 9, 2024
8ffbbdf
Fix
lucasbordeau Jul 9, 2024
0cc7e64
Fixed test
lucasbordeau Jul 9, 2024
2521676
Fixed coverage with test on new useFetchAllRecordIds and other utils
lucasbordeau Jul 10, 2024
80621c6
Fix lint
lucasbordeau Jul 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { getObjectMetadataItemByNameSingular } from '@/object-metadata/utils/getObjectMetadataItemBySingularName';
import { getObjectMetadataItemsMock } from '@/object-metadata/utils/getObjectMetadataItemsMock';

const mockObjectMetadataItems = getObjectMetadataItemsMock();

describe('getObjectMetadataItemBySingularName', () => {
it('should work as expected', () => {
const firstObjectMetadataItem = mockObjectMetadataItems[0];

const foundObjectMetadataItem = getObjectMetadataItemByNameSingular({
objectMetadataItems: mockObjectMetadataItems,
objectNameSingular: firstObjectMetadataItem.nameSingular,
});

expect(foundObjectMetadataItem.id).toEqual(firstObjectMetadataItem.id);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { peopleQueryResult } from '~/testing/mock-data/people';

import { isObjectRecordConnection } from '@/object-record/cache/utils/isObjectRecordConnection';

describe('isObjectRecordConnection', () => {
it('should work with query result', () => {
const validQueryResult = peopleQueryResult.people;

const isValidQueryResult = isObjectRecordConnection(
'person',
validQueryResult,
);

expect(isValidQueryResult).toEqual(true);
});

it('should fail with invalid result', () => {
const invalidResult = { test: 123 };

const isValidQueryResult = isObjectRecordConnection(
'person',
invalidResult,
);

expect(isValidQueryResult).toEqual(false);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const DEFAULT_MUTATION_BATCH_SIZE = 30;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const DEFAULT_QUERY_PAGE_SIZE = 30;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const DELETE_MAX_COUNT = 10000;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export type RecordGqlConnection = {
__typename?: string;
edges: RecordGqlEdge[];
pageInfo: {
__typename?: string;
hasNextPage?: boolean;
hasPreviousPage?: boolean;
startCursor?: Nullable<string>;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { RecordGqlConnection } from '@/object-record/graphql/types/RecordGqlConnection';
import { gql } from '@apollo/client';

import { peopleQueryResult } from '~/testing/mock-data/people';


export const query = gql`
query FindManyPeople($filter: PersonFilterInput, $orderBy: [PersonOrderByInput], $lastCursor: String, $limit: Int) {
people(filter: $filter, orderBy: $orderBy, first: $limit, after: $lastCursor){
edges {
node {
__typename
id
}
cursor
}
pageInfo {
hasNextPage
startCursor
endCursor
}
totalCount
}
}
`;

export const mockPageSize = 2;

export const peopleMockWithIdsOnly: RecordGqlConnection = { ...peopleQueryResult.people,edges: peopleQueryResult.people.edges.map((edge) => ({ ...edge, node: { __typename: 'Person', id: edge.node.id } })) };

export const firstRequestLastCursor = peopleMockWithIdsOnly.edges[mockPageSize].cursor;
export const secondRequestLastCursor = peopleMockWithIdsOnly.edges[mockPageSize * 2].cursor;
export const thirdRequestLastCursor = peopleMockWithIdsOnly.edges[mockPageSize * 3].cursor;

export const variablesFirstRequest = {
filter: undefined,
limit: undefined,
orderBy: undefined
};

export const variablesSecondRequest = {
filter: undefined,
limit: undefined,
orderBy: undefined,
lastCursor: firstRequestLastCursor
};

export const variablesThirdRequest = {
filter: undefined,
limit: undefined,
orderBy: undefined,
lastCursor: secondRequestLastCursor
}

const paginateRequestResponse = (response: RecordGqlConnection, start: number, end: number, hasNextPage: boolean, totalCount: number) => {
return {
...response,
edges: [
...response.edges.slice(start, end)
],
pageInfo: {
...response.pageInfo,
startCursor: response.edges[start].cursor,
endCursor: response.edges[end].cursor,
hasNextPage,
} satisfies RecordGqlConnection['pageInfo'],
totalCount,
}
}

export const responseFirstRequest = {
people: paginateRequestResponse(peopleMockWithIdsOnly, 0, mockPageSize, true, 6),
};

export const responseSecondRequest = {
people: paginateRequestResponse(peopleMockWithIdsOnly, mockPageSize, mockPageSize * 2, true, 6),
};

export const responseThirdRequest = {
people: paginateRequestResponse(peopleMockWithIdsOnly, mockPageSize * 2, mockPageSize * 3, false, 6),
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ReactNode } from 'react';
import { MockedProvider } from '@apollo/client/testing';
import { act, renderHook } from '@testing-library/react';
import { ReactNode } from 'react';
import { RecoilRoot } from 'recoil';

import {
Expand All @@ -23,7 +23,7 @@ const mocks = [
},
result: jest.fn(() => ({
data: {
deletePeople: responseData,
deletePeople: [responseData],
},
})),
},
Expand All @@ -49,7 +49,7 @@ describe('useDeleteManyRecords', () => {
await act(async () => {
const res = await result.current.deleteManyRecords(people);
expect(res).toBeDefined();
expect(res).toHaveProperty('id');
expect(res[0]).toHaveProperty('id');
});

expect(mocks[0].result).toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { MockedProvider } from '@apollo/client/testing';
import { act, renderHook } from '@testing-library/react';
import { ReactNode, useEffect } from 'react';
import { RecoilRoot, useRecoilState } from 'recoil';

import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadataItemsState';
import { getObjectMetadataItemsMock } from '@/object-metadata/utils/getObjectMetadataItemsMock';
import {
mockPageSize,
peopleMockWithIdsOnly,
query,
responseFirstRequest,
responseSecondRequest,
responseThirdRequest,
variablesFirstRequest,
variablesSecondRequest,
variablesThirdRequest,
} from '@/object-record/hooks/__mocks__/useFetchAllRecordIds';
import { useFetchAllRecordIds } from '@/object-record/hooks/useFetchAllRecordIds';
import { SnackBarManagerScopeInternalContext } from '@/ui/feedback/snack-bar-manager/scopes/scope-internal-context/SnackBarManagerScopeInternalContext';

const mocks = [
{
delay: 100,
request: {
query,
variables: variablesFirstRequest,
},
result: jest.fn(() => ({
data: responseFirstRequest,
})),
},
{
delay: 100,
request: {
query,
variables: variablesSecondRequest,
},
result: jest.fn(() => ({
data: responseSecondRequest,
})),
},
{
delay: 100,
request: {
query,
variables: variablesThirdRequest,
},
result: jest.fn(() => ({
data: responseThirdRequest,
})),
},
];

describe('useFetchAllRecordIds', () => {
it('fetches all record ids with fetch more synchronous loop', async () => {
const Wrapper = ({ children }: { children: ReactNode }) => (
<RecoilRoot>
<SnackBarManagerScopeInternalContext.Provider
value={{
scopeId: 'snack-bar-manager',
}}
>
<MockedProvider mocks={mocks} addTypename={false}>
{children}
</MockedProvider>
</SnackBarManagerScopeInternalContext.Provider>
</RecoilRoot>
);

const { result } = renderHook(
() => {
const [, setObjectMetadataItems] = useRecoilState(
objectMetadataItemsState,
);

useEffect(() => {
setObjectMetadataItems(getObjectMetadataItemsMock());
}, [setObjectMetadataItems]);

return useFetchAllRecordIds({
objectNameSingular: 'person',
pageSize: mockPageSize,
});
},
{
wrapper: Wrapper,
},
);

const { fetchAllRecordIds } = result.current;

let recordIds: string[] = [];

await act(async () => {
recordIds = await fetchAllRecordIds();
});

expect(mocks[0].result).toHaveBeenCalled();
expect(mocks[1].result).toHaveBeenCalled();
expect(mocks[2].result).toHaveBeenCalled();

expect(recordIds).toEqual(
peopleMockWithIdsOnly.edges.map((edge) => edge.node.id).slice(0, 6),
);
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ReactNode } from 'react';
import { MockedProvider } from '@apollo/client/testing';
import { renderHook } from '@testing-library/react';
import { ReactNode } from 'react';
import { RecoilRoot, useSetRecoilState } from 'recoil';

import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
Expand Down
Loading
Loading