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

Refactor LearnerCreditAllocationTable #1019

Merged
merged 8 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@

import TableTextFilter from './TableTextFilter';
import EmailAddressTableCell from './EmailAddressTableCell';
import { getCourseProductLineText } from '../../utils';

export const PAGE_SIZE = 20;
export const DEFAULT_PAGE = 0; // `DataTable` uses zero-index array

const getDescriptionAccessor = row => ({
courseTitle: row.courseTitle,
userEmail: row.userEmail,
});

const FilterStatus = (rest) => <DataTable.FilterStatus showFilteredFields={false} {...rest} />;

const LearnerCreditAllocationTable = ({
isLoading,
tableData,
Expand All @@ -33,38 +39,37 @@
showFiltersInSidebar={isDesktopTable}
isLoading={isLoading}
defaultColumnValues={{ Filter: TableTextFilter }}
FilterStatusComponent={FilterStatus}
columns={[
{
Header: 'Email Address',
accessor: 'userEmail',
Header: 'Date',
accessor: 'enrollmentDate',
// eslint-disable-next-line react/prop-types, react/no-unstable-nested-components
Cell: ({ row }) => <EmailAddressTableCell row={row} enterpriseUUID={enterpriseUUID} />,
Cell: ({ row }) => dayjs(row.values.enrollmentDate).format('MMMM DD, YYYY'),
emrosarioa marked this conversation as resolved.
Show resolved Hide resolved
disableFilters: true,
},
{
Header: 'Course Name',
accessor: 'courseTitle',
Header: 'Description',
accessor: getDescriptionAccessor,
// eslint-disable-next-line react/prop-types, react/no-unstable-nested-components
Cell: ({ row }) => (
<>
<div>{row.original.courseTitle}</div>

Check failure on line 57 in src/components/learner-credit-management/LearnerCreditAllocationTable.jsx

View workflow job for this annotation

GitHub Actions / tests

'row.original' is missing in props validation

Check failure on line 57 in src/components/learner-credit-management/LearnerCreditAllocationTable.jsx

View workflow job for this annotation

GitHub Actions / tests

'row.original.courseTitle' is missing in props validation
<EmailAddressTableCell row={row} enterpriseUUID={enterpriseUUID} />
</>
),
disableFilters: false,
disableSortBy: true,
},
{
Header: 'Course Price',
Header: 'Amount',
accessor: 'courseListPrice',
Cell: ({ row }) => `$${row.values.courseListPrice}`,

Check failure on line 67 in src/components/learner-credit-management/LearnerCreditAllocationTable.jsx

View workflow job for this annotation

GitHub Actions / tests

'row.values' is missing in props validation

Check failure on line 67 in src/components/learner-credit-management/LearnerCreditAllocationTable.jsx

View workflow job for this annotation

GitHub Actions / tests

'row.values.courseListPrice' is missing in props validation
adamstankiewicz marked this conversation as resolved.
Show resolved Hide resolved
disableFilters: true,
},
{
Header: 'Date Spent',
accessor: 'enrollmentDate',
Cell: ({ row }) => dayjs(row.values.enrollmentDate).format('MMMM DD, YYYY'),
disableFilters: true,
},
{
Header: 'Product',
accessor: 'courseProductLine',
Cell: ({ row }) => getCourseProductLineText(row.values.courseProductLine),
disableFilters: true,
},
]}
initialTableOptions={{
getRowId: row => row?.uuid?.toString(),

Check failure on line 72 in src/components/learner-credit-management/LearnerCreditAllocationTable.jsx

View workflow job for this annotation

GitHub Actions / tests

'row.uuid' is missing in props validation
}}
initialState={{
pageSize: PAGE_SIZE,
Expand Down
13 changes: 5 additions & 8 deletions src/components/learner-credit-management/data/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,15 @@ const applySortByToOptions = (sortBy, options) => {
};

const applyFiltersToOptions = (filters, options) => {
const userSearchQuery = filters?.find(filter => filter.id === 'userEmail')?.value;
const courseTitleSearchQuery = filters?.find(filter => filter.id === 'courseTitle')?.value;
const courseProductLineSearchQuery = filters?.find(filter => filter.id === 'courseProductLine')?.value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up from Slack conversation:

[clarification] in the current state of the (LCM) world, is the courseProductLine filter being used?
const courseProductLineSearchQuery = filters?.find(filter => filter.id === 'courseProductLine')?.value;

[Emily] probably not.

[Adam] even if not used in the current state, since the "Product" column you're keeping in for now isn't exposed in the filters (i.e., disableFilters: true), Markhors next iteration probably will be using it again lolol. So maybe we just leave it in for now with that assumption it will be used again in the near future.

if (userSearchQuery) {
Object.assign(options, { search: userSearchQuery });
}
if (courseTitleSearchQuery) {
Object.assign(options, { searchCourse: courseTitleSearchQuery });
}
const searchQuery = filters?.find(filter => filter.id.toLowerCase() === 'description')?.value;

if (courseProductLineSearchQuery) {
Object.assign(options, { courseProductLine: courseProductLineSearchQuery });
}
if (searchQuery) {
Object.assign(options, { searchAll: searchQuery });
}
};

export const useOfferRedemptions = (enterpriseUUID, offerId) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ describe('useOfferRedemptions', () => {
{ id: 'enrollmentDate', desc: true },
],
filters: [
{ id: 'userEmail', value: mockOfferEnrollments[0].user_email },
{ id: 'courseTitle', value: mockOfferEnrollments[0].course_title },
{ id: 'Description', value: mockOfferEnrollments[0].user_email },
],
});
});
Expand All @@ -118,8 +117,7 @@ describe('useOfferRedemptions', () => {
pageSize: 20,
offerId: mockEnterpriseOffer.id,
ordering: '-enrollment_date', // default sort order
search: mockOfferEnrollments[0].user_email,
searchCourse: mockOfferEnrollments[0].course_title,
searchAll: mockOfferEnrollments[0].user_email,
ignoreNullCourseListPrice: true,
};
expect(EnterpriseDataApiService.fetchCourseEnrollments).toHaveBeenCalledWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ describe('<BudgetCard />', () => {
const elementsWithTestId = screen.getAllByTestId('view-budget');
const firstElementWithTestId = elementsWithTestId[0];
await waitFor(() => userEvent.click(firstElementWithTestId));
expect(screen.getByText('Filters'));
expect(screen.getByText('No results found'));
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ describe('<LearnerCreditAllocationTable />', () => {

render(<LearnerCreditAllocationTableWrapper {...props} />);

expect(screen.getByText('Open', { exact: false }));
expect(screen.getByText(props.tableData.results[0].userEmail.toString(), {
exact: false,
}));
Expand Down