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

feat: added default product line filter for budget #1012

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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,
};
Loading