Skip to content

Commit 91ab1c1

Browse files
authored
Fix: Nits on the new sidebars [FC-0123] (#2985)
Fixes these issues: - #2638 (comment) - #2634 (comment) - #2868 (comment)
1 parent cc1af47 commit 91ab1c1

12 files changed

Lines changed: 132 additions & 68 deletions

File tree

src/course-outline/OutlineAddChildButtons.test.tsx

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ jest.mock('@src/course-outline/CourseOutlineContext', () => ({
3838
}));
3939

4040
const startCurrentFlow = jest.fn();
41+
const openContainerInfoSidebar = jest.fn();
4142
let currentFlow: OutlineFlow | null = null;
4243
jest.mock('@src/course-outline/outline-sidebar/OutlineSidebarContext', () => ({
4344
...jest.requireActual('@src/course-outline/outline-sidebar/OutlineSidebarContext'),
4445
useOutlineSidebarContext: () => ({
4546
...jest.requireActual('@src/course-outline/outline-sidebar/OutlineSidebarContext').useOutlineSidebarContext(),
4647
startCurrentFlow,
48+
openContainerInfoSidebar,
4749
currentFlow,
4850
isCurrentFlowOn: !!currentFlow,
4951
}),
@@ -104,21 +106,35 @@ jest.mock('@src/course-outline/outline-sidebar/OutlineSidebarContext', () => ({
104106
switch (containerType) {
105107
case ContainerType.Section:
106108
await waitFor(() =>
107-
expect(handleAddBlock.mutateAsync).toHaveBeenCalledWith({
108-
type: ContainerType.Chapter,
109-
parentLocator: courseUsageKey,
110-
displayName: 'Section',
111-
})
109+
expect(handleAddBlock.mutateAsync).toHaveBeenCalledWith(
110+
{
111+
type: ContainerType.Chapter,
112+
parentLocator: courseUsageKey,
113+
displayName: 'Section',
114+
},
115+
expect.objectContaining({ onSuccess: expect.any(Function) }),
116+
)
112117
);
118+
handleAddBlock.mutateAsync.mock.calls[0][1].onSuccess({ locator: 'new-section-id' });
119+
expect(openContainerInfoSidebar).toHaveBeenCalledWith('new-section-id', undefined, 'new-section-id');
113120
break;
114121
case ContainerType.Subsection:
115122
await waitFor(() =>
116-
expect(handleAddBlock.mutateAsync).toHaveBeenCalledWith({
117-
type: ContainerType.Sequential,
118-
parentLocator,
119-
displayName: 'Subsection',
120-
sectionId: parentLocator,
121-
})
123+
expect(handleAddBlock.mutateAsync).toHaveBeenCalledWith(
124+
{
125+
type: ContainerType.Sequential,
126+
parentLocator,
127+
displayName: 'Subsection',
128+
sectionId: parentLocator,
129+
},
130+
expect.objectContaining({ onSuccess: expect.any(Function) }),
131+
)
132+
);
133+
handleAddBlock.mutateAsync.mock.calls[0][1].onSuccess({ locator: 'new-subsection-id' });
134+
expect(openContainerInfoSidebar).toHaveBeenCalledWith(
135+
'new-subsection-id',
136+
'new-subsection-id',
137+
parentLocator,
122138
);
123139
break;
124140
case ContainerType.Unit:

src/course-outline/OutlineAddChildButtons.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const NewOutlineAddChildButtons = ({
114114
handleAddBlock,
115115
handleAddAndOpenUnit,
116116
} = useCourseOutlineContext();
117-
const { startCurrentFlow } = useOutlineSidebarContext();
117+
const { startCurrentFlow, openContainerInfoSidebar } = useOutlineSidebarContext();
118118
let messageMap = {
119119
newButton: messages.newUnitButton,
120120
importButton: messages.useUnitFromLibraryButton,
@@ -134,6 +134,10 @@ const NewOutlineAddChildButtons = ({
134134
type: ContainerType.Chapter,
135135
parentLocator: courseUsageKey,
136136
displayName: COURSE_BLOCK_NAMES.chapter.name,
137+
}, {
138+
onSuccess: (data: { locator: string; }) => {
139+
openContainerInfoSidebar(data.locator, undefined, data.locator);
140+
},
137141
});
138142
flowType = ContainerType.Section;
139143
break;
@@ -148,6 +152,10 @@ const NewOutlineAddChildButtons = ({
148152
parentLocator,
149153
displayName: COURSE_BLOCK_NAMES.sequential.name,
150154
sectionId: parentLocator,
155+
}, {
156+
onSuccess: (data: { locator: string; }) => {
157+
openContainerInfoSidebar(data.locator, data.locator, parentLocator);
158+
},
151159
});
152160
flowType = ContainerType.Subsection;
153161
break;

src/course-outline/card-header/CardHeader.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
justify-content: flex-start;
77
padding: 0;
88
flex: 1 1 0;
9-
height: 1.5rem;
9+
height: 1.75rem;
1010
margin-right: .25rem;
1111
background: transparent;
1212
color: var(--pgn-color-black);

src/course-outline/outline-sidebar/AddSidebar.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ const ShowLibraryContent = () => {
224224
lastEditableSubsection,
225225
selectedContainerState,
226226
currentItemData,
227+
openContainerInfoSidebar,
227228
} = useOutlineSidebarContext();
228229

229230
let sectionParentId = lastEditableSection?.id;
@@ -237,6 +238,11 @@ const ShowLibraryContent = () => {
237238
category: ContainerType.Chapter,
238239
parentLocator: courseUsageKey,
239240
libraryContentKey: usageKey,
241+
}, {
242+
onSuccess: (data: { locator: string; }) => {
243+
// istanbul ignore next
244+
openContainerInfoSidebar(data.locator, undefined, data.locator);
245+
},
240246
});
241247
break;
242248
case 'subsection':
@@ -248,6 +254,11 @@ const ShowLibraryContent = () => {
248254
parentLocator: sectionParentId,
249255
libraryContentKey: usageKey,
250256
sectionId: sectionParentId,
257+
}, {
258+
onSuccess: (data: { locator: string; }) => {
259+
// istanbul ignore next
260+
openContainerInfoSidebar(data.locator, data.locator, sectionParentId);
261+
},
251262
});
252263
}
253264
break;
@@ -261,6 +272,11 @@ const ShowLibraryContent = () => {
261272
parentLocator: subsectionParentId,
262273
libraryContentKey: usageKey,
263274
sectionId: sectionParentId,
275+
}, {
276+
onSuccess: (data: { locator: string; }) => {
277+
// istanbul ignore next
278+
openContainerInfoSidebar(data.locator, subsectionParentId, sectionParentId);
279+
},
264280
});
265281
}
266282
break;

src/course-unit/CourseUnit.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ const CourseUnit = () => {
310310
headerNavigationsActions={headerNavigationsActions}
311311
unitTitle={unitTitle}
312312
verticalBlocks={courseVerticalChildren.children}
313+
isPublished={courseUnit.published}
313314
/>
314315
}
315316
/>

src/course-unit/header-navigations/HeaderNavigations.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ describe('<HeaderNavigations />', () => {
7979
});
8080
});
8181

82+
it('should enable the "View Live" button when isPublished is true', () => {
83+
renderComponent({ unitCategory: COURSE_BLOCK_NAMES.vertical.id, isPublished: true });
84+
85+
expect(screen.getByRole('button', { name: messages.viewLiveButton.defaultMessage })).not.toBeDisabled();
86+
});
87+
88+
it('should disable the "View Live" button when isPublished is false', () => {
89+
renderComponent({ unitCategory: COURSE_BLOCK_NAMES.vertical.id, isPublished: false });
90+
91+
expect(screen.getByRole('button', { name: messages.viewLiveButton.defaultMessage })).toBeDisabled();
92+
});
93+
8294
it('click Info button should open info sidebar', async () => {
8395
setConfig({
8496
...getConfig(),

src/course-unit/header-navigations/HeaderNavigations.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import messages from './messages';
1616
import { isUnitPageNewDesignEnabled } from '../utils';
1717
import { useUnitSidebarContext } from '../unit-sidebar/UnitSidebarContext';
1818

19-
type HeaderNavigationActions = {
19+
export type HeaderNavigationActions = {
2020
handleViewLive: () => void;
2121
handlePreview: () => void;
2222
handleEdit: () => void;
@@ -25,6 +25,7 @@ type HeaderNavigationActions = {
2525
type HeaderNavigationsProps = {
2626
headerNavigationsActions: HeaderNavigationActions;
2727
category: string;
28+
isPublished?: boolean;
2829
};
2930

3031
/**
@@ -33,7 +34,11 @@ type HeaderNavigationsProps = {
3334
* - Legacy library content page
3435
* - Split test page
3536
*/
36-
const HeaderNavigations = ({ headerNavigationsActions, category }: HeaderNavigationsProps) => {
37+
const HeaderNavigations = ({
38+
headerNavigationsActions,
39+
category,
40+
isPublished = true,
41+
}: HeaderNavigationsProps) => {
3742
const intl = useIntl();
3843
const {
3944
handleViewLive,
@@ -82,9 +87,11 @@ const HeaderNavigations = ({ headerNavigationsActions, category }: HeaderNavigat
8287
>
8388
{intl.formatMessage(messages.previewButton)}
8489
</Button>
90+
{/* TODO: convert to <Button as="a" href="..."> since it navigates to a URL */}
8591
<Button
8692
variant="outline-primary"
8793
onClick={handleViewLive}
94+
disabled={!isPublished}
8895
>
8996
{intl.formatMessage(messages.viewLiveButton)}
9097
</Button>

src/generic/sidebar/BlockCardButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const BlockCardButton = ({
5151
<div data-testid={`${blockType}-collapsible`}>
5252
<Collapsible
5353
styling="card-lg"
54-
className="mx-2 font-weight-bold shadow pl-1 rounded"
54+
className="mx-n2 font-weight-bold shadow-sm pl-1 rounded"
5555
title={titleComponent}
5656
>
5757
<Stack direction="horizontal" className="d-flex flex-wrap" gap={2}>
@@ -69,7 +69,7 @@ export const BlockCardButton = ({
6969
return (
7070
<Button
7171
variant="tertiary"
72-
className="mx-2 shadow border justify-content-between pl-4 font-weight-bold"
72+
className="mx-n2 shadow-sm border justify-content-between pl-4 font-weight-bold"
7373
onClick={onClick}
7474
disabled={disabled}
7575
>

src/generic/sidebar/Sidebar.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export function Sidebar<T extends SidebarPages>({
137137
alt={intl.formatMessage(messages.toggle)}
138138
onClick={toggle}
139139
variant="primary"
140+
className="mb-2"
140141
/>
141142
<IconButtonToggle
142143
activeValue={activeKey}

src/plugin-slots/CourseUnitHeaderActionsSlot/index.jsx

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)