|
|
|
@ -72,6 +72,7 @@ export class GfTagsSelectorComponent |
|
|
|
); |
|
|
|
public readonly separatorKeysCodes: number[] = [COMMA, ENTER]; |
|
|
|
public readonly tagInputControl = new FormControl(''); |
|
|
|
public readonly tagNameToCreate = signal<string | null>(null); |
|
|
|
public readonly tagsSelected = signal<SelectedTag[]>([]); |
|
|
|
|
|
|
|
private readonly tagInput = |
|
|
|
@ -80,8 +81,8 @@ export class GfTagsSelectorComponent |
|
|
|
public constructor() { |
|
|
|
this.tagInputControl.valueChanges |
|
|
|
.pipe(takeUntilDestroyed()) |
|
|
|
.subscribe((value) => { |
|
|
|
this.filteredOptions.next(this.filterTags(value ?? '')); |
|
|
|
.subscribe(() => { |
|
|
|
this.updateFilters(); |
|
|
|
}); |
|
|
|
|
|
|
|
addIcons({ addCircleOutline, closeOutline }); |
|
|
|
@ -161,9 +162,8 @@ export class GfTagsSelectorComponent |
|
|
|
this.updateFilters(); |
|
|
|
} |
|
|
|
|
|
|
|
private filterTags(query: string = ''): SelectedTag[] { |
|
|
|
const tags = this.tagsSelected() ?? []; |
|
|
|
const tagIds = [...tags, ...(this.tagsReadOnly ?? [])].map(({ id }) => { |
|
|
|
private filterTags(query: string): SelectedTag[] { |
|
|
|
const tagIds = this.getTagsSelectedAndReadOnly().map(({ id }) => { |
|
|
|
return id; |
|
|
|
}); |
|
|
|
|
|
|
|
@ -179,6 +179,27 @@ export class GfTagsSelectorComponent |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private getTagNameToCreate(query: string): string | null { |
|
|
|
const name = query.trim(); |
|
|
|
|
|
|
|
if (!name) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
const isExistingTagName = [ |
|
|
|
...(this.tagsAvailable ?? []), |
|
|
|
...this.getTagsSelectedAndReadOnly() |
|
|
|
].some((tag) => { |
|
|
|
return tag.name.toLowerCase() === name.toLowerCase(); |
|
|
|
}); |
|
|
|
|
|
|
|
return isExistingTagName ? null : name; |
|
|
|
} |
|
|
|
|
|
|
|
private getTagsSelectedAndReadOnly(): SelectedTag[] { |
|
|
|
return [...this.tagsSelected(), ...(this.tagsReadOnly ?? [])]; |
|
|
|
} |
|
|
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
private onChange = (_value: SelectedTag[]): void => { |
|
|
|
// ControlValueAccessor onChange callback
|
|
|
|
@ -189,6 +210,9 @@ export class GfTagsSelectorComponent |
|
|
|
}; |
|
|
|
|
|
|
|
private updateFilters() { |
|
|
|
this.filteredOptions.next(this.filterTags()); |
|
|
|
const query = this.tagInputControl.value ?? ''; |
|
|
|
|
|
|
|
this.filteredOptions.next(this.filterTags(query)); |
|
|
|
this.tagNameToCreate.set(this.getTagNameToCreate(query)); |
|
|
|
} |
|
|
|
} |
|
|
|
|