Skip to content

Commit

Permalink
refactor: send MessageForm as child prop to Disclosure component
Browse files Browse the repository at this point in the history
This commit refactors the Disclosure component to receive the MessageForm component as a child prop. This avoids the need to pass the courseId and unitId props through to the Disclosure component, which does not make use of either prop. This decreases the prop drilling and only passes these props through to components that actively use them.
  • Loading branch information
MichaelRoytman committed Jan 4, 2024
1 parent 57f7816 commit 71e11bf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
8 changes: 3 additions & 5 deletions src/components/Disclosure/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import { Hyperlink, Icon } from '@edx/paragon';
import { Chat } from '@edx/paragon/icons';
import { getConfig } from '@edx/frontend-platform/config';

import MessageForm from '../MessageForm';
import './Disclosure.scss';

const Disclosure = ({ courseId, unitId }) => (
const Disclosure = ({ children }) => (
<div className="disclosure d-flex flex-column align-items-stretch px-4 py-3">
<h2 className="text-light-100">
Xpert
Expand Down Expand Up @@ -45,13 +44,12 @@ const Disclosure = ({ courseId, unitId }) => (
</Hyperlink>
.
</p>
<MessageForm courseId={courseId} unitId={unitId} />
{children}
</div>
);

Disclosure.propTypes = {
courseId: PropTypes.string.isRequired,
unitId: PropTypes.string.isRequired,
children: PropTypes.node.isRequired,
};

export default Disclosure;
8 changes: 6 additions & 2 deletions src/components/Sidebar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ const Sidebar = ({
});
};

const getMessageForm = () => (
<MessageForm courseId={courseId} shouldAutofocus unitId={unitId} />
);

const getSidebar = () => (
<div className="h-100 d-flex flex-column justify-content-stretch">
<div className="d-flex flex-column align-items-center p-3">
Expand All @@ -107,7 +111,7 @@ const Sidebar = ({
</div>
)
}
<MessageForm courseId={courseId} shouldAutofocus unitId={unitId} />
{getMessageForm()}
<div className="d-flex justify-content-start">
<Button
className="clear mx-2 mb-2 border-0"
Expand Down Expand Up @@ -137,7 +141,7 @@ const Sidebar = ({
variant="primary"
invertColors={!disclosureAcknowledged}
/>
{disclosureAcknowledged ? (getSidebar()) : (<Disclosure courseId={courseId} unitId={unitId} />)}
{disclosureAcknowledged ? (getSidebar()) : (<Disclosure>{getMessageForm()}</Disclosure>)}
</div>
)
);
Expand Down
1 change: 0 additions & 1 deletion src/widgets/Xpert.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const Xpert = ({ courseId, contentToolsEnabled, unitId }) => {
const setSidebarIsOpen = (isOpen) => {
dispatch(updateSidebarIsOpen(isOpen));
};

return (
<div>
<ToggleXpert
Expand Down

0 comments on commit 71e11bf

Please sign in to comment.