mirror of https://github.com/grafana/grafana.git
AzureMonitor: Create read-only React view for Insights Analytics (#33719)
* AzureMonitor: Create read-only React view for Insights Analytics * Fix spacing
This commit is contained in:
parent
e58aca2d20
commit
8333c55bee
|
|
@ -0,0 +1,49 @@
|
||||||
|
import { Alert, CodeEditor, Select } from '@grafana/ui';
|
||||||
|
import React from 'react';
|
||||||
|
import { AzureMonitorOption, AzureMonitorQuery, AzureResultFormat } from '../../types';
|
||||||
|
import { findOption } from '../../utils/common';
|
||||||
|
import { Field } from '../Field';
|
||||||
|
import { Space } from '../Space';
|
||||||
|
|
||||||
|
interface InsightsAnalyticsEditorProps {
|
||||||
|
query: AzureMonitorQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
const FORMAT_OPTIONS: Array<AzureMonitorOption<AzureResultFormat>> = [
|
||||||
|
{ label: 'Time series', value: 'time_series' },
|
||||||
|
{ label: 'Table', value: 'table' },
|
||||||
|
];
|
||||||
|
|
||||||
|
const InsightsAnalyticsEditor: React.FC<InsightsAnalyticsEditorProps> = ({ query }) => {
|
||||||
|
return (
|
||||||
|
<div data-testid="azure-monitor-insights-analytics-query-editor">
|
||||||
|
<CodeEditor
|
||||||
|
language="kusto"
|
||||||
|
value={query.insightsAnalytics.query}
|
||||||
|
height={200}
|
||||||
|
width="100%"
|
||||||
|
readOnly={true}
|
||||||
|
showMiniMap={false}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Field label="Format as">
|
||||||
|
<Select
|
||||||
|
inputId="azure-monitor-logs-workspaces-field"
|
||||||
|
value={findOption(FORMAT_OPTIONS, query.insightsAnalytics.resultFormat)}
|
||||||
|
disabled={true}
|
||||||
|
options={FORMAT_OPTIONS}
|
||||||
|
onChange={() => {}}
|
||||||
|
width={38}
|
||||||
|
/>
|
||||||
|
</Field>
|
||||||
|
|
||||||
|
<Space v={2} />
|
||||||
|
|
||||||
|
<Alert severity="info" title="Deprecated">
|
||||||
|
Insights Analytics is deprecated and is now read only. Migrate your queries to Logs to make changes.
|
||||||
|
</Alert>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default InsightsAnalyticsEditor;
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Alert, VerticalGroup } from '@grafana/ui';
|
import { Alert } from '@grafana/ui';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import Datasource from '../../datasource';
|
import Datasource from '../../datasource';
|
||||||
import { AzureMonitorQuery, AzureQueryType, AzureMonitorOption, AzureMonitorErrorish } from '../../types';
|
import { AzureMonitorQuery, AzureQueryType, AzureMonitorOption, AzureMonitorErrorish } from '../../types';
|
||||||
|
|
@ -7,6 +7,8 @@ import QueryTypeField from './QueryTypeField';
|
||||||
import useLastError from '../../utils/useLastError';
|
import useLastError from '../../utils/useLastError';
|
||||||
import LogsQueryEditor from '../LogsQueryEditor';
|
import LogsQueryEditor from '../LogsQueryEditor';
|
||||||
import ApplicationInsightsEditor from '../ApplicationInsightsEditor';
|
import ApplicationInsightsEditor from '../ApplicationInsightsEditor';
|
||||||
|
import InsightsAnalyticsEditor from '../InsightsAnalyticsEditor';
|
||||||
|
import { Space } from '../Space';
|
||||||
|
|
||||||
interface BaseQueryEditorProps {
|
interface BaseQueryEditorProps {
|
||||||
query: AzureMonitorQuery;
|
query: AzureMonitorQuery;
|
||||||
|
|
@ -27,22 +29,23 @@ const QueryEditor: React.FC<BaseQueryEditorProps> = ({ query, datasource, onChan
|
||||||
<div data-testid="azure-monitor-query-editor">
|
<div data-testid="azure-monitor-query-editor">
|
||||||
<QueryTypeField query={query} onQueryChange={onChange} />
|
<QueryTypeField query={query} onQueryChange={onChange} />
|
||||||
|
|
||||||
<VerticalGroup>
|
<EditorForQueryType
|
||||||
<EditorForQueryType
|
subscriptionId={subscriptionId}
|
||||||
subscriptionId={subscriptionId}
|
query={query}
|
||||||
query={query}
|
datasource={datasource}
|
||||||
datasource={datasource}
|
onChange={onChange}
|
||||||
onChange={onChange}
|
variableOptionGroup={variableOptionGroup}
|
||||||
variableOptionGroup={variableOptionGroup}
|
setError={setError}
|
||||||
setError={setError}
|
/>
|
||||||
/>
|
|
||||||
|
|
||||||
{errorMessage && (
|
{errorMessage && (
|
||||||
|
<>
|
||||||
|
<Space v={2} />
|
||||||
<Alert severity="error" title="An error occurred while requesting metadata from Azure Monitor">
|
<Alert severity="error" title="An error occurred while requesting metadata from Azure Monitor">
|
||||||
{errorMessage}
|
{errorMessage}
|
||||||
</Alert>
|
</Alert>
|
||||||
)}
|
</>
|
||||||
</VerticalGroup>
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
@ -87,6 +90,9 @@ const EditorForQueryType: React.FC<EditorForQueryTypeProps> = ({
|
||||||
|
|
||||||
case AzureQueryType.ApplicationInsights:
|
case AzureQueryType.ApplicationInsights:
|
||||||
return <ApplicationInsightsEditor query={query} />;
|
return <ApplicationInsightsEditor query={query} />;
|
||||||
|
|
||||||
|
case AzureQueryType.InsightsAnalytics:
|
||||||
|
return <InsightsAnalyticsEditor query={query} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
import React from 'react';
|
||||||
|
import { css, cx } from '@emotion/css';
|
||||||
|
import { GrafanaTheme2 } from '@grafana/data';
|
||||||
|
import { stylesFactory, useTheme2 } from '@grafana/ui';
|
||||||
|
|
||||||
|
export interface SpaceProps {
|
||||||
|
v?: number;
|
||||||
|
h?: number;
|
||||||
|
layout?: 'block' | 'inline';
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Space = (props: SpaceProps) => {
|
||||||
|
const theme = useTheme2();
|
||||||
|
const styles = getStyles(theme, props);
|
||||||
|
|
||||||
|
return <span className={cx(styles.wrapper)} />;
|
||||||
|
};
|
||||||
|
|
||||||
|
Space.defaultProps = {
|
||||||
|
v: 0,
|
||||||
|
h: 0,
|
||||||
|
layout: 'block',
|
||||||
|
};
|
||||||
|
|
||||||
|
const getStyles = stylesFactory((theme: GrafanaTheme2, props: SpaceProps) => ({
|
||||||
|
wrapper: css([
|
||||||
|
{
|
||||||
|
paddingRight: theme.spacing(props.h ?? 0),
|
||||||
|
paddingBottom: theme.spacing(props.v ?? 0),
|
||||||
|
},
|
||||||
|
props.layout === 'inline' && {
|
||||||
|
display: 'inline-block',
|
||||||
|
},
|
||||||
|
props.layout === 'block' && {
|
||||||
|
display: 'block',
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
}));
|
||||||
|
|
@ -30,7 +30,12 @@ export class AzureMonitorQueryCtrl extends QueryCtrl {
|
||||||
];
|
];
|
||||||
|
|
||||||
// Query types that have been migrated to React
|
// Query types that have been migrated to React
|
||||||
reactQueryEditors = [AzureQueryType.AzureMonitor, AzureQueryType.LogAnalytics, AzureQueryType.ApplicationInsights];
|
reactQueryEditors = [
|
||||||
|
AzureQueryType.AzureMonitor,
|
||||||
|
AzureQueryType.LogAnalytics,
|
||||||
|
AzureQueryType.ApplicationInsights,
|
||||||
|
AzureQueryType.InsightsAnalytics,
|
||||||
|
];
|
||||||
|
|
||||||
// target: AzureMonitorQuery;
|
// target: AzureMonitorQuery;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue