Prevent self-referencing locations and items as parents (#773)

* prevent current location and descendants from being selected as parent

* prevent an item from showing up in the parent items drop-down for itself

* pass location object to filter function to allow for more flexible filtering

* align exclude prop and fix type comparison, change item filter to array of ItemsObjects to allow for descendant filtering in future

* fix linting prop reference
This commit is contained in:
Nikolai Oakfield
2025-06-28 18:58:46 -04:00
committed by GitHub
parent c1c8eb649c
commit c9d055fe03
5 changed files with 45 additions and 10 deletions

View File

@@ -65,6 +65,7 @@
searchPlaceholder?: string;
noResultsText?: string;
placeholder?: string;
excludeItems?: ItemsObject[];
}
const emit = defineEmits(["update:modelValue", "update:search"]);
@@ -78,6 +79,7 @@
searchPlaceholder: undefined,
noResultsText: undefined,
placeholder: undefined,
excludeItems: undefined,
});
const id = useId();
@@ -137,12 +139,19 @@
}
const filtered = computed(() => {
if (!search.value) return props.items;
if (isStrings(props.items)) {
return props.items.filter(item => item.toLowerCase().includes(search.value.toLowerCase()));
let baseItems = props.items;
if (!isStrings(baseItems) && props.excludeItems) {
const excludeIds = props.excludeItems.map(i => i.id);
baseItems = baseItems.filter(item => !excludeIds?.includes(item.id));
}
if (!search.value) return baseItems;
if (isStrings(baseItems)) {
return baseItems.filter(item => item.toLowerCase().includes(search.value.toLowerCase()));
} else {
// Fuzzy search on itemText
return fuzzysort.go(search.value, props.items, { key: props.itemText, all: true }).map(i => i.obj);
return fuzzysort.go(search.value, baseItems, { key: props.itemText, all: true }).map(i => i.obj);
}
});
</script>