Skip to content

Commit 81c44eb

Browse files
committed
Merge branch 'revert-13502-revert-13488-org-users-to-react'
2 parents f35fd0c + 9b4dd31 commit 81c44eb

39 files changed

+1896
-440
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
import OrgActionBar, { Props } from './OrgActionBar';
4+
5+
const setup = (propOverrides?: object) => {
6+
const props: Props = {
7+
searchQuery: '',
8+
setSearchQuery: jest.fn(),
9+
linkButton: { href: 'some/url', title: 'test' },
10+
};
11+
12+
Object.assign(props, propOverrides);
13+
14+
return shallow(<OrgActionBar {...props} />);
15+
};
16+
17+
describe('Render', () => {
18+
it('should render component', () => {
19+
const wrapper = setup();
20+
21+
expect(wrapper).toMatchSnapshot();
22+
});
23+
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import React, { PureComponent } from 'react';
2+
import LayoutSelector, { LayoutMode } from '../LayoutSelector/LayoutSelector';
3+
4+
export interface Props {
5+
searchQuery: string;
6+
layoutMode?: LayoutMode;
7+
onSetLayoutMode?: (mode: LayoutMode) => {};
8+
setSearchQuery: (value: string) => {};
9+
linkButton: { href: string; title: string };
10+
}
11+
12+
export default class OrgActionBar extends PureComponent<Props> {
13+
render() {
14+
const { searchQuery, layoutMode, onSetLayoutMode, linkButton, setSearchQuery } = this.props;
15+
16+
return (
17+
<div className="page-action-bar">
18+
<div className="gf-form gf-form--grow">
19+
<label className="gf-form--has-input-icon">
20+
<input
21+
type="text"
22+
className="gf-form-input width-20"
23+
value={searchQuery}
24+
onChange={event => setSearchQuery(event.target.value)}
25+
placeholder="Filter by name or type"
26+
/>
27+
<i className="gf-form-input-icon fa fa-search" />
28+
</label>
29+
<LayoutSelector mode={layoutMode} onLayoutModeChanged={(mode: LayoutMode) => onSetLayoutMode(mode)} />
30+
</div>
31+
<div className="page-action-bar__spacer" />
32+
<a className="btn btn-success" href={linkButton.href} target="_blank">
33+
{linkButton.title}
34+
</a>
35+
</div>
36+
);
37+
}
38+
}

public/app/features/plugins/__snapshots__/PluginActionBar.test.tsx.snap renamed to public/app/core/components/OrgActionBar/__snapshots__/OrgActionBar.test.tsx.snap

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ exports[`Render should render component 1`] = `
2222
/>
2323
</label>
2424
<LayoutSelector
25-
mode="grid"
2625
onLayoutModeChanged={[Function]}
2726
/>
2827
</div>
@@ -31,10 +30,10 @@ exports[`Render should render component 1`] = `
3130
/>
3231
<a
3332
className="btn btn-success"
34-
href="https://grafana.com/plugins?utm_source=grafana_plugin_list"
33+
href="some/url"
3534
target="_blank"
3635
>
37-
Find more plugins on Grafana.com
36+
test
3837
</a>
3938
</div>
4039
`;

public/app/features/datasources/DataSourcesActionBar.test.tsx

Lines changed: 0 additions & 23 deletions
This file was deleted.

public/app/features/datasources/DataSourcesActionBar.tsx

Lines changed: 0 additions & 62 deletions
This file was deleted.

public/app/features/datasources/DataSourcesListPage.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ const setup = (propOverrides?: object) => {
1212
loadDataSources: jest.fn(),
1313
navModel: {} as NavModel,
1414
dataSourcesCount: 0,
15+
searchQuery: '',
16+
setDataSourcesSearchQuery: jest.fn(),
17+
setDataSourcesLayoutMode: jest.fn(),
1518
};
1619

1720
Object.assign(props, propOverrides);

public/app/features/datasources/DataSourcesListPage.tsx

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,29 @@ import React, { PureComponent } from 'react';
22
import { connect } from 'react-redux';
33
import { hot } from 'react-hot-loader';
44
import PageHeader from '../../core/components/PageHeader/PageHeader';
5-
import DataSourcesActionBar from './DataSourcesActionBar';
5+
import OrgActionBar from '../../core/components/OrgActionBar/OrgActionBar';
6+
import EmptyListCTA from '../../core/components/EmptyListCTA/EmptyListCTA';
67
import DataSourcesList from './DataSourcesList';
7-
import { loadDataSources } from './state/actions';
8-
import { getDataSources, getDataSourcesCount, getDataSourcesLayoutMode } from './state/selectors';
9-
import { getNavModel } from '../../core/selectors/navModel';
108
import { DataSource, NavModel } from 'app/types';
119
import { LayoutMode } from '../../core/components/LayoutSelector/LayoutSelector';
12-
import EmptyListCTA from '../../core/components/EmptyListCTA/EmptyListCTA';
10+
import { loadDataSources, setDataSourcesLayoutMode, setDataSourcesSearchQuery } from './state/actions';
11+
import { getNavModel } from '../../core/selectors/navModel';
12+
import {
13+
getDataSources,
14+
getDataSourcesCount,
15+
getDataSourcesLayoutMode,
16+
getDataSourcesSearchQuery,
17+
} from './state/selectors';
1318

1419
export interface Props {
1520
navModel: NavModel;
1621
dataSources: DataSource[];
1722
dataSourcesCount: number;
1823
layoutMode: LayoutMode;
24+
searchQuery: string;
1925
loadDataSources: typeof loadDataSources;
26+
setDataSourcesLayoutMode: typeof setDataSourcesLayoutMode;
27+
setDataSourcesSearchQuery: typeof setDataSourcesSearchQuery;
2028
}
2129

2230
const emptyListModel = {
@@ -40,7 +48,20 @@ export class DataSourcesListPage extends PureComponent<Props> {
4048
}
4149

4250
render() {
43-
const { dataSources, dataSourcesCount, navModel, layoutMode } = this.props;
51+
const {
52+
dataSources,
53+
dataSourcesCount,
54+
navModel,
55+
layoutMode,
56+
searchQuery,
57+
setDataSourcesSearchQuery,
58+
setDataSourcesLayoutMode,
59+
} = this.props;
60+
61+
const linkButton = {
62+
href: 'datasources/new',
63+
title: 'Add data source',
64+
};
4465

4566
return (
4667
<div>
@@ -50,7 +71,14 @@ export class DataSourcesListPage extends PureComponent<Props> {
5071
<EmptyListCTA model={emptyListModel} />
5172
) : (
5273
[
53-
<DataSourcesActionBar key="action-bar" />,
74+
<OrgActionBar
75+
layoutMode={layoutMode}
76+
searchQuery={searchQuery}
77+
onSetLayoutMode={mode => setDataSourcesLayoutMode(mode)}
78+
setSearchQuery={query => setDataSourcesSearchQuery(query)}
79+
linkButton={linkButton}
80+
key="action-bar"
81+
/>,
5482
<DataSourcesList dataSources={dataSources} layoutMode={layoutMode} key="list" />,
5583
]
5684
)}
@@ -66,11 +94,14 @@ function mapStateToProps(state) {
6694
dataSources: getDataSources(state.dataSources),
6795
layoutMode: getDataSourcesLayoutMode(state.dataSources),
6896
dataSourcesCount: getDataSourcesCount(state.dataSources),
97+
searchQuery: getDataSourcesSearchQuery(state.dataSources),
6998
};
7099
}
71100

72101
const mapDispatchToProps = {
73102
loadDataSources,
103+
setDataSourcesSearchQuery,
104+
setDataSourcesLayoutMode,
74105
};
75106

76107
export default hot(module)(connect(mapStateToProps, mapDispatchToProps)(DataSourcesListPage));

public/app/features/datasources/__snapshots__/DataSourcesActionBar.test.tsx.snap

Lines changed: 0 additions & 42 deletions
This file was deleted.

public/app/features/datasources/__snapshots__/DataSourcesListPage.test.tsx.snap

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,18 @@ exports[`Render should render action bar and datasources 1`] = `
88
<div
99
className="page-container page-body"
1010
>
11-
<Connect(DataSourcesActionBar)
11+
<OrgActionBar
1212
key="action-bar"
13+
layoutMode="grid"
14+
linkButton={
15+
Object {
16+
"href": "datasources/new",
17+
"title": "Add data source",
18+
}
19+
}
20+
onSetLayoutMode={[Function]}
21+
searchQuery=""
22+
setSearchQuery={[Function]}
1323
/>
1424
<DataSourcesList
1525
dataSources={

public/app/features/org/all.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import './org_users_ctrl';
21
import './profile_ctrl';
3-
import './org_users_ctrl';
42
import './select_org_ctrl';
53
import './change_password_ctrl';
64
import './new_org_ctrl';

0 commit comments

Comments
 (0)