mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
Revert "[ACS-10083] Filter not behaving correctly in file and site (#11237)"
This reverts commit 5016eff847.
This commit is contained in:
+1
-17
@@ -1276,25 +1276,9 @@ describe('DocumentList', () => {
|
|||||||
documentList.onNodeDblClick(node);
|
documentList.onNodeDblClick(node);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should load folder by ID on init if no filterValue is provided', async () => {
|
it('should load folder by ID on init', async () => {
|
||||||
spyOn(documentList, 'loadFolder').and.stub();
|
spyOn(documentList, 'loadFolder').and.stub();
|
||||||
|
|
||||||
documentList.filterValue = {};
|
|
||||||
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
documentList.ngOnChanges({ currentFolderId: new SimpleChange(undefined, '1d26e465-dea3-42f3-b415-faa8364b9692', true) });
|
|
||||||
|
|
||||||
await fixture.whenStable();
|
|
||||||
|
|
||||||
expect(documentList.loadFolder).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should NOT load folder by ID on init if filterValue is provided', async () => {
|
|
||||||
spyOn(documentList, 'loadFolder').and.stub();
|
|
||||||
|
|
||||||
documentList.filterValue = undefined;
|
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
documentList.ngOnChanges({ currentFolderId: new SimpleChange(undefined, '1d26e465-dea3-42f3-b415-faa8364b9692', true) });
|
documentList.ngOnChanges({ currentFolderId: new SimpleChange(undefined, '1d26e465-dea3-42f3-b415-faa8364b9692', true) });
|
||||||
|
|||||||
@@ -599,7 +599,7 @@ export class DocumentListComponent extends DataTableSchema implements OnInit, On
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.currentFolderId && changes['currentFolderId']?.currentValue !== changes['currentFolderId']?.previousValue) {
|
if (this.currentFolderId && changes['currentFolderId']?.currentValue !== changes['currentFolderId']?.previousValue) {
|
||||||
!this.filterValue && this.loadFolder();
|
this.loadFolder();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.data) {
|
if (this.data) {
|
||||||
@@ -816,6 +816,7 @@ export class DocumentListComponent extends DataTableSchema implements OnInit, On
|
|||||||
this.preserveExistingSelection();
|
this.preserveExistingSelection();
|
||||||
}
|
}
|
||||||
this.onPreselectNodes();
|
this.onPreselectNodes();
|
||||||
|
this.setLoadingState(false);
|
||||||
this.onDataReady(nodePaging);
|
this.onDataReady(nodePaging);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1022,7 +1023,6 @@ export class DocumentListComponent extends DataTableSchema implements OnInit, On
|
|||||||
private onDataReady(nodePaging: NodePaging) {
|
private onDataReady(nodePaging: NodePaging) {
|
||||||
this.ready.emit(nodePaging);
|
this.ready.emit(nodePaging);
|
||||||
this.pagination.next(nodePaging.list.pagination);
|
this.pagination.next(nodePaging.list.pagination);
|
||||||
this.setLoadingState(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePagination(requestPaginationModel: RequestPaginationModel) {
|
updatePagination(requestPaginationModel: RequestPaginationModel) {
|
||||||
|
|||||||
+3
-49
@@ -109,35 +109,7 @@ describe('FilterHeaderComponent', () => {
|
|||||||
expect(setCurrentRootFolderIdSpy).toHaveBeenCalled();
|
expect(setCurrentRootFolderIdSpy).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set filters if initial value is provided', async () => {
|
it('should set active filters when an initial value is set', async () => {
|
||||||
spyOn(queryBuilder, 'setCurrentRootFolderId');
|
|
||||||
spyOn(queryBuilder, 'isCustomSourceNode').and.returnValue(false);
|
|
||||||
spyOn(queryBuilder, 'setActiveFilter');
|
|
||||||
|
|
||||||
component.value = { name: 'pinocchio' };
|
|
||||||
const currentFolderNodeIdChange = new SimpleChange('current-node-id', 'next-node-id', true);
|
|
||||||
component.ngOnChanges({ currentFolderId: currentFolderNodeIdChange });
|
|
||||||
fixture.detectChanges();
|
|
||||||
await fixture.whenStable();
|
|
||||||
|
|
||||||
expect(queryBuilder.setActiveFilter).toHaveBeenCalledWith('name', 'pinocchio');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should NOT set filters if initial value is not provided', async () => {
|
|
||||||
spyOn(queryBuilder, 'setCurrentRootFolderId');
|
|
||||||
spyOn(queryBuilder, 'isCustomSourceNode').and.returnValue(false);
|
|
||||||
spyOn(queryBuilder, 'setActiveFilter');
|
|
||||||
|
|
||||||
component.value = undefined;
|
|
||||||
const currentFolderNodeIdChange = new SimpleChange('current-node-id', 'next-node-id', true);
|
|
||||||
component.ngOnChanges({ currentFolderId: currentFolderNodeIdChange });
|
|
||||||
fixture.detectChanges();
|
|
||||||
await fixture.whenStable();
|
|
||||||
|
|
||||||
expect(queryBuilder.setActiveFilter).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should set active filters correctly', async () => {
|
|
||||||
spyOn(queryBuilder, 'setCurrentRootFolderId');
|
spyOn(queryBuilder, 'setCurrentRootFolderId');
|
||||||
spyOn(queryBuilder, 'isCustomSourceNode').and.returnValue(false);
|
spyOn(queryBuilder, 'isCustomSourceNode').and.returnValue(false);
|
||||||
|
|
||||||
@@ -145,7 +117,8 @@ describe('FilterHeaderComponent', () => {
|
|||||||
await fixture.whenStable();
|
await fixture.whenStable();
|
||||||
expect(queryBuilder.getActiveFilters().length).toBe(0);
|
expect(queryBuilder.getActiveFilters().length).toBe(0);
|
||||||
|
|
||||||
component.value = { name: 'pinocchio' };
|
const initialFilterValue = { name: 'pinocchio' };
|
||||||
|
component.value = initialFilterValue;
|
||||||
const currentFolderNodeIdChange = new SimpleChange('current-node-id', 'next-node-id', true);
|
const currentFolderNodeIdChange = new SimpleChange('current-node-id', 'next-node-id', true);
|
||||||
component.ngOnChanges({ currentFolderId: currentFolderNodeIdChange });
|
component.ngOnChanges({ currentFolderId: currentFolderNodeIdChange });
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
@@ -156,25 +129,6 @@ describe('FilterHeaderComponent', () => {
|
|||||||
expect(queryBuilder.getActiveFilters()[0].value).toBe('pinocchio');
|
expect(queryBuilder.getActiveFilters()[0].value).toBe('pinocchio');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should update queryParams if initial value is provided', async () => {
|
|
||||||
spyOn(queryBuilder, 'setCurrentRootFolderId');
|
|
||||||
spyOn(queryBuilder, 'isCustomSourceNode').and.returnValue(false);
|
|
||||||
|
|
||||||
fixture.detectChanges();
|
|
||||||
await fixture.whenStable();
|
|
||||||
expect(Object.keys(queryBuilder.filterRawParams).length).toBe(0);
|
|
||||||
|
|
||||||
component.value = { name: 'pinocchio' };
|
|
||||||
const currentFolderNodeIdChange = new SimpleChange('current-node-id', 'next-node-id', true);
|
|
||||||
component.ngOnChanges({ currentFolderId: currentFolderNodeIdChange });
|
|
||||||
fixture.detectChanges();
|
|
||||||
await fixture.whenStable();
|
|
||||||
|
|
||||||
expect(Object.keys(queryBuilder.filterRawParams).length).toBe(1);
|
|
||||||
expect(queryBuilder.filterRawParams['name']).toBe('pinocchio');
|
|
||||||
expect(queryBuilder.queryFragments['name']).toBe('pinocchio');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should emit filterSelection when a filter is changed', (done) => {
|
it('should emit filterSelection when a filter is changed', (done) => {
|
||||||
spyOn(queryBuilder, 'getActiveFilters').and.returnValue([{ key: 'name', value: 'pinocchio' }]);
|
spyOn(queryBuilder, 'getActiveFilters').and.returnValue([{ key: 'name', value: 'pinocchio' }]);
|
||||||
|
|
||||||
|
|||||||
+4
-13
@@ -46,10 +46,7 @@ export class FilterHeaderComponent implements OnInit, OnChanges {
|
|||||||
|
|
||||||
private readonly destroyRef = inject(DestroyRef);
|
private readonly destroyRef = inject(DestroyRef);
|
||||||
|
|
||||||
constructor(
|
constructor(@Inject(ADF_DOCUMENT_PARENT_COMPONENT) private documentList: any, private searchFilterQueryBuilder: SearchHeaderQueryBuilderService) {
|
||||||
@Inject(ADF_DOCUMENT_PARENT_COMPONENT) private readonly documentList: any,
|
|
||||||
private readonly searchFilterQueryBuilder: SearchHeaderQueryBuilderService
|
|
||||||
) {
|
|
||||||
this.isFilterServiceActive = this.searchFilterQueryBuilder.isFilterServiceActive();
|
this.isFilterServiceActive = this.searchFilterQueryBuilder.isFilterServiceActive();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,17 +102,11 @@ export class FilterHeaderComponent implements OnInit, OnChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private initSearchHeader(currentFolderId: string) {
|
private initSearchHeader(currentFolderId: string) {
|
||||||
|
this.searchFilterQueryBuilder.setCurrentRootFolderId(currentFolderId);
|
||||||
if (this.value) {
|
if (this.value) {
|
||||||
Object.keys(this.value).forEach((key) => {
|
Object.keys(this.value).forEach((columnKey) => {
|
||||||
this.searchFilterQueryBuilder.setActiveFilter(key, this.value[key]);
|
this.searchFilterQueryBuilder.setActiveFilter(columnKey, this.value[columnKey]);
|
||||||
|
|
||||||
const operator = this.searchFilterQueryBuilder.getOperatorForFilterId(key) || 'OR';
|
|
||||||
this.searchFilterQueryBuilder.filterRawParams[key] = this.value[key];
|
|
||||||
this.searchFilterQueryBuilder.queryFragments[key] = Array.isArray(this.value[key])
|
|
||||||
? this.value[key].join(` ${operator} `)
|
|
||||||
: this.value[key];
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.searchFilterQueryBuilder.setCurrentRootFolderId(currentFolderId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-24
@@ -203,17 +203,18 @@ describe('SearchCheckListComponent', () => {
|
|||||||
expect(checkedElements.length).toBe(0);
|
expect(checkedElements.length).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should check the checkbox with startValue on init, if provided', () => {
|
it('should update query with startValue on init, if provided', () => {
|
||||||
component.id = 'checkList';
|
component.id = 'checkList';
|
||||||
component.options = new SearchFilterList<SearchListOption>([
|
component.options = new SearchFilterList<SearchListOption>([
|
||||||
{ name: 'Folder', value: `TYPE:'cm:folder'`, checked: false },
|
{ name: 'Folder', value: `TYPE:'cm:folder'`, checked: false },
|
||||||
{ name: 'Document', value: `TYPE:'cm:content'`, checked: false }
|
{ name: 'Document', value: `TYPE:'cm:content'`, checked: false }
|
||||||
]);
|
]);
|
||||||
component.startValue = [`TYPE:'cm:folder'`];
|
component.startValue = `TYPE:'cm:folder'`;
|
||||||
|
component.context.queryFragments[component.id] = 'query';
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(component.options.items[0].checked).toBeTrue();
|
|
||||||
expect(component.options.items[1].checked).toBeFalse();
|
expect(component.context.queryFragments[component.id]).toBe(`TYPE:'cm:folder'`);
|
||||||
expect(component.isActive).toBeTrue();
|
expect(component.context.update).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set query context as blank and not call query update, if no start value was provided', () => {
|
it('should set query context as blank and not call query update, if no start value was provided', () => {
|
||||||
@@ -230,25 +231,6 @@ describe('SearchCheckListComponent', () => {
|
|||||||
expect(component.context.update).not.toHaveBeenCalled();
|
expect(component.context.update).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle initial populateFilters emission and no filter state properly', () => {
|
|
||||||
component.id = 'checkList';
|
|
||||||
component.options = new SearchFilterList<SearchListOption>([
|
|
||||||
{ name: 'Folder', value: `TYPE:'cm:folder'`, checked: false },
|
|
||||||
{ name: 'Document', value: `TYPE:'cm:content'`, checked: false }
|
|
||||||
]);
|
|
||||||
|
|
||||||
component.context.filterLoaded = new ReplaySubject(1);
|
|
||||||
spyOn(component.context.filterLoaded, 'next').and.stub();
|
|
||||||
spyOn(component.displayValue$, 'next').and.stub();
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
component.context.populateFilters.next({});
|
|
||||||
component.context.populateFilters.next({ checkList: [`TYPE:'cm:content'`] });
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
expect(component.context.filterLoaded.next).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should populate filter state when populate filters event has been observed', () => {
|
it('should populate filter state when populate filters event has been observed', () => {
|
||||||
component.id = 'checkList';
|
component.id = 'checkList';
|
||||||
component.options = new SearchFilterList<SearchListOption>([
|
component.options = new SearchFilterList<SearchListOption>([
|
||||||
|
|||||||
+5
-5
@@ -23,7 +23,7 @@ import { SearchQueryBuilderService } from '../../services/search-query-builder.s
|
|||||||
import { SearchFilterList } from '../../models/search-filter-list.model';
|
import { SearchFilterList } from '../../models/search-filter-list.model';
|
||||||
import { TranslationService } from '@alfresco/adf-core';
|
import { TranslationService } from '@alfresco/adf-core';
|
||||||
import { ReplaySubject } from 'rxjs';
|
import { ReplaySubject } from 'rxjs';
|
||||||
import { filter, map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { TranslatePipe } from '@ngx-translate/core';
|
import { TranslatePipe } from '@ngx-translate/core';
|
||||||
import { MatButtonModule } from '@angular/material/button';
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
@@ -50,7 +50,7 @@ export class SearchCheckListComponent implements SearchWidget, OnInit {
|
|||||||
context?: SearchQueryBuilderService;
|
context?: SearchQueryBuilderService;
|
||||||
options: SearchFilterList<SearchListOption>;
|
options: SearchFilterList<SearchListOption>;
|
||||||
operator: string = 'OR';
|
operator: string = 'OR';
|
||||||
startValue: string | string[];
|
startValue: string;
|
||||||
pageSize = 5;
|
pageSize = 5;
|
||||||
isActive = false;
|
isActive = false;
|
||||||
enableChangeUpdate = true;
|
enableChangeUpdate = true;
|
||||||
@@ -81,9 +81,9 @@ export class SearchCheckListComponent implements SearchWidget, OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.context.populateFilters
|
this.context.populateFilters
|
||||||
|
.asObservable()
|
||||||
.pipe(
|
.pipe(
|
||||||
map((filtersQueries) => filtersQueries[this.id]),
|
map((filtersQueries) => filtersQueries[this.id]),
|
||||||
filter((filterQuery) => filterQuery !== undefined),
|
|
||||||
takeUntilDestroyed(this.destroyRef)
|
takeUntilDestroyed(this.destroyRef)
|
||||||
)
|
)
|
||||||
.subscribe((filterQuery) => {
|
.subscribe((filterQuery) => {
|
||||||
@@ -160,8 +160,8 @@ export class SearchCheckListComponent implements SearchWidget, OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setValue(value: any) {
|
setValue(value: any) {
|
||||||
this.options.items.forEach((item) => (item.checked = value.includes(item.value)));
|
this.options.items.filter((item) => value.includes(item.value)).map((item) => (item.checked = true));
|
||||||
this.isActive = true;
|
this.submitValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
private getCheckedValues() {
|
private getCheckedValues() {
|
||||||
|
|||||||
+3
-3
@@ -94,7 +94,7 @@ describe('SearchFilterContainerComponent', () => {
|
|||||||
await applyButton.click();
|
await applyButton.click();
|
||||||
|
|
||||||
expect(queryBuilder.getActiveFilters().length).toBe(1);
|
expect(queryBuilder.getActiveFilters().length).toBe(1);
|
||||||
expect(queryBuilder.getActiveFilters()[0].key).toBe('queryName');
|
expect(queryBuilder.getActiveFilters()[0].key).toBe('name');
|
||||||
expect(queryBuilder.getActiveFilters()[0].value).toBe('searchText');
|
expect(queryBuilder.getActiveFilters()[0].value).toBe('searchText');
|
||||||
|
|
||||||
await menu.open();
|
await menu.open();
|
||||||
@@ -103,12 +103,12 @@ describe('SearchFilterContainerComponent', () => {
|
|||||||
|
|
||||||
await applyButton.click();
|
await applyButton.click();
|
||||||
expect(queryBuilder.getActiveFilters().length).toBe(1);
|
expect(queryBuilder.getActiveFilters().length).toBe(1);
|
||||||
expect(queryBuilder.getActiveFilters()[0].key).toBe('queryName');
|
expect(queryBuilder.getActiveFilters()[0].key).toBe('name');
|
||||||
expect(queryBuilder.getActiveFilters()[0].value).toBe('updated text');
|
expect(queryBuilder.getActiveFilters()[0].value).toBe('updated text');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should remove active filter after the Clear button is clicked', async () => {
|
it('should remove active filter after the Clear button is clicked', async () => {
|
||||||
queryBuilder.setActiveFilter('queryName', 'searchText');
|
queryBuilder.setActiveFilter('name', 'searchText');
|
||||||
|
|
||||||
const menu = await loader.getHarness(MatMenuHarness);
|
const menu = await loader.getHarness(MatMenuHarness);
|
||||||
await menu.open();
|
await menu.open();
|
||||||
|
|||||||
+4
-4
@@ -76,7 +76,7 @@ export class SearchFilterContainerComponent implements OnInit {
|
|||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.category = this.searchFilterQueryBuilder.getCategoryForColumn(this.col.key);
|
this.category = this.searchFilterQueryBuilder.getCategoryForColumn(this.col.key);
|
||||||
this.initialValue = this.value?.[this.category?.id];
|
this.initialValue = this.value?.[this.col.key] ? this.value[this.col.key] : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
onKeyPressed(event: KeyboardEvent, menuTrigger: MatMenuTrigger) {
|
onKeyPressed(event: KeyboardEvent, menuTrigger: MatMenuTrigger) {
|
||||||
@@ -88,7 +88,7 @@ export class SearchFilterContainerComponent implements OnInit {
|
|||||||
|
|
||||||
onApply() {
|
onApply() {
|
||||||
if (this.widgetContainer.hasValueSelected()) {
|
if (this.widgetContainer.hasValueSelected()) {
|
||||||
this.searchFilterQueryBuilder.setActiveFilter(this.category.id, this.widgetContainer.getCurrentValue());
|
this.searchFilterQueryBuilder.setActiveFilter(this.category.columnKey, this.widgetContainer.getCurrentValue());
|
||||||
this.filterChange.emit();
|
this.filterChange.emit();
|
||||||
this.widgetContainer.applyInnerWidget();
|
this.widgetContainer.applyInnerWidget();
|
||||||
} else {
|
} else {
|
||||||
@@ -103,7 +103,7 @@ export class SearchFilterContainerComponent implements OnInit {
|
|||||||
|
|
||||||
resetSearchFilter() {
|
resetSearchFilter() {
|
||||||
this.widgetContainer.resetInnerWidget();
|
this.widgetContainer.resetInnerWidget();
|
||||||
this.searchFilterQueryBuilder.removeActiveFilter(this.category.id);
|
this.searchFilterQueryBuilder.removeActiveFilter(this.category.columnKey);
|
||||||
this.filterChange.emit();
|
this.filterChange.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ export class SearchFilterContainerComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isActive(): boolean {
|
isActive(): boolean {
|
||||||
return this.searchFilterQueryBuilder.getActiveFilters().findIndex((f: FilterSearch) => f.key === this.category.id) > -1;
|
return this.searchFilterQueryBuilder.getActiveFilters().findIndex((f: FilterSearch) => f.key === this.category.columnKey) > -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
onMenuOpen() {
|
onMenuOpen() {
|
||||||
|
|||||||
+1
-1
@@ -123,7 +123,7 @@ describe('SearchTextComponent', () => {
|
|||||||
|
|
||||||
expect(component.value).toBe('');
|
expect(component.value).toBe('');
|
||||||
expect(component.context.queryFragments[component.id]).toBe('');
|
expect(component.context.queryFragments[component.id]).toBe('');
|
||||||
expect(component.context.filterRawParams[component.id]).toBeUndefined();
|
expect(component.context.filterRawParams[component.id]).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should update query with startValue on init, if provided', () => {
|
it('should update query with startValue on init, if provided', () => {
|
||||||
|
|||||||
@@ -99,8 +99,6 @@ export class SearchTextComponent implements SearchWidget, OnInit {
|
|||||||
|
|
||||||
reset(updateContext = true) {
|
reset(updateContext = true) {
|
||||||
this.value = '';
|
this.value = '';
|
||||||
this.context.filterRawParams[this.id] = undefined;
|
|
||||||
this.context.queryFragments[this.id] = '';
|
|
||||||
this.updateQuery(null, updateContext);
|
this.updateQuery(null, updateContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,10 +111,7 @@ export class SearchTextComponent implements SearchWidget, OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private updateQuery(value: string, updateContext = true) {
|
private updateQuery(value: string, updateContext = true) {
|
||||||
if (value !== null) {
|
this.context.filterRawParams[this.id] = value;
|
||||||
this.context.filterRawParams[this.id] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.displayValue$.next(value);
|
this.displayValue$.next(value);
|
||||||
if (this.context && this.settings && this.settings.field) {
|
if (this.context && this.settings && this.settings.field) {
|
||||||
this.context.queryFragments[this.id] = value ? `${this.settings.field}:'${this.getSearchPrefix()}${value}${this.getSearchSuffix()}'` : '';
|
this.context.queryFragments[this.id] = value ? `${this.settings.field}:'${this.getSearchPrefix()}${value}${this.getSearchSuffix()}'` : '';
|
||||||
|
|||||||
+16
-45
@@ -22,7 +22,6 @@ import { TestBed } from '@angular/core/testing';
|
|||||||
import { ContentTestingModule } from '../../testing/content.testing.module';
|
import { ContentTestingModule } from '../../testing/content.testing.module';
|
||||||
import { AlfrescoApiService } from '../../services/alfresco-api.service';
|
import { AlfrescoApiService } from '../../services/alfresco-api.service';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import { SearchCategory } from '../models';
|
|
||||||
|
|
||||||
describe('SearchHeaderQueryBuilderService', () => {
|
describe('SearchHeaderQueryBuilderService', () => {
|
||||||
let activatedRoute: ActivatedRoute;
|
let activatedRoute: ActivatedRoute;
|
||||||
@@ -44,13 +43,10 @@ describe('SearchHeaderQueryBuilderService', () => {
|
|||||||
|
|
||||||
it('should load the configuration from app config', () => {
|
it('should load the configuration from app config', () => {
|
||||||
TestBed.runInInjectionContext(() => {
|
TestBed.runInInjectionContext(() => {
|
||||||
const config = {
|
const config: SearchConfiguration = {
|
||||||
categories: [
|
categories: [{ id: 'cat1', enabled: true } as any, { id: 'cat2', enabled: true } as any],
|
||||||
{ id: 'cat1', enabled: true },
|
|
||||||
{ id: 'cat2', enabled: true }
|
|
||||||
],
|
|
||||||
filterQueries: [{ query: 'query1' }, { query: 'query2' }]
|
filterQueries: [{ query: 'query1' }, { query: 'query2' }]
|
||||||
} as SearchConfiguration;
|
};
|
||||||
|
|
||||||
const alfrescoApiService = TestBed.inject(AlfrescoApiService);
|
const alfrescoApiService = TestBed.inject(AlfrescoApiService);
|
||||||
const builder = new SearchHeaderQueryBuilderService(buildConfig(config), alfrescoApiService, null);
|
const builder = new SearchHeaderQueryBuilderService(buildConfig(config), alfrescoApiService, null);
|
||||||
@@ -70,13 +66,13 @@ describe('SearchHeaderQueryBuilderService', () => {
|
|||||||
|
|
||||||
it('should return the category assigned to a column key', () => {
|
it('should return the category assigned to a column key', () => {
|
||||||
TestBed.runInInjectionContext(() => {
|
TestBed.runInInjectionContext(() => {
|
||||||
const config = {
|
const config: SearchConfiguration = {
|
||||||
categories: [
|
categories: [
|
||||||
{ id: 'cat1', columnKey: 'fake-key-1', enabled: true },
|
{ id: 'cat1', columnKey: 'fake-key-1', enabled: true } as any,
|
||||||
{ id: 'cat2', columnKey: 'fake-key-2', enabled: true }
|
{ id: 'cat2', columnKey: 'fake-key-2', enabled: true } as any
|
||||||
],
|
],
|
||||||
filterQueries: [{ query: 'query1' }, { query: 'query2' }]
|
filterQueries: [{ query: 'query1' }, { query: 'query2' }]
|
||||||
} as SearchConfiguration;
|
};
|
||||||
|
|
||||||
const alfrescoApiService = TestBed.inject(AlfrescoApiService);
|
const alfrescoApiService = TestBed.inject(AlfrescoApiService);
|
||||||
const service = new SearchHeaderQueryBuilderService(buildConfig(config), alfrescoApiService, null);
|
const service = new SearchHeaderQueryBuilderService(buildConfig(config), alfrescoApiService, null);
|
||||||
@@ -88,25 +84,6 @@ describe('SearchHeaderQueryBuilderService', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return operator for a category by id', () => {
|
|
||||||
TestBed.runInInjectionContext(() => {
|
|
||||||
const config: SearchConfiguration = {
|
|
||||||
categories: [
|
|
||||||
{ id: 'cat1', columnKey: 'fake-key-1', enabled: true, component: { settings: { operator: 'operator' } } },
|
|
||||||
{ id: 'cat2', columnKey: 'fake-key-2', enabled: true }
|
|
||||||
] as SearchCategory[]
|
|
||||||
};
|
|
||||||
|
|
||||||
const alfrescoApiService = TestBed.inject(AlfrescoApiService);
|
|
||||||
const service = new SearchHeaderQueryBuilderService(buildConfig(config), alfrescoApiService, null);
|
|
||||||
|
|
||||||
const operator = service.getOperatorForFilterId('cat1');
|
|
||||||
expect(operator).toBe('operator');
|
|
||||||
const operator1 = service.getOperatorForFilterId('cat2');
|
|
||||||
expect(operator1).toBeUndefined();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should have empty user query by default', () => {
|
it('should have empty user query by default', () => {
|
||||||
TestBed.runInInjectionContext(() => {
|
TestBed.runInInjectionContext(() => {
|
||||||
const alfrescoApiService = TestBed.inject(AlfrescoApiService);
|
const alfrescoApiService = TestBed.inject(AlfrescoApiService);
|
||||||
@@ -117,13 +94,10 @@ describe('SearchHeaderQueryBuilderService', () => {
|
|||||||
|
|
||||||
it('should add the extra filter for the parent node', () => {
|
it('should add the extra filter for the parent node', () => {
|
||||||
TestBed.runInInjectionContext(() => {
|
TestBed.runInInjectionContext(() => {
|
||||||
const config = {
|
const config: SearchConfiguration = {
|
||||||
categories: [
|
categories: [{ id: 'cat1', enabled: true } as any, { id: 'cat2', enabled: true } as any],
|
||||||
{ id: 'cat1', enabled: true },
|
|
||||||
{ id: 'cat2', enabled: true }
|
|
||||||
],
|
|
||||||
filterQueries: [{ query: 'query1' }, { query: 'query2' }]
|
filterQueries: [{ query: 'query1' }, { query: 'query2' }]
|
||||||
} as SearchConfiguration;
|
};
|
||||||
|
|
||||||
const expectedResult = [{ query: 'PARENT:"workspace://SpacesStore/fake-node-id"' }];
|
const expectedResult = [{ query: 'PARENT:"workspace://SpacesStore/fake-node-id"' }];
|
||||||
|
|
||||||
@@ -140,13 +114,10 @@ describe('SearchHeaderQueryBuilderService', () => {
|
|||||||
TestBed.runInInjectionContext(() => {
|
TestBed.runInInjectionContext(() => {
|
||||||
const expectedResult = [{ query: 'PARENT:"workspace://SpacesStore/fake-node-id"' }];
|
const expectedResult = [{ query: 'PARENT:"workspace://SpacesStore/fake-node-id"' }];
|
||||||
|
|
||||||
const config = {
|
const config: SearchConfiguration = {
|
||||||
categories: [
|
categories: [{ id: 'cat1', enabled: true } as any, { id: 'cat2', enabled: true } as any],
|
||||||
{ id: 'cat1', enabled: true },
|
|
||||||
{ id: 'cat2', enabled: true }
|
|
||||||
],
|
|
||||||
filterQueries: expectedResult
|
filterQueries: expectedResult
|
||||||
} as SearchConfiguration;
|
};
|
||||||
|
|
||||||
const alfrescoApiService = TestBed.inject(AlfrescoApiService);
|
const alfrescoApiService = TestBed.inject(AlfrescoApiService);
|
||||||
const searchHeaderService = new SearchHeaderQueryBuilderService(buildConfig(config), alfrescoApiService, null);
|
const searchHeaderService = new SearchHeaderQueryBuilderService(buildConfig(config), alfrescoApiService, null);
|
||||||
@@ -161,10 +132,10 @@ describe('SearchHeaderQueryBuilderService', () => {
|
|||||||
TestBed.runInInjectionContext(() => {
|
TestBed.runInInjectionContext(() => {
|
||||||
const activeFilter = 'FakeColumn';
|
const activeFilter = 'FakeColumn';
|
||||||
|
|
||||||
const config = {
|
const config: SearchConfiguration = {
|
||||||
categories: [{ id: 'cat1', enabled: true }],
|
categories: [{ id: 'cat1', enabled: true } as any],
|
||||||
filterQueries: [{ query: 'PARENT:"workspace://SpacesStore/fake-node-id' }]
|
filterQueries: [{ query: 'PARENT:"workspace://SpacesStore/fake-node-id' }]
|
||||||
} as SearchConfiguration;
|
};
|
||||||
|
|
||||||
const alfrescoApiService = TestBed.inject(AlfrescoApiService);
|
const alfrescoApiService = TestBed.inject(AlfrescoApiService);
|
||||||
const searchHeaderService = new SearchHeaderQueryBuilderService(buildConfig(config), alfrescoApiService, null);
|
const searchHeaderService = new SearchHeaderQueryBuilderService(buildConfig(config), alfrescoApiService, null);
|
||||||
|
|||||||
+1
-11
@@ -36,11 +36,7 @@ export class SearchHeaderQueryBuilderService extends BaseQueryBuilderService {
|
|||||||
|
|
||||||
activeFilters: FilterSearch[] = [];
|
activeFilters: FilterSearch[] = [];
|
||||||
|
|
||||||
constructor(
|
constructor(appConfig: AppConfigService, alfrescoApiService: AlfrescoApiService, private nodeApiService: NodesApiService) {
|
||||||
appConfig: AppConfigService,
|
|
||||||
alfrescoApiService: AlfrescoApiService,
|
|
||||||
private readonly nodeApiService: NodesApiService
|
|
||||||
) {
|
|
||||||
super(appConfig, alfrescoApiService);
|
super(appConfig, alfrescoApiService);
|
||||||
|
|
||||||
this.updated.pipe(filter((query) => !!query)).subscribe(() => {
|
this.updated.pipe(filter((query) => !!query)).subscribe(() => {
|
||||||
@@ -131,12 +127,6 @@ export class SearchHeaderQueryBuilderService extends BaseQueryBuilderService {
|
|||||||
return foundCategory;
|
return foundCategory;
|
||||||
}
|
}
|
||||||
|
|
||||||
getOperatorForFilterId(id: string): string | undefined {
|
|
||||||
const foundCategory = this.categories?.find((category) => category.id === id);
|
|
||||||
|
|
||||||
return foundCategory?.component?.settings?.operator;
|
|
||||||
}
|
|
||||||
|
|
||||||
setCurrentRootFolderId(currentFolderId: string) {
|
setCurrentRootFolderId(currentFolderId: string) {
|
||||||
const alreadyAddedFilter = this.filterQueries.find((filterQueries) => filterQueries.query.includes(currentFolderId));
|
const alreadyAddedFilter = this.filterQueries.find((filterQueries) => filterQueries.query.includes(currentFolderId));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user