Skip to content

Commit

Permalink
[Discover] Change the approach
Browse files Browse the repository at this point in the history
  • Loading branch information
jughosta committed Aug 1, 2024
1 parent 4e62f3e commit 02e9fa1
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React, { useCallback, useMemo, useState } from 'react';
import type { DataTableRecord } from '@kbn/discover-utils/types';
import { AggregateQuery, Query } from '@kbn/es-query';
import type { SearchResponseWarning } from '@kbn/search-response-warnings';
import { MAX_DOC_FIELDS_DISPLAYED, ROW_HEIGHT_OPTION, SHOW_MULTIFIELDS } from '@kbn/discover-utils';
import { MAX_DOC_FIELDS_DISPLAYED, SHOW_MULTIFIELDS } from '@kbn/discover-utils';
import {
type UnifiedDataTableProps,
type DataTableColumnsMeta,
Expand Down Expand Up @@ -107,15 +107,13 @@ export function DiscoverGridEmbeddable(props: DiscoverGridEmbeddableProps) {
totalHits={props.totalHitCount}
setExpandedDoc={setExpandedDoc}
expandedDoc={expandedDoc}
configRowHeight={props.services.uiSettings.get(ROW_HEIGHT_OPTION)}
showMultiFields={props.services.uiSettings.get(SHOW_MULTIFIELDS)}
maxDocFieldsDisplayed={props.services.uiSettings.get(MAX_DOC_FIELDS_DISPLAYED)}
renderDocumentView={renderDocumentView}
renderCustomToolbar={renderCustomToolbarWithElements}
externalCustomRenderers={cellRenderers}
enableComparisonMode
showColumnTokens
configHeaderRowHeight={3}
showFullScreenButton={false}
className="unifiedDataTable"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { BehaviorSubject } from 'rxjs';
import type { DataView } from '@kbn/data-views-plugin/common';
import {
DOC_HIDE_TIME_COLUMN_SETTING,
isLegacyTableEnabled,
SEARCH_FIELDS_FROM_SOURCE,
isLegacyTableEnabled,
} from '@kbn/discover-utils';
import { Filter } from '@kbn/es-query';
import {
Expand All @@ -33,6 +33,7 @@ import { SEARCH_EMBEDDABLE_CELL_ACTIONS_TRIGGER_ID } from '../constants';
import { isEsqlMode } from '../initialize_fetch';
import type { SearchEmbeddableApi, SearchEmbeddableStateManager } from '../types';
import { DiscoverGridEmbeddable } from './saved_search_grid';
import { getSearchEmbeddableDefaults } from '../get_search_embeddable_defaults';

interface SavedSearchEmbeddableComponentProps {
api: SearchEmbeddableApi & { fetchWarnings$: BehaviorSubject<SearchResponseIncompleteWarning[]> };
Expand Down Expand Up @@ -144,13 +145,15 @@ export function SearchEmbeddableGridComponent({
return getAllowedSampleSize(savedSearch.sampleSize, discoverServices.uiSettings);
}, [savedSearch.sampleSize, discoverServices]);

const defaults = getSearchEmbeddableDefaults(discoverServices.uiSettings);

const sharedProps = {
columns: savedSearch.columns ?? [],
dataView,
interceptedWarnings,
onFilter: onAddFilter,
rows,
rowsPerPageState: savedSearch.rowsPerPage,
rowsPerPageState: savedSearch.rowsPerPage ?? defaults.rowsPerPage,
sampleSizeState: fetchedSampleSize,
searchDescription: panelDescription || savedSearchDescription,
sort,
Expand Down Expand Up @@ -179,12 +182,14 @@ export function SearchEmbeddableGridComponent({
ariaLabelledBy={'documentsAriaLabel'}
cellActionsTriggerId={SEARCH_EMBEDDABLE_CELL_ACTIONS_TRIGGER_ID}
columnsMeta={columnsMeta}
configHeaderRowHeight={defaults.headerRowHeight}
configRowHeight={defaults.rowHeight}
headerRowHeightState={savedSearch.headerRowHeight}
rowHeightState={savedSearch.rowHeight}
isPlainRecord={isEsql}
loadingState={Boolean(loading) ? DataLoadingState.loading : DataLoadingState.loaded}
maxAllowedSampleSize={getMaxAllowedSampleSize(discoverServices.uiSettings)}
query={savedSearch.searchSource.getField('query')}
rowHeightState={savedSearch.rowHeight}
savedSearchId={savedSearchId}
searchTitle={panelTitle || savedSearchTitle}
services={discoverServices}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { IUiSettingsClient } from '@kbn/core/public';
import { ROW_HEIGHT_OPTION, SAMPLE_SIZE_SETTING } from '@kbn/discover-utils';
import { getDefaultRowsPerPage } from '../../common/constants';
import { DEFAULT_HEADER_ROW_HEIGHT_LINES } from './constants';

export interface SearchEmbeddableDefaults {
rowHeight: number | undefined;
headerRowHeight: number | undefined;
rowsPerPage: number | undefined;
sampleSize: number | undefined;
}

export const getSearchEmbeddableDefaults = (
uiSettings: IUiSettingsClient
): SearchEmbeddableDefaults => {
return {
rowHeight: uiSettings.get(ROW_HEIGHT_OPTION),
headerRowHeight: DEFAULT_HEADER_ROW_HEIGHT_LINES,
rowsPerPage: getDefaultRowsPerPage(uiSettings),
sampleSize: uiSettings.get(SAMPLE_SIZE_SETTING),
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { BehaviorSubject, combineLatest, map, Observable, skip } from 'rxjs';

import { ISearchSource, SerializedSearchSourceFields } from '@kbn/data-plugin/common';
import { DataView } from '@kbn/data-views-plugin/common';
import { ROW_HEIGHT_OPTION, SAMPLE_SIZE_SETTING } from '@kbn/discover-utils';
import { DataTableRecord } from '@kbn/discover-utils/types';
import type {
PublishesDataViews,
Expand All @@ -24,9 +23,9 @@ import { SortOrder, VIEW_MODE } from '@kbn/saved-search-plugin/public';
import { DataTableColumnsMeta } from '@kbn/unified-data-table';

import { AggregateQuery, Filter, Query } from '@kbn/es-query';
import { getDefaultRowsPerPage } from '../../common/constants';
import { DiscoverServices } from '../build_services';
import { DEFAULT_HEADER_ROW_HEIGHT_LINES, EDITABLE_SAVED_SEARCH_KEYS } from './constants';
import { EDITABLE_SAVED_SEARCH_KEYS } from './constants';
import { getSearchEmbeddableDefaults } from './get_search_embeddable_defaults';
import {
PublishesSavedSearch,
SearchEmbeddableRuntimeState,
Expand Down Expand Up @@ -85,19 +84,14 @@ export const initializeSearchEmbeddableApi = async (
const searchSource$ = new BehaviorSubject<ISearchSource>(searchSource);
const dataViews = new BehaviorSubject<DataView[] | undefined>(dataView ? [dataView] : undefined);

const defaultHeaderRowHeight = DEFAULT_HEADER_ROW_HEIGHT_LINES;
const defaultRowHeight = discoverServices.uiSettings.get(ROW_HEIGHT_OPTION);
const defaultRowsPerPage = getDefaultRowsPerPage(discoverServices.uiSettings);
const defaultSampleSize = discoverServices.uiSettings.get(SAMPLE_SIZE_SETTING);
const defaults = getSearchEmbeddableDefaults(discoverServices.uiSettings);

/** This is the state that can be initialized from the saved initial state */
const columns$ = new BehaviorSubject<string[] | undefined>(initialState.columns);
const grid$ = new BehaviorSubject<DiscoverGridSettings | undefined>(initialState.grid);
const headerRowHeight$ = new BehaviorSubject<number | undefined>(initialState.headerRowHeight);
const rowHeight$ = new BehaviorSubject<number | undefined>(initialState.rowHeight);
const rowsPerPage$ = new BehaviorSubject<number | undefined>(
initialState.rowsPerPage ?? defaultRowsPerPage
);
const rowsPerPage$ = new BehaviorSubject<number | undefined>(initialState.rowsPerPage);
const sampleSize$ = new BehaviorSubject<number | undefined>(initialState.sampleSize);
const sort$ = new BehaviorSubject<SortOrder[] | undefined>(initialState.sort);
const savedSearchViewMode$ = new BehaviorSubject<VIEW_MODE | undefined>(initialState.viewMode);
Expand Down Expand Up @@ -178,22 +172,22 @@ export const initializeSearchEmbeddableApi = async (
sampleSize: [
sampleSize$,
(value) => sampleSize$.next(value),
(a, b) => (a ?? defaultSampleSize) === (b ?? defaultSampleSize),
(a, b) => (a ?? defaults.sampleSize) === (b ?? defaults.sampleSize),
],
rowsPerPage: [
rowsPerPage$,
(value) => rowsPerPage$.next(value),
(a, b) => (a ?? defaultRowsPerPage) === (b ?? defaultRowsPerPage),
(a, b) => (a ?? defaults.rowsPerPage) === (b ?? defaults.rowsPerPage),
],
rowHeight: [
rowHeight$,
(value) => rowHeight$.next(value),
(a, b) => (a ?? defaultRowHeight) === (b ?? defaultRowHeight),
(a, b) => (a ?? defaults.rowHeight) === (b ?? defaults.rowHeight),
],
headerRowHeight: [
headerRowHeight$,
(value) => headerRowHeight$.next(value),
(a, b) => (a ?? defaultHeaderRowHeight) === (b ?? defaultHeaderRowHeight),
(a, b) => (a ?? defaults.headerRowHeight) === (b ?? defaults.headerRowHeight),
],

/** The following can't currently be changed from the dashboard */
Expand Down

0 comments on commit 02e9fa1

Please sign in to comment.