import './QuerySection.styles.scss'; import { Button, Tabs, Tooltip } from 'antd'; import { ALERTS_DATA_SOURCE_MAP } from 'constants/alerts'; import { PANEL_TYPES } from 'constants/queryBuilder'; import { QBShortcuts } from 'constants/shortcuts/QBShortcuts'; import { QueryBuilder } from 'container/QueryBuilder'; import { useKeyboardHotkeys } from 'hooks/hotkeys/useKeyboardHotkeys'; import { Atom, Play, Terminal } from 'lucide-react'; import { useEffect, useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { useSelector } from 'react-redux'; import { AppState } from 'store/reducers'; import { AlertTypes } from 'types/api/alerts/alertTypes'; import { AlertDef } from 'types/api/alerts/def'; import { EQueryType } from 'types/common/dashboard'; import AppReducer from 'types/reducer/app'; import ChQuerySection from './ChQuerySection'; import PromqlSection from './PromqlSection'; import { FormContainer, StepHeading } from './styles'; function QuerySection({ queryCategory, setQueryCategory, alertType, runQuery, alertDef, panelType, }: QuerySectionProps): JSX.Element { // init namespace for translations const { t } = useTranslation('alerts'); const [currentTab, setCurrentTab] = useState(queryCategory); const { featureResponse } = useSelector( (state) => state.app, ); const handleQueryCategoryChange = (queryType: string): void => { featureResponse.refetch().then(() => { setQueryCategory(queryType as EQueryType); }); setCurrentTab(queryType as EQueryType); }; const renderPromqlUI = (): JSX.Element => ; const renderChQueryUI = (): JSX.Element => ; const renderMetricUI = (): JSX.Element => ( ); const tabs = [ { label: ( ), key: EQueryType.QUERY_BUILDER, }, { label: ( ), key: EQueryType.CLICKHOUSE, }, ]; const items = useMemo( () => [ { label: ( ), key: EQueryType.QUERY_BUILDER, }, { label: ( ), key: EQueryType.CLICKHOUSE, }, { label: ( ), key: EQueryType.PROM, }, ], [], ); const { registerShortcut, deregisterShortcut } = useKeyboardHotkeys(); useEffect(() => { registerShortcut(QBShortcuts.StageAndRunQuery, runQuery); return (): void => { deregisterShortcut(QBShortcuts.StageAndRunQuery); }; // eslint-disable-next-line react-hooks/exhaustive-deps }, [runQuery]); const renderTabs = (typ: AlertTypes): JSX.Element | null => { switch (typ) { case AlertTypes.TRACES_BASED_ALERT: case AlertTypes.LOGS_BASED_ALERT: case AlertTypes.EXCEPTIONS_BASED_ALERT: return (
} items={tabs} />
); case AlertTypes.METRICS_BASED_ALERT: default: return (
} items={items} />
); } }; const renderQuerySection = (c: EQueryType): JSX.Element | null => { switch (c) { case EQueryType.PROM: return renderPromqlUI(); case EQueryType.CLICKHOUSE: return renderChQueryUI(); case EQueryType.QUERY_BUILDER: return renderMetricUI(); default: return null; } }; return ( <> {t('alert_form_step1')}
{renderTabs(alertType)}
{renderQuerySection(currentTab)}
); } interface QuerySectionProps { queryCategory: EQueryType; setQueryCategory: (n: EQueryType) => void; alertType: AlertTypes; runQuery: VoidFunction; alertDef: AlertDef; panelType: PANEL_TYPES; } export default QuerySection;