Skip to content

Commit

Permalink
Merge branch 'main' of github.com:elastic/kibana into unskip-rac-secu…
Browse files Browse the repository at this point in the history
…rity-solution-tests
  • Loading branch information
madirey committed Jan 11, 2022
2 parents 7e406d5 + 33af3fc commit 7326f7c
Show file tree
Hide file tree
Showing 15 changed files with 298 additions and 62 deletions.
7 changes: 7 additions & 0 deletions src/plugins/home/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@

export const PLUGIN_ID = 'home';
export const HOME_APP_BASE_PATH = `/app/${PLUGIN_ID}`;

export enum TutorialsCategory {
LOGGING = 'logging',
SECURITY_SOLUTION = 'security',
METRICS = 'metrics',
OTHER = 'other',
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ import {
EuiPageHeader,
EuiButtonEmpty,
EuiSpacer,
EuiBadge,
} from '@elastic/eui';

import { FormattedMessage, injectI18n } from '@kbn/i18n-react';
import { TutorialsCategory } from '../../../../common/constants';

function IntroductionUI({
description,
Expand All @@ -30,6 +32,7 @@ function IntroductionUI({
intl,
notices,
basePath,
category,
}) {
let rightSideItems;
if (previewUrl) {
Expand Down Expand Up @@ -98,6 +101,18 @@ function IntroductionUI({
{betaBadge}
</>
)}

{category === TutorialsCategory.LOGGING || category === TutorialsCategory.METRICS ? (
<>
&nbsp;
<EuiBadge>
<FormattedMessage
id="home.tutorial.introduction.beatsBadgeLabel"
defaultMessage="Beats"
/>
</EuiBadge>
</>
) : null}
</>
}
description={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { shallowWithIntl } from '@kbn/test/jest';

import { Introduction } from './introduction';
import { httpServiceMock } from '../../../../../../core/public/mocks';
import { TutorialsCategory } from '../../../../common/constants';

const basePathMock = httpServiceMock.createBasePath();

Expand Down Expand Up @@ -73,4 +74,30 @@ describe('props', () => {
);
expect(component).toMatchSnapshot(); // eslint-disable-line
});

test('Beats badge should show', () => {
const component = shallowWithIntl(
<Introduction.WrappedComponent
description="this is a great tutorial about..."
title="Great tutorial"
basePath={basePathMock}
isBeta={true}
category={TutorialsCategory.METRICS}
/>
);
expect(component).toMatchSnapshot();
});

test('Beats badge should not show', () => {
const component = shallowWithIntl(
<Introduction.WrappedComponent
description="this is a great tutorial about..."
title="Great tutorial"
basePath={basePathMock}
isBeta={true}
category={TutorialsCategory.SECURITY_SOLUTION}
/>
);
expect(component).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ class TutorialUi extends React.Component {
content = (
<div>
<Introduction
category={this.state.tutorial.category}
title={this.state.tutorial.name}
description={this.props.replaceTemplateStrings(this.state.tutorial.longDescription)}
previewUrl={previewUrl}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import type { KibanaRequest } from 'src/core/server';
import type { TutorialSchema } from './tutorial_schema';
export { TutorialsCategory } from '../../../../common/constants';

export type {
TutorialSchema,
ArtifactsSchema,
Expand All @@ -19,13 +21,6 @@ export type {
Instruction,
} from './tutorial_schema';

/** @public */
export enum TutorialsCategory {
LOGGING = 'logging',
SECURITY_SOLUTION = 'security',
METRICS = 'metrics',
OTHER = 'other',
}
export type Platform = 'WINDOWS' | 'OSX' | 'DEB' | 'RPM';

export interface TutorialContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,17 @@ export function WaterfallWithSummary({

return (
<>
<EuiFlexGroup>
<EuiFlexItem style={{ flexDirection: 'row', alignItems: 'center' }}>
<EuiFlexGroup alignItems="center">
<EuiFlexItem grow={false}>
<EuiTitle size="xs">
<h5>
{i18n.translate('xpack.apm.transactionDetails.traceSampleTitle', {
defaultMessage: 'Trace sample',
})}
</h5>
</EuiTitle>
</EuiFlexItem>
<EuiFlexItem>
{traceSamples && (
<EuiPagination
pageCount={traceSamples.length}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ export const CreatePackagePolicyPage: React.FunctionComponent = () => {
inputs: [],
});

const [wasNewAgentPolicyCreated, setWasNewAgentPolicyCreated] = useState<boolean>(false);

// Validation state
const [validationResults, setValidationResults] = useState<PackagePolicyValidationResults>();
const [hasAgentPolicyError, setHasAgentPolicyError] = useState<boolean>(false);
Expand Down Expand Up @@ -276,6 +278,10 @@ export const CreatePackagePolicyPage: React.FunctionComponent = () => {
}, [packagePolicy, agentCount]);
const doOnSaveNavigation = useRef<boolean>(true);

const handleInlineAgentPolicyCreate = useCallback(() => {
setWasNewAgentPolicyCreated(true);
}, []);

// Detect if user left page
useEffect(() => {
return () => {
Expand All @@ -295,12 +301,16 @@ export const CreatePackagePolicyPage: React.FunctionComponent = () => {
return;
}

const packagePolicyPath = getPath('policy_details', { policyId: packagePolicy.policy_id });

if (routeState?.onSaveNavigateTo && policy) {
const [appId, options] = routeState.onSaveNavigateTo;

if (options?.path) {
const pathWithQueryString = appendOnSaveQueryParamsToPath({
path: options.path,
// In cases where we created a new agent policy inline, we need to override the initial `path`
// value and navigate to the newly-created agent policy instead
path: wasNewAgentPolicyCreated ? packagePolicyPath : options.path,
policy,
mappingOptions: routeState.onSaveQueryParams,
paramsToApply,
Expand All @@ -310,10 +320,10 @@ export const CreatePackagePolicyPage: React.FunctionComponent = () => {
navigateToApp(...routeState.onSaveNavigateTo);
}
} else {
history.push(getPath('policy_details', { policyId: agentPolicy!.id }));
history.push(packagePolicyPath);
}
},
[agentPolicy, getPath, navigateToApp, history, routeState]
[packagePolicy.policy_id, getPath, navigateToApp, history, routeState, wasNewAgentPolicyCreated]
);

const onSubmit = useCallback(async () => {
Expand Down Expand Up @@ -400,9 +410,16 @@ export const CreatePackagePolicyPage: React.FunctionComponent = () => {
agentPolicy={agentPolicy}
updateAgentPolicy={updateAgentPolicy}
setHasAgentPolicyError={setHasAgentPolicyError}
onNewAgentPolicyCreate={handleInlineAgentPolicyCreate}
/>
),
[packageInfo, queryParamsPolicyId, agentPolicy, updateAgentPolicy]
[
packageInfo,
queryParamsPolicyId,
agentPolicy,
updateAgentPolicy,
handleInlineAgentPolicyCreate,
]
);

const extensionView = useUIExtension(packagePolicy.package?.name ?? '', 'package-policy-create');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,14 @@ export const StepSelectAgentPolicy: React.FunctionComponent<{
agentPolicy: AgentPolicy | undefined;
updateAgentPolicy: (agentPolicy: AgentPolicy | undefined) => void;
setHasAgentPolicyError: (hasError: boolean) => void;
onNewAgentPolicyCreate: () => void;
}> = ({
packageInfo,
agentPolicy,
updateAgentPolicy,
defaultAgentPolicyId,
setHasAgentPolicyError,
onNewAgentPolicyCreate,
}) => {
const { isReady: isFleetReady } = useFleetStatus();

Expand Down Expand Up @@ -203,6 +205,7 @@ export const StepSelectAgentPolicy: React.FunctionComponent<{
onClose={(newAgentPolicy?: AgentPolicy) => {
setIsCreateAgentPolicyFlyoutOpen(false);
if (newAgentPolicy) {
onNewAgentPolicyCreate();
refreshAgentPolicies();
setSelectedPolicyId(newAgentPolicy.id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Redirect, Route, Switch, useLocation, useParams, useHistory } from 'rea
import styled from 'styled-components';
import type { EuiToolTipProps } from '@elastic/eui';
import {
EuiBadge,
EuiBetaBadge,
EuiButton,
EuiButtonEmpty,
Expand Down Expand Up @@ -209,11 +210,22 @@ export function Detail() {
</FlexItemWithMaxHeight>
<EuiFlexItem>
<EuiFlexGroup alignItems="center" gutterSize="m">
<FlexItemWithMinWidth grow={false}>
<EuiText>
{/* Render space in place of package name while package info loads to prevent layout from jumping around */}
<h1>{integrationInfo?.title || packageInfo?.title || '\u00A0'}</h1>
</EuiText>
<FlexItemWithMinWidth grow={true}>
<EuiFlexGroup alignItems="center">
<EuiFlexItem grow={false}>
<EuiText>
{/* Render space in place of package name while package info loads to prevent layout from jumping around */}
<h1>{integrationInfo?.title || packageInfo?.title || '\u00A0'}</h1>
</EuiText>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiBadge color="default">
{i18n.translate('xpack.fleet.epm.elasticAgentBadgeLabel', {
defaultMessage: 'Elastic Agent',
})}
</EuiBadge>
</EuiFlexItem>
</EuiFlexGroup>
</FlexItemWithMinWidth>
{packageInfo?.release && packageInfo.release !== 'ga' ? (
<EuiFlexItem grow={false}>
Expand Down
Loading

0 comments on commit 7326f7c

Please sign in to comment.