diff --git a/x-pack/plugins/entity_manager/server/lib/entity_client.ts b/x-pack/plugins/entity_manager/server/lib/entity_client.ts
index 67e9f52e32bf5..4e1dd263f9ca3 100644
--- a/x-pack/plugins/entity_manager/server/lib/entity_client.ts
+++ b/x-pack/plugins/entity_manager/server/lib/entity_client.ts
@@ -117,9 +117,7 @@ export class EntityClient {
});
if (!definition) {
- const message = `Unable to find entity definition [${id}]`;
- this.options.logger.error(message);
- throw new EntityDefinitionNotFound(message);
+ throw new EntityDefinitionNotFound(`Unable to find entity definition [${id}]`);
}
this.options.logger.info(
diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/entities_list.test.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/entities_list.test.tsx
index 0e598d6463c5a..91f0c42eab385 100644
--- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/entities_list.test.tsx
+++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/entities_list.test.tsx
@@ -6,7 +6,7 @@
*/
import React from 'react';
-import { render, screen, fireEvent } from '@testing-library/react';
+import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import { EntitiesList } from './entities_list';
import { useGlobalTime } from '../../../common/containers/use_global_time';
import { useQueryToggle } from '../../../common/containers/query_toggle';
@@ -15,6 +15,7 @@ import { useErrorToast } from '../../../common/hooks/use_error_toast';
import type { ListEntitiesResponse } from '../../../../common/api/entity_analytics/entity_store/entities/list_entities.gen';
import { useGlobalFilterQuery } from '../../../common/hooks/use_global_filter_query';
import { TestProviders } from '../../../common/mock';
+import { times } from 'lodash/fp';
jest.mock('../../../common/containers/use_global_time');
jest.mock('../../../common/containers/query_toggle');
@@ -22,21 +23,23 @@ jest.mock('./hooks/use_entities_list_query');
jest.mock('../../../common/hooks/use_error_toast');
jest.mock('../../../common/hooks/use_global_filter_query');
-const entityName = 'Entity Name';
+const secondPageTestId = 'pagination-button-1';
+const entityName = 'Entity Name 1';
const responseData: ListEntitiesResponse = {
page: 1,
per_page: 10,
- total: 1,
- records: [
- {
+ total: 20,
+ records: times(
+ (index) => ({
'@timestamp': '2021-08-02T14:00:00.000Z',
- user: { name: entityName },
+ user: { name: `Entity Name ${index}` },
entity: {
- name: entityName,
+ name: `Entity Name ${index}`,
source: 'test-index',
},
- },
- ],
+ }),
+ 10
+ ),
inspect: undefined,
};
@@ -81,7 +84,7 @@ describe('EntitiesList', () => {
it('displays the correct number of rows', () => {
render(, { wrapper: TestProviders });
- expect(screen.getAllByRole('row')).toHaveLength(2);
+ expect(screen.getAllByRole('row')).toHaveLength(10 + 1);
});
it('calls refetch on time range change', () => {
@@ -112,6 +115,21 @@ describe('EntitiesList', () => {
);
});
+ it('should reset the page when sort order changes ', async () => {
+ render(, { wrapper: TestProviders });
+
+ const secondPageButton = screen.getByTestId(secondPageTestId);
+ fireEvent.click(secondPageButton);
+
+ const columnHeader = screen.getByText('Name');
+ fireEvent.click(columnHeader);
+
+ await waitFor(() => {
+ const firstPageButton = screen.getByTestId('pagination-button-0');
+ expect(firstPageButton).toHaveAttribute('aria-current', 'true');
+ });
+ });
+
it('displays error toast when there is an error', () => {
const error = new Error('Test error');
mockUseEntitiesListQuery.mockReturnValueOnce({
diff --git a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/entities_list.tsx b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/entities_list.tsx
index aa03e41c553cb..69afa8dd32108 100644
--- a/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/entities_list.tsx
+++ b/x-pack/plugins/security_solution/public/entity_analytics/components/entity_store/entities_list.tsx
@@ -94,6 +94,11 @@ export const EntitiesList: React.FC = () => {
inspect: data?.inspect ?? null,
});
+ // Reset the active page when the search criteria changes
+ useEffect(() => {
+ setActivePage(0);
+ }, [sorting, limit, filter]);
+
const columns = useEntitiesListColumns();
// Force a refetch when "refresh" button is clicked.
@@ -112,7 +117,7 @@ export const EntitiesList: React.FC = () => {
return (