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: modifies logic for setting cookies on dashboard page load #881

Merged
merged 11 commits into from
Dec 5, 2023

Conversation

brobro10000
Copy link
Member

@brobro10000 brobro10000 commented Dec 1, 2023

Modifies the logic for redirecting the page to the search page based on whether the has-user-visited-learner-dashboard cookie has been set to take into account whether active course assignments exist.

This involves hoisting some of the logic from CourseEnrollments.jsx into DashboardPage.jsx to avoid partial render before redirect.

For all changes

  • Ensure adequate tests are in place (or reviewed existing tests cover changes)

Only if submitting a visual change

  • Ensure to attach screenshots
  • Ensure to have UX team confirm screenshots

Copy link

codecov bot commented Dec 1, 2023

Codecov Report

Attention: 98 lines in your changes are missing coverage. Please review.

Comparison is base (d36b78a) 84.87% compared to head (20e3c7d) 85.02%.
Report is 88 commits behind head on master.

Files Patch % Lines
...ntent/course-enrollments/CourseAssignmentAlert.jsx 27.27% 8 Missing ⚠️
src/components/course/data/hooks.jsx 87.93% 7 Missing ⚠️
...course-enrollments/course-cards/BaseCourseCard.jsx 89.85% 7 Missing ⚠️
src/components/my-career/VisualizeCareer.jsx 74.07% 6 Missing and 1 partial ⚠️
src/components/my-career/data/service.js 56.25% 7 Missing ⚠️
src/components/course/data/utils.jsx 95.89% 6 Missing ⚠️
...n-content/course-enrollments/CourseEnrollments.jsx 81.25% 6 Missing ⚠️
src/components/my-career/AddJobRole.jsx 60.00% 5 Missing and 1 partial ⚠️
src/components/my-career/data/hooks.jsx 50.00% 6 Missing ⚠️
...oard/main-content/course-enrollments/data/utils.js 83.33% 5 Missing ⚠️
... and 19 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #881      +/-   ##
==========================================
+ Coverage   84.87%   85.02%   +0.14%     
==========================================
  Files         320      328       +8     
  Lines        6399     6883     +484     
  Branches     1552     1685     +133     
==========================================
+ Hits         5431     5852     +421     
- Misses        941     1000      +59     
- Partials       27       31       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@brobro10000 brobro10000 marked this pull request as ready for review December 4, 2023 15:24
Comment on lines 43 to 45
const learnerContentAssignmentsArray = learnerCreditPolicies?.flatMap(
item => item?.learnerContentAssignments || [],
);
Copy link
Member

Choose a reason for hiding this comment

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

[suggestion, non-blocking] Looks like logic to generate a flat map of assignments based on the learner credit policies happens in two places now. I'm wondering if it'd be worth abstracting this logic out to where we get the response about redeemable learner credit policies from the credits_available API so components such as this one don't need to run their own .flatMap to get a list of assignments.

E.g., useRedeemableLearnerCreditPolicies and its query function getRedeemablePoliciesData could return a data structure more along the lines of the following, where it splits out redeemablePolicies vs. learnerContentAssignments:

const getRedeemablePoliciesData = async ({ queryKey }) => {
  const enterpriseId = queryKey[1];
  const userID = queryKey[2];
  const response = await fetchRedeemableLearnerCreditPolicies(enterpriseId, userID);
  const redeemablePolicies = camelCaseObject(transformRedeemablePoliciesData(response.data));
  const learnerContentAssignments = redeemablePolicies.flatMap(policy => policy.learnerContentAssignments);
  return {
    redeemablePolicies,
    learnerContentAssignments,
  };
};

export function useRedeemableLearnerCreditPolicies(enterpriseId, userID) {
  return useQuery({
    queryKey: ['redeemablePolicies', enterpriseId, userID],
    queryFn: getRedeemablePoliciesData,
    onError: (error) => {
      logError(error);
    },
  });
}

Any component that relies on an assignments list could rely on learnerContentAssignments returned by the hook instead of having to re-compute the .flatMap each time. Then, the same line in the isDisableCourseSearch function could be simplified to:

const assignments = redeemableLearnerCreditPolicies?.learnerContentAssignments;

Copy link
Member Author

Choose a reason for hiding this comment

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

Opted to resolve this in a followup PR to focus on the MVP, but intended to resolve immediately following the validation of functionality of this PR in stage/prod environment. Updated ticket to document the decision.

src/components/dashboard/DashboardPage.jsx Outdated Show resolved Hide resolved
src/components/dashboard/tests/DashboardPage.test.jsx Outdated Show resolved Hide resolved
Comment on lines 30 to 33
{
learnerContentAssignments: {
state: 'accepted',
},
Copy link
Member

Choose a reason for hiding this comment

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

nit: should we include assignment(s) with state='errored' and state='cancelled' as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

Deferred on the errored state for now since the repo doesn't handle the error state at the moment, but the following PR with the optimizations will handle the error state. Will leave comment open to reference. 👍🏽

Copy link
Member

@adamstankiewicz adamstankiewicz left a comment

Choose a reason for hiding this comment

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

LGTM, with a couple more nit-level comments. Great job!

src/components/dashboard/data/utils.js Outdated Show resolved Hide resolved
src/components/dashboard/data/utils.js Outdated Show resolved Hide resolved
@brobro10000 brobro10000 merged commit d77b948 into master Dec 5, 2023
6 checks passed
@brobro10000 brobro10000 deleted the hu/ent-8067 branch December 5, 2023 13:10
@jajjibhai008 jajjibhai008 mentioned this pull request Dec 7, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants