@@ -12,46 +12,65 @@ import {
1212 MappedIcon ,
1313 ValidatedIcon ,
1414 AsteriskIcon ,
15+ StarIcon ,
1516 HalfStarIcon ,
1617 FullStarIcon ,
18+ FullStarIconYellow ,
1719 ChartLineIcon ,
20+ FullStarIconBlue ,
1821} from '../svgIcons' ;
1922import ProjectProgressBar from '../projectCard/projectProgressBar' ;
2023import { useComputeCompleteness } from '../../hooks/UseProjectCompletenessCalc' ;
2124import { useFilterContributors } from '../../hooks/UseFilterContributors' ;
2225import { OSMChaButton } from '../projectDetail/osmchaButton' ;
2326import { useProjectContributionsLevelQuery } from '../../api/projects.js' ;
2427
25- export const MappingLevelIcon = ( { mappingLevel } ) => {
26- if ( ! mappingLevel ) {
28+ export const MappingLevelIcon = ( { mappingLevel, mappingLevelList } : Object ) => {
29+ if ( ! mappingLevel || ! mappingLevelList || mappingLevelList . length === 0 ) {
2730 return null ;
2831 }
32+
33+ // Sort the mapping levels by ordering
34+ const sortedLevels = [ ...mappingLevelList ] . sort ( ( a , b ) => a . ordering - b . ordering ) ;
35+
36+ // Find the current mapping level in the sorted list
2937 const upperCaseLevelStr = mappingLevel . toUpperCase ( ) ;
30- let level = null ;
38+ const currentLevel = sortedLevels . find ( ( level ) => level . name . toUpperCase ( ) === upperCaseLevelStr ) ;
3139
32- if ( upperCaseLevelStr . includes ( 'ADVANCED' ) ) {
33- level = 'ADVANCED' ;
34- } else if ( upperCaseLevelStr . includes ( 'INTERMEDIATE' ) ) {
35- level = 'INTERMEDIATE' ;
40+ if ( ! currentLevel ) {
41+ return null ;
3642 }
3743
38- if ( level ) {
39- return (
40- < FormattedMessage { ...messages [ `mappingLevel${ level } ` ] } >
41- { ( msg ) => (
42- < span className = "blue-grey ttl" title = { msg } >
43- { level === 'ADVANCED' ? (
44- < FullStarIcon className = "h1 w1 v-mid pb1" />
45- ) : (
46- < HalfStarIcon className = "h1 w1 v-mid pb1" />
47- ) }
48- </ span >
49- ) }
50- </ FormattedMessage >
51- ) ;
52- }
44+ // Determine which icon to show based on position in sorted array
45+ const getStarIcon = ( ) => {
46+ // Find the index (position) of the current level in the sorted array
47+ const currentIndex = sortedLevels . findIndex ( ( level ) => level . name === currentLevel . name ) ;
48+ const lastIndex = sortedLevels . length - 1 ;
5349
54- return null ;
50+ // First 3 positions (indices 0, 1, 2)
51+ if ( currentIndex === 0 ) {
52+ // Empty star for first position
53+ return < StarIcon className = "h1 w1 v-mid pb1" /> ;
54+ } else if ( currentIndex === 1 ) {
55+ // Half star for second position
56+ return < HalfStarIcon className = "h1 w1 v-mid pb1" /> ;
57+ } else if ( currentIndex === 2 ) {
58+ // Full star for third position
59+ return < FullStarIcon className = "h1 w1 v-mid pb1" /> ;
60+ } else if ( currentIndex === lastIndex ) {
61+ // Yellow star for last position (highest level)
62+ return < FullStarIconYellow className = "h1 w1 v-mid pb1" /> ;
63+ } else {
64+ // Full stars for anything in between
65+ return < FullStarIconBlue className = "h1 w1 v-mid pb1" /> ;
66+ }
67+ } ;
68+
69+ return (
70+ < span className = "blue-grey ttl" title = { currentLevel . name } >
71+ { getStarIcon ( ) }
72+ </ span >
73+ ) ;
5574} ;
5675
5776const sortByLits = [
@@ -95,7 +114,7 @@ const SortingHeader = ({ sortBy, setSortBy }: Object) => {
95114 ) ;
96115} ;
97116
98- function Contributor ( { user, activeUser, activeStatus, displayTasks } : Object ) {
117+ function Contributor ( { user, activeUser, activeStatus, displayTasks, mappingLevelList } : Object ) {
99118 const intl = useIntl ( ) ;
100119 const checkActiveUserAndStatus = ( status , username ) =>
101120 activeStatus === status && activeUser === username ? 'bg-blue-dark' : 'bg-grey-light' ;
@@ -123,7 +142,7 @@ function Contributor({ user, activeUser, activeStatus, displayTasks }: Object) {
123142 </ >
124143 ) }
125144 </ FormattedMessage >
126- { /* <MappingLevelIcon mappingLevel={user.mappingLevel} /> */ }
145+ < MappingLevelIcon mappingLevel = { user . mappingLevel } mappingLevelList = { mappingLevelList } />
127146 </ div >
128147
129148 < div className = "w-20 fl tr dib truncate" >
@@ -170,9 +189,16 @@ function Contributor({ user, activeUser, activeStatus, displayTasks }: Object) {
170189 ) ;
171190}
172191
173- const Contributions = ( { project, tasks, contribsData, activeUser, activeStatus, selectTask } ) => {
192+ const Contributions = ( {
193+ project,
194+ tasks,
195+ contribsData,
196+ activeUser,
197+ activeStatus,
198+ selectTask,
199+ } : Object ) => {
174200 const intl = useIntl ( ) ;
175- const { data } = useProjectContributionsLevelQuery ( ) ;
201+ const { data : mappingLevelList } = useProjectContributionsLevelQuery ( ) ;
176202
177203 const mappingLevels = useMemo ( ( ) => {
178204 const getLevelLabel = ( level ) => {
@@ -183,7 +209,7 @@ const Contributions = ({ project, tasks, contribsData, activeUser, activeStatus,
183209 } ;
184210
185211 const dynamicLevels =
186- data ?. map ( ( level ) => ( {
212+ mappingLevelList ?. map ( ( level ) => ( {
187213 value : level . name ,
188214 label : getLevelLabel ( level . name || '' ) ,
189215 } ) ) || [ ] ;
@@ -193,7 +219,7 @@ const Contributions = ({ project, tasks, contribsData, activeUser, activeStatus,
193219 ...dynamicLevels ,
194220 { value : 'NEWUSER' , label : intl . formatMessage ( messages . mappingLevelNEWUSER ) } ,
195221 ] ;
196- } , [ data , intl ] ) ;
222+ } , [ mappingLevelList , intl ] ) ;
197223
198224 const defaultUserFilter = {
199225 label : intl . formatMessage ( messages . userFilterDefaultLabel ) ,
@@ -279,6 +305,7 @@ const Contributions = ({ project, tasks, contribsData, activeUser, activeStatus,
279305 activeStatus = { activeStatus }
280306 displayTasks = { displayTasks }
281307 key = { k }
308+ mappingLevelList = { mappingLevelList }
282309 />
283310 ) ) }
284311 </ ReactPlaceholder >
0 commit comments