Skip to content

Commit adb5295

Browse files
committed
feat: Enable view library menu in all container sidebars
1 parent 7cea73d commit adb5295

3 files changed

Lines changed: 30 additions & 4 deletions

File tree

src/course-outline/outline-sidebar/info-sidebar/SectionInfoSidebar.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useState } from 'react';
22
import { useIntl } from '@edx/frontend-platform/i18n';
33
import { Tab, Tabs } from '@openedx/paragon';
4+
import { useNavigate } from 'react-router-dom';
45

56
import { getItemIcon } from '@src/generic/block-type-utils';
67

@@ -10,13 +11,15 @@ import { useCourseItemData } from '@src/course-outline/data/apiHooks';
1011
import Loading from '@src/generic/Loading';
1112
import { useCourseAuthoringContext } from '@src/CourseAuthoringContext';
1213
import { useOutlineSidebarContext } from '@src/course-outline/outline-sidebar/OutlineSidebarContext';
14+
import { getLibraryId } from '@src/generic/key-utils';
1315
import { InfoSection } from './InfoSection';
1416
import messages from '../messages';
1517
import { PublishButon } from './PublishButon';
1618
import { canMoveSection } from '@src/course-outline/drag-helper/utils';
1719

1820
export const SectionSidebar = () => {
1921
const intl = useIntl();
22+
const navigate = useNavigate();
2023
const [tab, setTab] = useState<'info' | 'settings'>('info');
2124
const { clearSelection, selectedContainerState, setSelectedContainerState } = useOutlineSidebarContext();
2225
const { sectionId = '', index } = selectedContainerState ?? {};
@@ -65,7 +68,13 @@ export const SectionSidebar = () => {
6568
onClickMoveDown: () => handleMove(1),
6669
onClickUnlink: () => openUnlinkModal({ value: sectionData, sectionId }),
6770
onClickDelete: openDeleteModal,
68-
onClickViewLibrary: () => {},
71+
onClickViewLibrary: () => {
72+
const upstreamRef = sectionData?.upstreamInfo?.upstreamRef;
73+
if (upstreamRef) {
74+
const libId = getLibraryId(upstreamRef);
75+
navigate(`/library/${libId}/section/${upstreamRef}`);
76+
}
77+
},
6978
}}
7079
/>
7180
{sectionData?.hasChanges && <PublishButon onClick={handlePublish} />}

src/course-outline/outline-sidebar/info-sidebar/SubsectionInfoSidebar.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import { isEmpty } from 'lodash';
33

44
import { useIntl } from '@edx/frontend-platform/i18n';
55
import { Tab, Tabs } from '@openedx/paragon';
6+
import { useNavigate } from 'react-router-dom';
67

78
import { getItemIcon } from '@src/generic/block-type-utils';
89
import { SidebarTitle } from '@src/generic/sidebar';
910
import { useCourseItemData } from '@src/course-outline/data/apiHooks';
1011
import Loading from '@src/generic/Loading';
1112
import { useCourseAuthoringContext } from '@src/CourseAuthoringContext';
1213
import { useOutlineSidebarContext } from '@src/course-outline/outline-sidebar/OutlineSidebarContext';
14+
import { getLibraryId } from '@src/generic/key-utils';
1315
import { possibleSubsectionMoves } from '@src/course-outline/drag-helper/utils';
1416

1517
import { InfoSection } from './InfoSection';
@@ -24,6 +26,7 @@ interface Props {
2426

2527
export const SubsectionSidebar = () => {
2628
const intl = useIntl();
29+
const navigate = useNavigate();
2730
const [tab, setTab] = useState<'info' | 'settings'>('info');
2831
const { clearSelection, selectedContainerState, setSelectedContainerState } = useOutlineSidebarContext();
2932
const { subsectionId = '', index, sectionIndex } = selectedContainerState ?? {};
@@ -110,7 +113,13 @@ export const SubsectionSidebar = () => {
110113
sectionId: selectedContainerState?.sectionId,
111114
}),
112115
onClickDelete: openDeleteModal,
113-
onClickViewLibrary: () => {},
116+
onClickViewLibrary: () => {
117+
const upstreamRef = subsectionData?.upstreamInfo?.upstreamRef;
118+
if (upstreamRef) {
119+
const libId = getLibraryId(upstreamRef);
120+
navigate(`/library/${libId}/subsection/${upstreamRef}`);
121+
}
122+
},
114123
}}
115124
/>
116125
{subsectionData?.hasChanges && <PublishButon onClick={handlePublish} />}

src/course-outline/outline-sidebar/info-sidebar/UnitInfoSidebar.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import Loading from '@src/generic/Loading';
1818
import { useCourseAuthoringContext } from '@src/CourseAuthoringContext';
1919
import XBlockContainerIframe from '@src/course-unit/xblock-container-iframe';
2020
import { IframeProvider } from '@src/generic/hooks/context/iFrameContext';
21-
import { Link } from 'react-router-dom';
21+
import { Link, useNavigate } from 'react-router-dom';
22+
import { getLibraryId } from '@src/generic/key-utils';
2223
import { possibleUnitMoves } from '@src/course-outline/drag-helper/utils';
2324
import { useOutlineSidebarContext } from '../OutlineSidebarContext';
2425
import { PublishButon } from './PublishButon';
@@ -27,6 +28,7 @@ import { InfoSection } from './InfoSection';
2728

2829
export const UnitSidebar = () => {
2930
const intl = useIntl();
31+
const navigate = useNavigate();
3032
const [tab, setTab] = useState<'preview' | 'info' | 'settings'>('info');
3133
const { selectedContainerState, clearSelection, setSelectedContainerState } = useOutlineSidebarContext();
3234
const {
@@ -135,7 +137,13 @@ export const UnitSidebar = () => {
135137
subsectionId: selectedContainerState?.subsectionId,
136138
}),
137139
onClickDelete: openDeleteModal,
138-
onClickViewLibrary: () => {},
140+
onClickViewLibrary: () => {
141+
const upstreamRef = unitData?.upstreamInfo?.upstreamRef;
142+
if (upstreamRef) {
143+
const libId = getLibraryId(upstreamRef);
144+
navigate(`/library/${libId}/unit/${upstreamRef}`);
145+
}
146+
},
139147
onClickCopy: () => {},
140148
onClickCopyLocation: () => {},
141149
}}

0 commit comments

Comments
 (0)