Files
openobserve/web/src/composables/useSearchInputUsingRegex.ts
T
ktx-vaidehi ab891e1d35 fix: dashboard filter option value format and added more operators in variables settings filter (#3676)
<!-- 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 -->
2024-06-06 17:59:02 +05:30

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 };
};