diff --git a/package.json b/package.json index a15fb2ff..fcae23de 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hmcts/rpx-xui-common-lib", - "version": "2.0.23-find-self-user-search", + "version": "2.0.25", "engines": { "node": ">=18.19.0" }, diff --git a/projects/exui-common-lib/package.json b/projects/exui-common-lib/package.json index 01ac237c..7cbabe6d 100644 --- a/projects/exui-common-lib/package.json +++ b/projects/exui-common-lib/package.json @@ -1,6 +1,6 @@ { "name": "@hmcts/rpx-xui-common-lib", - "version": "2.0.23-find-self-user-search", + "version": "2.0.25", "peerDependencies": { "launchdarkly-js-client-sdk": "^3.3.0", "ngx-pagination": "^3.2.1", diff --git a/projects/exui-common-lib/src/lib/components/generic-filter/generic-filter.component.html b/projects/exui-common-lib/src/lib/components/generic-filter/generic-filter.component.html index 9ae56521..bcc78f1f 100644 --- a/projects/exui-common-lib/src/lib/components/generic-filter/generic-filter.component.html +++ b/projects/exui-common-lib/src/lib/components/generic-filter/generic-filter.component.html @@ -162,6 +162,7 @@

+ {{serviceErrorMsg | rpxTranslate}} { RpxTranslateMockPipe ], providers: [ - {provide: FilterService, useValue: mockFilterService}, - {provide: LocationService, useValue: searchFilterServiceMock} + { provide: FilterService, useValue: mockFilterService }, + { provide: LocationService, useValue: searchFilterServiceMock } ] }) .compileComponents(); @@ -76,17 +76,17 @@ describe('GenericFilterComponent', () => { cancelButtonText: 'cancel', cancelSetting: { id: 'examples', - fields: [{name: 'example1', value: ['Fernando Alonso']}] + fields: [{ name: 'example1', value: ['Fernando Alonso'] }] }, fields: [ { name: 'example1', options: [ - {key: 'Fernando Alonso', label: 'Fernando Alonso'}, - {key: 'Sebastian Vettel', label: 'Sebastian Vettel'}, - {key: 'Lewis Hamilton', label: 'Lewis Hamilton'}, - {key: 'Mick Schumacher', label: 'Mick Schumacher'}, - {key: 'Lando Norris', label: 'Lando Norris'}, + { key: 'Fernando Alonso', label: 'Fernando Alonso' }, + { key: 'Sebastian Vettel', label: 'Sebastian Vettel' }, + { key: 'Lewis Hamilton', label: 'Lewis Hamilton' }, + { key: 'Mick Schumacher', label: 'Mick Schumacher' }, + { key: 'Lando Norris', label: 'Lando Norris' }, ], title: 'Sample title', subTitle: 'Sample subtitle', @@ -97,11 +97,11 @@ describe('GenericFilterComponent', () => { { name: 'example2', options: [ - {key: 'Tinky Winky', label: 'Tinky Winky'}, - {key: 'Dipsy', label: 'Dipsy'}, - {key: 'Laa-Laa', label: 'Laa-Laa'}, - {key: 'Po', label: 'Po'}, - {key: 'Noo-noo', label: 'Noo-noo'}, + { key: 'Tinky Winky', label: 'Tinky Winky' }, + { key: 'Dipsy', label: 'Dipsy' }, + { key: 'Laa-Laa', label: 'Laa-Laa' }, + { key: 'Po', label: 'Po' }, + { key: 'Noo-noo', label: 'Noo-noo' }, ], title: 'Sample2 title', subTitle: 'Sample2 subtitle', @@ -112,11 +112,11 @@ describe('GenericFilterComponent', () => { { name: 'example3', options: [ - {key: 'yellow', label: 'Yellow'}, - {key: 'green', label: 'Green'}, - {key: 'red', label: 'Red'}, - {key: 'blue', label: 'Blue'}, - {key: 'orange', label: 'Orange'}, + { key: 'yellow', label: 'Yellow' }, + { key: 'green', label: 'Green' }, + { key: 'red', label: 'Red' }, + { key: 'blue', label: 'Blue' }, + { key: 'orange', label: 'Orange' }, ], title: 'Sample3 title', subTitle: 'Sample3 subtitle', @@ -443,12 +443,12 @@ describe('Select all checkboxes', () => { { name: 'example1', options: [ - {key: 'All', label: 'Select All', selectAll: true}, - {key: 'Fernando Alonso', label: 'Fernando Alonso'}, - {key: 'Sebastian Vettel', label: 'Sebastian Vettel'}, - {key: 'Lewis Hamilton', label: 'Lewis Hamilton'}, - {key: 'Mick Schumacher', label: 'Mick Schumacher'}, - {key: 'Lando Norris', label: 'Lando Norris'}, + { key: 'All', label: 'Select All', selectAll: true }, + { key: 'Fernando Alonso', label: 'Fernando Alonso' }, + { key: 'Sebastian Vettel', label: 'Sebastian Vettel' }, + { key: 'Lewis Hamilton', label: 'Lewis Hamilton' }, + { key: 'Mick Schumacher', label: 'Mick Schumacher' }, + { key: 'Lando Norris', label: 'Lando Norris' }, ], title: 'Sample title', subTitle: 'Sample subtitle', @@ -521,7 +521,7 @@ describe('Find location filter config', () => { ], providers: [ FilterService, - {provide: LocationService, useValue: searchFilterServiceMock} + { provide: LocationService, useValue: searchFilterServiceMock } ] }) .compileComponents(); @@ -557,58 +557,75 @@ describe('Find location filter config', () => { expect(findLocationFormGroup).toBeTruthy(); }); + it('should call the inputchanged function and set isSelectedService', () => { + const field: FilterFieldConfig = { + name: 'user-location', + title: 'Skills', + options: [], + minSelected: 0, + maxSelected: 0, + type: 'find-location', + lineBreakBefore: true, + disabledText: 'All' + }; + component['selectedServices'] = []; + component.isServiceSelected = false; + fixture.detectChanges(); + component.inputChanged(field); + expect(component.isServiceSelected).toBeTruthy(); + }); describe('group-select dropdown', () => { - const groupOptions: GroupOptions[] = [ + const groupOptions: GroupOptions[] = [ { group: 'servieA', options: [ - {key: 'serviceA-key1', label: 'Key1'}, - {key: 'serviceA-key3', label: 'Key3'}, - {key: 'serviceA-key2', label: 'Key2'} + { key: 'serviceA-key1', label: 'Key1' }, + { key: 'serviceA-key3', label: 'Key3' }, + { key: 'serviceA-key2', label: 'Key2' } ] }, { group: 'servieC', options: [ - {key: 'serviceC-key3', label: 'Key3'}, - {key: 'serviceC-key2', label: 'Key2'}, - {key: 'serviceC-key1', label: 'Key1'} + { key: 'serviceC-key3', label: 'Key3' }, + { key: 'serviceC-key2', label: 'Key2' }, + { key: 'serviceC-key1', label: 'Key1' } ] }, { group: 'servieB', options: [ - {key: 'serviceB-key2', label: 'Key2'}, - {key: 'serviceB-key1', label: 'Key1'}, - {key: 'serviceB-key3', label: 'Key3'} + { key: 'serviceB-key2', label: 'Key2' }, + { key: 'serviceB-key1', label: 'Key1' }, + { key: 'serviceB-key3', label: 'Key3' } ] } ]; - const sortedGroupOptions: GroupOptions[] = [ + const sortedGroupOptions: GroupOptions[] = [ { group: 'servieA', options: [ - {key: 'serviceA-key1', label: 'Key1'}, - {key: 'serviceA-key2', label: 'Key2'}, - {key: 'serviceA-key3', label: 'Key3'} + { key: 'serviceA-key1', label: 'Key1' }, + { key: 'serviceA-key2', label: 'Key2' }, + { key: 'serviceA-key3', label: 'Key3' } ] }, { group: 'servieB', options: [ - {key: 'serviceB-key1', label: 'Key1'}, - {key: 'serviceB-key2', label: 'Key2'}, - {key: 'serviceB-key3', label: 'Key3'} + { key: 'serviceB-key1', label: 'Key1' }, + { key: 'serviceB-key2', label: 'Key2' }, + { key: 'serviceB-key3', label: 'Key3' } ] }, { group: 'servieC', options: [ - {key: 'serviceC-key1', label: 'Key1'}, - {key: 'serviceC-key2', label: 'Key2'}, - {key: 'serviceC-key3', label: 'Key3'} + { key: 'serviceC-key1', label: 'Key1' }, + { key: 'serviceC-key2', label: 'Key2' }, + { key: 'serviceC-key3', label: 'Key3' } ] } ]; diff --git a/projects/exui-common-lib/src/lib/components/generic-filter/generic-filter.component.ts b/projects/exui-common-lib/src/lib/components/generic-filter/generic-filter.component.ts index 9e552559..c0125fc7 100644 --- a/projects/exui-common-lib/src/lib/components/generic-filter/generic-filter.component.ts +++ b/projects/exui-common-lib/src/lib/components/generic-filter/generic-filter.component.ts @@ -20,8 +20,11 @@ export class GenericFilterComponent implements OnInit, OnDestroy { public filteredSkillsByServicesCheckbox: FilterConfigOption[]; public previousSelectedNestedCheckbox: string[] = []; public formSubmissionEvent$ = new Subject(); + public isServiceSelected: boolean = false; + public serviceErrorMsg = 'Please select a service'; + private selectedServices: string[] = []; - constructor(private readonly filterService: FilterService, private readonly fb: FormBuilder) {} + constructor(private readonly filterService: FilterService, private readonly fb: FormBuilder) { } // tslint:disable-next-line:variable-name private _config: FilterConfig; @@ -90,7 +93,7 @@ export class GenericFilterComponent implements OnInit, OnDestroy { const services = this.config.fields.find(field => field.name === 'user-services'); if (services) { this.startFilterSkillsByServices(this.form, services); - if(!this._config.copyFields) { + if (!this._config.copyFields) { this.initValuesFromCacheForSkillsByServices(); } } @@ -179,7 +182,7 @@ export class GenericFilterComponent implements OnInit, OnDestroy { fields: this.getSelectedValues(form.value, this.config) }; this.filterService.givenErrors.next(null); - const settings = {...this.settings, reset: false}; + const settings = { ...this.settings, reset: false }; this.filterService.persist(settings, this.config.persistence); } else { this.emitFormErrors(form); @@ -202,6 +205,13 @@ export class GenericFilterComponent implements OnInit, OnDestroy { // when user enters input change radio button public inputChanged(field: FilterFieldConfig): void { + if (field.name === 'user-location') { + if (!this.selectedServices.length) { + this.isServiceSelected = true; + } else { + this.isServiceSelected = false; + } + } if (field.radioSelectionChange && typeof field.radioSelectionChange === 'string') { const [name, value] = field.enableCondition.split('='); this.form.get(name).patchValue(value); @@ -210,8 +220,13 @@ export class GenericFilterComponent implements OnInit, OnDestroy { public inputServiceChanged(field: FilterFieldConfig): void { if (field.name === 'user-services') { - const selectedServices = this.getSelectedValuesForFields(this.form.controls, field); - this.filterSkillsByServices(selectedServices, this.config); + this.selectedServices = this.getSelectedValuesForFields(this.form.controls, field); + this.filterSkillsByServices(this.selectedServices, this.config); + if (this.selectedServices.length) { + this.isServiceSelected = false; + } else { + this.isServiceSelected = true; + } } } @@ -220,7 +235,7 @@ export class GenericFilterComponent implements OnInit, OnDestroy { if (this.config && this.config.cancelSetting) { this._settings.fields = JSON.parse(JSON.stringify(this.config.cancelSetting.fields)); } - const settings = {...this.settings, reset: true}; + const settings = { ...this.settings, reset: true }; this.filterService.persist(settings, this.config.persistence); this.filterService.givenErrors.next(null); this.submitted = false; @@ -477,12 +492,12 @@ export class GenericFilterComponent implements OnInit, OnDestroy { if (Array.isArray(values)) { const field = config.fields.find(f => f.name === name); if (field.type === 'find-location' || field.type === 'find-service') { - return {value: values, name}; + return { value: values, name }; } else { - return {value: getValues(field.options, values), name}; + return { value: getValues(field.options, values), name }; } } else { - return {value: [values], name}; + return { value: [values], name }; } }); } @@ -493,15 +508,15 @@ export class GenericFilterComponent implements OnInit, OnDestroy { const fieldName = field.name; const formGroup = form.get(fieldName); if (formGroup && formGroup.errors && (formGroup.errors.minlength || formGroup.errors.required)) { - errors.push({name: fieldName, error: field.minSelectedError}); + errors.push({ name: fieldName, error: field.minSelectedError }); } if (formGroup && formGroup.errors && formGroup.errors.maxlength) { - errors.push({name: fieldName, error: field.maxSelectedError}); + errors.push({ name: fieldName, error: field.maxSelectedError }); } } // remove duplicates - errors = errors.filter( (filterError, i, arr) => { + errors = errors.filter((filterError, i, arr) => { return errors.indexOf(arr.find(item => item.name === filterError.name)) === i; }); @@ -602,10 +617,10 @@ export class GenericFilterComponent implements OnInit, OnDestroy { const preSelectedSkills: boolean[] = []; this.filteredSkillsByServicesCheckbox.map((skillsByServices, index) => { - for(let i = 0; i 0) { + if (preSelectedSkills.length > 0) { preSelectedSkills.forEach((h) => { (this.form.get('user-skills') as FormArray).push(new FormControl(h)); }); @@ -655,7 +670,7 @@ export class GenericFilterComponent implements OnInit, OnDestroy { return a.label.toLowerCase() > b.label.toLowerCase() ? 1 : (b.label.toLowerCase() > a.label.toLowerCase() ? -1 : 0); }); const result = { - group : g, + group: g, options: sortedOptions }; sortedResults.push(result); diff --git a/projects/exui-common-lib/src/lib/services/find-person/find-person.service.ts b/projects/exui-common-lib/src/lib/services/find-person/find-person.service.ts index fdf83b5d..07889056 100644 --- a/projects/exui-common-lib/src/lib/services/find-person/find-person.service.ts +++ b/projects/exui-common-lib/src/lib/services/find-person/find-person.service.ts @@ -79,10 +79,11 @@ export class FindAPersonService { roleCategory = RoleCategory.CTSC; } } + const searchTerm = searchOptions && searchOptions.searchTerm ? searchOptions.searchTerm.toLowerCase() : ''; const people = caseworkers ? this.mapCaseworkers(caseworkers, roleCategory) : []; - const finalPeopleList = people.filter(person => person && person.name && person.name.toLowerCase().includes(searchOptions.searchTerm)); + const finalPeopleList = people.filter(person => person && person.name && person.name.toLowerCase().includes(searchTerm)); return searchOptions.userIncluded ? finalPeopleList.filter(person => person && person.id !== this.assignedUser) - : finalPeopleList.filter(person => person && person.id !== this.assignedUser); + : finalPeopleList.filter(person => person || person.id.includes(this.userId) && person.id !== this.assignedUser); } public searchJudicial(value: string, serviceId: string): Observable {