Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ describe('Filter URL service', () => {
providers: [
mockProvider(NavigationService, {
navigation$: EMPTY,
addQueryParametersToUrl: (paramObject: QueryParamObject) => (testQueryParamObject = paramObject),
addQueryParametersToUrl: (paramObject: QueryParamObject) =>
(testQueryParamObject = { ...testQueryParamObject, ...paramObject }),
getAllValuesForQueryParameter: (param: string) => testQueryParamObject[param] ?? []
})
]
Expand Down Expand Up @@ -361,4 +362,23 @@ describe('Filter URL service', () => {
filter: ['numberAttribute_neq_217', 'stringAttribute_eq_test', 'stringMapAttribute.myKey_eq_myValue']
});
});

test('correctly gets filters and group by from url', () => {
testQueryParamObject = {
...expectedQueryParamObject,
['group-by']: ['field1,field2']
};
expect(spectator.service.getUrlFilters(attributes)).toEqual(filters);
expect(spectator.service.getUrlGroupBy()).toEqual(['field1', 'field2']);
});

test('correctly sets filters and group by in url', () => {
spectator.service.setUrlGroupBy(['field1', 'field2']);
spectator.service.setUrlFilters(filters);

expect(testQueryParamObject).toEqual({
...expectedQueryParamObject,
['group-by']: ['field1,field2']
});
});
});
16 changes: 15 additions & 1 deletion projects/components/src/filtering/filter/filter-url.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { NavigationService } from '@hypertrace/common';
import { remove } from 'lodash-es';
import { isEmpty, remove } from 'lodash-es';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { FilterBuilderLookupService } from './builder/filter-builder-lookup.service';
Expand All @@ -15,6 +15,7 @@ import { splitFilterStringByOperator } from './parser/parsed-filter';
})
export class FilterUrlService {
private static readonly FILTER_QUERY_PARAM: string = 'filter';
private static readonly GROUP_BY_QUERY_PARAM: string = 'group-by';

public constructor(
private readonly navigationService: NavigationService,
Expand Down Expand Up @@ -54,6 +55,19 @@ export class FilterUrlService {
});
}

public setUrlGroupBy(groupBy?: string[]): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Group by isn't a filter - feels like a curious spot for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to change the name of this service. This should be more like filterBarUrlService. I have a follow up with related change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing explorer and "advanced filter" is dependant on this service, so I am trying to make bite size changes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But explorer manages its own group by, while its filters are managed by a filter bar component which uses this, I believe. So it seems like we're setting up multiple ways of doing it? Should we put explorers group by into here then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

going to merge this now unless you have an objection.

this.navigationService.addQueryParametersToUrl({
[FilterUrlService.GROUP_BY_QUERY_PARAM]: isEmpty(groupBy) ? undefined : [groupBy!.toString()]
});
}

public getUrlGroupBy(): string[] {
return this.navigationService
.getAllValuesForQueryParameter(FilterUrlService.GROUP_BY_QUERY_PARAM)
.map(groupByString => groupByString.split(',').map(attributeName => attributeName.trim()))
.flat();
}

public addUrlFilter(attributes: FilterAttribute[], filter: Filter): void {
const remainingFilters = this.getUrlFilters(attributes).filter(f => areCompatibleFilters(f, filter));

Expand Down