Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DataView] show empty matching sources when no matched index pattern #195537

Merged
merged 14 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { i18n } from '@kbn/i18n';
import useObservable from 'react-use/lib/useObservable';
import { Observable } from 'rxjs';
import { INDEX_PATTERN_TYPE } from '@kbn/data-views-plugin/public';
import { FormattedMessage } from '@kbn/i18n-react';
import { StatusMessage } from './status_message';
import { IndicesList } from './indices_list';
import { matchedIndiciesDefault } from '../../data_view_editor_service';
Expand Down Expand Up @@ -74,7 +75,10 @@ export const PreviewPanel = ({ type, allowHidden, title = '', matchedIndices$ }:
}
/>
) : (
<></>
<FormattedMessage
id="indexPatternEditor.status.notMatchLabel.notMatchNoIndicesDetail"
defaultMessage="The index pattern you entered doesn't match any data streams, indices, or index aliases."
/>
);

return (
Expand All @@ -86,7 +90,7 @@ export const PreviewPanel = ({ type, allowHidden, title = '', matchedIndices$ }:
query={title}
/>
<EuiSpacer size="m" />
{Boolean(title) && currentlyVisibleIndices.length > 0 && (
{Boolean(title) && (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for the contribution @lsq645599166, and apologies for all the back and forth on this. After testing this locally, I think misunderstood the intent of the code originally. I also overlooked @kertal's second comment where he suggested hiding the tabs entirely, but I agree this is actually the best approach.

We already do this before the user has typed anything, and we show the full list of sources:
image

We also intentionally return the full list as visibleIndices from getMatchedIndices when there are no matches because we want the user to see the available options when their pattern doesn't match. It turns out this was behaving as intended, but the confusing part was that the tabs were still visible and "Matching sources" was still selected.

If we hide the tabs when there are no matches as @kertal suggested, it behaves the same as if the user hadn't typed anything, so there's no confusion about the tabs, and they'll still be able to see the available sources:
image

This seems like the least confusing and most consistent behaviour (and matches the original intent). Luckily if we follow the same logic used in src/plugins/data_view_editor/public/components/preview_panel/status_message/status_message.tsx, I think we should be able to revert all changes except for this line in PreviewPanel.

Suggested change
{Boolean(title) && (
{title.length > 0 && (matched.exactMatchedIndices.length > 0 || matched.partialMatchedIndices.length > 0) && (

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I commit a change to hide tab when no matched index.
image

<EuiButtonGroup
isFullWidth
legend={i18n.translate('indexPatternEditor.previewPanel.viewModeGroup.legend', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ describe('getMatchedIndices', () => {
]);
});

it('should return all indices as visible if there are no exact or partial', () => {
it('should return empty array if there are no exact or partial', () => {
const { visibleIndices } = getMatchedIndices(indices, [], [], true);

expect(visibleIndices).toEqual(indices);
expect(visibleIndices).toEqual([]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ export function getMatchedIndices(
// 1) If there are exact matches, show those as the query is good to go
// 2) If there are no exact matches, but there are partial matches,
// show the partial matches
// 3) If there are no exact or partial matches, just show all indices
let visibleIndices;
// 3) If there are no exact or partial matches, show empty indices
let visibleIndices: MatchedItem[];
if (exactMatchedIndices.length) {
visibleIndices = exactMatchedIndices;
} else if (partialMatchedIndices.length) {
visibleIndices = partialMatchedIndices;
} else {
visibleIndices = allIndices;
visibleIndices = [];
}

return {
Expand Down