Skip to content

Commit

Permalink
update rule link in case activities
Browse files Browse the repository at this point in the history
  • Loading branch information
christineweng committed Nov 4, 2024
1 parent a8c54f2 commit e8c67d8
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 90 deletions.
4 changes: 2 additions & 2 deletions x-pack/plugins/cases/public/client/ui/get_cases.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const getCasesLazy = ({
permissions,
basePath,
actionsNavigation,
ruleDetailsNavigation,
showRuleDetails,
showAlertDetails,
useFetchAlertData,
onAlertsTableLoaded,
Expand All @@ -53,7 +53,7 @@ export const getCasesLazy = ({
<Suspense fallback={<EuiLoadingSpinner />}>
<CasesRoutesLazy
actionsNavigation={actionsNavigation}
ruleDetailsNavigation={ruleDetailsNavigation}
showRuleDetails={showRuleDetails}
showAlertDetails={showAlertDetails}
useFetchAlertData={useFetchAlertData}
onAlertsTableLoaded={onAlertsTableLoaded}
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/cases/public/components/app/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const CaseViewLazy: React.FC<CaseViewProps> = lazy(() => import('../case_view'))

const CasesRoutesComponent: React.FC<CasesRoutesProps> = ({
actionsNavigation,
ruleDetailsNavigation,
showRuleDetails,
showAlertDetails,
useFetchAlertData,
onAlertsTableLoaded,
Expand Down Expand Up @@ -83,7 +83,7 @@ const CasesRoutesComponent: React.FC<CasesRoutesProps> = ({
<Suspense fallback={<EuiLoadingSpinner />}>
<CaseViewLazy
actionsNavigation={actionsNavigation}
ruleDetailsNavigation={ruleDetailsNavigation}
showRuleDetails={showRuleDetails}
showAlertDetails={showAlertDetails}
useFetchAlertData={useFetchAlertData}
onAlertsTableLoaded={onAlertsTableLoaded}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/public/components/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { CasesTimelineIntegration } from '../timeline_context';

export interface CasesRoutesProps {
actionsNavigation?: CasesNavigation<string, 'configurable'>;
ruleDetailsNavigation?: CasesNavigation<string | null | undefined, 'configurable'>;
showRuleDetails?: (ruleId: string) => void;
showAlertDetails?: (alertId: string, index: string) => void;
useFetchAlertData: UseFetchAlertData;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const CaseViewPage = React.memo<CaseViewPageProps>(
({
caseData,
refreshRef,
ruleDetailsNavigation,
showRuleDetails,
actionsNavigation,
showAlertDetails,
useFetchAlertData,
Expand Down Expand Up @@ -111,7 +111,7 @@ export const CaseViewPage = React.memo<CaseViewPageProps>(
<EuiFlexGroup data-test-subj={`case-view-tab-content-${activeTabId}`} alignItems="baseline">
{activeTabId === CASE_VIEW_PAGE_TABS.ACTIVITY && (
<CaseViewActivity
ruleDetailsNavigation={ruleDetailsNavigation}
showRuleDetails={showRuleDetails}
caseData={caseData}
actionsNavigation={actionsNavigation}
showAlertDetails={showAlertDetails}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ const caseViewProps: CaseViewProps = {
href: jest.fn(),
onClick: jest.fn(),
},
ruleDetailsNavigation: {
href: jest.fn(),
onClick: jest.fn(),
},
showRuleDetails: jest.fn(),
showAlertDetails: jest.fn(),
useFetchAlertData: () => [
false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ import { CustomFields } from './custom_fields';
import { useReplaceCustomField } from '../../../containers/use_replace_custom_field';

export const CaseViewActivity = ({
ruleDetailsNavigation,
showRuleDetails,
caseData,
actionsNavigation,
showAlertDetails,
useFetchAlertData,
}: {
ruleDetailsNavigation?: CasesNavigation<string | null | undefined, 'configurable'>;
showRuleDetails?: (ruleId: string) => void;
caseData: CaseUI;
actionsNavigation?: CasesNavigation<string, 'configurable'>;
showAlertDetails?: (alertId: string, index: string) => void;
Expand Down Expand Up @@ -218,8 +218,7 @@ export const CaseViewActivity = ({
<UserActions
userProfiles={userProfiles}
currentUserProfile={currentUserProfile}
getRuleDetailsHref={ruleDetailsNavigation?.href}
onRuleDetailsClick={ruleDetailsNavigation?.onClick}
onRuleDetailsClick={showRuleDetails}
caseConnectors={caseConnectors}
data={caseData}
casesConfiguration={casesConfiguration}
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/cases/public/components/case_view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const CaseViewLoading = () => (
export const CaseView = React.memo(
({
actionsNavigation,
ruleDetailsNavigation,
showRuleDetails,
showAlertDetails,
timelineIntegration,
useFetchAlertData,
Expand Down Expand Up @@ -83,7 +83,7 @@ export const CaseView = React.memo(
caseData={data.case}
fetchCase={refetch}
actionsNavigation={actionsNavigation}
ruleDetailsNavigation={ruleDetailsNavigation}
showRuleDetails={showRuleDetails}
showAlertDetails={showAlertDetails}
useFetchAlertData={useFetchAlertData}
onAlertsTableLoaded={onAlertsTableLoaded}
Expand Down
5 changes: 1 addition & 4 deletions x-pack/plugins/cases/public/components/case_view/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ export const caseViewProps: CaseViewProps = {
href: jest.fn(),
onClick: jest.fn(),
},
ruleDetailsNavigation: {
href: jest.fn(),
onClick: jest.fn(),
},
showRuleDetails: jest.fn(),
showAlertDetails: jest.fn(),
useFetchAlertData: () => [
false,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/public/components/case_view/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { UseFetchAlertData } from '../../../common/ui';
export interface CaseViewBaseProps {
onComponentInitialized?: () => void;
actionsNavigation?: CasesNavigation<string, 'configurable'>;
ruleDetailsNavigation?: CasesNavigation<string | null | undefined, 'configurable'>;
showRuleDetails?: (ruleId: string) => void;
showAlertDetails?: (alertId: string, index: string) => void;
useFetchAlertData: UseFetchAlertData;
onAlertsTableLoaded?: (eventIds: Array<Partial<{ _id: string }>>) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ type BuilderArgs = Pick<
UserActionBuilderArgs,
| 'userAction'
| 'alertData'
| 'getRuleDetailsHref'
| 'onRuleDetailsClick'
| 'loadingAlertData'
| 'onShowAlertDetails'
Expand All @@ -43,7 +42,6 @@ const getSingleAlertUserAction = ({
alertData,
loadingAlertData,
loadingCommentIds,
getRuleDetailsHref,
onRuleDetailsClick,
onShowAlertDetails,
handleDeleteComment,
Expand All @@ -68,7 +66,6 @@ const getSingleAlertUserAction = ({
event: (
<SingleAlertCommentEvent
actionId={userAction.id}
getRuleDetailsHref={getRuleDetailsHref}
loadingAlertData={loadingAlertData}
onRuleDetailsClick={onRuleDetailsClick}
ruleId={ruleId}
Expand Down Expand Up @@ -106,7 +103,6 @@ const getMultipleAlertsUserAction = ({
alertData,
loadingAlertData,
loadingCommentIds,
getRuleDetailsHref,
onRuleDetailsClick,
handleDeleteComment,
}: BuilderArgs): EuiCommentProps[] => {
Expand All @@ -130,7 +126,6 @@ const getMultipleAlertsUserAction = ({
totalAlerts={totalAlerts}
ruleId={ruleId}
ruleName={ruleName}
getRuleDetailsHref={getRuleDetailsHref}
onRuleDetailsClick={onRuleDetailsClick}
/>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ describe('Alert events', () => {
expect(wrapper.text()).toBe('added an alert from Awesome rule');
});

it('does NOT render the link when the href is invalid but it shows the rule name', async () => {
it('does NOT render the link when ruleId is invalid but it shows the rule name', async () => {
const wrapper = mount(
<TestProviders>
<SingleAlertCommentEvent {...props} getRuleDetailsHref={undefined} />
<SingleAlertCommentEvent {...props} ruleId={undefined} />
</TestProviders>
);

Expand Down Expand Up @@ -142,9 +142,9 @@ describe('Alert events', () => {
expect(result.queryByTestId('alert-rule-link-action-id-1')).toBeFalsy();
});

it('does NOT render the link when the href is invalid but it shows the rule name', async () => {
it('does NOT render the link when the ruleId is invalid but it shows the rule name', async () => {
const result = appMock.render(
<MultipleAlertsCommentEvent {...props} totalAlerts={2} getRuleDetailsHref={undefined} />
<MultipleAlertsCommentEvent {...props} totalAlerts={2} ruleId={undefined} />
);

expect(result.getByTestId('multiple-alerts-user-action-action-id-1')).toHaveTextContent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@
* 2.0.
*/

import React, { memo, useCallback } from 'react';
import React, { memo } from 'react';
import { isEmpty } from 'lodash';
import { EuiLoadingSpinner } from '@elastic/eui';

import * as i18n from '../translations';
import { LinkAnchor } from '../../links';
import type { RuleDetailsNavigation } from '../types';

interface SingleAlertProps {
actionId: string;
ruleId?: string | null;
ruleName?: string | null;
getRuleDetailsHref?: RuleDetailsNavigation['href'];
onRuleDetailsClick?: RuleDetailsNavigation['onClick'];
onRuleDetailsClick?: (ruleId: string) => void;
loadingAlertData?: boolean;
}

Expand All @@ -27,27 +25,17 @@ interface MultipleAlertsProps extends SingleAlertProps {
}

const RuleLink: React.FC<SingleAlertProps> = memo(
({ onRuleDetailsClick, getRuleDetailsHref, ruleId, ruleName, loadingAlertData, actionId }) => {
const onLinkClick = useCallback(
(ev: React.MouseEvent) => {
ev.preventDefault();
if (onRuleDetailsClick) onRuleDetailsClick(ruleId, ev);
},
[ruleId, onRuleDetailsClick]
);

const ruleDetailsHref = getRuleDetailsHref?.(ruleId);
({ onRuleDetailsClick, ruleId, ruleName, loadingAlertData, actionId }) => {
const finalRuleName = ruleName ?? i18n.UNKNOWN_RULE;

if (loadingAlertData) {
return <EuiLoadingSpinner size="m" data-test-subj={`alert-loading-spinner-${actionId}`} />;
}

if (!isEmpty(ruleId) && ruleDetailsHref != null) {
if (!isEmpty(ruleId) && ruleId != null && onRuleDetailsClick) {
return (
<LinkAnchor
onClick={onLinkClick}
href={ruleDetailsHref}
onClick={() => onRuleDetailsClick(ruleId)}
data-test-subj={`alert-rule-link-${actionId}`}
>
{finalRuleName}
Expand All @@ -63,7 +51,6 @@ RuleLink.displayName = 'RuleLink';

const SingleAlertCommentEventComponent: React.FC<SingleAlertProps> = ({
actionId,
getRuleDetailsHref,
loadingAlertData = false,
onRuleDetailsClick,
ruleId,
Expand All @@ -76,7 +63,6 @@ const SingleAlertCommentEventComponent: React.FC<SingleAlertProps> = ({
actionId={actionId}
ruleId={ruleId}
ruleName={ruleName}
getRuleDetailsHref={getRuleDetailsHref}
onRuleDetailsClick={onRuleDetailsClick}
loadingAlertData={loadingAlertData}
/>
Expand All @@ -90,7 +76,6 @@ export const SingleAlertCommentEvent = memo(SingleAlertCommentEventComponent);

const MultipleAlertsCommentEventComponent: React.FC<MultipleAlertsProps> = ({
actionId,
getRuleDetailsHref,
loadingAlertData = false,
onRuleDetailsClick,
ruleId,
Expand All @@ -104,7 +89,6 @@ const MultipleAlertsCommentEventComponent: React.FC<MultipleAlertsProps> = ({
actionId={actionId}
ruleId={ruleId}
ruleName={ruleName}
getRuleDetailsHref={getRuleDetailsHref}
onRuleDetailsClick={onRuleDetailsClick}
loadingAlertData={loadingAlertData}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ const getCreateCommentUserAction = ({
handleSaveComment,
handleManageQuote,
handleDeleteComment,
getRuleDetailsHref,
loadingAlertData,
onRuleDetailsClick,
alertData,
Expand Down Expand Up @@ -197,7 +196,6 @@ const getCreateCommentUserAction = ({
alertData,
comment,
userAction,
getRuleDetailsHref,
loadingAlertData,
onRuleDetailsClick,
onShowAlertDetails,
Expand Down Expand Up @@ -262,7 +260,6 @@ export const createCommentUserActionBuilder: UserActionBuilder = ({
loadingAlertData,
alertData,
euiTheme,
getRuleDetailsHref,
onRuleDetailsClick,
onShowAlertDetails,
handleManageMarkdownEditId,
Expand Down Expand Up @@ -310,7 +307,6 @@ export const createCommentUserActionBuilder: UserActionBuilder = ({
loadingAlertData,
alertData,
euiTheme,
getRuleDetailsHref,
onRuleDetailsClick,
onShowAlertDetails,
handleManageMarkdownEditId,
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/cases/public/components/user_actions/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export const getMockBuilderArgs = (): UserActionBuilderArgs => {

const caseConnectors = getCaseConnectorsMockResponse();

const getRuleDetailsHref = jest.fn().mockReturnValue('https://example.com');
const onRuleDetailsClick = jest.fn();
const onShowAlertDetails = jest.fn();
const handleManageMarkdownEditId = jest.fn();
Expand Down Expand Up @@ -74,7 +73,6 @@ export const getMockBuilderArgs = (): UserActionBuilderArgs => {
loadingCommentIds: [],
loadingAlertData: false,
caseConnectors,
getRuleDetailsHref,
onRuleDetailsClick,
onShowAlertDetails,
handleManageMarkdownEditId,
Expand Down
7 changes: 2 additions & 5 deletions x-pack/plugins/cases/public/components/user_actions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ export interface UserActionTreeProps {
currentUserProfile: CurrentUserProfile;
data: CaseUI;
casesConfiguration: CasesConfigurationUI;
getRuleDetailsHref?: RuleDetailsNavigation['href'];
actionsNavigation?: ActionsNavigation;
onRuleDetailsClick?: RuleDetailsNavigation['onClick'];
onRuleDetailsClick?: (ruleId: string) => void;
onShowAlertDetails?: (alertId: string, index: string) => void;
onUpdateField: ({ key, value, onSuccess, onError }: OnUpdateFields) => void;
statusActionButton: JSX.Element | null;
Expand Down Expand Up @@ -77,8 +76,7 @@ export interface UserActionBuilderArgs {
handleDeleteComment: (id: string, successToasterTitle: string) => void;
handleManageQuote: (quote: string) => void;
onShowAlertDetails?: (alertId: string, index: string) => void;
getRuleDetailsHref?: RuleDetailsNavigation['href'];
onRuleDetailsClick?: RuleDetailsNavigation['onClick'];
onRuleDetailsClick?: (ruleId: string) => void;
euiTheme?: EuiThemeComputed<{}>;
}

Expand All @@ -88,7 +86,6 @@ export type UserActionBuilder = (args: UserActionBuilderArgs) => {

export type UserActionBuilderMap = Record<SupportedUserActionTypes, UserActionBuilder>;

export type RuleDetailsNavigation = CasesNavigation<string | null | undefined, 'configurable'>;
export type ActionsNavigation = CasesNavigation<string, 'configurable'>;

interface Signal {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export const UserActionsList = React.memo(
currentUserProfile,
data: caseData,
casesConfiguration,
getRuleDetailsHref,
actionsNavigation,
onRuleDetailsClick,
onShowAlertDetails,
Expand Down Expand Up @@ -150,7 +149,6 @@ export const UserActionsList = React.memo(
handleManageQuote,
onShowAlertDetails,
actionsNavigation,
getRuleDetailsHref,
onRuleDetailsClick,
});
return [...comments, ...userActionBuilder.build()];
Expand Down Expand Up @@ -179,7 +177,6 @@ export const UserActionsList = React.memo(
handleManageQuote,
onShowAlertDetails,
actionsNavigation,
getRuleDetailsHref,
onRuleDetailsClick,
]);

Expand Down
Loading

0 comments on commit e8c67d8

Please sign in to comment.