Skip to content

Commit

Permalink
feat: remove use my record, use filter instead
Browse files Browse the repository at this point in the history
  • Loading branch information
f-necas committed Oct 3, 2023
1 parent f3c2c8b commit 609628b
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ <h2 class="text-xl mr-4 font-title" translate>
[title]="'search.filters.myRecordsHelp' | translate"
[label]="'search.filters.myRecords' | translate"
[color]="'secondary'"
[value]="searchFacade.myRecordsFilterEnabled$ | async"
[value]="myRecordsFilterEnabled() | async"
(toggled)="toggleMyRecordsFilter($event)"
></gn-ui-check-toggle>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
SearchService,
} from '@geonetwork-ui/feature/search'
import { getOptionalSearchConfig } from '@geonetwork-ui/util/app-config'
import { switchMap } from 'rxjs'
import { map } from 'rxjs/operators'

@Component({
selector: 'datahub-search-filters',
Expand All @@ -26,6 +28,7 @@ export class SearchFiltersComponent implements OnInit {
filters: QueryList<FilterDropdownComponent>
searchConfig: { fieldName: string; title: string }[]
isOpen = false
private userId: string

constructor(
public searchFacade: SearchFacade,
Expand All @@ -35,6 +38,7 @@ export class SearchFiltersComponent implements OnInit {
) {}

ngOnInit(): void {
this.authService.user$.subscribe((user) => (this.userId = user.id))
this.searchConfig = (
getOptionalSearchConfig().ADVANCED_FILTERS || [
'publisher',
Expand Down Expand Up @@ -116,17 +120,18 @@ export class SearchFiltersComponent implements OnInit {
}

toggleMyRecordsFilter(enabled: boolean) {
this.searchFacade.setMyRecordsFilterEnabled(enabled)
this.searchFacade.myRecordsFilterEnabled$.subscribe((isToggled) => {
if (isToggled) {
this.authService.user$.subscribe((user) =>
this.searchFacade.updateFilters({ owner: user.id })
)
} else {
this.searchFacade.resetSearch()
this.searchFacade.updateFilters({})
}
})
this.fieldsService
.buildFiltersFromFieldValues({ owner: enabled ? this.userId : [] })
.subscribe((filters) => this.searchService.updateFilters(filters))
}

myRecordsFilterEnabled() {
return this.searchFacade.searchFilters$.pipe(
switchMap((filters) => {
return this.fieldsService.readFieldValuesFromFilters(filters)
}),
map((fieldValues) => !!fieldValues['owner'])
)
}

clearFilters() {
Expand Down
13 changes: 1 addition & 12 deletions libs/feature/search/src/lib/state/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ export const PATCH_RESULTS_AGGREGATIONS = '[Search] Patch Results Aggregations'
export const SET_ERROR = '[Search] Set Error'
export const CLEAR_ERROR = '[Search] Clear Error'
export const SET_SPATIAL_FILTER_ENABLED = '[Search] Set Spatial Filter Enabled'
export const SET_MY_RECORDS_FILTER_ENABLED =
'[Search] Set My Records Filter Enabled'

export const DEFAULT_SEARCH_KEY = 'default'

Expand Down Expand Up @@ -247,15 +245,7 @@ export class SetSpatialFilterEnabled extends AbstractAction implements Action {
super(id)
}
}
export class SetMyRecordsFilterEnabled
extends AbstractAction
implements Action
{
readonly type = SET_MY_RECORDS_FILTER_ENABLED
constructor(public enabled: boolean, id?: string) {
super(id)
}
}

export type SearchActions =
| AddSearch
| SetConfigFilters
Expand All @@ -282,4 +272,3 @@ export type SearchActions =
| SetError
| ClearError
| SetSpatialFilterEnabled
| SetMyRecordsFilterEnabled
5 changes: 1 addition & 4 deletions libs/feature/search/src/lib/state/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
SET_FAVORITES_ONLY,
SET_FILTERS,
SET_INCLUDE_ON_AGGREGATION,
SET_MY_RECORDS_FILTER_ENABLED,
SET_PAGE_SIZE,
SET_SEARCH,
SET_SORT_BY,
Expand Down Expand Up @@ -73,8 +72,7 @@ export class SearchEffects {
UPDATE_FILTERS,
SET_SEARCH,
SET_FAVORITES_ONLY,
SET_SPATIAL_FILTER_ENABLED,
SET_MY_RECORDS_FILTER_ENABLED
SET_SPATIAL_FILTER_ENABLED
),
map((action: SearchActions) => new Paginate(1, action.id))
)
Expand All @@ -88,7 +86,6 @@ export class SearchEffects {
SET_SEARCH,
SET_FAVORITES_ONLY,
SET_SPATIAL_FILTER_ENABLED,
SET_MY_RECORDS_FILTER_ENABLED,
PAGINATE,
SET_PAGE_SIZE
)
Expand Down
11 changes: 0 additions & 11 deletions libs/feature/search/src/lib/state/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export type SearchStateParams = {
fields?: FieldName[]
favoritesOnly?: boolean
useSpatialFilter?: boolean
useMyRecordsFilter?: boolean
}

export type SearchError = {
Expand Down Expand Up @@ -335,16 +334,6 @@ export function reducerSearch(
},
}
}

case fromActions.SET_MY_RECORDS_FILTER_ENABLED: {
return {
...state,
params: {
...state.params,
useMyRecordsFilter: action.enabled,
},
}
}
}

return state
Expand Down
13 changes: 1 addition & 12 deletions libs/feature/search/src/lib/state/search.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
SetFavoritesOnly,
SetFilters,
SetIncludeOnAggregation,
SetMyRecordsFilterEnabled,
SetPageSize,
SetResultsLayout,
SetSearch,
Expand All @@ -28,6 +27,7 @@ import {
currentPage,
getError,
getFavoritesOnly,
getPageSize,
getSearchConfigAggregations,
getSearchFilters,
getSearchResults,
Expand All @@ -36,11 +36,9 @@ import {
getSearchResultsLayout,
getSearchResultsLoading,
getSearchSortBy,
getPageSize,
getSpatialFilterEnabled,
isEndOfResults,
totalPages,
getMyRecordsFilterEnabled,
} from './selectors'
import { FILTER_GEOMETRY } from '../feature-search.module'
import { Geometry } from 'geojson'
Expand Down Expand Up @@ -76,7 +74,6 @@ export class SearchFacade {
catchError(() => of(false)),
shareReplay(1)
)
myRecordsFilterEnabled$: Observable<boolean>

searchId: string

Expand Down Expand Up @@ -117,9 +114,6 @@ export class SearchFacade {
this.spatialFilterEnabled$ = this.store.pipe(
select(getSpatialFilterEnabled, searchId)
)
this.myRecordsFilterEnabled$ = this.store.pipe(
select(getMyRecordsFilterEnabled, searchId)
)
}

clearResults(): SearchFacade {
Expand Down Expand Up @@ -216,11 +210,6 @@ export class SearchFacade {
return this
}

setMyRecordsFilterEnabled(enabled: boolean) {
this.store.dispatch(new SetMyRecordsFilterEnabled(enabled, this.searchId))
return this
}

resetSearch() {
this.store.dispatch(new Paginate(1, this.searchId))
this.store.dispatch(new SetFilters({}, this.searchId))
Expand Down
5 changes: 0 additions & 5 deletions libs/feature/search/src/lib/state/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,3 @@ export const getSpatialFilterEnabled = createSelector(
getSearchStateSearch,
(state: SearchStateSearch) => state.params.useSpatialFilter
)

export const getMyRecordsFilterEnabled = createSelector(
getSearchStateSearch,
(state: SearchStateSearch) => !!state.params.filters?.owner
)

0 comments on commit 609628b

Please sign in to comment.