Loki, Prometheus: Show Query patterns in all editor modes (#50263)

This commit is contained in:
Ivana Huckova 2022-06-13 09:45:01 +02:00 committed by GitHub
parent 8fd9cb4854
commit 088a1880d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 40 deletions

View File

@ -79,25 +79,21 @@ export const LokiQueryEditorSelector = React.memo<LokiQueryEditorProps>((props)
onDismiss={() => setParseModalOpen(false)}
/>
<EditorHeader>
{editorMode === QueryEditorMode.Builder && (
<>
<InlineSelect
value={null}
placeholder="Query patterns"
allowCustomValue
onChange={({ value }) => {
const result = buildVisualQueryFromString(query.expr || '');
result.query.operations = value?.operations!;
onChange({
...query,
expr: lokiQueryModeller.renderQuery(result.query),
});
}}
options={lokiQueryModeller.getQueryPatterns().map((x) => ({ label: x.name, value: x }))}
/>
<QueryHeaderSwitch label="Raw query" value={rawQuery} onChange={onQueryPreviewChange} />
</>
)}
<InlineSelect
value={null}
placeholder="Query patterns"
allowCustomValue
onChange={({ value }) => {
const result = buildVisualQueryFromString(query.expr || '');
result.query.operations = value?.operations!;
onChange({
...query,
expr: lokiQueryModeller.renderQuery(result.query),
});
}}
options={lokiQueryModeller.getQueryPatterns().map((x) => ({ label: x.name, value: x }))}
/>
<QueryHeaderSwitch label="Raw query" value={rawQuery} onChange={onQueryPreviewChange} />
<FlexItem grow={1} />
{app !== CoreApp.Explore && (
<Button

View File

@ -82,27 +82,23 @@ export const PromQueryEditorSelector = React.memo<Props>((props) => {
onDismiss={() => setParseModalOpen(false)}
/>
<EditorHeader>
{editorMode === QueryEditorMode.Builder && (
<>
<InlineSelect
value={null}
placeholder="Query patterns"
allowCustomValue
onChange={({ value }) => {
// TODO: Bit convoluted as we don't have access to visualQuery model here. Maybe would make sense to
// move it inside the editor?
const result = buildVisualQueryFromString(query.expr || '');
result.query.operations = value?.operations!;
onChange({
...query,
expr: promQueryModeller.renderQuery(result.query),
});
}}
options={promQueryModeller.getQueryPatterns().map((x) => ({ label: x.name, value: x }))}
/>
<QueryHeaderSwitch label="Raw query" value={rawQuery} onChange={onQueryPreviewChange} />
</>
)}
<InlineSelect
value={null}
placeholder="Query patterns"
allowCustomValue
onChange={({ value }) => {
// TODO: Bit convoluted as we don't have access to visualQuery model here. Maybe would make sense to
// move it inside the editor?
const result = buildVisualQueryFromString(query.expr || '');
result.query.operations = value?.operations!;
onChange({
...query,
expr: promQueryModeller.renderQuery(result.query),
});
}}
options={promQueryModeller.getQueryPatterns().map((x) => ({ label: x.name, value: x }))}
/>
<QueryHeaderSwitch label="Raw query" value={rawQuery} onChange={onQueryPreviewChange} />
{editorMode === QueryEditorMode.Builder && (
<FeedbackLink feedbackUrl="https://github.com/grafana/grafana/discussions/47693" />
)}