Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Users: Pagination and infinite scroll #824

Merged
merged 53 commits into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
d4d3e37
pagination
luanecavalcantizup Jan 15, 2021
4c039c2
Adding max pag length at users endpoint.
monicaribeiro Jan 21, 2021
ffa1bb5
Merge branch 'main' of github.com:ZupIT/charlescd into fix/users-pagi…
luanecavalcantizup Jan 21, 2021
c53d286
Merge branch 'fix/users-pagination' of github.com:ZupIT/charlescd int…
luanecavalcantizup Jan 21, 2021
aa356c9
adjust space between icon and text in list item
luanecavalcantizup Jan 26, 2021
01f1584
adjust spacing
luanecavalcantizup Jan 26, 2021
0c0fddb
adjust loader margin
luanecavalcantizup Jan 26, 2021
ed6c1d9
adjust alignment
luanecavalcantizup Jan 26, 2021
32836b8
add infinite scroll
luanecavalcantizup Jan 26, 2021
fa73bb2
fix call to filterUsers
luanecavalcantizup Jan 27, 2021
5e263d5
load users when some user is deleted
luanecavalcantizup Jan 27, 2021
0fe7f10
adjust test
luanecavalcantizup Jan 27, 2021
ad87234
create a folder for test file
luanecavalcantizup Jan 27, 2021
fcf5561
edit data-testid
luanecavalcantizup Jan 28, 2021
4c87103
add test file
luanecavalcantizup Jan 28, 2021
78570c7
fix test
luanecavalcantizup Jan 28, 2021
9d8720d
remove a style
luanecavalcantizup Jan 28, 2021
283b159
remove log
luanecavalcantizup Jan 28, 2021
200f7f4
remove log
luanecavalcantizup Jan 28, 2021
312bb54
Merge branch 'main' into fix/users-pagination
monicaribeirozup Jan 28, 2021
48bfe32
fix infinite scroll when screen zoom is above 80%
luanecavalcantizup Jan 28, 2021
623f127
Merge branch 'fix/users-pagination' of github.com:ZupIT/charlescd int…
luanecavalcantizup Jan 28, 2021
40dc4e7
Merge branch 'main' into fix/users-pagination
luanecavalcantizup Jan 28, 2021
97dd8e8
Fixing test.
monicaribeiro Jan 28, 2021
6b28fee
Merge branch 'main' into fix/users-pagination
luanecavalcantizup Jan 28, 2021
b75fa27
Merge branch 'fix/users-pagination' of github.com:ZupIT/charlescd int…
monicaribeiro Jan 28, 2021
25d1b1a
replace deprecated function and remove unused code in test of Groups
luanecavalcantizup Jan 29, 2021
8556124
add tests and adjust hook
luanecavalcantizup Jan 29, 2021
3740397
create fixtures
luanecavalcantizup Jan 29, 2021
490eedc
Merge branch 'main' of github.com:ZupIT/charlescd into fix/users-pagi…
luanecavalcantizup Jan 29, 2021
d08ddd3
remove code after resolving conflicts
luanecavalcantizup Jan 29, 2021
f125786
temporary: remove test
luanecavalcantizup Jan 29, 2021
17f6b17
add test
luanecavalcantizup Jan 29, 2021
0830fe9
add test
luanecavalcantizup Jan 29, 2021
af910c3
Merge branch 'main' into fix/users-pagination
pedroborgeszup Jan 29, 2021
0c8765f
remove unnecessary code
luanecavalcantizup Feb 1, 2021
b542719
Merge branch 'main' into fix/users-pagination
monicaribeirozup Feb 1, 2021
c0e0f34
add assertions to test
luanecavalcantizup Feb 1, 2021
0d7bc21
Merge branch 'fix/users-pagination' of github.com:ZupIT/charlescd int…
luanecavalcantizup Feb 1, 2021
88b2ad5
Merge branch 'main' into fix/users-pagination
luanecavalcantizup Feb 1, 2021
f38362b
remove unused code
luanecavalcantizup Feb 1, 2021
abd9931
Merge branch 'fix/users-pagination' of github.com:ZupIT/charlescd int…
luanecavalcantizup Feb 1, 2021
5cfbe5c
Merge branch 'main' into fix/users-pagination
luanecavalcantizup Feb 1, 2021
cbba2ff
Merge branch 'main' into fix/users-pagination
luanecavalcantizup Feb 2, 2021
32d3991
Merge branch 'main' into fix/users-pagination
luanecavalcantizup Feb 3, 2021
40215c3
Merge branch 'main' into fix/users-pagination
pedroborgeszup Feb 4, 2021
9c11167
Merge branch 'main' into fix/users-pagination
luanecavalcantizup Feb 5, 2021
8210d40
Merge branch 'main' into fix/users-pagination
monicaribeirozup Feb 8, 2021
172d10d
Merge branch 'main' into fix/users-pagination
monicaribeirozup Feb 9, 2021
77390c1
undo changes
luanecavalcantizup Feb 9, 2021
5f65b34
Merge branch fix/users-pagination of github.com:ZupIT/charlescd into …
luanecavalcantizup Feb 9, 2021
68e86d9
Merge branch 'main' into fix/users-pagination
luanecavalcantizup Feb 10, 2021
073e7f9
Merge branch 'main' into fix/users-pagination
monicaribeirozup Feb 18, 2021
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
Expand Up @@ -71,7 +71,7 @@ class V2UserController(
@RequestHeader(value = "Authorization") authorization: String,
@RequestParam("name", required = false) name: String?,
@RequestParam("email", required = false) email: String?,
pageable: PageRequest
@Valid pageable: PageRequest
): ResourcePageResponse<SimpleUserResponse> {
return this.findAllUsersInteractor.execute(name, email, authorization, pageable)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test('renders LabeledIcon component with default properties', () => {

expect(textElement).toBeInTheDocument();
expect(labelElement).toBeInTheDocument();
expect(labelElement).toHaveStyle('margin-left: 5px;');
expect(labelElement).toHaveStyle('margin-left:8px;');
expect(iconElement).toBeInTheDocument();
});

Expand Down
2 changes: 1 addition & 1 deletion ui/src/core/components/LabeledIcon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const LabeledIcon = ({
className,
size = '15px',
isActive,
marginContent = '5px',
marginContent = '8px',
onClick
}: Props) => {
return (
Expand Down
8 changes: 5 additions & 3 deletions ui/src/core/providers/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ const endpointWorkspaces = '/moove/v2/workspaces/users';
const v1Endpoint = '/moove/users';

export interface UserFilter {
id?: string;
name?: string;
email?: string;
page?: number;
}

const initialUserFilter = {
email: ''
name: '',
page: 0
};

export const findAllWorkspaceUsers = (
Expand All @@ -48,10 +51,9 @@ export const findAllWorkspaceUsers = (
};

export const findAllUsers = (filter: UserFilter = initialUserFilter) => {
const defaultPage = 0;
const params = new URLSearchParams({
size: `${DEFAULT_PAGE_SIZE}`,
page: `${defaultPage}`
page: `${filter.page ?? 0}`
});

if (filter?.name) params.append('name', filter?.name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,35 @@
* limitations under the License.
*/

import React from 'react';
import { renderHook } from '@testing-library/react-hooks';
import { useGlobalState, useDispatch } from '../hooks';
import { AllTheProviders as wrapper } from 'unit-test/testUtils';
import { circlesInitialState } from 'modules/Circles/state/reducer';
import { userInitialState } from 'modules/Users/state/reducer';

test('useGlobalState', () => {
test('circle: useGlobalState', () => {
const { result } = renderHook(() => useGlobalState(state => state.circles), {
wrapper
});

expect(result.current).toEqual(circlesInitialState);
});

test('useDispatch', () => {
test('circle: useDispatch', () => {
const { result } = renderHook(() => useDispatch(), { wrapper });

expect(result.current).toEqual(expect.any(Function));
});

test('users: useGlobalState', () => {
const { result } = renderHook(() => useGlobalState(state => state.users), {
wrapper
});

expect(result.current).toEqual(userInitialState);
});

test('users: useDispatch', () => {
const { result } = renderHook(() => useDispatch(), { wrapper });

expect(result.current).toEqual(expect.any(Function));
Expand Down
2 changes: 1 addition & 1 deletion ui/src/modules/Account/Menu/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const MenuItem = ({ id, icon, name, path }: Props) => {
isActive={isActive(id)}
data-testid={`menu-${name}`}
>
<Styled.ListItem icon={icon} marginContent="8px">
<Styled.ListItem icon={icon}>
<Text.h4 color="light">{name}</Text.h4>
</Styled.ListItem>
</Styled.Link>
Expand Down
55 changes: 55 additions & 0 deletions ui/src/modules/Groups/__tests__/fixtures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
export const userGroupPagination = {
content: [{
id: '123',
name: 'group 1',
users: [{
id: '123',
name: 'Charles',
email: 'charlescd@zup.com.br',
photoUrl: 'https://charlescd.io',
createdAt: '2020-01-01 12:00'
}]
}],
page: 0,
size: 0,
totalPages: 0,
last: true
};

export const userGroup = {
id: '123',
name: 'group 1',
author: {
id: '456',
name: 'Charles',
email: 'charlescd@zup.com.br',
createdAt: '2020-01-01 12:00',
},
createdAt: '2020-01-01 12:00',
users: [{
id: '123',
name: 'Charles',
email: 'charlescd@zup.com.br',
photoUrl: 'https://charlescd.io',
createdAt: '2020-01-01 12:00'
}]
};

export const users = {
content: [{
id: '123',
name: 'Charles',
email: 'charlescd@zup.com.br',
photoUrl: 'https://charlescd.io',
applications: [{
id: '123',
name: 'Application 1',
menbersCount: 1
}],
createdAt: '2020-01-01 12:00'
}],
page: 0,
size: 0,
totalPages: 0,
last: true
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
*/

import { renderHook, act } from '@testing-library/react-hooks';
import { screen, wait } from 'unit-test/testUtils';
import { waitFor } from 'unit-test/testUtils';
import { FetchMock } from 'jest-fetch-mock';
import { useCreateUserGroup, useDeleteUserGroup, useFindAllUserGroup, useFindUserGroupByID, useListUser, useManagerMemberInUserGroup, useUpdateUserGroup } from '../hooks';
import { UserGroup } from '../interfaces/UserGroups';
import {userGroupPagination, userGroup, users} from './fixtures';

beforeEach(() => {
(fetch as FetchMock).resetMocks();
Expand All @@ -41,7 +42,7 @@ test('create a new user group', async () => {
await result.current.createUserGroup(newUserGroup.name);
});

await wait(() => expect(result.current.response).toMatchObject(newUserGroup));
await waitFor(() => expect(result.current.response).toMatchObject(newUserGroup));
});

test('error create a new user group', async () => {
Expand All @@ -60,29 +61,11 @@ test('error create a new user group', async () => {
response = await result.current.createUserGroup(newUserGroup.name);
});

await wait(() => expect(response).toBeUndefined());
await wait(() => expect(result.current.response).toBeUndefined());
await waitFor(() => expect(response).toBeUndefined());
await waitFor(() => expect(result.current.response).toBeUndefined());
});

test('to find all user groups', async () => {
const userGroupPagination = {
content: [{
id: '123',
name: 'group 1',
users: [{
id: '123',
name: 'Charles',
email: 'charlescd@zup.com.br',
photoUrl: 'https://charlescd.io',
createdAt: '2020-01-01 12:00'
}]
}],
page: 0,
size: 0,
totalPages: 0,
last: true
};

(fetch as FetchMock).mockResponseOnce(JSON.stringify(userGroupPagination));

const { result } = renderHook(() => useFindAllUserGroup());
Expand All @@ -91,29 +74,10 @@ test('to find all user groups', async () => {
await result.current[0]('group 1');
});

await wait(() => expect(result.current[2]).toMatchObject(userGroupPagination));
await waitFor(() => expect(result.current[2]).toMatchObject(userGroupPagination));
});

test('to find user group by id', async () => {
const userGroup = {
id: '123',
name: 'group 1',
author: {
id: '456',
name: 'Charles',
email: 'charlescd@zup.com.br',
createdAt: '2020-01-01 12:00',
},
createdAt: '2020-01-01 12:00',
users: [{
id: '123',
name: 'Charles',
email: 'charlescd@zup.com.br',
photoUrl: 'https://charlescd.io',
createdAt: '2020-01-01 12:00'
}]
};

(fetch as FetchMock).mockResponseOnce(JSON.stringify(userGroup));

const { result } = renderHook(() => useFindUserGroupByID());
Expand All @@ -122,29 +86,10 @@ test('to find user group by id', async () => {
await result.current[0]('123');
});

await wait(() => expect(result.current[1]).toMatchObject(userGroup));
await waitFor(() => expect(result.current[1]).toMatchObject(userGroup));
});

test('to list users', async () => {
const users = {
content: [{
id: '123',
name: 'Charles',
email: 'charlescd@zup.com.br',
photoUrl: 'https://charlescd.io',
applications: [{
id: '123',
name: 'Application 1',
menbersCount: 1
}],
createdAt: '2020-01-01 12:00'
}],
page: 0,
size: 0,
totalPages: 0,
last: true
};

(fetch as FetchMock).mockResponseOnce(JSON.stringify(users));

const { result } = renderHook(() => useListUser());
Expand All @@ -153,29 +98,10 @@ test('to list users', async () => {
await result.current[0]('charlescd@zup.com.br');
});

await wait(() => expect(result.current[1]).toMatchObject(users));
await waitFor(() => expect(result.current[1]).toMatchObject(users));
});

test('to update user group', async () => {
const userGroup = {
id: '123',
name: 'group 1',
author: {
id: '456',
name: 'Charles',
email: 'charlescd@zup.com.br',
createdAt: '2020-01-01 12:00',
},
createdAt: '2020-01-01 12:00',
users: [{
id: '123',
name: 'Charles',
email: 'charlescd@zup.com.br',
photoUrl: 'https://charlescd.io',
createdAt: '2020-01-01 12:00'
}]
};

(fetch as FetchMock).mockResponseOnce(JSON.stringify(userGroup));

const { result } = renderHook(() => useUpdateUserGroup());
Expand All @@ -184,7 +110,7 @@ test('to update user group', async () => {
await result.current[0]('123', 'Charles');
});

await wait(() => expect(result.current[1]).toMatchObject(userGroup));
await waitFor(() => expect(result.current[1]).toMatchObject(userGroup));
});

test('to delete user group', async () => {
Expand All @@ -196,7 +122,7 @@ test('to delete user group', async () => {
await result.current[0]('123');
});

await wait(() => expect(result.current[1]).toMatchObject({}));
await waitFor(() => expect(result.current[1]).toMatchObject({}));
});

test('to manager members in user group', async () => {
Expand All @@ -208,5 +134,5 @@ test('to manager members in user group', async () => {
await result.current[0](false, '123', '456');
});

await wait(() => expect(result.current[1]).toBe('resolved'));
await waitFor(() => expect(result.current[1]).toBe('resolved'));
});
6 changes: 1 addition & 5 deletions ui/src/modules/Hypotheses/Menu/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ const MenuItem = ({ id, name, onClick }: Props) => {

return (
<Styled.Link onClick={() => onClick()} isActive={isActive}>
<Styled.ListItem
icon="hypotheses"
marginContent="8px"
isActive={isActive}
>
<Styled.ListItem icon="hypotheses" isActive={isActive}>
<Styled.Item color="light">{name}</Styled.Item>
</Styled.ListItem>
</Styled.Link>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/modules/Metrics/Menu/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const MenuItem = ({ route, id, name }: Props) => {

return (
<Styled.Link onClick={() => history.push(route)} isActive={isActive}>
<Styled.ListItem icon="metrics" marginContent="8px" isActive={isActive}>
<Styled.ListItem icon="metrics" isActive={isActive}>
<Styled.Item color="light">{name}</Styled.Item>
</Styled.ListItem>
</Styled.Link>
Expand Down
6 changes: 1 addition & 5 deletions ui/src/modules/Modules/Menu/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ const MenuItem = ({ id, name }: Props) => {
return (
<Can I="read" a="modules" passThrough>
<Styled.Link onClick={() => onMenuClick()} isActive={isActive()}>
<Styled.ListItem
icon="modules"
marginContent="8px"
isActive={isActive()}
>
<Styled.ListItem icon="modules" isActive={isActive()}>
<Text.h4 color="light">{moduleFormatterName(name)}</Text.h4>
</Styled.ListItem>
</Styled.Link>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/modules/Settings/Menu/MenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const MenuItem = ({ id, icon, name, path }: Props) => {
isActive={isActive(id)}
data-testid={`menu-item-link-${name}`}
>
<Styled.ListItem icon={icon} marginContent="8px" isActive={isActive(id)}>
<Styled.ListItem icon={icon} isActive={isActive(id)}>
<Text.h4 color="light">{name}</Text.h4>
</Styled.ListItem>
</Styled.Link>
Expand Down
4 changes: 2 additions & 2 deletions ui/src/modules/Users/Menu/Loaders/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
*/

import React from 'react';
import { Loader as LoaderList } from './list';
import { Loader as LoaderList, Props as ListProps } from './list';

const Loader = {
List: () => <LoaderList />
List: ({ className }: ListProps) => <LoaderList className={className} />
};

export default Loader;
Loading