mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[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 <img width="1486" alt="Screenshot 2023-11-03 at 17 53 18" src="92bc5ae0
-b4ef-4710-a9c2-8dd505b0febf"> #### Long index name1b89381b
-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)
This commit is contained in:
parent
f93e57bbcf
commit
cecd175d34
6 changed files with 68 additions and 19 deletions
|
@ -395,6 +395,29 @@ describe('<IndexDetailsPage />', () => {
|
|||
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';
|
||||
|
|
|
@ -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(
|
||||
<Fragment key={label}>
|
||||
{' '}
|
||||
const badge =
|
||||
onFilterChange && filterExpression ? (
|
||||
<EuiBadge color={color} onClick={clickHandler} onClickAriaLabel={ariaLabel}>
|
||||
{label}
|
||||
</EuiBadge>
|
||||
</Fragment>
|
||||
);
|
||||
) : (
|
||||
<EuiBadge color={color}>{label}</EuiBadge>
|
||||
);
|
||||
badgeLabels.push(<Fragment key={label}> {badge}</Fragment>);
|
||||
}
|
||||
});
|
||||
return <Fragment>{badgeLabels}</Fragment>;
|
|
@ -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<Props> = ({
|
|||
}));
|
||||
}, [tabs, tab, onSectionChange]);
|
||||
|
||||
const pageTitle = (
|
||||
<>
|
||||
{index.name}
|
||||
{renderBadges(index, extensionsService)}
|
||||
</>
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<EuiPageSection paddingSize="none">
|
||||
|
@ -146,7 +154,7 @@ export const DetailsPageContent: FunctionComponent<Props> = ({
|
|||
<EuiSpacer size="l" />
|
||||
<EuiPageHeader
|
||||
data-test-subj="indexDetailsHeader"
|
||||
pageTitle={index.name}
|
||||
pageTitle={pageTitle}
|
||||
bottomBorder
|
||||
rightSideItems={[
|
||||
<DiscoverLink indexName={index.name} asButton={true} />,
|
||||
|
|
|
@ -295,7 +295,7 @@ export class IndexTable extends Component {
|
|||
>
|
||||
{value}
|
||||
</EuiLink>
|
||||
{renderBadges(index, filterChanged, appServices.extensionsService)}
|
||||
{renderBadges(index, appServices.extensionsService, filterChanged)}
|
||||
</Fragment>
|
||||
);
|
||||
} else if (fieldName === 'data_stream' && value) {
|
||||
|
|
|
@ -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<FunctionComponent>;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue