Skip to content

Commit

Permalink
refactor(fields): clarify curently used types for date range
Browse files Browse the repository at this point in the history
todo: methods should only accept DateRange or string, not both
  • Loading branch information
tkohr committed Oct 29, 2024
1 parent 6cb464b commit ad65635
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
6 changes: 1 addition & 5 deletions libs/feature/router/src/lib/default/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,4 @@ export enum ROUTE_PARAMS {
PUBLISHER = 'publisher', // FIXME: this shouldn't be here as it is a search field
PAGE = '_page',
}
export type TimestampRange = { start?: number; end?: number }
export type SearchRouteParams = Record<
string,
string | string[] | number | TimestampRange
>
export type SearchRouteParams = Record<string, string | string[] | number>
11 changes: 4 additions & 7 deletions libs/feature/search/src/lib/utils/service/fields.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
OrganizationSearchField,
OwnerSearchField,
SimpleSearchField,
TimestampRange,
TranslatedSearchField,
UserSearchField,
} from './fields'
Expand Down Expand Up @@ -107,7 +106,7 @@ export class FieldsService {

private getFiltersForValues(
fieldName: string,
values: FieldValue[] | DateRange
values: FieldValue[] | DateRange | string
) {
return this.fields[fieldName].getFiltersForValues(values)
}
Expand All @@ -120,7 +119,7 @@ export class FieldsService {
}

buildFiltersFromFieldValues(
fieldValues: FieldValues | DateRange
fieldValues: FieldValues | DateRange | string
): Observable<FieldFilters> {
const fieldNames = Object.keys(fieldValues).filter((fieldName) =>
this.supportedFields.includes(fieldName)
Expand All @@ -134,7 +133,7 @@ export class FieldsService {
: [fieldValues[fieldName]] //TODO: handle stringified ranges which are not an object properly
return this.getFiltersForValues(
fieldName,
values as FieldValue[] | DateRange
values as FieldValue[] | DateRange | string
)
})
return forkJoin(filtersByField$).pipe(
Expand All @@ -144,9 +143,7 @@ export class FieldsService {
)
}

readFieldValuesFromFilters(
filters: FieldFilters
): Observable<FieldValues | TimestampRange> {
readFieldValuesFromFilters(filters: FieldFilters): Observable<FieldValues> {
const fieldValues$ = this.supportedFields.map((fieldName) =>
this.getValuesForFilters(fieldName, filters).pipe(
map((values) => ({ [fieldName]: values }))
Expand Down
6 changes: 4 additions & 2 deletions libs/feature/search/src/lib/utils/service/fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface FieldAvailableValue {
export abstract class AbstractSearchField {
abstract getAvailableValues(): Observable<FieldAvailableValue[] | DateRange[]>
abstract getFiltersForValues(
values: FieldValue[] | DateRange
values: FieldValue[] | DateRange | string
): Observable<FieldFilters>
abstract getValuesForFilter(
filters: FieldFilters
Expand Down Expand Up @@ -83,7 +83,9 @@ export class SimpleSearchField implements AbstractSearchField {
})
)
}
getFiltersForValues(values: FieldValue[] /*| DateRange*/): Observable<any> {
getFiltersForValues(
values: FieldValue[] | DateRange | string
): Observable<any> {
// FieldValue[]
if (Array.isArray(values) && this.getType() === 'values') {
return of({
Expand Down

0 comments on commit ad65635

Please sign in to comment.