diff --git a/public/app/core/components/LayoutSelector/LayoutSelector.tsx b/public/app/core/components/LayoutSelector/LayoutSelector.tsx
new file mode 100644
index 00000000000..85322dc9da0
--- /dev/null
+++ b/public/app/core/components/LayoutSelector/LayoutSelector.tsx
@@ -0,0 +1,24 @@
+import React from 'react';
+
+export default function LayoutSelector({ mode, onLayoutModeChanged }) {
+ return (
+
+
+
+
+ );
+}
diff --git a/public/app/features/plugins/PluginActionBar.tsx b/public/app/features/plugins/PluginActionBar.tsx
index e420bc3eca6..12b1353e9dd 100644
--- a/public/app/features/plugins/PluginActionBar.tsx
+++ b/public/app/features/plugins/PluginActionBar.tsx
@@ -1,24 +1,62 @@
-import React from 'react';
+import React, { PureComponent } from 'react';
+import { connect } from 'react-redux';
+import LayoutSelector from '../../core/components/LayoutSelector/LayoutSelector';
+import { setLayoutMode, setPluginsSearchQuery } from './state/actions';
+import { getPluginsSearchQuery, getLayoutMode } from './state/selectors';
-export default function({ searchQuery, onQueryChange }) {
- return (
-
- );
+export interface Props {
+ searchQuery: string;
+ layoutMode: string;
+ setLayoutMode: typeof setLayoutMode;
+ setPluginsSearchQuery: typeof setPluginsSearchQuery;
}
+
+export class PluginActionBar extends PureComponent {
+ onSearchQueryChange = event => {
+ this.props.setPluginsSearchQuery(event.target.value);
+ };
+
+ render() {
+ const { searchQuery, layoutMode, setLayoutMode } = this.props;
+
+ return (
+
+ );
+ }
+}
+
+function mapStateToProps(state) {
+ return {
+ searchQuery: getPluginsSearchQuery(state.plugins),
+ layoutMode: getLayoutMode(state.plugins),
+ };
+}
+
+const mapDispatchToProps = {
+ setPluginsSearchQuery,
+ setLayoutMode,
+};
+
+export default connect(mapStateToProps, mapDispatchToProps)(PluginActionBar);
diff --git a/public/app/features/plugins/PluginListPage.tsx b/public/app/features/plugins/PluginListPage.tsx
index 73837cfe75f..a2b0348aefd 100644
--- a/public/app/features/plugins/PluginListPage.tsx
+++ b/public/app/features/plugins/PluginListPage.tsx
@@ -7,11 +7,12 @@ import PluginList from './PluginList';
import { NavModel, Plugin } from '../../types';
import { loadPlugins } from './state/actions';
import { getNavModel } from '../../core/selectors/navModel';
-import { getPlugins } from './state/selectors';
+import { getLayoutMode, getPlugins } from './state/selectors';
interface Props {
navModel: NavModel;
plugins: Plugin[];
+ layoutMode: string;
loadPlugins: typeof loadPlugins;
}
@@ -25,14 +26,14 @@ export class PluginListPage extends PureComponent {
}
render() {
- const { navModel, plugins } = this.props;
+ const { navModel, plugins, layoutMode } = this.props;
return (
{}} />
- {plugins && }
+ {plugins && }
);
@@ -43,6 +44,7 @@ function mapStateToProps(state) {
return {
navModel: getNavModel(state.navIndex, 'plugins'),
plugins: getPlugins(state.plugins),
+ layoutMode: getLayoutMode(state.plugins),
};
}
diff --git a/public/app/features/plugins/state/actions.ts b/public/app/features/plugins/state/actions.ts
index d044a7ba56f..b842037ffc7 100644
--- a/public/app/features/plugins/state/actions.ts
+++ b/public/app/features/plugins/state/actions.ts
@@ -4,6 +4,8 @@ import { getBackendSrv } from '../../../core/services/backend_srv';
export enum ActionTypes {
LoadPlugins = 'LOAD_PLUGINS',
+ SetPluginsSearchQuery = 'SET_PLUGIN_SEARCH_QUERY',
+ SetLayoutMode = 'SET_LAYOUT_MODE',
}
export interface LoadPluginsAction {
@@ -11,12 +13,32 @@ export interface LoadPluginsAction {
payload: Plugin[];
}
-export const pluginsLoaded = (plugins: Plugin[]): LoadPluginsAction => ({
+export interface SetPluginsSearchQueryAction {
+ type: ActionTypes.SetPluginsSearchQuery;
+ payload: string;
+}
+
+export interface SetLayoutModeAction {
+ type: ActionTypes.SetLayoutMode;
+ payload: string;
+}
+
+export const setLayoutMode = (mode: string): SetLayoutModeAction => ({
+ type: ActionTypes.SetLayoutMode,
+ payload: mode,
+});
+
+export const setPluginsSearchQuery = (query: string): SetPluginsSearchQueryAction => ({
+ type: ActionTypes.SetPluginsSearchQuery,
+ payload: query,
+});
+
+const pluginsLoaded = (plugins: Plugin[]): LoadPluginsAction => ({
type: ActionTypes.LoadPlugins,
payload: plugins,
});
-export type Action = LoadPluginsAction;
+export type Action = LoadPluginsAction | SetPluginsSearchQueryAction | SetLayoutModeAction;
type ThunkResult = ThunkAction;
diff --git a/public/app/features/plugins/state/reducers.ts b/public/app/features/plugins/state/reducers.ts
index af4089220b6..aadf78afe5e 100644
--- a/public/app/features/plugins/state/reducers.ts
+++ b/public/app/features/plugins/state/reducers.ts
@@ -1,12 +1,18 @@
import { Action, ActionTypes } from './actions';
import { Plugin, PluginsState } from 'app/types';
-export const initialState: PluginsState = { plugins: [] as Plugin[] };
+export const initialState: PluginsState = { plugins: [] as Plugin[], searchQuery: '', layoutMode: 'grid' };
export const pluginsReducer = (state = initialState, action: Action): PluginsState => {
switch (action.type) {
case ActionTypes.LoadPlugins:
return { ...state, plugins: action.payload };
+
+ case ActionTypes.SetPluginsSearchQuery:
+ return { ...state, searchQuery: action.payload };
+
+ case ActionTypes.SetLayoutMode:
+ return { ...state, layoutMode: action.payload };
}
return state;
};
diff --git a/public/app/features/plugins/state/selectors.ts b/public/app/features/plugins/state/selectors.ts
index d436e9fa016..80c74649a4b 100644
--- a/public/app/features/plugins/state/selectors.ts
+++ b/public/app/features/plugins/state/selectors.ts
@@ -1 +1,10 @@
-export const getPlugins = state => state.plugins;
+export const getPlugins = state => {
+ const regex = new RegExp(state.searchQuery, 'i');
+
+ return state.plugins.filter(item => {
+ return regex.test(item.name);
+ });
+};
+
+export const getPluginsSearchQuery = state => state.searchQuery;
+export const getLayoutMode = state => state.layoutMode;
diff --git a/public/app/types/plugins.ts b/public/app/types/plugins.ts
index e1594296acb..25c5b13153e 100644
--- a/public/app/types/plugins.ts
+++ b/public/app/types/plugins.ts
@@ -46,4 +46,6 @@ export interface Plugin {
export interface PluginsState {
plugins: Plugin[];
+ searchQuery: string;
+ layoutMode: string;
}