Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions src/course-outline/OutlineAddChildButtons.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,27 @@ jest.mock('@src/course-outline/outline-sidebar/OutlineSidebarContext', () => ({
switch (containerType) {
case ContainerType.Section:
await waitFor(() =>
expect(handleAddBlock.mutateAsync).toHaveBeenCalledWith({
type: ContainerType.Chapter,
parentLocator: courseUsageKey,
displayName: 'Section',
})
expect(handleAddBlock.mutateAsync).toHaveBeenCalledWith(
{
type: ContainerType.Chapter,
parentLocator: courseUsageKey,
displayName: 'Section',
},
expect.objectContaining({ onSuccess: expect.any(Function) }),
)
);
break;
case ContainerType.Subsection:
await waitFor(() =>
expect(handleAddBlock.mutateAsync).toHaveBeenCalledWith({
type: ContainerType.Sequential,
parentLocator,
displayName: 'Subsection',
sectionId: parentLocator,
})
expect(handleAddBlock.mutateAsync).toHaveBeenCalledWith(
{
type: ContainerType.Sequential,
parentLocator,
displayName: 'Subsection',
sectionId: parentLocator,
},
expect.objectContaining({ onSuccess: expect.any(Function) }),
)
);
break;
case ContainerType.Unit:
Expand Down
12 changes: 11 additions & 1 deletion src/course-outline/OutlineAddChildButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const NewOutlineAddChildButtons = ({
handleAddBlock,
handleAddAndOpenUnit,
} = useCourseOutlineContext();
const { startCurrentFlow } = useOutlineSidebarContext();
const { startCurrentFlow, openContainerInfoSidebar } = useOutlineSidebarContext();
let messageMap = {
newButton: messages.newUnitButton,
importButton: messages.useUnitFromLibraryButton,
Expand All @@ -134,6 +134,11 @@ const NewOutlineAddChildButtons = ({
type: ContainerType.Chapter,
parentLocator: courseUsageKey,
displayName: COURSE_BLOCK_NAMES.chapter.name,
}, {
onSuccess: (data: { locator: string; }) => {
// istanbul ignore next
openContainerInfoSidebar(data.locator, undefined, data.locator);
},
});
flowType = ContainerType.Section;
break;
Expand All @@ -148,6 +153,11 @@ const NewOutlineAddChildButtons = ({
parentLocator,
displayName: COURSE_BLOCK_NAMES.sequential.name,
sectionId: parentLocator,
}, {
onSuccess: (data: { locator: string; }) => {
// istanbul ignore next
openContainerInfoSidebar(data.locator, data.locator, parentLocator);
},
});
flowType = ContainerType.Subsection;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/course-outline/card-header/CardHeader.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
justify-content: flex-start;
padding: 0;
flex: 1 1 0;
height: 1.5rem;
height: 1.75rem;
margin-right: .25rem;
background: transparent;
color: var(--pgn-color-black);
Expand Down
16 changes: 16 additions & 0 deletions src/course-outline/outline-sidebar/AddSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ const ShowLibraryContent = () => {
lastEditableSubsection,
selectedContainerState,
currentItemData,
openContainerInfoSidebar,
} = useOutlineSidebarContext();

let sectionParentId = lastEditableSection?.id;
Expand All @@ -237,6 +238,11 @@ const ShowLibraryContent = () => {
category: ContainerType.Chapter,
parentLocator: courseUsageKey,
libraryContentKey: usageKey,
}, {
onSuccess: (data: { locator: string; }) => {
// istanbul ignore next
openContainerInfoSidebar(data.locator, undefined, data.locator);
},
});
break;
case 'subsection':
Expand All @@ -248,6 +254,11 @@ const ShowLibraryContent = () => {
parentLocator: sectionParentId,
libraryContentKey: usageKey,
sectionId: sectionParentId,
}, {
onSuccess: (data: { locator: string; }) => {
// istanbul ignore next
openContainerInfoSidebar(data.locator, data.locator, sectionParentId);
},
});
}
break;
Expand All @@ -261,6 +272,11 @@ const ShowLibraryContent = () => {
parentLocator: subsectionParentId,
libraryContentKey: usageKey,
sectionId: sectionParentId,
}, {
onSuccess: (data: { locator: string; }) => {
// istanbul ignore next
openContainerInfoSidebar(data.locator, subsectionParentId, sectionParentId);
},
});
}
break;
Expand Down
1 change: 1 addition & 0 deletions src/course-unit/CourseUnit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ const CourseUnit = () => {
headerNavigationsActions={headerNavigationsActions}
unitTitle={unitTitle}
verticalBlocks={courseVerticalChildren.children}
isPublished={courseUnit.published}
/>
}
/>
Expand Down
12 changes: 12 additions & 0 deletions src/course-unit/header-navigations/HeaderNavigations.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ describe('<HeaderNavigations />', () => {
});
});

it('should enable the "View Live" button when isPublished is true', () => {
renderComponent({ unitCategory: COURSE_BLOCK_NAMES.vertical.id, isPublished: true });

expect(screen.getByRole('button', { name: messages.viewLiveButton.defaultMessage })).not.toBeDisabled();
});

it('should disable the "View Live" button when isPublished is false', () => {
renderComponent({ unitCategory: COURSE_BLOCK_NAMES.vertical.id, isPublished: false });

expect(screen.getByRole('button', { name: messages.viewLiveButton.defaultMessage })).toBeDisabled();
});

it('click Info button should open info sidebar', async () => {
setConfig({
...getConfig(),
Expand Down
10 changes: 8 additions & 2 deletions src/course-unit/header-navigations/HeaderNavigations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import messages from './messages';
import { isUnitPageNewDesignEnabled } from '../utils';
import { useUnitSidebarContext } from '../unit-sidebar/UnitSidebarContext';

type HeaderNavigationActions = {
export type HeaderNavigationActions = {
handleViewLive: () => void;
handlePreview: () => void;
handleEdit: () => void;
Expand All @@ -25,6 +25,7 @@ type HeaderNavigationActions = {
type HeaderNavigationsProps = {
headerNavigationsActions: HeaderNavigationActions;
category: string;
isPublished?: boolean;
};

/**
Expand All @@ -33,7 +34,11 @@ type HeaderNavigationsProps = {
* - Legacy library content page
* - Split test page
*/
const HeaderNavigations = ({ headerNavigationsActions, category }: HeaderNavigationsProps) => {
const HeaderNavigations = ({
headerNavigationsActions,
category,
isPublished = true,
}: HeaderNavigationsProps) => {
const intl = useIntl();
const {
handleViewLive,
Expand Down Expand Up @@ -85,6 +90,7 @@ const HeaderNavigations = ({ headerNavigationsActions, category }: HeaderNavigat
<Button
variant="outline-primary"
onClick={handleViewLive}
disabled={!isPublished}
>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not something you need to fix now, but: this button should really be a link (<Button as="a" href="...">), since it changes the URL.

{intl.formatMessage(messages.viewLiveButton)}
</Button>
Expand Down
4 changes: 2 additions & 2 deletions src/generic/sidebar/BlockCardButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const BlockCardButton = ({
<div data-testid={`${blockType}-collapsible`}>
<Collapsible
styling="card-lg"
className="mx-2 font-weight-bold shadow pl-1 rounded"
className="mx-n2 font-weight-bold shadow-sm pl-1 rounded"
title={titleComponent}
>
<Stack direction="horizontal" className="d-flex flex-wrap" gap={2}>
Expand All @@ -69,7 +69,7 @@ export const BlockCardButton = ({
return (
<Button
variant="tertiary"
className="mx-2 shadow border justify-content-between pl-4 font-weight-bold"
className="mx-n2 shadow-sm border justify-content-between pl-4 font-weight-bold"
onClick={onClick}
disabled={disabled}
>
Expand Down
1 change: 1 addition & 0 deletions src/generic/sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ export function Sidebar<T extends SidebarPages>({
alt={intl.formatMessage(messages.toggle)}
onClick={toggle}
variant="primary"
className="mb-2"
/>
<IconButtonToggle
activeValue={activeKey}
Expand Down
51 changes: 0 additions & 51 deletions src/plugin-slots/CourseUnitHeaderActionsSlot/index.jsx

This file was deleted.

3 changes: 3 additions & 0 deletions src/plugin-slots/CourseUnitHeaderActionsSlot/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const headerNavProps = {
unitTitle: 'Mock Unit',
isUnitVerticalType: false,
verticalBlocks: [],
isPublished: true,
};

describe('CourseUnitHeaderActionsSlot', () => {
Expand All @@ -40,6 +41,7 @@ describe('CourseUnitHeaderActionsSlot', () => {
verticalBlocks={[]}
category="library"
headerNavigationsActions={headerNavProps.headerNavigationsActions}
isPublished
/>,
);
expect(component.toJSON().props.pluginProps.isUnitVerticalType).toEqual(false);
Expand All @@ -50,6 +52,7 @@ describe('CourseUnitHeaderActionsSlot', () => {
verticalBlocks={[]}
category={COURSE_BLOCK_NAMES.vertical.id}
headerNavigationsActions={headerNavProps.headerNavigationsActions}
isPublished
/>,
);
expect(component.toJSON().props.pluginProps.isUnitVerticalType).toEqual(true);
Expand Down
51 changes: 51 additions & 0 deletions src/plugin-slots/CourseUnitHeaderActionsSlot/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { PluginSlot } from '@openedx/frontend-plugin-framework';

import HeaderNavigations, {
HeaderNavigationActions,
} from 'CourseAuthoring/course-unit/header-navigations/HeaderNavigations';
import { COURSE_BLOCK_NAMES } from 'CourseAuthoring/constants';

export interface CourseUnitHeaderActionsSlotProps {
headerNavigationsActions: HeaderNavigationActions;
category: string;
unitTitle: string;
verticalBlocks: {
id: string;
blockId: string;
name: string;
blockType: string;
}[];
isPublished: boolean;
}

const CourseUnitHeaderActionsSlot = ({
headerNavigationsActions,
category,
unitTitle,
verticalBlocks,
isPublished,
}: CourseUnitHeaderActionsSlotProps) => {
const isUnitVerticalType = category === COURSE_BLOCK_NAMES.vertical.id;
return (
<PluginSlot
id="org.openedx.frontend.authoring.course_unit_header_actions.v1"
idAliases={['course_unit_header_actions_slot']}
pluginProps={{
headerNavigationsActions,
category,
unitTitle,
isUnitVerticalType,
verticalBlocks,
isPublished,
}}
>
<HeaderNavigations
headerNavigationsActions={headerNavigationsActions}
category={category}
isPublished={isPublished}
/>
</PluginSlot>
);
};

export default CourseUnitHeaderActionsSlot;