Skip to content

Commit

Permalink
[Discover] Respect default column setting (#92137) (#92178)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maja Grubic authored Feb 22, 2021
1 parent 4911540 commit 18d5b27
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import { IUiSettingsClient } from 'src/core/public';
import { isEqual } from 'lodash';
import { SEARCH_FIELDS_FROM_SOURCE, DEFAULT_COLUMNS_SETTING } from '../../../../common';

/**
Expand All @@ -25,9 +26,15 @@ export function handleSourceColumnState<TState extends { columns?: string[] }>(
const defaultColumns = uiSettings.get(DEFAULT_COLUMNS_SETTING);
if (useNewFieldsApi) {
// if fields API is used, filter out the source column
let cleanedColumns = state.columns.filter((column) => column !== '_source');
if (cleanedColumns.length === 0 && !isEqual(defaultColumns, ['_source'])) {
cleanedColumns = defaultColumns;
// defaultColumns could still contain _source
cleanedColumns = cleanedColumns.filter((column) => column !== '_source');
}
return {
...state,
columns: state.columns.filter((column) => column !== '_source'),
columns: cleanedColumns,
};
} else if (state.columns.length === 0) {
// if _source fetching is used and there are no column, switch back to default columns
Expand Down

0 comments on commit 18d5b27

Please sign in to comment.