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

Zhylka/legacy chips rewriting #2655

merged 7 commits into from
Dec 4, 2024

Conversation

MaxZhylka
Copy link
Contributor

Replaced MatLegacyChipModule, replaced all chip-lists by chip-set. In the CreateDescriptionForm component, specifically updated mat-chip-list to mat-chip-grid to resolve test failures

@@ -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

@@ -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

@MaxZhylka
Copy link
Contributor Author

I am not sure if ngModel needs to be set on mat-chip-grid (as shown in the docs), because we use reactive forms. So, I removed ngModel from the input and fixed the issue where the input remained disabled after adding 5 elements and then removing one.

<input
[ngClass]="{ 'keywords-input': !keyWord && keyWords.length < 1 }"
[ngClass]="{ 'keywords-input': !keyWordsCtrl.value && keyWords$.value.length < 1 }"
Copy link
Contributor

Choose a reason for hiding this comment

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

remove extra whitespace after { and before }

public keyWord: string;

public disabilityOptionRadioBtn: FormControl = new FormControl(false);
public disabledKeyWordsInput = false;

public separatorKeysCodes = [13, 188]; // Enter and Comma
Copy link
Contributor

Choose a reason for hiding this comment

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

Import keycodes from @angular/cdk/keycodes

@@ -74,18 +75,29 @@ export class CreateDescriptionFormComponent implements OnInit, OnDestroy {

this.passDescriptionFormGroup.emit(this.DescriptionFormGroup);
this.keyWordsListener();

this.keyWords$.pipe(takeUntil(this.destroy$)).subscribe((keyWords) => {
this.disabledKeyWordsInput = keyWords.length >= 5;
Copy link
Contributor

Choose a reason for hiding this comment

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

create a private read-only property for max keywords instead of a magic number

@@ -40,12 +40,13 @@ export class CreateDescriptionFormComponent implements OnInit, OnDestroy {
public SectionItemsFormArray = new FormArray([]);
public keyWordsCtrl: FormControl = new FormControl('', Validators.required);

public keyWords: string[] = [];
public keyWords$: BehaviorSubject<string[]> = new BehaviorSubject<string[]>([]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need a subject in this case?
We can simply do checks inside the method or create a separate method to switch the input state

if (this.keyWords.length) {
this.DescriptionFormGroup.get('keyWords').setValue([...this.keyWords]);
const keyWords = this.keyWords$.value;
const index = keyWords.indexOf(word);
Copy link
Contributor

Choose a reason for hiding this comment

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

keyWords.includes()

@DmyMi DmyMi merged commit eed0726 into develop Dec 4, 2024
3 checks passed
@DmyMi DmyMi deleted the Zhylka/legacy-Chips-Rewriting branch December 4, 2024 10:25
Liuboff added a commit that referenced this pull request Dec 5, 2024
* Liuboff/Replacing legacy snack bar

* Liuboff/Replacing legacy snack bar

* Zhylka/legacy chips rewriting (#2655)

* chip-list replaced by chip-set/chip-listbox

* all chip-lists replaced by chip-set

* replaced list-set by list-grid in create-description-form for passing tests

* added test for removing chips when changing language

* removed ngModel and fixed input behavior after adding 5 elements

* removed behavior subject, added function to change keyword input state, fixed remarks

* changed cdk version

* changed based on PR recommendations

* Liuboff/Replacing legacy snack bar

* changed based on PR recommendations

* fix tests according PR recomendations

* Replace > to previous line

* fix tests according PR recomendations

* Replace > to previous line

---------

Co-authored-by: Liubov Zatsepina <liubov_zatsepina@epam.com>
Co-authored-by: MaxZhylka <132847452+MaxZhylka@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants