forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourseInfoSidebar.tsx
More file actions
176 lines (162 loc) · 5.57 KB
/
CourseInfoSidebar.tsx
File metadata and controls
176 lines (162 loc) · 5.57 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import { useIntl } from '@edx/frontend-platform/i18n';
import {
Tab,
Tabs,
useToggle,
} from '@openedx/paragon';
import { SchoolOutline, Tag } from '@openedx/paragon/icons';
import { useUserPermissions } from '@src/authz/data/apiHooks';
import { COURSE_PERMISSIONS } from '@src/authz/constants';
import { ContentTagsDrawerSheet, ContentTagsSnippet } from '@src/content-tags-drawer';
import { useCourseSettings, useWaffleFlags } from '@src/data/apiHooks';
import { ComponentCountSnippet } from '@src/generic/block-type-utils';
import { HelpSidebarLink, otherLinkURLParams, messages as helpSidebarMessages } from '@src/generic/help-sidebar';
import { SidebarContent, SidebarSection, SidebarTitle } from '@src/generic/sidebar';
import { useGetBlockTypes } from '@src/search-manager';
import { useCourseAuthoringContext } from '@src/CourseAuthoringContext';
import { useCourseDetails } from '@src/course-outline/data/apiHooks';
import messages from '../messages';
const DetailsTab = () => {
const intl = useIntl();
const { courseId } = useCourseAuthoringContext();
const { data: componentData } = useGetBlockTypes(
[`context_key = "${courseId}"`],
);
const [isManageTagsDrawerOpen, openManageTagsDrawer, closeManageTagsDrawer] = useToggle(false);
return (
<>
<SidebarContent>
<SidebarSection
title={intl.formatMessage(messages.sidebarSectionSummary)}
icon={SchoolOutline}
>
{componentData && <ComponentCountSnippet componentData={componentData} />}
</SidebarSection>
<SidebarSection
title={intl.formatMessage(messages.sidebarSectionTaxonomy)}
icon={Tag}
actions={[
{
label: intl.formatMessage(messages.sidebarSectionTaxonomyManageTags),
onClick: openManageTagsDrawer,
},
]}
>
<ContentTagsSnippet contentId={courseId} />
</SidebarSection>
</SidebarContent>
<ContentTagsDrawerSheet
id={courseId}
onClose={closeManageTagsDrawer}
showSheet={isManageTagsDrawerOpen}
/>
</>
);
};
const SettingsTab = () => {
const intl = useIntl();
const { courseId } = useCourseAuthoringContext();
const { data: courseSettingsData } = useCourseSettings(courseId);
const {
grading,
courseTeam,
advancedSettings,
scheduleAndDetails,
groupConfigurations,
} = otherLinkURLParams;
const waffleFlags = useWaffleFlags(courseId);
const proctoredExamSettingsUrl = courseSettingsData?.mfeProctoredExamSettingsUrl;
/*
AuthZ for Course Authoring
If authz.enable_course_authoring flag is enabled, validate permissions using AuthZ API.
*/
const isAuthzEnabled = waffleFlags.enableAuthzCourseAuthoring;
const { isLoading: isLoadingUserPermissions, data: userPermissions } = useUserPermissions({
canManageAdvancedSettings: {
action: COURSE_PERMISSIONS.MANAGE_ADVANCED_SETTINGS,
scope: courseId,
},
}, isAuthzEnabled);
// If it's still loading, don't show the Advanced Settings link, otherwise, use the permission to decide
const authzCanManageAdvancedSettings = isLoadingUserPermissions
? false
: !!userPermissions?.canManageAdvancedSettings;
// When authz is enabled, use permission, otherwise it's always allowed (legacy behavior)
const canManageAdvancedSettings = isAuthzEnabled ? authzCanManageAdvancedSettings : true;
return (
<SidebarSection
title={intl.formatMessage(messages.settingsTabText)}
>
<HelpSidebarLink
as="span"
pathToPage={`/course/${courseId}/${scheduleAndDetails}`}
title={intl.formatMessage(
helpSidebarMessages.sidebarLinkToScheduleAndDetails,
)}
isNewPage
/>
<HelpSidebarLink
as="span"
pathToPage={`/course/${courseId}/${grading}`}
title={intl.formatMessage(helpSidebarMessages.sidebarLinkToGrading)}
isNewPage
/>
<HelpSidebarLink
as="span"
pathToPage={`/course/${courseId}/${courseTeam}`}
title={intl.formatMessage(helpSidebarMessages.sidebarLinkToCourseTeam)}
isNewPage
/>
<HelpSidebarLink
as="span"
pathToPage={`/course/${courseId}/${groupConfigurations}`}
title={intl.formatMessage(helpSidebarMessages.sidebarLinkToGroupConfigurations)}
isNewPage
/>
{canManageAdvancedSettings && (
<HelpSidebarLink
as="span"
pathToPage={`/course/${courseId}/${advancedSettings}`}
title={intl.formatMessage(helpSidebarMessages.sidebarLinkToAdvancedSettings)}
isNewPage
/>
)}
{proctoredExamSettingsUrl && (
<HelpSidebarLink
as="span"
pathToPage={proctoredExamSettingsUrl}
title={intl.formatMessage(
helpSidebarMessages.sidebarLinkToProctoredExamSettings,
)}
isNewPage
/>
)}
</SidebarSection>
);
};
export const CourseInfoSidebar = () => {
const intl = useIntl();
const { courseId } = useCourseAuthoringContext();
const { data: courseDetails } = useCourseDetails(courseId);
return (
<>
<SidebarTitle
title={courseDetails?.title || ''}
icon={SchoolOutline}
/>
<Tabs
variant="tabs"
className="my-2 mx-n3.5"
id="course-info-tabs"
mountOnEnter
>
<Tab eventKey="info" title={intl.formatMessage(messages.infoTabText)}>
<DetailsTab />
</Tab>
<Tab eventKey="settings" title={intl.formatMessage(messages.settingsTabText)}>
<SettingsTab />
</Tab>
</Tabs>
</>
);
};