Skip to content

feat: implement scrolling to XBlocks when browsing metrics#24

Merged
farhaanbukhsh merged 31 commits intoopenedx:mainfrom
open-craft:tecoholic/BB-9656-scroll-to-xblock-in-unit-page
Apr 23, 2025
Merged

feat: implement scrolling to XBlocks when browsing metrics#24
farhaanbukhsh merged 31 commits intoopenedx:mainfrom
open-craft:tecoholic/BB-9656-scroll-to-xblock-in-unit-page

Conversation

@tecoholic
Copy link
Contributor

@tecoholic tecoholic commented Apr 13, 2025

Changelist

1. Styling

  • Font sizing and styling to match the Figma Designs.
  • Width of the chart to full width
  • Height of the chart - WIP - temporarily at 30rem.

2. Unit Page

  • Remove 404 Errors in the unit page
  • Limit the components in the sidebar to only those in current view
  • Scroll to the relevant component when chart is opened

3. Course Outline Sidebar

  • Limit view to max 5 items and allow for expanding to others
  • Problem Analytics above Video Analytics

Screen capture of the scrolling in action

Screencast_20250414_143034.webm

Testing Instructions

This PR depends on a number of custom branches, so set them all up in the tutor environment before testing.

  1. Add edx-platform as tutor mount and checkout to this PR branch
  2. Install tutor-contrib-aspects from this PR branch
  3. Clone the platform-plugin-aspects from this PR branch and add it as a tutor-mount.
  4. Add the following as a simple tutor plugin and enable it
from tutor import hooks
  
hooks.Filters.ENV_PATCHES.add_item(
    (
        "openedx-dev-dockerfile-post-python-requirements",
        """RUN pip install -e /mnt/platform-plugin-aspects"""
    )
)
  1. Clone frontend-app-authoring and checkout to this branch and add it as a tutor mount so that the authoring-dev image is created.
  2. Now inside frontend-app-authoring clone this repo and checkout the PR. This is needed as the frontend-app-authoring is being bind mounted and we need access to this plugin's PR branch in the mounted volume.
  3. Run npm install ./frontend-plugin-aspects to install the plugin for the Authoring MFE.
  4. Create or update the env.config.jsx to match the following:
import { PLUGIN_OPERATIONS, DIRECT_PLUGIN } from '@openedx/frontend-plugin-framework';
import { SidebarToggleWrapper, CourseHeaderButton, UnitActionsButton, AspectsSidebarProvider, CourseOutlineSidebar, UnitPageSidebar } from '@openedx/frontend-plugin-aspects';

// Load environment variables from .env file
const config = {
  ...process.env,
  pluginSlots: {
    course_authoring_outline_sidebar_slot: {
      keepDefault: true,
      plugins: [
        {
          op: PLUGIN_OPERATIONS.Insert,
          widget: {
            id: 'outline-sidebar',
            priority: 1,
            type: DIRECT_PLUGIN,
            RenderWidget: CourseOutlineSidebar,
          }
        },
        {
          op: PLUGIN_OPERATIONS.Wrap,
          widgetId: 'default_contents',
          wrapper: SidebarToggleWrapper,
        }
      ]
    },
    course_authoring_unit_sidebar_slot: {
      keepDefault: true,
      plugins: [
        {
          op: PLUGIN_OPERATIONS.Insert,
          widget: {
            id: 'course-unit-sidebar',
            priority: 1,
            type: DIRECT_PLUGIN,
            RenderWidget: UnitPageSidebar,
          }
        },
        {
          op: PLUGIN_OPERATIONS.Wrap,
          widgetId: 'default_contents',
          wrapper: SidebarToggleWrapper,
        }
      ]
    },
    course_outline_header_actions_slot: {
      keepDefault: true,
      plugins: [
        {
          op: PLUGIN_OPERATIONS.Insert,
          widget: {
            id: 'outline-analytics',
            type: DIRECT_PLUGIN,
            priority: 51,
            RenderWidget: CourseHeaderButton,
          },
        },
      ],
    },
    course_unit_header_actions_slot: {
      keepDefault: true,
      plugins: [
        {
          op: PLUGIN_OPERATIONS.Insert,
          widget: {
            id: 'unit-analytics',
            type: DIRECT_PLUGIN,
            priority: 51,
            RenderWidget: CourseHeaderButton,
          }
        },
      ]
    },
    course_outline_unit_card_extra_actions_slot: {
      keepDefault: true,
      plugins: [
        {
          op: PLUGIN_OPERATIONS.Insert,
          widget: {
            id: 'uni-card-my-extra-action',
            type: DIRECT_PLUGIN,
            priority: 51,
            RenderWidget: UnitActionsButton,
          }
        }
      ]
    },
    course_outline_subsection_card_extra_actions_slot: {
      keepDefault: true,
      plugins: [
        {
          op: PLUGIN_OPERATIONS.Insert,
          widget: {
            id: 'sub-card-my-extra-action',
            type: DIRECT_PLUGIN,
            priority: 51,
            RenderWidget: () => (<></>),
          }
        }
      ]
    },
    authoring_app_slot: {
      keepDefault: true,
      plugins: [
        {
          op: PLUGIN_OPERATIONS.Wrap,
          widgetId: 'default_contents',
          wrapper: AspectsSidebarProvider,
        }
      ]
    },
    // -------------------
  },
};

export default config;
  1. Run tutor dev launch and wait for everything to be online. Import the democourse if it's not done already.
  2. Visit the Studio to test everything. If the "Unit Page" goes to the legacy studio UI, follow the instruction under Course Unit Analytics in this PR description to enable it for the test course.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Apr 13, 2025
@openedx-webhooks
Copy link

openedx-webhooks commented Apr 13, 2025

Thanks for the pull request, @tecoholic!

This repository is currently maintained by @openedx/committers-frontend.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@github-project-automation github-project-automation bot moved this to Needs Triage in Contributions Apr 13, 2025
@tecoholic tecoholic marked this pull request as draft April 13, 2025 03:45
@tecoholic tecoholic self-assigned this Apr 14, 2025
@tecoholic tecoholic marked this pull request as ready for review April 14, 2025 04:43
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: After a recent rebase on Authoring MFE master, the MFE wouldn't load at all until I updated the React Version to match the Authoring MFE.

"scripts": {
"preinstall": "npm run build",
"build": "fedx-scripts babel -x .js,.jsx,.ts,.tsx src --out-dir dist --ignore **/*.test.jsx,**/*.test.js,**/setupTest.js",
"build": "fedx-scripts babel -x .js,.jsx,.ts,.tsx src --out-dir dist --ignore **/*.test.jsx,**/*.test.js,**/setupTest.js && cp src/*.css dist/",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just tacked on a cp to copy the CSS file. Since we are running babel directly without webpack, there is not css-loader and didn't want to spend too much time on this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is entirely fair since we have no need for CSS here and the future of paragon is to use CSS variables.

"scripts": {
"preinstall": "npm run build",
"build": "fedx-scripts babel -x .js,.jsx,.ts,.tsx src --out-dir dist --ignore **/*.test.jsx,**/*.test.js,**/setupTest.js",
"build": "fedx-scripts babel -x .js,.jsx,.ts,.tsx src --out-dir dist --ignore **/*.test.jsx,**/*.test.js,**/setupTest.js && cp src/*.css dist/",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is entirely fair since we have no need for CSS here and the future of paragon is to use CSS variables.

// can be used only with the provider. So here the context is first checked before
// the hook is called.
const ctx = React.useContext(IframeContext);
const {sendMessageToIframe} = !!ctx ? useIframe() : {};
Copy link
Contributor

Choose a reason for hiding this comment

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

You should not have an optional hook.
i.e. here the hook only runs if ctx is defined, but won't run otherwise. This can lead to errors with hooks.
Use something like the following:

  const iframe = useIframe();
  const {sendMessageToIframe} = !!ctx ? iframe : {};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xitij2000 I knew this was pretty hacky, but calling useIframe() unconditionally breaks the component on CourseOutline page as there is not IframeContext.

useIframe must be used within an IframeProvider

Call Stack
 useIframe
  src/generic/hooks/context/hooks.tsx:19:11
 CourseContentList
  frontend-plugin-aspects/dist/components/AspectsSidebar.js:60:104
 renderWithHooks
  node_modules/react-dom/cjs/react-dom.development.js:15486:18
 mountIndeterminateComponent
  node_modules/react-dom/cjs/react-dom.development.js:20098:13
 beginWork
  node_modules/react-dom/cjs/react-dom.development.js:21621:16

I think I might need to call useIframe in the UnitPageSidebar (where I am sure the IframeContext exists) and pass it down as props. Kindly let me know if there is a better way to do this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that might be the way to go. If you have a hook that should be conditional, it's better to put it in a separate component. i.e. in this case you can have sendMessageToIFrame as an optional prop in AspectsSidebar and then have a UnitPageSidebar that uses AspectsSidebar and uses the hook to populate that prop, and an OutlineSidebar that leaves it as null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xitij2000 Thank you. It worked out pretty nicely in 6a7e633

@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Apr 14, 2025
@codecov
Copy link

codecov bot commented Apr 22, 2025

Codecov Report

Attention: Patch coverage is 18.84058% with 224 lines in your changes missing coverage. Please review.

Project coverage is 16.61%. Comparing base (533cfbf) to head (61b0e4f).
Report is 33 commits behind head on main.

Files with missing lines Patch % Lines
src/components/AspectsSidebar/index.tsx 0.00% 53 Missing ⚠️
src/components/AspectsSidebar/Dashboard.tsx 0.00% 45 Missing ⚠️
src/hooks.ts 0.00% 44 Missing ⚠️
...rc/components/AspectsSidebar/CourseContentList.tsx 0.00% 22 Missing ⚠️
src/components/UnitActionsButton.tsx 0.00% 20 Missing ⚠️
src/components/UnitPageSidebar.tsx 0.00% 14 Missing ⚠️
src/components/SubSectionAnalyticsButton.tsx 0.00% 13 Missing ⚠️
src/components/CourseHeaderButton.tsx 0.00% 6 Missing ⚠️
src/index.ts 0.00% 3 Missing ⚠️
src/components/SidebarToggleWrapper.tsx 0.00% 2 Missing ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff            @@
##           main      #24       +/-   ##
=========================================
+ Coverage      0   16.61%   +16.61%     
=========================================
  Files         0       15       +15     
  Lines         0      331      +331     
  Branches      0       66       +66     
=========================================
+ Hits          0       55       +55     
- Misses        0      276      +276     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tecoholic tecoholic force-pushed the tecoholic/BB-9656-scroll-to-xblock-in-unit-page branch from 482fca4 to 61b0e4f Compare April 23, 2025 13:20
Copy link
Member

@farhaanbukhsh farhaanbukhsh left a comment

Choose a reason for hiding this comment

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

👍

  • ✅ I tested this on the sandbox
  • ✅ I read through the code
  • ❌ I checked for accessibility issues
  • ❌ Includes documentation
  • ❌ I made sure any change in configuration variables is reflected in the corresponding client's configuration-secure repository.

@farhaanbukhsh farhaanbukhsh merged commit ca370f9 into openedx:main Apr 23, 2025
6 checks passed
@github-project-automation github-project-automation bot moved this from Waiting on Author to Done in Contributions Apr 23, 2025
@tecoholic tecoholic deleted the tecoholic/BB-9656-scroll-to-xblock-in-unit-page branch April 24, 2025 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open-source-contribution PR author is not from Axim or 2U

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants