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

[Discover][SavedSearch] Fix default rowsPerPage for Dashboard panels #189717

Merged
merged 4 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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 @@ -108,15 +108,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,14 +84,16 @@ export const initializeSearchEmbeddableApi = async (
const searchSource$ = new BehaviorSubject<ISearchSource>(searchSource);
const dataViews = new BehaviorSubject<DataView[] | undefined>(dataView ? [dataView] : undefined);

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);
const headerRowHeight$ = new BehaviorSubject<number | undefined>(initialState.headerRowHeight);
const sort$ = new BehaviorSubject<SortOrder[] | undefined>(initialState.sort);
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 All @@ -112,10 +113,6 @@ export const initializeSearchEmbeddableApi = async (
const columnsMeta$ = new BehaviorSubject<DataTableColumnsMeta | undefined>(undefined);
const totalHitCount$ = new BehaviorSubject<number | undefined>(undefined);

const defaultRowHeight = discoverServices.uiSettings.get(ROW_HEIGHT_OPTION);
const defaultRowsPerPage = getDefaultRowsPerPage(discoverServices.uiSettings);
const defaultSampleSize = discoverServices.uiSettings.get(SAMPLE_SIZE_SETTING);

/**
* The state manager is used to modify the state of the saved search - this should never be
* treated as the source of truth
Expand Down Expand Up @@ -175,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 ?? DEFAULT_HEADER_ROW_HEIGHT_LINES) === (b ?? DEFAULT_HEADER_ROW_HEIGHT_LINES),
(a, b) => (a ?? defaults.headerRowHeight) === (b ?? defaults.headerRowHeight),
],

/** The following can't currently be changed from the dashboard */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const retry = getService('retry');
const security = getService('security');
const dashboardAddPanel = getService('dashboardAddPanel');
const dashboardPanelActions = getService('dashboardPanelActions');

describe('discover data grid pagination', function describeIndexTests() {
before(async () => {
Expand Down Expand Up @@ -126,6 +127,23 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await PageObjects.discover.waitUntilSearchingHasFinished();
expect((await dataGrid.getDocTableRows()).length).to.be(10); // as in the saved search
await dataGrid.checkCurrentRowsPerPageToBe(10);

// should use "rowsPerPage" form the saved search on dashboard
await PageObjects.common.navigateToApp('dashboard');
await PageObjects.dashboard.clickNewDashboard();
await PageObjects.timePicker.setDefaultAbsoluteRange();
await dashboardAddPanel.clickOpenAddPanel();
await dashboardAddPanel.addSavedSearch(savedSearchTitle);
await PageObjects.header.waitUntilLoadingHasFinished();
expect((await dataGrid.getDocTableRows()).length).to.be(10); // as in the saved search
await dataGrid.checkCurrentRowsPerPageToBe(10);

// should use "rowsPerPage" form settings by default on dashboard
await dashboardPanelActions.removePanelByTitle(savedSearchTitle);
await dashboardAddPanel.addSavedSearch('A Saved Search');
await PageObjects.header.waitUntilLoadingHasFinished();
expect((await dataGrid.getDocTableRows()).length).to.be(6); // as in settings
await dataGrid.checkCurrentRowsPerPageToBe(6);
});

it('should not split ES|QL results into pages', async () => {
Expand Down