@@ -22,6 +22,11 @@ import {
2222} from '@togglecorp/fujs' ;
2323import { PartialForm } from '@togglecorp/toggle-form' ;
2424
25+ import {
26+ PER_FALLBACK_COLOR ,
27+ perAreaColorMap ,
28+ perRatingColorMap ,
29+ } from '#utils/domain/per' ;
2530import { type GoApiResponse } from '#utils/restRequest' ;
2631
2732import i18n from './i18n.json' ;
@@ -43,27 +48,29 @@ interface Props {
4348 areaIdToTitleMap : Record < number , string | undefined > ;
4449}
4550
46- const perRatingColors : {
47- [ key : string ] : string ;
48- } = {
49- 5 : 'var(--go-ui-color-dark-blue-40)' ,
50- 4 : 'var(--go-ui-color-dark-blue-30)' ,
51- 3 : 'var(--go-ui-color-dark-blue-20)' ,
52- 2 : 'var(--go-ui-color-dark-blue-10)' ,
53- 1 : 'var(--go-ui-color-gray-40)' ,
54- 0 : 'var(--go-ui-color-gray-30)' ,
55- } ;
56-
57- const areaColorShades : { [ key : string ] : string } = {
58- 1 : 'var(--go-ui-color-purple-per)' ,
59- 2 : 'var(--go-ui-color-orange-per)' ,
60- 3 : 'var(--go-ui-color-blue-per)' ,
61- 4 : 'var(--go-ui-color-teal-per)' ,
62- 5 : 'var(--go-ui-color-red-per)' ,
63- } ;
64-
6551const progressBarColor = 'var(--go-ui-color-dark-blue-40)' ;
6652
53+ function numberOfComponentsSelector ( { components } : { components : unknown [ ] } ) {
54+ return components . length ;
55+ }
56+
57+ function perRatingColorSelector ( { ratingValue } : { ratingValue : number | undefined } ) {
58+ if ( isDefined ( ratingValue ) ) {
59+ return perRatingColorMap [ ratingValue ] ;
60+ }
61+ return PER_FALLBACK_COLOR ;
62+ }
63+
64+ function perRatingLabelSelector ( {
65+ ratingValue,
66+ ratingDisplay,
67+ } : {
68+ ratingValue ?: number ;
69+ ratingDisplay ?: string ;
70+ } ) : string {
71+ return `${ ratingValue } -${ ratingDisplay } ` ;
72+ }
73+
6774function PerAssessmentSummary ( props : Props ) {
6875 const {
6976 className,
@@ -156,7 +163,7 @@ function PerAssessmentSummary(props: Props) {
156163 // components?
157164 const filteredComponents = areaResponse ?. component_responses ?. filter (
158165 ( component ) => isDefined ( component ?. rating_details ?. value )
159- && component . rating_details ? .value !== 0 ,
166+ && component . rating_details . value !== 0 ,
160167 ) ?? [ ] ;
161168
162169 if ( filteredComponents . length === 0 ) {
@@ -185,7 +192,7 @@ function PerAssessmentSummary(props: Props) {
185192 areaId,
186193 rating : averageRatingByAreaMap [ Number ( areaId ) ] ?? 0 ,
187194 areaDisplay : resolveToString (
188- strings . multiImageArea ,
195+ strings . perArea ,
189196 { areaId } ,
190197 ) ,
191198 } ) ,
@@ -241,20 +248,9 @@ function PerAssessmentSummary(props: Props) {
241248 < StackedProgressBar
242249 className = { styles . componentRating }
243250 data = { statusGroupedComponentList ?? [ ] }
244- // FIXME: don't use inline selectors
245- valueSelector = {
246- ( statusGroupedComponent ) => (
247- statusGroupedComponent . components . length
248- )
249- }
250- // FIXME: don't use inline selectors
251- colorSelector = { ( statusGroupedComponent ) => (
252- perRatingColors [ statusGroupedComponent . ratingValue ?? 0 ]
253- ) }
254- // FIXME: don't use inline selectors
255- labelSelector = {
256- ( statusGroupedComponent ) => `${ statusGroupedComponent . ratingValue } -${ statusGroupedComponent . ratingDisplay } `
257- }
251+ valueSelector = { numberOfComponentsSelector }
252+ colorSelector = { perRatingColorSelector }
253+ labelSelector = { perRatingLabelSelector }
258254 />
259255 < div className = { styles . avgComponentRating } >
260256 { averageRatingByAreaList . map (
@@ -272,7 +268,7 @@ function PerAssessmentSummary(props: Props) {
272268 className = { styles . filledBar }
273269 style = { {
274270 height : `${ getPercentage ( rating . rating , averageRatingByAreaList . length ) } %` ,
275- backgroundColor : areaColorShades [ rating . areaId ] ,
271+ backgroundColor : perAreaColorMap [ Number ( rating . areaId ) ] ,
276272 } }
277273 />
278274 </ div >
0 commit comments