Skip to content

Commit

Permalink
fix: remove isSubsection state, fix css issues and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
steff456 committed Dec 22, 2023
1 parent 89464b5 commit de0d8e5
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 44 deletions.
11 changes: 2 additions & 9 deletions src/course-outline/CourseOutline.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ const CourseOutline = ({ courseId }) => {
handleInternetConnectionFailed,
handleOpenHighlightsModal,
handleHighlightsFormSubmit,
handleConfigureSectionSubmit,
handleConfigureSubsectionSubmit,
handleConfigureSubmit,
handlePublishItemSubmit,
handleEditSubmit,
handleDeleteItemSubmit,
Expand All @@ -90,8 +89,6 @@ const CourseOutline = ({ courseId }) => {
} = useCourseOutline({ courseId });

const [sections, setSections] = useState(sectionsList);
const [isSubsectionConfigure, setIsSubsectionConfigure] = useState(false);

const initialSections = [...sectionsList];

const {
Expand Down Expand Up @@ -198,7 +195,6 @@ const CourseOutline = ({ courseId }) => {
onDuplicateSubmit={handleDuplicateSectionSubmit}
isSectionsExpanded={isSectionsExpanded}
onNewSubsectionSubmit={handleNewSubsectionSubmit}
setIsSubsectionConfigure={setIsSubsectionConfigure}
>
{section.childInfo.children.map((subsection) => (
<SubsectionCard
Expand All @@ -211,7 +207,6 @@ const CourseOutline = ({ courseId }) => {
onEditSubmit={handleEditSubmit}
onDuplicateSubmit={handleDuplicateSubsectionSubmit}
onOpenConfigureModal={openConfigureModal}
setIsSubsectionConfigure={setIsSubsectionConfigure}
/>
))}
</SectionCard>
Expand Down Expand Up @@ -260,9 +255,7 @@ const CourseOutline = ({ courseId }) => {
<ConfigureModal
isOpen={isConfigureModalOpen}
onClose={closeConfigureModal}
onConfigureSubmit={
isSubsectionConfigure ? handleConfigureSubsectionSubmit : handleConfigureSectionSubmit
}
onConfigureSubmit={handleConfigureSubmit}
/>
<DeleteModal
isOpen={isDeleteModalOpen}
Expand Down
15 changes: 7 additions & 8 deletions src/course-outline/CourseOutline.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,9 @@ describe('<CourseOutline />', () => {
findAllByTestId,
findByText,
findAllByPlaceholderText,
getByText,
getByRole,
getAllByRole,
getByTestId,
findAllByRole,
findByRole,
findByTestId,
} = render(<RootWrapper />);
const section = courseOutlineIndexMock.courseStructure.childInfo.children[0];
const subsection = section.childInfo.children[0];
Expand Down Expand Up @@ -562,13 +561,13 @@ describe('<CourseOutline />', () => {
expect(datePicker[0]).toHaveValue('08/10/2025');
expect(datePicker[1]).toHaveValue('09/10/2025');

expect(getByText(newGraderType)).toBeInTheDocument();
const advancedTab = getByRole('tab', { name: configureModalMessages.advancedTabTitle.defaultMessage });
expect(await findByText(newGraderType)).toBeInTheDocument();
const advancedTab = await findByRole('tab', { name: configureModalMessages.advancedTabTitle.defaultMessage });
fireEvent.click(advancedTab);
const radioButtons = await getAllByRole('radio');
const radioButtons = await findAllByRole('radio');
expect(radioButtons[0]).toHaveProperty('checked', false);
expect(radioButtons[1]).toHaveProperty('checked', true);
const hours = await getByTestId('hour-autosuggest');
const hours = await findByTestId('hour-autosuggest');
expect(hours).toHaveValue('03:30');
});

Expand Down
11 changes: 1 addition & 10 deletions src/course-outline/card-header/CardHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import messages from './messages';
const CardHeader = ({
title,
status,
isSubsection,
hasChanges,
isExpanded,
onClickPublish,
Expand All @@ -42,7 +41,6 @@ const CardHeader = ({
onClickDelete,
onClickDuplicate,
namePrefix,
setIsSubsectionConfigure,
}) => {
const intl = useIntl();
const [titleValue, setTitleValue] = useState(title);
Expand All @@ -59,11 +57,6 @@ const CardHeader = ({
dependency: title,
});

const performClickConfigure = () => {
setIsSubsectionConfigure(isSubsection);
onClickConfigure();
};

return (
<div className="item-card-header" data-testid={`${namePrefix}-card-header`}>
{isFormOpen ? (
Expand Down Expand Up @@ -148,7 +141,7 @@ const CardHeader = ({
</Dropdown.Item>
<Dropdown.Item
data-testid={`${namePrefix}-card-header__menu-configure-button`}
onClick={performClickConfigure}
onClick={onClickConfigure}
>
{intl.formatMessage(messages.menuConfigure)}
</Dropdown.Item>
Expand All @@ -174,7 +167,6 @@ const CardHeader = ({
CardHeader.propTypes = {
title: PropTypes.string.isRequired,
status: PropTypes.string.isRequired,
isSubsection: PropTypes.bool.isRequired,
hasChanges: PropTypes.bool.isRequired,
isExpanded: PropTypes.bool.isRequired,
onExpand: PropTypes.func.isRequired,
Expand All @@ -189,7 +181,6 @@ CardHeader.propTypes = {
onClickDelete: PropTypes.func.isRequired,
onClickDuplicate: PropTypes.func.isRequired,
namePrefix: PropTypes.string.isRequired,
setIsSubsectionConfigure: PropTypes.func.isRequired,
};

export default CardHeader;
1 change: 0 additions & 1 deletion src/course-outline/card-header/CardHeader.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const cardHeaderProps = {
onClickDelete: onClickDeleteMock,
onClickDuplicate: onClickDuplicateMock,
namePrefix: 'section',
setIsSubsectionConfigure: jest.fn(),
};

const renderComponent = (props) => render(
Expand Down
2 changes: 1 addition & 1 deletion src/course-outline/configure-modal/BasicTab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const BasicTab = ({
<option value="Not Graded"> Not Graded </option>
{createOptions()}
</Form.Control>
<Stack direction="horizontal" gap={5}>
<Stack className="mt-3" direction="horizontal" gap={5}>
<DatepickerControl
type={DATEPICKER_TYPES.date}
value={dueDate}
Expand Down
2 changes: 1 addition & 1 deletion src/course-outline/configure-modal/ConfigureModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ const ConfigureModal = ({
{intl.formatMessage(messages.title, { title: displayName })}
</ModalDialog.Title>
</ModalDialog.Header>
<ModalDialog.Body className="configure-modal__body">
<ModalDialog.Body className={!isSubsection ? 'configure-modal__body' : ''}>
<Tabs>
<Tab eventKey="basic" title={intl.formatMessage(messages.basicTabTitle)}>
<BasicTab
Expand Down
4 changes: 4 additions & 0 deletions src/course-outline/configure-modal/ConfigureModal.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
padding-top: 1.5rem;
}
}

.configure-modal__body {
overflow: visible;
}
18 changes: 14 additions & 4 deletions src/course-outline/hooks.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ const useCourseOutline = ({ courseId }) => {

const handleConfigureSectionSubmit = (isVisibleToStaffOnly, startDatetime) => {
dispatch(configureCourseSectionQuery(currentSection.id, isVisibleToStaffOnly, startDatetime));

closeConfigureModal();
};

const handleConfigureSubsectionSubmit = (
Expand All @@ -142,6 +140,19 @@ const useCourseOutline = ({ courseId }) => {
hideAfterDueState,
showCorrectnessState,
));
};

const handleConfigureSubmit = (...args) => {
switch (currentItem.category) {
case COURSE_BLOCK_NAMES.chapter.id:
handleConfigureSectionSubmit(...args);
break;
case COURSE_BLOCK_NAMES.sequential.id:
handleConfigureSubsectionSubmit(...args);
break;
default:
return;
}
closeConfigureModal();
};

Expand Down Expand Up @@ -212,8 +223,7 @@ const useCourseOutline = ({ courseId }) => {
headerNavigationsActions,
handleEnableHighlightsSubmit,
handleHighlightsFormSubmit,
handleConfigureSectionSubmit,
handleConfigureSubsectionSubmit,
handleConfigureSubmit,
handlePublishItemSubmit,
handleEditSubmit,
statusBarData,
Expand Down
4 changes: 0 additions & 4 deletions src/course-outline/section-card/SectionCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ const SectionCard = ({
onDuplicateSubmit,
isSectionsExpanded,
onNewSubsectionSubmit,
setIsSubsectionConfigure,
}) => {
const currentRef = useRef(null);
const intl = useIntl();
Expand Down Expand Up @@ -109,8 +108,6 @@ const SectionCard = ({
title={displayName}
status={sectionStatus}
hasChanges={hasChanges}
isSubsection={false}
setIsSubsectionConfigure={setIsSubsectionConfigure}
isExpanded={isExpanded}
onExpand={handleExpandContent}
onClickMenuButton={handleClickMenuButton}
Expand Down Expand Up @@ -185,7 +182,6 @@ SectionCard.propTypes = {
onDuplicateSubmit: PropTypes.func.isRequired,
isSectionsExpanded: PropTypes.bool.isRequired,
onNewSubsectionSubmit: PropTypes.func.isRequired,
setIsSubsectionConfigure: PropTypes.func.isRequired,
};

export default SectionCard;
1 change: 0 additions & 1 deletion src/course-outline/section-card/SectionCard.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const renderComponent = (props) => render(
onDuplicateSubmit={jest.fn()}
isSectionsExpanded
onNewSubsectionSubmit={jest.fn()}
setIsSubsectionConfigure={jest.fn()}
{...props}
>
<span>children</span>
Expand Down
4 changes: 0 additions & 4 deletions src/course-outline/subsection-card/SubsectionCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const SubsectionCard = ({
onOpenDeleteModal,
onDuplicateSubmit,
onOpenConfigureModal,
setIsSubsectionConfigure,
}) => {
const currentRef = useRef(null);
const intl = useIntl();
Expand Down Expand Up @@ -87,7 +86,6 @@ const SubsectionCard = ({
<CardHeader
title={displayName}
status={subsectionStatus}
isSubsection
hasChanges={hasChanges}
isExpanded={isExpanded}
onExpand={handleExpandContent}
Expand All @@ -102,7 +100,6 @@ const SubsectionCard = ({
isDisabledEditField={savingStatus === RequestStatus.IN_PROGRESS}
onClickDuplicate={onDuplicateSubmit}
namePrefix="subsection"
setIsSubsectionConfigure={setIsSubsectionConfigure}
/>
{isExpanded && (
<>
Expand Down Expand Up @@ -158,7 +155,6 @@ SubsectionCard.propTypes = {
onOpenDeleteModal: PropTypes.func.isRequired,
onDuplicateSubmit: PropTypes.func.isRequired,
onOpenConfigureModal: PropTypes.func.isRequired,
setIsSubsectionConfigure: PropTypes.func.isRequired,
};

export default SubsectionCard;
1 change: 0 additions & 1 deletion src/course-outline/subsection-card/SubsectionCard.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const renderComponent = (props) => render(
onEditSubmit={onEditSubectionSubmit}
onDuplicateSubmit={jest.fn()}
namePrefix="subsection"
setIsSubsectionConfigure={jest.fn()}
{...props}
>
<span>children</span>
Expand Down

0 comments on commit de0d8e5

Please sign in to comment.