Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter by PID enabling different matching conditions #1061

Merged
merged 5 commits into from
May 17, 2023
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
5 changes: 2 additions & 3 deletions CI/PSI/config.development.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,5 @@
"scienceSearchUnitsEnabled": false,
"metadataStructure": "",
"loginFormEnabled": true,
"oAuth2Endpoints": [],
"prefix": "20.500.11935"
}
"oAuth2Endpoints": []
}
1 change: 0 additions & 1 deletion src/app/app-config.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { of } from "rxjs";
import { MockHttp } from "shared/MockStubs";

const appConfig: AppConfig = {
prefix: "20.500.11935",
accessTokenPrefix: "",
addDatasetEnabled: true,
archiveWorkflowEnabled: true,
Expand Down
4 changes: 2 additions & 2 deletions src/app/app-config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ export interface AppConfig {
fileserverButtonLabel: string | undefined;
datasetDetailsShowMissingProposalId: boolean;
helpMessages?: HelpMessages;
prefix: string | undefined;
notificationInterceptorEnabled: boolean;
pidSearchMethod?: string;
}

@Injectable()
export class AppConfigService {
private appConfig: Object = {};

constructor(private http: HttpClient) {}
constructor(private http: HttpClient) { }

async loadAppConfig(): Promise<void> {
try {
Expand Down
1 change: 0 additions & 1 deletion src/app/datasets/dashboard/dashboard.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<mat-sidenav-content>
<div fxLayout="row" fxLayout.xs="column">
<div class="action-column" fxFlex="14" fxFlex.lt-xl="20">
<dataset-pid-selection></dataset-pid-selection>
<datasets-filter></datasets-filter>
<ng-template [ngIf]="this.loggedIn$ | async">
<mat-card
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

11 changes: 11 additions & 0 deletions src/app/datasets/datasets-filter/datasets-filter.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
<div style="clear: both;"></div>
</div>


<app-search-bar
#pidBar
[prefilledValue]="pidTerms$ | async"
[placeholder]="'PID'"
[clear]="clearSearchBar"
(search)="pidSearchChanged($event)"
(searchBarFocus)="pidSearchChanged($event)"
>
</app-search-bar>

<app-search-bar
#searchBar
[prefilledValue]="searchTerms$ | async"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
removeScientificConditionAction,
setDateRangeFilterAction,
addScientificConditionAction,
setPidTermsAction,
} from "state-management/actions/datasets.actions";
import { of } from "rxjs";
import {
Expand Down Expand Up @@ -479,8 +480,9 @@ describe("DatasetsFilterComponent", () => {

component.clearFacets();

expect(dispatchSpy).toHaveBeenCalledTimes(2);
expect(dispatchSpy).toHaveBeenCalledTimes(3);
expect(dispatchSpy).toHaveBeenCalledWith(clearFacetsAction());
expect(dispatchSpy).toHaveBeenCalledWith(setPidTermsAction({ pid: "" }));
expect(dispatchSpy).toHaveBeenCalledWith(
deselectAllCustomColumnsAction()
);
Expand Down Expand Up @@ -545,4 +547,34 @@ describe("DatasetsFilterComponent", () => {
);
});
});

describe("#pidSearchChanged()", () => {
it("should dispatch a SetSearchTermsAction", () => {
dispatchSpy = spyOn(store, "dispatch");

const pid = "1";
component.pidSearchChanged(pid);

expect(dispatchSpy).toHaveBeenCalledTimes(1);
expect(dispatchSpy).toHaveBeenCalledWith(setPidTermsAction({ pid }));
});
});

describe("#buildPidTermsCondition()", () => {
const tests = [
["", "", ""],
["1", "startsWith", {"$regex": "^1"}],
["1", "contains", {"$regex": "1"}],
["1", "equals", "1"],
["1", "", "1"]
];
tests.forEach((t, i) => {
it(`should return buildPidTermsCondition ${i}`, () => {
component.appConfig.pidSearchMethod = t[1] as string;
const condition = component["buildPidTermsCondition"](t[0] as string);
expect(condition).toEqual(t[2]);
});
});
});

});
52 changes: 50 additions & 2 deletions src/app/datasets/datasets-filter/datasets-filter.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import {
selectTypeFacetCounts,
selectTypeFilter,
selectKeywordsTerms,
selectMetadataKeys
selectMetadataKeys,
selectPidTerms,
} from "state-management/selectors/datasets.selectors";

import {
Expand All @@ -40,7 +41,9 @@ import {
setDateRangeFilterAction,
clearFacetsAction,
addScientificConditionAction,
removeScientificConditionAction
removeScientificConditionAction,
setPidTermsAction,
setPidTermsFilterAction,
} from "state-management/actions/datasets.actions";
import { combineLatest, BehaviorSubject, Observable, Subscription } from "rxjs";
import {
Expand All @@ -59,6 +62,12 @@ interface DateRange {
begin: string;
end: string;
}
enum PidTermsSearchCondition {
startsWith = "startsWith",
contains = "contains",
equals = "equals",
}

@Component({
selector: "datasets-filter",
templateUrl: "datasets-filter.component.html",
Expand All @@ -73,6 +82,7 @@ export class DatasetsFilterComponent implements OnInit, OnDestroy {
keywordFacetCounts$ = this.store.select(selectKeywordFacetCounts);

searchTerms$ = this.store.select(selectSearchTerms);
pidTerms$ = this.store.select(selectPidTerms);
keywordsTerms$ = this.store.select(selectKeywordsTerms);
locationFilter$ = this.store.select(selectLocationFilter);
groupFilter$ = this.store.select(selectGroupFilter);
Expand Down Expand Up @@ -128,6 +138,21 @@ export class DatasetsFilterComponent implements OnInit, OnDestroy {
private store: Store
) {}

private buildPidTermsCondition(terms: string) {
if (!terms) return "";
switch(this.appConfig.pidSearchMethod) {
case PidTermsSearchCondition.startsWith: {
return {"$regex": `^${terms}`};
}
case PidTermsSearchCondition.contains: {
return {"$regex": terms};
}
default: {
return terms;
}
}
}

createSuggestionObserver(
facetCounts$: Observable<FacetCount[]>,
input$: BehaviorSubject<string>,
Expand Down Expand Up @@ -163,6 +188,12 @@ export class DatasetsFilterComponent implements OnInit, OnDestroy {
this.store.dispatch(setSearchTermsAction({ terms }));
}

pidSearchChanged(pid: string) {
if ("string" != typeof pid) return;
this.clearSearchBar = false;
this.store.dispatch(setPidTermsAction({ pid }));
}

onLocationInput(event: any) {
const value = (<HTMLInputElement>event.target).value;
this.locationInput$.next(value);
Expand All @@ -188,6 +219,7 @@ export class DatasetsFilterComponent implements OnInit, OnDestroy {
this.store.dispatch(addLocationFilterAction({ location: loc }));
this.locationInput$.next("");
}

locationRemoved(location: string) {
this.store.dispatch(removeLocationFilterAction({ location }));
}
Expand Down Expand Up @@ -244,6 +276,7 @@ export class DatasetsFilterComponent implements OnInit, OnDestroy {
end: "",
};
this.store.dispatch(clearFacetsAction());
this.store.dispatch(setPidTermsAction({ pid: "" }));
this.store.dispatch(deselectAllCustomColumnsAction());
}

Expand Down Expand Up @@ -297,6 +330,21 @@ export class DatasetsFilterComponent implements OnInit, OnDestroy {
this.store.dispatch(addKeywordFilterAction({ keyword: terms }));
})
);

this.subscriptions.push(
this.pidTerms$
.pipe(
skipWhile((terms) => terms.length < 5),
debounceTime(500),
distinctUntilChanged()
)
.subscribe((terms) => {
const condition = this.buildPidTermsCondition(terms);
this.store.dispatch(setPidTermsFilterAction(
{ pid: condition }
));
})
);
}

ngOnDestroy() {
Expand Down
2 changes: 0 additions & 2 deletions src/app/datasets/datasets.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ import { AdminTabComponent } from "./admin-tab/admin-tab.component";
import { instrumentsReducer } from "state-management/reducers/instruments.reducer";
import { InstrumentEffects } from "state-management/effects/instruments.effects";
import { RelatedDatasetsComponent } from "./related-datasets/related-datasets.component";
import { DatasetPidSelectionComponent } from "./dataset-pid-selection/dataset-pid-selection.component";

@NgModule({
imports: [
Expand Down Expand Up @@ -158,7 +157,6 @@ import { DatasetPidSelectionComponent } from "./dataset-pid-selection/dataset-pi
DatasetFileUploaderComponent,
AdminTabComponent,
RelatedDatasetsComponent,
DatasetPidSelectionComponent,
],
providers: [
ArchivingService,
Expand Down
Loading