mirror of
https://github.com/sysadminsmedia/homebox.git
synced 2025-12-26 23:21:39 +01:00
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:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user