-
Notifications
You must be signed in to change notification settings - Fork 3
Feature/dropdown improved #2073
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
Changes from all commits
51d3b55
9bacc1d
aadd8ab
e2fdf2f
39956cd
a51b29a
a87be3f
5810556
58c9c11
8a874c2
39b334b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import { TermsAggregator, TermsResult } from '@models/aggregation'; | |
| import { SearchService } from '@services'; | ||
| import { MultipleChoiceFilter, MultipleChoiceFilterOptions } from '@models'; | ||
| import { BaseFilterComponent } from '../base-filter.component'; | ||
| import { MultiSelectLazyLoadEvent } from 'primeng/multiselect'; | ||
|
|
||
| @Component({ | ||
| selector: 'ia-multiple-choice-filter', | ||
|
|
@@ -15,6 +16,7 @@ import { BaseFilterComponent } from '../base-filter.component'; | |
| }) | ||
| export class MultipleChoiceFilterComponent extends BaseFilterComponent<MultipleChoiceFilter> { | ||
| options: { label: string; value: string; doc_count: number }[] = []; | ||
| allOptionsCalled: boolean = false; | ||
|
|
||
| constructor(private searchService: SearchService) { | ||
| super(); | ||
|
|
@@ -25,12 +27,26 @@ export class MultipleChoiceFilterComponent extends BaseFilterComponent<MultipleC | |
| } | ||
|
|
||
| onQueryModelUpdate(): void { | ||
| this.getOptions(); | ||
| if( this.allOptionsCalled ) { | ||
| this.getOptions(true); | ||
| } | ||
| this.getOptions(false); | ||
| } | ||
|
|
||
| /** Gets all the filter options from ES, only if there are more than 10 options for that filter */ | ||
| getAllOptionsFromES(event:MultiSelectLazyLoadEvent) { | ||
| const optionCount = (this.filter.corpusField.filterOptions as MultipleChoiceFilterOptions).option_count; | ||
| if (optionCount > 10) { | ||
| this.getOptions(true); | ||
| this.allOptionsCalled = true; | ||
| } | ||
| } | ||
|
Comment on lines
+37
to
43
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now, every filter will make a new query request when the panel is opened, but this results in unnecessary extra requests for fields with only a few values - it's just fetching the data twice. Then for filters like My suggestion would be to use the (In the future, we might transition the option count to a boolean.) |
||
|
|
||
| private async getOptions(): Promise<void> { | ||
| private async getOptions(all: boolean = false): Promise<void> { | ||
| console.log('fire'); | ||
| if (this.filter && this.queryModel) { | ||
| const optionCount = (this.filter.corpusField.filterOptions as MultipleChoiceFilterOptions).option_count; | ||
| // optionCount is set to the maximum when the filter panel is shown, but not when other filters change | ||
| const optionCount = all ? 10000 : (this.filter.corpusField.filterOptions as MultipleChoiceFilterOptions).option_count; | ||
| const aggregator = new TermsAggregator(this.filter.corpusField, optionCount); | ||
| const queryModel = this.queryModel.clone(); | ||
| queryModel.filterForField(this.filter.corpusField).deactivate(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why set this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[virtualscroll]: necessary to virtualscroll
[virtualScrollItemSize]: obligatory field, is overwritten in CSS (should we make that clear somewhere?)
[lazy]: can be and will be removed, good catch
[maxSelectedLabels]: this ensures that if more than 1 label (filter) is selected, it shows '2 items selected' instead of the labelnames.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know what
maxSelectedLabelsmeans, but why did you change it here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not actually change it, I just put it on a newline :)