diff --git a/public/app/core/components/LayoutSelector/LayoutSelector.tsx b/public/app/core/components/LayoutSelector/LayoutSelector.tsx index 85322dc9da0..d9e00102438 100644 --- a/public/app/core/components/LayoutSelector/LayoutSelector.tsx +++ b/public/app/core/components/LayoutSelector/LayoutSelector.tsx @@ -1,24 +1,39 @@ -import React from 'react'; +import React, { SFC } from 'react'; -export default function LayoutSelector({ mode, onLayoutModeChanged }) { +export type LayoutMode = LayoutModes.Grid | LayoutModes.List; + +export enum LayoutModes { + Grid = 'grid', + List = 'list', +} + +interface Props { + mode: LayoutMode; + onLayoutModeChanged: (mode: LayoutMode) => {}; +} + +const LayoutSelector: SFC = props => { + const { mode, onLayoutModeChanged } = props; return (
); -} +}; + +export default LayoutSelector; diff --git a/public/app/features/plugins/PluginActionBar.test.tsx b/public/app/features/plugins/PluginActionBar.test.tsx index c761b37d9ea..be3f37e89fa 100644 --- a/public/app/features/plugins/PluginActionBar.test.tsx +++ b/public/app/features/plugins/PluginActionBar.test.tsx @@ -1,11 +1,12 @@ import React from 'react'; import { shallow } from 'enzyme'; import { PluginActionBar, Props } from './PluginActionBar'; +import { LayoutModes } from '../../core/components/LayoutSelector/LayoutSelector'; const setup = (propOverrides?: object) => { const props: Props = { searchQuery: '', - layoutMode: 'grid', + layoutMode: LayoutModes.Grid, setLayoutMode: jest.fn(), setPluginsSearchQuery: jest.fn(), }; diff --git a/public/app/features/plugins/PluginActionBar.tsx b/public/app/features/plugins/PluginActionBar.tsx index 12b1353e9dd..301b432ff5c 100644 --- a/public/app/features/plugins/PluginActionBar.tsx +++ b/public/app/features/plugins/PluginActionBar.tsx @@ -1,12 +1,12 @@ import React, { PureComponent } from 'react'; import { connect } from 'react-redux'; -import LayoutSelector from '../../core/components/LayoutSelector/LayoutSelector'; +import LayoutSelector, { LayoutMode } from '../../core/components/LayoutSelector/LayoutSelector'; import { setLayoutMode, setPluginsSearchQuery } from './state/actions'; import { getPluginsSearchQuery, getLayoutMode } from './state/selectors'; export interface Props { searchQuery: string; - layoutMode: string; + layoutMode: LayoutMode; setLayoutMode: typeof setLayoutMode; setPluginsSearchQuery: typeof setPluginsSearchQuery; } @@ -32,7 +32,7 @@ export class PluginActionBar extends PureComponent { /> - setLayoutMode(mode)} /> + setLayoutMode(mode)} />
{ const props = Object.assign( { plugins: getMockPlugins(5), - layout: 'grid', + layoutMode: LayoutModes.Grid, }, propOverrides ); diff --git a/public/app/features/plugins/PluginList.tsx b/public/app/features/plugins/PluginList.tsx index 02d7dac0dce..0074839e754 100644 --- a/public/app/features/plugins/PluginList.tsx +++ b/public/app/features/plugins/PluginList.tsx @@ -1,12 +1,21 @@ -import React from 'react'; +import React, { SFC } from 'react'; import classNames from 'classnames/bind'; import PluginListItem from './PluginListItem'; +import { Plugin } from 'app/types'; +import { LayoutMode, LayoutModes } from '../../core/components/LayoutSelector/LayoutSelector'; + +interface Props { + plugins: Plugin[]; + layoutMode: LayoutMode; +} + +const PluginList: SFC = props => { + const { plugins, layoutMode } = props; -export default function PluginList({ plugins, layout }) { const listStyle = classNames({ 'card-section': true, - 'card-list-layout-grid': layout === 'grid', - 'card-list-layout-list': layout === 'list', + 'card-list-layout-grid': layoutMode === LayoutModes.Grid, + 'card-list-layout-list': layoutMode === LayoutModes.List, }); return ( @@ -18,4 +27,6 @@ export default function PluginList({ plugins, layout }) { ); -} +}; + +export default PluginList; diff --git a/public/app/features/plugins/PluginListItem.tsx b/public/app/features/plugins/PluginListItem.tsx index a143625459a..05eac614fd5 100644 --- a/public/app/features/plugins/PluginListItem.tsx +++ b/public/app/features/plugins/PluginListItem.tsx @@ -1,6 +1,13 @@ -import React from 'react'; +import React, { SFC } from 'react'; +import { Plugin } from 'app/types'; + +interface Props { + plugin: Plugin; +} + +const PluginListItem: SFC = props => { + const { plugin } = props; -export default function PluginListItem({ plugin }) { return (
  • @@ -27,4 +34,6 @@ export default function PluginListItem({ plugin }) {
  • ); -} +}; + +export default PluginListItem; diff --git a/public/app/features/plugins/PluginListPage.tsx b/public/app/features/plugins/PluginListPage.tsx index 5a467881d94..de2968b126c 100644 --- a/public/app/features/plugins/PluginListPage.tsx +++ b/public/app/features/plugins/PluginListPage.tsx @@ -8,11 +8,12 @@ import { NavModel, Plugin } from '../../types'; import { loadPlugins } from './state/actions'; import { getNavModel } from '../../core/selectors/navModel'; import { getLayoutMode, getPlugins } from './state/selectors'; +import { LayoutMode } from '../../core/components/LayoutSelector/LayoutSelector'; export interface Props { navModel: NavModel; plugins: Plugin[]; - layoutMode: string; + layoutMode: LayoutMode; loadPlugins: typeof loadPlugins; } @@ -33,7 +34,7 @@ export class PluginListPage extends PureComponent {
    - {plugins && } + {plugins && }
    ); diff --git a/public/app/features/plugins/__snapshots__/PluginListPage.test.tsx.snap b/public/app/features/plugins/__snapshots__/PluginListPage.test.tsx.snap index 9c428b54ca0..74b23d8850a 100644 --- a/public/app/features/plugins/__snapshots__/PluginListPage.test.tsx.snap +++ b/public/app/features/plugins/__snapshots__/PluginListPage.test.tsx.snap @@ -10,7 +10,7 @@ exports[`Render should render component 1`] = ` > diff --git a/public/app/features/plugins/state/actions.ts b/public/app/features/plugins/state/actions.ts index b842037ffc7..24774c6061c 100644 --- a/public/app/features/plugins/state/actions.ts +++ b/public/app/features/plugins/state/actions.ts @@ -1,6 +1,7 @@ import { Plugin, StoreState } from 'app/types'; import { ThunkAction } from 'redux-thunk'; import { getBackendSrv } from '../../../core/services/backend_srv'; +import { LayoutMode } from '../../../core/components/LayoutSelector/LayoutSelector'; export enum ActionTypes { LoadPlugins = 'LOAD_PLUGINS', @@ -20,10 +21,10 @@ export interface SetPluginsSearchQueryAction { export interface SetLayoutModeAction { type: ActionTypes.SetLayoutMode; - payload: string; + payload: LayoutMode; } -export const setLayoutMode = (mode: string): SetLayoutModeAction => ({ +export const setLayoutMode = (mode: LayoutMode): SetLayoutModeAction => ({ type: ActionTypes.SetLayoutMode, payload: mode, }); diff --git a/public/app/features/plugins/state/reducers.ts b/public/app/features/plugins/state/reducers.ts index aadf78afe5e..af1badb8785 100644 --- a/public/app/features/plugins/state/reducers.ts +++ b/public/app/features/plugins/state/reducers.ts @@ -1,7 +1,8 @@ import { Action, ActionTypes } from './actions'; import { Plugin, PluginsState } from 'app/types'; +import { LayoutModes } from '../../../core/components/LayoutSelector/LayoutSelector'; -export const initialState: PluginsState = { plugins: [] as Plugin[], searchQuery: '', layoutMode: 'grid' }; +export const initialState: PluginsState = { plugins: [] as Plugin[], searchQuery: '', layoutMode: LayoutModes.Grid }; export const pluginsReducer = (state = initialState, action: Action): PluginsState => { switch (action.type) {