Skip to content

Commit

Permalink
SED-3278 Allow reset of dropdowns and search for empty values (#913)
Browse files Browse the repository at this point in the history
* SED-3278 Allow reset of dropdowns and search for empty values

* SED-3278 Allow reset of dropdowns and search for empty values. Improvements

* SED-3278 Allow reset of dropdowns and search for empty values. Revert unset filter
  • Loading branch information
dvladir authored Aug 12, 2024
1 parent 2df47fb commit 739d25b
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<step-form-field [matTooltip]="(invalidFilterMessage$ | async)!">
<mat-select [multiple]="true" [formControl]="filterControl">
@if (useUnsetItem()) {
<mat-option class="unset-item" [value]="UNSET_VALUE">
<span class="unset-content">unset</span>
</mat-option>
}
@for (item of displayItems(); track item.key) {
<mat-option [value]="item.key">{{ item.value }}</mat-option>
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@use 'projects/step-core/styles/core-variables' as var;

.unset-item {
border-bottom: solid 0.1rem;
}

.unset-content::before {
content: '(';
}
.unset-content::after {
content: ')';
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import {
Component,
computed,
forwardRef,
input,
Input,
OnChanges,
SimpleChanges,
TrackByFunction,
} from '@angular/core';
import { Component, computed, forwardRef, input, Input } from '@angular/core';
import { ArrayItemLabelValueExtractor } from '../../injectables/array-item-label-value-extractor';
import { KeyValue } from '@angular/common';
import { BaseFilterComponent } from '../base-filter/base-filter.component';
import { FormBuilder, FormControl } from '@angular/forms';
import { map, Observable } from 'rxjs';

export const UNSET_VALUE = 'unset';

@Component({
selector: 'step-array-filter-advanced',
templateUrl: './array-filter-advanced.component.html',
Expand All @@ -27,10 +20,15 @@ import { map, Observable } from 'rxjs';
})
export class ArrayFilterAdvancedComponent<T = unknown> extends BaseFilterComponent<string[], unknown> {
/** @Input() **/
items = input<T[] | ReadonlyArray<T>>([]);
readonly items = input<T[] | ReadonlyArray<T>>([]);

/** @Input() **/
readonly extractor = input<ArrayItemLabelValueExtractor<T, unknown> | undefined>(undefined);

/** @Input() **/
extractor = input<ArrayItemLabelValueExtractor<T, unknown> | undefined>(undefined);
readonly useUnsetItem = input(false);

protected readonly UNSET_VALUE = UNSET_VALUE;

protected displayItems = computed<KeyValue<unknown, string>[]>(() => {
const items = this.items();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@use 'projects/step-core/styles/core-mixins' as m;

:host.disabled {
pointer-events: none;
}

@include m.unset-item;
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@case (InputType.DROPDOWN) {
<ng-template #dropdownItemTemplate let-item>{{ item }}</ng-template>
<step-editable-dropdown-label
[useUnsetItem]="true"
[labelTemplate]="labelTemplate"
[items]="dropdownItems()"
[itemTemplate]="dropdownItemTemplate"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
(ngModelChange)="onValueChange($event)"
(blur)="invokeTouch()"
>
@if (!!value) {
<mat-option class="unset-item" [value]="null">unset</mat-option>
}
@for (item of dropdownItems(); track item) {
<mat-option [value]="item">{{ item }}</mat-option>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<step-form-field>
<mat-select [ngModel]="value" (ngModelChange)="onValueChange($event)" (openedChange)="onOpenedChange($event)">
<ng-container [stepZIndex]="1050">
@if (useUnsetItem() && !!value) {
<mat-option class="unset-item" [value]="null">unset</mat-option>
}
@for (item of items; track item) {
<mat-option [value]="item">
<ng-container *ngTemplateOutlet="itemTemplate(); context: { $implicit: item }" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@use 'projects/step-core/styles/core-variables' as var;
@use 'projects/step-core/styles/core-mixins' as m;

:host {
position: relative;
Expand Down Expand Up @@ -36,3 +37,5 @@
background: var.$gray-50;
}
}

@include m.unset-item;
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export class EditableDropdownLabelComponent<T> extends EditableComponent<T> {
() => (this.itemTemplateDirective()?.templateRef as ItemTemplateRef<T>) ?? this.itemTemplateInput(),
);

/** @Input() **/
readonly useUnsetItem = input(false);

protected override onValueChange(value: T): void {
super.onValueChange(value);
this.focusedElement = this.matSelectElementRef!.nativeElement;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CompareCondition } from '../../basics/step-basics.module';
import { CompareCondition, UNSET_VALUE } from '../../basics/step-basics.module';
import { TableCollectionFilter, TableRequestFilter } from '../../../client/step-client-module';
import { FilterCondition } from './filter-condition';
import { FilterConditionType } from './filter-condition-type.enum';
Expand All @@ -20,7 +20,7 @@ export class ArrayFilterCondition extends FilterCondition<string[]> {
const children = valueArray.map((value) => ({
field,
type: CompareCondition.EQUALS,
expectedValue: value,
expectedValue: value === UNSET_VALUE ? null : value,
}));

const arrayFilter: TableCollectionFilter = {
Expand Down
11 changes: 11 additions & 0 deletions projects/step-core/styles/_core-mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,14 @@
margin-bottom: 0;
}
}

@mixin unset-item {
.unset-item {
text-decoration: underline;
font-style: italic;
color: var.$blue-650;
min-height: 3rem;
font-size: 1.4rem;
padding-left: calc(100% - 5rem);
}
}

0 comments on commit 739d25b

Please sign in to comment.