Skip to content

Commit

Permalink
Stop using static + class to namespace functions
Browse files Browse the repository at this point in the history
Instead, export each function individually.
  • Loading branch information
stacey-gammon committed Mar 23, 2017
1 parent 0c61fc7 commit b0745aa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/core_plugins/kibana/public/dashboard/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import chrome from 'ui/chrome';
import 'plugins/kibana/dashboard/grid';
import 'plugins/kibana/dashboard/panel/panel';

import { DashboardStrings } from './dashboard_strings';
import { getDashboardTitle, getUnsavedChangesWarningMessage } from './dashboard_strings';
import { DashboardViewMode } from './dashboard_view_mode';
import { TopNavIds } from './top_nav/top_nav_ids';
import { ConfirmationButtonTypes } from 'ui/modals/confirm_modal';
Expand Down Expand Up @@ -113,7 +113,7 @@ app.directive('dashboardApp', function (Notifier, courier, AppState, timefilter,
$scope.getBrushEvent = () => brushEvent(dashboardState.getAppState());
$scope.getFilterBarClickHandler = () => filterBarClickHandler(dashboardState.getAppState());
$scope.hasExpandedPanel = () => $scope.expandedPanel !== null;
$scope.getDashTitle = () => DashboardStrings.getDashboardTitle(
$scope.getDashTitle = () => getDashboardTitle(
dashboardState.getTitle(),
dashboardState.getViewMode(),
dashboardState.getIsDirty(timefilter));
Expand Down
75 changes: 36 additions & 39 deletions src/core_plugins/kibana/public/dashboard/dashboard_strings.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,45 @@
import { DashboardViewMode } from './dashboard_view_mode';
import _ from 'lodash';

export class DashboardStrings {
/**
* @param list {Array.<string>}
* @returns {string} The list of strings concatenated with commas so it can be used in a message.
* E.g. ['a', 'b', 'c'] returns 'a, b, and c'.
*/
export function createStringList(list) {
const listClone = _.clone(list);
const isPlural = list.length > 1;
const lastEntry = isPlural ? `, and ${list[list.length - 1]}` : '';
if (isPlural) listClone.splice(-1, 1);

/**
* @param list {Array.<string>}
* @returns {string} The list of strings concatenated with commas so it can be used in a message.
* E.g. ['a', 'b', 'c'] returns 'a, b, and c'.
*/
static createStringList(list) {
const listClone = _.clone(list);
const isPlural = list.length > 1;
const lastEntry = isPlural ? `, and ${list[list.length - 1]}` : '';
if (isPlural) listClone.splice(-1, 1);

return `${listClone.join(', ')}${lastEntry}`;
}
return `${listClone.join(', ')}${lastEntry}`;
}

/**
* @param changedFilters {Array.<string>} An optional list of filter types that have changed.
* @returns {string} A warning message to display to the user that they are going to lose changes.
*/
static getUnsavedChangesWarningMessage(changedFilters) {
const changedFilterList = this.createStringList(changedFilters);
/**
* @param changedFilters {Array.<string>} An optional list of filter types that have changed.
* @returns {string} A warning message to display to the user that they are going to lose changes.
*/
export function getUnsavedChangesWarningMessage(changedFilters) {
const changedFilterList = createStringList(changedFilters);

return changedFilterList ?
`Are you sure you want to cancel and lose changes, including changes made to your ${changedFilterList}?` :
`Are you sure you want to cancel and lose changes?`;
}
return changedFilterList ?
`Are you sure you want to cancel and lose changes, including changes made to your ${changedFilterList}?` :
`Are you sure you want to cancel and lose changes?`;
}

/**
* @param title {string} the current title of the dashboard
* @param viewMode {DashboardViewMode} the current mode. If in editing state, prepends 'Editing ' to the title.
* @param isDirty {boolean} if the dashboard is in a dirty state. If in dirty state, adds (unsaved) to the
* end of the title.
* @returns {string} A title to display to the user based on the above parameters.
*/
static getDashboardTitle(title, viewMode, isDirty) {
const isEditMode = viewMode === DashboardViewMode.EDIT;
const unsavedSuffix = isEditMode && isDirty
? ' (unsaved)'
: '';
/**
* @param title {string} the current title of the dashboard
* @param viewMode {DashboardViewMode} the current mode. If in editing state, prepends 'Editing ' to the title.
* @param isDirty {boolean} if the dashboard is in a dirty state. If in dirty state, adds (unsaved) to the
* end of the title.
* @returns {string} A title to display to the user based on the above parameters.
*/
export function getDashboardTitle(title, viewMode, isDirty) {
const isEditMode = viewMode === DashboardViewMode.EDIT;
const unsavedSuffix = isEditMode && isDirty
? ' (unsaved)'
: '';

const displayTitle = `${title}${unsavedSuffix}`;
return isEditMode ? 'Editing ' + displayTitle : displayTitle;
}
const displayTitle = `${title}${unsavedSuffix}`;
return isEditMode ? 'Editing ' + displayTitle : displayTitle;
}

0 comments on commit b0745aa

Please sign in to comment.