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

Add ability to delete a report in My Alerts #267

Merged
merged 43 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
fc78a11
TTAHUB-83 Add delete button to My Alerts
Apr 1, 2021
a8570c7
TTAHUB-83 Add some tests
Apr 2, 2021
0f27375
TTAHUB-83 Fix lint errors
Apr 2, 2021
96322c2
Merge branch 'TTAHUB-83-enable-deleting-of-activity-reports' of https…
kryswisnaskas Apr 9, 2021
43e4874
Merge branch 'main' into TTAHUB-83-enable-deleting-of-activity-reports
Apr 9, 2021
1f0cf34
TTAHUB-83 Merge from 'main'
Apr 14, 2021
02b60a9
Merge branch 'main' into TTAHUB-83-enable-deleting-of-activity-reports
Apr 14, 2021
989ff18
TTAHUB-83 Update to use preferred way of checking key code events
Apr 14, 2021
e60d911
TTAHUB-83 Remove console.log statement
Apr 14, 2021
afeafce
Merge branch 'main' into TTAHUB-83-enable-deleting-of-activity-reports
Apr 15, 2021
e7ca8c3
Merge branch 'main' into TTAHUB-83-enable-deleting-of-activity-reports
Apr 16, 2021
8a13376
Merge branch 'main' into TTAHUB-83-enable-deleting-of-activity-reports
kryswisnaskas Apr 16, 2021
88f2a21
Merge branch 'main' into TTAHUB-83-enable-deleting-of-activity-reports
kryswisnaskas Apr 16, 2021
038aaf7
TTAHUB-83 Add more tests
Apr 19, 2021
a25f126
Merge branch 'main' into TTAHUB-83-enable-deleting-of-activity-reports
Apr 19, 2021
a9ae2d2
TTAHUB-83 Allow Report to be deleted in Front End
Apr 19, 2021
398ce4f
Merge branch 'TTAHUB-83-enable-deleting-of-activity-reports' of githu…
Apr 19, 2021
a7e1431
TTAHUB-83 Add in PR review
Apr 19, 2021
a46cb02
TTAHUB-83 Update tests with new labesl
Apr 19, 2021
5beda09
TTAHUB-83 Deploy to staging
Apr 20, 2021
608c58a
TTAHUB-83 Add async/await keywords
Apr 20, 2021
6252b5a
TTAHUB-83 Fix react hook error
Apr 21, 2021
9afed5a
Merge branch 'main' into TTAHUB-83-enable-deleting-of-activity-reports
gopar Apr 21, 2021
3f6bf4f
Merge branch 'main' into TTAHUB-83-enable-deleting-of-activity-reports
Apr 26, 2021
c561c90
TTAHUB-83 Fix styling according to design
Apr 27, 2021
7d98cb0
Merge branch 'TTAHUB-83-enable-deleting-of-activity-reports' of githu…
Apr 27, 2021
95d86b8
Merge branch 'main' into TTAHUB-83-enable-deleting-of-activity-reports
kryswisnaskas May 3, 2021
f956b24
Merge branch 'main' into TTAHUB-83-enable-deleting-of-activity-reports
kryswisnaskas May 5, 2021
06fc60f
Merge branch 'TTAHUB-83-enable-deleting-of-activity-reports' of https…
kryswisnaskas May 5, 2021
a94edba
Fix test
kryswisnaskas May 5, 2021
4ebf3c0
Fix test
kryswisnaskas May 5, 2021
2e9cce1
Adjust delete authorization
kryswisnaskas May 6, 2021
e6d5b3d
Remove eslint errors
kryswisnaskas May 6, 2021
8c7ba51
Merge branch 'main' into TTAHUB-83-enable-deleting-of-activity-reports
kryswisnaskas May 6, 2021
b5e2e8a
Adjust test after change
kryswisnaskas May 6, 2021
9f26023
Merge branch 'TTAHUB-83-enable-deleting-of-activity-reports' of https…
kryswisnaskas May 6, 2021
9de64df
Merge branch 'main' into TTAHUB-83-enable-deleting-of-activity-reports
kryswisnaskas May 6, 2021
1332370
Merge branch 'main' into TTAHUB-83-enable-deleting-of-activity-reports
kryswisnaskas May 6, 2021
2ca0ce2
Merge branch 'main' of https://github.com/adhocteam/Head-Start-TTADP …
kryswisnaskas May 7, 2021
f5458dc
Include fix for context menu display in MyAlerts
kryswisnaskas May 10, 2021
6aa3ef2
Merge branch 'main' into TTAHUB-83-enable-deleting-of-activity-reports
kryswisnaskas May 10, 2021
a7bfd21
Update audit known issues
kryswisnaskas May 10, 2021
3e38ff2
Merge branch 'TTAHUB-83-enable-deleting-of-activity-reports' of https…
kryswisnaskas May 10, 2021
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
6 changes: 6 additions & 0 deletions frontend/src/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const managerReportStatuses = [

export const REPORT_STATUSES = {
DRAFT: 'draft',
DELETED: 'deleted',
rahearn marked this conversation as resolved.
Show resolved Hide resolved
SUBMITTED: 'submitted',
NEEDS_ACTION: 'needs_action',
APPROVED: 'approved',
Expand All @@ -82,3 +83,8 @@ export const REPORT_STATUSES = {
export const REPORTS_PER_PAGE = 10;
export const ALERTS_PER_PAGE = 10;
export const GOVERNMENT_HOSTNAME_EXTENSION = '.ohs.acf.hhs.gov';
export const ESCAPE_KEY_CODE = 27;

// In Internet Explorer (tested on release 9 and 11) and Firefox 36 and earlier
// the Esc key returns "Esc" instead of "Escape".
export const ESCAPE_KEY_CODES = ['Escape', 'Esc'];
8 changes: 8 additions & 0 deletions frontend/src/components/DeleteReportModal.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#deleteDialog div {
border-style: none;
padding: .5rem;
margin: .5rem;
}
#deleteDialog button {
margin-left: 20px;
}
62 changes: 62 additions & 0 deletions frontend/src/components/DeleteReportModal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React, { useCallback, useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import { Button, Modal } from '@trussworks/react-uswds';

import { ESCAPE_KEY_CODES } from '../Constants';
import './DeleteReportModal.css';

const DeleteModal = ({
onDelete, onClose, closeModal,
}) => {
const modalRef = useRef(null);

const onEscape = useCallback((event) => {
if (ESCAPE_KEY_CODES.includes(event.key)) {
closeModal();
}
}, [closeModal]);

useEffect(() => {
document.addEventListener('keydown', onEscape, false);
return () => {
document.removeEventListener('keydown', onEscape, false);
};
}, [onEscape]);

useEffect(() => {
const button = modalRef.current.querySelector('button');
if (button) {
button.focus();
}
});

return (
<div ref={modalRef} aria-modal="true" role="dialog" id="deleteDialog">
<Modal
title={<h2>Delete Activity Report</h2>}
actions={(
<>
<Button type="button" onClick={onClose}>
Cancel
</Button>

<Button type="button" secondary onClick={onDelete}>
Delete
</Button>
</>
)}
>
Are you sure you want to delete this activity report?
This action can only be undone by a TTA Smart Hub Administrator
</Modal>
</div>
);
};

DeleteModal.propTypes = {
onDelete: PropTypes.func.isRequired,
onClose: PropTypes.func.isRequired,
closeModal: PropTypes.func.isRequired,
};

export default DeleteModal;
59 changes: 59 additions & 0 deletions frontend/src/components/__tests__/DeleteReportModal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import '@testing-library/jest-dom';
import React from 'react';
import {
render, screen,
} from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { useModal, connectModal, Button } from '@trussworks/react-uswds';

import DeleteReportModal from '../DeleteReportModal';

const SomeComponent = () => {
const { isOpen, openModal, closeModal } = useModal();
const ConnectModal = connectModal(DeleteReportModal);

return (
<div>
<ConnectModal
onDelete={() => {}}
onClose={() => {}}
closeModal={closeModal}
isOpen={isOpen}
/>
<Button onClick={openModal}>Open</Button>
</div>
);
};

describe('DeleteReportModal', () => {
it('shows two buttons', async () => {
// Given a page with a modal
render(<DeleteReportModal
onDelete={() => {}}
onClose={() => {}}
closeModal={() => {}}
isOpen
/>);
// When the modal is triggered
const buttons = await screen.findAllByRole('button');

// Then we see our options
expect(buttons.length).toBe(2);
});

it('exits when escapse key is pressed', async () => {
// Given a page with a modal
render(<SomeComponent />);

// When the modal is triggered
const button = await screen.findByText('Open');
userEvent.click(button);

const modal = await screen.findByTestId('modal');
expect(modal).toBeVisible();

// And the modal can closeclose the modal via the escape key
userEvent.type(modal, '{esc}', { skipClick: true });
expect(screen.queryByTestId('modal')).not.toBeTruthy();
});
});
10 changes: 10 additions & 0 deletions frontend/src/fetchers/__tests__/activityReports.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
legacyReportById,
getReports,
getReportAlerts,
deleteReport,
} from '../activityReports';
import { REPORTS_PER_PAGE } from '../../Constants';

Expand Down Expand Up @@ -119,4 +120,13 @@ describe('activityReports fetcher', () => {
expect(savedReport).toEqual(report);
});
});

describe('deleteReport', () => {
it('deletes the report', async () => {
const status = { status: 200 };
fetchMock.delete(join('api', 'activity-reports', '1'), status);
await deleteReport(1);
expect(fetchMock.called()).toBeTruthy();
});
});
});
8 changes: 7 additions & 1 deletion frontend/src/fetchers/activityReports.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import join from 'url-join';
import { get, put, post } from './index';
import {
get, put, post, destroy,
} from './index';
import { DECIMAL_BASE, REPORTS_PER_PAGE, ALERTS_PER_PAGE } from '../Constants';

const activityReportUrl = join('/', 'api', 'activity-reports');
Expand All @@ -26,6 +28,10 @@ export const saveReport = async (reportId, data) => {
return report.json();
};

export const deleteReport = async (reportId) => {
await destroy(join(activityReportUrl, reportId.toString(DECIMAL_BASE)));
};

export const createReport = async (data) => {
const report = await post(activityReportUrl, data);
return report.json();
Expand Down
18 changes: 18 additions & 0 deletions frontend/src/fetchers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,21 @@ export const post = async (url, data) => {
}
return res;
};

/*
* Note: Due to `delete` being a keyword, we'll settle with `destroy`
*/
export const destroy = async (url) => {
const res = await fetch(url, {
method: 'DELETE',
credentials: 'same-origin',
headers: {
'Content-Type': 'application/json',
},
});

if (!res.ok) {
throw new Error(res.statusText);
}
return res;
};
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,31 @@ describe('goals objectives', () => {
const objective = await screen.findByText('title');
expect(objective).toBeVisible();
});

it('isPageComplete is true', async () => {
const objectives = [
{
id: 1,
title: 'title',
ttaProvided: 'tta',
status: 'In Progress',
},
{
id: 2,
title: 'title',
ttaProvided: 'tta',
status: 'In Progress',
},
];
const formData = { activityRecipientType: 'non-grantee', objectivesWithoutGoals: objectives };
const isComplete = goalsObjectives.isPageComplete(formData);
expect(isComplete).toBeTruthy();
});

it('isPageComplete is false', async () => {
const formData = { activityRecipientType: 'grantee', goals: [] };
const isComplete = goalsObjectives.isPageComplete(formData);
expect(isComplete).not.toBeTruthy();
});
});
});
Loading