Skip to content

Commit

Permalink
[Discover][SavedSearch] Fix default rowsPerPage for Dashboard panels
Browse files Browse the repository at this point in the history
  • Loading branch information
jughosta committed Aug 1, 2024
1 parent 7e46462 commit 4e62f3e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,21 @@ 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);

/** 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 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 rowHeight$ = new BehaviorSubject<number | undefined>(initialState.rowHeight);
const rowsPerPage$ = new BehaviorSubject<number | undefined>(
initialState.rowsPerPage ?? defaultRowsPerPage
);
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 +119,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 @@ -190,7 +193,7 @@ export const initializeSearchEmbeddableApi = async (
headerRowHeight: [
headerRowHeight$,
(value) => headerRowHeight$.next(value),
(a, b) => (a ?? DEFAULT_HEADER_ROW_HEIGHT_LINES) === (b ?? DEFAULT_HEADER_ROW_HEIGHT_LINES),
(a, b) => (a ?? defaultHeaderRowHeight) === (b ?? defaultHeaderRowHeight),
],

/** The following can't currently be changed from the dashboard */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,23 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
const kibanaServer = getService('kibanaServer');
const dataGrid = getService('dataGrid');
const PageObjects = getPageObjects(['settings', 'common', 'discover', 'header', 'timePicker']);
const PageObjects = getPageObjects([
'settings',
'common',
'discover',
'header',
'timePicker',
'dashboard',
]);
const defaultSettings = {
defaultIndex: 'logstash-*',
'discover:rowHeightOption': 0, // single line
};
const testSubjects = getService('testSubjects');
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 @@ -118,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);
});
});
}

0 comments on commit 4e62f3e

Please sign in to comment.