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

Removed Table and StatusAlert deprecation of Paragon #798

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
9174fd5
refactor: updated columns for table deprecations
abdullahwaheed Jun 7, 2022
6250d81
refactor: updated unit tests for Datatable changes
abdullahwaheed Jun 8, 2022
45691d7
feat: allowing for idp direct entry + bug fixes
alex-sheehan-edx May 23, 2022
a441acd
chore: redesigned connect step and rolling back idp data direct entry
alex-sheehan-edx Jun 3, 2022
0ab3c24
refactor: updated StatusAlert deprecated component to Alert and made …
abdullahwaheed Jun 9, 2022
c6d4e9b
fix: added specific npm version to fix peerdependency issue (#799)
abdullahwaheed Jun 13, 2022
b0f1b38
refactor: improved coverage
abdullahwaheed Jun 15, 2022
b2386ff
refactor: improved code coverage and removed unused code
abdullahwaheed Jun 16, 2022
067ced0
refactor: updated the missing prop
abdullahwaheed Jun 20, 2022
d5b9663
refactor: removed StatusAlert wrapper and updated each component indi…
abdullahwaheed Jun 28, 2022
208f779
fix: undo removal of coverage in package.json
abdullahwaheed Jun 28, 2022
855f298
fix: fixing config info entry bug (#800)
kiram15 Jun 15, 2022
7473722
feat: hide learner credit management automatically, refactor sidebar
long74100 Jun 15, 2022
55dc278
fix: removed codecov deprecated package (#802)
mamankhan99 Jun 17, 2022
99f1e63
feat: learner credit mgmt offer metadata display (#803)
adamstankiewicz Jun 22, 2022
40a666e
fix: accounting for unique entity ID errors
alex-sheehan-edx Jun 21, 2022
4e1810d
chore: upgrade dependencies to resolve peer dependency resolutions (#…
adamstankiewicz Jun 23, 2022
f7a3ee9
fix: cleaning up self serve integration config settings page
alex-sheehan-edx Jun 23, 2022
7fdf1e9
feat: integrate offers api from analytics
long74100 Jun 24, 2022
5dcb796
fix: tweaking error responses to read better
alex-sheehan-edx Jun 27, 2022
50d705a
fix: add ability to enable FEATURE_LEARNER_CREDIT_MANAGEMENT via quar…
adamstankiewicz Jun 28, 2022
e6ed817
feat: Add learner credit management product tour (#805)
christopappas Jun 28, 2022
866dc11
refactor: updated datatable to handle sorting and pagination as sugge…
abdullahwaheed Jun 30, 2022
d12a372
fix: upgrade paragon and frontend-platform to latest to bring in styl…
adamstankiewicz Jun 29, 2022
2bcaa06
chore: cleaning up SSO and LMS settings page feature flags
alex-sheehan-edx Jun 28, 2022
cd4fd8d
fix: pass bool to hotjarDebug
long74100 Jun 29, 2022
88fca02
fix: fixed crashing unit tests
abdullahwaheed Jun 30, 2022
6aa0c51
feat: alerts and color variants for low/no funds remaining in Learner…
adamstankiewicz Jun 30, 2022
4d6890c
feat: ignore null course price in learner credit mgmt table (#819)
adamstankiewicz Jun 30, 2022
dc04679
fix: failed unit tests after backmerging from master
abdullahwaheed Jul 1, 2022
d517092
Merge branch 'master' of github.com:openedx/frontend-app-admin-portal…
abdullahwaheed Jul 1, 2022
03c04ae
refactor: code coverage improvement
abdullahwaheed Jul 1, 2022
5b2bfa9
refactor: added unit tests for tablecomponent coverage
abdullahwaheed Jul 4, 2022
71b1d69
refactor: removed unused code
abdullahwaheed Jul 5, 2022
e116965
Merge branch 'master' of github.com:openedx/frontend-app-admin-portal…
abdullahwaheed Jul 15, 2022
ceae377
Merge branch 'master' of github.com:openedx/frontend-app-admin-portal…
abdullahwaheed Sep 20, 2022
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
Prev Previous commit
Next Next commit
feat: integrate offers api from analytics
  • Loading branch information
long74100 authored and abdullahwaheed committed Jul 1, 2022
commit 7fdf1e914af02d6ec4bbf14d492f5b71fff4a418
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import LearnerCreditAllocationTable from './LearnerCreditAllocationTable';
import LearnerCreditAggregateCards from './LearnerCreditAggregateCards';
import OfferDates from './OfferDates';
import OfferNameHeading from './OfferNameHeading';
import { useOfferUtilization } from './data/hooks';
import { useOfferSummary } from './data/hooks';

const LearnerCreditManagement = ({ enterpriseUUID }) => {
const { offers } = useContext(EnterpriseSubsidiesContext);
Expand All @@ -29,7 +29,7 @@ const LearnerCreditManagement = ({ enterpriseUUID }) => {
}
}, [offers, enterpriseUUID]);

const { isLoading, offerUtilization } = useOfferUtilization(enterpriseUUID, enterpriseOffer);
const { isLoading, offerSummary } = useOfferSummary(enterpriseUUID, enterpriseOffer);

if (!enterpriseOffer) {
return <NotFound />;
Expand Down Expand Up @@ -59,10 +59,10 @@ const LearnerCreditManagement = ({ enterpriseUUID }) => {
<div className="mb-4.5 d-flex flex-wrap mx-n3">
<LearnerCreditAggregateCards
isLoading={isLoading}
totalFunds={offerUtilization?.totalFunds}
redeemedFunds={offerUtilization?.redeemedFunds}
remainingFunds={offerUtilization?.remainingFunds}
percentUtilized={offerUtilization?.percentUtilized}
totalFunds={offerSummary?.totalFunds}
redeemedFunds={offerSummary?.redeemedFunds}
remainingFunds={offerSummary?.remainingFunds}
percentUtilized={offerSummary?.percentUtilized}
/>
</div>
<div>
Expand Down
28 changes: 15 additions & 13 deletions src/components/learner-credit-management/data/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,43 @@ import debounce from 'lodash.debounce';

import EnterpriseDataApiService from '../../../data/services/EnterpriseDataApiService';
import {
transformOfferUtilization,
transformOfferSummary,
transformUtilizationTableResults,
} from './utils';
import { API_FIELDS_BY_TABLE_COLUMN_ACCESSOR } from './constants';

export const useOfferUtilization = (enterpriseUUID, enterpriseOffer) => {
const [isOfferUtilizationLoading, setIsOfferUtilizationLoading] = useState(true);
const [offerUtilization, setOfferUtilization] = useState();
export const useOfferSummary = (enterpriseUUID, enterpriseOffer) => {
const [isLoading, setIsLoading] = useState(true);
const [offerSummary, setOfferSummary] = useState();

useEffect(() => {
if (!enterpriseOffer) {
setIsOfferUtilizationLoading(false);
setIsLoading(false);
return;
}

const fetchData = async () => {
try {
setIsOfferUtilizationLoading(true);
const response = await EnterpriseDataApiService.fetchEnterpriseOfferUtilization(
setIsLoading(true);
const response = await EnterpriseDataApiService.fetchEnterpriseOfferSummary(
enterpriseUUID, enterpriseOffer.id,
);
const utilization = camelCaseObject(response.data);
const transformedUtilization = transformOfferUtilization(utilization);
setOfferUtilization(transformedUtilization);
const data = camelCaseObject(response.data);
const transformedOfferSummary = transformOfferSummary(data);
setOfferSummary(transformedOfferSummary);
} catch (error) {
logError(error);
} finally {
setIsOfferUtilizationLoading(false);
setIsLoading(false);
}
};

fetchData();
}, [enterpriseUUID, enterpriseOffer]);

return {
isLoading: isOfferUtilizationLoading,
offerUtilization,
isLoading,
offerSummary,
};
};

Expand Down
24 changes: 12 additions & 12 deletions src/components/learner-credit-management/data/tests/hooks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { act, renderHook } from '@testing-library/react-hooks/dom';
import { camelCaseObject } from '@edx/frontend-platform/utils';

import {
useOfferUtilization,
useOfferSummary,
useLearnerCreditAllocations,
} from '../hooks';
import EnterpriseDataApiService from '../../../../data/services/EnterpriseDataApiService';
Expand All @@ -17,13 +17,13 @@ jest.mock('../../../../data/services/EnterpriseDataApiService');
const TEST_ENTERPRISE_UUID = 'test-enterprise-uuid';
const TEST_ENTERPRISE_OFFER_ID = 1;

const mockOfferUtilization = {
const mockOfferSummary = {
offer_id: TEST_ENTERPRISE_OFFER_ID,
status: 'Open',
enterprise_customer_uuid: TEST_ENTERPRISE_UUID,
amount_of_offer_spent: '200.00',
max_discount: '5000.00',
percent_utilized: '0.04',
percent_of_offer_spent: '0.04',
remaining_balance: '4800.00',
};
const mockEnterpriseOffer = {
Expand All @@ -43,38 +43,38 @@ const mockOfferEnrollmentsResponse = {
results: mockOfferEnrollments,
};

describe('useOfferUtilization', () => {
describe('useOfferSummary', () => {
it('should handle null enterprise offer', async () => {
const { result } = renderHook(() => useOfferUtilization(TEST_ENTERPRISE_UUID));
const { result } = renderHook(() => useOfferSummary(TEST_ENTERPRISE_UUID));

expect(result.current).toEqual({
offerUtilization: undefined,
offerSummary: undefined,
isLoading: false,
});
});

it('should fetch utilization metadata for enterprise offer', async () => {
EnterpriseDataApiService.fetchEnterpriseOfferUtilization.mockResolvedValueOnce({ data: mockOfferUtilization });
const { result, waitForNextUpdate } = renderHook(() => useOfferUtilization(
it('should fetch summary data for enterprise offer', async () => {
EnterpriseDataApiService.fetchEnterpriseOfferSummary.mockResolvedValueOnce({ data: mockOfferSummary });
const { result, waitForNextUpdate } = renderHook(() => useOfferSummary(
TEST_ENTERPRISE_UUID, mockEnterpriseOffer,
));

expect(result.current).toEqual({
offerUtilization: undefined,
offerSummary: undefined,
isLoading: true,
});

await waitForNextUpdate();

expect(EnterpriseDataApiService.fetchEnterpriseOfferUtilization).toHaveBeenCalled();
expect(EnterpriseDataApiService.fetchEnterpriseOfferSummary).toHaveBeenCalled();
const expectedResult = {
totalFunds: 5000,
redeemedFunds: 200,
remainingFunds: 4800,
percentUtilized: 0.04,
};
expect(result.current).toEqual({
offerUtilization: expectedResult,
offerSummary: expectedResult,
isLoading: false,
});
});
Expand Down
18 changes: 9 additions & 9 deletions src/components/learner-credit-management/data/utils.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/**
* Transforms utilization data from API for display in the UI.
* Transforms offer summary from API for display in the UI.
*
* @param {object} offerUtilization Object containing metadata about utilization for an offer.
* @returns Object transformed metadata about an enterprise offer.
* @param {object} offerSummary Object containing summary about an offer.
* @returns Object containing transformed summary about an enterprise offer.
*/
export const transformOfferUtilization = (offerUtilization) => {
if (!offerUtilization) { return null; }
export const transformOfferSummary = (offerSummary) => {
if (!offerSummary) { return null; }

const totalFunds = parseFloat(offerUtilization.maxDiscount);
const redeemedFunds = parseFloat(offerUtilization.amountOfOfferSpent);
const remainingFunds = parseFloat(offerUtilization.remainingBalance);
const percentUtilized = parseFloat(offerUtilization.percentUtilized);
const totalFunds = parseFloat(offerSummary.maxDiscount);
const redeemedFunds = parseFloat(offerSummary.amountOfOfferSpent);
const remainingFunds = parseFloat(offerSummary.remainingBalance);
const percentUtilized = parseFloat(offerSummary.percentOfOfferSpent);

return {
totalFunds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import '@testing-library/jest-dom/extend-expect';

import LearnerCreditManagement from '../LearnerCreditManagement';
import { EnterpriseSubsidiesContext } from '../../EnterpriseSubsidiesContext';
import { useOfferUtilization } from '../data/hooks';
import { useOfferSummary } from '../data/hooks';

jest.mock('../data/hooks');
useOfferUtilization.mockReturnValue({
useOfferSummary.mockReturnValue({
isLoading: false,
offerUtilization: null,
offerSummary: null,
});

jest.mock('../../NotFoundPage', () => ({
Expand Down Expand Up @@ -80,7 +80,7 @@ const defaultEnterpriseSubsidiesContextValue = {
};

const mockOfferDisplayName = 'Test Enterprise Offer';
const mockUtilization = {
const mockOfferSummary = {
totalFunds: 5000,
redeemedFunds: 200,
remainingFunds: 4800,
Expand Down Expand Up @@ -119,9 +119,9 @@ describe('<LearnerCreditManagement />', () => {
const subsidiesContextValue = {
offers: [mockOffer],
};
useOfferUtilization.mockReturnValue({
useOfferSummary.mockReturnValue({
isLoading: false,
offerUtilization: mockUtilization,
offerSummary: mockOfferSummary,
});
render(<LearnerCreditManagementWrapper enterpriseSubsidiesContextValue={subsidiesContextValue} />);
expect(screen.queryByTestId('404-page-not-found')).toBeFalsy();
Expand Down Expand Up @@ -149,9 +149,9 @@ describe('<LearnerCreditManagement />', () => {
isCurrent: false,
}],
};
useOfferUtilization.mockReturnValue = {
useOfferSummary.mockReturnValue = {
isLoading: false,
offerUtilization: mockUtilization,
offerSummary: mockOfferSummary,
};
render(<LearnerCreditManagementWrapper enterpriseSubsidiesContextValue={subsidiesContextValue} />);
expect(screen.getByText('Ended'));
Expand All @@ -164,9 +164,9 @@ describe('<LearnerCreditManagement />', () => {
isCurrent: true,
}],
};
useOfferUtilization.mockReturnValue = {
useOfferSummary.mockReturnValue = {
isLoading: false,
offerUtilization: mockUtilization,
offerSummary: mockOfferSummary,
};
render(<LearnerCreditManagementWrapper enterpriseSubsidiesContextValue={subsidiesContextValue} />);
expect(screen.getByText('Active'));
Expand Down
30 changes: 4 additions & 26 deletions src/data/services/EnterpriseDataApiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,36 +30,14 @@ class EnterpriseDataApiService {
return EnterpriseDataApiService.apiClient().get(url);
}

static fetchEnterpriseOfferUtilization(enterpriseUUID, offerId, options = {}) {
static fetchEnterpriseOfferSummary(enterpriseId, offerId, options = {}) {
const queryParams = new URLSearchParams({
...snakeCaseObject(options),
});
// eslint-disable-next-line no-unused-vars
const url = `${EnterpriseDataApiService.enterpriseBaseUrl}${enterpriseUUID}/offers/${offerId}/?${queryParams.toString()}`;

// mocked api response
return new Promise((resolve) => {
setTimeout(() => {
const maxDiscount = 38000;
const amountSpent = 1200;
const remainingBalance = maxDiscount - amountSpent;
const percentSpent = amountSpent / maxDiscount;

resolve({
data: {
offer_id: offerId,
status: 'Open',
enterprise_customer_uuid: enterpriseUUID,
amount_of_offer_spent: amountSpent,
max_discount: maxDiscount,
percent_utilized: percentSpent,
remaining_balance: remainingBalance,
},
});
}, 2000);
});

// return EnterpriseDataApiService.apiClient().get(url);
const url = `${EnterpriseDataApiService.enterpriseBaseUrl}${enterpriseId}/offers/${offerId}/?${queryParams.toString()}`;

return EnterpriseDataApiService.apiClient().get(url);
}

static fetchUnenrolledRegisteredLearners(enterpriseId, options, { csv } = {}) {
Expand Down