[ADF-5176] - fixed apply when no value is given (#5841)

* [ADF-5176] - added check for when values are empty for headers

* [ADF-5176] - added test for the clear check
This commit is contained in:
Vito
2020-07-07 17:07:49 +01:00
committed by GitHub
parent ed12b13c87
commit 30e980837a
11 changed files with 86 additions and 16 deletions

View File

@@ -178,14 +178,14 @@ describe('SearchCheckListComponent', () => {
update: () => {} update: () => {}
}; };
component.settings = <any> { options: sizeOptions }; component.settings = <any> { options: sizeOptions };
spyOn(component, 'flush').and.stub(); spyOn(component, 'submitValues').and.stub();
component.ngOnInit(); component.ngOnInit();
fixture.detectChanges(); fixture.detectChanges();
const optionElements = fixture.debugElement.query(By.css('mat-checkbox')); const optionElements = fixture.debugElement.query(By.css('mat-checkbox'));
optionElements.triggerEventHandler('change', { checked: true }); optionElements.triggerEventHandler('change', { checked: true });
expect(component.flush).toHaveBeenCalled(); expect(component.submitValues).toHaveBeenCalled();
const clearAllElement = fixture.debugElement.query(By.css('button[title="SEARCH.FILTER.ACTIONS.CLEAR-ALL"]')); const clearAllElement = fixture.debugElement.query(By.css('button[title="SEARCH.FILTER.ACTIONS.CLEAR-ALL"]'));
clearAllElement.triggerEventHandler('click', {} ); clearAllElement.triggerEventHandler('click', {} );

View File

@@ -74,13 +74,22 @@ export class SearchCheckListComponent implements SearchWidget, OnInit {
changeHandler(event: MatCheckboxChange, option: any) { changeHandler(event: MatCheckboxChange, option: any) {
option.checked = event.checked; option.checked = event.checked;
this.flush(); this.submitValues();
} }
flush() { hasValidValue() {
const checkedValues = this.options.items const checkedValues = this.getCheckedValues();
return !!checkedValues.length;
}
private getCheckedValues() {
return this.options.items
.filter((option) => option.checked) .filter((option) => option.checked)
.map((option) => option.value); .map((option) => option.value);
}
submitValues() {
const checkedValues = this.getCheckedValues();
this.isActive = !!checkedValues.length; this.isActive = !!checkedValues.length;

View File

@@ -129,10 +129,14 @@ export class SearchDateRangeComponent implements SearchWidget, OnInit, OnDestroy
} }
} }
applyCurrentForm() { submitValues() {
this.apply(this.form.value, this.form.valid); this.apply(this.form.value, this.form.valid);
} }
hasValidValue() {
return this.form.valid;
}
reset() { reset() {
this.isActive = false; this.isActive = false;
this.form.reset({ this.form.reset({

View File

@@ -188,4 +188,25 @@ describe('SearchHeaderComponent', () => {
fixture.detectChanges(); fixture.detectChanges();
await fixture.whenStable(); await fixture.whenStable();
}); });
it('should emit the clear event when no filter has valued applied', async (done) => {
spyOn(queryBuilder, 'isNoFilterActive').and.returnValue(true);
spyOn(alfrescoApiService.searchApi, 'search').and.returnValue(Promise.resolve(fakeNodePaging));
spyOn(queryBuilder, 'buildQuery').and.returnValue({});
spyOn(component.widgetContainer, 'resetInnerWidget').and.stub();
component.widgetContainer.componentRef.instance.value = '';
const fakeEvent = jasmine.createSpyObj('event', ['stopPropagation']);
component.clear.subscribe(() => {
done();
});
const menuButton: HTMLButtonElement = fixture.nativeElement.querySelector('#filter-menu-button');
menuButton.click();
fixture.detectChanges();
await fixture.whenStable();
const applyButton = fixture.debugElement.query(By.css('#apply-filter-button'));
applyButton.triggerEventHandler('click', fakeEvent);
fixture.detectChanges();
await fixture.whenStable();
});
}); });

View File

@@ -129,15 +129,13 @@ export class SearchHeaderComponent implements OnInit, OnChanges, OnDestroy {
} }
onApply() { onApply() {
// TODO Move this piece of code in the search text widget if (this.widgetContainer.hasValueSelected()) {
if (this.widgetContainer.selector === 'text' && this.widgetContainer.componentRef.instance.value === '') { this.widgetContainer.applyInnerWidget();
this.searchHeaderQueryBuilder.setActiveFilter(this.category.columnKey);
this.searchHeaderQueryBuilder.execute();
} else {
this.clearHeader(); this.clearHeader();
return;
} }
this.widgetContainer.applyInnerWidget();
this.searchHeaderQueryBuilder.setActiveFilter(this.category.columnKey);
this.searchHeaderQueryBuilder.execute();
} }
onClearButtonClick(event: Event) { onClearButtonClick(event: Event) {

View File

@@ -100,6 +100,14 @@ export class SearchNumberRangeComponent implements SearchWidget, OnInit {
return result; return result;
} }
submitValues() {
this.apply(this.form.value, this.form.valid);
}
hasValidValue() {
return this.form.valid;
}
reset() { reset() {
this.isActive = false; this.isActive = false;

View File

@@ -83,6 +83,16 @@ export class SearchRadioComponent implements SearchWidget, OnInit {
return null; return null;
} }
submitValues() {
const currentValue = this.getSelectedValue();
this.setValue(currentValue);
}
hasValidValue() {
const currentValue = this.getSelectedValue();
return !!currentValue;
}
private setValue(newValue: string) { private setValue(newValue: string) {
this.value = newValue; this.value = newValue;
this.context.queryFragments[this.id] = newValue; this.context.queryFragments[this.id] = newValue;

View File

@@ -70,6 +70,14 @@ export class SearchSliderComponent implements SearchWidget, OnInit {
this.updateQuery(this.value); this.updateQuery(this.value);
} }
submitValues() {
this.updateQuery(this.value);
}
hasValidValue() {
return !!this.value;
}
private updateQuery(value: number | null) { private updateQuery(value: number | null) {
if (this.id && this.context && this.settings && this.settings.field) { if (this.id && this.context && this.settings && this.settings.field) {
if (value === null) { if (value === null) {

View File

@@ -71,6 +71,14 @@ export class SearchTextComponent implements SearchWidget, OnInit {
} }
submitValues() {
this.updateQuery(this.value);
}
hasValidValue() {
return !!this.value;
}
private getSearchPrefix(): string { private getSearchPrefix(): string {
return this.settings.searchPrefix ? this.settings.searchPrefix : ''; return this.settings.searchPrefix ? this.settings.searchPrefix : '';
} }

View File

@@ -77,9 +77,11 @@ export class SearchWidgetContainerComponent implements OnInit, OnDestroy {
} }
applyInnerWidget() { applyInnerWidget() {
if (this.selector === 'date-range' && this.componentRef && this.componentRef.instance) { this.componentRef.instance.submitValues();
this.componentRef.instance.applyCurrentForm(); }
}
hasValueSelected() {
return this.componentRef.instance.hasValidValue();
} }
resetInnerWidget() { resetInnerWidget() {

View File

@@ -24,4 +24,6 @@ export interface SearchWidget {
context?: SearchQueryBuilderService; context?: SearchQueryBuilderService;
isActive?: boolean; isActive?: boolean;
reset(); reset();
submitValues();
hasValidValue();
} }