fix tag delete, todo on repository, removed console logs

This commit is contained in:
Lone Iversen
2023-05-08 16:16:07 +02:00
parent 6bfb660d3f
commit 7c99ba3784
3 changed files with 19 additions and 17 deletions

View File

@@ -19,7 +19,8 @@ export class UmbTagsInputElement extends FormControlMixin(UmbLitElement) {
_items: string[] = [];
@property({ type: Array })
public set items(newTags: string[]) {
this._items = newTags;
const newItems = newTags.filter((x) => x !== '');
this._items = newItems;
super.value = this._items.join(',');
}
public get items(): string[] {
@@ -55,7 +56,7 @@ export class UmbTagsInputElement extends FormControlMixin(UmbLitElement) {
}
async #getExistingTags(query: string) {
if (!this.group || this.culture === undefined) return;
if (!this.group || this.culture === undefined || !query) return;
const { data } = await this.#repository.queryTags(this.group, this.culture, query);
if (!data) return;
this._matches = data.items;
@@ -83,8 +84,11 @@ export class UmbTagsInputElement extends FormControlMixin(UmbLitElement) {
#onInput(e: UUIInputEvent) {
this._currentInput = e.target.value as string;
if (!this._currentInput.length) this._matches = [];
else this.#getExistingTags(this._currentInput);
if (!this._currentInput || !this._currentInput.length) {
this._matches = [];
} else {
this.#getExistingTags(this._currentInput);
}
}
protected updated(): void {
@@ -96,10 +100,7 @@ export class UmbTagsInputElement extends FormControlMixin(UmbLitElement) {
else this.#createTag();
}
#createTag(text?: string) {
if (text) {
this._tagInput.value = text;
}
#createTag() {
this.#inputError(false);
const newTag = (this._tagInput.value as string).trim();
if (!newTag) return;
@@ -125,11 +126,10 @@ export class UmbTagsInputElement extends FormControlMixin(UmbLitElement) {
}
#delete(tag: string) {
this.items.splice(
this.items.findIndex((x) => x === tag),
1
);
this.items = [...this.items];
const currentItems = [...this.items];
const index = currentItems.findIndex((x) => x === tag);
currentItems.splice(index, 1);
currentItems.length ? (this.items = [...currentItems]) : (this.items = []);
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }));
}
@@ -216,7 +216,7 @@ export class UmbTagsInputElement extends FormControlMixin(UmbLitElement) {
return html`
<div id="matchlist">
${repeat(
matchfilter,
matchfilter.slice(0, 5),
(tag: TagResponseModel) => tag.id,
(tag: TagResponseModel, index: number) => {
return html` <input

View File

@@ -5,6 +5,5 @@ import { UmbEntrypointOnInit } from '@umbraco-cms/backoffice/extensions-api';
export const manifests = [...repositoryManifests];
export const onInit: UmbEntrypointOnInit = (host, extensionRegistry) => {
console.log('tags registrer');
extensionRegistry.registerMany(manifests);
};

View File

@@ -21,7 +21,6 @@ export class UmbTagStore extends UmbStoreBase {
*/
constructor(host: UmbControllerHostElement) {
super(host, UMB_TAG_STORE_CONTEXT_TOKEN.toString(), new UmbArrayState<TagResponseModel>([], (x) => x.id));
console.log('Store is open');
}
/**
@@ -48,7 +47,11 @@ export class UmbTagStore extends UmbStoreBase {
);
}
//TODO Skriv god kommentar til filter/exclude
// TODO
// There isnt really any way to exclude certain tags when searching for suggestions.
// This is important for the skip/take in the endpoint. We do not want to get the tags from database that we already have picked.
// Forexample: we have 10 different tags that includes "berry" (and searched for "berry") and we have a skip of 0 and take of 5.
// If we already has picked lets say 4 of them, the list will only show 1 more, even though there is more remaining in the database.
byQuery(group: TagResponseModel['group'], culture: string, query: string) {
return this._data.getObservablePart((items) =>