Skip to content

Commit

Permalink
opening panel
Browse files Browse the repository at this point in the history
  • Loading branch information
tiansivive committed Jan 2, 2024
1 parent d3db40e commit 9b10b2e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import { css } from '@emotion/react';
import { FormattedMessage } from '@kbn/i18n-react';
import { euiThemeVars } from '@kbn/ui-theme';
import { i18n } from '@kbn/i18n';
import { EntityDetailsLeftPanelTab } from '../../../flyout/entity_details/shared/components/left_panel/left_panel_header';
import type {
HostRiskScore,
UserRiskScore,
} from '../../../../common/search_strategy/security_solution/risk_score';
import { UserDetailsLeftPanelTab } from '../../../flyout/entity_details/user_details_left/tabs';
import { InspectButton, InspectButtonContainer } from '../../../common/components/inspect';
import { ONE_WEEK_IN_HOURS } from '../../../timelines/components/side_panel/new_user_detail/constants';
import { FormattedRelativePreferenceDate } from '../../../common/components/formatted_date';
Expand All @@ -38,7 +38,7 @@ import { getRiskScoreSummaryAttributes } from '../../lens_attributes/risk_score_
export interface RiskSummaryProps<T extends RiskScoreEntity> {
riskScoreData: RiskScoreState<T>;
queryId: string;
openDetailsPanel: (tab: UserDetailsLeftPanelTab) => void;
openDetailsPanel: (tab: EntityDetailsLeftPanelTab) => void;
entity: T;
}

Expand Down Expand Up @@ -174,7 +174,7 @@ const RiskSummaryComponent = <T extends RiskScoreEntity>({
/>
),
link: {
callback: () => openDetailsPanel(UserDetailsLeftPanelTab.RISK_INPUTS),
callback: () => openDetailsPanel(EntityDetailsLeftPanelTab.RISK_INPUTS),
tooltip: (
<FormattedMessage
id="xpack.securitySolution.flyout.entityDetails.showAllRiskInputs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ import { ObservedEntity } from '../shared/components/observed_entity';
import { HOST_PANEL_OBSERVED_HOST_QUERY_ID, HOST_PANEL_RISK_SCORE_QUERY_ID } from '.';
import type { ObservedEntityData } from '../shared/components/observed_entity/types';
import { useObservedHostFields } from './hooks/use_observed_host_fields';
import type { EntityDetailsLeftPanelTab } from '../shared/components/left_panel/left_panel_header';

interface HostPanelContentProps {
observedHost: ObservedEntityData<HostItem>;
riskScoreState: RiskScoreState<RiskScoreEntity.user>;
contextID: string;
scopeId: string;
isDraggable: boolean;
openDetailsPanel: (tab: EntityDetailsLeftPanelTab) => void;
}

export const HostPanelContent = ({
Expand All @@ -32,6 +34,7 @@ export const HostPanelContent = ({
contextID,
scopeId,
isDraggable,
openDetailsPanel,
}: HostPanelContentProps) => {
const observedFields = useObservedHostFields(observedHost);

Expand All @@ -44,7 +47,7 @@ export const HostPanelContent = ({
riskScoreData={riskScoreState}
queryId={HOST_PANEL_RISK_SCORE_QUERY_ID}
entity={RiskScoreEntity.host}
openDetailsPanel={() => {}}
openDetailsPanel={openDetailsPanel}
/>
}
<EuiHorizontalRule margin="m" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import React, { useCallback, useMemo } from 'react';
import type { FlyoutPanelProps } from '@kbn/expandable-flyout';
import { useExpandableFlyoutContext } from '@kbn/expandable-flyout';

import { hostToCriteria } from '../../../common/components/ml/criteria/host_to_criteria';
import { useRiskScore } from '../../../entity_analytics/api/hooks/use_risk_score';
import { useQueryInspector } from '../../../common/components/page/manage_query';
Expand All @@ -23,6 +24,7 @@ import { AnomalyTableProvider } from '../../../common/components/ml/anomaly/anom
import type { ObservedEntityData } from '../shared/components/observed_entity/types';
import { useObservedHost } from './hooks/use_observed_host';
import { HostDetailsPanelKey } from '../host_details_left';
import type { EntityDetailsLeftPanelTab } from '../shared/components/left_panel/left_panel_header';

export interface HostPanelProps extends Record<string, unknown> {
contextID: string;
Expand Down Expand Up @@ -72,17 +74,25 @@ export const HostPanel = ({ contextID, scopeId, hostName, isDraggable }: HostPan
setQuery,
});

const openPanel = useCallback(() => {
openLeftPanel({
id: HostDetailsPanelKey,
params: {
riskInputs: {
alertIds: hostRiskData?.host.risk.inputs?.map(({ id }) => id) ?? [],
const openTabPanel = useCallback(
(tab?: EntityDetailsLeftPanelTab) => {
openLeftPanel({
id: HostDetailsPanelKey,
params: {
riskInputs: {
alertIds: hostRiskData?.host.risk.inputs?.map(({ id }) => id) ?? [],
host: {
name: hostName,
},
},
path: tab ? { tab } : undefined,
},
},
});
}, [openLeftPanel, hostRiskData?.host.risk.inputs]);
});
},
[openLeftPanel, hostRiskData?.host.risk.inputs, hostName]
);

const openDefaultPanel = useCallback(() => openTabPanel(), [openTabPanel]);
const observedHost = useObservedHost(hostName);

if (riskScoreState.loading || observedHost.isLoading) {
Expand Down Expand Up @@ -110,7 +120,7 @@ export const HostPanel = ({ contextID, scopeId, hostName, isDraggable }: HostPan
<>
<FlyoutNavigation
flyoutIsExpandable={!!hostRiskData?.host.risk}
expandDetails={openPanel}
expandDetails={openDefaultPanel}
/>
<HostPanelHeader hostName={hostName} observedHost={observedHostWithAnomalies} />
<HostPanelContent
Expand All @@ -119,6 +129,7 @@ export const HostPanel = ({ contextID, scopeId, hostName, isDraggable }: HostPan
contextID={contextID}
scopeId={scopeId}
isDraggable={!!isDraggable}
openDetailsPanel={openTabPanel}
/>
</>
);
Expand Down

0 comments on commit 9b10b2e

Please sign in to comment.