Skip to content

Commit

Permalink
Hide all panel titles option at the dashboard level (#15006) (#15080)
Browse files Browse the repository at this point in the history
* Hide all panel titles option at the dashboard level

* Hide panel titles in edit mode too
  • Loading branch information
stacey-gammon authored Nov 21, 2017
1 parent a492c01 commit a9ce9ee
Show file tree
Hide file tree
Showing 14 changed files with 69 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/core_plugins/kibana/public/dashboard/actions/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export const maximizePanel = createAction('MAXIMIZE_PANEl');
export const minimizePanel = createAction('MINIMIZE_PANEL');
export const updateIsFullScreenMode = createAction('UPDATE_IS_FULL_SCREEN_MODE');
export const updateUseMargins = createAction('UPDATE_USE_MARGINS');
export const updateHidePanelTitles = createAction('HIDE_PANEL_TITLES');
4 changes: 4 additions & 0 deletions src/core_plugins/kibana/public/dashboard/dashboard_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ app.directive('dashboardApp', function ($injector) {
$scope.model = {
query: dashboardStateManager.getQuery(),
useMargins: dashboardStateManager.getUseMargins(),
hidePanelTitles: dashboardStateManager.getHidePanelTitles(),
darkTheme: dashboardStateManager.getDarkTheme(),
timeRestore: dashboardStateManager.getTimeRestore(),
title: dashboardStateManager.getTitle(),
Expand Down Expand Up @@ -181,6 +182,9 @@ app.directive('dashboardApp', function ($injector) {
dashboardStateManager.addNewPanel(hit.id, 'search');
notify.info(`Search successfully added to your dashboard`);
};
$scope.$watch('model.hidePanelTitles', () => {
dashboardStateManager.setHidePanelTitles($scope.model.hidePanelTitles);
});
$scope.$watch('model.useMargins', () => {
dashboardStateManager.setUseMargins($scope.model.useMargins);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ export class DashboardContainerAPI extends ContainerAPI {
this.dashboardState.saveState();
}

getHidePanelTitles() {
return this.dashboardState.getHidePanelTitles();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
minimizePanel,
updateTitle,
updateDescription,
updateHidePanelTitles,
} from './actions';
import { stateMonitorFactory } from 'ui/state_management/state_monitor_factory';
import { createPanelState, getPersistedStateId } from './panel';
Expand All @@ -25,6 +26,7 @@ import {
getTitle,
getDescription,
getUseMargins,
getHidePanelTitles,
} from '../selectors';

/**
Expand Down Expand Up @@ -85,6 +87,7 @@ export class DashboardStateManager {
store.dispatch(setPanels(this.getPanels()));
store.dispatch(updateViewMode(this.getViewMode()));
store.dispatch(updateUseMargins(this.getUseMargins()));
store.dispatch(updateHidePanelTitles(this.getHidePanelTitles()));
store.dispatch(updateIsFullScreenMode(this.getFullScreenMode()));
store.dispatch(updateTitle(this.getTitle()));
store.dispatch(updateDescription(this.getDescription()));
Expand Down Expand Up @@ -138,6 +141,10 @@ export class DashboardStateManager {
store.dispatch(updateUseMargins(this.getUseMargins()));
}

if (getHidePanelTitles(state) !== this.getHidePanelTitles()) {
store.dispatch(updateHidePanelTitles(this.getHidePanelTitles()));
}

if (getFullScreenMode(state) !== this.getFullScreenMode()) {
store.dispatch(updateIsFullScreenMode(this.getFullScreenMode()));
}
Expand Down Expand Up @@ -270,6 +277,15 @@ export class DashboardStateManager {
this.saveState();
}

getHidePanelTitles() {
return this.appState.options.hidePanelTitles;
}

setHidePanelTitles(hidePanelTitles) {
this.appState.options.hidePanelTitles = hidePanelTitles;
this.saveState();
}

getDarkTheme() {
return this.appState.options.darkTheme;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';

export function PanelHeader({ title, actions, isViewOnlyMode }) {
if (isViewOnlyMode && !title) {
export function PanelHeader({ title, actions, isViewOnlyMode, hidePanelTitles }) {
if (isViewOnlyMode && (!title || hidePanelTitles)) {
return (
<div className="panel-heading-floater">
<div className="kuiMicroButtonGroup">
Expand All @@ -20,7 +20,7 @@ export function PanelHeader({ title, actions, isViewOnlyMode }) {
title={title}
aria-label={`Dashboard panel: ${title}`}
>
{title}
{hidePanelTitles ? '' : title}
</span>

<div className="kuiMicroButtonGroup">
Expand All @@ -34,4 +34,5 @@ PanelHeader.propTypes = {
isViewOnlyMode: PropTypes.bool,
title: PropTypes.string,
actions: PropTypes.node,
hidePanelTitles: PropTypes.bool.isRequired,
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import {
getPanel,
getMaximizedPanelId,
getFullScreenMode,
getViewMode
getViewMode,
getHidePanelTitles,
} from '../../selectors';

const mapStateToProps = ({ dashboard }, { panelId }) => {
Expand All @@ -29,6 +30,7 @@ const mapStateToProps = ({ dashboard }, { panelId }) => {
title: panel.title === undefined ? embeddableTitle : panel.title,
isExpanded: getMaximizedPanelId(dashboard) === panelId,
isViewOnlyMode: getFullScreenMode(dashboard) || getViewMode(dashboard) === DashboardViewMode.VIEW,
hidePanelTitles: getHidePanelTitles(dashboard),
};
};

Expand All @@ -38,7 +40,7 @@ const mapDispatchToProps = (dispatch, { panelId }) => ({
});

const mergeProps = (stateProps, dispatchProps, ownProps) => {
const { isExpanded, isViewOnlyMode, title } = stateProps;
const { isExpanded, isViewOnlyMode, title, hidePanelTitles } = stateProps;
const { onMaximizePanel, onMinimizePanel } = dispatchProps;
const { panelId, embeddableFactory } = ownProps;
let actions;
Expand All @@ -60,6 +62,7 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
title,
actions,
isViewOnlyMode,
hidePanelTitles,
};
};

Expand Down
7 changes: 7 additions & 0 deletions src/core_plugins/kibana/public/dashboard/reducers/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
maximizePanel,
minimizePanel,
updateUseMargins,
updateHidePanelTitles,
updateIsFullScreenMode,
} from '../actions';

Expand All @@ -20,6 +21,11 @@ export const view = handleActions({
useMargins: payload
}),

[updateHidePanelTitles]: (state, { payload }) => ({
...state,
hidePanelTitles: payload
}),

[combineActions(maximizePanel, minimizePanel)]: (state, { payload }) => ({
...state,
maximizedPanelId: payload
Expand All @@ -34,4 +40,5 @@ export const view = handleActions({
viewMode: DashboardViewMode.VIEW,
maximizedPanelId: undefined,
useMargins: true,
hidePanelTitles: false,
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.factory('SavedDashboard', function (courier, config) {
darkTheme: config.get('dashboard:defaultDarkTheme'),
// for BWC reasons we can't default dashboards that already exist without this setting to true.
useMargins: id ? false : true,
hidePanelTitles: false,
}),
uiStateJSON: '{}',
version: 1,
Expand Down
5 changes: 5 additions & 0 deletions src/core_plugins/kibana/public/dashboard/selectors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ export const getViewMode = dashboard => dashboard.view.viewMode;
* @return {boolean}
*/
export const getFullScreenMode = dashboard => dashboard.view.isFullScreenMode;
/**
* @param dashboard {DashboardState}
* @return {boolean}
*/
export const getHidePanelTitles = dashboard => dashboard.view.hidePanelTitles;
/**
* @param dashboard {DashboardState}
* @return {string|undefined}
Expand Down
12 changes: 12 additions & 0 deletions src/core_plugins/kibana/public/dashboard/top_nav/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,17 @@ <h2 class="kuiLocalDropdownTitle">
Use margins between panels
</span>
</label>
<label class="kuiCheckBoxLabel">
<input
class="kuiCheckBox"
type="checkbox"
ng-model="model.hidePanelTitles"
ng-checked="model.hidePanelTitles"
data-test-subj="dashboardPanelTitlesCheckbox"
>
<span class="kuiCheckBoxLabel__text">
Hide all panel titles
</span>
</label>
</div>
</form>
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export class SearchEmbeddableFactory extends EmbeddableFactory {
searchScope.editPath = this.getEditPath(panel.id);
return this.searchLoader.get(panel.id)
.then(savedObject => {
searchScope.sharedItemTitle = panel.title !== undefined ? panel.title : savedObject.title;
if (!container.getHidePanelTitles()) {
searchScope.sharedItemTitle = panel.title !== undefined ? panel.title : savedObject.title;
}
searchScope.savedObj = savedObject;
searchScope.panel = panel;
container.registerPanelIndexPattern(panel.panelIndex, savedObject.searchSource.get('index'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const getViewMode = state => DashboardSelectors.getViewMode(getDashboard(
export const getFullScreenMode = state => DashboardSelectors.getFullScreenMode(getDashboard(state));
export const getMaximizedPanelId = state => DashboardSelectors.getMaximizedPanelId(getDashboard(state));
export const getUseMargins = state => DashboardSelectors.getUseMargins(getDashboard(state));
export const getHidePanelTitles = state => DashboardSelectors.getHidePanelTitles(getDashboard(state));

export const getTitle = state => DashboardSelectors.getTitle(getDashboard(state));
export const getDescription = state => DashboardSelectors.getDescription(getDashboard(state));
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory {
visualizeScope.editUrl = this.getEditPath(panel.id);
return this.visualizeLoader.get(panel.id)
.then(savedObject => {
visualizeScope.sharedItemTitle = panel.title !== undefined ? panel.title : savedObject.title;
if (!container.getHidePanelTitles()) {
visualizeScope.sharedItemTitle = panel.title !== undefined ? panel.title : savedObject.title;
}
visualizeScope.savedObj = savedObject;
visualizeScope.panel = panel;

Expand Down
4 changes: 4 additions & 0 deletions src/ui/public/embeddable/container_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ export class ContainerAPI {
updatePanel(/*paneIndex, panelAttributes */) {
throw new Error('Must implement updatePanel.');
}

getHidePanelTitles() {
return this.dashboardState.getHidePanelTitles();
}
}

0 comments on commit a9ce9ee

Please sign in to comment.