Skip to content

Commit

Permalink
Merge branch 'main' into get-cases
Browse files Browse the repository at this point in the history
  • Loading branch information
lcawl authored Nov 9, 2022
2 parents bec9d74 + b721fdc commit 55ef6c2
Show file tree
Hide file tree
Showing 154 changed files with 4,345 additions and 1,403 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@
/x-pack/plugins/security_solution/cypress/tasks/network @elastic/security-threat-hunting-explore
/x-pack/plugins/security_solution/cypress/upgrade_e2e/threat_hunting/cases @elastic/security-threat-hunting-explore

/x-pack/plugins/security_solution/public/common/components/guided_onboarding_tour @elastic/security-threat-hunting-explore
/x-pack/plugins/security_solution/public/common/components/charts @elastic/security-threat-hunting-explore
/x-pack/plugins/security_solution/public/common/components/header_page @elastic/security-threat-hunting-explore
/x-pack/plugins/security_solution/public/common/components/header_section @elastic/security-threat-hunting-explore
Expand Down
3 changes: 3 additions & 0 deletions nav-kibana-dev.docnav.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@
{
"label": "Contributors Newsletters",
"items": [
{
"id": "kibOctober2022ContributorNewsletter"
},
{
"id": "kibSeptember2022ContributorNewsletter"
},
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@
"react-fast-compare": "^2.0.4",
"react-focus-on": "^3.6.0",
"react-grid-layout": "^1.3.4",
"react-hook-form": "^7.38.0",
"react-hook-form": "^7.39.1",
"react-intl": "^2.8.0",
"react-is": "^17.0.2",
"react-markdown": "^6.0.3",
Expand Down Expand Up @@ -869,7 +869,7 @@
"@types/jsonwebtoken": "^8.5.6",
"@types/license-checker": "15.0.0",
"@types/listr": "^0.14.0",
"@types/loader-utils": "^1.1.3",
"@types/loader-utils": "^2.0.3",
"@types/lodash": "^4.14.159",
"@types/lru-cache": "^5.1.0",
"@types/lz-string": "^1.3.34",
Expand Down Expand Up @@ -1061,7 +1061,7 @@
"license-checker": "^25.0.1",
"listr": "^0.14.1",
"lmdb-store": "^1.6.11",
"loader-utils": "^1.2.3",
"loader-utils": "^2.0.3",
"marge": "^1.0.1",
"micromatch": "^4.0.5",
"mini-css-extract-plugin": "1.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/src/worker/theme_loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function (this: webpack.loader.LoaderContext) {
this.cacheable(true);

const options = getOptions(this);
const bundleId: string = options.bundleId!;
const bundleId = options.bundleId as string;
const themeTags = parseThemeTags(options.themeTags);

const cases = ALL_THEMES.map((tag) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { fireEvent, render } from '@testing-library/react';
import { createEvent, fireEvent, render } from '@testing-library/react';
import React from 'react';
import { HeaderMenu } from '.';
import { actions, actionsWithDisabledDelete } from '../mocks/header.mock';
Expand Down Expand Up @@ -90,7 +90,6 @@ describe('HeaderMenu', () => {
expect(wrapper.queryByTestId('ActionItemedit')).not.toBeInTheDocument();
expect(wrapper.queryByTestId('MenuPanel')).not.toBeInTheDocument();
});

it('should call onEdit if action has onClick', () => {
const onEdit = jest.fn();
const customAction = [...actions];
Expand All @@ -113,4 +112,16 @@ describe('HeaderMenu', () => {
fireEvent.click(wrapper.getByTestId('EmptyButton'));
expect(wrapper.queryByTestId('MenuPanel')).toBeInTheDocument();
});
it('should stop propagation when clicking on the menu', () => {
const onEdit = jest.fn();
const customAction = [...actions];
customAction[0].onClick = onEdit;
const wrapper = render(
<HeaderMenu dataTestSubj="headerMenu" disableActions={false} actions={actions} />
);
const headerMenu = wrapper.getByTestId('headerMenuItems');
const click = createEvent.click(headerMenu);
const result = fireEvent(headerMenu, click);
expect(result).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import {
} from '@elastic/eui';
import { ButtonContentIconSide } from '@elastic/eui/src/components/button/_button_content_deprecated';

interface Action {
export interface Action {
key: string;
icon: string;
label: string | boolean;
disabled?: boolean;
onClick: () => void;
onClick: (e: React.MouseEvent<Element, MouseEvent>) => void;
}
interface HeaderMenuComponentProps {
disableActions: boolean;
Expand Down Expand Up @@ -66,9 +66,9 @@ const HeaderMenuComponent: FC<HeaderMenuComponentProps> = ({
icon={action.icon}
disabled={action.disabled}
layoutAlign="center"
onClick={() => {
onClick={(e) => {
onClosePopover();
if (typeof action.onClick === 'function') action.onClick();
if (typeof action.onClick === 'function') action.onClick(e);
}}
>
{action.label}
Expand Down Expand Up @@ -103,6 +103,7 @@ const HeaderMenuComponent: FC<HeaderMenuComponentProps> = ({
</EuiButtonIcon>
)
}
onClick={(e) => e.stopPropagation()}
panelPaddingSize={panelPaddingSize}
isOpen={isPopoverOpen}
closePopover={onClosePopover}
Expand Down
1 change: 0 additions & 1 deletion src/dev/typescript/run_type_check_cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ function createTypeCheckConfigs(projects: Project[], bazelPackages: BazelPackage
compilerOptions: {
...parsed.compilerOptions,
composite: true,
incremental: true,
rootDir: '.',
paths: undefined,
},
Expand Down
1 change: 1 addition & 0 deletions src/plugins/kibana_utils/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export {
replaceUrlHashQuery,
} from './state_management/url';
export type {
IStateStorage,
IStateSyncConfig,
ISyncStateRef,
IKbnUrlStateStorage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const find = getService('find');
const comboBox = getService('comboBox');

// FLAKY: https://github.com/elastic/kibana/issues/96997
// FLAKY: https://github.com/elastic/kibana/issues/100372
describe.skip('chained controls', function () {
describe('chained controls', function () {
this.tags('includeFirefox');

before(async () => {
Expand All @@ -42,7 +40,6 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

it('should filter child control options by parent control value', async () => {
await comboBox.set('listControlSelect0', 'BR');

const childControlMenu = await comboBox.getOptionsList('listControlSelect1');
expect(childControlMenu.trim().split('\n').join()).to.equal(
'14.61.182.136,3.174.21.181,6.183.121.70,71.241.97.89,9.69.255.135'
Expand Down
10 changes: 6 additions & 4 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -1209,8 +1209,10 @@
"useUnknownInCatchVariables": false,
// disabled for better IDE support, enabled when running the type_check script
"composite": false,
// disabled for better IDE support, enabled when running the type_check script
"incremental": false,
// enabled for improved performance
"incremental": true,
// Do not check d.ts files ts ships by default
"skipDefaultLibCheck": true,
// Do not check d.ts files by default
"skipLibCheck": true,
// enables "core language features"
Expand Down Expand Up @@ -1261,7 +1263,7 @@
"@testing-library/jest-dom",
"@emotion/react/types/css-prop",
"@kbn/ambient-ui-types",
"@kbn/ambient-storybook-types",
"@kbn/ambient-storybook-types"
]
}
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('when navigating to integration page', () => {
cy.getByTestSubj('addIntegrationPolicyButton').click();
});

it('checks validators for required fields', () => {
it.skip('checks validators for required fields', () => {
const requiredFields = policyFormFields.filter((field) => field.required);

requiredFields.map((field) => {
Expand All @@ -76,7 +76,7 @@ describe('when navigating to integration page', () => {
});
});

it('should display Tail-based section on latest version', () => {
it.skip('should display Tail-based section on latest version', () => {
cy.visitKibana('/app/fleet/integrations/apm/add-integration');
cy.contains('Tail-based sampling').should('exist');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import styled, { createGlobalStyle } from 'styled-components';
import { EuiFlyout, EuiFlyoutHeader, EuiTitle, EuiFlyoutBody } from '@elastic/eui';

import { QueryClientProvider } from '@tanstack/react-query';
import type { CasePostRequest } from '../../../../common/api';
import * as i18n from '../translations';
import type { Case } from '../../../../common/ui/types';
import { CreateCaseForm } from '../form';
Expand All @@ -26,6 +27,7 @@ export interface CreateCaseFlyoutProps {
onSuccess?: (theCase: Case) => Promise<void>;
attachments?: CaseAttachmentsWithoutOwner;
headerContent?: React.ReactNode;
initialValue?: Pick<CasePostRequest, 'title' | 'description'>;
}

const StyledFlyout = styled(EuiFlyout)`
Expand Down Expand Up @@ -72,7 +74,7 @@ const FormWrapper = styled.div`
`;

export const CreateCaseFlyout = React.memo<CreateCaseFlyoutProps>(
({ afterCaseCreated, onClose, onSuccess, attachments, headerContent }) => {
({ afterCaseCreated, attachments, headerContent, initialValue, onClose, onSuccess }) => {
const handleCancel = onClose || function () {};
const handleOnSuccess = onSuccess || async function () {};

Expand All @@ -81,6 +83,7 @@ export const CreateCaseFlyout = React.memo<CreateCaseFlyoutProps>(
<GlobalStyle />
<StyledFlyout
onClose={onClose}
tour-step="create-case-flyout"
data-test-subj="create-case-flyout"
// maskProps is needed in order to apply the z-index to the parent overlay element, not to the flyout only
maskProps={{ className: maskOverlayClassName }}
Expand All @@ -99,6 +102,7 @@ export const CreateCaseFlyout = React.memo<CreateCaseFlyoutProps>(
onCancel={handleCancel}
onSuccess={handleOnSuccess}
withSteps={false}
initialValue={initialValue}
/>
</FormWrapper>
</StyledEuiFlyoutBody>
Expand Down
32 changes: 31 additions & 1 deletion x-pack/plugins/cases/public/components/create/form.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import React from 'react';
import { mount } from 'enzyme';
import { act, render } from '@testing-library/react';
import { act, render, within } from '@testing-library/react';
import { licensingMock } from '@kbn/licensing-plugin/public/mocks';

import { NONE_CONNECTOR_ID } from '../../../common/api';
Expand Down Expand Up @@ -182,4 +182,34 @@ describe('CreateCaseForm', () => {

expect(result.getByTestId('createCaseAssigneesComboBox')).toBeInTheDocument();
});

it('should not prefill the form when no initialValue provided', () => {
const { getByTestId } = render(
<MockHookWrapperComponent>
<CreateCaseForm {...casesFormProps} />
</MockHookWrapperComponent>
);

const titleInput = within(getByTestId('caseTitle')).getByTestId('input');
const descriptionInput = within(getByTestId('caseDescription')).getByRole('textbox');
expect(titleInput).toHaveValue('');
expect(descriptionInput).toHaveValue('');
});

it('should prefill the form when provided with initialValue', () => {
const { getByTestId } = render(
<MockHookWrapperComponent>
<CreateCaseForm
{...casesFormProps}
initialValue={{ title: 'title', description: 'description' }}
/>
</MockHookWrapperComponent>
);

const titleInput = within(getByTestId('caseTitle')).getByTestId('input');
const descriptionInput = within(getByTestId('caseDescription')).getByRole('textbox');

expect(titleInput).toHaveValue('title');
expect(descriptionInput).toHaveValue('description');
});
});
6 changes: 5 additions & 1 deletion x-pack/plugins/cases/public/components/create/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { Tags } from './tags';
import { Connector } from './connector';
import * as i18n from './translations';
import { SyncAlertsToggle } from './sync_alerts_toggle';
import type { ActionConnector } from '../../../common/api';
import type { ActionConnector, CasePostRequest } from '../../../common/api';
import type { Case } from '../../containers/types';
import type { CasesTimelineIntegration } from '../timeline_context';
import { CasesTimelineIntegrationProvider } from '../timeline_context';
Expand Down Expand Up @@ -70,6 +70,7 @@ export interface CreateCaseFormProps extends Pick<Partial<CreateCaseFormFieldsPr
) => Promise<void>;
timelineIntegration?: CasesTimelineIntegration;
attachments?: CaseAttachmentsWithoutOwner;
initialValue?: Pick<CasePostRequest, 'title' | 'description'>;
}

const empty: ActionConnector[] = [];
Expand All @@ -79,6 +80,7 @@ export const CreateCaseFormFields: React.FC<CreateCaseFormFieldsProps> = React.m
const { isSyncAlertsEnabled, caseAssignmentAuthorized } = useCasesFeatures();

const { owner } = useCasesContext();

const availableOwners = useAvailableCasesOwners();
const canShowCaseSolutionSelection = !owner.length && availableOwners.length;

Expand Down Expand Up @@ -181,12 +183,14 @@ export const CreateCaseForm: React.FC<CreateCaseFormProps> = React.memo(
onSuccess,
timelineIntegration,
attachments,
initialValue,
}) => (
<CasesTimelineIntegrationProvider timelineIntegration={timelineIntegration}>
<FormContext
afterCaseCreated={afterCaseCreated}
onSuccess={onSuccess}
attachments={attachments}
initialValue={initialValue}
>
<CreateCaseFormFields
connectors={empty}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { usePostCase } from '../../containers/use_post_case';
import { usePostPushToService } from '../../containers/use_post_push_to_service';

import type { Case } from '../../containers/types';
import type { CasePostRequest } from '../../../common/api';
import { CaseSeverity, NONE_CONNECTOR_ID } from '../../../common/api';
import type { UseCreateAttachments } from '../../containers/use_create_attachments';
import { useCreateAttachments } from '../../containers/use_create_attachments';
Expand Down Expand Up @@ -44,13 +45,15 @@ interface Props {
children?: JSX.Element | JSX.Element[];
onSuccess?: (theCase: Case) => Promise<void>;
attachments?: CaseAttachmentsWithoutOwner;
initialValue?: Pick<CasePostRequest, 'title' | 'description'>;
}

export const FormContext: React.FC<Props> = ({
afterCaseCreated,
children,
onSuccess,
attachments,
initialValue,
}) => {
const { data: connectors = [], isLoading: isLoadingConnectors } = useGetConnectors();
const { owner, appId } = useCasesContext();
Expand Down Expand Up @@ -128,7 +131,7 @@ export const FormContext: React.FC<Props> = ({
);

const { form } = useForm<FormProps>({
defaultValue: initialCaseValue,
defaultValue: { ...initialCaseValue, ...initialValue },
options: { stripEmptyFields: false },
schema,
onSubmit: submitCase,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const SubmitCaseButtonComponent: React.FC = () => {

return (
<EuiButton
tour-step="create-case-submit"
data-test-subj="create-case-submit"
fill
iconType="plusInCircle"
Expand Down
Loading

0 comments on commit 55ef6c2

Please sign in to comment.