@@ -56,16 +56,14 @@ const useOranisationUsersData = (organisationId: string) => {
56
56
. map ( ( { projects, activity, first_seen, last_seen_date, username } ) => {
57
57
// get all the unique units from the projects
58
58
// include the unit name from the units response
59
- const inventoryUnits = Object . values ( projects )
60
- . flat ( )
59
+ const touchableProjects = [ projects . administrator , projects . editor ] . flat ( ) ;
60
+ const inventoryUnits = touchableProjects
61
61
. map ( ( { unit_id } ) => ( {
62
62
id : unit_id ,
63
63
name : units ?. find ( ( unit ) => unit . id === unit_id ) ?. name ,
64
- number_of_projects : Object . values ( projects )
65
- . flat ( )
66
- . reduce ( ( count , project ) => {
67
- return project . unit_id === unit_id ? count + 1 : count ;
68
- } , 0 ) ,
64
+ number_of_projects : touchableProjects . reduce ( ( count , project ) => {
65
+ return project . unit_id === unit_id ? count + 1 : count ;
66
+ } , 0 ) ,
69
67
} ) )
70
68
. reduce < Unit [ ] > ( ( uniqueUnits , unit ) => {
71
69
// keep only unique units
@@ -98,7 +96,12 @@ const useOranisationUsersData = (organisationId: string) => {
98
96
id : unit . id ,
99
97
name : unit . name ,
100
98
number_of_projects :
101
- allProjects ?. filter ( ( project ) => project . unit_id === unit . id ) . length ?? 0 ,
99
+ allProjects ?. filter (
100
+ ( project ) =>
101
+ project . unit_id === unit . id &&
102
+ ( project . editors . includes ( username ) ||
103
+ project . administrators . includes ( username ) ) ,
104
+ ) . length ?? 0 ,
102
105
} ) ) ?? [ ] ;
103
106
104
107
const allUnits = [ ...inventoryUnits , ...newUnits ] ;
0 commit comments