diff --git a/packages/grafana-ui/src/components/Forms/RadioButtonGroup/RadioButtonGroup.tsx b/packages/grafana-ui/src/components/Forms/RadioButtonGroup/RadioButtonGroup.tsx index 8d045fa1a6c..72f372e3168 100644 --- a/packages/grafana-ui/src/components/Forms/RadioButtonGroup/RadioButtonGroup.tsx +++ b/packages/grafana-ui/src/components/Forms/RadioButtonGroup/RadioButtonGroup.tsx @@ -3,6 +3,7 @@ import { css } from 'emotion'; import uniqueId from 'lodash/uniqueId'; import { SelectableValue } from '@grafana/data'; import { RadioButtonSize, RadioButton } from './RadioButton'; +import { Icon } from '../../Icon/Icon'; const getRadioButtonGroupStyles = () => { return { @@ -67,19 +68,20 @@ export function RadioButtonGroup({ return (
- {options.map(o => { + {options.map((o, i) => { const isItemDisabled = disabledOptions && o.value && disabledOptions.includes(o.value); return ( + {o.icon && } {o.label} ); diff --git a/public/app/core/components/LayoutSelector/LayoutSelector.tsx b/public/app/core/components/LayoutSelector/LayoutSelector.tsx index d12f5d539af..2633ef8838d 100644 --- a/public/app/core/components/LayoutSelector/LayoutSelector.tsx +++ b/public/app/core/components/LayoutSelector/LayoutSelector.tsx @@ -1,5 +1,5 @@ import React, { FC } from 'react'; -import { Icon } from '@grafana/ui'; +import { RadioButtonGroup } from '@grafana/ui'; export type LayoutMode = LayoutModes.Grid | LayoutModes.List; @@ -13,28 +13,15 @@ interface Props { onLayoutModeChanged: (mode: LayoutMode) => {}; } -const LayoutSelector: FC = props => { - const { mode, onLayoutModeChanged } = props; - return ( -
- - -
- ); -}; +const options = [ + { icon: 'table', value: LayoutModes.Grid }, + { icon: 'list-ul', value: LayoutModes.List }, +]; + +const LayoutSelector: FC = ({ mode, onLayoutModeChanged }) => ( +
+ +
+); export default LayoutSelector; diff --git a/public/app/core/components/OrgActionBar/OrgActionBar.tsx b/public/app/core/components/OrgActionBar/OrgActionBar.tsx index b563fe9098b..bc810f40d84 100644 --- a/public/app/core/components/OrgActionBar/OrgActionBar.tsx +++ b/public/app/core/components/OrgActionBar/OrgActionBar.tsx @@ -1,6 +1,7 @@ import React, { PureComponent } from 'react'; import LayoutSelector, { LayoutMode } from '../LayoutSelector/LayoutSelector'; import { FilterInput } from '../FilterInput/FilterInput'; +import { LinkButton } from '@grafana/ui'; export interface Props { searchQuery: string; @@ -33,9 +34,7 @@ export default class OrgActionBar extends PureComponent { onSetLayoutMode(mode)} />
- - {linkButton.title} - + {linkButton.title}
); } diff --git a/public/app/core/components/OrgActionBar/__snapshots__/OrgActionBar.test.tsx.snap b/public/app/core/components/OrgActionBar/__snapshots__/OrgActionBar.test.tsx.snap index a8a6a5da651..df6a8ddb545 100644 --- a/public/app/core/components/OrgActionBar/__snapshots__/OrgActionBar.test.tsx.snap +++ b/public/app/core/components/OrgActionBar/__snapshots__/OrgActionBar.test.tsx.snap @@ -21,12 +21,11 @@ exports[`Render should render component 1`] = `
- test - +
`; diff --git a/public/app/core/components/layout_selector/layout_selector.ts b/public/app/core/components/layout_selector/layout_selector.ts deleted file mode 100644 index 6782b846c9f..00000000000 --- a/public/app/core/components/layout_selector/layout_selector.ts +++ /dev/null @@ -1,74 +0,0 @@ -import store from 'app/core/store'; -import coreModule from 'app/core/core_module'; -import { GrafanaRootScope } from 'app/routes/GrafanaCtrl'; -import { CoreEvents } from 'app/types'; - -const template = ` -
- - -
-`; - -export class LayoutSelectorCtrl { - mode: string; - - /** @ngInject */ - constructor(private $rootScope: GrafanaRootScope) { - this.mode = store.get('grafana.list.layout.mode') || 'grid'; - } - - listView() { - this.mode = 'list'; - store.set('grafana.list.layout.mode', 'list'); - this.$rootScope.appEvent(CoreEvents.layoutModeChanged, 'list'); - } - - gridView() { - this.mode = 'grid'; - store.set('grafana.list.layout.mode', 'grid'); - this.$rootScope.appEvent(CoreEvents.layoutModeChanged, 'grid'); - } -} - -/** @ngInject */ -export function layoutSelector() { - return { - restrict: 'E', - controller: LayoutSelectorCtrl, - bindToController: true, - controllerAs: 'ctrl', - scope: {}, - template: template, - }; -} - -/** @ngInject */ -export function layoutMode($rootScope: GrafanaRootScope) { - return { - restrict: 'A', - scope: {}, - link: (scope: any, elem: any) => { - const layout = store.get('grafana.list.layout.mode') || 'grid'; - let className = 'card-list-layout-' + layout; - elem.addClass(className); - - $rootScope.onAppEvent( - CoreEvents.layoutModeChanged, - (evt: any, newLayout: any) => { - elem.removeClass(className); - className = 'card-list-layout-' + newLayout; - elem.addClass(className); - }, - scope - ); - }, - }; -} - -coreModule.directive('layoutSelector', layoutSelector); -coreModule.directive('layoutMode', layoutMode); diff --git a/public/app/core/core.ts b/public/app/core/core.ts index bcad92e0660..07e61f46667 100644 --- a/public/app/core/core.ts +++ b/public/app/core/core.ts @@ -23,7 +23,6 @@ import { infoPopover } from './components/info_popover'; import { arrayJoin } from './directives/array_join'; import { liveSrv } from './live/live_srv'; import { Emitter } from './utils/emitter'; -import { layoutSelector } from './components/layout_selector/layout_selector'; import { switchDirective } from './components/switch'; import { dashboardSelector } from './components/dashboard_selector'; import { queryPartEditorDirective } from './components/query_part/query_part_editor'; @@ -54,7 +53,6 @@ export { coreModule, searchDirective, liveSrv, - layoutSelector, switchDirective, infoPopover, Emitter,