consolidating index management extension code

This commit is contained in:
Bill McConaghy 2018-11-14 15:39:58 -05:00
parent 4a63330484
commit 6e081b19cd
7 changed files with 65 additions and 90 deletions

View file

@ -0,0 +1,64 @@
/*
* 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 React from 'react';
import { IndexLifecycleSummary } from './components/index_lifecycle_summary';
import chrome from 'ui/chrome';
import { get, every } from 'lodash';
import { i18n } from '@kbn/i18n';
import { addSummaryExtension, addBannerExtension, addActionExtension } from '../../../index_management/public/index_management_extensions';
import { retryLifecycleForIndex } from '../services/api';
const stepPath = 'ilm.step';
if (chrome.getInjected('indexLifecycleManagementUiEnabled')) {
addActionExtension((indices) => {
const allHaveErrors = every(indices, (index) => {
return (index.ilm && index.ilm.failed_step);
});
if (!allHaveErrors) {
return null;
}
const indexNames = indices.map(({ name }) => name);
return {
requestMethod: retryLifecycleForIndex,
icon: 'play',
indexNames: [indexNames],
buttonLabel: i18n.translate('xpack.idxMgmt.retryIndexLifecycleActionButtonLabel', {
defaultMessage: 'Retry lifecycle',
}),
successMessage: i18n.translate('xpack.idxMgmt.retryIndexLifecycleAction.successfullyRetriedLifecycleMessage', {
defaultMessage: 'Successfully called retry lifecycle for: [{indexNames}]',
values: { indexNames: indexNames.join(', ') }
}),
};
});
addBannerExtension((indices) =>{
if (!indices.length) {
return null;
}
const indicesWithLifecycleErrors = indices.filter((index) => {
return get(index, stepPath) === 'ERROR';
});
const numIndicesWithLifecycleErrors = indicesWithLifecycleErrors.length;
if (!numIndicesWithLifecycleErrors) {
return null;
}
return {
type: 'warning',
filter: `${stepPath}:ERROR`,
message: i18n.translate('xpack.indexLifecycleMgmt.indexMgmtBanner.errorMessage', {
defaultMessage: `{ numIndicesWithLifecycleErrors, number}
{numIndicesWithLifecycleErrors, plural, one {index has} other {indices have} }
lifecycle errors`,
values: { numIndicesWithLifecycleErrors }
}),
};
});
addSummaryExtension((index, urlService) => {
return <IndexLifecycleSummary index={index} urlService={urlService} />;
});
}

View file

@ -6,4 +6,4 @@
import './register_management_section';
import './register_routes';
import './register_index_management_extensions';
import './extend_index_management';

View file

@ -1,12 +0,0 @@
/*
* 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 chrome from 'ui/chrome';
if (chrome.getInjected('indexLifecycleManagementUiEnabled')) {
require('./register_index_lifecycle_actions');
require('./register_index_lifecycle_banner');
require('./register_index_lifecycle_summary');
}

View file

@ -1,32 +0,0 @@
/*
* 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 { every } from 'lodash';
import { i18n } from '@kbn/i18n';
import { addActionExtension } from '../../../index_management/public/index_management_extensions';
import { retryLifecycleForIndex } from '../services/api';
addActionExtension((indices) => {
const allHaveErrors = every(indices, (index) => {
return (index.ilm && index.ilm.failed_step);
});
if (!allHaveErrors) {
return null;
}
const indexNames = indices.map(({ name }) => name);
return {
requestMethod: retryLifecycleForIndex,
icon: 'play',
indexNames: [indexNames],
buttonLabel: i18n.translate('xpack.idxMgmt.retryIndexLifecycleActionButtonLabel', {
defaultMessage: 'Retry lifecycle',
}),
successMessage: i18n.translate('xpack.idxMgmt.retryIndexLifecycleAction.successfullyRetriedLifecycleMessage', {
defaultMessage: 'Successfully called retry lifecycle for: [{indexNames}]',
values: { indexNames: indexNames.join(', ') }
}),
};
});

View file

@ -1,32 +0,0 @@
/*
* 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 { get } from 'lodash';
import { addBannerExtension } from '../../../index_management/public/index_management_extensions';
const stepPath = 'ilm.step';
import { i18n } from '@kbn/i18n';
addBannerExtension((indices) =>{
if (!indices.length) {
return null;
}
const indicesWithLifecycleErrors = indices.filter((index) => {
return get(index, stepPath) === 'ERROR';
});
const numIndicesWithLifecycleErrors = indicesWithLifecycleErrors.length;
if (!numIndicesWithLifecycleErrors) {
return null;
}
return {
type: 'warning',
filter: `${stepPath}:ERROR`,
message: i18n.translate('xpack.indexLifecycleMgmt.indexMgmtBanner.errorMessage', {
defaultMessage: `{ numIndicesWithLifecycleErrors, number}
{numIndicesWithLifecycleErrors, plural, one {index has} other {indices have} }
lifecycle errors`,
values: { numIndicesWithLifecycleErrors }
}),
};
});

View file

@ -1,13 +0,0 @@
/*
* 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 React from 'react';
import { addSummaryExtension } from '../../../index_management/public/index_management_extensions';
import { IndexLifecycleSummary } from './components/index_lifecycle_summary';
addSummaryExtension((index, urlService) => {
return <IndexLifecycleSummary index={index} urlService={urlService} />;
});