2020-09-23 23:40:52 +02:00
|
|
|
/*
|
|
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
|
|
* or more contributor license agreements. Licensed under the Elastic License;
|
|
|
|
* you may not use this file except in compliance with the Elastic License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { i18n } from '@kbn/i18n';
|
|
|
|
import { TopNavMenuData } from '../../../../../src/plugins/navigation/public';
|
|
|
|
import { LensTopNavActions } from './types';
|
|
|
|
|
|
|
|
export function getLensTopNavConfig(options: {
|
|
|
|
showSaveAndReturn: boolean;
|
2020-11-24 12:37:27 +01:00
|
|
|
enableExportToCSV: boolean;
|
2020-09-23 23:40:52 +02:00
|
|
|
showCancel: boolean;
|
|
|
|
isByValueMode: boolean;
|
|
|
|
actions: LensTopNavActions;
|
|
|
|
savingPermitted: boolean;
|
|
|
|
}): TopNavMenuData[] {
|
2020-11-24 12:37:27 +01:00
|
|
|
const { showSaveAndReturn, showCancel, actions, savingPermitted, enableExportToCSV } = options;
|
2020-09-23 23:40:52 +02:00
|
|
|
const topNavMenu: TopNavMenuData[] = [];
|
|
|
|
|
|
|
|
const saveButtonLabel = options.isByValueMode
|
|
|
|
? i18n.translate('xpack.lens.app.addToLibrary', {
|
|
|
|
defaultMessage: 'Save to library',
|
|
|
|
})
|
|
|
|
: options.showSaveAndReturn
|
|
|
|
? i18n.translate('xpack.lens.app.saveAs', {
|
|
|
|
defaultMessage: 'Save as',
|
|
|
|
})
|
|
|
|
: i18n.translate('xpack.lens.app.save', {
|
|
|
|
defaultMessage: 'Save',
|
|
|
|
});
|
|
|
|
|
2020-11-24 12:37:27 +01:00
|
|
|
topNavMenu.push({
|
|
|
|
label: i18n.translate('xpack.lens.app.downloadCSV', {
|
|
|
|
defaultMessage: 'Download as CSV',
|
|
|
|
}),
|
|
|
|
run: actions.exportToCSV,
|
|
|
|
testId: 'lnsApp_downloadCSVButton',
|
|
|
|
description: i18n.translate('xpack.lens.app.downloadButtonAriaLabel', {
|
|
|
|
defaultMessage: 'Download the data as CSV file',
|
|
|
|
}),
|
|
|
|
disableButton: !enableExportToCSV,
|
|
|
|
});
|
|
|
|
|
2020-10-02 18:47:20 +02:00
|
|
|
if (showCancel) {
|
2020-09-23 23:40:52 +02:00
|
|
|
topNavMenu.push({
|
2020-10-02 18:47:20 +02:00
|
|
|
label: i18n.translate('xpack.lens.app.cancel', {
|
|
|
|
defaultMessage: 'cancel',
|
2020-09-23 23:40:52 +02:00
|
|
|
}),
|
2020-10-02 18:47:20 +02:00
|
|
|
run: actions.cancel,
|
|
|
|
testId: 'lnsApp_cancelButton',
|
|
|
|
description: i18n.translate('xpack.lens.app.cancelButtonAriaLabel', {
|
|
|
|
defaultMessage: 'Return to the last app without saving changes',
|
2020-09-23 23:40:52 +02:00
|
|
|
}),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
topNavMenu.push({
|
|
|
|
label: saveButtonLabel,
|
2020-10-02 18:47:20 +02:00
|
|
|
iconType: !showSaveAndReturn ? 'save' : undefined,
|
2020-09-23 23:40:52 +02:00
|
|
|
emphasize: !showSaveAndReturn,
|
|
|
|
run: actions.showSaveModal,
|
|
|
|
testId: 'lnsApp_saveButton',
|
|
|
|
description: i18n.translate('xpack.lens.app.saveButtonAriaLabel', {
|
|
|
|
defaultMessage: 'Save the current lens visualization',
|
|
|
|
}),
|
|
|
|
disableButton: !savingPermitted,
|
|
|
|
});
|
|
|
|
|
2020-10-02 18:47:20 +02:00
|
|
|
if (showSaveAndReturn) {
|
2020-09-23 23:40:52 +02:00
|
|
|
topNavMenu.push({
|
2020-10-02 18:47:20 +02:00
|
|
|
label: i18n.translate('xpack.lens.app.saveAndReturn', {
|
|
|
|
defaultMessage: 'Save and return',
|
2020-09-23 23:40:52 +02:00
|
|
|
}),
|
2020-10-02 18:47:20 +02:00
|
|
|
emphasize: true,
|
|
|
|
iconType: 'checkInCircleFilled',
|
|
|
|
run: actions.saveAndReturn,
|
|
|
|
testId: 'lnsApp_saveAndReturnButton',
|
|
|
|
disableButton: !savingPermitted,
|
|
|
|
description: i18n.translate('xpack.lens.app.saveAndReturnButtonAriaLabel', {
|
|
|
|
defaultMessage: 'Save the current lens visualization and return to the last app',
|
2020-09-23 23:40:52 +02:00
|
|
|
}),
|
|
|
|
});
|
|
|
|
}
|
2020-10-02 18:47:20 +02:00
|
|
|
|
2020-09-23 23:40:52 +02:00
|
|
|
return topNavMenu;
|
|
|
|
}
|