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

[Logs Explorer] Update DataGrid default preferences #165718

Merged
Merged
Show file tree
Hide file tree
Changes from 10 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
1 change: 1 addition & 0 deletions packages/kbn-unified-data-table/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
export { UnifiedDataTable, DataLoadingState } from './src/components/data_table';
export type { UnifiedDataTableProps } from './src/components/data_table';
export { getDisplayedColumns } from './src/utils/columns';
export { ROWS_HEIGHT_OPTIONS } from './src/constants';

export { JSONCodeEditorCommonMemoized } from './src/components/json_code_editor/json_code_editor_common';

Expand Down
11 changes: 11 additions & 0 deletions packages/kbn-unified-data-table/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ export const DEFAULT_ROWS_PER_PAGE = 100;
export const MAX_LOADED_GRID_ROWS = 10000;

export const ROWS_PER_PAGE_OPTIONS = [10, 25, 50, DEFAULT_ROWS_PER_PAGE, 250, 500];
/**
* Row height might be a value from -1 to 20
* A value of -1 automatically adjusts the row height to fit the contents.
* A value of 0 displays the content in a single line.
* A value from 1 to 20 represents number of lines of Document explorer row to display.
*/
export const ROWS_HEIGHT_OPTIONS = {
auto: -1,
single: 0,
default: 3,
};

export const defaultMonacoEditorWidth = 370;
export const defaultTimeColumnWidth = 210;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getStoredRowHeight,
updateStoredRowHeight,
} from '../utils/row_heights';
import { ROWS_HEIGHT_OPTIONS } from '../constants';

interface UseRowHeightProps {
rowHeightState?: number;
Expand All @@ -24,36 +25,26 @@ interface UseRowHeightProps {
consumer: string;
}

/**
* Row height might be a value from -1 to 20
* A value of -1 automatically adjusts the row height to fit the contents.
* A value of 0 displays the content in a single line.
* A value from 1 to 20 represents number of lines of Document explorer row to display.
*/
const SINGLE_ROW_HEIGHT_OPTION = 0;
const AUTO_ROW_HEIGHT_OPTION = -1;
const DEFAULT_ROW_HEIGHT_OPTION = 3;

/**
* Converts rowHeight of EuiDataGrid to rowHeight number (-1 to 20)
*/
const serializeRowHeight = (rowHeight?: EuiDataGridRowHeightOption): number => {
if (rowHeight === 'auto') {
return AUTO_ROW_HEIGHT_OPTION;
return ROWS_HEIGHT_OPTIONS.auto;
} else if (typeof rowHeight === 'object' && rowHeight.lineCount) {
return rowHeight.lineCount; // custom
}

return SINGLE_ROW_HEIGHT_OPTION;
return ROWS_HEIGHT_OPTIONS.single;
};

/**
* Converts rowHeight number (-1 to 20) of EuiDataGrid rowHeight
*/
const deserializeRowHeight = (number: number): EuiDataGridRowHeightOption | undefined => {
if (number === AUTO_ROW_HEIGHT_OPTION) {
if (number === ROWS_HEIGHT_OPTIONS.auto) {
return 'auto';
} else if (number === SINGLE_ROW_HEIGHT_OPTION) {
} else if (number === ROWS_HEIGHT_OPTIONS.single) {
return undefined;
}

Expand All @@ -64,7 +55,7 @@ export const useRowHeightsOptions = ({
rowHeightState,
onUpdateRowHeight,
storage,
configRowHeight = DEFAULT_ROW_HEIGHT_OPTION,
configRowHeight = ROWS_HEIGHT_OPTIONS.default,
consumer,
}: UseRowHeightProps) => {
return useMemo((): EuiDataGridRowHeightsOptions => {
Expand Down
13 changes: 13 additions & 0 deletions x-pack/plugins/log_explorer/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,17 @@ export const LOG_EXPLORER_PROFILE_ID = 'log-explorer';

// Fields constants
export const TIMESTAMP_FIELD = '@timestamp';
export const HOST_NAME_FIELD = 'host.name';
export const MESSAGE_FIELD = 'message';
export const SERVICE_NAME_FIELD = 'service.name';

// Sizing
export const DATA_GRID_COLUMN_WIDTH_SMALL = 240;
export const DATA_GRID_COLUMN_WIDTH_MEDIUM = 320;

// UI preferences
export const DATA_GRID_DEFAULT_COLUMNS = [SERVICE_NAME_FIELD, HOST_NAME_FIELD, MESSAGE_FIELD];
export const DATA_GRID_COLUMNS_PREFERENCES = {
[HOST_NAME_FIELD]: { width: DATA_GRID_COLUMN_WIDTH_MEDIUM },
[SERVICE_NAME_FIELD]: { width: DATA_GRID_COLUMN_WIDTH_SMALL },
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
import { InvokeCreator } from 'xstate';
import { pick, mapValues } from 'lodash';
import deepEqual from 'fast-deep-equal';
import { DiscoverStateContainer } from '@kbn/discover-plugin/public';
import { DiscoverAppState, DiscoverStateContainer } from '@kbn/discover-plugin/public';
import type { DataView } from '@kbn/data-views-plugin/public';
import { MESSAGE_FIELD } from '../../../../common/constants';
import { ROWS_HEIGHT_OPTIONS } from '@kbn/unified-data-table';
import {
DATA_GRID_COLUMNS_PREFERENCES,
DATA_GRID_DEFAULT_COLUMNS,
} from '../../../../common/constants';
import {
AllDatasetSelection,
decodeDatasetSelectionId,
Expand Down Expand Up @@ -178,14 +182,27 @@ export const updateStateContainer =
LogExplorerProfileEvent
> =>
async () => {
const { columns } = stateContainer.appState.getState();
const { columns, grid, rowHeight } = stateContainer.appState.getState();
const stateUpdates: DiscoverAppState = {};

// Update data grid columns list
const shouldSetDefaultColumns =
stateContainer.appState.isEmptyURL() || !columns || columns.length === 0;

if (shouldSetDefaultColumns) {
stateContainer.appState.update({ columns: [MESSAGE_FIELD] }, true);
stateUpdates.columns = DATA_GRID_DEFAULT_COLUMNS;
}

// Configure DataGrid columns preferences
const initialColumnsPreferences = grid?.columns ?? {};
stateUpdates.grid = {
columns: { ...DATA_GRID_COLUMNS_PREFERENCES, ...initialColumnsPreferences },
};

// Configure rowHeight preference
stateUpdates.rowHeight = rowHeight ?? ROWS_HEIGHT_OPTIONS.single;

// Finally batch update state app state
stateContainer.appState.update(stateUpdates, true);
};

/**
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/log_explorer/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@kbn/data-plugin",
"@kbn/unified-field-list",
"@kbn/core-application-browser",
"@kbn/unified-data-table",
],
"exclude": ["target/**/*"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import rison from '@kbn/rison';
import querystring from 'querystring';
import { FtrProviderContext } from '../../ftr_provider_context';

const defaultLogColumns = ['@timestamp', 'message'];
const defaultLogColumns = ['@timestamp', 'service.name', 'host.name', 'message'];

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
Expand Down Expand Up @@ -44,7 +44,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.observabilityLogExplorer.navigateTo({
search: querystring.stringify({
_a: rison.encode({
columns: ['message', 'data_stream.namespace'],
columns: ['service.name', 'host.name', 'message', 'data_stream.namespace'],
}),
}),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import rison from '@kbn/rison';
import querystring from 'querystring';
import { FtrProviderContext } from '../../../ftr_provider_context';

const defaultLogColumns = ['@timestamp', 'message'];
const defaultLogColumns = ['@timestamp', 'service.name', 'host.name', 'message'];

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
Expand Down Expand Up @@ -46,7 +46,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.observabilityLogExplorer.navigateTo({
search: querystring.stringify({
_a: rison.encode({
columns: ['message', 'data_stream.namespace'],
columns: ['service.name', 'host.name', 'message', 'data_stream.namespace'],
}),
}),
});
Expand Down