Skip to content

Commit

Permalink
[Index Management] Fix navigation on the index page (elastic#175456)
Browse files Browse the repository at this point in the history
## Summary

This PR fixes a regression from
elastic#174515: When any tab on the index
details page is clicked, then subsequent tab changes are not possible.
To reproduce: 
1. Open any index on the index details page
2. Click "Mappings" tab to navigate to that tab
3. Click "Settings" to navigate to another tab but nothing happens. 

The bug is caused by the logic to keep url parameters for the indices
list table, but those parameters already include `tab` which should be
reset before any further navigation is possible.


### 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—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)
  • Loading branch information
yuliacech authored Jan 25, 2024
1 parent f2fb3ee commit 4b200f6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ describe('<IndexDetailsPage />', () => {
expect(header).toEqual(testIndexName);
});

it('changes the tab when its header is clicked', async () => {
await testBed.actions.clickIndexDetailsTab(IndexDetailsSection.Mappings);
expect(testBed.exists('indexDetailsMappingsCodeBlock')).toBe(true);
await testBed.actions.clickIndexDetailsTab(IndexDetailsSection.Settings);
expect(testBed.exists('indexDetailsSettingsCodeBlock')).toBe(true);
});

describe('Overview tab', () => {
it('updates the breadcrumbs to index details overview', async () => {
expect(breadcrumbService.setBreadcrumbs).toHaveBeenLastCalledWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
*/

import React, { useCallback, useEffect, useMemo, useState, FunctionComponent } from 'react';
import qs from 'query-string';
import { RouteComponentProps } from 'react-router-dom';
import { FormattedMessage } from '@kbn/i18n-react';
import { EuiPageTemplate, EuiText, EuiCode } from '@elastic/eui';
import { SectionLoading } from '@kbn/es-ui-shared-plugin/public';

import { resetIndexUrlParams } from './reset_index_url_params';
import {
IndexDetailsSection,
IndexDetailsTabId,
Expand All @@ -35,10 +35,7 @@ export const DetailsPage: FunctionComponent<
const [index, setIndex] = useState<Index | null>();

const navigateToIndicesList = useCallback(() => {
const indicesListParams = qs.parse(search);
delete indicesListParams.indexName;
delete indicesListParams.tab;
const paramsString = qs.stringify(indicesListParams);
const paramsString = resetIndexUrlParams(search);
history.push(`/${Section.Indices}${paramsString ? '?' : ''}${paramsString}`);
}, [history, search]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { css } from '@emotion/react';
import { FormattedMessage } from '@kbn/i18n-react';
import { RouteComponentProps } from 'react-router-dom';

import { resetIndexUrlParams } from './reset_index_url_params';
import { renderBadges } from '../../../../lib/render_badges';
import { Index } from '../../../../../../common';
import {
Expand Down Expand Up @@ -113,7 +114,7 @@ export const DetailsPageContent: FunctionComponent<Props> = ({

const onSectionChange = useCallback(
(newSection: IndexDetailsTabId) => {
return history.push(getIndexDetailsLink(index.name, search, newSection));
return history.push(getIndexDetailsLink(index.name, resetIndexUrlParams(search), newSection));
},
[history, index.name, search]
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import qs from 'query-string';

export const resetIndexUrlParams = (search: string): string => {
const indicesListParams = qs.parse(search);
delete indicesListParams.indexName;
delete indicesListParams.tab;
return qs.stringify(indicesListParams);
};

0 comments on commit 4b200f6

Please sign in to comment.