Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 3 additions & 2 deletions src/core/apollo/generated/apollo-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10810,8 +10810,8 @@ export function refetchContributorsPageOrganizationsQuery(
}

export const ContributorsPageUsersDocument = gql`
query ContributorsPageUsers($first: Int!, $after: UUID, $filter: UserFilterInput) {
usersPaginated(first: $first, after: $after, filter: $filter) {
query ContributorsPageUsers($first: Int!, $after: UUID, $filter: UserFilterInput, $withTags: Boolean) {
usersPaginated(first: $first, after: $after, filter: $filter, withTags: $withTags) {
...UserContributorPaginated
}
}
Expand All @@ -10833,6 +10833,7 @@ export const ContributorsPageUsersDocument = gql`
* first: // value for 'first'
* after: // value for 'after'
* filter: // value for 'filter'
* withTags: // value for 'withTags'
* },
* });
*/
Expand Down
2 changes: 2 additions & 0 deletions src/core/apollo/generated/graphql-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4743,6 +4743,7 @@ export type QueryUsersPaginatedArgs = {
filter?: InputMaybe<UserFilterInput>;
first?: InputMaybe<Scalars['Int']>;
last?: InputMaybe<Scalars['Int']>;
withTags?: InputMaybe<Scalars['Boolean']>;
};

export type QueryUsersWithAuthorizationCredentialArgs = {
Expand Down Expand Up @@ -16032,6 +16033,7 @@ export type ContributorsPageUsersQueryVariables = Exact<{
first: Scalars['Int'];
after?: InputMaybe<Scalars['UUID']>;
filter?: InputMaybe<UserFilterInput>;
withTags?: InputMaybe<Scalars['Boolean']>;
}>;

export type ContributorsPageUsersQuery = {
Expand Down
8 changes: 8 additions & 0 deletions src/core/utils/array.shuffle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const arrayShuffle = <T>(array: T[]): T[] => {
const shuffledArray = array.slice(); // Create a copy of the array
for (let i = shuffledArray.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[shuffledArray[i], shuffledArray[j]] = [shuffledArray[j], shuffledArray[i]];
}
return shuffledArray;
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC } from 'react';
import React, { FC, useMemo } from 'react';
import { ApolloError } from '@apollo/client';
import { ContainerChildProps } from '../../../../core/container/container';
import {
Expand All @@ -16,6 +16,7 @@ import {
UserContributorFragment,
} from '../../../../core/apollo/generated/graphql-schema';
import usePaginatedQuery from '../../../shared/pagination/usePaginatedQuery';
import { arrayShuffle } from '../../../../core/utils/array.shuffle';

export interface PaginatedResult<T> {
items: T[] | undefined;
Expand Down Expand Up @@ -60,14 +61,29 @@ const ContributorsSearchContainer: FC<ContributorsSearchContainerProps> = ({ sea
skip: !isAuthenticated,
},
variables: {
withTags: true,
filter: { firstName: searchTerms, lastName: searchTerms, email: searchTerms },
},
pageSize: pageSize,
getPageInfo: result => result.usersPaginated.pageInfo,
});

const randomizedUsers = useMemo(() => {
// if the length changed, shuffle only the new portion of the array
// to avoid re-rendering the entire list
const users = usersQueryResult.data?.usersPaginated.users;

if (!users) {
return [];
}

const randomizedNewUsers = arrayShuffle(users.slice(-pageSize));

return [...users.slice(0, users.length - pageSize), ...randomizedNewUsers];
}, [usersQueryResult.data?.usersPaginated.users?.length]);

const users: PaginatedResult<UserContributorFragment> = {
items: usersQueryResult.data?.usersPaginated.users,
items: randomizedUsers,
loading: usersQueryResult.loading,
hasMore: usersQueryResult.hasMore,
pageSize: usersQueryResult.pageSize,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ query ContributorsPageOrganizations($first: Int!, $after: UUID, $status: Organiz
}
}

query ContributorsPageUsers($first: Int!, $after: UUID, $filter: UserFilterInput) {
usersPaginated(first: $first, after: $after, filter: $filter) {
query ContributorsPageUsers($first: Int!, $after: UUID, $filter: UserFilterInput, $withTags: Boolean) {
usersPaginated(first: $first, after: $after, filter: $filter, withTags: $withTags) {
...UserContributorPaginated
}
}
Expand Down
31 changes: 18 additions & 13 deletions src/domain/community/user/ContributorsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export interface ContributorsPageProps {}
const ContributorsPage: FC<ContributorsPageProps> = () => {
const { t } = useTranslation();

// temporary disable the search (server #4545)
const [searchEnabled] = useState(false);

const [searchTerms, setSearchTerms] = useState<string>('');
const [searchTermsDebounced, setSearchTermsDebounced] = useState<string>('');

Expand Down Expand Up @@ -49,19 +52,21 @@ const ContributorsPage: FC<ContributorsPageProps> = () => {
}
>
<PageContentColumn columns={12}>
<PageContentBlockSeamless disablePadding>
<OutlinedInput
value={searchTerms}
sx={{ width: '100%' }}
placeholder={t('components.searchableList.placeholder')}
onChange={onSearchHandler}
endAdornment={
<InputAdornment position="end">
<SearchIcon />
</InputAdornment>
}
/>
</PageContentBlockSeamless>
{searchEnabled && (
<PageContentBlockSeamless disablePadding>
<OutlinedInput
value={searchTerms}
sx={{ width: '100%' }}
placeholder={t('components.searchableList.placeholder')}
onChange={onSearchHandler}
endAdornment={
<InputAdornment position="end">
<SearchIcon />
</InputAdornment>
}
/>
</PageContentBlockSeamless>
)}
<ContributorsSearchContainer searchTerms={searchTermsDebounced} pageSize={ITEMS_PER_PAGE}>
{({ users, organizations }) => {
return (
Expand Down
2 changes: 1 addition & 1 deletion src/domain/community/user/ContributorsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import GridProvider from '../../../core/ui/grid/GridProvider';
import { Identifiable } from '../../../core/utils/Identifiable';

const USERS_GRAYED_OUT_IMAGE = '/contributors/users-grayed.png';
export const ITEMS_PER_PAGE = 16;
export const ITEMS_PER_PAGE = 32;

const userToContributorCard = (user: UserContributorFragment): ContributorCardSquareProps => {
return {
Expand Down