Shaheer Kochai f1ce82ac25
feat: client side query builder search (#5891)
* feat: build client side QB search

* feat: query builder light mode support + overall UI improvements

* fix: preserve the alert rule labels in context

* feat: get labels and all possible values from /timeline API

* chore: remove unnecessary dropdownRender and optional fields from AttributeKey

* chore: merge the styles of .tag

* chore: use the correct type for attributeKeys

* chore: use the correct values for alert rule state in the context
2024-10-09 09:29:44 +04:30

45 lines
982 B
TypeScript

import React, { createContext, useContext, useState } from 'react';
interface AlertRuleContextType {
alertRuleState: string | undefined;
setAlertRuleState: React.Dispatch<React.SetStateAction<string | undefined>>;
}
const AlertRuleContext = createContext<AlertRuleContextType | undefined>(
undefined,
);
function AlertRuleProvider({
children,
}: {
children: React.ReactNode;
}): JSX.Element {
const [alertRuleState, setAlertRuleState] = useState<string | undefined>(
undefined,
);
const value = React.useMemo(
() => ({
alertRuleState,
setAlertRuleState,
}),
[alertRuleState],
);
return (
<AlertRuleContext.Provider value={value}>
{children}
</AlertRuleContext.Provider>
);
}
export const useAlertRule = (): AlertRuleContextType => {
const context = useContext(AlertRuleContext);
if (context === undefined) {
throw new Error('useAlertRule must be used within an AlertRuleProvider');
}
return context;
};
export default AlertRuleProvider;