Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into per-fields-diffs-tour
Browse files Browse the repository at this point in the history
  • Loading branch information
dplumlee committed Feb 13, 2024
2 parents a0a9587 + 789fe56 commit 78c7321
Show file tree
Hide file tree
Showing 39 changed files with 615 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import { screen, waitFor } from '@testing-library/react';
import { waitForEuiPopoverOpen } from '@elastic/eui/lib/test/rtl';
import { SeverityFilter } from './severity_filter';

describe('Severity form field', () => {
// FLAKY: https://github.com/elastic/kibana/issues/176336
describe.skip('Severity form field', () => {
const onChange = jest.fn();
let appMockRender: AppMockRenderer;
const props = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import { MAX_DESCRIPTION_LENGTH } from '../../../common/constants';
import { FormTestComponent } from '../../common/test_utils';
import type { FormSchema } from '@kbn/index-management-plugin/public/shared_imports';

describe('Description', () => {
// FLAKY: https://github.com/elastic/kibana/issues/175204
describe.skip('Description', () => {
let appMockRender: AppMockRenderer;
const onSubmit = jest.fn();
const draftStorageKey = `cases.caseView.createCase.description.markdownEditor`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import {
import { RegisteredAttachmentsPropertyActions } from './registered_attachments_property_actions';
import { AttachmentActionType } from '../../../client/attachment_framework/types';

describe('RegisteredAttachmentsPropertyActions', () => {
// FLAKY: https://github.com/elastic/kibana/issues/174384
describe.skip('RegisteredAttachmentsPropertyActions', () => {
let appMock: AppMockRenderer;

const props = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import React from 'react';
import { waitFor, screen } from '@testing-library/react';
import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
// eslint-disable-next-line @kbn/eslint/module_migration
import routeData from 'react-router';
Expand All @@ -31,9 +31,7 @@ const defaultProps = {

jest.mock('../../common/lib/kibana');

// FLAKY: https://github.com/elastic/kibana/issues/176524
// FLAKY: https://github.com/elastic/kibana/issues/176525
describe.skip(`UserActionsList`, () => {
describe(`UserActionsList`, () => {
let appMockRender: AppMockRenderer;

beforeEach(() => {
Expand All @@ -46,27 +44,21 @@ describe.skip(`UserActionsList`, () => {
it('renders list correctly with isExpandable option', async () => {
appMockRender.render(<UserActionsList {...defaultProps} isExpandable />);

await waitFor(() => {
expect(screen.getByTestId('user-actions-list')).toBeInTheDocument();
});
expect(await screen.findByTestId('user-actions-list')).toBeInTheDocument();
});

it('renders list correctly with isExpandable=false option', async () => {
appMockRender.render(<UserActionsList {...defaultProps} />);

await waitFor(() => {
expect(screen.getByTestId('user-actions-list')).toBeInTheDocument();
});
expect(await screen.findByTestId('user-actions-list')).toBeInTheDocument();
});

it('renders user actions correctly', async () => {
appMockRender.render(<UserActionsList {...defaultProps} />);

await waitFor(() => {
expect(screen.getByTestId(`description-create-action-${caseUserActions[0].id}`));
expect(screen.getByTestId(`comment-create-action-${caseUserActions[1].commentId}`));
expect(screen.getByTestId(`description-update-action-${caseUserActions[2].id}`));
});
expect(await screen.findByTestId(`description-create-action-${caseUserActions[0].id}`));
expect(await screen.findByTestId(`comment-create-action-${caseUserActions[1].commentId}`));
expect(await screen.findByTestId(`description-update-action-${caseUserActions[2].id}`));
});

it('renders bottom actions correctly', async () => {
Expand All @@ -82,12 +74,11 @@ describe.skip(`UserActionsList`, () => {
children: <span>{sample}</span>,
},
];

appMockRender.render(<UserActionsList {...defaultProps} bottomActions={bottomActions} />);

await waitFor(() => {
expect(screen.getByTestId('user-actions-list')).toBeInTheDocument();
expect(screen.getByTestId('add-comment')).toBeInTheDocument();
});
expect(await screen.findByTestId('user-actions-list')).toBeInTheDocument();
expect(await screen.findByTestId('add-comment')).toBeInTheDocument();
});

it('Outlines comment when url param is provided', async () => {
Expand Down Expand Up @@ -121,18 +112,18 @@ describe.skip(`UserActionsList`, () => {

appMockRender.render(<UserActionsList {...props} />);
expect(
screen
.queryAllByTestId(`comment-create-action-${props.data.comments[0].id}`)[0]
?.classList.contains('outlined')
(
await screen.findAllByTestId(`comment-create-action-${props.data.comments[0].id}`)
)[0]?.classList.contains('outlined')
).toBe(false);

expect(
screen
.queryAllByTestId(`comment-create-action-${props.data.comments[0].id}`)[0]
?.classList.contains('outlined')
(
await screen.findAllByTestId(`comment-create-action-${props.data.comments[0].id}`)
)[0]?.classList.contains('outlined')
).toBe(false);

userEvent.click(screen.getByTestId(`comment-update-action-${ourActions[1].id}`));
userEvent.click(await screen.findByTestId(`comment-update-action-${ourActions[1].id}`));

expect(
await screen.findAllByTestId(`comment-create-action-${props.data.comments[0].id}`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import React from 'react';
import { UserToolTip } from './user_tooltip';

describe('UserToolTip', () => {
// FLAKY: https://github.com/elastic/kibana/issues/176643
describe.skip('UserToolTip', () => {
it('renders the tooltip when hovering', async () => {
const profile: UserProfileWithAvatar = {
uid: '1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const DEFAULT_INITIAL_APP_DATA = {
hasIncrementalSyncEnabled: true,
hasNativeConnectors: true,
hasWebCrawler: true,
showAIPlayground: false,
},
appSearch: {
accountId: 'some-id-string',
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/enterprise_search/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export const DEFAULT_PRODUCT_FEATURES: ProductFeatures = {
hasIncrementalSyncEnabled: true,
hasNativeConnectors: true,
hasWebCrawler: true,
showAIPlayground: false,
};

export const CONNECTORS_ACCESS_CONTROL_INDEX_PREFIX = '.search-acl-filter-';
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/enterprise_search/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export interface ProductFeatures {
hasIncrementalSyncEnabled: boolean;
hasNativeConnectors: boolean;
hasWebCrawler: boolean;
// Temp Feature Flag for AI Playground page
showAIPlayground: boolean;
}

export interface SearchOAuth {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const mockKibanaProps: KibanaLogicProps = {
hasIncrementalSyncEnabled: true,
hasNativeConnectors: true,
hasWebCrawler: true,
showAIPlayground: false,
},
renderHeaderActions: jest.fn(),
security: securityMock.createStart(),
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/enterprise_search/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export const configSchema = schema.object({
ui: schema.object({
enabled: schema.boolean({ defaultValue: true }),
}),
// Temp Feature Flag for AI Playground page
showAIPlayground: schema.boolean({ defaultValue: false }),
});

export type ConfigType = TypeOf<typeof configSchema>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ describe('callEnterpriseSearchConfigAPI', () => {
hasDefaultIngestPipeline: false,
hasNativeConnectors: false,
hasWebCrawler: false,
showAIPlayground: false,
host: '',
};

Expand All @@ -224,6 +225,7 @@ describe('callEnterpriseSearchConfigAPI', () => {
hasDefaultIngestPipeline: false,
hasNativeConnectors: false,
hasWebCrawler: false,
showAIPlayground: false,
},
kibanaVersion: '1.0.0',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const callEnterpriseSearchConfigAPI = async ({
hasIncrementalSyncEnabled: config.hasIncrementalSyncEnabled,
hasNativeConnectors: config.hasNativeConnectors,
hasWebCrawler: config.hasWebCrawler,
showAIPlayground: config.showAIPlayground,
},
kibanaVersion: kibanaPackageJson.version,
};
Expand Down Expand Up @@ -111,6 +112,7 @@ export const callEnterpriseSearchConfigAPI = async ({
hasIncrementalSyncEnabled: config.hasIncrementalSyncEnabled,
hasNativeConnectors: config.hasNativeConnectors,
hasWebCrawler: config.hasWebCrawler,
showAIPlayground: config.showAIPlayground,
},
publicUrl: stripTrailingSlash(data?.settings?.external_url),
readOnlyMode: !!data?.settings?.read_only_mode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ export const ServicesAPIQueryAggregationRT = rt.type({
export type ServicesAPIQueryAggregation = rt.TypeOf<typeof ServicesAPIQueryAggregationRT>;

export const ServiceRT = rt.type({
'service.name': rt.string,
'agent.name': AgentNameRT,
serviceName: rt.string,
agentName: AgentNameRT,
});

export type Service = rt.TypeOf<typeof ServiceRT>;

export const ServicesAPIResponseRT = rt.type({
services: rt.array(ServiceRT),
});

export type ServicesAPIResponse = rt.TypeOf<typeof ServicesAPIResponseRT>;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { i18n } from '@kbn/i18n';
import { type AssetDetailsProps, ContentTabIds, type Tab } from '../../../types';

const links: AssetDetailsProps['links'] = ['alertRule', 'nodeDetails', 'apmServices'];
const links: AssetDetailsProps['links'] = ['alertRule', 'nodeDetails'];
const tabs: Tab[] = [
{
id: ContentTabIds.OVERVIEW,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { i18n } from '@kbn/i18n';
import { HostMetricsExplanationContent } from '../../lens';
import { Popover } from '../tabs/common/popover';
import { AlertsTooltipContent } from './alerts_tooltip_content';
import { ServicesTooltipContent } from './services_tooltip_content';

const SectionTitle = ({
title,
Expand Down Expand Up @@ -94,3 +95,15 @@ export const AlertsSectionTitle = () => {
</TitleWithTooltip>
);
};

export const ServicesSectionTitle = () => (
<TitleWithTooltip
title={i18n.translate('xpack.infra.assetDetails.overview.servicesSectionTitle', {
defaultMessage: 'Services',
})}
data-test-subj="infraAssetDetailsServicesTitle"
tooltipTestSubj="infraAssetDetailsServicesPopoverButton"
>
<ServicesTooltipContent />
</TitleWithTooltip>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React from 'react';
import { EuiText, EuiLink } from '@elastic/eui';
import { RedirectAppLinks } from '@kbn/shared-ux-link-redirect-app';
import { FormattedMessage } from '@kbn/i18n-react';
import { useLinkProps } from '@kbn/observability-shared-plugin/public';
import { useKibanaContextForPlugin } from '../../../hooks/use_kibana';

export const ServicesTooltipContent = () => {
const { services } = useKibanaContextForPlugin();
const linkProps = useLinkProps({
app: 'home',
hash: '/tutorial/apm',
});
return (
<EuiText size="xs">
<FormattedMessage
id="xpack.infra.assetDetails.services.tooltip.servicesLabel"
defaultMessage="Showing {apmTutorialLink} services detected on this host."
values={{
apmTutorialLink: (
<RedirectAppLinks coreStart={services} style={{ display: 'inline-block' }}>
<EuiLink data-test-subj="assetDetailsTooltipApmTutorialLink" href={linkProps.href}>
<FormattedMessage
id="xpack.infra.assetDetails.table.services.tooltip.tutorialLink"
defaultMessage="APM-instrumented"
/>
</EuiLink>
</RedirectAppLinks>
),
}}
/>
</EuiText>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { usePluginConfig } from '../../../containers/plugin_config_context';
import { useKibanaContextForPlugin } from '../../../hooks/use_kibana';
import { useProfilingIntegrationSetting } from '../../../hooks/use_profiling_integration_setting';
import { APM_HOST_FILTER_FIELD } from '../constants';
import { LinkToAlertsRule, LinkToApmServices, LinkToNodeDetails } from '../links';
import { LinkToAlertsRule, LinkToNodeDetails } from '../links';
import { ContentTabIds, type LinkOptions, type RouteState, type Tab, type TabIds } from '../types';
import { useAssetDetailsRenderPropsContext } from './use_asset_details_render_props';
import { useTabSwitcherContext } from './use_tab_switcher';
Expand Down Expand Up @@ -96,7 +96,6 @@ const useRightSideItems = (links?: LinkOptions[]) => {
<LinkToNodeDetails assetId={asset.id} assetName={asset.name} assetType={asset.type} />
),
alertRule: <LinkToAlertsRule />,
apmServices: <LinkToApmServices assetName={asset.name} apmField={APM_HOST_FILTER_FIELD} />,
}),
[asset.id, asset.name, asset.type]
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { fold } from 'fp-ts/lib/Either';
import { identity } from 'fp-ts/lib/function';
import { pipe } from 'fp-ts/lib/pipeable';
import { useEffect, useMemo } from 'react';
import {
ServicesAPIResponse,
ServicesAPIResponseRT,
ServicesAPIRequest,
} from '../../../../common/http_api/host_details';
import { throwErrors, createPlainError } from '../../../../common/runtime_types';
import { useHTTPRequest } from '../../../hooks/use_http_request';
import { useRequestObservable } from './use_request_observable';

export function useServices(params: ServicesAPIRequest) {
const { request$ } = useRequestObservable();
const decodeResponse = (response: any) => {
return pipe(
ServicesAPIResponseRT.decode(response),
fold(throwErrors(createPlainError), identity)
);
};
const fetchOptions = useMemo(
() => ({ query: { ...params, filters: JSON.stringify(params.filters) } }),
[params]
);
const { error, loading, response, makeRequest } = useHTTPRequest<ServicesAPIResponse>(
`/api/infra/services`,
'GET',
undefined,
decodeResponse,
undefined,
undefined,
true,
fetchOptions
);

useEffect(() => {
if (request$) {
request$.next(makeRequest);
} else {
makeRequest();
}
}, [makeRequest, request$]);

return {
error,
loading,
response,
makeRequest,
};
}
Loading

0 comments on commit 78c7321

Please sign in to comment.