From b7e4b8b8dc9bf528009026b686c3840fea5f94ca Mon Sep 17 00:00:00 2001 From: Vyacheslav Tumanov Date: Fri, 24 Mar 2023 14:37:50 +0500 Subject: [PATCH] TSK-897: Allow team-leads and managers to edit descendant departments (#2825) Signed-off-by: Vyacheslav Tumanov --- .../src/components/ScheduleView.svelte | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/plugins/hr-resources/src/components/ScheduleView.svelte b/plugins/hr-resources/src/components/ScheduleView.svelte index 283b360053..3803bf7ab0 100644 --- a/plugins/hr-resources/src/components/ScheduleView.svelte +++ b/plugins/hr-resources/src/components/ScheduleView.svelte @@ -129,7 +129,7 @@ descendants: Map, Department[]> ): void { const staff = departmentStaff.filter((p) => p.department === department) - editableList.push(...staff.map((p) => p._id)) + editableList.push(...staff.filter((p) => !editableList.includes(p._id)).map((p) => p._id)) const desc = descendants.get(department) ?? [] for (const des of desc) { pushChilds(des._id, departmentStaff, descendants) @@ -147,10 +147,11 @@ descendants: Map, Department[]> ) { const dep = departmentById.get(department) - if (dep !== undefined && isEditable(dep)) { + if (dep === undefined) return + if (isEditable(dep)) { pushChilds(dep._id, departmentStaff, descendants) } else { - const descendantDepartments = descendants.get(department) + const descendantDepartments = descendants.get(dep._id) if (descendantDepartments !== undefined) { for (const department of descendantDepartments) { if (isEditable(department)) { @@ -165,12 +166,11 @@ function updateEditableList ( departmentById: Map, Department>, - department: Ref, departmentStaff: Staff[], descendants: Map, Department[]> ) { editableList = [currentEmployee] - checkDepartmentEditable(departmentById, department, departmentStaff, descendants) + checkDepartmentEditable(departmentById, hr.ids.Head, departmentStaff, descendants) editableList = editableList } @@ -178,15 +178,14 @@ staff: Staff[], departments: Ref[], employeeRequests: Map, Request[]>, - department: Ref, descendants: Map, Department[]>, departmentById: Map, Department> ) { departmentStaff = staff.filter((p) => departments.includes(p.department) || employeeRequests.has(p._id)) - updateEditableList(departmentById, department, departmentStaff, descendants) + updateEditableList(departmentById, departmentStaff, descendants) } - $: updateStaff(staff, departments, employeeRequests, department, descendants, departmentById) + $: updateStaff(staff, departments, employeeRequests, descendants, departmentById) const reportQuery = createQuery()