forked from openedx/frontend-app-learning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Pearson-Advance/vue/PADV-256
PADV-256 - Integrate current Sidebar MFE into the Learning Site.
- Loading branch information
Showing
23 changed files
with
311 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Add Outline Sidebar | ||
|
||
Following the [DISCOVERY](https://agile-jira.pearson.com/browse/PADV-213) made and the proposed [DESIGN](https://lucid.app/lucidchart/d52cc785-409f-4964-af29-ff277baa5bc5/edit?invitationId=inv_e569412e-e9f0-44aa-a9fa-54123d272f1a&referringApp=slack&page=l2M~LaFs47mo#), the MFE sidebar navigation is added in Frontend-App-Learning. | ||
|
||
Using currently logic in Frontend-App-Learning, **Outline Sidebar** is integrated following Discussion Sidebar. Using the already created **SidebarBase** function, the integration of the Outline sidebar is done through an iframe, which allows the integration of a Microfrontend located in a certain path, in this case using the port :9090, called **SIDEBAR_MFE_BASE_URL**. | ||
|
||
Then, using **SidebarTriggerBase**, the respective integration of the trigger is done, where to locate it in a different div from the one that already exists in src/courseware/course/Course.jsx module, the **SidebarOutlineTrigger** module is created. | ||
|
||
To show the Outline Sidebar it is necessary to take the context through the **SidebarContext** function to src/courseware/course/sequence/Sequence.jsx where if the Outline Sidebar is active it will be shown on the left, otherwise another sidebar will be shown in the default from the platform. | ||
|
||
## Next Step: Add Navigation Functionality | ||
|
||
The next step for the Outline Sidebar integration is to make the navigation more user friendly where it goes to the subsection the user needs without the need to open another tab. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
import TriggerButton from 'courseware/course/sidebar/TriggerButton'; | ||
import { ID } from 'courseware/course/sidebar/sidebars/outline/OutlineTrigger'; | ||
|
||
function SidebarOutlineTrigger() { | ||
return ( | ||
<section className="d-flex mb-auto"> | ||
<TriggerButton sidebarId={ID} /> | ||
</section> | ||
); | ||
} | ||
|
||
SidebarOutlineTrigger.propTypes = {}; | ||
|
||
export default SidebarOutlineTrigger; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import classNames from 'classnames'; | ||
import PropTypes from 'prop-types'; | ||
import React, { useContext } from 'react'; | ||
import SidebarContext from './SidebarContext'; | ||
import { SIDEBARS } from './sidebars'; | ||
|
||
function TriggerButton({ | ||
sidebarId, | ||
}) { | ||
const { | ||
toggleSidebar, | ||
currentSidebar, | ||
} = useContext(SidebarContext); | ||
const { Trigger } = SIDEBARS[sidebarId]; | ||
const isActive = sidebarId === currentSidebar; | ||
return ( | ||
<section | ||
className={classNames('mt-3', { 'border-primary-700': isActive })} | ||
style={{ borderBottom: isActive ? '2px solid' : null }} | ||
key={sidebarId} | ||
> | ||
<Trigger onClick={() => toggleSidebar(sidebarId)} key={sidebarId} /> | ||
</section> | ||
); | ||
} | ||
|
||
TriggerButton.propTypes = { | ||
sidebarId: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default TriggerButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/courseware/course/sidebar/sidebars/outline/OutlineSidebar.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { ensureConfig, getConfig } from '@edx/frontend-platform'; | ||
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; | ||
import React, { useContext } from 'react'; | ||
import SidebarBase from 'courseware/course/sidebar/common/SidebarBase'; | ||
import SidebarContext from 'courseware/course/sidebar/SidebarContext'; | ||
import { ID } from 'courseware/course/sidebar/sidebars/outline/OutlineTrigger'; | ||
|
||
import messages from './messages'; | ||
|
||
ensureConfig(['SIDEBAR_MFE_BASE_URL']); | ||
|
||
function OutlineSidebar({ intl }) { | ||
const { | ||
courseId, | ||
} = useContext(SidebarContext); | ||
|
||
const outlineUrl = `${getConfig().SIDEBAR_MFE_BASE_URL}/${courseId}`; | ||
return ( | ||
<SidebarBase | ||
title={intl.formatMessage(messages.outlineTitle)} | ||
ariaLabel={intl.formatMessage(messages.outlineTitle)} | ||
sidebarId={ID} | ||
width="40rem" | ||
showTitleBar={false} | ||
> | ||
<iframe | ||
src={`${outlineUrl}?inContext`} | ||
className="d-flex w-100 border-0" | ||
style={{ minHeight: '60rem' }} | ||
title={intl.formatMessage(messages.outlineTitle)} | ||
/> | ||
</SidebarBase> | ||
); | ||
} | ||
|
||
OutlineSidebar.propTypes = { | ||
intl: intlShape.isRequired, | ||
}; | ||
|
||
OutlineSidebar.Trigger = OutlineSidebar; | ||
OutlineSidebar.ID = ID; | ||
|
||
export default injectIntl(OutlineSidebar); |
43 changes: 43 additions & 0 deletions
43
src/courseware/course/sidebar/sidebars/outline/OutlineSidebar.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from 'react'; | ||
import { | ||
initializeMockApp, initializeTestStore, render, screen, | ||
} from 'setupTest'; | ||
import SidebarContext from 'courseware/course/sidebar/SidebarContext'; | ||
import OutlineSidebar from 'courseware/course/sidebar/sidebars/outline/OutlineSidebar'; | ||
|
||
initializeMockApp(); | ||
|
||
describe('Outline Sidebar', () => { | ||
let mockData; | ||
let courseId; | ||
|
||
beforeEach(async () => { | ||
const store = await initializeTestStore({ | ||
excludeFetchCourse: false, | ||
excludeFetchSequence: false, | ||
}); | ||
const state = store.getState(); | ||
courseId = state.courseware.courseId; | ||
|
||
mockData = { | ||
courseId, | ||
currentSidebar: 'OUTLINE', | ||
}; | ||
}); | ||
|
||
function renderWithProvider(testData = {}) { | ||
const { container } = render( | ||
<SidebarContext.Provider value={{ ...mockData, ...testData }}> | ||
<OutlineSidebar /> | ||
</SidebarContext.Provider>, | ||
); | ||
return container; | ||
} | ||
|
||
it('should show up if courseId associated with it', async () => { | ||
renderWithProvider(); | ||
expect(screen.queryByTitle('Outline')).toBeInTheDocument(); | ||
expect(screen.queryByTitle('Outline')) | ||
.toHaveAttribute('src', `http://localhost:9090/${courseId}?inContext`); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
src/courseware/course/sidebar/sidebars/outline/OutlineTrigger.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { ensureConfig } from '@edx/frontend-platform'; | ||
import { injectIntl, intlShape } from '@edx/frontend-platform/i18n'; | ||
import { Icon } from '@edx/paragon'; | ||
import { ExpandMore } from '@edx/paragon/icons'; | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import SidebarTriggerBase from 'courseware/course/sidebar/common/TriggerBase'; | ||
import messages from 'courseware/course/sidebar/sidebars/outline/messages'; | ||
|
||
ensureConfig(['SIDEBAR_MFE_BASE_URL']); | ||
export const ID = 'OUTLINE'; | ||
|
||
function OutlineTrigger({ | ||
intl, | ||
onClick, | ||
}) { | ||
return ( | ||
<SidebarTriggerBase onClick={onClick} ariaLabel={intl.formatMessage(messages.openOutlineTrigger)}> | ||
<Icon src={ExpandMore} className="m-0 m-auto" /> | ||
</SidebarTriggerBase> | ||
); | ||
} | ||
|
||
OutlineTrigger.propTypes = { | ||
intl: intlShape.isRequired, | ||
onClick: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default injectIntl(OutlineTrigger); |
Oops, something went wrong.