From aaf218acd4c6cc0ad910ab3707e12aa865cbac59 Mon Sep 17 00:00:00 2001 From: samuelmbabhazi Date: Tue, 17 Dec 2024 09:50:42 +0200 Subject: [PATCH] =?UTF-8?q?Fix:=20Unable=20to=20remove=20selection=20when?= =?UTF-8?q?=20user=20use=20=E2=80=9CSelect=20All=E2=80=9D=20Option=20in=20?= =?UTF-8?q?=E2=80=9CInvite=20Employee=E2=80=9D=20Popup=20Window?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../email-invite-form.component.ts | 47 +++++++++++++------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/packages/ui-core/shared/src/lib/invite/forms/email-invite-form/email-invite-form.component.ts b/packages/ui-core/shared/src/lib/invite/forms/email-invite-form/email-invite-form.component.ts index 0a2b3b67084..3a9ab5af7c5 100644 --- a/packages/ui-core/shared/src/lib/invite/forms/email-invite-form/email-invite-form.component.ts +++ b/packages/ui-core/shared/src/lib/invite/forms/email-invite-form/email-invite-form.component.ts @@ -157,9 +157,16 @@ export class EmailInviteFormComponent extends TranslationBaseComponent implement * SELECT all organization projects */ selectAllProjects() { - const organizationProjects = this.organizationProjects.map((project) => project.id).filter(Boolean); + const currentValue = this.form.get('projects').value || []; + const allProjectIds = this.organizationProjects.map((project) => project.id).filter(Boolean); - this.form.get('projects').setValue(organizationProjects); + if (currentValue.length === allProjectIds.length) { + // Deselect all if all are already selected + this.form.get('projects').setValue([]); + } else { + // Select all + this.form.get('projects').setValue(allProjectIds); + } this.form.get('projects').updateValueAndValidity(); } @@ -167,33 +174,45 @@ export class EmailInviteFormComponent extends TranslationBaseComponent implement * SELECT all organization departments and update form control value */ selectAllDepartments() { - const departmentIds = this.organizationDepartments.map((department) => department.id).filter(Boolean); + const currentValue = this.form.get('departments').value || []; + const allDepartmentIds = this.organizationDepartments.map((department) => department.id).filter(Boolean); - this.form.patchValue({ - departments: departmentIds - }); + if (currentValue.length === allDepartmentIds.length) { + this.form.get('departments').setValue([]); + } else { + this.form.get('departments').setValue(allDepartmentIds); + } + this.form.get('departments').updateValueAndValidity(); } /** * SELECT all organization contacts and update form control value */ selectAllOrganizationContacts() { - const organizationContactIds = this.organizationContacts.map((contact) => contact.id).filter(Boolean); + const currentValue = this.form.get('organizationContacts').value || []; + const allContactIds = this.organizationContacts.map((contact) => contact.id).filter(Boolean); - this.form.patchValue({ - organizationContacts: organizationContactIds - }); + if (currentValue.length === allContactIds.length) { + this.form.get('organizationContacts').setValue([]); + } else { + this.form.get('organizationContacts').setValue(allContactIds); + } + this.form.get('organizationContacts').updateValueAndValidity(); } /** * SELECT all organization teams and update form control value */ selectAllTeams() { - const organizationTeamsIds = this.organizationTeams.map((team) => team.id).filter(Boolean); + const currentValue = this.form.get('teams').value || []; + const allTeamIds = this.organizationTeams.map((team) => team.id).filter(Boolean); - this.form.patchValue({ - teams: organizationTeamsIds - }); + if (currentValue.length === allTeamIds.length) { + this.form.get('teams').setValue([]); + } else { + this.form.get('teams').setValue(allTeamIds); + } + this.form.get('teams').updateValueAndValidity(); } /**