generated from openedx/frontend-template-application
-
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.
- Loading branch information
1 parent
8a3dc5f
commit 0501387
Showing
5 changed files
with
64 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,53 @@ | ||
import React from 'react'; | ||
import React, { useState } from 'react'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
import { | ||
MenuItem, SearchField, | ||
SelectMenu, | ||
} from '@edx/paragon'; | ||
import PropTypes from 'prop-types'; | ||
import { useUpdateCurrentExamIndex } from '../hooks'; | ||
|
||
// todo: implement substring search | ||
const ExamSelection = ({ exams, handleSelectExam }) => { | ||
const { formatMessage, formatDate } = useIntl(); | ||
const [searchText, setSearchText] = useState(''); | ||
|
||
const ExamSelection = ({ exams }) => { | ||
const { updateSelectedExam } = useUpdateCurrentExamIndex(); | ||
const placeholderMessage = formatMessage({ | ||
id: 'ExamSelection.select_exam_placeholder', | ||
defaultMessage: 'Search for an exam...', | ||
description: 'Placeholder message for the exam selection dropdown', | ||
}); | ||
|
||
const getMenuItems = () => { | ||
const menuItems = [ | ||
<MenuItem as={SearchField} onChange={setSearchText} placeholder={placeholderMessage} />, | ||
] | ||
return menuItems.concat(exams.filter(exam => ( | ||
exam.name.toLowerCase().includes(searchText.toLowerCase())) | ||
).map(exam => { | ||
Check failure on line 25 in src/pages/ExamsPage/components/ExamSelection.jsx GitHub Actions / test (16)
|
||
return <MenuItem onClick={() => handleSelectExam(exam.id)}>{exam.name}</MenuItem> | ||
})); | ||
} | ||
|
||
return ( | ||
<div data-testid="exam_selection"> | ||
<SelectMenu defaultMessage="Select an exam..."> | ||
<MenuItem as={SearchField} /> | ||
{exams.map(exam => ( | ||
// todo: update redux state | ||
// <MenuItem onClick={() => console.log(exam.id)}>{exam.name}</MenuItem> | ||
<MenuItem onClick={() => updateSelectedExam(exam.id)}>{exam.name}</MenuItem> | ||
))} | ||
<SelectMenu | ||
defaultMessage={formatMessage({ | ||
id: 'ExamSelection.select_exam', | ||
defaultMessage: 'Select an exam', | ||
description: 'Default message for the exam selection dropdown', | ||
})} | ||
> | ||
{ getMenuItems() } | ||
</SelectMenu> | ||
</div> | ||
); | ||
}; | ||
|
||
ExamSelection.propTypes = { | ||
exams: PropTypes.arrayOf(PropTypes.object).isRequired, // eslint-disable-line react/forbid-prop-types | ||
exams: PropTypes.arrayOf(PropTypes.shape({ | ||
id: PropTypes.number, | ||
name: PropTypes.string, | ||
})).isRequired, | ||
handleSelectExam: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default ExamSelection; |
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
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,14 @@ | ||
@import "~@edx/paragon/scss/core/core"; | ||
|
||
#exam-selector { | ||
margin: 0.5em auto; | ||
} | ||
|
||
.pgn__searchfield .form-control { | ||
border: 1px solid $search-border-color !important; | ||
} | ||
|
||
.pgn__searchfield.has-focus:not(.pgn__searchfield--external)::after { | ||
border: none; | ||
width: 0px; | ||
} |