Skip to content

Commit 92c3a98

Browse files
authored
fix: show/hide add unit button based on childAddable flag of parent in unit page (#2351)
Course unit page shows Add Unit option without checking whether the parent subsection allows adding children. This fixes it.
1 parent 0e1550a commit 92c3a98

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/course-unit/CourseUnit.test.jsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,28 @@ describe('<CourseUnit />', () => {
792792
.toHaveBeenCalledWith(`/course/${courseId}/container/${blockId}/${updatedAncestorsChild.id}`, { replace: true });
793793
});
794794

795+
it('Show or hide new unit button based on parent sequence childAddable action', async () => {
796+
render(<RootWrapper />);
797+
// The new unit button should be visible when childAddable is true
798+
await screen.findByRole('button', { name: courseSequenceMessages.newUnitBtnText.defaultMessage });
799+
800+
const updatedCourseSectionVerticalData = cloneDeep(courseSectionVerticalMock);
801+
// Set childAddable to false for sequence i.e. current units parent.
802+
set(updatedCourseSectionVerticalData, 'xblock_info.ancestor_info.ancestors[0].actions.childAddable', false);
803+
axiosMock
804+
.onGet(getCourseSectionVerticalApiUrl(blockId))
805+
.reply(200, {
806+
...updatedCourseSectionVerticalData,
807+
});
808+
render(<RootWrapper />);
809+
// to wait for loading
810+
screen.findByTestId('unit-header-title');
811+
// The new unit button should not be visible when childAddable is false
812+
expect(
813+
screen.queryByRole('button', { name: courseSequenceMessages.newUnitBtnText.defaultMessage }),
814+
).not.toBeInTheDocument();
815+
});
816+
795817
it('the sequence unit is updated after changing the unit header', async () => {
796818
const user = userEvent.setup();
797819
render(<RootWrapper />);

src/course-unit/course-sequence/sequence-navigation/SequenceNavigationTabs.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Plus as PlusIcon, ContentPasteGo as ContentPasteGoIcon } from '@openedx
66
import { useIntl } from '@edx/frontend-platform/i18n';
77

88
import { changeEditTitleFormOpen, updateQueryPendingStatus } from '../../data/slice';
9-
import { getCourseId, getSequenceId } from '../../data/selectors';
9+
import { getCourseUnitData, getCourseId, getSequenceId } from '../../data/selectors';
1010
import messages from '../messages';
1111
import { useIndexOfLastVisibleChild } from '../hooks';
1212
import SequenceNavigationDropdown from './SequenceNavigationDropdown';
@@ -20,6 +20,8 @@ const SequenceNavigationTabs = ({
2020
const navigate = useNavigate();
2121
const sequenceId = useSelector(getSequenceId);
2222
const courseId = useSelector(getCourseId);
23+
const courseUnit = useSelector(getCourseUnitData);
24+
const sequenceChildAddable = courseUnit?.ancestorInfo?.ancestors?.[0]?.actions?.childAddable;
2325

2426
const [
2527
indexOfLastVisibleChild,
@@ -58,6 +60,7 @@ const SequenceNavigationTabs = ({
5860
isActive={unitId === buttonUnitId}
5961
/>
6062
))}
63+
{sequenceChildAddable && (
6164
<Button
6265
className="sequence-navigation-tabs-action-btn"
6366
variant="outline-primary"
@@ -66,6 +69,7 @@ const SequenceNavigationTabs = ({
6669
>
6770
{intl.formatMessage(messages.newUnitBtnText)}
6871
</Button>
72+
)}
6973
{showPasteUnit && (
7074
<Button
7175
className="sequence-navigation-tabs-action-btn"

0 commit comments

Comments
 (0)