Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SecuritySolution] Rename security solution plugins #161153

Merged
merged 17 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor constants
  • Loading branch information
semd committed Jul 4, 2023
commit 5e8d8c72e38b6fd244455634f2ddef53b9f1355e
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
* 2.0.
*/

import type { PluginStart as SecuritySolutionPluginStart } from '@kbn/security-solution-plugin/public';
import type { ChromeBreadcrumb, CoreStart } from '@kbn/core/public';
import type { ChromeBreadcrumb } from '@kbn/core/public';
import type { Services } from '../common/services';

export const subscribeBreadcrumbs = (
securitySolution: SecuritySolutionPluginStart,
core: CoreStart
) => {
export const subscribeBreadcrumbs = (services: Services) => {
const { chrome, securitySolution } = services;
securitySolution.getBreadcrumbsNav$().subscribe((breadcrumbsNav) => {
const breadcrumbs = [...breadcrumbsNav.leading, ...breadcrumbsNav.trailing];
if (breadcrumbs.length > 0) {
core.chrome.setBreadcrumbs(emptyLastBreadcrumbUrl(breadcrumbs));
chrome.setBreadcrumbs(emptyLastBreadcrumbUrl(breadcrumbs));
}
});
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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 { I18nProvider } from '@kbn/i18n-react';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import { coreMock } from '@kbn/core/public/mocks';
import { securitySolutionMock } from '@kbn/security-solution-plugin/public/mocks';
import type { Services } from './services';

export const servicesMocks: Services = {
...coreMock.createStart(),
securitySolution: securitySolutionMock.createStart(),
};

export const KibanaServicesProvider = React.memo(function KibanaServicesProvider({ children }) {
return (
<I18nProvider>
<KibanaContextProvider services={servicesMocks}>{children}</KibanaContextProvider>
</I18nProvider>
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@ import {
KibanaContextProvider,
useKibana as useKibanaReact,
} from '@kbn/kibana-react-plugin/public';
import type { SecuritySolutionEssPluginStartDeps } from './types';
import type { SecuritySolutionEssPluginStartDeps } from '../types';

export type Services = CoreStart & SecuritySolutionEssPluginStartDeps;

export const KibanaServicesProvider: React.FC<{
core: CoreStart;
pluginsStart: SecuritySolutionEssPluginStartDeps;
}> = ({ core, pluginsStart, children }) => {
const services: Services = { ...core, ...pluginsStart };
services: Services;
}> = ({ services, children }) => {
return <KibanaContextProvider services={services}>{children}</KibanaContextProvider>;
};

export const useKibana = () => useKibanaReact<Services>();

export const createServices = (
core: CoreStart,
pluginsStart: SecuritySolutionEssPluginStartDeps
): Services => {
return { ...core, ...pluginsStart };
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,13 @@
*/
import React from 'react';

import type { CoreStart } from '@kbn/core/public';
import { KibanaServicesProvider } from '../services';
import type { SecuritySolutionEssPluginStartDeps } from '../types';
import { KibanaServicesProvider, type Services } from '../common/services';
import { GetStarted } from './lazy';

export const getSecurityGetStartedComponent = (
core: CoreStart,
pluginsStart: SecuritySolutionEssPluginStartDeps
) =>
export const getSecurityGetStartedComponent = (services: Services): React.ComponentType =>
function GetStartedComponent() {
return (
<KibanaServicesProvider core={core} pluginsStart={pluginsStart}>
<KibanaServicesProvider services={services}>
<GetStarted />
</KibanaServicesProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ADD_DATA_PATH } from '@kbn/security-solution-plugin/common';
import { useVariation } from '../common/hooks/use_variation';

jest.mock('../common/hooks/use_variation');
jest.mock('../services');
jest.mock('../common/services');

describe('LandingCards component', () => {
beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import * as i18n from './translations';
import endpointSvg from './images/endpoint1.svg';
import cloudSvg from './images/cloud1.svg';
import siemSvg from './images/siem1.svg';
import { useKibana } from '../services';
import { useKibana } from '../common/services';

const imgUrls = {
cloud: cloudSvg,
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/security_solution_ess/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import type { CoreSetup, CoreStart, Plugin } from '@kbn/core/public';
import { subscribeBreadcrumbs } from './breadcrumbs';
import { createServices } from './common/services';
import { getSecurityGetStartedComponent } from './get_started';
import type {
SecuritySolutionEssPluginSetup,
Expand Down Expand Up @@ -36,9 +37,10 @@ export class SecuritySolutionEssPlugin
startDeps: SecuritySolutionEssPluginStartDeps
): SecuritySolutionEssPluginStart {
const { securitySolution } = startDeps;
const services = createServices(core, startDeps);

subscribeBreadcrumbs(securitySolution, core);
securitySolution.setGetStartedPage(getSecurityGetStartedComponent(core, startDeps));
securitySolution.setGetStartedPage(getSecurityGetStartedComponent(services));
subscribeBreadcrumbs(services);

return {};
}
Expand Down
14 changes: 6 additions & 8 deletions x-pack/plugins/security_solution_serverless/common/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@
* 2.0.
*/

import { schema, TypeOf } from '@kbn/config-schema';

export enum ProductLine {
security = 'security',
cloud = 'cloud',
endpoint = 'endpoint',
}
import { schema, type TypeOf } from '@kbn/config-schema';
import { ProductLine, ProductTier } from './product';

export const productLine = schema.oneOf([
schema.literal(ProductLine.security),
Expand All @@ -21,7 +16,10 @@ export const productLine = schema.oneOf([

export type SecurityProductLine = TypeOf<typeof productLine>;

export const productTier = schema.oneOf([schema.literal('essentials'), schema.literal('complete')]);
export const productTier = schema.oneOf([
schema.literal(ProductTier.essentials),
schema.literal(ProductTier.complete),
]);
export type SecurityProductTier = TypeOf<typeof productTier>;

export const productType = schema.object({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import { getProductAppFeatures } from './pli_features';
import * as pliConfig from './pli_config';
import { ProductLine } from '../config';
import { ProductLine, ProductTier } from '../product';

describe('getProductAppFeatures', () => {
it('should return the essentials PLIs features', () => {
Expand All @@ -19,7 +19,7 @@ describe('getProductAppFeatures', () => {
};

const appFeatureKeys = getProductAppFeatures([
{ product_line: ProductLine.security, product_tier: 'essentials' },
{ product_line: ProductLine.security, product_tier: ProductTier.essentials },
]);

expect(appFeatureKeys).toEqual(['foo']);
Expand All @@ -35,7 +35,7 @@ describe('getProductAppFeatures', () => {
};

const appFeatureKeys = getProductAppFeatures([
{ product_line: ProductLine.security, product_tier: 'complete' },
{ product_line: ProductLine.security, product_tier: ProductTier.complete },
]);

expect(appFeatureKeys).toEqual(['foo', 'baz']);
Expand All @@ -59,9 +59,9 @@ describe('getProductAppFeatures', () => {
};

const appFeatureKeys = getProductAppFeatures([
{ product_line: ProductLine.security, product_tier: 'essentials' },
{ product_line: ProductLine.endpoint, product_tier: 'complete' },
{ product_line: ProductLine.cloud, product_tier: 'essentials' },
{ product_line: ProductLine.security, product_tier: ProductTier.essentials },
{ product_line: ProductLine.endpoint, product_tier: ProductTier.complete },
{ product_line: ProductLine.cloud, product_tier: ProductTier.essentials },
]);

expect(appFeatureKeys).toEqual(['foo', 'bar', 'repeated', 'qux', 'quux', 'corge', 'garply']);
Expand Down
17 changes: 17 additions & 0 deletions x-pack/plugins/security_solution_serverless/common/product.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* 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.
*/

export enum ProductLine {
security = 'security',
endpoint = 'endpoint',
cloud = 'cloud',
}

export enum ProductTier {
essentials = 'essentials',
complete = 'complete',
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ export const servicesMocks: Services = {
getProjectNavLinks$: jest.fn(() => new BehaviorSubject(mockProjectNavLinks())),
};

export const KibanaServicesProvider = React.memo(({ children }) => (
<I18nProvider>
<KibanaContextProvider services={servicesMocks}>{children}</KibanaContextProvider>
</I18nProvider>
));
export const KibanaServicesProvider = React.memo(function KibanaServicesProvider({ children }) {
return (
<I18nProvider>
<KibanaContextProvider services={servicesMocks}>{children}</KibanaContextProvider>
</I18nProvider>
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { CoreStart } from '@kbn/core/public';
import type { CoreStart } from '@kbn/core/public';
import React from 'react';
import {
KibanaContextProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
SectionId,
} from './types';
import * as sectionsConfigs from './sections';
import { ProductLine } from '../../common/config';
import { ProductLine } from '../../common/product';
const mockSections = jest.spyOn(sectionsConfigs, 'getSections');
describe('getCardTimeInMinutes', () => {
it('should calculate the total time in minutes for a card correctly', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type { ProductLine } from '../../common/config';
import type { ProductLine } from '../../common/product';
import { getSections } from './sections';
import type { ActiveCard, ActiveCards, Card, CardId, SectionId, StepId } from './types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
import React from 'react';

import { KibanaServicesProvider, type Services } from '../common/services';
import type { GetStartedComponent } from './types';
import { GetStarted } from './lazy';
import type { SecurityProductTypes } from '../../common/config';

export const getSecurityGetStartedComponent = (
services: Services,
productTypes: SecurityProductTypes
): GetStartedComponent =>
): React.ComponentType =>
function GetStartedComponent() {
return (
<KibanaServicesProvider services={services}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import { ProductSwitch } from './product_switch';
import type { EuiThemeComputed } from '@elastic/eui';
import { ProductLine } from '../../common/config';
import { ProductLine } from '../../common/product';

describe('ProductSwitch', () => {
const onProductSwitchChangedMock = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { EuiPanel, EuiSwitch, EuiText, EuiTitle, type EuiThemeComputed } from '@elastic/eui';
import { css } from '@emotion/react';
import React, { useMemo } from 'react';
import { ProductLine } from '../../common/config';
import { ProductLine } from '../../common/product';
import * as i18n from './translations';
import type { Switch } from './types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { ProductLine } from '../../common/config';
import { ProductLine } from '../../common/product';
import {
reducer,
getFinishedStepsInitialStates,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type { ProductLine } from '../../common/config';
import type { ProductLine } from '../../common/product';
import { setupCards, updateCard } from './helpers';
import {
type CardId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import * as i18n from './translations';
import respond from './images/respond.svg';
import protect from './images/protect.svg';
import { ProductLine } from '../../common/config';
import { ProductLine } from '../../common/product';

export const introductionSteps = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { getStartedStorage } from './storage';
import { GetSetUpCardId, IntroductionSteps, type StepId } from './types';
import { storage } from '../common/lib/storage';
import type { MockStorage } from '../common/lib/__mocks__/storage';
import { ProductLine } from '../../common/config';
import { ProductLine } from '../../common/product';

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

describe('useStorage', () => {
const mockStorage = storage as unknown as MockStorage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import type { ProductLine } from '../../common/config';
import type { ProductLine } from '../../common/product';
import type { CardId, StepId } from './types';
import { storage } from '../common/lib/storage';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ import { TogglePanel } from './toggle_panel';
import { useSetUpCardSections } from './use_setup_cards';
import type { ActiveCards, CardId, StepId } from './types';
import { GetSetUpCardId, IntroductionSteps, SectionId } from './types';
import { ProductLine } from '../../common/config';
import { ProductLine } from '../../common/product';

jest.mock('@elastic/eui', () => ({
...jest.requireActual('@elastic/eui'),
useEuiTheme: jest.fn(() => ({ euiTheme: { base: 16, size: { xs: '4px' } } })),
useEuiShadow: jest.fn(),
}));

jest.mock('../../lib/get_started/storage');

jest.mock('./use_setup_cards', () => ({
useSetUpCardSections: jest.fn(),
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import * as i18n from './translations';
import { useSetUpCardSections } from './use_setup_cards';

import type { ActiveCards, CardId, IntroductionSteps, SectionId } from './types';
import type { ProductLine } from '../../common/config';
import type { ProductLine } from '../../common/product';

const TogglePanelComponent: React.FC<{
finishedSteps: Record<CardId, Set<IntroductionSteps>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@

import type { EuiIconProps } from '@elastic/eui';
import type React from 'react';
import type { ProductLine } from '../../common/config';

// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export type GetStartedComponentProps = {};

export type GetStartedComponent = (props?: GetStartedComponentProps) => JSX.Element;
import type { ProductLine } from '../../common/product';

export interface HeaderSection {
description?: string;
Expand Down
Loading