-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stop using static + class to namespace functions
Instead, export each function individually.
- Loading branch information
1 parent
0c61fc7
commit b0745aa
Showing
2 changed files
with
38 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 36 additions & 39 deletions
75
src/core_plugins/kibana/public/dashboard/dashboard_strings.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |