Skip to content

Commit 158528b

Browse files
authored
Fix adding new data source and minor updates (#68)
1 parent 7e7167f commit 158528b

File tree

5 files changed

+24
-31
lines changed

5 files changed

+24
-31
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
- "Available Requirements" panel should be set to $redis datasource #63
88
- Cannot read property 'v1' of undefined (theme.v1) in the Grafana8 #65
9-
- Upgrade to Grafana 8.0.2
9+
- Upgrade to Grafana 8.0.2 (#67)
1010

1111
## 1.2.0 (2021-05-11)
1212

src/components/data-source-list/data-source-list.test.tsx

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import React from 'react';
21
import { shallow, ShallowWrapper } from 'enzyme';
32
import {
43
HighAvailability,
@@ -12,7 +11,8 @@ import {
1211
RedisJSON,
1312
RedisTimeSeries,
1413
} from 'icons';
15-
import { InfoBox } from '@grafana/ui';
14+
import React from 'react';
15+
import { Alert } from '@grafana/ui';
1616
import { DataSourceType, RedisCommand } from '../../constants';
1717
import { DataSourceList } from './data-source-list';
1818

@@ -22,13 +22,11 @@ const backendSrvMock = {
2222
post: jest.fn(),
2323
};
2424

25-
const locationSrvMock = {
26-
update: jest.fn(),
27-
};
28-
2925
jest.mock('@grafana/runtime', () => ({
3026
getBackendSrv: () => backendSrvMock,
31-
getLocationSrv: () => locationSrvMock,
27+
locationService: {
28+
push: () => jest.fn(),
29+
},
3230
}));
3331

3432
/**
@@ -46,12 +44,11 @@ describe('DataSourceList', () => {
4644

4745
beforeEach(() => {
4846
Object.values(backendSrvMock).forEach((mock) => mock.mockClear());
49-
Object.values(locationSrvMock).forEach((mock) => mock.mockClear());
5047
});
5148

5249
it('If datasources.length=0 should show no items message', () => {
5350
const wrapper = shallow(<DataSourceList dataSources={[]} />);
54-
const testedComponent = wrapper.findWhere((node) => node.is(InfoBox));
51+
const testedComponent = wrapper.findWhere((node) => node.is(Alert));
5552
expect(testedComponent.exists()).toBeTruthy();
5653
});
5754

@@ -365,15 +362,14 @@ describe('DataSourceList', () => {
365362
const addDataSourceButton = wrapper.findWhere(
366363
(node) => node.name() === 'Button' && node.text() === 'Add Redis Data Source'
367364
);
368-
backendSrvMock.post.mockImplementationOnce(() => Promise.resolve({ id: 123 }));
365+
backendSrvMock.post.mockImplementationOnce(() => Promise.resolve({ datasource: { uid: 123 } }));
369366
addDataSourceButton.simulate('click');
370367
setImmediate(() => {
371368
expect(backendSrvMock.post).toHaveBeenCalledWith('/api/datasources', {
372369
name: 'Redis',
373370
type: DataSourceType.REDIS,
374371
access: 'proxy',
375372
});
376-
expect(locationSrvMock.update).toHaveBeenCalledWith({ path: 'datasources/edit/123' });
377373
done();
378374
});
379375
});
@@ -397,15 +393,14 @@ describe('DataSourceList', () => {
397393
const addDataSourceButton = wrapper.findWhere(
398394
(node) => node.name() === 'Button' && node.text() === 'Add Redis Data Source'
399395
);
400-
backendSrvMock.post.mockImplementationOnce(() => Promise.resolve({ id: 1234 }));
396+
backendSrvMock.post.mockImplementationOnce(() => Promise.resolve({ datasource: { uid: 123 } }));
401397
addDataSourceButton.simulate('click');
402398
setImmediate(() => {
403399
expect(backendSrvMock.post).toHaveBeenCalledWith('/api/datasources', {
404400
name: 'Redis-2',
405401
type: DataSourceType.REDIS,
406402
access: 'proxy',
407403
});
408-
expect(locationSrvMock.update).toHaveBeenCalledWith({ path: 'datasources/edit/1234' });
409404
done();
410405
});
411406
});

src/components/data-source-list/data-source-list.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { FC, useCallback } from 'react';
2-
import { getBackendSrv, getLocationSrv } from '@grafana/runtime';
3-
import { Button, Container, HorizontalGroup, InfoBox, LinkButton, VerticalGroup } from '@grafana/ui';
2+
import { getBackendSrv, locationService } from '@grafana/runtime';
3+
import { Alert, Button, Container, HorizontalGroup, LinkButton, VerticalGroup } from '@grafana/ui';
44
import { DataSourceName, DataSourceType, RedisCommand } from '../../constants';
55
import {
66
HighAvailability,
@@ -58,10 +58,8 @@ export const DataSourceList: FC<Props> = ({ dataSources }) => {
5858
type: DataSourceType.REDIS,
5959
access: 'proxy',
6060
})
61-
.then(({ id }) => {
62-
getLocationSrv().update({
63-
path: `datasources/edit/${id}`,
64-
});
61+
.then(({ datasource }) => {
62+
locationService.push(`/datasources/edit/${datasource.uid}`);
6563
});
6664
}, [dataSources]);
6765

@@ -77,9 +75,9 @@ export const DataSourceList: FC<Props> = ({ dataSources }) => {
7775
Add Redis Data Source
7876
</Button>
7977
</div>
80-
<InfoBox title="Please add Redis Data Sources." url={'https://grafana.com/plugins/redis-datasource'}>
78+
<Alert title="Please add Redis Data Sources." severity="info">
8179
<p>You can add as many data sources as you want to support multiple Redis databases.</p>
82-
</InfoBox>
80+
</Alert>
8381
</div>
8482
);
8583
}

src/components/root-page/root-page.test.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { shallow } from 'enzyme';
22
import React from 'react';
33
import { Observable } from 'rxjs';
44
import { AppPluginMeta, PluginType } from '@grafana/data';
5-
import { InfoBox } from '@grafana/ui';
5+
import { Alert } from '@grafana/ui';
66
import { DataSourceType, RedisCommand } from '../../constants';
77
import { DataSourceList } from '../data-source-list';
88
import { RootPage } from './root-page';
@@ -170,7 +170,7 @@ describe('RootPage', () => {
170170
text: 'Home',
171171
url: path,
172172
id: 'home',
173-
icon: 'fa fa-fw fa-database',
173+
icon: 'fa fa-fw fa-home',
174174
active: true,
175175
},
176176
],
@@ -191,14 +191,14 @@ describe('RootPage', () => {
191191
<RootPage basename="" meta={meta} path={path} query={null as any} onNavChanged={onNavChangedMock} />
192192
);
193193
const loadingMessageComponent = wrapper.findWhere(
194-
(node) => node.is(InfoBox) && node.prop('title') === 'Loading...'
194+
(node) => node.is(Alert) && node.prop('title') === 'Loading...'
195195
);
196196
expect(loadingMessageComponent.exists()).toBeTruthy();
197197
wrapper.instance().componentDidMount();
198198
setImmediate(() => {
199199
const dataSourceListComponent = wrapper.findWhere((node) => node.is(DataSourceList));
200200
const loadingMessageComponent = wrapper.findWhere(
201-
(node) => node.is(InfoBox) && node.prop('title') === 'Loading...'
201+
(node) => node.is(Alert) && node.prop('title') === 'Loading...'
202202
);
203203
expect(loadingMessageComponent.exists()).not.toBeTruthy();
204204
expect(dataSourceListComponent.exists()).toBeTruthy();
@@ -217,7 +217,7 @@ describe('RootPage', () => {
217217

218218
const dataSourceListComponent = wrapper.findWhere((node) => node.is(DataSourceList));
219219
const loadingMessageComponent = wrapper.findWhere(
220-
(node) => node.is(InfoBox) && node.prop('title') === 'Loading...'
220+
(node) => node.is(Alert) && node.prop('title') === 'Loading...'
221221
);
222222
expect(loadingMessageComponent.exists()).not.toBeTruthy();
223223
expect(dataSourceListComponent.exists()).toBeTruthy();

src/components/root-page/root-page.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
NavModelItem,
1010
} from '@grafana/data';
1111
import { config, getBackendSrv, getDataSourceSrv } from '@grafana/runtime';
12-
import { InfoBox } from '@grafana/ui';
12+
import { Alert } from '@grafana/ui';
1313
import { DataSourceType, RedisCommand } from '../../constants';
1414
import { RedisQuery } from '../../redis-cli-panel/types';
1515
import { GlobalSettings, RedisDataSourceInstanceSettings } from '../../types';
@@ -157,7 +157,7 @@ export class RootPage extends PureComponent<Props, State> {
157157
text: 'Home',
158158
url: path,
159159
id: 'home',
160-
icon: 'fa fa-fw fa-database',
160+
icon: 'fa fa-fw fa-home',
161161
active: true,
162162
});
163163

@@ -192,9 +192,9 @@ export class RootPage extends PureComponent<Props, State> {
192192
*/
193193
if (loading) {
194194
return (
195-
<InfoBox title="Loading...">
195+
<Alert title="Loading..." severity="info">
196196
<p>Loading time depends on the number of configured data sources.</p>
197-
</InfoBox>
197+
</Alert>
198198
);
199199
}
200200

0 commit comments

Comments
 (0)