-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from edx/azan/PROD-2257
Add Licenses Subscription Data for Users
- Loading branch information
Showing
11 changed files
with
338 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
import React, { | ||
useMemo, | ||
useState, | ||
useCallback, | ||
} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Collapsible, Badge } from '@edx/paragon'; | ||
import sort from './sort'; | ||
import Table from '../Table'; | ||
import formatDate from '../dates/formatDate'; | ||
|
||
export default function Licenses({ | ||
data, status, expanded, | ||
}) { | ||
const [sortColumn, setSortColumn] = useState('status'); | ||
const [sortDirection, setSortDirection] = useState('desc'); | ||
const responseStatus = useMemo(() => status, [status]); | ||
const tableData = useMemo(() => { | ||
if (data === null || data.length === 0) { | ||
return []; | ||
} | ||
return data.map(result => ({ | ||
status: { | ||
value: result.status, | ||
}, | ||
assignedDate: { | ||
displayValue: formatDate(result.assignedDate), | ||
value: result.assignedDate, | ||
}, | ||
activationDate: { | ||
displayValue: formatDate(result.activationDate), | ||
value: result.activationDate, | ||
}, | ||
revokedDate: { | ||
displayValue: formatDate(result.revokedDate), | ||
value: result.revokedDate, | ||
}, | ||
lastRemindDate: { | ||
displayValue: formatDate(result.lastRemindDate), | ||
value: result.lastRemindDate, | ||
}, | ||
subscriptionPlanTitle: { | ||
value: result.subscriptionPlanTitle, | ||
}, | ||
subscriptionPlanExpirationDate: { | ||
displayValue: formatDate(result.subscriptionPlanExpirationDate), | ||
value: result.subscriptionPlanExpirationDate, | ||
}, | ||
activationLink: { | ||
displayValue: <a href={result.activationLink} rel="noopener noreferrer" target="_blank" className="word_break">{result.activationLink}</a>, | ||
value: result.activationLink, | ||
}, | ||
})); | ||
}, [data]); | ||
|
||
const setSort = useCallback((column) => { | ||
if (sortColumn === column) { | ||
setSortDirection(sortDirection === 'desc' ? 'asc' : 'desc'); | ||
} else { | ||
setSortDirection('desc'); | ||
} | ||
setSortColumn(column); | ||
}); | ||
const columns = [ | ||
|
||
{ | ||
label: 'Status', key: 'status', columnSortable: true, onSort: () => setSort('status'), width: 'col-3', | ||
}, | ||
{ | ||
label: 'Assigned Date', key: 'assignedDate', columnSortable: true, onSort: () => setSort('assignedDate'), width: 'col-3', | ||
}, | ||
{ | ||
label: 'Activation Date', key: 'activationDate', columnSortable: true, onSort: () => setSort('activationDate'), width: 'col-3', | ||
}, | ||
{ | ||
label: 'Revoked Date', key: 'revokedDate', columnSortable: true, onSort: () => setSort('revokedDate'), width: 'col-3', | ||
}, | ||
{ | ||
label: 'Last Remind Date', key: 'lastRemindDate', columnSortable: true, onSort: () => setSort('lastRemindDate'), width: 'col-3', | ||
}, | ||
{ | ||
label: 'Subscription Plan Title', key: 'subscriptionPlanTitle', columnSortable: true, onSort: () => setSort('subscriptionPlanTitle'), width: 'col-3', | ||
}, | ||
{ | ||
label: 'Subscription Plan Expiration Date', key: 'subscriptionPlanExpirationDate', columnSortable: true, onSort: () => setSort('subscriptionPlanExpirationDate'), width: 'col-3', | ||
}, | ||
{ | ||
label: 'Activation Link', key: 'activationLink', columnSortable: true, onSort: () => setSort('activationLink'), width: 'col-3', | ||
}, | ||
]; | ||
|
||
const tableDataSortable = [...tableData]; | ||
let statusMsg; | ||
if (responseStatus !== '') { | ||
statusMsg = <Badge variant="light">{`Fetch Status: ${responseStatus}`}</Badge>; | ||
} else { | ||
statusMsg = null; | ||
} | ||
|
||
return ( | ||
<section className="mb-3"> | ||
<Collapsible | ||
title={( | ||
<> | ||
{`Licenses (${tableData.length})`} | ||
{statusMsg} | ||
</> | ||
)} | ||
defaultOpen={expanded} | ||
> | ||
<Table | ||
className="w-auto" | ||
data={tableDataSortable.sort( | ||
(firstElement, secondElement) => sort(firstElement, secondElement, sortColumn, sortDirection), | ||
)} | ||
columns={columns} | ||
tableSortable | ||
defaultSortedColumn="status" | ||
defaultSortDirection="desc" | ||
/> | ||
</Collapsible> | ||
</section> | ||
); | ||
} | ||
|
||
Licenses.propTypes = { | ||
data: PropTypes.arrayOf(PropTypes.shape({ | ||
status: PropTypes.string, | ||
assignedDate: PropTypes.string, | ||
revokedDate: PropTypes.string, | ||
activationDate: PropTypes.string, | ||
subscriptionPlanTitle: PropTypes.string, | ||
lastRemindDate: PropTypes.string, | ||
activationLink: PropTypes.string, | ||
subscriptionPlanExpirationDate: PropTypes.string, | ||
})), | ||
status: PropTypes.string, | ||
expanded: PropTypes.bool, | ||
}; | ||
|
||
Licenses.defaultProps = { | ||
data: null, | ||
status: '', | ||
expanded: false, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { mount } from 'enzyme'; | ||
import React from 'react'; | ||
|
||
import Licenses from './Licenses'; | ||
import licensesData from './data/test/licenses'; | ||
import UserMessagesProvider from '../user-messages/UserMessagesProvider'; | ||
|
||
const LicensesPageWrapper = (props) => ( | ||
<UserMessagesProvider> | ||
<Licenses {...props} /> | ||
</UserMessagesProvider> | ||
); | ||
|
||
describe('User Licenses Listing', () => { | ||
let wrapper; | ||
|
||
beforeEach(() => { | ||
wrapper = mount(<LicensesPageWrapper {...licensesData} />); | ||
}); | ||
|
||
it('default collapsible with enrollment data', () => { | ||
const collapsible = wrapper.find('CollapsibleAdvanced').find('.collapsible-trigger').hostNodes(); | ||
expect(collapsible.text()).toEqual('Licenses (2)'); | ||
}); | ||
|
||
it('No License Data', () => { | ||
const licenseData = { ...licensesData, data: [], status: 'No record found' }; | ||
wrapper = mount(<Licenses {...licenseData} />); | ||
const collapsible = wrapper.find('CollapsibleAdvanced').find('.collapsible-trigger').hostNodes(); | ||
expect(collapsible.text()).toEqual('Licenses (0)Fetch Status: No record found'); | ||
}); | ||
|
||
it('Sorting Columns Button Enabled by default', () => { | ||
const dataTable = wrapper.find('table.table'); | ||
const tableHeaders = dataTable.find('thead tr th'); | ||
|
||
tableHeaders.forEach(header => { | ||
const sortButton = header.find('button.btn-header'); | ||
expect(sortButton.disabled).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
it('Table Header Lenght', () => { | ||
const dataTable = wrapper.find('table.table'); | ||
const tableHeaders = dataTable.find('thead tr th'); | ||
expect(tableHeaders).toHaveLength(Object.keys(licensesData.data[0]).length); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.