Prometheus: Fixes crash in the new options component when range was undefined (#45921)
* Prometheus: Fixes crash in the new options component when range was undefined * Simplified conditions
This commit is contained in:
+7
-1
@@ -59,13 +59,19 @@ describe('PromQueryBuilderOptions', () => {
|
||||
legendFormat: '{{label_name}}',
|
||||
});
|
||||
});
|
||||
|
||||
it('Handle defaults with undefined range', async () => {
|
||||
setup(getQueryWithDefaults({ refId: 'A', expr: '', range: undefined, instant: true }, CoreApp.Dashboard));
|
||||
|
||||
expect(screen.getByText('Type: Instant')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
function setup(queryOverrides: Partial<PromQuery> = {}) {
|
||||
const props = {
|
||||
query: {
|
||||
...getQueryWithDefaults({ refId: 'A' } as PromQuery, CoreApp.PanelEditor),
|
||||
queryOverrides,
|
||||
...queryOverrides,
|
||||
},
|
||||
onRunQuery: jest.fn(),
|
||||
onChange: jest.fn(),
|
||||
|
||||
@@ -131,14 +131,14 @@ export function getQueryWithDefaults(query: PromQuery, app: CoreApp | undefined)
|
||||
result = { ...result, expr: '', legendFormat: LegendFormatMode.Auto };
|
||||
}
|
||||
|
||||
// Default to range query
|
||||
if (query.range == null) {
|
||||
if (query.range == null && query.instant == null) {
|
||||
// Default to range query
|
||||
result = { ...result, range: true };
|
||||
}
|
||||
|
||||
// In explore we default to both instant & range
|
||||
if (query.instant == null && app === CoreApp.Explore) {
|
||||
result = { ...result, instant: true };
|
||||
// In explore we default to both instant & range
|
||||
if (app === CoreApp.Explore) {
|
||||
result.instant = true;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user