-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support filtering on quizzes not completed by multiple people (#58)
* #57 Move user selector into it's own component so it can be reused * #57 Fix htmlFor label for participant selector * #57 Add user selector with wrapper that also handles the loading of available users * #57 Allow filtering the quiz list with incomplete targetting multiple users Refactors QuizFilters into QuizControls to better control layout of the top section of the quiz list * #57 Fix mobile padding for the new exclusion selector control
- Loading branch information
1 parent
d18f2f8
commit 9a65bc7
Showing
9 changed files
with
240 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { userIdentifier } from '../helpers'; | ||
import { User } from '../types/user'; | ||
|
||
export interface UserSelectorProps { | ||
availableUsers: User[]; | ||
selectedUserEmails: string[]; | ||
onSelectionsChanged: (selectedUserEmails: string[]) => void; | ||
name?: string; | ||
} | ||
|
||
export function UserSelector({ | ||
availableUsers, | ||
selectedUserEmails, | ||
onSelectionsChanged, | ||
name = 'user-selector', | ||
}: UserSelectorProps) { | ||
return ( | ||
<select | ||
multiple | ||
id={name} | ||
name={name} | ||
className='mt-1 block w-full py-2 px-3 border border-gray-300 bg-white rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500 sm:text-sm' | ||
onChange={(e) => { | ||
const items = [...(e.target as HTMLSelectElement).selectedOptions]; | ||
onSelectionsChanged(items.map((item) => item.value)); | ||
}} | ||
> | ||
{availableUsers.map((user) => ( | ||
<option selected={selectedUserEmails.includes(user.email)} value={user.email}> | ||
{userIdentifier(user)} | ||
</option> | ||
))} | ||
</select> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import { faFilter, faFilterCircleXmark, faRefresh } from '@fortawesome/free-solid-svg-icons'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { useState } from 'preact/hooks'; | ||
|
||
import { useQuizlord } from '../../QuizlordProvider'; | ||
import Button from '../../components/Button'; | ||
import { userIdentifier } from '../../helpers'; | ||
import { UserSelectorWithLoader } from './UserSelectorWithLoader'; | ||
import { QuizFilters } from './quizFilters'; | ||
|
||
export interface QuizListControlsProps { | ||
filters: QuizFilters; | ||
onFiltersChanged: (filterChanges: QuizFilters) => void; | ||
onRefreshClicked: () => void; | ||
className?: string; | ||
} | ||
|
||
export function QuizListControls({ filters, onFiltersChanged, onRefreshClicked, className }: QuizListControlsProps) { | ||
const { user: authenticatedUser } = useQuizlord(); | ||
const [isSelectingUsers, setIsSelectingUsers] = useState(false); | ||
const [pendingSelections, setPendingSelections] = useState<string[]>(filters.excludedUserEmails); | ||
return ( | ||
<> | ||
<div className='flex m-4 lg:m-0 lg:mb-4'> | ||
<div | ||
className={`cursor-pointer${className ? ` ${className}` : ''}`} | ||
onClick={() => setIsSelectingUsers((prevState) => !prevState)} | ||
> | ||
<FontAwesomeIcon | ||
icon={filters.excludedUserEmails ? faFilter : faFilterCircleXmark} | ||
size='xl' | ||
className='text-gray-800' | ||
/> | ||
<span className='ml-4'>{getIncompleteText(filters.excludedUserEmails.length)}</span> | ||
</div> | ||
<div | ||
className={`cursor-pointer${className ? ` ${className}` : ''}`} | ||
onClick={() => | ||
onFiltersChanged({ | ||
...filters, | ||
isFilteringOnIllegible: !filters.isFilteringOnIllegible, | ||
}) | ||
} | ||
> | ||
<FontAwesomeIcon | ||
icon={filters.isFilteringOnIllegible ? faFilter : faFilterCircleXmark} | ||
size='xl' | ||
className='text-gray-800' | ||
/> | ||
<span className='ml-4'>{filters.isFilteringOnIllegible ? 'Readable Only' : 'No Readability Filter'}</span> | ||
</div> | ||
<div className='flex-0 cursor-pointer' onClick={() => onRefreshClicked()}> | ||
<FontAwesomeIcon icon={faRefresh} size='xl' className='text-gray-800' /> | ||
</div> | ||
</div> | ||
{isSelectingUsers && ( | ||
<div className='m-4 lg:m-0 lg:mb-4'> | ||
<label htmlFor='excludedUserEmails' className='block text-sm font-medium text-gray-700'> | ||
Excluded quizzes completed by | ||
</label> | ||
<p className='text-sm text-gray-500'> | ||
{userIdentifier(authenticatedUser)} <strong>OR</strong> | ||
</p> | ||
<UserSelectorWithLoader | ||
selectedUserEmails={filters.excludedUserEmails} | ||
onSelectionsChanged={(newSelections) => { | ||
setPendingSelections(newSelections); | ||
}} | ||
excludeUserEmails={authenticatedUser ? [authenticatedUser.email] : []} | ||
name='excludedUserEmails' | ||
/> | ||
|
||
<div className='space-x-2 my-2'> | ||
<Button | ||
onClick={() => { | ||
onFiltersChanged({ | ||
...filters, | ||
excludedUserEmails: [...pendingSelections, ...(authenticatedUser ? [authenticatedUser.email] : [])], | ||
}); | ||
setIsSelectingUsers(false); | ||
}} | ||
> | ||
Apply | ||
</Button> | ||
<Button | ||
warning | ||
onClick={() => { | ||
onFiltersChanged({ | ||
...filters, | ||
excludedUserEmails: [], | ||
}); | ||
setIsSelectingUsers(false); | ||
}} | ||
> | ||
Remove Filter | ||
</Button> | ||
<Button | ||
danger | ||
onClick={() => { | ||
setPendingSelections(filters.excludedUserEmails); | ||
setIsSelectingUsers(false); | ||
}} | ||
> | ||
Cancel | ||
</Button> | ||
</div> | ||
</div> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
function getIncompleteText(numExcluded: number) { | ||
if (numExcluded === 0) { | ||
return 'No Incomplete Filter'; | ||
} | ||
if (numExcluded === 1) { | ||
return 'Incomplete (You)'; | ||
} | ||
return `Incomplete (You + ${numExcluded - 1})`; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useQuery } from '@apollo/client'; | ||
|
||
import Loader from '../../components/Loader'; | ||
import { UserSelector } from '../../components/UserSelector'; | ||
import { AVAILABLE_USERS } from '../../queries/quiz'; | ||
import { User } from '../../types/user'; | ||
|
||
export interface UserSelectorWithLoaderProps { | ||
selectedUserEmails: string[]; | ||
onSelectionsChanged: (selectedUserEmails: string[]) => void; | ||
excludeUserEmails?: string[]; | ||
name?: string; | ||
} | ||
|
||
export function UserSelectorWithLoader({ | ||
selectedUserEmails, | ||
onSelectionsChanged, | ||
name, | ||
excludeUserEmails, | ||
}: UserSelectorWithLoaderProps) { | ||
const { loading, data } = useQuery<{ | ||
users: { edges: { node: User }[] }; | ||
}>(AVAILABLE_USERS); | ||
|
||
if (loading || !data) { | ||
return <Loader message='Loading available users' />; | ||
} | ||
|
||
return ( | ||
<UserSelector | ||
availableUsers={data.users.edges | ||
.map((edge) => edge.node) | ||
.filter((user) => !excludeUserEmails?.includes(user.email))} | ||
selectedUserEmails={selectedUserEmails} | ||
onSelectionsChanged={onSelectionsChanged} | ||
name={name} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export interface QuizFilters { | ||
isFilteringOnIncomplete: boolean; | ||
excludedUserEmails: string[]; | ||
isFilteringOnIllegible: boolean; | ||
} |
Oops, something went wrong.