Skip to content

Commit

Permalink
[Cases] Set breadcrumbs on update case title (#113266)
Browse files Browse the repository at this point in the history
* set title on breadcrumbs on update case title

* test case added
  • Loading branch information
semd authored Sep 29, 2021
1 parent 2ce47f8 commit fd9dd2c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
11 changes: 11 additions & 0 deletions x-pack/plugins/cases/public/components/case_view/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const useGetCaseUserActionsMock = useGetCaseUserActions as jest.Mock;
const useConnectorsMock = useConnectors as jest.Mock;
const usePostPushToServiceMock = usePostPushToService as jest.Mock;
const useKibanaMock = useKibana as jest.Mocked<typeof useKibana>;
const onCaseDataSuccessMock = jest.fn();

const spacesUiApiMock = {
redirectLegacyUrl: jest.fn().mockResolvedValue(undefined),
Expand Down Expand Up @@ -127,6 +128,7 @@ export const caseProps: CaseComponentProps = {
},
fetchCase: jest.fn(),
updateCase: jest.fn(),
onCaseDataSuccess: onCaseDataSuccessMock,
};

export const caseClosedProps: CaseComponentProps = {
Expand Down Expand Up @@ -371,6 +373,15 @@ describe('CaseView ', () => {
await waitFor(() => {
expect(updateObject.updateKey).toEqual('title');
expect(updateObject.updateValue).toEqual(newTitle);
expect(updateObject.onSuccess).toBeDefined();
});

updateObject.onSuccess(); // simulate the request has succeed
await waitFor(() => {
expect(onCaseDataSuccessMock).toHaveBeenCalledWith({
...caseProps.caseData,
title: newTitle,
});
});
});

Expand Down
16 changes: 14 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 @@ -83,6 +83,7 @@ export interface CaseComponentProps extends CaseViewComponentProps {
fetchCase: UseGetCase['fetchCase'];
caseData: Case;
updateCase: (newCase: Case) => void;
onCaseDataSuccess?: (newCase: Case) => void;
}

export const CaseComponent = React.memo<CaseComponentProps>(
Expand All @@ -94,6 +95,7 @@ export const CaseComponent = React.memo<CaseComponentProps>(
configureCasesNavigation,
getCaseDetailHrefWithCommentId,
fetchCase,
onCaseDataSuccess,
onComponentInitialized,
actionsNavigation,
ruleDetailsNavigation,
Expand Down Expand Up @@ -315,8 +317,17 @@ export const CaseComponent = React.memo<CaseComponentProps>(
);

const onSubmitTitle = useCallback(
(newTitle) => onUpdateField({ key: 'title', value: newTitle }),
[onUpdateField]
(newTitle) =>
onUpdateField({
key: 'title',
value: newTitle,
onSuccess: () => {
if (onCaseDataSuccess) {
onCaseDataSuccess({ ...caseData, title: newTitle });
}
},
}),
[caseData, onUpdateField, onCaseDataSuccess]
);

const changeStatus = useCallback(
Expand Down Expand Up @@ -588,6 +599,7 @@ export const CaseView = React.memo(
configureCasesNavigation={configureCasesNavigation}
getCaseDetailHrefWithCommentId={getCaseDetailHrefWithCommentId}
fetchCase={fetchCase}
onCaseDataSuccess={onCaseDataSuccess}
onComponentInitialized={onComponentInitialized}
actionsNavigation={actionsNavigation}
ruleDetailsNavigation={ruleDetailsNavigation}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const CaseView = React.memo(({ caseId, subCaseId, userCanCrud }: Props) =

const onCaseDataSuccess = useCallback(
(data: Case) => {
if (caseTitle === null) {
if (caseTitle === null || caseTitle !== data.title) {
setCaseTitle(data.title);
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const CaseView = React.memo(({ caseId, subCaseId, userCanCrud }: Props) =

const onCaseDataSuccess = useCallback(
(data: Case) => {
if (spyState.caseTitle === undefined) {
if (spyState.caseTitle === undefined || spyState.caseTitle !== data.title) {
setSpyState({ caseTitle: data.title });
}
},
Expand Down

0 comments on commit fd9dd2c

Please sign in to comment.