Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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 @@ -19,7 +19,7 @@ export interface DataStreamsTabTestBed extends TestBed<TestSubjects> {
goToDataStreamsList: () => void;
clickEmptyPromptIndexTemplateLink: () => void;
clickIncludeStatsSwitch: () => void;
clickIncludeManagedSwitch: () => void;
toggleViewFilterAt: (index: number) => void;
clickReloadButton: () => void;
clickNameAt: (index: number) => void;
clickIndicesAt: (index: number) => void;
Expand Down Expand Up @@ -82,9 +82,16 @@ export const setup = async (overridingDependencies: any = {}): Promise<DataStrea
find('includeStatsSwitch').simulate('click');
};

const clickIncludeManagedSwitch = () => {
const { find } = testBed;
find('includeManagedSwitch').simulate('click');
const toggleViewFilterAt = (index: number) => {
const { find, component } = testBed;
act(() => {
find('viewButton').simulate('click');
});
component.update();
act(() => {
find('filterItem').at(index).simulate('click');
});
component.update();
};

const clickReloadButton = () => {
Expand Down Expand Up @@ -197,7 +204,7 @@ export const setup = async (overridingDependencies: any = {}): Promise<DataStrea
goToDataStreamsList,
clickEmptyPromptIndexTemplateLink,
clickIncludeStatsSwitch,
clickIncludeManagedSwitch,
toggleViewFilterAt,
clickReloadButton,
clickNameAt,
clickIndicesAt,
Expand Down Expand Up @@ -235,6 +242,7 @@ export const createDataStreamPayload = (dataStream: Partial<DataStream>): DataSt
privileges: {
delete_index: true,
},
hidden: false,
...dataStream,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {
createNonDataStreamIndex,
} from './data_streams_tab.helpers';

const nonBreakingSpace = ' ';

describe('Data Streams tab', () => {
const { server, httpRequestsMockHelpers } = setupEnvironment();
let testBed: DataStreamsTabTestBed;
Expand Down Expand Up @@ -82,6 +84,25 @@ describe('Data Streams tab', () => {
// Assert against the text because the href won't be available, due to dependency upon our core mock.
expect(findEmptyPromptIndexTemplateLink().text()).toBe('Fleet');
});

test('when hidden data streams are filtered by default, the table is rendered empty', async () => {
const hiddenDataStream = createDataStreamPayload({
name: 'hidden-data-stream',
hidden: true,
});
httpRequestsMockHelpers.setLoadDataStreamsResponse([hiddenDataStream]);

testBed = await setup({
plugins: {},
});

await act(async () => {
testBed.actions.goToDataStreamsList();
});

testBed.component.update();
expect(testBed.find('dataStreamTable').text()).toContain('No data streams found');
});
});

describe('when there are data streams', () => {
Expand Down Expand Up @@ -397,7 +418,6 @@ describe('Data Streams tab', () => {
});

describe('managed data streams', () => {
const nonBreakingSpace = ' ';
beforeEach(async () => {
const managedDataStream = createDataStreamPayload({
name: 'managed-data-stream',
Expand Down Expand Up @@ -429,24 +449,49 @@ describe('Data Streams tab', () => {
]);
});

test('turning off "Include managed" switch hides managed data streams', async () => {
const { exists, actions, component, table } = testBed;
test('turning off "managed" filter hides managed data streams', async () => {
const { actions, table } = testBed;
let { tableCellsValues } = table.getMetaData('dataStreamTable');

expect(tableCellsValues).toEqual([
['', `managed-data-stream${nonBreakingSpace}Managed`, 'green', '1', 'Delete'],
['', 'non-managed-data-stream', 'green', '1', 'Delete'],
]);

expect(exists('includeManagedSwitch')).toBe(true);
actions.toggleViewFilterAt(0);

({ tableCellsValues } = table.getMetaData('dataStreamTable'));
expect(tableCellsValues).toEqual([['', 'non-managed-data-stream', 'green', '1', 'Delete']]);
});
});

describe('hidden data streams', () => {
beforeEach(async () => {
const hiddenDataStream = createDataStreamPayload({
name: 'hidden-data-stream',
hidden: true,
});
httpRequestsMockHelpers.setLoadDataStreamsResponse([hiddenDataStream]);

testBed = await setup({
history: createMemoryHistory(),
});
await act(async () => {
actions.clickIncludeManagedSwitch();
testBed.actions.goToDataStreamsList();
});
component.update();
testBed.component.update();
});

({ tableCellsValues } = table.getMetaData('dataStreamTable'));
expect(tableCellsValues).toEqual([['', 'non-managed-data-stream', 'green', '1', 'Delete']]);
test('show hidden data streams when filter is toggled', () => {
const { table, actions } = testBed;

actions.toggleViewFilterAt(1);

const { tableCellsValues } = table.getMetaData('dataStreamTable');

expect(tableCellsValues).toEqual([
['', `hidden-data-stream${nonBreakingSpace}Hidden`, 'green', '1', 'Delete'],
]);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export function deserializeDataStream(dataStreamFromEs: DataStreamFromEs): DataS
maximum_timestamp: maxTimeStamp,
_meta,
privileges,
hidden,
} = dataStreamFromEs;

return {
Expand All @@ -39,6 +40,7 @@ export function deserializeDataStream(dataStreamFromEs: DataStreamFromEs): DataS
maxTimeStamp,
_meta,
privileges,
hidden,
};
}

Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/index_management/common/types/data_streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export interface DataStreamFromEs {
store_size?: string;
maximum_timestamp?: number;
privileges: PrivilegesFromEs;
hidden: boolean;
}

export interface DataStreamIndexFromEs {
Expand All @@ -59,6 +60,7 @@ export interface DataStream {
maxTimeStamp?: number;
_meta?: Meta;
privileges: Privileges;
hidden: boolean;
}

export interface DataStreamIndex {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,34 @@

import { DataStream } from '../../../common';

export const isManagedByIngestManager = (dataStream: DataStream): boolean => {
export const isFleetManaged = (dataStream: DataStream): boolean => {
// TODO check if the wording will change to 'fleet'
Copy link
Contributor

Choose a reason for hiding this comment

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

Were you planning on addressing this TODO as part of this PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll remove this as soon as I get info from the Fleet team :)

return Boolean(dataStream._meta?.managed && dataStream._meta?.managed_by === 'ingest-manager');
};

export const filterDataStreams = (dataStreams: DataStream[]): DataStream[] => {
return dataStreams.filter((dataStream: DataStream) => !isManagedByIngestManager(dataStream));
export const filterDataStreams = (
dataStreams: DataStream[],
visibleTypes: string[]
): DataStream[] => {
return dataStreams.filter((dataStream: DataStream) => {
// include all data streams that are neither hidden nor managed
if (!dataStream.hidden && !isFleetManaged(dataStream)) {
return true;
}
if (dataStream.hidden && visibleTypes.includes('hidden')) {
return true;
}
return isFleetManaged(dataStream) && visibleTypes.includes('managed');
});
};

export const isSelectedDataStreamHidden = (
dataStreams: DataStream[],
selectedDataStreamName?: string
): boolean => {
return (
!!selectedDataStreamName &&
!!dataStreams.find((dataStream: DataStream) => dataStream.name === selectedDataStreamName)
?.hidden
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export { FilterListButton, Filters } from './filter_list_button';
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { useUrlGenerator } from '../../../../services/use_url_generator';
import { getIndexListUri, getTemplateDetailsLink } from '../../../../services/routing';
import { ILM_PAGES_POLICY_EDIT, ILM_URL_GENERATOR_ID } from '../../../../constants';
import { useAppContext } from '../../../../app_context';
import { DataStreamsBadges } from '../data_stream_table/data_stream_badges';

interface DetailsListProps {
details: Array<{
Expand Down Expand Up @@ -269,6 +270,7 @@ export const DataStreamDetailPanel: React.FunctionComponent<Props> = ({
<EuiTitle size="m">
<h2 id="dataStreamDetailPanelTitle" data-test-subj="dataStreamDetailPanelTitle">
{dataStreamName}
{dataStream && <DataStreamsBadges dataStream={dataStream} />}
</h2>
</EuiTitle>
</EuiFlyoutHeader>
Expand Down
Loading