Skip to content

Commit 9c80f59

Browse files
authored
Fix: Config editor crash when global query added (#1330)
1 parent eaafcc8 commit 9c80f59

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'grafana-infinity-datasource': patch
3+
---
4+
5+
Fix: Config editor crash when global query added

src/components/SourceSelector.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@ export const SourceSelector = (props: { query: InfinityQuery; onChange: (e: Infi
1616
};
1717
return (
1818
<EditorField label={query.type === 'series' ? 'Scenario' : 'Source'} horizontal={true}>
19-
<Select width={18} options={supportedSources} value={query.source || 'url'} onChange={(e) => onSourceChange(e.value as InfinityQuerySources)} menuShouldPortal={true}></Select>
19+
<Select
20+
width={18}
21+
data-testid="infinity-query-source-selector"
22+
options={supportedSources}
23+
value={query.source || 'url'}
24+
onChange={(e) => onSourceChange(e.value as InfinityQuerySources)}
25+
menuShouldPortal={true}
26+
></Select>
2027
</EditorField>
2128
);
2229
};

src/editors/config.editor.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ export const InfinityConfigEditor = (props: DataSourcePluginOptionsEditorProps<I
219219
tabIndex={tabIndex + 1}
220220
className={activeTab === tab.value ? styles.tab_active : styles.tab}
221221
onClick={() => setActiveTab(tab.value)}
222+
role="button"
222223
onKeyDown={(e) => {
223224
if (e.key === ' ' || e.key === 'Enter') {
224225
setActiveTab(tab.value);

src/editors/config/GlobalQueryEditor.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import { Datasource } from '@/datasource';
2+
import { InfinityQueryEditor } from '@/editors/query/infinityQuery';
3+
import type { GlobalInfinityQuery, InfinityOptions, InfinityQuery } from '@/types';
14
import { DataSourcePluginOptionsEditorProps, DataSourceSettings } from '@grafana/data';
5+
import { getDataSourceSrv } from '@grafana/runtime';
26
import { Button, Drawer, InlineFormLabel, Input, Stack } from '@grafana/ui';
37
import React, { useState } from 'react';
4-
import { InfinityQueryEditor } from '@/editors/query/infinityQuery';
5-
import { Datasource } from '@/datasource';
6-
import type { GlobalInfinityQuery, InfinityOptions, InfinityQuery } from '@/types';
8+
import { useAsync } from 'react-use';
79

810
const DefaultGlobalQuery: InfinityQuery = {
911
refId: '',
@@ -106,6 +108,7 @@ const GlobalQuery = (props: { query: GlobalInfinityQuery; onUpdate: (query: Glob
106108
const [id, setId] = useState(query.id || '');
107109
const [name, setName] = useState(query.name || '');
108110
const [popupState, setPopupState] = useState(false);
111+
const datasource = useAsync(async () => await getDataSourceSrv().get(options.name));
109112
return (
110113
<>
111114
<Button
@@ -148,7 +151,7 @@ const GlobalQuery = (props: { query: GlobalInfinityQuery; onUpdate: (query: Glob
148151
onRunQuery={() => {}}
149152
instanceSettings={options}
150153
mode="global"
151-
datasource={{} as Datasource}
154+
datasource={datasource.value as Datasource}
152155
/>
153156
<Button variant="primary" onClick={() => setPopupState(false)}>
154157
Update

tests/e2e/configeditor.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { test, expect } from '@grafana/plugin-e2e';
2+
3+
test('Config editor: should be able to add a global query', async ({ createDataSourceConfigPage, page }) => {
4+
await createDataSourceConfigPage({ type: 'yesoreyeram-infinity-datasource' });
5+
await page.getByRole('button', { name: 'Global queries' }).click();
6+
await page.getByRole('button', { name: 'Add Global Query' }).click();
7+
await page.getByRole('button', { name: 'Edit' }).click();
8+
9+
await page.getByTestId('infinity-query-source-selector').click();
10+
const select = page.getByLabel('Select options menu');
11+
await select.locator(page.getByText('Reference')).click();
12+
13+
expect(await page.getByTestId('infinity-query-field-label-reference')).toBeVisible();
14+
});

0 commit comments

Comments
 (0)