Skip to content

Commit

Permalink
feat: added default product line filter for budget
Browse files Browse the repository at this point in the history
  • Loading branch information
zamanafzal committed Jul 31, 2023
1 parent 6b26a9d commit ddf41d9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/components/learner-credit-management/BudgetCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Breadcrumb,
} from '@edx/paragon';

import { getCourseProductLineAbbreviation } from '../../utils';
import { useOfferRedemptions, useOfferSummary } from './data/hooks';
import LearnerCreditAggregateCards from './LearnerCreditAggregateCards';
import LearnerCreditAllocationTable from './LearnerCreditAllocationTable';
Expand Down Expand Up @@ -153,6 +154,7 @@ const BudgetCard = ({
tableData={offerRedemptions}
fetchTableData={fetchOfferRedemptions}
enterpriseUUID={enterpriseUUID}
budgetType={getCourseProductLineAbbreviation(activeLabel)}
/>
)}
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import moment from 'moment';
import TableTextFilter from './TableTextFilter';
import EmailAddressTableCell from './EmailAddressTableCell';
import { getCourseProductLineText } from '../../utils';
import SubscriptionCard from "../subscriptions/SubscriptionCard";

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

View workflow job for this annotation

GitHub Actions / tests (16, 8.5.x)

Strings must use singlequote

export const PAGE_SIZE = 20;
export const DEFAULT_PAGE = 0; // `DataTable` uses zero-index array
Expand All @@ -17,8 +18,11 @@ const LearnerCreditAllocationTable = ({
tableData,
fetchTableData,
enterpriseUUID,
budgetType

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

View workflow job for this annotation

GitHub Actions / tests (16, 8.5.x)

Missing trailing comma
}) => {
const isDesktopTable = useMediaQuery({ minWidth: breakpoints.extraLarge.minWidth });
const defaultFilter = budgetType ? [{ id: 'courseProductLine', value: budgetType }] : [];

return (
<DataTable
isSortable
Expand Down Expand Up @@ -57,6 +61,7 @@ const LearnerCreditAllocationTable = ({
Header: 'Product',
accessor: 'courseProductLine',
Cell: ({ row }) => getCourseProductLineText(row.values.courseProductLine),
disableFilters: true,

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

View workflow job for this annotation

GitHub Actions / tests (16, 8.5.x)

Expected indentation of 10 spaces but found 12
},
]}
initialTableOptions={{
Expand All @@ -68,6 +73,7 @@ const LearnerCreditAllocationTable = ({
sortBy: [
{ id: 'enrollmentDate', desc: true },
],
filters: defaultFilter,
}}
fetchData={fetchTableData}
data={tableData.results}
Expand All @@ -85,6 +91,9 @@ const LearnerCreditAllocationTable = ({
/>
);
};
SubscriptionCard.defaultProps = {
budgetType: null,
};

LearnerCreditAllocationTable.propTypes = {
enterpriseUUID: PropTypes.string.isRequired,
Expand All @@ -101,6 +110,7 @@ LearnerCreditAllocationTable.propTypes = {
pageCount: PropTypes.number.isRequired,
}).isRequired,
fetchTableData: PropTypes.func.isRequired,
budgetType: PropTypes.string,
};

export default LearnerCreditAllocationTable;
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('<LearnerCreditAllocationTable />', () => {
const props = {
enterpriseUUID: 'test-enterprise-id',
isLoading: false,
budgetType: "OCM",
tableData: {
results: [{
userEmail: '[email protected]',
Expand Down Expand Up @@ -47,4 +48,22 @@ describe('<LearnerCreditAllocationTable />', () => {
}));
expect(screen.getByText('February', { exact: false }));
});
it('renders with empty table data', () => {
const props = {
enterpriseUUID: 'test-enterprise-id',
isLoading: false,
budgetType: "OCM",
tableData: {
results: [],
itemCount: 0,
pageCount: 0,
},
fetchTableData: jest.fn(),
};
props.fetchTableData.mockReturnValue(props.tableData);

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

expect(screen.getByText('No results found', { exact: false }));
});
});
7 changes: 7 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,12 @@ const getCourseProductLineText = (courseProductLine) => {
return courseProductLineText;
};

const getCourseProductLineAbbreviation = (courseProductLine) => {
let courseProductLineText = '';
courseProductLineText = courseProductLine === 'Open Courses Marketplace' ? 'OCM' : 'Executive Education';
return courseProductLineText;
};

export {
camelCaseDict,
camelCaseDictArray,
Expand Down Expand Up @@ -440,4 +446,5 @@ export {
pollAsync,
isNotValidNumberString,
getCourseProductLineText,
getCourseProductLineAbbreviation,
};

0 comments on commit ddf41d9

Please sign in to comment.