Compare commits
30 Commits
v7.0.0
...
renovate/a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
85881f5857 | ||
|
|
af6fe9fcdb | ||
|
|
1118dca6c8 | ||
|
|
59ac43b1cc | ||
|
|
aaa849a697 | ||
|
|
840b042606 | ||
|
|
93d62e35e8 | ||
|
|
0c305651b0 | ||
|
|
dfad1edcb9 | ||
|
|
af46ef756e | ||
|
|
c86165180f | ||
|
|
97063850c6 | ||
|
|
af252d2d3f | ||
|
|
9e850c3229 | ||
|
|
413454b6e6 | ||
|
|
ed7cc8a36e | ||
|
|
a8a4ad59ed | ||
|
|
9f2b2a4026 | ||
|
|
21953ec96d | ||
|
|
57671449b1 | ||
|
|
66012905b2 | ||
|
|
209d52ed60 | ||
|
|
6d424edbd5 | ||
|
|
5a4279a7f3 | ||
|
|
ef0ea1378d | ||
|
|
b8b39bffbc | ||
|
|
7f778adda9 | ||
|
|
4cf48d8ba8 | ||
|
|
2e82ba910d | ||
|
|
02533b0474 |
10
.github/workflows/ci.yml
vendored
@@ -9,19 +9,15 @@ on:
|
||||
jobs:
|
||||
tests:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
node: [20, 24]
|
||||
continue-on-error: ${{ matrix.node == 24 }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Setup Nodejs
|
||||
uses: actions/setup-node@v4
|
||||
uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: ${{ matrix.node }}
|
||||
node-version-file: '.nvmrc'
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
- name: Validate package-lock.json changes
|
||||
|
||||
16
.github/workflows/release.yml
vendored
@@ -4,19 +4,26 @@ on:
|
||||
branches:
|
||||
- master
|
||||
- alpha
|
||||
permissions:
|
||||
contents: read # for checkout
|
||||
jobs:
|
||||
release:
|
||||
name: Release
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: write # to be able to publish a GitHub release
|
||||
issues: write # to be able to comment on released issues
|
||||
pull-requests: write # to be able to comment on released pull requests
|
||||
id-token: write # to enable use of OIDC for trusted publishing and npm provenance
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- name: Setup Nodejs Env
|
||||
run: echo "NODE_VER=`cat .nvmrc`" >> $GITHUB_ENV
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: ${{ env.NODE_VER }}
|
||||
- name: Install dependencies
|
||||
@@ -39,9 +46,6 @@ jobs:
|
||||
- name: Build
|
||||
run: npm run build
|
||||
- name: Release
|
||||
uses: cycjimmy/semantic-release-action@v3
|
||||
with:
|
||||
semantic_version: 16
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE_GITHUB_TOKEN }}
|
||||
NPM_TOKEN: ${{ secrets.SEMANTIC_RELEASE_NPM_TOKEN }}
|
||||
run: npx semantic-release@25
|
||||
|
||||
@@ -72,9 +72,9 @@ Cloning and Startup
|
||||
|
||||
``git clone https://github.com/openedx/frontend-component-header.git``
|
||||
|
||||
2. Use node v18.x.
|
||||
2. Use node v24.x.
|
||||
|
||||
The current version of the micro-frontend build scripts support node 18.
|
||||
The current version of the micro-frontend build scripts support node 24.
|
||||
Using other major versions of node *may* work, but this is unsupported. For
|
||||
convenience, this repository includes an .nvmrc file to help in setting the
|
||||
correct node version via `nvm <https://github.com/nvm-sh/nvm>`_.
|
||||
|
||||
11391
package-lock.json
generated
@@ -34,22 +34,22 @@
|
||||
"@edx/brand": "npm:@openedx/brand-openedx@^1.2.2",
|
||||
"@edx/browserslist-config": "^1.1.1",
|
||||
"@edx/frontend-platform": "^8.3.1",
|
||||
"@edx/reactifex": "^2.1.1",
|
||||
"@openedx/frontend-build": "^14.3.2",
|
||||
"@openedx/paragon": "^23.0.0",
|
||||
"@testing-library/dom": "^10.4.0",
|
||||
"@testing-library/jest-dom": "5.17.0",
|
||||
"@testing-library/react": "^16.2.0",
|
||||
"jest": "30.1.3",
|
||||
"jest": "30.2.0",
|
||||
"jest-environment-jsdom": "^30.0.0",
|
||||
"prop-types": "15.8.1",
|
||||
"react": "^18.3.1",
|
||||
"react-dom": "^18.3.1",
|
||||
"react-redux": "^8.1.1",
|
||||
"react-router-dom": "6.30.1",
|
||||
"react-router-dom": "6.30.2",
|
||||
"react-test-renderer": "^18.3.1",
|
||||
"redux": "4.2.1",
|
||||
"redux-saga": "1.3.0"
|
||||
"redux-saga": "1.4.2",
|
||||
"ts-jest": "^29.4.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"@fortawesome/fontawesome-svg-core": "6.7.2",
|
||||
@@ -71,4 +71,3 @@
|
||||
"react-router-dom": "^6.14.2"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,11 +61,6 @@ const messages = defineMessages({
|
||||
defaultMessage: 'Studio Home',
|
||||
description: 'Link to the Studio Home',
|
||||
},
|
||||
'header.user.menu.studio.maintenance': {
|
||||
id: 'header.user.menu.studio.maintenance',
|
||||
defaultMessage: 'Maintenance',
|
||||
description: 'Link to the Studio Maintenance',
|
||||
},
|
||||
'header.label.account.nav': {
|
||||
id: 'header.label.account.nav',
|
||||
defaultMessage: 'Account',
|
||||
|
||||
@@ -13,9 +13,11 @@ This slot is used to replace/modify/hide the desktop main menu.
|
||||
|
||||
### Modify Items
|
||||
|
||||
The following `env.config.jsx` will modify the items in the desktop main menu.
|
||||
#### Replace All Items
|
||||
|
||||

|
||||
The following `env.config.jsx` will replace all items in the desktop main menu.
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
@@ -59,6 +61,58 @@ const config = {
|
||||
export default config;
|
||||
```
|
||||
|
||||
#### Add Items
|
||||
|
||||
The following `env.config.jsx` will add items in the desktop main menu.
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const modifyMainMenu = (widget) => {
|
||||
const existingMenu = widget.RenderWidget.props.menu || [];
|
||||
|
||||
const newMarketingLinks = [
|
||||
{
|
||||
type: 'item',
|
||||
href: 'https://example.com/how-it-works',
|
||||
content: 'How it works',
|
||||
},
|
||||
{
|
||||
type: 'item',
|
||||
href: 'https://example.com/courses',
|
||||
content: 'Courses',
|
||||
},
|
||||
{
|
||||
type: 'item',
|
||||
href: 'https://example.com/schools',
|
||||
content: 'Schools',
|
||||
}
|
||||
];
|
||||
|
||||
widget.content.menu = [...existingMenu, ...newMarketingLinks];
|
||||
return widget;
|
||||
};
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_desktop_main_menu.v1': {
|
||||
keepDefault: true,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Modify,
|
||||
widgetId: 'default_contents',
|
||||
fn: modifyMainMenu,
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Replace Menu with Custom Component
|
||||
|
||||
The following `env.config.jsx` will replace the desktop main menu entirely (in this case with a centered 🗺️ `h1`)
|
||||
@@ -134,4 +188,3 @@ const config = {
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
|
||||
|
After Width: | Height: | Size: 5.0 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
@@ -13,9 +13,11 @@ This slot is used to replace/modify/hide the mobile main menu.
|
||||
|
||||
### Modify Items
|
||||
|
||||
The following `env.config.jsx` will modify the items in the mobile main menu.
|
||||
#### Replace All Items
|
||||
|
||||

|
||||
The following `env.config.jsx` will replace all items in the mobile main menu.
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
@@ -59,6 +61,58 @@ const config = {
|
||||
export default config;
|
||||
```
|
||||
|
||||
#### Add Items
|
||||
|
||||
The following `env.config.jsx` will add items in the mobile main menu.
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import { PLUGIN_OPERATIONS } from '@openedx/frontend-plugin-framework';
|
||||
|
||||
const modifyMainMenu = (widget) => {
|
||||
const existingMenu = widget.RenderWidget.props.menu || [];
|
||||
|
||||
const newMarketingLinks = [
|
||||
{
|
||||
type: 'item',
|
||||
href: 'https://example.com/how-it-works',
|
||||
content: 'How it works',
|
||||
},
|
||||
{
|
||||
type: 'item',
|
||||
href: 'https://example.com/courses',
|
||||
content: 'Courses',
|
||||
},
|
||||
{
|
||||
type: 'item',
|
||||
href: 'https://example.com/schools',
|
||||
content: 'Schools',
|
||||
}
|
||||
];
|
||||
|
||||
widget.content.menu = [...existingMenu, ...newMarketingLinks];
|
||||
return widget;
|
||||
};
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
'org.openedx.frontend.layout.header_mobile_main_menu.v1': {
|
||||
keepDefault: true,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Modify,
|
||||
widgetId: 'default_contents',
|
||||
fn: modifyMainMenu,
|
||||
},
|
||||
]
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Replace Menu with Custom Component
|
||||
|
||||
The following `env.config.jsx` will replace the mobile main menu entirely (in this case with a centered 🗺️ `h1`)
|
||||
|
||||
|
After Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 9.0 KiB After Width: | Height: | Size: 9.0 KiB |
@@ -24,3 +24,6 @@
|
||||
* [`org.openedx.frontend.layout.header_mobile_main_menu.v1`](./MobileMainMenuSlot/)
|
||||
* [`org.openedx.frontend.layout.header_mobile_user_menu.v1`](./MobileUserMenuSlot/)
|
||||
* [`org.openedx.frontend.layout.header_mobile_user_menu_trigger.v1`](./MobileUserMenuToggleSlot/)
|
||||
|
||||
### Studio Header
|
||||
* [`org.openedx.frontend.layout.studio_header_search_button_slot.v1`](./StudioHeaderSearchButtonSlot/)
|
||||
|
||||
89
src/plugin-slots/StudioHeaderSearchButtonSlot/README.md
Normal file
@@ -0,0 +1,89 @@
|
||||
# Studio Header Search Button Slot
|
||||
|
||||
### Slot ID: `org.openedx.frontend.layout.studio_header_search_button_slot.v1`
|
||||
|
||||
## Description
|
||||
|
||||
This slot is used to replace/modify/hide the search button in the studio header.
|
||||
|
||||
## Examples
|
||||
|
||||
### Replace search with custom component
|
||||
|
||||
The following `env.config.jsx` will replace the search button entirely (in this case with a custom emoji icon):
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import {
|
||||
DIRECT_PLUGIN,
|
||||
PLUGIN_OPERATIONS,
|
||||
} from "@openedx/frontend-plugin-framework";
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
"org.openedx.frontend.layout.studio_header_search_button_slot.v1": {
|
||||
keepDefault: false,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
id: "custom_notification_tray",
|
||||
type: DIRECT_PLUGIN,
|
||||
RenderWidget: () => <span>🔔</span>,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
### Add custom component before and after search button
|
||||
|
||||
The following `env.config.jsx` will insert emoji after and before the search button
|
||||
|
||||

|
||||
|
||||
```jsx
|
||||
import {
|
||||
DIRECT_PLUGIN,
|
||||
PLUGIN_OPERATIONS,
|
||||
} from "@openedx/frontend-plugin-framework";
|
||||
|
||||
const config = {
|
||||
pluginSlots: {
|
||||
"org.openedx.frontend.layout.studio_header_search_button_slot.v1": {
|
||||
keepDefault: true,
|
||||
plugins: [
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
priority: 10,
|
||||
id: 'custom_notification_tray_before',
|
||||
type: DIRECT_PLUGIN,
|
||||
RenderWidget: () => <span>🔔</span>,
|
||||
},
|
||||
},
|
||||
{
|
||||
op: PLUGIN_OPERATIONS.Insert,
|
||||
widget: {
|
||||
priority: 90,
|
||||
id: 'custom_notification_tray_after',
|
||||
type: DIRECT_PLUGIN,
|
||||
RenderWidget: () => <span>🔕</span>,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
export default config;
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
- **Slot ID:** `org.openedx.frontend.layout.studio_header_search_button_slot.v1`
|
||||
- **Component:** Uses the [PluginSlot](https://github.com/openedx/frontend-plugin-framework#pluginslot) from the Open edX Frontend Plugin Framework for plugin injection.
|
||||
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 10 KiB |
34
src/plugin-slots/StudioHeaderSearchButtonSlot/index.jsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import React from 'react';
|
||||
import { PluginSlot } from '@openedx/frontend-plugin-framework';
|
||||
import { Nav, IconButton, Icon } from '@openedx/paragon';
|
||||
import { Search } from '@openedx/paragon/icons';
|
||||
import PropTypes from 'prop-types';
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
import messages from '../../studio-header/messages';
|
||||
|
||||
const StudioHeaderSearchButtonSlot = ({ searchButtonAction }) => {
|
||||
const intl = useIntl();
|
||||
return (
|
||||
<PluginSlot
|
||||
id="org.openedx.frontend.layout.studio_header_search_button_slot.v1"
|
||||
>
|
||||
{searchButtonAction && (
|
||||
<Nav>
|
||||
<IconButton
|
||||
src={Search}
|
||||
iconAs={Icon}
|
||||
onClick={searchButtonAction}
|
||||
aria-label={intl.formatMessage(messages['header.label.search.nav'])}
|
||||
alt={intl.formatMessage(messages['header.label.search.nav'])}
|
||||
/>
|
||||
</Nav>
|
||||
)}
|
||||
</PluginSlot>
|
||||
);
|
||||
};
|
||||
|
||||
StudioHeaderSearchButtonSlot.propTypes = {
|
||||
searchButtonAction: PropTypes.func,
|
||||
};
|
||||
|
||||
export default StudioHeaderSearchButtonSlot;
|
||||
@@ -1,8 +1,13 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { type FunctionComponent } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
const BrandNav = ({
|
||||
interface Props {
|
||||
studioBaseUrl: string;
|
||||
logo: string;
|
||||
logoAltText: string;
|
||||
}
|
||||
|
||||
const BrandNav: FunctionComponent<Props> = ({
|
||||
studioBaseUrl,
|
||||
logo,
|
||||
logoAltText,
|
||||
@@ -16,10 +21,4 @@ const BrandNav = ({
|
||||
</Link>
|
||||
);
|
||||
|
||||
BrandNav.propTypes = {
|
||||
studioBaseUrl: PropTypes.string.isRequired,
|
||||
logo: PropTypes.string.isRequired,
|
||||
logoAltText: PropTypes.string.isRequired,
|
||||
};
|
||||
|
||||
export default BrandNav;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { type FunctionComponent } from 'react';
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
import {
|
||||
OverlayTrigger,
|
||||
@@ -9,14 +8,19 @@ import { Link } from 'react-router-dom';
|
||||
|
||||
import messages from './messages';
|
||||
|
||||
const CourseLockUp = (
|
||||
{
|
||||
outlineLink,
|
||||
org,
|
||||
number,
|
||||
title,
|
||||
},
|
||||
) => {
|
||||
interface Props {
|
||||
outlineLink?: string;
|
||||
org?: string;
|
||||
number?: string;
|
||||
title?: string;
|
||||
}
|
||||
|
||||
const CourseLockUp: FunctionComponent<Props> = ({
|
||||
outlineLink = '',
|
||||
org = '',
|
||||
number = '',
|
||||
title = '',
|
||||
}) => {
|
||||
const intl = useIntl();
|
||||
|
||||
return (
|
||||
@@ -41,18 +45,4 @@ const CourseLockUp = (
|
||||
);
|
||||
};
|
||||
|
||||
CourseLockUp.propTypes = {
|
||||
number: PropTypes.string,
|
||||
org: PropTypes.string,
|
||||
title: PropTypes.string,
|
||||
outlineLink: PropTypes.string,
|
||||
};
|
||||
|
||||
CourseLockUp.defaultProps = {
|
||||
number: null,
|
||||
org: null,
|
||||
title: null,
|
||||
outlineLink: null,
|
||||
};
|
||||
|
||||
export default CourseLockUp;
|
||||
|
||||
@@ -1,23 +1,45 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import { useIntl } from '@edx/frontend-platform/i18n';
|
||||
import React, { type ReactNode, type ComponentProps } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import {
|
||||
ActionRow,
|
||||
Button,
|
||||
Container,
|
||||
Icon,
|
||||
IconButton,
|
||||
Nav,
|
||||
Row,
|
||||
} from '@openedx/paragon';
|
||||
import { Close, MenuIcon, Search } from '@openedx/paragon/icons';
|
||||
import { Close, MenuIcon } from '@openedx/paragon/icons';
|
||||
|
||||
import CourseLockUp from './CourseLockUp';
|
||||
import UserMenu from './UserMenu';
|
||||
import BrandNav from './BrandNav';
|
||||
import NavDropdownMenu from './NavDropdownMenu';
|
||||
import messages from './messages';
|
||||
import StudioHeaderSearchButtonSlot from '../plugin-slots/StudioHeaderSearchButtonSlot';
|
||||
|
||||
export interface HeaderBodyProps {
|
||||
studioBaseUrl: string;
|
||||
logoutUrl: string;
|
||||
setModalPopupTarget?: ((instance: HTMLButtonElement | null) => void) | null;
|
||||
toggleModalPopup?: React.MouseEventHandler<HTMLButtonElement>;
|
||||
isModalPopupOpen?: boolean;
|
||||
number?: string;
|
||||
org?: string;
|
||||
title: string;
|
||||
logo: string;
|
||||
logoAltText: string;
|
||||
authenticatedUserAvatar?: string;
|
||||
username?: string;
|
||||
isAdmin?: boolean;
|
||||
isMobile?: boolean;
|
||||
isHiddenMainMenu?: boolean;
|
||||
mainMenuDropdowns?: {
|
||||
id: string;
|
||||
buttonTitle: ReactNode;
|
||||
items: { title: ReactNode; href: string; }[];
|
||||
}[];
|
||||
outlineLink?: string;
|
||||
searchButtonAction?: React.MouseEventHandler<HTMLButtonElement>;
|
||||
containerProps?: Omit<ComponentProps<typeof Container>, 'children'>;
|
||||
}
|
||||
|
||||
const HeaderBody = ({
|
||||
logo,
|
||||
@@ -31,16 +53,15 @@ const HeaderBody = ({
|
||||
logoutUrl,
|
||||
authenticatedUserAvatar,
|
||||
isMobile,
|
||||
setModalPopupTarget,
|
||||
setModalPopupTarget = null,
|
||||
toggleModalPopup,
|
||||
isModalPopupOpen,
|
||||
isHiddenMainMenu,
|
||||
mainMenuDropdowns,
|
||||
isModalPopupOpen = false,
|
||||
isHiddenMainMenu = false,
|
||||
mainMenuDropdowns = [],
|
||||
outlineLink,
|
||||
searchButtonAction,
|
||||
containerProps,
|
||||
}) => {
|
||||
const intl = useIntl();
|
||||
containerProps = {},
|
||||
}: HeaderBodyProps) => {
|
||||
|
||||
const renderBrandNav = (
|
||||
<BrandNav
|
||||
@@ -52,7 +73,7 @@ const HeaderBody = ({
|
||||
/>
|
||||
);
|
||||
|
||||
const { className: containerClassName, ...restContainerProps } = containerProps || {};
|
||||
const { className: containerClassName, ...restContainerProps } = containerProps;
|
||||
|
||||
return (
|
||||
<Container
|
||||
@@ -116,17 +137,9 @@ const HeaderBody = ({
|
||||
</>
|
||||
)}
|
||||
<ActionRow.Spacer />
|
||||
{searchButtonAction && (
|
||||
<Nav>
|
||||
<IconButton
|
||||
src={Search}
|
||||
iconAs={Icon}
|
||||
onClick={searchButtonAction}
|
||||
aria-label={intl.formatMessage(messages['header.label.search.nav'])}
|
||||
alt={intl.formatMessage(messages['header.label.search.nav'])}
|
||||
/>
|
||||
</Nav>
|
||||
)}
|
||||
<StudioHeaderSearchButtonSlot
|
||||
searchButtonAction={searchButtonAction}
|
||||
/>
|
||||
<Nav>
|
||||
<UserMenu
|
||||
{...{
|
||||
@@ -144,53 +157,4 @@ const HeaderBody = ({
|
||||
);
|
||||
};
|
||||
|
||||
HeaderBody.propTypes = {
|
||||
studioBaseUrl: PropTypes.string.isRequired,
|
||||
logoutUrl: PropTypes.string.isRequired,
|
||||
setModalPopupTarget: PropTypes.func,
|
||||
toggleModalPopup: PropTypes.func,
|
||||
isModalPopupOpen: PropTypes.bool,
|
||||
number: PropTypes.string,
|
||||
org: PropTypes.string,
|
||||
title: PropTypes.string,
|
||||
logo: PropTypes.string,
|
||||
logoAltText: PropTypes.string,
|
||||
authenticatedUserAvatar: PropTypes.string,
|
||||
username: PropTypes.string,
|
||||
isAdmin: PropTypes.bool,
|
||||
isMobile: PropTypes.bool,
|
||||
isHiddenMainMenu: PropTypes.bool,
|
||||
mainMenuDropdowns: PropTypes.arrayOf(PropTypes.shape({
|
||||
id: PropTypes.string,
|
||||
buttonTitle: PropTypes.node,
|
||||
items: PropTypes.arrayOf(PropTypes.shape({
|
||||
href: PropTypes.string,
|
||||
title: PropTypes.node,
|
||||
})),
|
||||
})),
|
||||
outlineLink: PropTypes.string,
|
||||
searchButtonAction: PropTypes.func,
|
||||
containerProps: PropTypes.shape(Container.propTypes),
|
||||
};
|
||||
|
||||
HeaderBody.defaultProps = {
|
||||
setModalPopupTarget: null,
|
||||
toggleModalPopup: null,
|
||||
isModalPopupOpen: false,
|
||||
logo: null,
|
||||
logoAltText: null,
|
||||
number: '',
|
||||
org: '',
|
||||
title: '',
|
||||
authenticatedUserAvatar: null,
|
||||
username: null,
|
||||
isAdmin: false,
|
||||
isMobile: false,
|
||||
isHiddenMainMenu: false,
|
||||
mainMenuDropdowns: [],
|
||||
outlineLink: null,
|
||||
searchButtonAction: null,
|
||||
containerProps: {},
|
||||
};
|
||||
|
||||
export default HeaderBody;
|
||||
|
||||
@@ -1,19 +1,32 @@
|
||||
import React, { useState } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { type FunctionComponent, useState } from 'react';
|
||||
import { useToggle, ModalPopup } from '@openedx/paragon';
|
||||
import HeaderBody from './HeaderBody';
|
||||
import HeaderBody, { type HeaderBodyProps } from './HeaderBody';
|
||||
import MobileMenu from './MobileMenu';
|
||||
|
||||
const MobileHeader = ({
|
||||
type Props = Pick<HeaderBodyProps,
|
||||
| 'studioBaseUrl'
|
||||
| 'logoutUrl'
|
||||
| 'number'
|
||||
| 'org'
|
||||
| 'title'
|
||||
| 'logo'
|
||||
| 'logoAltText'
|
||||
| 'authenticatedUserAvatar'
|
||||
| 'username'
|
||||
| 'isAdmin'
|
||||
| 'mainMenuDropdowns'
|
||||
| 'outlineLink'
|
||||
>;
|
||||
|
||||
const MobileHeader: FunctionComponent<Props> = ({
|
||||
mainMenuDropdowns,
|
||||
...props
|
||||
}) => {
|
||||
const [isOpen, , close, toggle] = useToggle(false);
|
||||
const [target, setTarget] = useState(null);
|
||||
const [target, setTarget] = useState<HTMLButtonElement | null>(null);
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* @ts-expect-error The type of 'props' is any until we convert from propTypes to TypeScript interface/types */}
|
||||
<HeaderBody
|
||||
{...props}
|
||||
isMobile
|
||||
@@ -36,39 +49,4 @@ const MobileHeader = ({
|
||||
);
|
||||
};
|
||||
|
||||
MobileHeader.propTypes = {
|
||||
studioBaseUrl: PropTypes.string.isRequired, // eslint-disable-line react/no-unused-prop-types
|
||||
logoutUrl: PropTypes.string.isRequired, // eslint-disable-line react/no-unused-prop-types
|
||||
number: PropTypes.string, // eslint-disable-line react/no-unused-prop-types
|
||||
org: PropTypes.string, // eslint-disable-line react/no-unused-prop-types
|
||||
title: PropTypes.string, // eslint-disable-line react/no-unused-prop-types
|
||||
logo: PropTypes.string, // eslint-disable-line react/no-unused-prop-types
|
||||
logoAltText: PropTypes.string, // eslint-disable-line react/no-unused-prop-types
|
||||
authenticatedUserAvatar: PropTypes.string, // eslint-disable-line react/no-unused-prop-types
|
||||
username: PropTypes.string, // eslint-disable-line react/no-unused-prop-types
|
||||
isAdmin: PropTypes.bool, // eslint-disable-line react/no-unused-prop-types
|
||||
mainMenuDropdowns: PropTypes.arrayOf(PropTypes.shape({
|
||||
id: PropTypes.string,
|
||||
buttonTitle: PropTypes.node,
|
||||
items: PropTypes.arrayOf(PropTypes.shape({
|
||||
href: PropTypes.string,
|
||||
title: PropTypes.node,
|
||||
})),
|
||||
})),
|
||||
outlineLink: PropTypes.string, // eslint-disable-line react/no-unused-prop-types
|
||||
};
|
||||
|
||||
MobileHeader.defaultProps = {
|
||||
logo: null,
|
||||
logoAltText: null,
|
||||
number: null,
|
||||
org: null,
|
||||
title: null,
|
||||
authenticatedUserAvatar: null,
|
||||
username: null,
|
||||
isAdmin: false,
|
||||
mainMenuDropdowns: [],
|
||||
outlineLink: null,
|
||||
};
|
||||
|
||||
export default MobileHeader;
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { type ReactNode } from 'react';
|
||||
import {
|
||||
Dropdown,
|
||||
DropdownButton,
|
||||
} from '@openedx/paragon';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
interface Props {
|
||||
id: string;
|
||||
buttonTitle: ReactNode;
|
||||
items: { title: ReactNode; href: string; }[];
|
||||
}
|
||||
|
||||
const NavDropdownMenu = ({
|
||||
id,
|
||||
buttonTitle,
|
||||
items,
|
||||
}) => (
|
||||
}: Props) => (
|
||||
<DropdownButton
|
||||
id={id}
|
||||
title={buttonTitle}
|
||||
@@ -30,13 +35,4 @@ const NavDropdownMenu = ({
|
||||
</DropdownButton>
|
||||
);
|
||||
|
||||
NavDropdownMenu.propTypes = {
|
||||
id: PropTypes.string.isRequired,
|
||||
buttonTitle: PropTypes.node.isRequired,
|
||||
items: PropTypes.arrayOf(PropTypes.shape({
|
||||
href: PropTypes.string.isRequired,
|
||||
title: PropTypes.node.isRequired,
|
||||
})).isRequired,
|
||||
};
|
||||
|
||||
export default NavDropdownMenu;
|
||||
|
||||
@@ -12,7 +12,6 @@ import { Context as ResponsiveContext } from 'react-responsive';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
|
||||
import StudioHeader from './StudioHeader';
|
||||
import messages from './messages';
|
||||
|
||||
const authenticatedUser = {
|
||||
userId: 3,
|
||||
@@ -72,12 +71,8 @@ const props: React.ComponentProps<typeof StudioHeader> = {
|
||||
},
|
||||
],
|
||||
outlineLink: 'tEsTLInK',
|
||||
searchButtonAction: null,
|
||||
searchButtonAction: undefined,
|
||||
isNewHomePage: true,
|
||||
// These default values shouldn't be needed but typescript is confused by propTypes; can remove after converting
|
||||
// from propTypes to TypeScript:
|
||||
containerProps: {},
|
||||
isHiddenMainMenu: false,
|
||||
};
|
||||
|
||||
describe('Header', () => {
|
||||
@@ -119,16 +114,6 @@ describe('Header', () => {
|
||||
expect(dropdownOption).toBeVisible();
|
||||
});
|
||||
|
||||
it('maintenance should not be in user menu', async () => {
|
||||
currentUser = { ...authenticatedUser, administrator: false };
|
||||
const { getAllByRole, queryByText } = render(<RootWrapper {...props} />);
|
||||
const userMenu = getAllByRole('button')[1];
|
||||
await waitFor(() => fireEvent.click(userMenu));
|
||||
const maintenanceButton = queryByText(messages['header.user.menu.maintenance'].defaultMessage);
|
||||
|
||||
expect(maintenanceButton).toBeNull();
|
||||
});
|
||||
|
||||
it('user menu should use avatar icon', async () => {
|
||||
currentUser = { ...authenticatedUser, avatar: null };
|
||||
const { getByTestId } = render(<RootWrapper {...props} />);
|
||||
@@ -157,7 +142,7 @@ describe('Header', () => {
|
||||
});
|
||||
|
||||
it('should not show search button', async () => {
|
||||
const testProps = { ...props, searchButtonAction: null };
|
||||
const testProps = { ...props, searchButtonAction: undefined };
|
||||
const { queryByRole } = render(<RootWrapper {...testProps} />);
|
||||
expect(queryByRole('button', { name: 'Search content' })).not.toBeInTheDocument();
|
||||
});
|
||||
@@ -190,15 +175,6 @@ describe('Header', () => {
|
||||
expect(desktopMenu).toBeNull();
|
||||
});
|
||||
|
||||
it('maintenance should be in user menu', async () => {
|
||||
const { getAllByRole, getByText } = render(<RootWrapper {...props} />);
|
||||
const userMenu = getAllByRole('button')[1];
|
||||
await waitFor(() => fireEvent.click(userMenu));
|
||||
const maintenanceButton = getByText(messages['header.user.menu.maintenance'].defaultMessage);
|
||||
|
||||
expect(maintenanceButton).toBeVisible();
|
||||
});
|
||||
|
||||
it('user menu should use avatar image', async () => {
|
||||
const { getByTestId } = render(<RootWrapper {...props} />);
|
||||
const avatarImage = getByTestId('avatar-image');
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import React, { useContext } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import React, { type FunctionComponent, useContext } from 'react';
|
||||
import Responsive from 'react-responsive';
|
||||
import { AppContext } from '@edx/frontend-platform/react';
|
||||
import { ensureConfig } from '@edx/frontend-platform';
|
||||
|
||||
import MobileHeader from './MobileHeader';
|
||||
import HeaderBody from './HeaderBody';
|
||||
import HeaderBody, { HeaderBodyProps } from './HeaderBody';
|
||||
|
||||
ensureConfig([
|
||||
'STUDIO_BASE_URL',
|
||||
@@ -15,9 +14,29 @@ ensureConfig([
|
||||
'LOGO_URL',
|
||||
], 'Studio Header component');
|
||||
|
||||
const StudioHeader = ({
|
||||
number, org, title, containerProps, isHiddenMainMenu, mainMenuDropdowns,
|
||||
outlineLink, searchButtonAction, isNewHomePage,
|
||||
type Props = Pick<HeaderBodyProps,
|
||||
| 'number'
|
||||
| 'org'
|
||||
| 'title'
|
||||
| 'containerProps'
|
||||
| 'isHiddenMainMenu'
|
||||
| 'mainMenuDropdowns'
|
||||
| 'outlineLink'
|
||||
| 'searchButtonAction'
|
||||
> & {
|
||||
isNewHomePage: boolean;
|
||||
};
|
||||
|
||||
const StudioHeader: FunctionComponent<Props> = ({
|
||||
number,
|
||||
org,
|
||||
title,
|
||||
containerProps,
|
||||
isHiddenMainMenu,
|
||||
mainMenuDropdowns,
|
||||
outlineLink,
|
||||
searchButtonAction,
|
||||
isNewHomePage,
|
||||
}) => {
|
||||
// @ts-expect-error - frontend-platform doesn't yet have type information :/
|
||||
const { authenticatedUser, config } = useContext(AppContext);
|
||||
@@ -52,33 +71,4 @@ const StudioHeader = ({
|
||||
);
|
||||
};
|
||||
|
||||
StudioHeader.propTypes = {
|
||||
number: PropTypes.string,
|
||||
org: PropTypes.string,
|
||||
title: PropTypes.string.isRequired,
|
||||
containerProps: HeaderBody.propTypes.containerProps,
|
||||
isHiddenMainMenu: PropTypes.bool,
|
||||
mainMenuDropdowns: PropTypes.arrayOf(PropTypes.shape({
|
||||
id: PropTypes.string,
|
||||
buttonTitle: PropTypes.node,
|
||||
items: PropTypes.arrayOf(PropTypes.shape({
|
||||
href: PropTypes.string,
|
||||
title: PropTypes.node,
|
||||
})),
|
||||
})),
|
||||
outlineLink: PropTypes.string,
|
||||
searchButtonAction: PropTypes.func,
|
||||
isNewHomePage: PropTypes.bool.isRequired,
|
||||
};
|
||||
|
||||
StudioHeader.defaultProps = {
|
||||
number: '',
|
||||
org: '',
|
||||
containerProps: {},
|
||||
isHiddenMainMenu: false,
|
||||
mainMenuDropdowns: [],
|
||||
outlineLink: null,
|
||||
searchButtonAction: null,
|
||||
};
|
||||
|
||||
export default StudioHeader;
|
||||
|
||||
@@ -6,11 +6,6 @@ const messages = defineMessages({
|
||||
defaultMessage: 'Studio Home',
|
||||
description: 'Link to Studio Home',
|
||||
},
|
||||
'header.user.menu.maintenance': {
|
||||
id: 'header.user.menu.maintenance',
|
||||
defaultMessage: 'Maintenance',
|
||||
description: 'Link to the Studio maintenance page',
|
||||
},
|
||||
'header.user.menu.logout': {
|
||||
id: 'header.user.menu.logout',
|
||||
defaultMessage: 'Logout',
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { getConfig } from '@edx/frontend-platform';
|
||||
import messages from './messages';
|
||||
|
||||
const getUserMenuItems = ({
|
||||
@@ -21,9 +20,6 @@ const getUserMenuItems = ({
|
||||
{
|
||||
href: `${studioBaseUrl}`,
|
||||
title: intl.formatMessage(messages['header.user.menu.studio']),
|
||||
}, {
|
||||
href: `${getConfig().STUDIO_BASE_URL}/maintenance`,
|
||||
title: intl.formatMessage(messages['header.user.menu.maintenance']),
|
||||
}, {
|
||||
href: `${logoutUrl}`,
|
||||
title: intl.formatMessage(messages['header.user.menu.logout']),
|
||||
|
||||