Skip to content

Commit

Permalink
Clean up old data streams code
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Jun 2, 2020
1 parent dc5470a commit 20f9649
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,13 @@ export const getFilteredIndices = createSelector(
(indices, allIds, tableState, tableLocation) => {
let indexArray = allIds.map((indexName) => indices[indexName]);
indexArray = filterByToggles(indexArray, tableState.toggleNameToVisibleMap);
const { includeHiddenIndices: includeHiddenParam, dataStreams: dataStreamsParam } = qs.parse(
tableLocation.search
);
const { includeHiddenIndices: includeHiddenParam } = qs.parse(tableLocation.search);
const includeHidden = includeHiddenParam === 'true';
const dataStreamsFilter = dataStreamsParam ? dataStreamsParam.split(',') : undefined;
const shouldFilterDataStreams = Boolean(dataStreamsFilter && dataStreamsFilter.length);
const filteredIndices = indexArray.filter((index) => {
let include = true;
if (!includeHidden) {
include = !(index.name + '').startsWith('.') && !index.hidden;
}

if (include && shouldFilterDataStreams) {
return dataStreamsFilter.includes(index.dataStream);
}

return include;
});
const filteredIndices = includeHidden
? indexArray
: indexArray.filter((index) => {
return !(index.name + '').startsWith('.') && !index.hidden;
});
const filter = tableState.filter || EuiSearchBar.Query.MATCH_ALL;
return EuiSearchBar.Query.execute(filter, filteredIndices, {
defaultFields: defaultFilterFields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ describe('getFilteredIndices selector', () => {
tableState: { ...defaultTableState },
indices: {
byId: {
test: { name: 'index1', hidden: true, dataStream: '123' },
test: { name: 'index1', hidden: true },
anotherTest: { name: 'index2', hidden: false },
aTest: { name: 'index3', dataStream: 'abc' },
aTest: { name: 'index3' },
aFinalTest: { name: '.index4' },
},
allIds: ['test', 'anotherTest', 'aTest', 'aFinalTest'],
Expand All @@ -32,37 +32,18 @@ describe('getFilteredIndices selector', () => {
it('filters out hidden indices', () => {
expect(getFilteredIndices(state, { location: { search: '' } })).toEqual([
{ name: 'index2', hidden: false },
{ name: 'index3', dataStream: 'abc' },
{ name: 'index3' },
]);
});

it('includes hidden indices', () => {
expect(
getFilteredIndices(state, { location: { search: '?includeHiddenIndices=true' } })
).toEqual([
{ name: 'index1', hidden: true, dataStream: '123' },
{ name: 'index1', hidden: true },
{ name: 'index2', hidden: false },
{ name: 'index3', dataStream: 'abc' },
{ name: 'index3' },
{ name: '.index4' },
]);
});

it('filters based on data stream', () => {
expect(getFilteredIndices(state, { location: { search: '?dataStreams=abc' } })).toEqual([
// We don't expect to see a case like this in the wild because data stream backing indicies
// are always hidden, but our logic can handle it
{ name: 'index3', dataStream: 'abc' },
]);
});

it('filters based on data stream and includes hidden indices', () => {
expect(
getFilteredIndices(state, {
location: { search: '?includeHiddenIndices=true&dataStreams=123,abc,does-not-exist' },
})
).toEqual([
{ name: 'index1', hidden: true, dataStream: '123' },
{ name: 'index3', dataStream: 'abc' },
]);
});
});

0 comments on commit 20f9649

Please sign in to comment.