Skip to content

Commit

Permalink
[BUG][Discover] Allow default columns settings
Browse files Browse the repository at this point in the history
This is a missing functionality
* When user sets up `Default columns` in advanced settings, discover should display
default columns if the selected idp has the columns.
* If selected idp has no such columns, display `_source` column.

Issue Resolve
opensearch-project#5246

Signed-off-by: ananzh <[email protected]>
  • Loading branch information
ananzh committed Oct 10, 2023
1 parent 1e980fa commit 4e05551
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { RootState, DefaultViewState } from '../../../../../data_explorer/public
import { buildColumns } from '../columns';
import * as utils from './common';
import { SortOrder } from '../../../saved_searches/types';
import { PLUGIN_ID } from '../../../../common';
import { DEFAULT_COLUMNS_SETTING, PLUGIN_ID } from '../../../../common';

export interface DiscoverState {
/**
Expand Down Expand Up @@ -57,6 +57,7 @@ const initialState: DiscoverState = {

export const getPreloadedState = async ({
getSavedSearchById,
uiSettings: config,
}: DiscoverServices): Promise<DefaultViewState<DiscoverState>> => {
const preloadedState: DefaultViewState<DiscoverState> = {
state: {
Expand Down Expand Up @@ -86,6 +87,8 @@ export const getPreloadedState = async ({

savedSearchInstance.destroy(); // this instance is no longer needed, will create another one later
}
} else if (config.get(DEFAULT_COLUMNS_SETTING)) {
preloadedState.state.columns = config.get(DEFAULT_COLUMNS_SETTING);
}

return preloadedState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export function filterColumns(
defaultColumns: string[]
) {
const fieldsName = indexPattern?.fields.getAll().map((fld) => fld.name) || [];
const filteredColumns = columns.filter((column) => fieldsName.includes(column));
return filteredColumns.length > 0 ? filteredColumns : defaultColumns;
// combine columns and defaultColumns without duplicates
const combinedColumns = [...new Set([...columns, ...defaultColumns])];
const filteredColumns = combinedColumns.filter((column) => fieldsName.includes(column));
return filteredColumns.length > 0 ? filteredColumns : ['_source'];
}

0 comments on commit 4e05551

Please sign in to comment.