forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSectionInfoSidebar.tsx
More file actions
122 lines (113 loc) · 3.98 KB
/
SectionInfoSidebar.tsx
File metadata and controls
122 lines (113 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import { useEffect } from 'react';
import { useIntl } from '@edx/frontend-platform/i18n';
import { Tab, Tabs } from '@openedx/paragon';
import { useNavigate } from 'react-router-dom';
import { getItemIcon } from '@src/generic/block-type-utils';
import { SidebarTitle } from '@src/generic/sidebar';
import { useCourseItemData } from '@src/course-outline/data/apiHooks';
import Loading from '@src/generic/Loading';
import { useCourseAuthoringContext } from '@src/CourseAuthoringContext';
import { useCourseOutlineContext } from '@src/course-outline/CourseOutlineContext';
import { useOutlineSidebarContext } from '@src/course-outline/outline-sidebar/OutlineSidebarContext';
import { getLibraryId } from '@src/generic/key-utils';
import { SectionSettings } from '@src/course-outline/outline-sidebar/info-sidebar/SectionSettings';
import { canMoveSection } from '@src/course-outline/drag-helper/utils';
import { InfoSection } from './InfoSection';
import messages from '../messages';
import { PublishButon } from './PublishButon';
export const SectionSidebar = () => {
const intl = useIntl();
const navigate = useNavigate();
const { openUnlinkModal } = useCourseAuthoringContext();
const {
openPublishModal,
handleDuplicateSectionSubmit,
sections,
updateSectionOrderByIndex,
openDeleteModal,
} = useCourseOutlineContext();
const {
clearSelection,
currentTabKey,
setCurrentTabKey,
selectedContainerState,
setSelectedContainerState,
} = useOutlineSidebarContext();
const availableTabs = {
info: 'info',
settings: 'settings',
};
useEffect(() => {
if (!currentTabKey || !Object.values(availableTabs).includes(currentTabKey)) {
// Set default Tab key
setCurrentTabKey('info');
}
}, [currentTabKey, setCurrentTabKey]);
const { sectionId = '', index } = selectedContainerState ?? {};
const { data: sectionData, isLoading } = useCourseItemData(sectionId);
const handlePublish = () => {
if (sectionData?.hasChanges) {
openPublishModal({
value: sectionData,
sectionId: sectionData.id,
});
}
};
if (isLoading || !sectionData) {
return <Loading />;
}
const handleMove = (step: number) => {
if (index !== undefined) {
updateSectionOrderByIndex(index, index + step);
setSelectedContainerState(
selectedContainerState ? { ...selectedContainerState, index: index + step } : undefined,
);
}
};
return (
<>
<SidebarTitle
title={sectionData.displayName || ''}
icon={getItemIcon(sectionData.category || '')}
onBackBtnClick={clearSelection}
menuProps={{
itemId: sectionId,
index: index ?? -1,
actions: sectionData.actions || {},
canMoveItem: canMoveSection(sections),
onClickDuplicate: handleDuplicateSectionSubmit,
onClickMoveUp: () => handleMove(-1),
onClickMoveDown: () => handleMove(1),
onClickUnlink: () => openUnlinkModal({ value: sectionData, sectionId }),
onClickDelete: openDeleteModal,
onClickViewLibrary: () => {
const upstreamRef = sectionData.upstreamInfo?.upstreamRef;
if (upstreamRef) {
const libId = getLibraryId(upstreamRef);
navigate(`/library/${libId}/section/${upstreamRef}`);
}
},
}}
/>
{sectionData.hasChanges && <PublishButon onClick={handlePublish} />}
<Tabs
variant="tabs"
className="my-2 mx-n3.5"
id="add-content-tabs"
activeKey={currentTabKey}
onSelect={setCurrentTabKey}
mountOnEnter
>
<Tab eventKey={availableTabs.info} title={intl.formatMessage(messages.infoTabText)}>
<InfoSection itemId={sectionId} />
</Tab>
<Tab
eventKey={availableTabs.settings}
title={intl.formatMessage(messages.settingsTabText)}
>
<SectionSettings key={sectionId} sectionId={sectionId} />
</Tab>
</Tabs>
</>
);
};