mirror of
https://github.com/openobserve/openobserve.git
synced 2026-11-05 16:10:43 +00:00
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Expanded filter operator options in settings to include '>=', '<=', '>', '<', 'Contains', 'Not Contains', 'Is Null', and 'Is Not Null'. - **Enhancements** - Improved filtering logic in search functionality to handle options using regular expressions. - Adjusted the width of scrollable containers in dashboard settings for better content display. - **Refactor** - Updated internal handling of filter items in various dashboard components to improve performance and maintainability. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
import { ref, watch, type Ref } from "vue";
|
|
|
|
export const useSearchInputUsingRegex = (
|
|
options: Ref<any>,
|
|
searchKey: string,
|
|
searchRegex: string
|
|
) => {
|
|
const filteredOptions = ref([...options.value]);
|
|
|
|
watch(options, (newValue) => {
|
|
if (!filteredOptions.value.length) {
|
|
filteredOptions.value = [...newValue];
|
|
}
|
|
});
|
|
|
|
const filterFn = (val: any) => {
|
|
if (val === "") {
|
|
filteredOptions.value = [...options.value];
|
|
return;
|
|
}
|
|
|
|
const regex = new RegExp(searchRegex, "gi");
|
|
let match = regex.exec(val)
|
|
|
|
if(!match) {
|
|
filteredOptions.value = [];
|
|
return;
|
|
}
|
|
|
|
let needle: any = null;
|
|
for (let i = 1; i < match.length; i++) {
|
|
if (match[i] !== undefined) {
|
|
needle = match[i];
|
|
break;
|
|
}
|
|
}
|
|
|
|
filteredOptions.value = options.value?.filter((option: any) => {
|
|
const value =
|
|
typeof option === "object" ? option[searchKey] : option.toString();
|
|
const lowerCaseValue = value.toLowerCase();
|
|
return lowerCaseValue.includes(needle);
|
|
});
|
|
};
|
|
|
|
return { filteredOptions, filterFn };
|
|
};
|