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

[ENG-4660] activeFilters query param #1990

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 4 additions & 2 deletions app/search/controller.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import Controller from '@ember/controller';
import { action } from '@ember/object';
import { tracked } from '@glimmer/tracking';
import { OnSearchParams, ResourceTypeFilterValue } from 'osf-components/components/search-page/component';
import { Filter, OnSearchParams, ResourceTypeFilterValue } from 'osf-components/components/search-page/component';

export default class SearchController extends Controller {
@tracked q?: string = '';
@tracked sort?: string = '-relevance';
@tracked resourceType?: ResourceTypeFilterValue | null = null;
@tracked activeFilters?: Filter[] = [];

queryParams = ['q', 'sort', 'resourceType'];
queryParams = ['q', 'sort', 'resourceType', 'activeFilters'];

@action
onSearch(queryOptions: OnSearchParams) {
this.q = queryOptions.cardSearchText;
this.sort = queryOptions.sort;
this.resourceType = queryOptions.resourceType;
this.activeFilters = queryOptions.activeFilters;
}
}
1 change: 1 addition & 0 deletions app/search/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
@sort={{this.sort}}
@resourceType={{this.resourceType}}
@page={{this.page}}
@activeFilters={{this.activeFilters}}
/>
5 changes: 4 additions & 1 deletion lib/osf-components/addon/components/search-page/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface OnSearchParams {
cardSearchText?: string;
sort?: string;
resourceType?: ResourceTypeFilterValue | null;
activeFilters?: Filter[];
}

interface SearchArgs {
Expand All @@ -63,6 +64,7 @@ interface SearchArgs {
provider?: ProviderModel;
showResourceTypeFilter: boolean;
page: string;
activeFilters: Filter[];
}

const searchDebounceTime = 100;
Expand All @@ -89,6 +91,7 @@ export default class SearchPage extends Component<SearchArgs> {
this.cardSearchText = this.args.cardSearchText;
this.sort = this.args.sort;
this.resourceType = this.args.resourceType;
this.activeFilters = A<Filter>(this.args.activeFilters);
taskFor(this.search).perform();
}

Expand Down Expand Up @@ -233,7 +236,7 @@ export default class SearchPage extends Component<SearchArgs> {
this.totalResultCount = searchResult.totalResultCount === ShareMoreThanTenThousand ? '10,000+' :
searchResult.totalResultCount;
if (this.args.onSearch) {
this.args.onSearch({cardSearchText, sort, resourceType});
this.args.onSearch({cardSearchText, sort, resourceType, activeFilters});
}
} catch (e) {
this.toast.error(e);
Expand Down
Loading