Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ export class VMwareCloudDirectorBasicNodeDataComponent
const networkControl = this.form.get(Controls.Network);
const additionalNetworksControl = this.form.get(Controls.AdditionalNetworks);

additionalNetworksControl.setValue(additionalNetworksControl.value.filter(n => this.networks.includes(n)));
additionalNetworksControl.setValue(additionalNetworksControl.value?.filter(n => this.networks.includes(n)));

if (networkControl.value && this.networks.includes(networkControl.value)) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@
</mat-select>
</mat-form-field>


<mat-form-field fxFlex *ngIf="networks.length > 1">
@if (networks.length > 1) {
<mat-form-field fxFlex>
<mat-label>Additional Networks</mat-label>
<mat-select [formControlName]="Controls.AdditionalNetworks"
(selectionChange)="onAdditionalNetworkChanged($event.value)"
Expand All @@ -111,6 +111,7 @@
[disabled]="network == form.get(Controls.Network).value"> {{network}} </mat-option>
</mat-select>
</mat-form-field>
}

<km-combobox #placementPolicyCombobox
[selected]="selectedPlacementPolicy"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
NG_VALUE_ACCESSOR,
ValidationErrors,
Validator,
ValidatorFn,
Validators,
} from '@angular/forms';
import {MatAutocompleteSelectedEvent} from '@angular/material/autocomplete';
Expand Down Expand Up @@ -82,7 +83,9 @@ export class ChipAutocompleteComponent implements OnChanges, OnInit, OnDestroy,
@Input() description = 'Use comma, enter or space key as the separator.';
@Input() placeholder = 'Select single or multiple values';
@Input() required = false;
@Output() change = new EventEmitter<string[]>();
@Input() patternError = 'Invalid pattern';
@Input() pattern: string;
@Output() onChange = new EventEmitter<string[]>();
@ViewChild('tagInput') tagInput: ElementRef;
private readonly _debounceTime = 250;
private _unsubscribe = new Subject<void>();
Expand All @@ -96,8 +99,11 @@ export class ChipAutocompleteComponent implements OnChanges, OnInit, OnDestroy,
if (changes?.disabled && this.form) {
if (this.disabled) {
this.form.get(Controls.Tags).disable();
this.form.get(Controls.Tags).clearValidators();
} else if (this.form.get(Controls.Tags).disabled) {
this.form.get(Controls.Tags).enable();
this.form.get(Controls.Tags).setValidators(this._validators());
this.form.get(Controls.Tags).updateValueAndValidity();
}
}
}
Expand All @@ -122,7 +128,11 @@ export class ChipAutocompleteComponent implements OnChanges, OnInit, OnDestroy,
}

removeTag(tag: string): void {
this.selectedTags = this.selectedTags.filter(selectedTag => selectedTag !== tag);
const index = this.selectedTags.indexOf(tag);

if (index >= 0) {
this.selectedTags.splice(index, 1);
}
this._valueUpdated();
}

Expand Down Expand Up @@ -151,10 +161,7 @@ export class ChipAutocompleteComponent implements OnChanges, OnInit, OnDestroy,
private _initForm() {
this.form = this._builder.group({
[Controls.Filter]: this._builder.control(''),
[Controls.Tags]: this._builder.control(
[],
this.required ? [Validators.required, KmValidators.unique()] : [KmValidators.unique()]
),
[Controls.Tags]: this._builder.control([], this._validators()),
});

if (this.disabled) {
Expand All @@ -180,7 +187,7 @@ export class ChipAutocompleteComponent implements OnChanges, OnInit, OnDestroy,
private _valueUpdated() {
this._patchValue();
this.filteredTags = this._removeSelectedTagsFromList();
this.change.emit(this.selectedTags);
this.onChange.emit(this.selectedTags);
}

private _patchValue() {
Expand All @@ -196,10 +203,23 @@ export class ChipAutocompleteComponent implements OnChanges, OnInit, OnDestroy,
}

private _removeSelectedTagsFromFilterList(tags: string[]): string[] {
return tags?.filter(tag => !this.selectedTags.includes(tag)) || [];
return tags?.filter(tag => !this.selectedTags?.includes(tag)) || [];
}

private _removeSelectedTagsFromList(): string[] {
return this.tags?.filter(tag => !this.selectedTags.includes(tag)) || [];
return this.tags?.filter(tag => !this.selectedTags?.includes(tag)) || [];
}

private _validators(): ValidatorFn[] {
const validators = [KmValidators.unique()];

if (this.required) {
validators.push(Validators.required);
}

if (this.pattern) {
validators.push(KmValidators.chipPattern(this.pattern));
}
return validators;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
[placeholder]="placeholder"
[matAutocomplete]="auto"
[matChipInputFor]="tagList"
[matChipInputAddOnBlur]="true"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
(matChipInputTokenEnd)="addTag($event)" />
</mat-chip-grid>
Expand All @@ -62,5 +63,13 @@
<span>Values must be <strong>unique</strong>.</span>
</mat-error>
}

@if (form.get(Controls.Tags).hasError('pattern')) {
<mat-error>
<span [innerHTML]="patternError"></span>
</mat-error>
}


</mat-form-field>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,18 @@ import {KUBERNETES_RESOURCE_NAME_PATTERN} from '@app/shared/validators/others';
import {AutocompleteControls, AutocompleteInitialState} from '@shared/components/autocomplete/component';
import _ from 'lodash';
import {EMPTY, forkJoin, merge, Observable, of, onErrorResumeNext} from 'rxjs';
import {catchError, debounceTime, distinctUntilChanged, filter, map, switchMap, takeUntil, tap} from 'rxjs/operators';
import {
catchError,
debounceTime,
distinctUntilChanged,
filter,
map,
switchMap,
take,
takeUntil,
tap,
} from 'rxjs/operators';
import {NodeDataService} from '@app/core/services/node-data/service';

enum Controls {
Networks = 'networks',
Expand Down Expand Up @@ -107,6 +118,7 @@ export class VSphereProviderExtendedComponent extends BaseFormValidator implemen
folderLabel = FolderState.Empty;
networkLabel = NetworkState.Empty;
tagCategories: VSphereTagCategory[] = [];
predefinedTagList: string[] = [];
tagCategoryLabel = TagCategoryState.Empty;
selectedTagCategory = '';
tags: string[] = [];
Expand All @@ -123,7 +135,8 @@ export class VSphereProviderExtendedComponent extends BaseFormValidator implemen
private readonly _builder: FormBuilder,
private readonly _presets: PresetsService,
private readonly _clusterSpecService: ClusterSpecService,
private readonly _cdr: ChangeDetectorRef
private readonly _cdr: ChangeDetectorRef,
private readonly _nodeDataService: NodeDataService
) {
super('VSphere Provider Extended');
}
Expand Down Expand Up @@ -245,9 +258,17 @@ export class VSphereProviderExtendedComponent extends BaseFormValidator implemen

onTagCategoryChange(tagCategory: string): void {
this.selectedTagCategory = tagCategory;
this.predefinedTagList = [];
if (tagCategory) {
this.form.get(Controls.Tags).enable();
this.onTagValuesChange(this.tags);
this._nodeDataService.vsphere
.categoryTags(tagCategory)
.pipe(take(1))
.subscribe(tags => {
this.predefinedTagList = tags.map(t => t.name);
this._cdr.detectChanges();
});
} else {
this.form.get(Controls.Tags).reset();
this.form.get(Controls.Tags).disable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,13 @@
filterBy="name">
<div *option="let category">{{category.name}}</div>
</km-combobox>

<km-chip-list label="Tags"
[tags]="tags"
(onChange)="onTagValuesChange($event)"
[formControlName]="Controls.Tags"
[disabled]="form.get(Controls.Tags).disabled"
placeholder="Add tags..."
[kmPattern]="tagValuesPattern"
[kmPatternError]="tagValuesPatternError"
[kmRequired]="!!form.get(Controls.TagCategory).value"
fxFlex />
<km-chip-autocomplete [formControlName]="Controls.Tags"
Copy link
Contributor

Choose a reason for hiding this comment

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

2 Questions:

I think this is the first time in codebase we are using this custom element i can't find any other usages in other parts of codebase. Just Curios (seem little outdated) I guess

Copy link
Contributor

Choose a reason for hiding this comment

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

Q2:
Compare to dev -> km-chip-list shows validations as we are passing

    [kmPattern]="tagValuesPattern"
    [kmPatternError]="tagValuesPatternError"

therefor i can see in dev validations works for cluster tags

Image

With km-chip-autocomplete (Validations I guess missing) in component itself. Which IMO, we need to restrict user to provide any invalid tags.

Image

label="Tags"
placeholder="Add tags..."
[disabled]="form.get(Controls.Tags).disabled"
[required]="!!form.get(Controls.TagCategory).value"
[patternError]="tagValuesPatternError"
[pattern]="tagValuesPattern"
[tags]="predefinedTagList"
(onChange)="onTagValuesChange($event)" />
</form>