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

feat: Add Infinite scroll to all tag screens & refactor code for better readability (GSoC) #2387

Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
66e1af2
add people to tag functaionality
meetulr Oct 25, 2024
edb8360
minor change
meetulr Oct 25, 2024
689ad90
more translations
meetulr Oct 25, 2024
abaf86e
minor change
meetulr Oct 26, 2024
7b7b6bf
add a variable for page size
meetulr Oct 26, 2024
72b6fd3
add tag actions
meetulr Oct 26, 2024
3b97043
add tests
meetulr Oct 26, 2024
6c13484
translations
meetulr Oct 26, 2024
76f5fbe
change to infinite scroll
meetulr Oct 27, 2024
d022c8d
add subtags infinite scroll
meetulr Oct 27, 2024
27227a9
Merge branch 'tagActions' into changeToInfiniteScroll
meetulr Oct 27, 2024
d11a6ee
extract common variables to utils
meetulr Oct 27, 2024
01b4b65
minor correction
meetulr Oct 27, 2024
c882dd6
Merge branch 'tagActions' into changeToInfiniteScroll
meetulr Oct 27, 2024
ba59202
more design adjustments
meetulr Oct 27, 2024
a59da70
add tests
meetulr Oct 27, 2024
f773005
add scrollbar for infinite scroll
meetulr Oct 27, 2024
e42b8fe
extract infinite scroll loader
meetulr Oct 27, 2024
ab3310a
minor adjustment
meetulr Oct 27, 2024
b223e21
refactoring
meetulr Oct 27, 2024
1b4b913
Merge branch 'develop' of https://github.com/PalisadoesFoundation/tal…
meetulr Oct 27, 2024
a8bca91
exclude ManageTag from countline check
meetulr Oct 27, 2024
58af286
fix linting
meetulr Oct 27, 2024
59f5e03
fix linting
meetulr Oct 27, 2024
879ef42
fix linting
meetulr Oct 27, 2024
6a79d51
make coderabbit suggested changes
meetulr Oct 28, 2024
9bc25d7
more changes
meetulr Oct 28, 2024
926f766
more changes
meetulr Oct 28, 2024
d3e91ac
minor correction
meetulr Oct 28, 2024
2a49ea0
add error component for tagNode subtags query
meetulr Oct 28, 2024
052aead
fix translation
meetulr Oct 28, 2024
d8d657a
fix translation
meetulr Oct 28, 2024
e9a86f8
Merge branch 'tagActions' into refactoringAndDesignAdjustments
meetulr Oct 28, 2024
4ae2507
remove unused css classes
meetulr Oct 28, 2024
ffbdffc
refactor ManageTag file to reduce its size
meetulr Oct 30, 2024
f4c7814
update pull-request check
meetulr Oct 30, 2024
95a1138
minor adjustments
meetulr Oct 30, 2024
4efe79e
minor correction
meetulr Oct 30, 2024
bbab01c
Merge branch 'develop' of https://github.com/PalisadoesFoundation/tal…
meetulr Oct 30, 2024
6f65f9f
minor change
meetulr Oct 30, 2024
eb5b7ea
correction
meetulr Oct 30, 2024
ee1cf2d
minor changes
meetulr Oct 30, 2024
5ac6cbe
minor change
meetulr Oct 30, 2024
9626c68
coderabbitai changes
meetulr Oct 30, 2024
9be6fa8
more changes
meetulr Oct 30, 2024
63febd0
fix dataGrid classes
meetulr Oct 30, 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
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Count number of lines
run: |
chmod +x ./.github/workflows/countline.py
./.github/workflows/countline.py --lines 600 --exclude_files src/screens/LoginPage/LoginPage.tsx src/GraphQl/Queries/Queries.ts src/screens/OrgList/OrgList.tsx src/GraphQl/Mutations/mutations.ts src/components/EventListCard/EventListCardModals.tsx src/screens/ManageTag/ManageTag.tsx
./.github/workflows/countline.py --lines 600 --exclude_files src/screens/LoginPage/LoginPage.tsx src/GraphQl/Queries/Queries.ts src/screens/OrgList/OrgList.tsx src/GraphQl/Mutations/mutations.ts src/components/EventListCard/EventListCardModals.tsx

- name: Get changed TypeScript files
id: changed-files
Expand Down
6 changes: 3 additions & 3 deletions src/GraphQl/Queries/userTagQueries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const USER_TAGS_ASSIGNED_MEMBERS = gql`
$first: PositiveInt
$last: PositiveInt
) {
getUserTag(id: $id) {
getAssignedUsers: getUserTag(id: $id) {
name
usersAssignedTo(
after: $after
Expand Down Expand Up @@ -57,7 +57,7 @@ export const USER_TAG_SUB_TAGS = gql`
$first: PositiveInt
$last: PositiveInt
) {
getUserTag(id: $id) {
getChildTags: getUserTag(id: $id) {
name
childTags(after: $after, before: $before, first: $first, last: $last) {
edges {
Expand Down Expand Up @@ -99,7 +99,7 @@ export const USER_TAGS_MEMBERS_TO_ASSIGN_TO = gql`
$first: PositiveInt
$last: PositiveInt
) {
getUserTag(id: $id) {
getUsersToAssignTo: getUserTag(id: $id) {
name
usersToAssignTo(
after: $after
Expand Down
36 changes: 3 additions & 33 deletions src/components/AddPeopleToTag/AddPeopleToTag.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
}

.scrollContainer {
max-height: 100px; /* Adjust as needed */
max-height: 100px;
overflow-y: auto;
margin-bottom: 1rem;
}
Expand All @@ -38,40 +38,10 @@
align-items: center;
padding: 5px 10px;
border-radius: 12px;
background-color: #f8f9fa; /* Light background */
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
max-width: calc(100% - 30px); /* Ensure it fits within the container */
box-shadow: 0 1px 3px var(--bs-gray-400);
max-width: calc(100% - 2rem);
}

.removeFilterIcon {
cursor: pointer;
}

.scrollContainer {
max-height: 350px; /* Set your desired max height */
overflow-y: auto; /* Enable vertical scrolling */
}

/* SimpleLoader.css */
.simple-loader {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
}

.spinner {
width: 40px;
height: 40px;
border: 4px solid rgba(0, 0, 0, 0.1);
border-top-color: #3498db;
border-radius: 50%;
animation: spin 0.6s linear infinite;
}

@keyframes spin {
to {
transform: rotate(360deg);
}
}
81 changes: 31 additions & 50 deletions src/components/AddPeopleToTag/AddPeopleToTag.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { ApolloError } from '@apollo/client';
import { useMutation, useQuery } from '@apollo/client';
import type { GridCellParams, GridColDef } from '@mui/x-data-grid';
import { DataGrid } from '@mui/x-data-grid';
Expand All @@ -10,8 +9,9 @@ import { Modal, Form, Button } from 'react-bootstrap';
import { useParams } from 'react-router-dom';
import type { InterfaceQueryUserTagsMembersToAssignTo } from 'utils/interfaces';
import styles from './AddPeopleToTag.module.css';
import type { InterfaceTagUsersToAssignToQuery } from 'utils/organizationTagsUtils';
import {
ADD_PEOPLE_TO_TAGS_QUERY_LIMIT,
TAGS_QUERY_DATA_CHUNK_SIZE,
dataGridStyle,
} from 'utils/organizationTagsUtils';
import { Stack } from '@mui/material';
Expand All @@ -20,6 +20,7 @@ import { ADD_PEOPLE_TO_TAG } from 'GraphQl/Mutations/TagMutations';
import InfiniteScroll from 'react-infinite-scroll-component';
import { WarningAmberRounded } from '@mui/icons-material';
import { useTranslation } from 'react-i18next';
import InfiniteScrollLoader from 'components/InfiniteScrollLoader/InfiniteScrollLoader';

/**
* Props for the `AddPeopleToTag` component.
Expand Down Expand Up @@ -58,64 +59,48 @@ const AddPeopleToTag: React.FC<InterfaceAddPeopleToTagProps> = ({
loading: userTagsMembersToAssignToLoading,
error: userTagsMembersToAssignToError,
fetchMore: fetchMoreMembersToAssignTo,
}: {
data?: {
getUserTag: InterfaceQueryUserTagsMembersToAssignTo;
};
loading: boolean;
error?: ApolloError;
fetchMore: (options: {
}: InterfaceTagUsersToAssignToQuery = useQuery(
USER_TAGS_MEMBERS_TO_ASSIGN_TO,
{
variables: {
after?: string | null;
first?: number | null;
};
updateQuery?: (
previousQueryResult: {
getUserTag: InterfaceQueryUserTagsMembersToAssignTo;
},
options: {
fetchMoreResult: {
getUserTag: InterfaceQueryUserTagsMembersToAssignTo;
};
},
) => { getUserTag: InterfaceQueryUserTagsMembersToAssignTo };
}) => Promise<unknown>;
} = useQuery(USER_TAGS_MEMBERS_TO_ASSIGN_TO, {
variables: {
id: currentTagId,
first: ADD_PEOPLE_TO_TAGS_QUERY_LIMIT,
id: currentTagId,
first: TAGS_QUERY_DATA_CHUNK_SIZE,
},
skip: !addPeopleToTagModalIsOpen,
fetchPolicy: 'no-cache',
},
skip: !addPeopleToTagModalIsOpen,
});
);

const loadMoreMembersToAssignTo = (): void => {
fetchMoreMembersToAssignTo({
variables: {
first: ADD_PEOPLE_TO_TAGS_QUERY_LIMIT,
first: TAGS_QUERY_DATA_CHUNK_SIZE,
after:
userTagsMembersToAssignToData?.getUserTag.usersToAssignTo.pageInfo
.endCursor, // Fetch after the last loaded cursor
userTagsMembersToAssignToData?.getUsersToAssignTo.usersToAssignTo
.pageInfo.endCursor, // Fetch after the last loaded cursor
},
updateQuery: (
prevResult: { getUserTag: InterfaceQueryUserTagsMembersToAssignTo },
prevResult: {
getUsersToAssignTo: InterfaceQueryUserTagsMembersToAssignTo;
},
{
fetchMoreResult,
}: {
fetchMoreResult: {
getUserTag: InterfaceQueryUserTagsMembersToAssignTo;
getUsersToAssignTo: InterfaceQueryUserTagsMembersToAssignTo;
};
},
) => {
if (!fetchMoreResult) return prevResult;

return {
getUserTag: {
...fetchMoreResult.getUserTag,
getUsersToAssignTo: {
...fetchMoreResult.getUsersToAssignTo,
usersToAssignTo: {
...fetchMoreResult.getUserTag.usersToAssignTo,
...fetchMoreResult.getUsersToAssignTo.usersToAssignTo,
edges: [
...prevResult.getUserTag.usersToAssignTo.edges,
...fetchMoreResult.getUserTag.usersToAssignTo.edges,
...prevResult.getUsersToAssignTo.usersToAssignTo.edges,
...fetchMoreResult.getUsersToAssignTo.usersToAssignTo.edges,
],
meetulr marked this conversation as resolved.
Show resolved Hide resolved
},
},
Expand All @@ -125,7 +110,7 @@ const AddPeopleToTag: React.FC<InterfaceAddPeopleToTagProps> = ({
};

const userTagMembersToAssignTo =
userTagsMembersToAssignToData?.getUserTag.usersToAssignTo.edges.map(
userTagsMembersToAssignToData?.getUsersToAssignTo.usersToAssignTo.edges.map(
(edge) => edge.node,
);

Expand Down Expand Up @@ -168,8 +153,7 @@ const AddPeopleToTag: React.FC<InterfaceAddPeopleToTagProps> = ({
hideAddPeopleToTagModal();
setAssignToMembers([]);
}
} catch (error: unknown) {
/* istanbul ignore next */
} catch (error: unknown) /* istanbul ignore next */ {
const errorMessage =
error instanceof Error ? error.message : tErrors('unknownError');
toast.error(errorMessage);
Expand Down Expand Up @@ -299,22 +283,19 @@ const AddPeopleToTag: React.FC<InterfaceAddPeopleToTagProps> = ({
id="scrollableDiv"
data-testid="scrollableDiv"
style={{
height: 300,
maxHeight: 300,
overflow: 'auto',
}}
>
<InfiniteScroll
dataLength={userTagMembersToAssignTo?.length ?? 0} // This is important field to render the next data
next={loadMoreMembersToAssignTo}
hasMore={
userTagsMembersToAssignToData?.getUserTag.usersToAssignTo
.pageInfo.hasNextPage ?? false
}
loader={
<div className="simpleLoader">
<div className="spinner" />
</div>
userTagsMembersToAssignToData?.getUsersToAssignTo
.usersToAssignTo.pageInfo.hasNextPage ??
/* istanbul ignore next */ false
}
loader={<InfiniteScrollLoader />}
scrollableTarget="scrollableDiv"
>
<DataGrid
Expand Down
67 changes: 42 additions & 25 deletions src/components/AddPeopleToTag/AddPeopleToTagsMocks.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { ADD_PEOPLE_TO_TAG } from 'GraphQl/Mutations/TagMutations';
import { USER_TAGS_MEMBERS_TO_ASSIGN_TO } from 'GraphQl/Queries/userTagQueries';
import { TAGS_QUERY_DATA_CHUNK_SIZE } from 'utils/organizationTagsUtils';

export const MOCKS = [
{
request: {
query: USER_TAGS_MEMBERS_TO_ASSIGN_TO,
variables: {
id: '1',
first: 7,
first: TAGS_QUERY_DATA_CHUNK_SIZE,
},
},
result: {
data: {
getUserTag: {
getUsersToAssignTo: {
meetulr marked this conversation as resolved.
Show resolved Hide resolved
name: 'tag1',
usersToAssignTo: {
edges: [
Expand Down Expand Up @@ -72,14 +73,38 @@ export const MOCKS = [
},
cursor: '7',
},
{
node: {
_id: '8',
firstName: 'member',
lastName: '8',
},
cursor: '8',
},
{
node: {
_id: '9',
firstName: 'member',
lastName: '9',
},
cursor: '9',
},
{
node: {
_id: '10',
firstName: 'member',
lastName: '10',
},
cursor: '10',
},
],
pageInfo: {
startCursor: '1',
endCursor: '7',
endCursor: '10',
hasNextPage: true,
hasPreviousPage: false,
},
totalCount: 10,
totalCount: 12,
},
},
},
Expand All @@ -90,48 +115,40 @@ export const MOCKS = [
query: USER_TAGS_MEMBERS_TO_ASSIGN_TO,
variables: {
id: '1',
first: 7,
after: '7',
first: TAGS_QUERY_DATA_CHUNK_SIZE,
after: '10',
},
},
result: {
data: {
getUserTag: {
getUsersToAssignTo: {
name: 'tag1',
usersToAssignTo: {
edges: [
{
node: {
_id: '8',
firstName: 'member',
lastName: '8',
},
cursor: '8',
},
{
node: {
_id: '9',
_id: '11',
firstName: 'member',
lastName: '9',
lastName: '11',
},
cursor: '9',
cursor: '11',
},
{
node: {
_id: '10',
_id: '12',
firstName: 'member',
lastName: '10',
lastName: '12',
},
cursor: '10',
cursor: '12',
},
],
pageInfo: {
startCursor: '8',
endCursor: '10',
startCursor: '11',
endCursor: '12',
hasNextPage: false,
hasPreviousPage: true,
},
totalCount: 10,
totalCount: 12,
},
},
},
Expand Down Expand Up @@ -161,7 +178,7 @@ export const MOCKS_ERROR = [
query: USER_TAGS_MEMBERS_TO_ASSIGN_TO,
variables: {
id: '1',
first: 7,
first: TAGS_QUERY_DATA_CHUNK_SIZE,
},
},
error: new Error('Mock Graphql Error'),
Expand Down
Loading
Loading