Skip to content

Commit

Permalink
Merge pull request #365 from TAMULib/august-sprint-363
Browse files Browse the repository at this point in the history
[Issue 363]: Prevent false positive filters query param check
  • Loading branch information
wwelling authored Aug 10, 2024
2 parents 7ce555e + b38ed28 commit 1c40c7e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/app/+directory/directory.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { DirectoryView, DiscoveryView, Filter } from '../core/model/view';
import { AppState } from '../core/store';
import { selectRouterQueryParamFilters, selectRouterQueryParams } from '../core/store/router';
import { selectAllResources, selectDiscoveryViewByClass, selectResourceById, selectResourceIsLoading, selectResourcesFacets, selectResourcesPage } from '../core/store/sdr';
import { hasFilter } from '../shared/utilities/discovery.utility';
import { addExportToQueryParams, getFilterField, getFilterValue, hasExport, removeFilterFromQueryParams, resetFiltersInQueryParams, showClearFilters, showFilter } from '../shared/utilities/view.utility';

@Component({
Expand Down Expand Up @@ -82,7 +83,7 @@ export class DirectoryComponent implements OnDestroy, OnInit {

public isActive(directoryView: DirectoryView, params: Params, option: string): boolean {
const queryParams: Params = Object.assign({}, params);
if (queryParams.filters && queryParams.filters.indexOf(directoryView.index.field) >= 0) {
if (hasFilter(queryParams.filters, directoryView.index.field)) {
return queryParams[`${directoryView.index.field}.filter`] === option;
}
return option === 'All';
Expand Down Expand Up @@ -130,7 +131,7 @@ export class DirectoryComponent implements OnDestroy, OnInit {

public getDirectoryQueryParamsResetting(params: Params, directoryView: DirectoryView): Params {
const queryParams: Params = Object.assign({}, params);
if (queryParams.filters && queryParams.filters.indexOf(directoryView.index.field) >= 0) {
if (hasFilter(queryParams.filters, directoryView.index.field)) {
const filters = queryParams.filters.split(',')
.map((field) => field.trim())
.filter((field) => field !== directoryView.index.field);
Expand Down
6 changes: 3 additions & 3 deletions src/app/core/store/sdr/sdr.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Observable, asapScheduler, combineLatest, defer, of, scheduled } from '
import { catchError, filter, map, mergeMap, skip, skipWhile, switchMap, take, withLatestFrom } from 'rxjs/operators';

import { AppState } from '../';
import { FILTER_VALUE_DELIMITER, buildDateYearFilterValue, buildNumberRangeFilterValue, createSdrRequest, getFacetFilterLabel } from '../../../shared/utilities/discovery.utility';
import { FILTER_VALUE_DELIMITER, buildDateYearFilterValue, buildNumberRangeFilterValue, createSdrRequest, getFacetFilterLabel, hasFilter } from '../../../shared/utilities/discovery.utility';
import { removeFilterFromQueryParams } from '../../../shared/utilities/view.utility';
import { Individual } from '../../model/discovery';
import { injectable, repos } from '../../model/repos';
Expand Down Expand Up @@ -820,7 +820,7 @@ export class SdrEffects {

if (selected) {
sidebarSection.collapsed = false;
if (sidebarItem.queryParams.filters && sidebarItem.queryParams.filters.indexOf(sdrFacet.field) >= 0) {
if (hasFilter(sidebarItem.queryParams.filters, sdrFacet.field)) {
const queryParams: Params = Object.assign({}, sidebarItem.queryParams);
removeFilterFromQueryParams(queryParams, {
field: sdrFacet.field,
Expand All @@ -833,7 +833,7 @@ export class SdrEffects {
selectedFilterValues.push(filterValue);
} else {
if (sidebarItem.queryParams.filters) {
if (sidebarItem.queryParams.filters.indexOf(sdrFacet.field) < 0) {
if (!hasFilter(sidebarItem.queryParams.filters, sdrFacet.field)) {
sidebarItem.queryParams.filters += `,${sdrFacet.field}`;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { AppState } from '../../../core/store';
import { selectRouterQueryParams, selectRouterState } from '../../../core/store/router';
import { CustomRouterState } from '../../../core/store/router/router.reducer';
import { selectCollectionViewByName } from '../../../core/store/sdr';
import { FILTER_VALUE_DELIMITER, buildDateYearFilterValue, buildNumberRangeFilterValue, createSdrRequest, getFacetFilterLabel } from '../../utilities/discovery.utility';
import { FILTER_VALUE_DELIMITER, buildDateYearFilterValue, buildNumberRangeFilterValue, createSdrRequest, getFacetFilterLabel, hasFilter } from '../../utilities/discovery.utility';

import * as fromDialog from '../../../core/store/dialog/dialog.actions';

Expand Down Expand Up @@ -267,7 +267,7 @@ export class FacetEntriesComponent implements OnDestroy, OnInit {
}
queryParams[`${this.field}.pageNumber`] = 1;
if (queryParams.filters && queryParams.filters.length > 0) {
if (queryParams.filters.indexOf(this.field) < 0) {
if (!hasFilter(queryParams.filters, this.field)) {
queryParams.filters += `,${facet.field}`;
}
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/app/shared/utilities/discovery.utility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { CustomRouterState } from '../../core/store/router/router.reducer';

export const FILTER_VALUE_DELIMITER = ';;';

export const hasFilter = (filters: string, filter: string): boolean => filters?.trim().split(',').find(f => f === filter) !== undefined;

export const buildDateYearFilterValue = (facetEntry: SdrFacetEntry): string => {
const date = new Date(facetEntry.value);
const year = date.getUTCFullYear();
Expand Down

0 comments on commit 1c40c7e

Please sign in to comment.