From cecd175d34f5b4e837d53adac9a05db3d63f96d3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Yulia=20=C4=8Cech?=
<6585477+yuliacech@users.noreply.github.com>
Date: Tue, 7 Nov 2023 11:29:59 +0100
Subject: [PATCH] [Index Management] Add index name badges to the details page
(#170558)
## Summary
Fixes https://github.com/elastic/kibana/issues/170335
This PR adds index name badges to the index details page. The badges
used to be rendered in the index details flyout but were not
re-implemented for the new details page in
https://github.com/elastic/kibana/pull/165705.
Currently, there are only 3 possible badges: "frozen", "rollup" and
"follower".
### Screenshots
#### Short index name
#### Long index name
https://github.com/elastic/kibana/assets/6585477/1b89381b-5b9a-4a59-9473-e5887a473250
### Checklist
- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)
### Risk Matrix
Delete this section if it is not applicable to this PR.
Before closing this PR, invite QA, stakeholders, and other developers to
identify risks that should be tested prior to the change/feature
release.
When forming the risk matrix, consider some of the following examples
and how they may potentially impact the change:
| Risk | Probability | Severity | Mitigation/Notes |
|---------------------------|-------------|----------|-------------------------|
| Multiple Spaces—unexpected behavior in non-default Kibana Space.
| Low | High | Integration tests will verify that all features are still
supported in non-default Kibana Space and when user switches between
spaces. |
| Multiple nodes—Elasticsearch polling might have race conditions
when multiple Kibana nodes are polling for the same tasks. | High | Low
| Tasks are idempotent, so executing them multiple times will not result
in logical error, but will degrade performance. To test for this case we
add plenty of unit tests around this logic and document manual testing
procedure. |
| Code should gracefully handle cases when feature X or plugin Y are
disabled. | Medium | High | Unit tests will verify that any feature flag
or plugin combination still results in our service operational. |
| [See more potential risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |
### For maintainers
- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
---
.../index_details_page.test.tsx | 23 +++++++++++++
.../{render_badges.js => render_badges.tsx} | 32 ++++++++++++-------
.../details_page/details_page_content.tsx | 10 +++++-
.../index_list/index_table/index_table.js | 2 +-
.../public/services/extensions_service.ts | 15 +++++++--
.../public/extend_index_management/index.ts | 5 +--
6 files changed, 68 insertions(+), 19 deletions(-)
rename x-pack/plugins/index_management/public/application/lib/{render_badges.js => render_badges.tsx} (54%)
diff --git a/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.test.tsx b/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.test.tsx
index 9f9018edceead..afdfa15c917aa 100644
--- a/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.test.tsx
+++ b/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.test.tsx
@@ -395,6 +395,29 @@ describe('', () => {
expect(testBed.actions.overview.addDocCodeBlockExists()).toBe(true);
});
+ it('renders index name badges from the extensions service', async () => {
+ const testBadges = ['testBadge1', 'testBadge2'];
+ await act(async () => {
+ testBed = await setup({
+ httpSetup,
+ dependencies: {
+ services: {
+ extensionsService: {
+ _badges: testBadges.map((badge) => ({
+ matchIndex: () => true,
+ label: badge,
+ color: 'primary',
+ })),
+ },
+ },
+ },
+ });
+ });
+ testBed.component.update();
+ const header = testBed.actions.getHeader();
+ expect(header).toEqual(`${testIndexName} ${testBadges.join(' ')}`);
+ });
+
describe('extension service overview content', () => {
it('renders the content instead of the default code block', async () => {
const extensionsServiceOverview = 'Test content via extensions service';
diff --git a/x-pack/plugins/index_management/public/application/lib/render_badges.js b/x-pack/plugins/index_management/public/application/lib/render_badges.tsx
similarity index 54%
rename from x-pack/plugins/index_management/public/application/lib/render_badges.js
rename to x-pack/plugins/index_management/public/application/lib/render_badges.tsx
index 0e6313bc689e7..54bdd906a7ec1 100644
--- a/x-pack/plugins/index_management/public/application/lib/render_badges.js
+++ b/x-pack/plugins/index_management/public/application/lib/render_badges.tsx
@@ -5,31 +5,39 @@
* 2.0.
*/
-import React, { Fragment } from 'react';
+import React, { Fragment, ReactNode } from 'react';
import { i18n } from '@kbn/i18n';
-import { EuiBadge, EuiSearchBar } from '@elastic/eui';
+import { EuiBadge, Query } from '@elastic/eui';
-export const renderBadges = (index, filterChanged, extensionsService) => {
- const badgeLabels = [];
+import { ExtensionsService } from '../../services';
+import { Index } from '../..';
+
+export const renderBadges = (
+ index: Index,
+ extensionsService: ExtensionsService,
+ onFilterChange?: (query: Query) => void
+) => {
+ const badgeLabels: ReactNode[] = [];
extensionsService.badges.forEach(({ matchIndex, label, color, filterExpression }) => {
if (matchIndex(index)) {
const clickHandler = () => {
- filterChanged &&
- filterExpression &&
- filterChanged(EuiSearchBar.Query.parse(filterExpression));
+ if (onFilterChange && filterExpression) {
+ onFilterChange(Query.parse(filterExpression));
+ }
};
const ariaLabel = i18n.translate('xpack.idxMgmt.badgeAriaLabel', {
defaultMessage: '{label}. Select to filter on this.',
values: { label },
});
- badgeLabels.push(
-
- {' '}
+ const badge =
+ onFilterChange && filterExpression ? (
{label}
-
- );
+ ) : (
+ {label}
+ );
+ badgeLabels.push( {badge});
}
});
return {badgeLabels};
diff --git a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_content.tsx b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_content.tsx
index 1a9d5935cca19..0360df733c945 100644
--- a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_content.tsx
+++ b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_content.tsx
@@ -17,6 +17,7 @@ import { css } from '@emotion/react';
import { FormattedMessage } from '@kbn/i18n-react';
import { RouteComponentProps } from 'react-router-dom';
+import { renderBadges } from '../../../../lib/render_badges';
import { Index } from '../../../../../../common';
import {
INDEX_OPEN,
@@ -128,6 +129,13 @@ export const DetailsPageContent: FunctionComponent = ({
}));
}, [tabs, tab, onSectionChange]);
+ const pageTitle = (
+ <>
+ {index.name}
+ {renderBadges(index, extensionsService)}
+ >
+ );
+
return (
<>
@@ -146,7 +154,7 @@ export const DetailsPageContent: FunctionComponent = ({
,
diff --git a/x-pack/plugins/index_management/public/application/sections/home/index_list/index_table/index_table.js b/x-pack/plugins/index_management/public/application/sections/home/index_list/index_table/index_table.js
index 183e108f4dc8d..7a15abef3a16f 100644
--- a/x-pack/plugins/index_management/public/application/sections/home/index_list/index_table/index_table.js
+++ b/x-pack/plugins/index_management/public/application/sections/home/index_list/index_table/index_table.js
@@ -295,7 +295,7 @@ export class IndexTable extends Component {
>
{value}
- {renderBadges(index, filterChanged, appServices.extensionsService)}
+ {renderBadges(index, appServices.extensionsService, filterChanged)}
);
} else if (fieldName === 'data_stream' && value) {
diff --git a/x-pack/plugins/index_management/public/services/extensions_service.ts b/x-pack/plugins/index_management/public/services/extensions_service.ts
index 5ffef366a016c..94211b32dbd70 100644
--- a/x-pack/plugins/index_management/public/services/extensions_service.ts
+++ b/x-pack/plugins/index_management/public/services/extensions_service.ts
@@ -8,6 +8,7 @@
import { i18n } from '@kbn/i18n';
import { FunctionComponent } from 'react';
import { ApplicationStart } from '@kbn/core-application-browser';
+import { EuiBadgeProps } from '@elastic/eui';
import type { IndexDetailsTab } from '../../common/constants';
import { Index } from '..';
@@ -18,11 +19,19 @@ export interface IndexOverviewContent {
}) => ReturnType;
}
+export interface IndexBadge {
+ matchIndex: (index: Index) => boolean;
+ label: string;
+ // a parseable search bar filter expression, for example "isFollowerIndex:true"
+ filterExpression?: string;
+ color: EuiBadgeProps['color'];
+}
+
export interface ExtensionsSetup {
addAction(action: any): void;
addBanner(banner: any): void;
addFilter(filter: any): void;
- addBadge(badge: any): void;
+ addBadge(badge: IndexBadge): void;
addToggle(toggle: any): void;
addIndexDetailsTab(tab: IndexDetailsTab): void;
setIndexOverviewContent(content: IndexOverviewContent): void;
@@ -32,7 +41,7 @@ export class ExtensionsService {
private _actions: any[] = [];
private _banners: any[] = [];
private _filters: any[] = [];
- private _badges: any[] = [
+ private _badges: IndexBadge[] = [
{
matchIndex: (index: { isFrozen: boolean }) => {
return index.isFrozen;
@@ -75,7 +84,7 @@ export class ExtensionsService {
this._filters.push(filter);
}
- private addBadge(badge: any) {
+ private addBadge(badge: IndexBadge) {
this._badges.push(badge);
}
diff --git a/x-pack/plugins/rollup/public/extend_index_management/index.ts b/x-pack/plugins/rollup/public/extend_index_management/index.ts
index 2b9bc623b4679..b285db2b9ca76 100644
--- a/x-pack/plugins/rollup/public/extend_index_management/index.ts
+++ b/x-pack/plugins/rollup/public/extend_index_management/index.ts
@@ -6,6 +6,7 @@
*/
import { i18n } from '@kbn/i18n';
+import { Index } from '@kbn/index-management-plugin/common';
import { get } from 'lodash';
const propertyPath = 'isRollupIndex';
@@ -20,8 +21,8 @@ export const rollupToggleExtension = {
};
export const rollupBadgeExtension = {
- matchIndex: (index: { isRollupIndex: boolean }) => {
- return get(index, propertyPath);
+ matchIndex: (index: Index) => {
+ return !!get(index, propertyPath);
},
label: i18n.translate('xpack.rollupJobs.indexMgmtBadge.rollupLabel', {
defaultMessage: 'Rollup',