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

Zhylka/legacy chips rewriting #2655

Merged
merged 7 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
2 changes: 1 addition & 1 deletion src/app/shared/modules/material.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { MatLegacyAutocompleteModule as MatAutocompleteModule } from '@angular/m
import { MatLegacyButtonModule as MatButtonModule } from '@angular/material/legacy-button';
import { MatLegacyCardModule as MatCardModule } from '@angular/material/legacy-card';
import { MatLegacyCheckboxModule as MatCheckboxModule } from '@angular/material/legacy-checkbox';
import { MatLegacyChipsModule as MatChipsModule } from '@angular/material/legacy-chips';
import { MatChipsModule } from '@angular/material/chips';
import { MatDialogModule } from '@angular/material/dialog';
import { MatLegacyFormFieldModule as MatFormFieldModule } from '@angular/material/legacy-form-field';
import { MatLegacyInputModule as MatInputModule } from '@angular/material/legacy-input';
Expand Down
4 changes: 2 additions & 2 deletions src/app/shared/styles/create-form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ button:focus {
height: auto;
}

.mat-chip-list ::ng-deep .mat-chip-list-wrapper {
.mat-set ::ng-deep .mat-chip-set-wrapper {
padding-right: 10px;
}

.mat-chip-list ::ng-deep .mat-chip {
.mat-chip-set ::ng-deep .mat-chip {
span {
overflow: hidden;
text-overflow: ellipsis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ <h3 class="wrapper-title">{{ 'TITLES.EDIT_INSTITUTION_HIERARCHY_FORM_TITLE' | tr
[compareWith]="compareItems"
[formControl]="this.directionsControl">
<mat-select-trigger>
<mat-chip-list #chipList>
<mat-chip-set #chipSet>
<mat-chip *ngFor="let direction of this.directionsControl.value" (removed)="onRemoveItem(direction)">
<img class="min-logo" src="../../assets/icons/icon_painting.svg" alt="Link" />
<span>{{ direction.title }}</span>
<mat-icon matChipRemove>cancel</mat-icon>
</mat-chip>
</mat-chip-list>
</mat-chip-set>
</mat-select-trigger>
<mat-option class="dropdown-option" *ngFor="let direction of directions$ | async" [value]="direction">
{{ direction.title }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@
[compareWith]="compareSocialGroups"
[formControl]="socialGroupControl">
<mat-select-trigger>
<mat-chip-list #chipList>
<mat-chip-set #chipSet>
<mat-chip *ngFor="let group of socialGroupControl.value" (removed)="onRemoveItem(group)">
<span>{{ group.name }}</span>
<mat-icon matChipRemove>cancel</mat-icon>
</mat-chip>
</mat-chip-list>
</mat-chip-set>
</mat-select-trigger>
<mat-option class="dropdown-option" *ngFor="let group of socialGroups" [value]="group" [disabled]="checkDisabled(group)">
{{ group.name }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { MatLegacyInputModule as MatInputModule } from '@angular/material/legacy
import { MatLegacySelectModule as MatSelectModule } from '@angular/material/legacy-select';
import { MatRadioModule } from '@angular/material/radio';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { TranslateModule } from '@ngx-translate/core';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { NgxsModule } from '@ngxs/store';

import { KeyFilterDirective } from 'shared/directives/key-filter.directive';
Expand All @@ -19,6 +19,7 @@ import { ChildFormComponent } from './child-form.component';
describe('ChildFormComponent', () => {
let component: ChildFormComponent;
let fixture: ComponentFixture<ChildFormComponent>;
let translate: TranslateService;

beforeEach(async () => {
await TestBed.configureTestingModule({
Expand Down Expand Up @@ -56,13 +57,23 @@ describe('ChildFormComponent', () => {
placeOfLiving: new FormControl(''),
certificateOfBirth: new FormControl('')
});

translate = TestBed.inject(TranslateService);
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});

it('should remove all chips when language changes', () => {
const mockChip = { remove: jest.fn() };

(component as any).chipSet = { _chips: [mockChip] };

translate.use('uk');

expect(mockChip.remove).toHaveBeenCalled();
});
});

@Component({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output, ViewChild } from '@angular/core';
import { AbstractControl, FormControl, FormGroup } from '@angular/forms';
import { MatLegacyChipList as MatChipList } from '@angular/material/legacy-chips';
import { MatChipSet } from '@angular/material/chips';
import { MatLegacyOption as MatOption } from '@angular/material/legacy-core';
import { MatLegacySelect as MatSelect } from '@angular/material/legacy-select';
import { LangChangeEvent, TranslateService } from '@ngx-translate/core';
Expand Down Expand Up @@ -34,8 +34,9 @@ export class ChildFormComponent implements OnInit, OnDestroy {

@ViewChild('select')
private select: MatSelect;
@ViewChild('chipList')
private chipList: MatChipList;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove empty row

@ViewChild('chipSet')
private chipSet: MatChipSet;

public readonly validationConstants = ValidationConstants;

Expand Down Expand Up @@ -63,7 +64,9 @@ export class ChildFormComponent implements OnInit, OnDestroy {

this.translateService.onLangChange.pipe(takeUntil(this.destroy$)).subscribe(({ lang }: LangChangeEvent) => {
this.store.dispatch(new GetSocialGroup(lang));
this.chipList.chips.forEach((chip) => chip.remove());
this.chipSet._chips.forEach((chip) => {
chip.remove();
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h3 class="wrapper-title">{{ 'FORMS.HEADERS.ADD_ACHIEVEMENT' | translate }}</h3>
placeholder="{{ 'FORMS.PLACEHOLDERS.CHILDREN' | translate }}"
[compareWith]="compareEntities">
<mat-select-trigger>
<mat-chip-list>
<mat-chip-set>
<mat-chip
*ngFor="let child of childrenFormControl.value"
[removable]="true"
Expand All @@ -60,7 +60,7 @@ <h3 class="wrapper-title">{{ 'FORMS.HEADERS.ADD_ACHIEVEMENT' | translate }}</h3>
</div>
<mat-icon matChipRemove>cancel</mat-icon>
</mat-chip>
</mat-chip-list>
</mat-chip-set>
</mat-select-trigger>
<mat-option *ngFor="let child of approvedChildren.entities" [value]="child" class="dropdown-option">
<div
Expand Down Expand Up @@ -105,7 +105,7 @@ <h3 class="wrapper-title">{{ 'FORMS.HEADERS.ADD_ACHIEVEMENT' | translate }}</h3>
placeholder="{{ 'FORMS.PLACEHOLDERS.SELECT_TEACHER' | translate }}"
[compareWith]="compareEntities">
<mat-select-trigger>
<mat-chip-list #chipList>
<mat-chip-set #chipSet>
<mat-chip *ngFor="let teacher of teachersFormControl.value" (removed)="onRemoveItem(teacher, 'teachers')">
<div
class="truncated-text"
Expand All @@ -117,7 +117,7 @@ <h3 class="wrapper-title">{{ 'FORMS.HEADERS.ADD_ACHIEVEMENT' | translate }}</h3>
</div>
<mat-icon matChipRemove>cancel</mat-icon>
</mat-chip>
</mat-chip-list>
</mat-chip-set>
</mat-select-trigger>
<ng-container *ngIf="workshop">
<mat-option *ngFor="let teacher of workshop.teachers" [value]="teacher" class="dropdown-option">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
>{{ 'FORMS.PLACEHOLDERS.KEYWORDS_START' | translate }} {{ validationConstants.MAX_KEYWORDS_LENGTH }}
{{ 'FORMS.PLACEHOLDERS.KEYWORDS_END' | translate }}</span
>
<mat-chip-list #chipList>
<mat-chip-grid #chipGrid>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to use mat-chip-grid together with the input to follow the correct interaction pattern

<mat-chip *ngFor="let keyWord of keyWords" (removed)="onRemoveKeyWord(keyWord)" class="keyWordChip">
<div [matTooltip]="keyWord" showTooltipIfTruncated matTooltipClass="tooltip" class="chip-text">
{{ keyWord }}
Expand All @@ -73,11 +73,11 @@
#keyWordsInput
(focusout)="onKeyWordsInput()"
[formControl]="keyWordsCtrl"
[matChipInputFor]="chipList"
[matChipInputFor]="chipGrid"
(keyup.enter)="onKeyWordsInput()"
[(ngModel)]="keyWord"
autocomplete="off"
appTrimValue />
</mat-chip-list>
</mat-chip-grid>
</div>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormControl, FormGroup, FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatGridListModule } from '@angular/material/grid-list';
import { MatIconModule } from '@angular/material/icon';
import { MatLegacyChipsModule as MatChipsModule } from '@angular/material/legacy-chips';
import { MatChipsModule } from '@angular/material/chips';
import { MatLegacyFormFieldModule as MatFormFieldModule } from '@angular/material/legacy-form-field';
import { MatLegacyInputModule as MatInputModule } from '@angular/material/legacy-input';
import { MatRadioModule } from '@angular/material/radio';
Expand Down
Loading