Skip to content

Commit

Permalink
Only show data warning screen on Serverless (#201920)
Browse files Browse the repository at this point in the history
## Summary

This PR resolves
[#11064](elastic/security-team#11064), where
the warning was previously shown in both serverless and non-serverless
instances. A quick fix removed the message entirely, and this update
reintroduces it for serverless environments only.

This PR adds a data warning specific to serverless environments using
upselling with the callout component from serverless solution
components. The idea being to avoid adding a lot of `if serverless`
checks throughout the component as mentioned
elastic/security-team#11064 (comment)

### To Test 

**Start a serverless instance** using these doccos:
https://docs.elastic.dev/security-solution/dev-docs/serverless or
following steps locally:

1. Using VSCode, Reopen PR in container. 
2. Start ElasticSearch: yarn es serverless --projectType security --ssl
--kill
3. Start Kibana (this is the only way I can make it work...): yarn start
--serverless=security --username=your_username --password=your_password

**Test the modal works as expected**: 

1. Remove / disable the 'entitytStoreDisable' flag here
**/config/serverless.security.yml** (I commented it out) for modal to
then show
2. Go to dashboards - Entity Analytics, hit the enable button and view
modal.

### Before 


![image](https://github.com/user-attachments/assets/43ac266d-9be1-47d3-874d-9edc9393fdd1)

### After 


![image](https://github.com/user-attachments/assets/a7bf47fb-8737-478b-9782-fe6897980e03)

### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
  • Loading branch information
CAWilson94 authored Nov 28, 2024
1 parent d3727a5 commit e9ee5b4
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { Observable } from 'rxjs';
export type ContractComponents = Partial<{
GetStarted: React.ComponentType<{ indicesExist?: boolean }>;
DashboardsLandingCallout: React.ComponentType<{}>;
EnablementModalCallout: React.ComponentType<{}>;
}>;

export type SetComponents = (components: ContractComponents) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import React from 'react';
import { act } from 'react-dom/test-utils';
import { fireEvent, render, screen } from '@testing-library/react';
import { EntityStoreEnablementModal } from './enablement_modal';
import { TestProviders } from '../../../../common/mock';
Expand All @@ -25,6 +26,11 @@ jest.mock('../../../hooks/use_missing_risk_engine_privileges', () => ({
useMissingRiskEnginePrivileges: () => mockUseMissingRiskEnginePrivileges(),
}));

const mockUseContractComponents = jest.fn(() => ({}));
jest.mock('../../../../common/hooks/use_contract_component', () => ({
useContractComponents: () => mockUseContractComponents(),
}));

const defaultProps = {
visible: true,
toggle: mockToggle,
Expand Down Expand Up @@ -77,8 +83,10 @@ const missingRiskEnginePrivileges: RiskEngineMissingPrivilegesResponse = {
},
};

const renderComponent = (props = defaultProps) => {
return render(<EntityStoreEnablementModal {...props} />, { wrapper: TestProviders });
const renderComponent = async (props = defaultProps) => {
await act(async () => {
return render(<EntityStoreEnablementModal {...props} />, { wrapper: TestProviders });
});
};

describe('EntityStoreEnablementModal', () => {
Expand Down Expand Up @@ -172,5 +180,16 @@ describe('EntityStoreEnablementModal', () => {
renderComponent();
expect(screen.getByTestId('callout-missing-risk-engine-privileges')).toBeInTheDocument();
});

it('should render additional charges message when available', async () => {
const EnablementModalCalloutMock = () => <span data-test-subj="enablement-modal-test" />;
mockUseContractComponents.mockReturnValue({
EnablementModalCallout: EnablementModalCalloutMock,
});

await renderComponent();

expect(screen.queryByTestId('enablement-modal-test')).toBeInTheDocument();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
import { css } from '@emotion/react';
import React, { useState } from 'react';
import { FormattedMessage } from '@kbn/i18n-react';
import { useContractComponents } from '../../../../common/hooks/use_contract_component';
import { TECHNICAL_PREVIEW, TECHNICAL_PREVIEW_TOOLTIP } from '../../../../common/translations';
import {
ENABLEMENT_DESCRIPTION_RISK_ENGINE_ONLY,
Expand Down Expand Up @@ -72,6 +73,7 @@ export const EntityStoreEnablementModal: React.FC<EntityStoreEnablementModalProp
useEntityEnginePrivileges();
const riskEnginePrivileges = useMissingRiskEnginePrivileges();
const enablementOptions = enablements.riskScore || enablements.entityStore;
const { EnablementModalCallout } = useContractComponents();

if (!visible) {
return null;
Expand Down Expand Up @@ -100,6 +102,7 @@ export const EntityStoreEnablementModal: React.FC<EntityStoreEnablementModalProp

<EuiModalBody>
<EuiFlexGroup direction="column">
<EuiFlexItem>{EnablementModalCallout && <EnablementModalCallout />}</EuiFlexItem>
<EuiFlexItem>
<EuiSwitch
label={
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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 } from '@elastic/eui';
import { ADDITIONAL_CHARGES_MESSAGE } from '../../upselling/translations';

export const EnablementModalCallout: React.FC = () => {
return (
<div>
<EuiText>{ADDITIONAL_CHARGES_MESSAGE}</EuiText>
</div>
);
};

// eslint-disable-next-line import/no-default-export
export default EnablementModalCallout;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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 type { Services } from '../../common/services';
import { ServicesProvider } from '../../common/services';
import { EnablementModalCallout } from './lazy';

export const getEnablementModalCallout = (services: Services): React.ComponentType =>
function EnablementModalCalloutComponent() {
return (
<ServicesProvider services={services}>
<EnablementModalCallout />
</ServicesProvider>
);
};
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.
*/

import React, { lazy, Suspense } from 'react';
import { EuiLoadingSpinner } from '@elastic/eui';

const EnablementModalCalloutLazy = lazy(() => import('./enablement_modal_callout'));

export const EnablementModalCallout = () => (
<Suspense fallback={<EuiLoadingSpinner size="s" />}>
<EnablementModalCalloutLazy />
</Suspense>
);
2 changes: 2 additions & 0 deletions x-pack/plugins/security_solution_serverless/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
type ExperimentalFeatures,
} from '../common/experimental_features';
import { setOnboardingSettings } from './onboarding';
import { getEnablementModalCallout } from './components/enablement_modal_callout';

export class SecuritySolutionServerlessPlugin
implements
Expand Down Expand Up @@ -69,6 +70,7 @@ export class SecuritySolutionServerlessPlugin

securitySolution.setComponents({
DashboardsLandingCallout: getDashboardsLandingCallout(services),
EnablementModalCallout: getEnablementModalCallout(services),
});

setOnboardingSettings(services);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,11 @@ export const UPGRADE_PRODUCT_MESSAGE = (requiredProduct: string) =>
},
}
);

export const ADDITIONAL_CHARGES_MESSAGE = i18n.translate(
'xpack.securitySolutionServerless.entityStoreEnablementCallout.additionalChargesMessage',
{
defaultMessage:
'Please be aware that activating these features may incur additional charges depending on your subscription plan. Review your plan details carefully to avoid unexpected costs before proceeding.',
}
);

0 comments on commit e9ee5b4

Please sign in to comment.