Skip to content

Commit

Permalink
[Index Management] Feature add button handler for the ilm banner via …
Browse files Browse the repository at this point in the history
  • Loading branch information
viajes7 authored and TattdCodeMonkey committed Nov 21, 2024
1 parent 492917d commit a9ba123
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 8 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,24 @@ describe('extend index management', () => {
expect(extension).toBeDefined();
expect(extension).toMatchSnapshot();
});

test('should return action definition when any index has lifecycle error', () => {
const extension = ilmBannerExtension([
indexWithoutLifecyclePolicy,
indexWithLifecyclePolicy,
indexWithLifecycleError,
]);
const { requestMethod, successMessage, buttonLabel } =
retryLifecycleActionExtension({
indices: [indexWithLifecycleError],
}) ?? {};
expect(extension?.action).toEqual({
requestMethod,
successMessage,
buttonLabel,
indexNames: [indexWithLifecycleError.name],
});
});
});

describe('ilm summary extension', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,20 @@ export const ilmBannerExtension = (indices: Index[]) => {
if (!numIndicesWithLifecycleErrors) {
return null;
}
const { requestMethod, successMessage, indexNames, buttonLabel } =
retryLifecycleActionExtension({ indices: indicesWithLifecycleErrors }) ?? {};
return {
type: 'warning',
filter: Query.parse(`${stepPath}:ERROR`),
filterLabel: i18n.translate('xpack.indexLifecycleMgmt.indexMgmtBanner.filterLabel', {
defaultMessage: 'Show errors',
}),
action: {
buttonLabel,
indexNames: indexNames?.[0] ?? [],
requestMethod,
successMessage,
},
title: i18n.translate('xpack.indexLifecycleMgmt.indexMgmtBanner.errorMessage', {
defaultMessage: `{ numIndicesWithLifecycleErrors, number}
{numIndicesWithLifecycleErrors, plural, one {index has} other {indices have} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
sortChanged,
loadIndices,
toggleChanged,
performExtensionAction,
} from '../../../../store/actions';

import { IndexTable as PresentationComponent } from './index_table';
Expand Down Expand Up @@ -63,6 +64,9 @@ const mapDispatchToProps = (dispatch) => {
loadIndices: () => {
dispatch(loadIndices());
},
performExtensionAction: (requestMethod, successMessage, indexNames) => {
dispatch(performExtensionAction({ requestMethod, successMessage, indexNames }));
},
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,24 +404,47 @@ export class IndexTable extends Component {
}

renderBanners(extensionsService) {
const { allIndices = [], filterChanged } = this.props;
const { allIndices = [], filterChanged, performExtensionAction } = this.props;
return extensionsService.banners.map((bannerExtension, i) => {
const bannerData = bannerExtension(allIndices);
if (!bannerData) {
return null;
}

const { type, title, message, filter, filterLabel } = bannerData;
const { type, title, message, filter, filterLabel, action } = bannerData;

return (
<Fragment key={`bannerExtension${i}`}>
<EuiCallOut color={type} size="m" title={title}>
<EuiText>
{message}
{filter ? (
<EuiLink onClick={() => filterChanged(filter)}>{filterLabel}</EuiLink>
) : null}
</EuiText>
{message && <p>{message}</p>}
{action || filter ? (
<EuiFlexGroup gutterSize="s" alignItems="center">
{action ? (
<EuiFlexItem grow={false}>
<EuiButton
color="warning"
fill
onClick={() => {
performExtensionAction(
action.requestMethod,
action.successMessage,
action.indexNames
);
}}
>
{action.buttonLabel}
</EuiButton>
</EuiFlexItem>
) : null}
{filter ? (
<EuiFlexItem grow={false}>
<EuiText>
<EuiLink onClick={() => filterChanged(filter)}>{filterLabel}</EuiLink>
</EuiText>
</EuiFlexItem>
) : null}
</EuiFlexGroup>
) : null}
</EuiCallOut>
<EuiSpacer size="m" />
</Fragment>
Expand Down

0 comments on commit a9ba123

Please sign in to comment.