Skip to content

Commit b3e8c6f

Browse files
committed
fix: hide units for which a user is only a project observer
1 parent 736d73c commit b3e8c6f

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/components/usage/OrganisationUserUsage.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,14 @@ const useOranisationUsersData = (organisationId: string) => {
5656
.map(({ projects, activity, first_seen, last_seen_date, username }) => {
5757
// get all the unique units from the projects
5858
// 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
6161
.map(({ unit_id }) => ({
6262
id: unit_id,
6363
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),
6967
}))
7068
.reduce<Unit[]>((uniqueUnits, unit) => {
7169
// keep only unique units
@@ -98,7 +96,12 @@ const useOranisationUsersData = (organisationId: string) => {
9896
id: unit.id,
9997
name: unit.name,
10098
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,
102105
})) ?? [];
103106

104107
const allUnits = [...inventoryUnits, ...newUnits];

0 commit comments

Comments
 (0)