Skip to content

Commit 4bf9631

Browse files
committed
show the related answers in history, summary betterments
1 parent f824c69 commit 4bf9631

File tree

7 files changed

+106
-20
lines changed

7 files changed

+106
-20
lines changed

src/client/components/Admin/Summary/Summary.tsx

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type TableProps = {
2222
tableValues: TableValues[]
2323
questionTitles: TableValues
2424
isOutdated: any
25+
entries: any[]
2526
}
2627

2728
const additionalColumnNames: TableValues = {
@@ -32,8 +33,13 @@ const additionalColumnNames: TableValues = {
3233
unit: 'Yksikkö',
3334
}
3435

35-
const Table = ({ tableValues, questionTitles, isOutdated }: TableProps) => {
36+
const Table = ({ tableValues, questionTitles, isOutdated, entries }: TableProps) => {
3637
const deleteMutation = useDeleteEntryMutation()
38+
39+
const isTestVersion = (id: string) => {
40+
return entries.find(e => e.id === Number(id))?.testVersion || false
41+
}
42+
3743
const columns = useMemo<MRT_ColumnDef<TableValues>[]>(() => {
3844
const outdatedWarning = { paddingRight: 10, color: 'red', fontSize: 'x-large' }
3945
return tableValues.length
@@ -54,10 +60,18 @@ const Table = ({ tableValues, questionTitles, isOutdated }: TableProps) => {
5460
})}
5561
>
5662
{columnId === '3' ? (
57-
<>
63+
<Box>
5864
{isOutdated(row.getValue('id')) && <span style={outdatedWarning}>!</span>}
5965
<Link to={`/admin/entry/${row.getValue('id')}`}>{cell.getValue<string>()}</Link>
60-
</>
66+
{isTestVersion(row.getValue('id')) && (
67+
<Box
68+
component="div"
69+
sx={{ color: 'red', fontWeight: 'bold', fontSize: '0.75rem', marginTop: '4px' }}
70+
>
71+
TEST VERSION
72+
</Box>
73+
)}
74+
</Box>
6175
) : (
6276
cell.getValue<number>()
6377
)}
@@ -106,7 +120,12 @@ const Table = ({ tableValues, questionTitles, isOutdated }: TableProps) => {
106120
enableColumnOrdering: true,
107121
enableGlobalFilter: false,
108122
enableRowActions: true,
109-
muiTableBodyRowProps: { hover: false },
123+
muiTableBodyRowProps: ({ row }) => ({
124+
hover: false,
125+
sx: {
126+
backgroundColor: isTestVersion(row.original.id) ? '#fffef5' : 'inherit',
127+
},
128+
}),
110129
muiTableBodyCellProps: {
111130
sx: {
112131
border: '1px solid rgba(81, 81, 81, .5)',
@@ -208,7 +227,12 @@ const Summary = () => {
208227
px: 8,
209228
}}
210229
>
211-
<Table tableValues={tableData} questionTitles={questionTitles} isOutdated={isOutdated} />
230+
<Table
231+
tableValues={tableData}
232+
questionTitles={questionTitles}
233+
isOutdated={isOutdated}
234+
entries={entriesWithData}
235+
/>
212236
</Box>
213237
</>
214238
)

src/client/components/Admin/Summary/utils.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ const createTableData = (entries: Entry[], questions: Question[], faculties: Fac
2626
if (entry.data.answers.selectOrganisation) {
2727
entry.data.answers[22] = entry.data.answers.selectOrganisation
2828
}
29-
if (entry.testVersion && !entry.data.answers[3].includes('TEST VERSION')) {
30-
entry.data.answers[3] = `${entry.data.answers[3]} -TEST VERSION-`
31-
}
3229
const formData = Object.fromEntries(
3330
questionIds.map(id => [
3431
id,

src/client/components/ResultPage/RenderAnswersDOM.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@ import useUnits from '../../hooks/useUnits'
44
import RenderAnswers from '@resultRenderer/RenderAnswers'
55
import { FormValues } from '@types'
66

7-
const RenderAnswersDOM = ({ survey, resultData }: { survey: Survey; resultData: FormValues }) => {
7+
const RenderAnswersDOM = ({
8+
survey,
9+
resultData,
10+
changedFields,
11+
}: {
12+
survey: Survey
13+
resultData: FormValues
14+
changedFields?: Set<number>
15+
}) => {
816
const { faculties, isLoading: facultiesLoading } = useFaculties()
917
const { faculties: units, isLoading: unitsLoading } = useUnits()
1018

@@ -15,7 +23,15 @@ const RenderAnswersDOM = ({ survey, resultData }: { survey: Survey; resultData:
1523
return null
1624
}
1725

18-
return <RenderAnswers survey={survey} resultData={resultData} faculties={faculties} units={units} />
26+
return (
27+
<RenderAnswers
28+
survey={survey}
29+
resultData={resultData}
30+
faculties={faculties}
31+
units={units}
32+
changedFields={changedFields}
33+
/>
34+
)
1935
}
2036

2137
export default RenderAnswersDOM

src/client/components/UserPage/UserEntry.tsx

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,26 @@ const UserEntry = () => {
6464

6565
const { answers, country, updatedData } = entry.data
6666

67+
// Helper function to compare answers and find changed fields
68+
const getChangedFields = (currentAnswers: any, previousAnswers: any): Set<number> => {
69+
const changed = new Set<number>()
70+
if (!previousAnswers) {
71+
return changed
72+
}
73+
74+
Object.keys(currentAnswers).forEach(key => {
75+
const numKey = Number(key)
76+
if (!isNaN(numKey)) {
77+
const current = JSON.stringify(currentAnswers[key])
78+
const previous = JSON.stringify(previousAnswers[key])
79+
if (current !== previous) {
80+
changed.add(numKey)
81+
}
82+
}
83+
})
84+
return changed
85+
}
86+
6787
return (
6888
<MuiComponentProvider>
6989
<div>
@@ -97,15 +117,26 @@ const UserEntry = () => {
97117

98118
<TabPanel value={tabValue} index={0}>
99119
<RiskTableDOM riskData={entry.data} countryData={country[0]} />
100-
<RenderAnswersDOM survey={survey} resultData={answers} />
120+
<RenderAnswersDOM
121+
survey={survey}
122+
resultData={answers}
123+
changedFields={getChangedFields(answers, updatedData?.[0]?.answers)}
124+
/>
101125
</TabPanel>
102-
{updatedData?.map((updated, index) => (
103-
/* eslint-disable-next-line react/no-array-index-key */
104-
<TabPanel key={index} value={tabValue} index={index + 1}>
105-
<RiskTableDOM riskData={updated} countryData={country[0]} />
106-
<RenderAnswersDOM survey={survey} resultData={updated.answers ?? answers} />
107-
</TabPanel>
108-
))}
126+
{updatedData?.map((updated, index) => {
127+
const previousAnswers = updatedData[index + 1]?.answers
128+
return (
129+
/* eslint-disable-next-line react/no-array-index-key */
130+
<TabPanel key={index} value={tabValue} index={index + 1}>
131+
<RiskTableDOM riskData={updated} countryData={country[0]} />
132+
<RenderAnswersDOM
133+
survey={survey}
134+
resultData={updated.answers ?? answers}
135+
changedFields={getChangedFields(updated.answers ?? answers, previousAnswers)}
136+
/>
137+
</TabPanel>
138+
)
139+
})}
109140
</Box>
110141
<SendSummaryEmail entryId={entryId} />
111142
</div>

src/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
"title": "Project risk profile",
111111
"riskTableTitle": "Risks of the collaboration",
112112
"answerBoxTitle": "Summary of your choices",
113+
"changedFieldsNote": "Questions with a light background indicate answers that have changed from the previous version.",
113114
"resultsMessage": "We have compiled a summary of your selections below",
114115
"proceedTitle": "Did you find what you were looking for?",
115116
"proceedToExit": "Yes",

src/locales/fi.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
"title": "Yhteistyöhankkeen riskiprofiili",
109109
"riskTableTitle": "Yhteistyön riskit",
110110
"answerBoxTitle": "Yhteenveto valinnoistasi",
111+
"changedFieldsNote": "Korostetulla taustalla näkyvät vastaukset, jotka ovat muuttuneet edellisestä versiosta.",
111112
"resultsMessage": "Listasimme sinulle vielä alle yhteevedon valinnoista",
112113
"proceedTitle": "Löysitkö etsimäsi?",
113114
"proceedToExit": "Kyllä",

src/resultRenderer/RenderAnswers.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ const RenderAnswers = ({
1313
resultData,
1414
faculties,
1515
units,
16+
changedFields,
1617
}: {
1718
survey: Survey
1819
resultData: FormValues
1920
faculties: FacultyOrUnit[]
2021
units: FacultyOrUnit[]
22+
changedFields?: Set<number>
2123
}) => {
2224
const { Div, Typography, t, language } = useComponents()
2325

@@ -73,12 +75,25 @@ const RenderAnswers = ({
7375
<Typography variant="h6" style={{ fontSize: '24px', marginBottom: '20px' }}>
7476
{t('results:answerBoxTitle')}
7577
</Typography>
78+
{changedFields && changedFields.size > 0 && (
79+
<Div style={{ backgroundColor: '#fffef0', padding: '12px', borderRadius: '4px', marginBottom: '16px' }}>
80+
<Typography style={{ fontSize: '14px', fontStyle: 'italic' }}>{t('results:changedFieldsNote')}</Typography>
81+
</Div>
82+
)}
7683
<Div style={{ borderLeft: '1px solid lightgray' }}>
7784
{survey?.Questions.map(currentQuestion => (
7885
<Div key={currentQuestion.id}>
7986
{!currentQuestion.parentId && !(hyCordinatedMultilateral && [6, 8, 24].includes(currentQuestion.id)) && (
8087
<>
81-
<Div style={{ margin: '16px' }} id={`question-${currentQuestion.id}`}>
88+
<Div
89+
style={{
90+
margin: '16px',
91+
...(changedFields?.has(currentQuestion.id)
92+
? { backgroundColor: '#fffef0', padding: '8px', borderRadius: '4px' }
93+
: {}),
94+
}}
95+
id={`question-${currentQuestion.id}`}
96+
>
8297
<Typography style={{ fontWeight: '800' }}>
8398
{currentQuestion.id === 8 && resultData[4] === 'multilateral'
8499
? t('questions:additionalPartnerOrganisationCountryQuestion')
@@ -98,7 +113,8 @@ const RenderAnswers = ({
98113
{survey?.Questions.filter(
99114
childQuestion =>
100115
childQuestion.parentId === currentQuestion.id &&
101-
!(resultData[9] !== 'coordinator' && childQuestion.parentId === 4)
116+
!(hyCordinatedMultilateral && [6, 8, 24].includes(childQuestion.id)) &&
117+
!(!hyCordinatedMultilateral && [26, 27, 28, 30].includes(childQuestion.id))
102118
)?.map(childQuestion => (
103119
<Div key={childQuestion.id} style={{ margin: '16px' }}>
104120
<Div style={{ borderLeft: '1px solid lightgray' }}>

0 commit comments

Comments
 (0)