Skip to content

Commit

Permalink
Merge branch 'main' of github.com:elastic/kibana into feat/149917-slo…
Browse files Browse the repository at this point in the history
…-cloning
  • Loading branch information
CoenWarmer committed Jan 31, 2023
2 parents 285b98c + a63404c commit 475b7b5
Show file tree
Hide file tree
Showing 65 changed files with 12,320 additions and 286 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const cspRuleTemplateMetadataSchemaV870 = rt.object({
id: rt.string(),
version: rt.string(),
rule_number: rt.maybe(rt.string()),
posture_type: rt.maybe(rt.string()),
}),
default_value: rt.maybe(rt.string()),
description: rt.string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,19 @@ function migrateCspRuleTemplatesToV870(
): SavedObjectUnsanitizedDoc<CspRuleTemplateV870> {
// Keeps only metadata, deprecated state
const { muted, enabled, ...attributes } = doc.attributes;

return {
...doc,
attributes,
attributes: {
metadata: {
...attributes.metadata,
benchmark: {
...attributes.metadata.benchmark,
// CSPM introduced in 8.7, so we can assume all docs from 8.4.0 are KSPM
posture_type: 'kspm',
},
},
},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,7 @@ describe('<FollowerIndicesList />', () => {
});
});

// FLAKY: https://github.com/elastic/kibana/issues/142774
describe.skip('detail panel', () => {
describe('detail panel', () => {
test('should open a detail panel when clicking on a follower index', async () => {
expect(exists('followerIndexDetail')).toBe(false);

Expand All @@ -334,7 +333,7 @@ describe('<FollowerIndicesList />', () => {
test('should have a "settings" section', async () => {
await actions.clickFollowerIndexAt(0);
expect(find('followerIndexDetail.settingsSection').find('h3').text()).toEqual('Settings');
expect(exists('followerIndexDetail.settingsValues')).toBe(true);
expect(find('followerIndexDetail.settingsValues').length).toBe(10);
});

test('should set the correct follower index settings values', async () => {
Expand Down
16 changes: 11 additions & 5 deletions x-pack/plugins/enterprise_search/common/types/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
* 2.0.
*/

export interface Page {
from: number; // current page index, 0-based
has_more_hits_than_total?: boolean;
size: number; // size per page
total: number; // total number of hits
}
export interface Meta {
page: Page;
}

export interface Paginate<T> {
_meta: Meta;
data: T[];
has_more_hits_than_total: boolean;
pageIndex: number;
pageSize: number;
size: number;
total: number;
}
2 changes: 1 addition & 1 deletion x-pack/plugins/enterprise_search/jest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ fi
# @see https://jestjs.io/docs/en/cli#options
ARGS="${*:2}"

yarn test:jest $TARGET $ARGS
TZ="Etc/UTC" yarn test:jest $TARGET $ARGS
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ describe('FetchSyncJobs', () => {
await nextTick();
expect(http.get).toHaveBeenCalledWith(
'/internal/enterprise_search/connectors/connectorId1/sync_jobs',
{ query: { page: 0, size: 10 } }
{ query: { from: 0, size: 10 } }
);
await expect(result).resolves.toEqual('result');
});
it('appends query if specified', async () => {
const promise = Promise.resolve('result');
http.get.mockReturnValue(promise);
const result = fetchSyncJobs({ connectorId: 'connectorId1', page: 10, size: 20 });
const result = fetchSyncJobs({ connectorId: 'connectorId1', from: 10, size: 20 });
await nextTick();
expect(http.get).toHaveBeenCalledWith(
'/internal/enterprise_search/connectors/connectorId1/sync_jobs',
{ query: { page: 10, size: 20 } }
{ query: { from: 10, size: 20 } }
);
await expect(result).resolves.toEqual('result');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import { HttpLogic } from '../../../shared/http';

export interface FetchSyncJobsArgs {
connectorId: string;
page?: number;
from?: number;
size?: number;
}

export type FetchSyncJobsResponse = Paginate<ConnectorSyncJob>;

export const fetchSyncJobs = async ({ connectorId, page = 0, size = 10 }: FetchSyncJobsArgs) => {
export const fetchSyncJobs = async ({ connectorId, from = 0, size = 10 }: FetchSyncJobsArgs) => {
const route = `/internal/enterprise_search/connectors/${connectorId}/sync_jobs`;
const query = { page, size };
const query = { from, size };
return await HttpLogic.values.http.get<Paginate<ConnectorSyncJob>>(route, { query });
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
*/

import { EnterpriseSearchEnginesResponse } from '../../../../../common/types/engines';
import { Page } from '../../../../../common/types/pagination';

import { createApiLogic } from '../../../shared/api_logic/create_api_logic';
import { HttpLogic } from '../../../shared/http';

import { Meta } from '../../components/engines/types';

export interface EnginesListAPIArguments {
meta: Meta;
meta: Page;
searchQuery?: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,23 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';

import { EnterpriseSearchEngine } from '../../../../../../../common/types/engines';
import { Page } from '../../../../../../../common/types/pagination';

import { MANAGE_BUTTON_LABEL } from '../../../../../shared/constants';

import { generateEncodedPath } from '../../../../../shared/encode_path_params';
import { FormattedDateTime } from '../../../../../shared/formatted_date_time';
import { KibanaLogic } from '../../../../../shared/kibana';
import { pageToPagination } from '../../../../../shared/pagination/page_to_pagination';
import { EuiLinkTo } from '../../../../../shared/react_router_helpers';

import { ENGINE_PATH } from '../../../../routes';

import { convertMetaToPagination, Meta } from '../../types';

interface EnginesListTableProps {
enginesList: EnterpriseSearchEngine[];
isLoading?: boolean;
loading: boolean;
meta: Meta;
meta: Page;
onChange: (criteria: CriteriaWithPagination<EnterpriseSearchEngine>) => void;
onDelete: (engine: EnterpriseSearchEngine) => void;
viewEngineIndices: (engineName: string) => void;
Expand Down Expand Up @@ -157,7 +158,7 @@ export const EnginesListTable: React.FC<EnginesListTableProps> = ({
<EuiBasicTable
items={enginesList}
columns={columns}
pagination={{ ...convertMetaToPagination(meta), showPerPageOptions: false }}
pagination={{ ...pageToPagination(meta), showPerPageOptions: false }}
onChange={onChange}
loading={isLoading}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
EnterpriseSearchEngine,
EnterpriseSearchEnginesResponse,
} from '../../../../../common/types/engines';
import { Page } from '../../../../../common/types/pagination';

import { Actions } from '../../../shared/api_logic/create_api_logic';

Expand All @@ -26,7 +27,7 @@ import {
FetchEnginesAPILogic,
} from '../../api/engines/fetch_engines_api_logic';

import { DEFAULT_META, Meta, updateMetaPageIndex } from './types';
import { DEFAULT_META, updateMetaPageIndex } from './types';

interface EuiBasicTableOnChange {
page: { index: number };
Expand Down Expand Up @@ -58,8 +59,8 @@ interface EngineListValues {
isDeleteLoading: boolean;
isDeleteModalVisible: boolean;
isLoading: boolean;
meta: Meta;
parameters: { meta: Meta; searchQuery?: string }; // Added this variable to store to the search Query value as well
meta: Page;
parameters: { meta: Page; searchQuery?: string }; // Added this variable to store to the search Query value as well
results: EnterpriseSearchEngine[]; // stores engine list value from data
searchQuery: string;
status: typeof FetchEnginesAPILogic.values.status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,14 @@
* 2.0.
*/

export interface Meta {
from: number;
size: number;
total: number;
}
import { Page } from '../../../../../common/types/pagination';

export const DEFAULT_META = {
from: 0,
size: 10,
total: 0,
};

export const convertMetaToPagination = (meta: Meta) => {
return {
pageIndex: meta.from / meta.size,
pageSize: meta.size,
totalItemCount: meta.total,
};
};
export const updateMetaPageIndex = (oldState: Meta, newPageIndex: number) => {
export const updateMetaPageIndex = (oldState: Page, newPageIndex: number) => {
return { ...oldState, from: newPageIndex * oldState.size };
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { i18n } from '@kbn/i18n';
import { SyncStatus } from '../../../../../../common/types/connectors';

import { FormattedDateTime } from '../../../../shared/formatted_date_time';
import { pageToPagination } from '../../../../shared/pagination/page_to_pagination';
import { durationToText } from '../../../utils/duration_to_text';

import { syncStatusToColor, syncStatusToText } from '../../../utils/sync_status_to_text';
Expand All @@ -35,8 +36,8 @@ export const SyncJobs: React.FC = () => {
if (connectorId) {
fetchSyncJobs({
connectorId,
page: syncJobsPagination.pageIndex ?? 0,
size: syncJobsPagination.pageSize ?? 10,
from: syncJobsPagination.from ?? 0,
size: syncJobsPagination.size ?? 10,
});
}
}, [connectorId]);
Expand Down Expand Up @@ -119,13 +120,10 @@ export const SyncJobs: React.FC = () => {
hasActions
onChange={({ page: { index, size } }: { page: { index: number; size: number } }) => {
if (connectorId) {
fetchSyncJobs({ connectorId, page: index, size });
fetchSyncJobs({ connectorId, from: index * size, size });
}
}}
pagination={{
...syncJobsPagination,
totalItemCount: syncJobsPagination.total,
}}
pagination={pageToPagination(syncJobsPagination)}
tableLayout="fixed"
loading={syncJobsLoading}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ const DEFAULT_VALUES = {
syncJobsData: undefined,
syncJobsLoading: true,
syncJobsPagination: {
data: [],
from: 0,
has_more_hits_than_total: false,
pageIndex: 0,
pageSize: 10,
size: 0,
size: 10,
total: 0,
},
syncJobsStatus: Status.IDLE,
Expand Down Expand Up @@ -93,30 +91,35 @@ describe('SyncJobsViewLogic', () => {
};
it('should update values', async () => {
FetchSyncJobsApiLogic.actions.apiSuccess({
_meta: {
page: {
from: 40,
has_more_hits_than_total: false,
size: 20,
total: 50,
},
},
data: [syncJob],
has_more_hits_than_total: false,
pageIndex: 3,
pageSize: 20,
size: 20,
total: 50,
});
await nextTick();
expect(SyncJobsViewLogic.values).toEqual({
...DEFAULT_VALUES,
syncJobs: [syncJobView],
syncJobsData: {
_meta: {
page: {
from: 40,
has_more_hits_than_total: false,
size: 20,
total: 50,
},
},
data: [syncJob],
has_more_hits_than_total: false,
pageIndex: 3,
pageSize: 20,
size: 20,
total: 50,
},
syncJobsLoading: false,
syncJobsPagination: {
from: 40,
has_more_hits_than_total: false,
pageIndex: 3,
pageSize: 20,
size: 20,
total: 50,
},
Expand All @@ -125,6 +128,14 @@ describe('SyncJobsViewLogic', () => {
});
it('should update values for incomplete job', async () => {
FetchSyncJobsApiLogic.actions.apiSuccess({
_meta: {
page: {
from: 40,
has_more_hits_than_total: false,
size: 20,
total: 50,
},
},
data: [
{
...syncJob,
Expand All @@ -133,11 +144,6 @@ describe('SyncJobsViewLogic', () => {
status: SyncStatus.IN_PROGRESS,
},
],
has_more_hits_than_total: false,
pageIndex: 3,
pageSize: 20,
size: 20,
total: 50,
});
await nextTick();
expect(SyncJobsViewLogic.values).toEqual({
Expand All @@ -153,6 +159,14 @@ describe('SyncJobsViewLogic', () => {
},
],
syncJobsData: {
_meta: {
page: {
from: 40,
has_more_hits_than_total: false,
size: 20,
total: 50,
},
},
data: [
{
...syncJob,
Expand All @@ -161,17 +175,11 @@ describe('SyncJobsViewLogic', () => {
status: SyncStatus.IN_PROGRESS,
},
],
has_more_hits_than_total: false,
pageIndex: 3,
pageSize: 20,
size: 20,
total: 50,
},
syncJobsLoading: false,
syncJobsPagination: {
from: 40,
has_more_hits_than_total: false,
pageIndex: 3,
pageSize: 20,
size: 20,
total: 50,
},
Expand Down
Loading

0 comments on commit 475b7b5

Please sign in to comment.