Skip to content

Commit

Permalink
Merge pull request #101 from edx/aakbar/PROD-2277
Browse files Browse the repository at this point in the history
Add Detail button to show Support Details for each Entitlement
  • Loading branch information
Ali-D-Akbar authored Apr 5, 2021
2 parents a956844 + 386040f commit d80848e
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/users/data/test/entitlements.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@ const entitlementsData = {
supportDetails: [{
supportUser: 'admin',
action: 'CREATE',
actionCreated: Date().toLocaleString(),
comments: 'creating entitlement',
unenrolledRun: null,
},
{
supportUser: 'admin',
action: 'EXPIRE',
actionCreated: Date().toLocaleString(),
comments: 'expiring entitlement',
unenrolledRun: null,
},
],
},
{
Expand Down
63 changes: 60 additions & 3 deletions src/users/entitlements/Entitlements.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import React, {
import PropTypes from 'prop-types';

import {
Button, Collapsible, TransitionReplace,
Button, Collapsible, Modal, TransitionReplace,
} from '@edx/paragon';
import { camelCaseObject, getConfig } from '@edx/frontend-platform';
import EntitlementForm from './EntitlementForm';
Expand All @@ -27,6 +27,9 @@ export default function Entitlements({
const [courseSummaryUUID, setCourseSummaryUUID] = useState(null);
const [courseSummaryData, setCourseSummaryData] = useState(null);
const [courseSummaryErrors, setCourseSummaryErrors] = useState(false);
const [entitlementDetailModalIsOpen, setEntitlementDetailModalIsOpen] = useState(false);
const [entitlementSupportDetailsTitle, setEntitlementSupportDetailsTitle] = useState('');
const [entitlementSupportDetails, setEntitlementSupportDetails] = useState([]);
const formRef = useRef(null);
const summaryRef = useRef(null);

Expand All @@ -45,6 +48,20 @@ export default function Entitlements({
setCourseSummaryErrors(false);
}

// Modal to display Support Details for each Entitlement
const openEntitlementsSupportDetailsModal = (title, supportDetails) => {
const tableData = supportDetails.map(supportDetail => ({
action: supportDetail.action,
comments: supportDetail.comments,
actionCreated: formatDate(supportDetail.created),
supportUser: supportDetail.supportUser,
unenrolledRun: supportDetail.unenrolledRun,
}));
setEntitlementSupportDetails(tableData);
setEntitlementSupportDetailsTitle(title);
setEntitlementDetailModalIsOpen(true);
};

const handleCourseSummaryDataGet = useCallback((courseUUID) => {
if (courseUUID !== null && courseUUID !== undefined) {
setCourseSummaryData(null);
Expand Down Expand Up @@ -126,8 +143,19 @@ export default function Entitlements({
displayValue: (
<div>
<Button
id="details"
type="button"
variant="outline-primary"
onClick={() => {
openEntitlementsSupportDetailsModal('Entitlement Support Details', entitlement.supportDetails);
}}
>
Details
</Button>
<Button
id="reissue"
type="button"
variant="outline-primary mt-2 mr-2"
disabled={!entitlement.enrollmentCourseRun}
onClick={() => {
clearCourseSummary();
Expand All @@ -139,8 +167,7 @@ export default function Entitlements({
</Button>
<Button
type="button"
className="mt-2"
variant="outline-danger"
variant="outline-danger mt-2"
disabled={entitlement.expiredAt}
onClick={() => {
clearCourseSummary();
Expand Down Expand Up @@ -193,6 +220,24 @@ export default function Entitlements({
},
];

const supportDetailsColumn = [
{
label: 'Action', key: 'action', width: 'col-3',
},
{
label: 'Comments', key: 'comments', width: 'col-3',
},
{
label: 'Action Creation Timestamp', key: 'actionCreated', width: 'col-3',
},
{
label: 'Support User', key: 'supportUser', width: 'col-3',
},
{
label: 'Unenrolled Run', key: 'unenrolledRun', width: 'col-3',
},
];

const tableDataSortable = [...tableData];

return (
Expand Down Expand Up @@ -240,6 +285,18 @@ export default function Entitlements({
/>
) : (<React.Fragment key="nothing" />)}
</TransitionReplace>
<Modal
open={entitlementDetailModalIsOpen}
onClose={() => setEntitlementDetailModalIsOpen(false)}
title={entitlementSupportDetailsTitle}
id="support-details"
body={(
<Table
data={entitlementSupportDetails}
columns={supportDetailsColumn}
/>
)}
/>
<Collapsible title={`Entitlements (${tableData.length})`} defaultOpen={expanded}>
<Table
className="w-100"
Expand Down
26 changes: 25 additions & 1 deletion src/users/entitlements/Entitlements.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,30 @@ describe('Entitlements Listing', () => {
expect(collapsible.text()).toEqual('Entitlements (0)');
});

it('Support Details data', () => {
wrapper = mount(<EntitlementsPageWrapper {...entitlementsData} />);
const tableRowsLengths = [2, 0];

const tableData = wrapper.find('table.table');
tableData.find('tbody tr').forEach((row, i) => {
const detailButton = row.find('button#details');
expect(detailButton.text()).toEqual('Details');
let supportDetailsModal = wrapper.find('Modal#support-details');
expect(supportDetailsModal.prop('open')).toEqual(false);
detailButton.simulate('click');

supportDetailsModal = wrapper.find('Modal#support-details');
expect(supportDetailsModal.prop('open')).toEqual(true);
expect(supportDetailsModal.prop('title')).toEqual('Entitlement Support Details');
expect(supportDetailsModal.find('table thead tr th')).toHaveLength(5);
expect(supportDetailsModal.find('table tbody tr')).toHaveLength(tableRowsLengths[i]);
supportDetailsModal.find('button.btn-link').simulate('click');

supportDetailsModal = wrapper.find('Modal#support-details');
expect(supportDetailsModal.prop('open')).toEqual(false);
});
});

describe('Expire and Reissue entitlement buttons', () => {
describe('Expire Entitlement button', () => {
it('Disabled Expire entitlement button', () => {
Expand Down Expand Up @@ -98,7 +122,7 @@ describe('Entitlements Listing', () => {
const tableData = wrapper.find('table.table');

tableData.find('tbody tr').forEach(row => {
const reissueButton = row.find('button.btn-outline-primary').last();
const reissueButton = row.find('button#reissue').last();
expect(reissueButton.text()).toEqual('Reissue');
expect(reissueButton.prop('disabled')).toBeTruthy();
});
Expand Down

0 comments on commit d80848e

Please sign in to comment.