Skip to content

Commit e7903e9

Browse files
committed
feat: Put selectable cards behind the new design flag
1 parent 071c47c commit e7903e9

File tree

8 files changed

+46
-73
lines changed

8 files changed

+46
-73
lines changed

src/course-outline/common/context/SidebarContext.tsx

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

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
useState,
77
} from 'react';
88
import { useIntl } from '@edx/frontend-platform/i18n';
9+
import { getConfig } from '@edx/frontend-platform';
910
import { useToggle } from '@openedx/paragon';
1011
import { HelpOutline, Info } from '@openedx/paragon/icons';
1112

@@ -25,6 +26,8 @@ interface OutlineSidebarContextData {
2526
open: () => void;
2627
toggle: () => void;
2728
sidebarPages: OutlineSidebarPages;
29+
selectedContainerId?: string;
30+
openContainerInfoSidebar: (containerId: string) => void;
2831
}
2932

3033
const OutlineSidebarContext = createContext<OutlineSidebarContextData | undefined>(undefined);
@@ -35,6 +38,14 @@ export const OutlineSidebarProvider = ({ children }: { children?: React.ReactNod
3538
const [currentPageKey, setCurrentPageKeyState] = useState<OutlineSidebarPageKeys>('info');
3639
const [isOpen, open, , toggle] = useToggle(true);
3740

41+
const [selectedContainerId, setSelectedContainerId] = useState<string | undefined>();
42+
43+
const openContainerInfoSidebar = useCallback((containerId: string) => {
44+
if (getConfig().ENABLE_COURSE_OUTLINE_NEW_DESIGN?.toString().toLowerCase() === 'true') {
45+
setSelectedContainerId(containerId);
46+
}
47+
}, [setSelectedContainerId]);
48+
3849
const setCurrentPageKey = useCallback((pageKey: OutlineSidebarPageKeys) => {
3950
setCurrentPageKeyState(pageKey);
4051
open();
@@ -61,6 +72,8 @@ export const OutlineSidebarProvider = ({ children }: { children?: React.ReactNod
6172
isOpen,
6273
open,
6374
toggle,
75+
selectedContainerId,
76+
openContainerInfoSidebar,
6477
}),
6578
[
6679
currentPageKey,
@@ -69,6 +82,8 @@ export const OutlineSidebarProvider = ({ children }: { children?: React.ReactNod
6982
isOpen,
7083
open,
7184
toggle,
85+
selectedContainerId,
86+
openContainerInfoSidebar,
7287
],
7388
);
7489

src/course-outline/section-card/SectionCard.test.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import { getConfig, setConfig } from '@edx/frontend-platform';
12
import {
23
act, fireEvent, initializeMocks, render, screen, waitFor, within,
34
} from '@src/testUtils';
45
import { XBlock } from '@src/data/types';
56
import SectionCard from './SectionCard';
6-
import { SidebarProvider } from '../common/context/SidebarContext';
7+
import { OutlineSidebarProvider } from '../outline-sidebar/OutlineSidebarContext';
78

89
const mockUseAcceptLibraryBlockChanges = jest.fn();
910
const mockUseIgnoreLibraryBlockChanges = jest.fn();
@@ -83,7 +84,7 @@ const section = {
8384
const onEditSectionSubmit = jest.fn();
8485

8586
const renderComponent = (props?: object, entry = '/course/:courseId') => render(
86-
<SidebarProvider>
87+
<OutlineSidebarProvider>
8788
<SectionCard
8889
section={section}
8990
index={1}
@@ -106,7 +107,7 @@ const renderComponent = (props?: object, entry = '/course/:courseId') => render(
106107
>
107108
<span>children</span>
108109
</SectionCard>
109-
</SidebarProvider>,
110+
</OutlineSidebarProvider>,
110111
{
111112
path: '/course/:courseId',
112113
params: { courseId: '5' },
@@ -133,6 +134,10 @@ describe('<SectionCard />', () => {
133134
});
134135

135136
it('render SectionCard component in selected state', () => {
137+
setConfig({
138+
...getConfig(),
139+
ENABLE_COURSE_OUTLINE_NEW_DESIGN: 'true',
140+
});
136141
const { container } = renderComponent();
137142

138143
expect(screen.getByTestId('section-card-header')).toBeInTheDocument();

src/course-outline/section-card/SectionCard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { UpstreamInfoIcon } from '@src/generic/upstream-info-icon';
2929
import type { XBlock } from '@src/data/types';
3030
import { invalidateLinksQuery } from '@src/course-libraries/data/apiHooks';
3131
import messages from './messages';
32-
import { useSidebarContext } from '../common/context/SidebarContext';
32+
import { useOutlineSidebarContext } from '../outline-sidebar/OutlineSidebarContext';
3333

3434
interface SectionCardProps {
3535
section: XBlock,
@@ -78,7 +78,7 @@ const SectionCard = ({
7878
const intl = useIntl();
7979
const dispatch = useDispatch();
8080
const { activeId, overId } = useContext(DragContext);
81-
const { selectedContainerId, openContainerInfoSidebar } = useSidebarContext();
81+
const { selectedContainerId, openContainerInfoSidebar } = useOutlineSidebarContext();
8282
const [searchParams] = useSearchParams();
8383
const locatorId = searchParams.get('show');
8484
const isScrolledToElement = locatorId === section.id;

src/course-outline/subsection-card/SubsectionCard.test.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { getConfig, setConfig } from '@edx/frontend-platform';
12
import { COMPONENT_TYPES } from '@src/generic/block-type-utils/constants';
23
import {
34
act, fireEvent, initializeMocks, render, screen, waitFor, within,
45
} from '@src/testUtils';
56
import { XBlock } from '@src/data/types';
67
import cardHeaderMessages from '../card-header/messages';
78
import SubsectionCard from './SubsectionCard';
8-
import { SidebarProvider } from '../common/context/SidebarContext';
9+
import { OutlineSidebarProvider } from '../outline-sidebar/OutlineSidebarContext';
910

1011
let store;
1112
const containerKey = 'lct:org:lib:unit:1';
@@ -107,7 +108,7 @@ const section: XBlock = {
107108
const onEditSubectionSubmit = jest.fn();
108109

109110
const renderComponent = (props?: object, entry = '/course/:courseId') => render(
110-
<SidebarProvider>
111+
<OutlineSidebarProvider>
111112
<SubsectionCard
112113
section={section}
113114
subsection={subsection}
@@ -131,7 +132,7 @@ const renderComponent = (props?: object, entry = '/course/:courseId') => render(
131132
>
132133
<span>children</span>
133134
</SubsectionCard>
134-
</SidebarProvider>,
135+
</OutlineSidebarProvider>,
135136
{
136137
path: '/course/:courseId',
137138
params: { courseId: '5' },
@@ -158,6 +159,10 @@ describe('<SubsectionCard />', () => {
158159
});
159160

160161
it('render SubsectionCard component in selected state', () => {
162+
setConfig({
163+
...getConfig(),
164+
ENABLE_COURSE_OUTLINE_NEW_DESIGN: 'true',
165+
});
161166
const { container } = renderComponent();
162167

163168
expect(screen.getByTestId('subsection-card-header')).toBeInTheDocument();

src/course-outline/subsection-card/SubsectionCard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { PreviewLibraryXBlockChanges } from '@src/course-unit/preview-changes';
3030
import type { XBlock } from '@src/data/types';
3131
import { invalidateLinksQuery } from '@src/course-libraries/data/apiHooks';
3232
import messages from './messages';
33-
import { useSidebarContext } from '../common/context/SidebarContext';
33+
import { useOutlineSidebarContext } from '../outline-sidebar/OutlineSidebarContext';
3434

3535
interface SubsectionCardProps {
3636
section: XBlock,
@@ -89,7 +89,7 @@ const SubsectionCard = ({
8989
const intl = useIntl();
9090
const dispatch = useDispatch();
9191
const { activeId, overId } = useContext(DragContext);
92-
const { selectedContainerId, openContainerInfoSidebar } = useSidebarContext();
92+
const { selectedContainerId, openContainerInfoSidebar } = useOutlineSidebarContext();
9393
const [searchParams] = useSearchParams();
9494
const locatorId = searchParams.get('show');
9595
const isScrolledToElement = locatorId === subsection.id;

src/course-outline/unit-card/UnitCard.test.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { getConfig, setConfig } from '@edx/frontend-platform';
12
import {
23
act, fireEvent, initializeMocks, render, screen, waitFor, within,
34
} from '@src/testUtils';
45

56
import { XBlock } from '@src/data/types';
67
import UnitCard from './UnitCard';
78
import cardMessages from '../card-header/messages';
8-
import { SidebarProvider } from '../common/context/SidebarContext';
9+
import { OutlineSidebarProvider } from '../outline-sidebar/OutlineSidebarContext';
910

1011
const mockUseAcceptLibraryBlockChanges = jest.fn();
1112
const mockUseIgnoreLibraryBlockChanges = jest.fn();
@@ -75,7 +76,7 @@ const unit = {
7576
} satisfies Partial<XBlock> as XBlock;
7677

7778
const renderComponent = (props?: object) => render(
78-
<SidebarProvider>
79+
<OutlineSidebarProvider>
7980
<UnitCard
8081
section={section}
8182
subsection={subsection}
@@ -98,7 +99,7 @@ const renderComponent = (props?: object) => render(
9899
}}
99100
{...props}
100101
/>
101-
</SidebarProvider>,
102+
</OutlineSidebarProvider>,
102103
{
103104
path: '/course/:courseId',
104105
params: { courseId: '5' },
@@ -125,6 +126,11 @@ describe('<UnitCard />', () => {
125126
});
126127

127128
it('render UnitCard component in selected state', () => {
129+
setConfig({
130+
...getConfig(),
131+
ENABLE_COURSE_OUTLINE_NEW_DESIGN: 'true',
132+
});
133+
128134
const { container } = renderComponent();
129135

130136
expect(screen.getByTestId('unit-card-header')).toBeInTheDocument();

src/course-outline/unit-card/UnitCard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import { UpstreamInfoIcon } from '@src/generic/upstream-info-icon';
2525
import { PreviewLibraryXBlockChanges } from '@src/course-unit/preview-changes';
2626
import { invalidateLinksQuery } from '@src/course-libraries/data/apiHooks';
2727
import type { XBlock } from '@src/data/types';
28-
import { useSidebarContext } from '../common/context/SidebarContext';
28+
import { useOutlineSidebarContext } from '../outline-sidebar/OutlineSidebarContext';
2929

3030
interface UnitCardProps {
3131
unit: XBlock;
@@ -72,7 +72,7 @@ const UnitCard = ({
7272
const currentRef = useRef(null);
7373
const dispatch = useDispatch();
7474
const [searchParams] = useSearchParams();
75-
const { selectedContainerId, openContainerInfoSidebar } = useSidebarContext();
75+
const { selectedContainerId, openContainerInfoSidebar } = useOutlineSidebarContext();
7676
const locatorId = searchParams.get('show');
7777
const isScrolledToElement = locatorId === unit.id;
7878
const [isFormOpen, openForm, closeForm] = useToggle(false);

0 commit comments

Comments
 (0)