forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelpSidebar.jsx
More file actions
155 lines (144 loc) · 5.91 KB
/
HelpSidebar.jsx
File metadata and controls
155 lines (144 loc) · 5.91 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
import PropTypes from 'prop-types';
import { useLocation } from 'react-router-dom';
import classNames from 'classnames';
import { useIntl } from '@edx/frontend-platform/i18n';
import { getConfig } from '@edx/frontend-platform';
import { useUserPermissions } from '@src/authz/data/apiHooks';
import { COURSE_PERMISSIONS } from '@src/authz/constants';
import { useWaffleFlags } from '../../data/apiHooks';
import { otherLinkURLParams } from './constants';
import messages from './messages';
import HelpSidebarLink from './HelpSidebarLink';
const HelpSidebar = ({
courseId,
showOtherSettings,
proctoredExamSettingsUrl,
children,
className,
}) => {
const intl = useIntl();
const { pathname } = useLocation();
const {
grading,
courseTeam,
advancedSettings,
scheduleAndDetails,
groupConfigurations,
} = otherLinkURLParams;
const waffleFlags = useWaffleFlags(courseId);
const showOtherLink = (params) => !pathname.includes(params);
const generateLegacyURL = (urlParameter) => {
const referObj = new URL(`${urlParameter}/${courseId}`, getConfig().STUDIO_BASE_URL);
return referObj.href;
};
const scheduleAndDetailsDestination = generateLegacyURL(scheduleAndDetails);
const gradingDestination = generateLegacyURL(grading);
const courseTeamDestination = generateLegacyURL(courseTeam);
const advancedSettingsDestination = generateLegacyURL(advancedSettings);
const groupConfigurationsDestination = generateLegacyURL(groupConfigurations);
/*
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 (
<aside className={classNames('help-sidebar', className)}>
<div className="help-sidebar-about">{children}</div>
{showOtherSettings && (
<>
<hr />
<div className="help-sidebar-other">
<h4 className="help-sidebar-other-title">
{intl.formatMessage(messages.sidebarTitleOther)}
</h4>
<nav
className="help-sidebar-other-links"
aria-label={intl.formatMessage(messages.sidebarTitleOther)}
>
<ul className="p-0 mb-0">
{showOtherLink(scheduleAndDetails) && (
<HelpSidebarLink
pathToPage={waffleFlags.useNewScheduleDetailsPage
? `/course/${courseId}/${scheduleAndDetails}` : scheduleAndDetailsDestination}
title={intl.formatMessage(
messages.sidebarLinkToScheduleAndDetails,
)}
isNewPage={waffleFlags.useNewScheduleDetailsPage}
/>
)}
{showOtherLink(grading) && (
<HelpSidebarLink
pathToPage={waffleFlags.useNewGradingPage
? `/course/${courseId}/${grading}` : gradingDestination}
title={intl.formatMessage(messages.sidebarLinkToGrading)}
isNewPage={waffleFlags.useNewGradingPage}
/>
)}
{showOtherLink(courseTeam) && (
<HelpSidebarLink
pathToPage={waffleFlags.useNewCourseTeamPage
? `/course/${courseId}/${courseTeam}` : courseTeamDestination}
title={intl.formatMessage(messages.sidebarLinkToCourseTeam)}
isNewPage={waffleFlags.useNewCourseTeamPage}
/>
)}
{showOtherLink(groupConfigurations) && (
<HelpSidebarLink
pathToPage={waffleFlags.useNewGroupConfigurationsPage
? `/course/${courseId}/${groupConfigurations}` : groupConfigurationsDestination}
title={intl.formatMessage(
messages.sidebarLinkToGroupConfigurations,
)}
isNewPage={waffleFlags.useNewGroupConfigurationsPage}
/>
)}
{showOtherLink(advancedSettings) && canManageAdvancedSettings && (
<HelpSidebarLink
pathToPage={waffleFlags.useNewAdvancedSettingsPage
? `/course/${courseId}/${advancedSettings}` : advancedSettingsDestination}
title={intl.formatMessage(messages.sidebarLinkToAdvancedSettings)}
isNewPage={waffleFlags.useNewAdvancedSettingsPage}
/>
)}
{proctoredExamSettingsUrl && (
<HelpSidebarLink
pathToPage={proctoredExamSettingsUrl}
title={intl.formatMessage(
messages.sidebarLinkToProctoredExamSettings,
)}
/>
)}
</ul>
</nav>
</div>
</>
)}
</aside>
);
};
HelpSidebar.defaultProps = {
proctoredExamSettingsUrl: '',
className: undefined,
courseId: undefined,
showOtherSettings: false,
};
HelpSidebar.propTypes = {
courseId: PropTypes.string,
showOtherSettings: PropTypes.bool,
proctoredExamSettingsUrl: PropTypes.string,
children: PropTypes.node.isRequired,
className: PropTypes.string,
};
export default HelpSidebar;