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: expose containerProps in StudioHeader [FC-0062] #529

1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"@openedx/frontend-plugin-framework": "^1.3.0",
"axios-mock-adapter": "1.22.0",
"babel-polyfill": "6.26.0",
"classnames": "^2.5.1",
"jest-environment-jsdom": "^29.7.0",
"react-responsive": "8.2.0",
"react-transition-group": "4.4.5"
Expand Down
17 changes: 14 additions & 3 deletions src/studio-header/HeaderBody.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { useIntl } from '@edx/frontend-platform/i18n';
import classNames from 'classnames';
import {
ActionRow,
Button,
Expand Down Expand Up @@ -37,6 +38,7 @@ const HeaderBody = ({
mainMenuDropdowns,
outlineLink,
searchButtonAction,
containerProps,
}) => {
const intl = useIntl();

Expand All @@ -50,8 +52,14 @@ const HeaderBody = ({
/>
);

const { className: containerClassName, ...restContainerProps } = containerProps || {};

return (
<Container size="xl" className="px-2.5">
<Container
size="xl"
className={classNames('px-2.5', containerClassName)}
{...restContainerProps}
>
<ActionRow as="header">
{isHiddenMainMenu ? (
<Row className="flex-nowrap ml-4">
Expand Down Expand Up @@ -110,6 +118,7 @@ const HeaderBody = ({
iconAs={Icon}
onClick={searchButtonAction}
aria-label={intl.formatMessage(messages['header.label.search.nav'])}
alt={intl.formatMessage(messages['header.label.search.nav'])}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not related to this feature. This is a fly-by fix of a console warning. Let me know if I should create a different PR for this.

Choose a reason for hiding this comment

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

Thanks for fixing these! Fewer warnings is always good.

/>
</Nav>
)}
Expand Down Expand Up @@ -147,14 +156,15 @@ HeaderBody.propTypes = {
isHiddenMainMenu: PropTypes.bool,
mainMenuDropdowns: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.string,
buttonTitle: PropTypes.string,
buttonTitle: PropTypes.node,
items: PropTypes.arrayOf(PropTypes.shape({
href: PropTypes.string,
title: PropTypes.string,
title: PropTypes.node,
})),
})),
outlineLink: PropTypes.string,
searchButtonAction: PropTypes.func,
containerProps: PropTypes.shape(Container.propTypes),
};

HeaderBody.defaultProps = {
Expand All @@ -174,6 +184,7 @@ HeaderBody.defaultProps = {
mainMenuDropdowns: [],
outlineLink: null,
searchButtonAction: null,
containerProps: {},
};

export default HeaderBody;
4 changes: 2 additions & 2 deletions src/studio-header/MobileHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ MobileHeader.propTypes = {
isAdmin: PropTypes.bool,
mainMenuDropdowns: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.string,
buttonTitle: PropTypes.string,
buttonTitle: PropTypes.node,
items: PropTypes.arrayOf(PropTypes.shape({
href: PropTypes.string,
title: PropTypes.string,
title: PropTypes.node,
})),
})),
outlineLink: PropTypes.string,
Expand Down
4 changes: 2 additions & 2 deletions src/studio-header/MobileMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ const MobileMenu = ({
MobileMenu.propTypes = {
mainMenuDropdowns: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.string,
buttonTitle: PropTypes.string,
buttonTitle: PropTypes.node,
items: PropTypes.arrayOf(PropTypes.shape({
href: PropTypes.string,
title: PropTypes.string,
title: PropTypes.node,
})),
})),
};
Expand Down
4 changes: 2 additions & 2 deletions src/studio-header/NavDropdownMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ const NavDropdownMenu = ({

NavDropdownMenu.propTypes = {
id: PropTypes.string.isRequired,
buttonTitle: PropTypes.string.isRequired,
buttonTitle: PropTypes.node.isRequired,
Copy link
Contributor Author

@rpenido rpenido Sep 5, 2024

Choose a reason for hiding this comment

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

Not related to this feature. This is a fly-by fix of a console warning. Let me know if I should create a different PR for this.

Copy link
Member

Choose a reason for hiding this comment

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

[clarification/suggestion] If we make the change here, should we also ensure all other prop type definitions for buttonTitle reflect PropTypes.node, too?

For example, here and here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed other places here: 06bfcc7

items: PropTypes.arrayOf(PropTypes.shape({
href: PropTypes.string,
title: PropTypes.string,
title: PropTypes.node,
})).isRequired,
};

Expand Down
9 changes: 6 additions & 3 deletions src/studio-header/StudioHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ensureConfig([
], 'Studio Header component');

const StudioHeader = ({
number, org, title, isHiddenMainMenu, mainMenuDropdowns, outlineLink, searchButtonAction,
number, org, title, containerProps, isHiddenMainMenu, mainMenuDropdowns, outlineLink, searchButtonAction,
}) => {
const { authenticatedUser, config } = useContext(AppContext);
const props = {
Expand All @@ -25,6 +25,7 @@ const StudioHeader = ({
number,
org,
title,
containerProps,
username: authenticatedUser?.username,
isAdmin: authenticatedUser?.administrator,
authenticatedUserAvatar: authenticatedUser?.avatar,
Expand Down Expand Up @@ -53,13 +54,14 @@ StudioHeader.propTypes = {
number: PropTypes.string,
org: PropTypes.string,
title: PropTypes.string.isRequired,
containerProps: HeaderBody.propTypes.containerProps,

Choose a reason for hiding this comment

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

containerProps should be optional, and/or populated with a default value below?

Copy link
Contributor Author

@rpenido rpenido Sep 19, 2024

Choose a reason for hiding this comment

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

Fixed here: e2249b2

isHiddenMainMenu: PropTypes.bool,
mainMenuDropdowns: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.string,
buttonTitle: PropTypes.string,
buttonTitle: PropTypes.node,
items: PropTypes.arrayOf(PropTypes.shape({
href: PropTypes.string,
title: PropTypes.string,
title: PropTypes.node,
})),
})),
outlineLink: PropTypes.string,
Expand All @@ -69,6 +71,7 @@ StudioHeader.propTypes = {
StudioHeader.defaultProps = {
number: '',
org: '',
containerProps: {},
isHiddenMainMenu: false,
mainMenuDropdowns: [],
outlineLink: null,
Expand Down