-
Notifications
You must be signed in to change notification settings - Fork 2
Td 2500 render results #361
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
Open
ghost
wants to merge
57
commits into
master
Choose a base branch
from
TD-2500-render-results
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 41 commits
Commits
Show all changes
57 commits
Select commit
Hold shift + click to select a range
f265c16
setup generic
48dc4be
add generic component graphql
ddad0df
render questions
07d1ad5
render questions and collect answers
d065fc4
refactor
662aecb
handle multi questions set
b0cf037
add conclusions view
aeeb84b
add show instructions
612d3fe
update Modal common
0ca367b
submit answers
26c932f
Merge branch 'master' into TD-2435-generic-assessment-ui
aa365bb
use assessmentID
2874102
bump version
8a997c1
refactor
a17c8c4
update graphql responses
8e04610
refactor code
0664436
add retry attempts
4295879
render score
317f1d0
remove secret key
57db093
Merge branch 'master' into TD-2435-generic-assessment-ui
869c028
render breakdown
398f21f
apply space-between
b262188
show hide all
7ce3439
format
cfb3a3c
handle question with set image
33408ce
Merge branch 'TD-2435-generic-assessment-ui' into TD-2500-render-results
02fde09
handle locale
a2537ab
update heading and hr tag
cd2a674
helper
91a5ed8
rearrange css class
c4bd1f8
use translate
a50b734
parse completedAt by millisecond
4152072
Merge branch 'master' into TD-2500-render-results
43315d5
Added loading state
tomprats 80c930f
remove header and actions
e416ea3
Merge branch 'master' into TD-2500-render-results
3241452
set loaded active assessment + remove redundant generic result css
bfafcb5
bump version to 3.9.0
1770629
extend box and container
1d57f34
extend container
2825d0f
refactor btn border
4529d36
return after setActive
71e7faf
name format
a51a651
get result if completed
2c2def5
not return cached survey if completed
1ba75f1
not call to result api
5d42077
render totalCorrectResponses
4a48daf
let question set in column for mobile
5ac1e92
survey mobile
9df964e
refactor direction class
e17e6a3
update btn mobile
173ecda
update reserved words
e8f085c
refactor with early return
d52a623
refactor progress bar
034eb57
add Generic components
9b84208
render score from api
23896f8
Merge branch 'master' into TD-2500-render-results
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,59 @@ | ||
| import PropTypes from "prop-types"; | ||
| import {useState} from "react"; | ||
| import useTranslate from "lib/hooks/use-translate"; | ||
| import Question from "./question"; | ||
| import style from "./style.scss"; | ||
|
|
||
| export default function Breakdown({assessmentResult}) { | ||
| const [showAll, setShowAll] = useState(false); | ||
| const translate = useTranslate(); | ||
| const showHideAll = () => { | ||
| setShowAll(!showAll); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className={style.breakdown}> | ||
| <div className={style.description}> | ||
| <div> | ||
| <div className={style.title}>{translate("results.generic.breakdown")}</div> | ||
| <span>{translate("results.generic.breakdown_description")}</span> | ||
| </div> | ||
| <div> | ||
| <button className={style.toggleButton} type="button" onClick={showHideAll}> | ||
| {translate("show_hide_all")} | ||
| </button> | ||
| </div> | ||
| </div> | ||
| <div className={style.questions}> | ||
| {assessmentResult.responses.map((question, index) => ( | ||
| <Question | ||
| key={question.questionId} | ||
| question={question} | ||
| index={index} | ||
| showState={showAll} | ||
| /> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| Breakdown.propTypes = { | ||
| assessmentResult: PropTypes.shape({ | ||
| responses: PropTypes.arrayOf( | ||
| PropTypes.shape({ | ||
| questionId: PropTypes.string.isRequired, | ||
| questionText: PropTypes.string, | ||
| isCorrect: PropTypes.bool.isRequired, | ||
| selectedResponseOptionId: PropTypes.string, | ||
| responseOptions: PropTypes.arrayOf( | ||
| PropTypes.shape({ | ||
| responseOptionId: PropTypes.string.isRequired, | ||
| responseOptionText: PropTypes.string.isRequired, | ||
| isCorrect: PropTypes.bool | ||
| }) | ||
| ).isRequired | ||
| }) | ||
| ).isRequired | ||
| }).isRequired | ||
| }; |
This file contains hidden or 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,43 @@ | ||
| import {useState, useEffect} from "react"; | ||
| import useGraphql from "lib/hooks/use-graphql"; | ||
| import useHttp from "lib/hooks/use-http"; | ||
| import useResults from "lib/hooks/use-results"; | ||
| import Breakdown from "./breakdown"; | ||
| import Score from "./score"; | ||
| import style from "./style.scss"; | ||
|
|
||
| export default function Generic() { | ||
| const [result, setResult] = useState(null); | ||
| const assessment = useResults({surveyType: "generic"}); | ||
| const assessmentResult = result ? result.assessment : {}; | ||
|
|
||
| const graphQL = useGraphql(); | ||
| const http = useHttp(); | ||
|
|
||
| useEffect(() => { | ||
| if(assessment === null) return; | ||
| const query = graphQL.generic.result; | ||
| const variables = {assessmentID: assessment.id}; | ||
|
|
||
| http.post(graphQL.generic.path, {query, variables}).then(({data, errors}) => { | ||
This conversation was marked as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if(!errors && data.genericAssessmentResult) { | ||
| setResult(data.genericAssessmentResult); | ||
| } else { | ||
| console.warn(errors || data); // eslint-disable-line no-console | ||
| } | ||
| }); | ||
| }, [assessment]); | ||
|
|
||
| return ( | ||
| <div> | ||
| {result && ( | ||
This conversation was marked as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <div className={style.container}> | ||
This conversation was marked as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <div className={style.contentBody}> | ||
| <Score assessmentResult={assessmentResult} /> | ||
| <Breakdown assessmentResult={assessmentResult} /> | ||
| </div> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or 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,98 @@ | ||
| import {faCheck, faXmark, faChevronDown, faChevronUp} from "@fortawesome/free-solid-svg-icons"; | ||
| import PropTypes from "prop-types"; | ||
| import {useState, useEffect} from "react"; | ||
| import Icon from "components/common/icon"; | ||
| import useTranslate from "lib/hooks/use-translate"; | ||
| import style from "./style.scss"; | ||
|
|
||
| export default function Question({question, index, showState}) { | ||
| const translate = useTranslate(); | ||
| const [showContent, setShowContent] = useState(false); | ||
| const responsesClassName = question.setImage | ||
| ? style.responsesWithImage | ||
| : style.responsesWithoutImage; | ||
| const longTextCondition = (option) => option.responseOptionText.length > 20; | ||
| const longTextResponses = question.responseOptions.some(longTextCondition); | ||
| const optionsDirection = (longTextResponses || responsesClassName === style.responsesWithImage) | ||
| ? "column" | ||
| : "row"; | ||
|
|
||
| useEffect(() => { | ||
| setShowContent(showState); | ||
| }, [showState]); | ||
|
|
||
| const toggleContent = () => { | ||
| setShowContent(!showContent); | ||
| }; | ||
|
|
||
| const optionClassName = (option) => { | ||
| let className = ""; | ||
| if(question.isCorrect) { | ||
This conversation was marked as resolved.
Show resolved
Hide resolved
|
||
| className = option.isCorrect ? style.correctResponse : ""; | ||
| } else { | ||
| if(option.isCorrect) { | ||
| className = style.correctOption; | ||
| } else if(option.responseOptionId === question.selectedResponseOptionId) { | ||
| className = style.incorrectResponse; | ||
| } | ||
| } | ||
| return className; | ||
| }; | ||
|
|
||
| return ( | ||
| <div key={question.questionId} className={style.question}> | ||
| <div className={style.questionTitle}> | ||
| <div> | ||
| {question.isCorrect | ||
| ? <Icon className={style.iconCorrect} alt="Checked" icon={faCheck} /> | ||
| : <Icon className={style.iconIncorrect} alt="X Mark" icon={faXmark} />} | ||
| </div> | ||
| <div> {translate("cognitive_question_alt_text")} {index + 1}</div> | ||
| <div> | ||
| <button type="button" onClick={toggleContent} className={style.toggleButton}> | ||
| <Icon className={style.icon} alt="Expand" icon={showContent ? faChevronUp : faChevronDown} /> | ||
| </button> | ||
| </div> | ||
| </div> | ||
| {showContent && ( | ||
| <div className={style.questionContent}> | ||
| <div className={style.responseOptions}> | ||
| <div className={style.questionText}>{question.questionText}</div> | ||
| <div className={responsesClassName} style={{flexDirection: optionsDirection}}> | ||
| {question.responseOptions.map((option) => ( | ||
| <div | ||
| key={option.responseOptionId} | ||
| className={`${optionClassName(option)} ${style.responseOption}`} | ||
| > | ||
| {option.responseOptionText} | ||
| </div> | ||
| ))} | ||
| </div> | ||
| </div> | ||
| {question.setImage && ( | ||
| <div className={style.questionImage}> | ||
| <img src={question.setImage} alt={question.questionText} /> | ||
| </div> | ||
| )} | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| Question.propTypes = { | ||
| question: PropTypes.shape({ | ||
| questionText: PropTypes.string, | ||
| questionId: PropTypes.string.isRequired, | ||
| isCorrect: PropTypes.bool.isRequired, | ||
| selectedResponseOptionId: PropTypes.string, | ||
| setImage: PropTypes.string, | ||
| responseOptions: PropTypes.arrayOf(PropTypes.shape({ | ||
| responseOptionId: PropTypes.string.isRequired, | ||
| responseOptionText: PropTypes.string.isRequired, | ||
| isCorrect: PropTypes.bool.isRequired | ||
| })).isRequired | ||
| }).isRequired, | ||
| index: PropTypes.number.isRequired, | ||
| showState: PropTypes.bool.isRequired | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.