@@ -75,9 +75,15 @@ const ElectionResult: FC = () => {
75
75
let textRes : TextResults = new Map < ID , string [ ] [ ] > ( ) ;
76
76
77
77
result . forEach ( ( res ) => {
78
- groupByID ( selectRes , res . SelectResultIDs , res . SelectResult , true ) ;
79
- groupByID ( rankRes , res . RankResultIDs , res . RankResult ) ;
80
- groupByID ( textRes , res . TextResultIDs , res . TextResult ) ;
78
+ if (
79
+ res . SelectResultIDs !== null &&
80
+ res . RankResultIDs !== null &&
81
+ res . TextResultIDs !== null
82
+ ) {
83
+ groupByID ( selectRes , res . SelectResultIDs , res . SelectResult , true ) ;
84
+ groupByID ( rankRes , res . RankResultIDs , res . RankResult ) ;
85
+ groupByID ( textRes , res . TextResultIDs , res . TextResult ) ;
86
+ }
81
87
} ) ;
82
88
83
89
return { rankRes, selectRes, textRes } ;
@@ -104,31 +110,39 @@ const ElectionResult: FC = () => {
104
110
switch ( element . Type ) {
105
111
case RANK :
106
112
const rank = element as RankQuestion ;
107
- res = countRankResult ( rankResult . get ( id ) , element as RankQuestion ) . resultsInPercent . map (
108
- ( percent , index ) => {
109
- return { Candidate : rank . Choices [ index ] , Percentage : `${ percent } %` } ;
110
- }
111
- ) ;
112
- dataToDownload . push ( { Title : element . Title , Results : res } ) ;
113
+
114
+ if ( rankResult . has ( id ) ) {
115
+ res = countRankResult ( rankResult . get ( id ) , element as RankQuestion ) . resultsInPercent . map (
116
+ ( percent , index ) => {
117
+ return { Candidate : rank . Choices [ index ] , Percentage : `${ percent } %` } ;
118
+ }
119
+ ) ;
120
+ dataToDownload . push ( { Title : element . Title , Results : res } ) ;
121
+ }
113
122
break ;
114
123
115
124
case SELECT :
116
125
const select = element as SelectQuestion ;
117
- res = countSelectResult ( selectResult . get ( id ) ) . resultsInPercent . map ( ( percent , index ) => {
118
- return { Candidate : select . Choices [ index ] , Percentage : `${ percent } %` } ;
119
- } ) ;
120
- dataToDownload . push ( { Title : element . Title , Results : res } ) ;
126
+
127
+ if ( selectResult . has ( id ) ) {
128
+ res = countSelectResult ( selectResult . get ( id ) ) . resultsInPercent . map ( ( percent , index ) => {
129
+ return { Candidate : select . Choices [ index ] , Percentage : `${ percent } %` } ;
130
+ } ) ;
131
+ dataToDownload . push ( { Title : element . Title , Results : res } ) ;
132
+ }
121
133
break ;
122
134
123
135
case SUBJECT :
124
136
getResultData ( element as Subject , dataToDownload ) ;
125
137
break ;
126
138
127
139
case TEXT :
128
- res = Array . from ( countTextResult ( textResult . get ( id ) ) . resultsInPercent ) . map ( ( r ) => {
129
- return { Candidate : r [ 0 ] , Percentage : `${ r [ 1 ] } %` } ;
130
- } ) ;
131
- dataToDownload . push ( { Title : element . Title , Results : res } ) ;
140
+ if ( textResult . has ( id ) ) {
141
+ res = Array . from ( countTextResult ( textResult . get ( id ) ) . resultsInPercent ) . map ( ( r ) => {
142
+ return { Candidate : r [ 0 ] , Percentage : `${ r [ 1 ] } %` } ;
143
+ } ) ;
144
+ dataToDownload . push ( { Title : element . Title , Results : res } ) ;
145
+ }
132
146
break ;
133
147
}
134
148
} ) ;
@@ -160,16 +174,18 @@ const ElectionResult: FC = () => {
160
174
return (
161
175
< div className = "pl-4 pb-4 sm:pl-6 sm:pb-6" >
162
176
< h2 className = "text-lg pb-2" > { element . Title } </ h2 >
163
- { element . Type === RANK && (
177
+ { element . Type === RANK && rankResult . has ( element . ID ) && (
164
178
< RankResult rank = { element as RankQuestion } rankResult = { rankResult . get ( element . ID ) } />
165
179
) }
166
- { element . Type === SELECT && (
180
+ { element . Type === SELECT && selectResult . has ( element . ID ) && (
167
181
< SelectResult
168
182
select = { element as SelectQuestion }
169
183
selectResult = { selectResult . get ( element . ID ) }
170
184
/>
171
185
) }
172
- { element . Type === TEXT && < TextResult textResult = { textResult . get ( element . ID ) } /> }
186
+ { element . Type === TEXT && textResult . has ( element . ID ) && (
187
+ < TextResult textResult = { textResult . get ( element . ID ) } />
188
+ ) }
173
189
</ div >
174
190
) ;
175
191
} ;
0 commit comments