Skip to content

Commit 1a6f323

Browse files
authored
feat: add results for ratings (#630)
fix: rating is empty by default not set to middle value fix: improve style and accessibility of AI-generated ideas
1 parent 9b8706b commit 1a6f323

File tree

9 files changed

+241
-291
lines changed

9 files changed

+241
-291
lines changed

src/modules/common/response/Response.tsx

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ const Response: FC<ResponseProps> = ({
103103
const renderTopResponseAnnotation = (): JSX.Element => {
104104
if (isAiGenerated) {
105105
return (
106-
<TopAnnotationTypography variant="caption" color="primary">
106+
<TopAnnotationTypography variant="caption" color="white">
107107
{t('AI_GENERATED')}
108108
</TopAnnotationTypography>
109109
);
@@ -121,7 +121,7 @@ const Response: FC<ResponseProps> = ({
121121
const getTopAnnotationBoxStyle = (): SxProps<Theme> => {
122122
if (isAiGenerated) {
123123
return {
124-
backgroundColor: 'white',
124+
backgroundColor: theme.palette.primary.main,
125125
};
126126
}
127127
const rLength =
@@ -134,14 +134,6 @@ const Response: FC<ResponseProps> = ({
134134
};
135135
};
136136

137-
const getCardActionStyle = (): SxProps<Theme> | undefined =>
138-
isAiGenerated
139-
? {
140-
backgroundColor: theme.palette.primary.main,
141-
color: theme.palette.primary.contrastText,
142-
}
143-
: undefined;
144-
145137
if (responseContent) {
146138
return (
147139
<Box
@@ -168,11 +160,10 @@ const Response: FC<ResponseProps> = ({
168160
variant="outlined"
169161
sx={{
170162
width: '100%',
171-
// backgroundColor: highlight ? 'hsla(0, 100%, 90%, 0.3)' : 'white',
172163
}}
173164
data-cy={RESPONSE_CY}
174165
>
175-
<CardContent sx={{ minHeight: '32pt', ...getCardActionStyle() }}>
166+
<CardContent sx={{ minHeight: '32pt' }}>
176167
{typeof responseContent === 'string' ? (
177168
<ResponsePart>{responseContent}</ResponsePart>
178169
) : (
@@ -217,7 +208,7 @@ const Response: FC<ResponseProps> = ({
217208
</Box>
218209
</CardContent>
219210
{renderEvaluationComponent()}
220-
{showRatings && <RatingsVisualization />}
211+
{showRatings && <RatingsVisualization responseId={id} />}
221212
{typeof nbrOfVotes !== 'undefined' && <Votes votes={nbrOfVotes} />}
222213
{showActions && (
223214
<>

src/modules/common/response/evaluation/Rate.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const Rate: FC<{
6363
maxLabel={r.maxLabel}
6464
levels={r.levels}
6565
key={index}
66-
value={values.get(r.name) ?? Math.ceil(r.levels / 2)}
66+
value={values.get(r.name)}
6767
/>
6868
))}
6969
</Container>

src/modules/common/response/visualization/DimensionsOfGlobalIssue.tsx

Lines changed: 0 additions & 111 deletions
This file was deleted.
Lines changed: 64 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,67 @@
1-
import { useTranslation } from 'react-i18next';
2-
3-
import { TRANSLATIONS_NS } from '@/config/i18n';
4-
5-
const RatingsVisualization = (): JSX.Element => {
6-
const { t } = useTranslation(TRANSLATIONS_NS);
7-
// const { activity } = useSettings();
8-
// const { evaluationType } = activity;
9-
// const { getRatingsForResponse } = useRatings(evaluationType);
10-
11-
// const ratings = useMemo(
12-
// () => getRatingsForResponse(response.id),
13-
// [getRatingsForResponse, response],
14-
// );
15-
16-
// if (evaluationType === EvaluationType.DimensionsOfGIRating) {
17-
// return (
18-
// <DimensionsOfGlobalIssue
19-
// ratings={ratings as RatingsAppData<DimensionsOfGIRatings>[]}
20-
// />
21-
// );
22-
// }
23-
// if (evaluationType === EvaluationType.SFERARating) {
24-
// return <SFERAViz ratings={ratings as RatingsAppData<SFERARating>[]} />;
25-
// }
26-
// if (evaluationType === EvaluationType.UsefulnessNoveltyRating) {
27-
// return (
28-
// <UsefulnessNovelty
29-
// ratings={ratings as RatingsAppData<UsefulnessNoveltyRatings>[]}
30-
// />
31-
// );
32-
// }
33-
return <>{t('NO_VISUALIZATION')}</>;
1+
import { FC, useEffect, useState } from 'react';
2+
3+
import CircularProgress from '@mui/material/CircularProgress';
4+
import Stack from '@mui/material/Stack';
5+
6+
import { RatingData } from '@/config/appDataTypes';
7+
import { useRatingsContext } from '@/modules/context/RatingsContext';
8+
9+
import CircularIndicator from './indicators/CircularIndicator';
10+
11+
interface RatingsVisualizationProps {
12+
responseId: string;
13+
}
14+
15+
const RatingsVisualization: FC<RatingsVisualizationProps> = ({
16+
responseId,
17+
}): JSX.Element => {
18+
const {
19+
ratings: ratingsDef,
20+
getRatingsStatsForResponse,
21+
ratingsThresholds,
22+
} = useRatingsContext();
23+
24+
const [ratings, setRatings] = useState<RatingData['ratings'] | undefined>(
25+
undefined,
26+
);
27+
28+
useEffect(() => {
29+
getRatingsStatsForResponse(responseId).then((d) => setRatings(d));
30+
}, [getRatingsStatsForResponse, responseId]);
31+
32+
if (typeof ratingsDef === 'undefined' || typeof ratings === 'undefined') {
33+
// TODO: Make that look good.
34+
return <CircularProgress />;
35+
}
36+
37+
const nbrRatings = ratingsDef?.length ?? 0;
38+
39+
return (
40+
<Stack
41+
direction="row"
42+
spacing={2}
43+
alignItems="stretch"
44+
justifyContent="center"
45+
m={2}
46+
>
47+
{ratingsDef.map((singleRatingDefinition, index) => {
48+
const { name } = singleRatingDefinition;
49+
if (ratings) {
50+
const result = ratings[index];
51+
return (
52+
<CircularIndicator
53+
key={index}
54+
value={result.value}
55+
thresholds={ratingsThresholds}
56+
label={name}
57+
width={`${100 / nbrRatings}%`}
58+
/>
59+
);
60+
}
61+
return <CircularProgress key={index} />;
62+
})}
63+
</Stack>
64+
);
3465
};
3566

3667
export default RatingsVisualization;

src/modules/common/response/visualization/SFERA.tsx

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)