mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-29 16:14:42 +00:00
* 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
45 lines
982 B
TypeScript
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;
|