Skip to content

Commit

Permalink
Merge branch 'lens/migrate_show_values_stage_2' of github.com:mbondyr…
Browse files Browse the repository at this point in the history
…a/kibana into lens/migrate_show_values_stage_2

# Conflicts:
#	x-pack/plugins/lens/public/visualizations/partition/visualization.test.ts
#	x-pack/plugins/lens/public/visualizations/xy/visualization.test.tsx
#	x-pack/plugins/security_solution/server/lib/dashboards/__mocks__/index.ts
#	x-pack/plugins/security_solution/server/lib/detection_engine/rule_monitoring/logic/detection_engine_health/assets/dashboard_rule_monitoring.json
  • Loading branch information
mbondyra committed May 2, 2024
2 parents b5d8c09 + 4369808 commit 43a81e5
Show file tree
Hide file tree
Showing 696 changed files with 6,124 additions and 2,297 deletions.
1 change: 1 addition & 0 deletions .buildkite/ftr_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ enabled:
- x-pack/test/api_integration/apis/asset_manager/config_when_disabled.ts
- x-pack/test/api_integration/apis/asset_manager/config_when_enabled.ts
- x-pack/test/api_integration/apis/cases/config.ts
- x-pack/test/api_integration/apis/content_management/config.ts
- x-pack/test/api_integration/apis/cloud_security_posture/config.ts
- x-pack/test/api_integration/apis/console/config.ts
- x-pack/test/api_integration/apis/es/config.ts
Expand Down
4 changes: 2 additions & 2 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ packages/kbn-apm-synthtrace-client @elastic/obs-ux-infra_services-team @elastic/
packages/kbn-apm-utils @elastic/obs-ux-infra_services-team
test/plugin_functional/plugins/app_link_test @elastic/kibana-core
x-pack/test/usage_collection/plugins/application_usage_test @elastic/kibana-core
x-pack/plugins/asset_manager @elastic/obs-knowledge-team
x-pack/plugins/observability_solution/asset_manager @elastic/obs-knowledge-team
x-pack/test/security_api_integration/plugins/audit_log @elastic/kibana-security
packages/kbn-axe-config @elastic/kibana-qa
packages/kbn-babel-preset @elastic/kibana-operations
Expand Down Expand Up @@ -555,7 +555,7 @@ x-pack/examples/third_party_maps_source_example @elastic/kibana-gis
src/plugins/maps_ems @elastic/kibana-gis
x-pack/plugins/maps @elastic/kibana-gis
x-pack/packages/maps/vector_tile_utils @elastic/kibana-gis
x-pack/plugins/metrics_data_access @elastic/obs-knowledge-team @elastic/obs-ux-infra_services-team
x-pack/plugins/observability_solution/metrics_data_access @elastic/obs-knowledge-team @elastic/obs-ux-infra_services-team
x-pack/packages/ml/agg_utils @elastic/ml-ui
x-pack/packages/ml/anomaly_utils @elastic/ml-ui
x-pack/packages/ml/cancellable_search @elastic/ml-ui
Expand Down
4 changes: 2 additions & 2 deletions docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ The plugin exposes the static DefaultEditorController class to consume.
|WARNING: Missing README.
|{kib-repo}blob/{branch}/x-pack/plugins/asset_manager/README.md[assetManager]
|{kib-repo}blob/{branch}/x-pack/plugins/observability_solution/asset_manager/README.md[assetManager]
|This plugin provides access to observed asset data, such as information about hosts, pods, containers, services, and more.
Expand Down Expand Up @@ -659,7 +659,7 @@ using the CURL scripts in the scripts folder.
|Visualize geo data from Elasticsearch or 3rd party geo-services.
|{kib-repo}blob/{branch}/x-pack/plugins/metrics_data_access/README.md[metricsDataAccess]
|{kib-repo}blob/{branch}/x-pack/plugins/observability_solution/metrics_data_access/README.md[metricsDataAccess]
|Exposes utilities to access metrics data.
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"@dnd-kit/utilities": "^2.0.0",
"@elastic/apm-rum": "^5.16.0",
"@elastic/apm-rum-react": "^2.0.2",
"@elastic/charts": "64.0.2",
"@elastic/charts": "64.1.0",
"@elastic/datemath": "5.0.3",
"@elastic/ecs": "^8.11.1",
"@elastic/elasticsearch": "^8.13.0",
Expand Down Expand Up @@ -173,7 +173,7 @@
"@kbn/apm-utils": "link:packages/kbn-apm-utils",
"@kbn/app-link-test-plugin": "link:test/plugin_functional/plugins/app_link_test",
"@kbn/application-usage-test-plugin": "link:x-pack/test/usage_collection/plugins/application_usage_test",
"@kbn/assetManager-plugin": "link:x-pack/plugins/asset_manager",
"@kbn/assetManager-plugin": "link:x-pack/plugins/observability_solution/asset_manager",
"@kbn/audit-log-plugin": "link:x-pack/test/security_api_integration/plugins/audit_log",
"@kbn/banners-plugin": "link:x-pack/plugins/banners",
"@kbn/bfetch-error": "link:packages/kbn-bfetch-error",
Expand Down Expand Up @@ -577,7 +577,7 @@
"@kbn/maps-ems-plugin": "link:src/plugins/maps_ems",
"@kbn/maps-plugin": "link:x-pack/plugins/maps",
"@kbn/maps-vector-tile-utils": "link:x-pack/packages/maps/vector_tile_utils",
"@kbn/metrics-data-access-plugin": "link:x-pack/plugins/metrics_data_access",
"@kbn/metrics-data-access-plugin": "link:x-pack/plugins/observability_solution/metrics_data_access",
"@kbn/ml-agg-utils": "link:x-pack/packages/ml/agg_utils",
"@kbn/ml-anomaly-utils": "link:x-pack/packages/ml/anomaly_utils",
"@kbn/ml-cancellable-search": "link:x-pack/packages/ml/cancellable_search",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type TableListViewProps<T extends UserContentCommonSchema = UserContentCo
| 'contentEditor'
| 'titleColumnName'
| 'withoutPageTemplateWrapper'
| 'createdByEnabled'
> & {
title: string;
description?: string;
Expand Down Expand Up @@ -73,6 +74,7 @@ export const TableListView = <T extends UserContentCommonSchema>({
titleColumnName,
additionalRightSideActions,
withoutPageTemplateWrapper,
createdByEnabled,
}: TableListViewProps<T>) => {
const PageTemplate = withoutPageTemplateWrapper
? (React.Fragment as unknown as typeof KibanaPageTemplate)
Expand Down Expand Up @@ -121,6 +123,7 @@ export const TableListView = <T extends UserContentCommonSchema>({
withoutPageTemplateWrapper={withoutPageTemplateWrapper}
onFetchSuccess={onFetchSuccess}
setPageDataTestSubject={setPageDataTestSubject}
createdByEnabled={createdByEnabled}
/>
</KibanaPageTemplate.Section>
</PageTemplate>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { SavedObjectsReference } from '@kbn/content-management-content-edit
export interface UserContentCommonSchema {
id: string;
updatedAt: string;
createdBy?: string;
managed?: boolean;
references: SavedObjectsReference[];
type: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
/*
* 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 React from 'react';
import { MemoryRouter } from 'react-router-dom';
import { render, screen, within, waitForElementToBeRemoved } from '@testing-library/react';
import { I18nProvider } from '@kbn/i18n-react';
import { WithServices } from './tests.helpers';
import { TableListViewTable, type TableListViewTableProps } from '../table_list_view_table';
import type { UserContentCommonSchema } from '@kbn/content-management-table-list-view-common';
import userEvent from '@testing-library/user-event';

const hits: UserContentCommonSchema[] = [
{
id: 'item-1',
type: 'dashboard',
updatedAt: '2020-01-01T00:00:00Z',
attributes: {
title: 'Item 1',
},
references: [],
},
{
id: 'item-2',
type: 'dashboard',
updatedAt: '2020-01-01T00:00:00Z',
attributes: {
title: 'Item 2',
},
createdBy: 'u_1',
references: [],
},
{
id: 'item-3',
type: 'dashboard',
updatedAt: '2020-01-01T00:00:00Z',
attributes: {
title: 'Item 3',
},
createdBy: 'u_2',
references: [],
},
];

describe('created_by', () => {
const requiredProps: TableListViewTableProps = {
entityName: 'test',
entityNamePlural: 'tests',
listingLimit: 500,
initialFilter: '',
initialPageSize: 20,
findItems: jest.fn().mockResolvedValue({ total: 0, hits }),
getDetailViewLink: () => 'http://elastic.co',
urlStateEnabled: false,
onFetchSuccess: () => {},
tableCaption: 'my caption',
setPageDataTestSubject: () => {},
};

const mockBulkGetUserProfiles = jest.fn((uids) =>
Promise.resolve(
[
{
uid: 'u_1',
enabled: true,
user: {
username: 'user1',
},
data: {},
},
{
uid: 'u_2',
enabled: true,
user: {
username: 'user2',
},
data: {},
},
].filter((user) => uids.includes(user.uid))
)
);

const TableListViewWithServices = WithServices<TableListViewTableProps>(TableListViewTable, {
bulkGetUserProfiles: mockBulkGetUserProfiles,
});
const TableListView = (overrides: Partial<TableListViewTableProps>) => (
<I18nProvider>
<MemoryRouter>
<TableListViewWithServices {...requiredProps} {...overrides} />
</MemoryRouter>
</I18nProvider>
);

test("shouldn't render created by filter when createdBy is disabled", async () => {
render(<TableListView {...requiredProps} />);

// wait until first render
expect(await screen.findByTestId('itemsInMemTable')).toBeVisible();

expect(() => screen.getByTestId('userFilterPopoverButton')).toThrow();
});

test('should be able to filter by creators', async () => {
render(<TableListView {...requiredProps} createdByEnabled={true} />);

// wait until first render
expect(await screen.findByTestId('itemsInMemTable')).toBeVisible();

// 3 items in the list
expect(screen.getAllByTestId(/userContentListingTitleLink/)).toHaveLength(3);

userEvent.click(screen.getByTestId('userFilterPopoverButton'));

const userSelectablePopover = screen.getByTestId('userSelectableList');
const popover = within(userSelectablePopover);
expect(await popover.findAllByTestId(/userProfileSelectableOption/)).toHaveLength(3);

userEvent.click(popover.getByTestId('userProfileSelectableOption-user1'));

// 2 item in the list
expect(screen.getAllByTestId(/userContentListingTitleLink/)).toHaveLength(1);

userEvent.click(popover.getByTestId('userProfileSelectableOption-user2'));

// 2 item in the list
expect(screen.getAllByTestId(/userContentListingTitleLink/)).toHaveLength(2);
});

test('should be able to filter by "no creators"', async () => {
render(<TableListView {...requiredProps} createdByEnabled={true} />);

// wait until first render
expect(await screen.findByTestId('itemsInMemTable')).toBeVisible();

// 3 items in the list
expect(screen.getAllByTestId(/userContentListingTitleLink/)).toHaveLength(3);

userEvent.click(screen.getByTestId('userFilterPopoverButton'));

const userSelectablePopover = screen.getByTestId('userSelectableList');
const popover = within(userSelectablePopover);
userEvent.click(await popover.findByTestId('userProfileSelectableOption-null'));

// just 1 item in the list
expect(screen.getAllByTestId(/userContentListingTitleLink/)).toHaveLength(1);
});

test('"no creators" options shouldn\'t appear if all objects have creators', async () => {
render(
<TableListView
{...requiredProps}
createdByEnabled={true}
findItems={async () => ({
hits: [hits[1], hits[2]],
total: 2,
})}
/>
);

// wait until first render
expect(await screen.findByTestId('itemsInMemTable')).toBeVisible();
// 2 items in the list
expect(screen.getAllByTestId(/userContentListingTitleLink/)).toHaveLength(2);

userEvent.click(screen.getByTestId('userFilterPopoverButton'));

const userSelectablePopover = screen.getByTestId('userSelectableList');
const popover = within(userSelectablePopover);
expect(await popover.findAllByTestId(/userProfileSelectableOption/)).toHaveLength(2);
expect(() => popover.getByTestId('userProfileSelectableOption-null')).toThrow();
});

test('empty message in case no objects have creators', async () => {
render(
<TableListView
{...requiredProps}
createdByEnabled={true}
findItems={async () => ({
hits: [hits[0]],
total: 1,
})}
/>
);

// wait until first render
expect(await screen.findByTestId('itemsInMemTable')).toBeVisible();
// 1 item in the list
expect(screen.getAllByTestId(/userContentListingTitleLink/)).toHaveLength(1);

userEvent.click(screen.getByTestId('userFilterPopoverButton'));

const userSelectablePopover = screen.getByTestId('userSelectableList');
const popover = within(userSelectablePopover);
await waitForElementToBeRemoved(() => popover.getByRole('progressbar'));
expect(popover.getAllByTestId('userFilterEmptyMessage')[1]).toBeVisible();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const getMockServices = (overrides?: Partial<Services>) => {
itemHasTags: () => true,
getTagManagementUrl: () => '',
getTagIdsFromReferences: () => [],
bulkGetUserProfiles: jest.fn(() => Promise.resolve([])),
...overrides,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface OnTableChangeAction<T extends UserContentCommonSchema> {
pageIndex: number;
pageSize: number;
};
filter?: Partial<State<T>['tableFilter']>;
};
}

Expand Down
Loading

0 comments on commit 43a81e5

Please sign in to comment.