Skip to content

Commit 52e81f0

Browse files
authored
Merge pull request #5098 from anynines/feature/modify_search_filter_to_cover_tags_too
Merging into Develop
2 parents 93a0c25 + ece8e98 commit 52e81f0

File tree

5 files changed

+95
-6
lines changed

5 files changed

+95
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ website/versions-repo
143143

144144
# Npm package builds
145145
/npm_pkg
146+
.npmrc
146147

147148
/scan_tmp
148149

src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-services/cf-services-data-source.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Store } from '@ngrx/store';
22
import { getRowMetadata } from '@stratosui/store';
3+
import { getDataFunctionList } from '../../../../../../../core/src/shared/components/list/data-sources-controllers/local-filtering-sorting';
34

45
import { CFAppState } from '../../../../../../../cloud-foundry/src/cf-app-state';
56
import { serviceEntityType } from '../../../../../../../cloud-foundry/src/cf-entity-types';
@@ -29,9 +30,22 @@ export class CfServicesDataSource extends ListDataSource<APIResource> {
2930
paginationKey,
3031
isLocal: true,
3132
transformEntities: [
32-
{
33-
type: 'filter',
34-
field: 'entity.label'
33+
(entities: APIResource[], paginationState: PaginationEntityState) => {
34+
const [filterByLabel, filterByTags] = getDataFunctionList(
35+
[{
36+
type: 'filter',
37+
field: 'entity.label'
38+
},
39+
{
40+
type: 'filter',
41+
field: 'entity.tags'
42+
}]
43+
)
44+
45+
const labels = filterByLabel(entities, paginationState)
46+
const tags = filterByTags(entities, paginationState)
47+
48+
return [...labels, ...tags]
3549
},
3650
(entities: APIResource[], paginationState: PaginationEntityState) => {
3751
const cfGuid = paginationState.clientPagination.filter.items.cf;

src/frontend/packages/cloud-foundry/src/shared/components/list/list-types/cf-services/cf-services-list-config.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class CfServicesListConfigService implements IListConfig<APIResource> {
7777
multiFilterConfigs: IListMultiFilterConfig[] = [];
7878
text: ITableText = {
7979
title: null,
80-
filter: 'Search by name',
80+
filter: 'Search by name and tags',
8181
noEntries: 'There are no services',
8282
maxedResults: {
8383
icon: 'store',

src/frontend/packages/core/src/shared/components/list/data-sources-controllers/local-filtering-sorting.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function getFieldArray(def: DataFunctionDefinition) {
2121
return def.field.split('.');
2222
}
2323

24-
function getFilterFunction(def: DataFunctionDefinition): DataFunction<any> {
24+
export function getFilterFunction(def: DataFunctionDefinition): DataFunction<any> {
2525
const fieldArray = getFieldArray(def);
2626
return (entities, paginationState) => {
2727
const upperCaseFilter = paginationState.clientPagination.filter.string.toUpperCase();
@@ -30,10 +30,14 @@ function getFilterFunction(def: DataFunctionDefinition): DataFunction<any> {
3030
}
3131
return entities.filter(e => {
3232
e = extractActualListEntity(e);
33-
const value = getValue(e, fieldArray, 0, true);
33+
let value = getValue(e, fieldArray, 0, true);
3434
if (!value) {
3535
return false;
3636
}
37+
if (Array.isArray(value)) {
38+
value = value.join(",")
39+
}
40+
3741
return value.toUpperCase().includes(upperCaseFilter);
3842
});
3943
};

src/frontend/packages/core/src/shared/components/list/list.component.spec.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ComponentFixture, inject, TestBed, waitForAsync } from '@angular/core/t
33
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
44
import { Store } from '@ngrx/store';
55
import { createBasicStoreModule } from '@stratosui/store/testing';
6+
import { PaginationEntityState } from 'frontend/packages/store/src/types/pagination.types';
67
import { BehaviorSubject, of as observableOf } from 'rxjs';
78
import { switchMap } from 'rxjs/operators';
89

@@ -16,6 +17,7 @@ import { CoreTestingModule } from '../../../../test-framework/core-test.modules'
1617
import { CoreModule } from '../../../core/core.module';
1718
import { CurrentUserPermissionsService } from '../../../core/permissions/current-user-permissions.service';
1819
import { SharedModule } from '../../shared.module';
20+
import { getFilterFunction } from './data-sources-controllers/local-filtering-sorting';
1921
import { EndpointCardComponent } from './list-types/endpoint/endpoint-card/endpoint-card.component';
2022
import { EndpointListHelper } from './list-types/endpoint/endpoint-list.helpers';
2123
import { EndpointsListConfigService } from './list-types/endpoint/endpoints-list-config.service';
@@ -320,6 +322,74 @@ describe('ListComponent', () => {
320322
expect(noEntriesMessage.hidden).toBeFalsy();
321323
});
322324

325+
describe('getFilterFunction filters entities ', () => {
326+
const paginationState: PaginationEntityState = {
327+
currentPage: 1,
328+
totalResults: 2,
329+
pageCount: 1,
330+
ids: {},
331+
params: {},
332+
pageRequests: {},
333+
clientPagination: {
334+
pageSize: 10,
335+
currentPage: 1,
336+
filter: {
337+
string: 'hello', // Filtering for 'hello'
338+
items: {}
339+
},
340+
totalResults: 2
341+
},
342+
maxedState: {},
343+
isListPagination: false
344+
};
345+
346+
it ('by label', () => {
347+
const filterbyLabel = getFilterFunction({
348+
type: 'filter',
349+
field: 'entity.label'
350+
},)
351+
352+
const entities: APIResource[] = [
353+
{
354+
metadata: { created_at: '2025-02-02', guid: '1', updated_at: '2025-02-03', url: '/url1' },
355+
entity: {label: 'hello'}
356+
},
357+
{
358+
metadata: { created_at: '2022-01-02', guid: '2', updated_at: '2022-01-03', url: '/url2' },
359+
entity: {label: 'world' }
360+
},
361+
]
362+
363+
const result = filterbyLabel(entities, paginationState)
364+
365+
expect(result.length).toBe(1);
366+
expect(result[0].entity.label).toEqual('hello');
367+
})
368+
369+
it ('by tags', () => {
370+
const filterbyTags = getFilterFunction({
371+
type: 'filter',
372+
field: 'entity.tags'
373+
})
374+
375+
const entities: APIResource[] = [
376+
{
377+
metadata: { created_at: '2025-02-02', guid: '1', updated_at: '2025-02-03', url: '/url1' },
378+
entity: { tags: ['hello', 'world'] }
379+
},
380+
{
381+
metadata: { created_at: '2022-01-02', guid: '2', updated_at: '2022-01-03', url: '/url2' },
382+
entity: { tags: ['bye', 'world'] }
383+
},
384+
]
385+
386+
const result = filterbyTags(entities, paginationState)
387+
388+
expect(result.length).toBe(1);
389+
expect(result[0].entity.tags).toEqual(['hello', 'world']);
390+
})
391+
})
392+
323393
});
324394

325395
});

0 commit comments

Comments
 (0)