mirror of https://github.com/grafana/grafana
Feature toggle to add filter and group by variables to all new dashboards by default (#85531)
* Add feature toggle * Add filters and group by variables by default to all new dashboards * Nits * Tests * Rename feature toggle to newDashboardWithFiltersAndGroupBypull/85590/head
parent
4e60f44d98
commit
32b6ef9d15
|
@ -0,0 +1,76 @@ |
||||
import { DataSourceApi, PluginType, VariableSupportType } from '@grafana/data'; |
||||
import { config } from '@grafana/runtime'; |
||||
|
||||
import { buildNewDashboardSaveModel } from './buildNewDashboardSaveModel'; |
||||
|
||||
const fakeDsMock: DataSourceApi = { |
||||
name: 'fake-std', |
||||
type: 'fake-std', |
||||
getRef: () => ({ type: 'fake-std', uid: 'fake-std' }), |
||||
query: () => |
||||
Promise.resolve({ |
||||
data: [], |
||||
}), |
||||
testDatasource: () => Promise.resolve({ status: 'success', message: 'abc' }), |
||||
meta: { |
||||
id: 'fake-std', |
||||
type: PluginType.datasource, |
||||
module: 'fake-std', |
||||
baseUrl: '', |
||||
name: 'fake-std', |
||||
info: { |
||||
author: { name: '' }, |
||||
description: '', |
||||
links: [], |
||||
logos: { large: '', small: '' }, |
||||
updated: '', |
||||
version: '', |
||||
screenshots: [], |
||||
}, |
||||
}, |
||||
// Standard variable support
|
||||
variables: { |
||||
getType: () => VariableSupportType.Standard, |
||||
toDataQuery: (q) => ({ ...q, refId: 'FakeDataSource-refId' }), |
||||
}, |
||||
getTagKeys: jest.fn(), |
||||
id: 1, |
||||
uid: 'fake-std', |
||||
}; |
||||
|
||||
jest.mock('@grafana/runtime', () => ({ |
||||
...jest.requireActual('@grafana/runtime'), |
||||
config: { |
||||
featureToggles: { |
||||
newDashboardWithFiltersAndGroupBy: false, |
||||
}, |
||||
}, |
||||
getDataSourceSrv: () => ({ |
||||
get: (): Promise<DataSourceApi> => { |
||||
return Promise.resolve(fakeDsMock); |
||||
}, |
||||
}), |
||||
})); |
||||
|
||||
describe('buildNewDashboardSaveModel', () => { |
||||
it('should not have template variables defined by default', async () => { |
||||
const result = await buildNewDashboardSaveModel(); |
||||
expect(result.dashboard.templating).toBeUndefined(); |
||||
}); |
||||
|
||||
describe('when featureToggles.newDashboardWithFiltersAndGroupBy is true', () => { |
||||
beforeAll(() => { |
||||
config.featureToggles.newDashboardWithFiltersAndGroupBy = true; |
||||
}); |
||||
afterAll(() => { |
||||
config.featureToggles.newDashboardWithFiltersAndGroupBy = false; |
||||
}); |
||||
|
||||
it('should add filter and group by variables if the datasource supports it and is set as default', async () => { |
||||
const result = await buildNewDashboardSaveModel(); |
||||
expect(result.dashboard.templating?.list).toHaveLength(2); |
||||
expect(result.dashboard.templating?.list?.[0].type).toBe('adhoc'); |
||||
expect(result.dashboard.templating?.list?.[1].type).toBe('groupby'); |
||||
}); |
||||
}); |
||||
}); |
||||
Loading…
Reference in new issue