mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* refactor header * split left and right header actions * cleanup * fix broken tests * move MetricsQueryEditor tests to QueryEditor tests * fix mock imports * remove no longer used onRunQuery func * move run queries button * apply defaults also when changing query type * remove not used prop
56 lines
1.8 KiB
TypeScript
56 lines
1.8 KiB
TypeScript
import React, { useCallback, useEffect, useState } from 'react';
|
|
|
|
import { QueryEditorProps } from '@grafana/data';
|
|
|
|
import { CloudWatchDatasource } from '../datasource';
|
|
import { isCloudWatchLogsQuery, isCloudWatchMetricsQuery } from '../guards';
|
|
import { CloudWatchJsonData, CloudWatchQuery } from '../types';
|
|
|
|
import LogsQueryEditor from './LogsQueryEditor';
|
|
import { MetricsQueryEditor } from './MetricsQueryEditor/MetricsQueryEditor';
|
|
import QueryHeader from './QueryHeader';
|
|
|
|
export type Props = QueryEditorProps<CloudWatchDatasource, CloudWatchQuery, CloudWatchJsonData>;
|
|
|
|
export const QueryEditor = (props: Props) => {
|
|
const { query, onChange, data } = props;
|
|
const [dataIsStale, setDataIsStale] = useState(false);
|
|
const [extraHeaderElementLeft, setExtraHeaderElementLeft] = useState<JSX.Element>();
|
|
const [extraHeaderElementRight, setExtraHeaderElementRight] = useState<JSX.Element>();
|
|
|
|
useEffect(() => {
|
|
setDataIsStale(false);
|
|
}, [data]);
|
|
|
|
const onChangeInternal = useCallback(
|
|
(query: CloudWatchQuery) => {
|
|
setDataIsStale(true);
|
|
onChange(query);
|
|
},
|
|
[onChange]
|
|
);
|
|
|
|
return (
|
|
<>
|
|
<QueryHeader
|
|
{...props}
|
|
extraHeaderElementLeft={extraHeaderElementLeft}
|
|
extraHeaderElementRight={extraHeaderElementRight}
|
|
dataIsStale={dataIsStale}
|
|
/>
|
|
|
|
{isCloudWatchMetricsQuery(query) && (
|
|
<MetricsQueryEditor
|
|
{...props}
|
|
query={query}
|
|
onRunQuery={() => {}}
|
|
onChange={onChangeInternal}
|
|
extraHeaderElementLeft={setExtraHeaderElementLeft}
|
|
extraHeaderElementRight={setExtraHeaderElementRight}
|
|
/>
|
|
)}
|
|
{isCloudWatchLogsQuery(query) && <LogsQueryEditor {...props} query={query} onChange={onChangeInternal} />}
|
|
</>
|
|
);
|
|
};
|