Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cases] Set breadcrumbs on update case title #113266

Merged
merged 3 commits into from
Sep 29, 2021
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
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