Skip to content

Commit

Permalink
[Index Management] Change the column Components in the Index template…
Browse files Browse the repository at this point in the history
…s table (#175823)

## Summary

Fixes #175690

This PR changes the column Components to display a number of component
templates instead of listing the names, since the text is truncated and
in my opinion is not really readable. The full list of component
templates can still be viewed in the index templates details flyout. The
number of component templates is also a link that redirects to the
Component templates table with a filter initialized in the search bar to
view only those component templates that are used by a specific index
template.

### Screenshots
#### Index templates
Before 
<img width="1376" alt="Screenshot 2024-01-29 at 16 41 55"
src="https://github.com/elastic/kibana/assets/6585477/b55e58eb-b9e9-4b8a-8d9c-47ad5b2d5cb6">


After 

<img width="1384" alt="Screenshot 2024-01-29 at 16 40 40"
src="https://github.com/elastic/kibana/assets/6585477/18c5122c-65b4-49d5-9b44-8855a84bf25b">

#### Component templates
<img width="1393" alt="Screenshot 2024-01-29 at 16 40 48"
src="https://github.com/elastic/kibana/assets/6585477/ac953630-30c1-43e4-9dbb-44d5dbc0adda">



Summarize your PR. If it involves visual changes include a screenshot or
gif.


### Checklist

Delete any items that are not applicable to this PR.

- [ ] 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
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] 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&mdash;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&mdash;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)
  • Loading branch information
yuliacech authored Feb 8, 2024
1 parent 3d431f3 commit 7a55b8c
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,5 @@ export type TestSubjects =
| 'createIndexMessage'
| 'indicesSearch'
| 'noIndicesMessage'
| 'clearIndicesSearch';
| 'clearIndicesSearch'
| 'componentTemplatesLink';
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const createActions = (testBed: TestBed<TestSubjects>) => {
component.update();
};

const clickTemplateAction = (
const clickTemplateAction = async (
templateName: TemplateDeserialized['name'],
action: 'edit' | 'clone' | 'delete'
) => {
Expand All @@ -76,7 +76,7 @@ const createActions = (testBed: TestBed<TestSubjects>) => {

clickActionMenu(templateName);

act(() => {
await act(async () => {
component.find('button.euiContextMenuItem').at(actions.indexOf(action)).simulate('click');
});
component.update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@ describe('Index Templates tab', () => {
expect(exists('templateTable')).toBe(true);
expect(exists('legacyTemplateTable')).toBe(false);
});

test('Components column renders a link to Component templates', async () => {
httpRequestsMockHelpers.setLoadTemplatesResponse({
templates: [
fixtures.getComposableTemplate({
name: 'Test',
composedOf: ['component1', 'component2'],
}),
],
legacyTemplates: [],
});

await act(async () => {
testBed = await setup(httpSetup);
});
const { exists, component } = testBed;
component.update();

expect(exists('componentTemplatesLink')).toBe(true);
});
});

describe('when there are index templates', () => {
Expand Down Expand Up @@ -168,19 +188,18 @@ describe('Index Templates tab', () => {
// Test composable table content
tableCellsValues.forEach((row, i) => {
const indexTemplate = templates[i];
const { name, indexPatterns, ilmPolicy, composedOf, template } = indexTemplate;
const { name, indexPatterns, composedOf, template } = indexTemplate;

const hasContent = !!template?.settings || !!template?.mappings || !!template?.aliases;
const ilmPolicyName = ilmPolicy && ilmPolicy.name ? ilmPolicy.name : '';
const composedOfString = composedOf ? composedOf.join(',') : '';
const composedOfCount = `${composedOf ? composedOf.length : 0}`;

try {
expect(removeWhiteSpaceOnArrayValues(row)).toEqual([
'', // Checkbox to select row
name,
indexPatterns.join(', '),
ilmPolicyName,
composedOfString,
composedOfCount,
'', // data stream column
hasContent ? 'M S A' : 'None', // M S A -> Mappings Settings Aliases badges
'EditDelete', // Column of actions
]);
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/index_management/common/types/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export interface TemplateListItem {
ilmPolicy?: {
name: string;
};
composedOf?: string[];
_kbnMeta: {
type: TemplateType;
hasDatastream: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,24 @@ describe('<ComponentTemplateList />', () => {
});
});

describe('if filter is set, component templates are filtered', () => {
test('search value is set if url param is set', async () => {
const filter = 'usedBy=(test_index_template_1)';
await act(async () => {
testBed = await setup(httpSetup, { filter });
});

testBed.component.update();

const { table } = testBed;
const search = testBed.actions.getSearchValue();
expect(search).toBe(filter);

const { rows } = table.getMetaData('componentTemplatesTable');
expect(rows.length).toBe(1);
});
});

describe('No component templates', () => {
beforeEach(async () => {
httpRequestsMockHelpers.setLoadComponentTemplatesResponse([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ import { BASE_PATH } from '../../../../../../../common';
import { WithAppDependencies } from './setup_environment';
import { ComponentTemplateList } from '../../../component_template_list/component_template_list';

const testBedConfig: AsyncTestBedConfig = {
const getTestBedConfig = (props?: any): AsyncTestBedConfig => ({
memoryRouter: {
initialEntries: [`${BASE_PATH}component_templates`],
componentRoutePath: `${BASE_PATH}component_templates`,
},
doMountAsync: true,
};
defaultProps: props,
});

export type ComponentTemplateListTestBed = TestBed<ComponentTemplateTestSubjects> & {
actions: ReturnType<typeof createActions>;
Expand Down Expand Up @@ -73,18 +74,26 @@ const createActions = (testBed: TestBed) => {
deleteButton.simulate('click');
};

const getSearchValue = () => {
return find('componentTemplatesSearch').prop('defaultValue');
};

return {
clickReloadButton,
clickComponentTemplateAt,
clickDeleteActionAt,
clickTableColumnSortButton,
getSearchValue,
};
};

export const setup = async (httpSetup: HttpSetup): Promise<ComponentTemplateListTestBed> => {
export const setup = async (
httpSetup: HttpSetup,
props?: any
): Promise<ComponentTemplateListTestBed> => {
const initTestBed = registerTestBed(
WithAppDependencies(ComponentTemplateList, httpSetup),
testBedConfig
getTestBedConfig(props)
);
const testBed = await initTestBed();

Expand All @@ -104,7 +113,8 @@ export type ComponentTemplateTestSubjects =
| 'sectionLoading'
| 'componentTemplatesLoadError'
| 'deleteComponentTemplateButton'
| 'deprecatedComponentTemplateBadge'
| 'reloadButton'
| 'componentTemplatesSearch'
| 'deprecatedComponentTemplateBadge'
| 'componentTemplatesFiltersButton'
| 'componentTemplates--deprecatedFilter';
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ import { useRedirectPath } from '../../../hooks/redirect_path';
interface Props {
componentTemplateName?: string;
history: RouteComponentProps['history'];
filter?: string;
}

const { useGlobalFlyout } = GlobalFlyout;

export const ComponentTemplateList: React.FunctionComponent<Props> = ({
componentTemplateName,
history,
filter,
}) => {
const { addContent: addContentToGlobalFlyout, removeContent: removeContentFromGlobalFlyout } =
useGlobalFlyout();
Expand Down Expand Up @@ -183,6 +185,7 @@ export const ComponentTemplateList: React.FunctionComponent<Props> = ({

<ComponentTable
componentTemplates={data}
defaultFilter={filter ?? ''}
onReloadClick={resendRequest}
onDeleteClick={setComponentTemplatesToDelete}
onEditClick={goToEditComponentTemplate}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import React from 'react';
import { RouteComponentProps } from 'react-router-dom';

import qs from 'query-string';
import { useExecutionContext } from '../shared_imports';
import { useComponentTemplatesContext } from '../component_templates_context';
import { ComponentTemplatesAuthProvider } from './auth_provider';
Expand All @@ -24,6 +25,7 @@ export const ComponentTemplateListContainer: React.FunctionComponent<
match: {
params: { componentTemplateName },
},
location,
history,
}) => {
const { executionContext } = useComponentTemplatesContext();
Expand All @@ -33,10 +35,17 @@ export const ComponentTemplateListContainer: React.FunctionComponent<
page: 'indexManagementComponentTemplatesTab',
});

const urlParams = qs.parse(location.search);
const filter = urlParams.filter ?? '';

return (
<ComponentTemplatesAuthProvider>
<ComponentTemplatesWithPrivileges>
<ComponentTemplateList componentTemplateName={componentTemplateName} history={history} />
<ComponentTemplateList
componentTemplateName={componentTemplateName}
history={history}
filter={String(filter)}
/>
</ComponentTemplatesWithPrivileges>
</ComponentTemplatesAuthProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const deprecatedFilterLabel = i18n.translate(

export interface Props {
componentTemplates: ComponentTemplateListItem[];
defaultFilter: string;
onReloadClick: () => void;
onDeleteClick: (componentTemplateName: string[]) => void;
onEditClick: (componentTemplateName: string) => void;
Expand All @@ -60,6 +61,7 @@ export interface Props {

export const ComponentTable: FunctionComponent<Props> = ({
componentTemplates,
defaultFilter,
onReloadClick,
onDeleteClick,
onEditClick,
Expand Down Expand Up @@ -188,6 +190,7 @@ export const ComponentTable: FunctionComponent<Props> = ({
],
box: {
incremental: true,
'data-test-subj': 'componentTemplatesSearch',
},
filters: [
{
Expand Down Expand Up @@ -220,6 +223,7 @@ export const ComponentTable: FunctionComponent<Props> = ({
},
},
],
defaultQuery: defaultFilter,
},
pagination: {
initialPageSize: 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import { UseRequestResponse, reactRouterNavigate } from '../../../../../shared_i
import { useServices } from '../../../../app_context';
import { TemplateDeleteModal } from '../../../../components';
import { TemplateContentIndicator } from '../../../../components/shared';
import { getComponentTemplatesLink, getTemplateDetailsLink } from '../../../../services/routing';
import { TemplateTypeIndicator, TemplateDeprecatedBadge } from '../components';
import { getTemplateDetailsLink } from '../../../../services/routing';

interface Props {
templates: TemplateListItem[];
Expand Down Expand Up @@ -85,12 +85,24 @@ export const TemplateTable: React.FunctionComponent<Props> = ({
{
field: 'composedOf',
name: i18n.translate('xpack.idxMgmt.templateList.table.componentsColumnTitle', {
defaultMessage: 'Components',
defaultMessage: 'Component templates',
}),
width: '100px',
truncateText: true,
sortable: true,
width: '20%',
render: (composedOf: string[] = []) => <span>{composedOf.join(', ')}</span>,
sortable: (template) => {
return template.composedOf?.length;
},
render: (composedOf: string[] = [], item: TemplateListItem) =>
composedOf.length === 0 ? (
<span>0</span>
) : (
<EuiLink
data-test-subj="componentTemplatesLink"
{...reactRouterNavigate(history, getComponentTemplatesLink(item.name))}
>
{composedOf.length}
</EuiLink>
),
},
{
name: i18n.translate('xpack.idxMgmt.templateList.table.dataStreamColumnTitle', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,12 @@ export const getIndexDetailsLink = (
}
return link;
};

export const getComponentTemplatesLink = (usedByTemplateName?: string) => {
let url = '/component_templates';
if (usedByTemplateName) {
const filter = `usedBy=(${usedByTemplateName})`;
url = `${url}?filter=${encodeURIComponent(filter)}`;
}
return url;
};
2 changes: 2 additions & 0 deletions x-pack/plugins/index_management/test/fixtures/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const getComposableTemplate = ({
isLegacy = false,
type = 'default',
allowAutoCreate = false,
composedOf = [],
}: Partial<
TemplateDeserialized & {
isLegacy?: boolean;
Expand Down Expand Up @@ -53,6 +54,7 @@ export const getComposableTemplate = ({
hasDatastream,
isLegacy,
},
composedOf,
};

return indexTemplate;
Expand Down

0 comments on commit 7a55b8c

Please sign in to comment.