Skip to content

Commit

Permalink
add input data type filters
Browse files Browse the repository at this point in the history
  • Loading branch information
rrchai committed Apr 22, 2024
1 parent db9369e commit 93c996c
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
ChallengePlatformSearchQuery,
ChallengePlatformService,
ChallengePlatformSort,
EdamConceptSearchQuery,
EdamConceptService,
Image,
ImageAspectRatio,
ImageHeight,
Expand All @@ -28,44 +30,48 @@ import { Filter } from '@sagebionetworks/openchallenges/ui';
providedIn: 'root',
})
export class ChallengeSearchDataService {
private platformSearchTerms: BehaviorSubject<string> =
new BehaviorSubject<string>('');
private edamConceptSearchTerms: BehaviorSubject<EdamConceptSearchQuery> =
new BehaviorSubject<EdamConceptSearchQuery>({ searchTerms: '' });

private organizationSearchTerms: BehaviorSubject<string> =
new BehaviorSubject<string>('');

private platformSearchTerms: BehaviorSubject<string> =
new BehaviorSubject<string>('');

constructor(
private edamConceptService: EdamConceptService,
private challengePlatformService: ChallengePlatformService,
private organizationService: OrganizationService,
private imageService: ImageService
) {}

setPlatformSearchTerms(searchTerms: string) {
this.platformSearchTerms.next(searchTerms);
setEdamConceptSearchTerms(searchQuery: EdamConceptSearchQuery) {
this.edamConceptSearchTerms.next(searchQuery);
}

setOriganizationSearchTerms(searchTerms: string) {
this.organizationSearchTerms.next(searchTerms);
}

searchPlatforms(): Observable<Filter[]> {
return this.platformSearchTerms.pipe(
setPlatformSearchTerms(searchTerms: string) {
this.platformSearchTerms.next(searchTerms);
}

searchEdamConcepts(): Observable<Filter[]> {
return this.edamConceptSearchTerms.pipe(
debounceTime(400),
distinctUntilChanged(),
switchMap((searchTerm: string) => {
const sortedBy: ChallengePlatformSort = 'name';
const platformQuery: ChallengePlatformSearchQuery = {
searchTerms: searchTerm,
sort: sortedBy,
};
return this.challengePlatformService.listChallengePlatforms(
platformQuery
);
switchMap((searchQuery: EdamConceptSearchQuery) => {
// const sortedBy: EdamSort = 'name';
const edamQuery: EdamConceptSearchQuery = searchQuery;
console.log(edamQuery);
return this.edamConceptService.listEdamConcepts(edamQuery);
}),
map((page) =>
page.challengePlatforms.map((platform) => ({
value: platform.slug,
label: platform.name,
page.edamConcepts.map((edamConcept) => ({
value: edamConcept.classId,
label: edamConcept.preferredLabel,
active: false,
}))
)
Expand Down Expand Up @@ -123,4 +129,28 @@ export class ChallengeSearchDataService {
})
);
}

searchPlatforms(): Observable<Filter[]> {
return this.platformSearchTerms.pipe(
debounceTime(400),
distinctUntilChanged(),
switchMap((searchTerm: string) => {
const sortedBy: ChallengePlatformSort = 'name';
const platformQuery: ChallengePlatformSearchQuery = {
searchTerms: searchTerm,
sort: sortedBy,
};
return this.challengePlatformService.listChallengePlatforms(
platformQuery
);
}),
map((page) =>
page.challengePlatforms.map((platform) => ({
value: platform.slug,
label: platform.name,
active: false,
}))
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,10 @@ export const challengeStartYearRangeFilterPanel: FilterPanel = {
collapsed: false,
};

// checkbox filters
export const challengeStatusFilterPanel: FilterPanel = {
query: 'status',
label: 'Status',
options: challengeStatusFilter,
collapsed: false,
};

export const challengeSubmissionTypesFilterPanel: FilterPanel = {
query: 'submissionTypes',
label: 'Submission Type',
options: challengeSubmissionTypesFilter,
export const challengeCategoriesFilterPanel: FilterPanel = {
query: 'categories',
label: 'Category',
options: challengeCategoriesFilter,
collapsed: false,
};

Expand All @@ -40,27 +32,11 @@ export const challengeIncentivesFilterPanel: FilterPanel = {
collapsed: false,
};

export const challengePlatformsFilterPanel: FilterPanel = {
query: 'platforms',
label: 'Platform',
options: challengePlatformsFilter,
collapsed: false,
};

// dropdown filters
export const challengeInputDataTypesFilterPanel: FilterPanel = {
query: 'inputDataTypes',
label: 'Input Data Type',
options: challengeInputDataTypesFilter,
collapsed: false,
showAvatar: false,
};

export const challengeCategoriesFilterPanel: FilterPanel = {
query: 'categories',
label: 'Category',
options: challengeCategoriesFilter,
collapsed: false,
};

export const challengeOrganizationsFilterPanel: FilterPanel = {
Expand All @@ -78,3 +54,24 @@ export const challengeOrganizatersFilterPanel: FilterPanel = {
collapsed: false,
showAvatar: true,
};

export const challengePlatformsFilterPanel: FilterPanel = {
query: 'platforms',
label: 'Platform',
options: challengePlatformsFilter,
collapsed: false,
};

export const challengeStatusFilterPanel: FilterPanel = {
query: 'status',
label: 'Status',
options: challengeStatusFilter,
collapsed: false,
};

export const challengeSubmissionTypesFilterPanel: FilterPanel = {
query: 'submissionTypes',
label: 'Submission Type',
options: challengeSubmissionTypesFilter,
collapsed: false,
};
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ <h2>Challenges</h2>
/>
</p-panel>
<p-divider></p-divider>
<p-panel
header="{{ inputDataTypesFilter.label }}"
[toggleable]="true"
[collapsed]="inputDataTypesFilter.collapsed"
>
<openchallenges-search-dropdown-filter
[options]="inputDataTypesFilter.options"
[selectedOptions]="selectedInputDataTypes"
placeholder="{{ inputDataTypesFilter.label.toLowerCase() + '(s)' }} "
[showAvatar]="inputDataTypesFilter.showAvatar"
[filterByApiClient]="true"
(selectionChange)="onParamChange({ inputDataTypes: $event })"
(searchChange)="onSearchChange('inputDataTypes', $event)"
/>
</p-panel>
<p-divider></p-divider>
<p-panel
header="{{ organizationsFilter.label }}"
[toggleable]="true"
Expand Down
Loading

0 comments on commit 93c996c

Please sign in to comment.