@@ -22,6 +22,10 @@ import {
2222} from '@togglecorp/fujs' ;
2323import { PartialForm } from '@togglecorp/toggle-form' ;
2424
25+ import {
26+ getPerAreaColor ,
27+ getPerRatingColor ,
28+ } from '#utils/domain/per' ;
2529import { type GoApiResponse } from '#utils/restRequest' ;
2630
2731import i18n from './i18n.json' ;
@@ -43,14 +47,25 @@ interface Props {
4347 areaIdToTitleMap : Record < number , string | undefined > ;
4448}
4549
46- const colors = [
47- 'var(--go-ui-color-red-90)' ,
48- 'var(--go-ui-color-red-70)' ,
49- 'var(--go-ui-color-red-50)' ,
50- 'var(--go-ui-color-red-40)' ,
51- 'var(--go-ui-color-red-20)' ,
52- 'var(--go-ui-color-red-10)' ,
53- ] ;
50+ const progressBarColor = 'var(--go-ui-color-dark-blue-40)' ;
51+
52+ function numberOfComponentsSelector ( { components } : { components : unknown [ ] } ) {
53+ return components . length ;
54+ }
55+
56+ function perRatingColorSelector ( { ratingValue } : { ratingValue : number | undefined } ) {
57+ return getPerRatingColor ( ratingValue ) ;
58+ }
59+
60+ function perRatingLabelSelector ( {
61+ ratingValue,
62+ ratingDisplay,
63+ } : {
64+ ratingValue ?: number ;
65+ ratingDisplay ?: string ;
66+ } ) : string {
67+ return `${ ratingValue } -${ ratingDisplay } ` ;
68+ }
5469
5570function PerAssessmentSummary ( props : Props ) {
5671 const {
@@ -142,9 +157,10 @@ function PerAssessmentSummary(props: Props) {
142157 ( areaResponse ) => {
143158 // NOTE: do we take the average of only rated components or of all the
144159 // components?
160+ // Also, 'component.rating' refers to the component ID and is misnamed.
145161 const filteredComponents = areaResponse ?. component_responses ?. filter (
146162 ( component ) => isDefined ( component ?. rating )
147- && component . rating !== 0 ,
163+ && component . rating !== 1 ,
148164 ) ?? [ ] ;
149165
150166 if ( filteredComponents . length === 0 ) {
@@ -173,7 +189,7 @@ function PerAssessmentSummary(props: Props) {
173189 areaId,
174190 rating : averageRatingByAreaMap [ Number ( areaId ) ] ?? 0 ,
175191 areaDisplay : resolveToString (
176- strings . multiImageArea ,
192+ strings . perArea ,
177193 { areaId } ,
178194 ) ,
179195 } ) ,
@@ -208,6 +224,7 @@ function PerAssessmentSummary(props: Props) {
208224 } ,
209225 ) }
210226 value = { allAnsweredResponses ?. length ?? 0 }
227+ color = { progressBarColor }
211228 totalValue = { totalQuestionCount }
212229 description = { (
213230 < div className = { styles . answerCounts } >
@@ -228,18 +245,9 @@ function PerAssessmentSummary(props: Props) {
228245 < StackedProgressBar
229246 className = { styles . componentRating }
230247 data = { statusGroupedComponentList ?? [ ] }
231- // FIXME: don't use inline selectors
232- valueSelector = {
233- ( statusGroupedComponent ) => (
234- statusGroupedComponent . components . length
235- )
236- }
237- // FIXME: don't use inline selectors
238- colorSelector = { ( _ , i ) => colors [ i ] }
239- // FIXME: don't use inline selectors
240- labelSelector = {
241- ( statusGroupedComponent ) => `${ statusGroupedComponent . ratingValue } -${ statusGroupedComponent . ratingDisplay } `
242- }
248+ valueSelector = { numberOfComponentsSelector }
249+ colorSelector = { perRatingColorSelector }
250+ labelSelector = { perRatingLabelSelector }
243251 />
244252 < div className = { styles . avgComponentRating } >
245253 { averageRatingByAreaList . map (
@@ -257,6 +265,7 @@ function PerAssessmentSummary(props: Props) {
257265 className = { styles . filledBar }
258266 style = { {
259267 height : `${ getPercentage ( rating . rating , averageRatingByAreaList . length ) } %` ,
268+ backgroundColor : getPerAreaColor ( Number ( rating . areaId ) ) ,
260269 } }
261270 />
262271 </ div >
0 commit comments