Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -178,14 +178,14 @@ describe('SearchCheckListComponent', () => {
update: () => {}
};
component.settings = <any> { options: sizeOptions };
spyOn(component, 'flush').and.stub();
spyOn(component, 'submitValues').and.stub();
component.ngOnInit();
fixture.detectChanges();

const optionElements = fixture.debugElement.query(By.css('mat-checkbox'));
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"]'));
clearAllElement.triggerEventHandler('click', {} );
Expand Down
Expand Up @@ -74,13 +74,22 @@ export class SearchCheckListComponent implements SearchWidget, OnInit {

changeHandler(event: MatCheckboxChange, option: any) {
option.checked = event.checked;
this.flush();
this.submitValues();
}

flush() {
const checkedValues = this.options.items
hasValidValue() {
const checkedValues = this.getCheckedValues();
return !!checkedValues.length;
}

private getCheckedValues() {
return this.options.items
.filter((option) => option.checked)
.map((option) => option.value);
}

submitValues() {
const checkedValues = this.getCheckedValues();

this.isActive = !!checkedValues.length;

Expand Down
Expand Up @@ -129,10 +129,14 @@ export class SearchDateRangeComponent implements SearchWidget, OnInit, OnDestroy
}
}

applyCurrentForm() {
submitValues() {
this.apply(this.form.value, this.form.valid);
}

hasValidValue() {
return this.form.valid;
}

reset() {
this.isActive = false;
this.form.reset({
Expand Down
Expand Up @@ -188,4 +188,25 @@ describe('SearchHeaderComponent', () => {
fixture.detectChanges();
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();
});
});
Expand Up @@ -129,15 +129,13 @@ export class SearchHeaderComponent implements OnInit, OnChanges, OnDestroy {
}

onApply() {
// TODO Move this piece of code in the search text widget
if (this.widgetContainer.selector === 'text' && this.widgetContainer.componentRef.instance.value === '') {
if (this.widgetContainer.hasValueSelected()) {
this.widgetContainer.applyInnerWidget();
this.searchHeaderQueryBuilder.setActiveFilter(this.category.columnKey);
this.searchHeaderQueryBuilder.execute();
} else {
this.clearHeader();
return;
}

this.widgetContainer.applyInnerWidget();
this.searchHeaderQueryBuilder.setActiveFilter(this.category.columnKey);
this.searchHeaderQueryBuilder.execute();
}

onClearButtonClick(event: Event) {
Expand Down
Expand Up @@ -100,6 +100,14 @@ export class SearchNumberRangeComponent implements SearchWidget, OnInit {
return result;
}

submitValues() {
this.apply(this.form.value, this.form.valid);
}

hasValidValue() {
return this.form.valid;
}

reset() {
this.isActive = false;

Expand Down
Expand Up @@ -83,6 +83,16 @@ export class SearchRadioComponent implements SearchWidget, OnInit {
return null;
}

submitValues() {
const currentValue = this.getSelectedValue();
this.setValue(currentValue);
}

hasValidValue() {
const currentValue = this.getSelectedValue();
return !!currentValue;
}

private setValue(newValue: string) {
this.value = newValue;
this.context.queryFragments[this.id] = newValue;
Expand Down
Expand Up @@ -70,6 +70,14 @@ export class SearchSliderComponent implements SearchWidget, OnInit {
this.updateQuery(this.value);
}

submitValues() {
this.updateQuery(this.value);
}

hasValidValue() {
return !!this.value;
}

private updateQuery(value: number | null) {
if (this.id && this.context && this.settings && this.settings.field) {
if (value === null) {
Expand Down
Expand Up @@ -71,6 +71,14 @@ export class SearchTextComponent implements SearchWidget, OnInit {

}

submitValues() {
this.updateQuery(this.value);
}

hasValidValue() {
return !!this.value;
}

private getSearchPrefix(): string {
return this.settings.searchPrefix ? this.settings.searchPrefix : '';
}
Expand Down
Expand Up @@ -77,9 +77,11 @@ export class SearchWidgetContainerComponent implements OnInit, OnDestroy {
}

applyInnerWidget() {
if (this.selector === 'date-range' && this.componentRef && this.componentRef.instance) {
this.componentRef.instance.applyCurrentForm();
}
this.componentRef.instance.submitValues();
}

hasValueSelected() {
return this.componentRef.instance.hasValidValue();
}

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