From b0745aa2c17dbc6bf5e82e1b3cdaf1084dd992ad Mon Sep 17 00:00:00 2001 From: Stacey Gammon Date: Wed, 22 Mar 2017 09:18:27 -0400 Subject: [PATCH] Stop using static + class to namespace functions Instead, export each function individually. --- .../kibana/public/dashboard/dashboard.js | 4 +- .../public/dashboard/dashboard_strings.js | 75 +++++++++---------- 2 files changed, 38 insertions(+), 41 deletions(-) diff --git a/src/core_plugins/kibana/public/dashboard/dashboard.js b/src/core_plugins/kibana/public/dashboard/dashboard.js index 4854d8fe8230e..909014a27c37a 100644 --- a/src/core_plugins/kibana/public/dashboard/dashboard.js +++ b/src/core_plugins/kibana/public/dashboard/dashboard.js @@ -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'; @@ -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)); diff --git a/src/core_plugins/kibana/public/dashboard/dashboard_strings.js b/src/core_plugins/kibana/public/dashboard/dashboard_strings.js index 9b15ad71e8e3b..5243ccdf49605 100644 --- a/src/core_plugins/kibana/public/dashboard/dashboard_strings.js +++ b/src/core_plugins/kibana/public/dashboard/dashboard_strings.js @@ -1,48 +1,45 @@ import { DashboardViewMode } from './dashboard_view_mode'; import _ from 'lodash'; -export class DashboardStrings { +/** + * @param list {Array.} + * @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.} - * @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.} 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.} 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; }