-
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.
work in progress
- Loading branch information
Showing
5 changed files
with
240 additions
and
42 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
98 changes: 65 additions & 33 deletions
98
src/modules/common/response/visualization/RatingsVisualization.tsx
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,36 +1,68 @@ | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { TRANSLATIONS_NS } from '@/config/i18n'; | ||
|
||
const RatingsVisualization = (): JSX.Element => { | ||
const { t } = useTranslation(TRANSLATIONS_NS); | ||
// const { activity } = useSettings(); | ||
// const { evaluationType } = activity; | ||
// const { getRatingsForResponse } = useRatings(evaluationType); | ||
|
||
// const ratings = useMemo( | ||
// () => getRatingsForResponse(response.id), | ||
// [getRatingsForResponse, response], | ||
// ); | ||
|
||
// if (evaluationType === EvaluationType.DimensionsOfGIRating) { | ||
// return ( | ||
// <DimensionsOfGlobalIssue | ||
// ratings={ratings as RatingsAppData<DimensionsOfGIRatings>[]} | ||
// /> | ||
// ); | ||
// } | ||
// if (evaluationType === EvaluationType.SFERARating) { | ||
// return <SFERAViz ratings={ratings as RatingsAppData<SFERARating>[]} />; | ||
// } | ||
// if (evaluationType === EvaluationType.UsefulnessNoveltyRating) { | ||
// return ( | ||
// <UsefulnessNovelty | ||
// ratings={ratings as RatingsAppData<UsefulnessNoveltyRatings>[]} | ||
// /> | ||
// ); | ||
// } | ||
return <>{t('NO_VISUALIZATION')}</>; | ||
import { FC, useEffect, useState } from 'react'; | ||
|
||
import CircularProgress from '@mui/material/CircularProgress'; | ||
import Stack from '@mui/material/Stack'; | ||
|
||
import { RatingData } from '@/config/appDataTypes'; | ||
import { useRatingsContext } from '@/modules/context/RatingsContext'; | ||
|
||
import CircularIndicator from './indicators/CircularIndicator'; | ||
|
||
interface RatingsVisualizationProps { | ||
responseId: string; | ||
} | ||
|
||
const RatingsVisualization: FC<RatingsVisualizationProps> = ({ | ||
responseId, | ||
}): JSX.Element => { | ||
const { | ||
ratings: ratingsDef, | ||
getRatingsStatsForResponse, | ||
ratingsThresholds, | ||
} = useRatingsContext(); | ||
|
||
const [ratings, setRatings] = useState<RatingData['ratings'] | undefined>( | ||
undefined, | ||
); | ||
|
||
useEffect(() => { | ||
getRatingsStatsForResponse(responseId).then((d) => setRatings(d)); | ||
}, [getRatingsStatsForResponse, responseId]); | ||
|
||
if (typeof ratingsDef === 'undefined' || typeof ratings === 'undefined') { | ||
// TODO: Make that look good. | ||
return <CircularProgress />; | ||
} | ||
|
||
const nbrRatings = ratingsDef?.length ?? 0; | ||
|
||
return ( | ||
<Stack | ||
direction="row" | ||
spacing={2} | ||
alignItems="stretch" | ||
justifyContent="center" | ||
m={2} | ||
> | ||
{ratingsDef.map((singleRatingDefinition, index) => { | ||
const { name } = singleRatingDefinition; | ||
if (ratings) { | ||
const result = ratings[index]; | ||
console.info(`For aspect ${name}, result is:`, result.value); | ||
return ( | ||
<CircularIndicator | ||
key={index} | ||
value={result.value} | ||
thresholds={ratingsThresholds} | ||
label={name} | ||
width={`${100 / nbrRatings}%`} | ||
/> | ||
); | ||
} | ||
return <CircularProgress key={index} />; | ||
})} | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default RatingsVisualization; |
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,38 @@ | ||
import { FC } from 'react'; | ||
|
||
import Grid from '@mui/material/Grid'; | ||
import Stack from '@mui/material/Stack'; | ||
|
||
import Response from '@/modules/common/response/Response'; | ||
|
||
import ExportResponsesButton from '../common/ExportRepsonsesButton'; | ||
import { useActivityContext } from '../context/ActivityContext'; | ||
|
||
type RatingsResultsProps = unknown; | ||
|
||
const RatingsResults: FC<RatingsResultsProps> = () => { | ||
const { allResponses } = useActivityContext(); | ||
// const sortedResponses = useMemo( | ||
// () => sortResponsesByNumberOfVote(allResponses, allVotes), | ||
// [allResponses, allVotes], | ||
// ); | ||
return ( | ||
<Stack | ||
direction="column" | ||
justifyItems="center" | ||
alignItems="center" | ||
spacing={2} | ||
> | ||
<Grid container spacing={2}> | ||
{allResponses.map((response) => ( | ||
<Grid item key={response.id} xl={2} sm={4} xs={6}> | ||
<Response response={response} showRatings /> | ||
</Grid> | ||
))} | ||
</Grid> | ||
<ExportResponsesButton responses={allResponses} /> | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default RatingsResults; |
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