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 course optimizer page #1533

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open

Conversation

jesperhodge
Copy link
Member

@jesperhodge jesperhodge commented Nov 26, 2024

Description

Course Optimizer is a feature approved by the Openedx community that adds a "Course Optimizer" page to studio where users can run a scan of a course for broken links - links that point to pages that have a 404.

Depends on backend: openedx/edx-platform#35887 - test together.

This also requires adding a nav menu item to edx-platform legacy studio. That should be implemented before enabling the waffle flag on prod.

Links

Testing instructions

  • Checkout Backend branch as well as this branch
  • Add the required waffle flag like this:
  • Go to localhost:18000/admin/waffle/flag/
  • Click "Add Flag"
  • As name, type: "contentstore.enable_course_optimizer"
  • In the "everyone" field, select "Yes"
  • Leave other fields as they are and save
  • Go to a course and insert a broken link to a text block, e.g. just write "https://broken.example.com" somewhere in the block
  • Add an image to a text block
  • Go to Content -> Files in the menu
  • Select that image and lock it
  • Go to course-authoring (not legacy studio) in a course and select "Course Optimizer" from Tools menu
  • Start a course scan (may take a while)
  • Progress steps should appear and show in-progress, then turn green
  • Result should show
  • Result should list all and only sections with broken or locked links (may be more than the ones you added if there are already broken links in the course)
  • "Go to block" links should bring you to the block with the broken or locked link
  • Next to it in the results display the broken link should be listed
  • You should see the date of the last scan, which should be today
  • Refresh page in browser
  • Same results as before should load without needing to start a new scan
  • Remove any broken and locked links from course
  • Refresh page
  • Outdated results should still be shown
  • Run new scan
  • Now, no results should be shown, and the page should signal that no broken links were found

};

CourseOptimizerPage.defaultProps = {};
export default injectIntl(CourseOptimizerPage);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use useIntl instead of injectIntl. If you use VS Code there should be a visual reminder of this:
Screenshot

Screenshot

let me know if not.

courseId: PropTypes.string.isRequired,
};

CourseOptimizerPage.defaultProps = {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't use defaultProps - it's deprecated.

CourseOptimizerPage.propTypes = {
intl: intlShape.isRequired,
courseId: PropTypes.string.isRequired,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

I strongly prefer TypeScript types over propTypes, because TypeScript types get checked by CI whereas propTypes warnings are routinely ignored. Open up the JS console on any authoring MFE page in your browser, and you'll see the problem.

Comment on lines 11 to 25
beforeEach(() => {
initializeMockApp({
authenticatedUser: {
userId: 3,
username: 'abc123',
administrator: true,
roles: [],
},
});
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
});

afterEach(() => {
jest.clearAllMocks();
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of all this boilerplate, you can just use

const { axiosMock } = initializeMocks();

as the first line of each test case. You can then remove the beforeEach and afterEach you have here, because initializeMocks takes care of that all for you, including jest.clearAllMocks();.

See

/**
* Initialize common mocks that many of our React components will require.
*
* This should be called within each test case, or in `beforeEach()`.
*
* Returns the new `axiosMock` in case you need to mock out axios requests.
*/
export function initializeMocks({ user = defaultUser, initialState = undefined }: {
user?: { userId: number, username: string },
initialState?: Record<string, any>, // TODO: proper typing for our redux state
} = {}) {

Copy link

codecov bot commented Dec 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.07%. Comparing base (66577b0) to head (1b8854c).
Report is 25 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1533      +/-   ##
==========================================
- Coverage   93.08%   93.07%   -0.01%     
==========================================
  Files        1051     1092      +41     
  Lines       20586    21617    +1031     
  Branches     4459     4654     +195     
==========================================
+ Hits        19162    20120     +958     
- Misses       1355     1425      +70     
- Partials       69       72       +3     

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

@jesperhodge jesperhodge marked this pull request as ready for review December 20, 2024 00:49
@jesperhodge jesperhodge requested a review from a team as a code owner December 20, 2024 00:49
@jesperhodge jesperhodge marked this pull request as draft December 20, 2024 00:50
@jesperhodge jesperhodge marked this pull request as ready for review December 20, 2024 16:35
@jesperhodge
Copy link
Member Author

Hi @bradenmacdonald , I think I addressed your main concerns. Is there anything I missed or that you would like me to change?

Copy link
Contributor

@rayzhou-bit rayzhou-bit left a comment

Choose a reason for hiding this comment

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

This looks really good! My feedback comments are summarized below:

  • We should show block displayName in results
  • Should we display locked link count?
  • Fix tooltip text for locked files (and text suggestion)

src/generic/course-stepper/index.jsx Outdated Show resolved Hide resolved
},
lockedInfoTooltip: {
id: 'course-authoring.course-optimizer.lockedInfoTooltip',
defaultMessage: 'These course files are &quot;locked&quot, so we cannot test whether they work or not.',
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: "so we cannot verify if the link can access the file"

Copy link
Contributor

Choose a reason for hiding this comment

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

not nit: The &quot; should be \'

id: string;
displayName: string;
blocks: {
id: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

We want to show the displayName for blocks.

onSort: () => {},
width: 'col-3',
hideHeader: true,
},
Copy link
Contributor

Choose a reason for hiding this comment

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

We should have show the displayName of the block. I think we can either add another column or replace the 'Go to Block' text with the displayName of the block.

<SectionCollapsible
key={section.id}
title={section.displayName}
redItalics={intl.formatMessage(messages.brokenLinksNumber, { count: brokenLinkCounts[index] })}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we show a count for locked links as well?

@bradenmacdonald
Copy link
Contributor

Hi @bradenmacdonald , I think I addressed your main concerns. Is there anything I missed or that you would like me to change?

I think it looks fantastic! Great job, and thanks so much.

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.

3 participants