Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
feat(filter-field): Display a hint when partial options are loaded.
Browse files Browse the repository at this point in the history
Fixes #APM-277597
  • Loading branch information
giordy authored and ffriedl89 committed May 31, 2021
1 parent bee825d commit f08b4a9
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 26 deletions.
15 changes: 15 additions & 0 deletions libs/barista-components/filter-field/src/filter-field-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ import {
} from './filter-field-util';
import { DtFilterValue, DtFilterFieldTagData } from './types';

/** InjectionToken of the Filter Field options. */
export const DT_FILTER_FIELD_CONFIG = new InjectionToken<string>(
'DT_FILTER_FIELD_CONFIG',
);

/** The config that can be passed to the dt-filter-field component for customization */
export interface DtFilterFieldConfig {
/** Message displayed in the options panel when partial results are listed */
partialHintMessage: string;
}

export const DT_FILTER_FIELD_DEFAULT_CONFIG: DtFilterFieldConfig = {
partialHintMessage: 'Pick or provide free text',
};

/** User defined parser function for tag key:values, overrides default parser function */
export type TagParserFunction = (
filterValues: DtFilterValue[],
Expand Down
60 changes: 34 additions & 26 deletions libs/barista-components/filter-field/src/filter-field.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,34 +87,42 @@
>
</dt-option>
</ng-container>
<ng-container
*ngFor="let optionOrGroupDef of _autocompleteOptionsOrGroups"
>
<dt-optgroup
*ngIf="optionOrGroupDef.group; else options"
[label]="optionOrGroupDef.group!.label"
<ng-container>
<div
class="dt-filter-field-hint-partial"
*ngIf="_currentDef?.autocomplete?.partial"
>
<dt-option
*ngFor="let optionDef of optionOrGroupDef.group!.options"
[value]="optionDef"
[disabled]="optionDef.option!.disabled"
[attr.title]="_getTitle(optionDef.option)"
>
<dt-highlight [term]="_inputValue">{{
optionDef.option!.viewValue
}}</dt-highlight>
</dt-option>
</dt-optgroup>
<ng-template #options>
<dt-option
[value]="optionOrGroupDef"
[attr.title]="_getTitle(optionOrGroupDef.option)"
{{ _filterFieldConfig.partialHintMessage }}
</div>
<ng-container
*ngFor="let optionOrGroupDef of _autocompleteOptionsOrGroups"
>
<dt-optgroup
*ngIf="optionOrGroupDef.group; else options"
[label]="optionOrGroupDef.group!.label"
>
<dt-highlight [term]="_inputValue">{{
optionOrGroupDef.option!.viewValue
}}</dt-highlight>
</dt-option>
</ng-template>
<dt-option
*ngFor="let optionDef of optionOrGroupDef.group!.options"
[value]="optionDef"
[disabled]="optionDef.option!.disabled"
[attr.title]="_getTitle(optionDef.option)"
>
<dt-highlight [term]="_inputValue">{{
optionDef.option!.viewValue
}}</dt-highlight>
</dt-option>
</dt-optgroup>
<ng-template #options>
<dt-option
[value]="optionOrGroupDef"
[attr.title]="_getTitle(optionOrGroupDef.option)"
>
<dt-highlight [term]="_inputValue">{{
optionOrGroupDef.option!.viewValue
}}</dt-highlight>
</dt-option>
</ng-template>
</ng-container>
</ng-container>
</dt-autocomplete>

Expand Down
12 changes: 12 additions & 0 deletions libs/barista-components/filter-field/src/filter-field.scss
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ $dt-filter-field-inner-height: 30px;
height: $dt-filter-field-inner-height;
align-items: center;
margin-right: 8px;

::ng-deep svg {
width: 16px;
height: 16px;
Expand Down Expand Up @@ -179,6 +180,17 @@ button.dt-filter-field-clear-all-button-hidden {
margin: 0;
}

::ng-deep .dt-filter-field-panel .dt-filter-field-hint-partial {
@include dt-text-ellipsis();
@include dt-custom-font-styles(
$custom-color: $gray-500,
$custom-font-size: 12px
);
text-align: center;
border-bottom: solid 1px $gray-200;
padding: 0 2px;
}

::ng-deep .dt-filter-field-panel .dt-option {
max-width: 100%;
overflow: hidden;
Expand Down
7 changes: 7 additions & 0 deletions libs/barista-components/filter-field/src/filter-field.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import {
getInput,
getTagButtons,
isClearAllVisible,
getPartialResultsHintPanel,
} from './testing/filter-field-test-helpers';
import { DtAutocompleteValue, DtFilterValue } from './types';

Expand Down Expand Up @@ -1146,11 +1147,17 @@ describe('DtFilterField', () => {
let options = getOptions(overlayContainerElement);
expect(options).toHaveLength(0);

let hintPanel = getPartialResultsHintPanel(overlayContainerElement);
expect(hintPanel).toBeNull();

fixture.componentInstance.dataSource.data = DATA_PARTIAL;
fixture.detectChanges();
advanceFilterfieldCycle(true, true);
tick();

hintPanel = getPartialResultsHintPanel(overlayContainerElement);
expect(hintPanel).not.toBeNull();

options = getOptions(overlayContainerElement);
expect(options).toHaveLength(4);
expect(options[0].textContent).toContain('Zürich');
Expand Down
9 changes: 9 additions & 0 deletions libs/barista-components/filter-field/src/filter-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,11 @@ import {
import {
DT_FILTER_EDITION_VALUES_DEFAULT_PARSER_CONFIG,
DT_FILTER_EDITION_VALUES_PARSER_CONFIG,
DT_FILTER_FIELD_CONFIG,
DT_FILTER_FIELD_DEFAULT_CONFIG,
DT_FILTER_VALUES_DEFAULT_PARSER_CONFIG,
DT_FILTER_VALUES_PARSER_CONFIG,
DtFilterFieldConfig,
EditionParserFunction,
TagParserFunction,
} from './filter-field-config';
Expand Down Expand Up @@ -557,7 +560,13 @@ export class DtFilterField<T = any>
@Optional()
@Inject(DT_FILTER_EDITION_VALUES_PARSER_CONFIG)
private editionValuesParser: EditionParserFunction,
@Optional()
@Inject(DT_FILTER_FIELD_CONFIG)
readonly _filterFieldConfig: DtFilterFieldConfig,
) {
this._filterFieldConfig =
this._filterFieldConfig || DT_FILTER_FIELD_DEFAULT_CONFIG;

this.tagValuesParser =
this.tagValuesParser || DT_FILTER_VALUES_DEFAULT_PARSER_CONFIG;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ export function customParser(
return tagData;
}

export function getPartialResultsHintPanel(
overlayContainerElement: HTMLElement,
): HTMLElement | null {
return overlayContainerElement.querySelector('.dt-filter-field-hint-partial');
}

export function getOptions(
overlayContainerElement: HTMLElement,
): HTMLElement[] {
Expand Down

0 comments on commit f08b4a9

Please sign in to comment.