Skip to content

Commit

Permalink
feat: added default product line filter for budget (#1012)
Browse files Browse the repository at this point in the history
  • Loading branch information
zamanafzal committed Aug 2, 2023
1 parent 01be2a5 commit 84f7b4d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 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 @@ -17,8 +17,11 @@ const LearnerCreditAllocationTable = ({
tableData,
fetchTableData,
enterpriseUUID,
budgetType,
}) => {
const isDesktopTable = useMediaQuery({ minWidth: breakpoints.extraLarge.minWidth });
const defaultFilter = budgetType ? [{ id: 'courseProductLine', value: budgetType }] : [];

return (
<DataTable
isSortable
Expand Down Expand Up @@ -57,6 +60,7 @@ const LearnerCreditAllocationTable = ({
Header: 'Product',
accessor: 'courseProductLine',
Cell: ({ row }) => getCourseProductLineText(row.values.courseProductLine),
disableFilters: true,
},
]}
initialTableOptions={{
Expand All @@ -68,6 +72,7 @@ const LearnerCreditAllocationTable = ({
sortBy: [
{ id: 'enrollmentDate', desc: true },
],
filters: defaultFilter,
}}
fetchData={fetchTableData}
data={tableData.results}
Expand All @@ -85,6 +90,9 @@ const LearnerCreditAllocationTable = ({
/>
);
};
LearnerCreditAllocationTable.defaultProps = {
budgetType: null,
};

LearnerCreditAllocationTable.propTypes = {
enterpriseUUID: PropTypes.string.isRequired,
Expand All @@ -101,6 +109,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 @@ -12,6 +12,7 @@ import {
} from '@testing-library/react';
import '@testing-library/jest-dom/extend-expect';

import { IntlProvider } from '@edx/frontend-platform/i18n';
import BudgetCard from '../BudgetCard';
import { useOfferSummary, useOfferRedemptions } from '../data/hooks';

Expand All @@ -30,7 +31,6 @@ useOfferRedemptions.mockReturnValue({
fetchOfferRedemptions: jest.fn(),
});


const mockStore = configureMockStore([thunk]);
const getMockStore = store => mockStore(store);
const enterpriseId = 'test-enterprise';
Expand All @@ -55,7 +55,9 @@ const mockOfferSummary = {

const BudgetCardWrapper = ({ ...rest }) => (
<Provider store={store}>
<BudgetCard {...rest} />
<IntlProvider locale="en">
<BudgetCard {...rest} />
</IntlProvider>
</Provider>
);

Expand Down
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 84f7b4d

Please sign in to comment.