mirror of
https://github.com/openobserve/openobserve.git
synced 2026-11-05 08:09:22 +00:00
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
31 lines
871 B
TypeScript
31 lines
871 B
TypeScript
import { ref, watch, type Ref } from "vue";
|
|
|
|
export const useSelectAutoComplete = (options: Ref<any>, searchKey: string) => {
|
|
const filteredOptions = ref(options.value);
|
|
|
|
watch(options, () => {
|
|
filteredOptions.value = options.value;
|
|
});
|
|
|
|
const filterFn = (val: any, update: any) => {
|
|
if (val === "") {
|
|
update(() => {
|
|
filteredOptions.value = options.value;
|
|
});
|
|
return;
|
|
}
|
|
|
|
update(() => {
|
|
const needle = val.toLowerCase();
|
|
filteredOptions.value = options.value?.filter((option: any) => {
|
|
const value = typeof option === "object" ? option[searchKey] : option.toString();
|
|
const lowerCaseValue = value.toLowerCase();
|
|
const lowerCaseNeedle = needle.toLowerCase();
|
|
return lowerCaseValue.indexOf(lowerCaseNeedle) > -1;
|
|
});
|
|
});
|
|
};
|
|
|
|
return { filteredOptions, filterFn };
|
|
};
|