Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ describe('InstallationStatus', () => {
const callout = getByTestId('installation-status-callout');

expect(spacer).toHaveStyle('background: #FFFFFF');
expect(callout).toHaveStyle('padding: 8px 16px');
expect(callout).toHaveTextContent('Installed');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import React from 'react';

import { EuiCallOut, EuiSpacer, useEuiTheme } from '@elastic/eui';
import { COLOR_MODES_STANDARD, EuiCallOut, EuiIcon, EuiSpacer, useEuiTheme } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { css } from '@emotion/react';
import { css } from '@emotion/css';

import { installationStatuses } from '../../../../../../common/constants';
import type { EpmPackageInstallStatus } from '../../../../../../common/types';
Expand Down Expand Up @@ -37,8 +37,50 @@ const installStatusMapToColor: Record<
interface InstallationStatusProps {
installStatus: EpmPackageInstallStatus | null | undefined;
showInstallationStatus?: boolean;
compressed?: boolean;
}

const useInstallationStatusStyles = () => {
const { euiTheme, colorMode } = useEuiTheme();
const successBackgroundColor = euiTheme.colors.backgroundBaseSuccess;
const isDarkMode = colorMode === COLOR_MODES_STANDARD.dark;

return {
installationStatus: css`
position: absolute;
border-radius: 0 0 ${euiTheme.border.radius.medium} ${euiTheme.border.radius.medium};
bottom: 0;
left: 0;
width: 100%;
overflow: hidden;
`,
compressedInstallationStatus: css`
position: absolute;
border-radius: 0 ${euiTheme.border.radius.medium} ${euiTheme.border.radius.medium} 0;
bottom: 0;
right: 0;
width: 65px;
overflow: hidden;
display: flex;
justify-content: center;
align-items: center;
height: 100%;
background-color: ${isDarkMode ? euiTheme.colors.success : successBackgroundColor};
color: ${isDarkMode ? euiTheme.colors.emptyShade : euiTheme.colors.textSuccess};
`,
compressedInstallationStatusIcon: css`
color: ${isDarkMode ? euiTheme.colors.emptyShade : euiTheme.colors.textSuccess};
`,
installationStatusCallout: css`
padding: ${euiTheme.size.s} ${euiTheme.size.m};
text-align: center;
`,
installationStatusSpacer: css`
background: ${euiTheme.colors.emptyShade};
`,
};
};

export const getLineClampStyles = (lineClamp?: number) =>
lineClamp
? `-webkit-line-clamp: ${lineClamp};display: -webkit-box;-webkit-box-orient: vertical;overflow: hidden;`
Expand All @@ -53,35 +95,32 @@ export const shouldShowInstallationStatus = ({
installStatus === installationStatuses.InstallFailed);

export const InstallationStatus: React.FC<InstallationStatusProps> = React.memo(
({ installStatus, showInstallationStatus }) => {
const { euiTheme } = useEuiTheme();
({ installStatus, showInstallationStatus, compressed }) => {
const styles = useInstallationStatusStyles();

const cardPanelClassName = compressed
? styles.compressedInstallationStatus
: styles.installationStatus;

return shouldShowInstallationStatus({ installStatus, showInstallationStatus }) ? (
<div
css={css`
position: absolute;
border-radius: 0 0 ${euiTheme.border.radius.medium} ${euiTheme.border.radius.medium};
bottom: 0;
left: 0;
width: 100%;
overflow: hidden;
`}
>
<EuiSpacer
data-test-subj="installation-status-spacer"
size="m"
css={css`
background: ${euiTheme.colors.emptyShade};
`}
/>
<EuiCallOut
data-test-subj="installation-status-callout"
css={css`
padding: ${euiTheme.size.s} ${euiTheme.size.m};
text-align: center;
`}
{...(installStatus ? installStatusMapToColor[installStatus] : {})}
/>
</div>
compressed ? (
<div className={cardPanelClassName}>
<EuiIcon type="checkInCircleFilled" className={styles.compressedInstallationStatusIcon} />
</div>
) : (
<div className={cardPanelClassName}>
<EuiSpacer
data-test-subj="installation-status-spacer"
size="m"
className={styles.installationStatusSpacer}
/>
<EuiCallOut
data-test-subj="installation-status-callout"
className={styles.installationStatusCallout}
{...(installStatus ? installStatusMapToColor[installStatus] : {})}
/>
</div>
)
) : null;
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export function PackageCard({
isUpdateAvailable,
showLabels = true,
showInstallationStatus,
showCompressedInstallationStatus,
extraLabelsBadges,
isQuickstart = false,
installStatus,
Expand Down Expand Up @@ -256,6 +257,7 @@ export function PackageCard({
<InstallationStatus
installStatus={installStatus}
showInstallationStatus={showInstallationStatus}
compressed={showCompressedInstallationStatus}
/>
</EuiFlexGroup>
</EuiCard>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface IntegrationCardItem {
release?: IntegrationCardReleaseLabel;
showDescription?: boolean;
showInstallationStatus?: boolean;
showCompressedInstallationStatus?: boolean;
showLabels?: boolean;
showReleaseBadge?: boolean;
title: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { NoDataFound } from './no_data_found';
import { renderWithTestProvider } from '../../test/test_provider';

// Mocking components which implementation details are out of scope for this unit test
jest.mock('../../../onboarding/components/onboarding_context', () => ({
OnboardingContextProvider: () => <div data-test-subj="onboarding-grid" />,
jest.mock('../../../common/lib/integrations/hooks/integration_context', () => ({
IntegrationContextProvider: () => <div data-test-subj="integration-grid" />,
}));

jest.mock('../../../common/hooks/use_space_id');
Expand Down Expand Up @@ -40,6 +40,6 @@ describe('NoDataFound Component', () => {
screen.getByRole('heading', { name: /connect sources to discover assets/i })
).toBeInTheDocument();

expect(screen.getByTestId('onboarding-grid')).toBeInTheDocument();
expect(screen.getByTestId('integration-grid')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import {
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';
import { OnboardingContextProvider } from '../../../onboarding/components/onboarding_context';
import { useSpaceId } from '../../../common/hooks/use_space_id';
import { AssetInventoryTitle } from '../asset_inventory_title';
import { AssetInventoryLoading } from '../asset_inventory_loading';
import illustration from '../../../common/images/integrations_light.png';
import { IntegrationsCardGridTabs } from '../../../onboarding/components/onboarding_body/cards/integrations/integration_card_grid_tabs';
import { TEST_SUBJ_ONBOARDING_NO_DATA_FOUND } from '../../constants';
import { SecurityIntegrations } from '../../../common/lib/integrations/components';
import { IntegrationContextProvider } from '../../../common/lib/integrations/hooks/integration_context';

export const NoDataFound = () => {
const spaceId = useSpaceId();
Expand Down Expand Up @@ -68,9 +68,9 @@ export const NoDataFound = () => {
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer size="l" />
<OnboardingContextProvider spaceId={spaceId}>
<IntegrationsCardGridTabs installedIntegrationsCount={0} isAgentRequired={false} />
</OnboardingContextProvider>
<IntegrationContextProvider spaceId={spaceId}>
<SecurityIntegrations />
</IntegrationContextProvider>
</EuiPanel>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,44 @@
*/
import { useCallback, useMemo } from 'react';
import { useLocation } from 'react-router-dom';
import { ADD_DATA_PATH, ADD_THREAT_INTELLIGENCE_DATA_PATH } from '../../../common/constants';
import { useNavigateTo, useGetAppUrl } from '@kbn/security-solution-navigation';
import {
ADD_DATA_PATH,
ADD_THREAT_INTELLIGENCE_DATA_PATH,
SECURITY_FEATURE_ID,
SecurityPageName,
} from '../../../common/constants';
import { isThreatIntelligencePath } from '../../helpers';

import { useKibana, useNavigateTo } from '../lib/kibana';
import { useKibana } from '../lib/kibana';
import { hasCapabilities } from '../lib/capabilities';

export const useAddIntegrationsUrl = () => {
const {
http: {
basePath: { prepend },
},
application: { capabilities },
} = useKibana().services;
const { pathname } = useLocation();
const { getAppUrl } = useGetAppUrl();
const { navigateTo } = useNavigateTo();

const isThreatIntelligence = isThreatIntelligencePath(pathname);
const hasSearchAILakeAccess = hasCapabilities(capabilities, [
[`${SECURITY_FEATURE_ID}.external_detections`],
]);

const integrationsUrl = isThreatIntelligence ? ADD_THREAT_INTELLIGENCE_DATA_PATH : ADD_DATA_PATH;
const searchAILakeIntegrationsPath = getAppUrl({
deepLinkId: SecurityPageName.configurationsIntegrations,
path: 'browse',
});

const integrationsUrl = isThreatIntelligence
? ADD_THREAT_INTELLIGENCE_DATA_PATH
: hasSearchAILakeAccess
? searchAILakeIntegrationsPath
: ADD_DATA_PATH;
Comment on lines +33 to +46
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are just checking whether the user needs to be redirected to the configurations page or the regular integrations page.
Why are concepts like "SearchAILake" or external_detections introduced here? People coming here will need to know more information than is necessary. And this is also introducing coupling.

Couldn't we just do:

  const shouldGoToConfigurations = hasCapabilities(
    capabilities,
    `${SECURITY_FEATURE_ID}.configurations`
  );

  const integrationsConfigurationsPath = getAppUrl({
    deepLinkId: SecurityPageName.configurationsIntegrations,
    path: 'browse',
  });

  const integrationsUrl = isThreatIntelligence
    ? ADD_THREAT_INTELLIGENCE_DATA_PATH
    : shouldGoToConfigurations
    ? integrationsConfigurationsPath
    : ADD_DATA_PATH;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


const href = useMemo(() => prepend(integrationsUrl), [prepend, integrationsUrl]);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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';

export const SecurityIntegrations = () => <div data-test-subj="securityIntegrations" />;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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';

export const WithFilteredIntegrations = () => <div data-test-subj="withFilteredIntegrations" />;
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 type { AvailablePackagesHookType } from '@kbn/fleet-plugin/public';
import type { UseSelectedTabReturn } from '../hooks/use_selected_tab';
import type { IntegrationCardMetadata, RenderChildrenType, TopCalloutRenderer } from '../types';
import { useFilterCards } from '../hooks/use_filter_cards';

export const AvailableIntegrationsComponent: React.FC<{
useAvailablePackages: AvailablePackagesHookType;
renderChildren: RenderChildrenType;
prereleaseIntegrationsEnabled: boolean;
checkCompleteMetadata?: IntegrationCardMetadata;
selectedTabResult: UseSelectedTabReturn;
topCalloutRenderer?: TopCalloutRenderer;
}> = ({
useAvailablePackages,
renderChildren,
prereleaseIntegrationsEnabled,
checkCompleteMetadata,
selectedTabResult,
topCalloutRenderer,
}) => {
const { availablePackagesResult, allowedIntegrations } = useFilterCards({
featuredCardIds: selectedTabResult.selectedTab?.featuredCardIds,
useAvailablePackages,
prereleaseIntegrationsEnabled,
});

return renderChildren({
Comment thread
semd marked this conversation as resolved.
allowedIntegrations,
availablePackagesResult,
checkCompleteMetadata,
selectedTabResult,
topCalloutRenderer,
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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 { useSelectedTab } from '../hooks/use_selected_tab';
import { INTEGRATION_TABS } from '../configs/integration_tabs_configs';
import { IntegrationsCardGridTabs } from './integration_card_grid_tabs';
import { WithFilteredIntegrations } from './with_filtered_integrations';
import type { IntegrationCardMetadata, TopCalloutRenderer } from '../types';
import { useIntegrationContext } from '../hooks/integration_context';

export const SecurityIntegrations: React.FC<{
checkCompleteMetadata?: IntegrationCardMetadata;
topCalloutRenderer?: TopCalloutRenderer;
}> = ({ checkCompleteMetadata, topCalloutRenderer }) => {
const { spaceId } = useIntegrationContext();
const selectedTabResult = useSelectedTab({
spaceId,
integrationTabs: INTEGRATION_TABS,
});
Comment on lines +19 to +23
Copy link
Copy Markdown
Contributor

@semd semd Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we do this in the AvailableIntegrationsComponent? It seems the logic to retrieve integrations is spread across different components and passed by props. Consider centralising the logic in one place and reducing the number of components.

return (
<WithFilteredIntegrations
renderChildren={IntegrationsCardGridTabs}
prereleaseIntegrationsEnabled={false}
selectedTabResult={selectedTabResult}
checkCompleteMetadata={checkCompleteMetadata}
topCalloutRenderer={topCalloutRenderer}
/>
);
};
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 type { RenderChildrenType } from '../types';
import { useIntegrationCardList } from '../hooks/use_integration_card_list';
import { IntegrationsCardGridTabsComponent } from './integration_card_grid_tabs_component';

export const DEFAULT_CHECK_COMPLETE_METADATA = {
installedIntegrationsCount: 0,
isAgentRequired: false,
};

export const IntegrationsCardGridTabs: RenderChildrenType = ({
topCalloutRenderer,
allowedIntegrations,
availablePackagesResult,
checkCompleteMetadata = DEFAULT_CHECK_COMPLETE_METADATA,
selectedTabResult,
}) => {
const list = useIntegrationCardList({
integrationsList: allowedIntegrations,
featuredCardIds: selectedTabResult.selectedTab?.featuredCardIds,
});

const { installedIntegrationsCount, isAgentRequired } = checkCompleteMetadata;

return (
<IntegrationsCardGridTabsComponent
isAgentRequired={isAgentRequired}
installedIntegrationsCount={installedIntegrationsCount}
topCalloutRenderer={topCalloutRenderer}
integrationList={list}
availablePackagesResult={availablePackagesResult}
selectedTabResult={selectedTabResult}
/>
);
};
Loading
Loading