forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hide "Advanced Settings" settings item [BB-9081] (openedx#1252)
* refactor: convert header utils to hooks * feat: hide advanced settings button if a user doesn't have access (cherry picked from commit 45c68d6)
- Loading branch information
Showing
6 changed files
with
194 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import { getConfig } from '@edx/frontend-platform'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
import { useSelector } from 'react-redux'; | ||
import { getPagePath } from '../utils'; | ||
import { getStudioHomeData } from '../studio-home/data/selectors'; | ||
import messages from './messages'; | ||
|
||
export const useContentMenuItems = courseId => { | ||
const intl = useIntl(); | ||
const studioBaseUrl = getConfig().STUDIO_BASE_URL; | ||
|
||
const items = [ | ||
{ | ||
href: `${studioBaseUrl}/course/${courseId}`, | ||
title: intl.formatMessage(messages['header.links.outline']), | ||
}, | ||
{ | ||
href: `${studioBaseUrl}/course_info/${courseId}`, | ||
title: intl.formatMessage(messages['header.links.updates']), | ||
}, | ||
{ | ||
href: getPagePath(courseId, 'true', 'tabs'), | ||
title: intl.formatMessage(messages['header.links.pages']), | ||
}, | ||
{ | ||
href: `${studioBaseUrl}/assets/${courseId}`, | ||
title: intl.formatMessage(messages['header.links.filesAndUploads']), | ||
}, | ||
]; | ||
if (getConfig().ENABLE_VIDEO_UPLOAD_PAGE_LINK_IN_CONTENT_DROPDOWN === 'true') { | ||
items.push({ | ||
href: `${studioBaseUrl}/videos/${courseId}`, | ||
title: intl.formatMessage(messages['header.links.videoUploads']), | ||
}); | ||
} | ||
|
||
return items; | ||
}; | ||
|
||
export const useSettingMenuItems = courseId => { | ||
const intl = useIntl(); | ||
const studioBaseUrl = getConfig().STUDIO_BASE_URL; | ||
const { canAccessAdvancedSettings } = useSelector(getStudioHomeData); | ||
|
||
const items = [ | ||
{ | ||
href: `${studioBaseUrl}/settings/details/${courseId}`, | ||
title: intl.formatMessage(messages['header.links.scheduleAndDetails']), | ||
}, | ||
{ | ||
href: `${studioBaseUrl}/settings/grading/${courseId}`, | ||
title: intl.formatMessage(messages['header.links.grading']), | ||
}, | ||
{ | ||
href: `${studioBaseUrl}/course_team/${courseId}`, | ||
title: intl.formatMessage(messages['header.links.courseTeam']), | ||
}, | ||
{ | ||
href: `${studioBaseUrl}/group_configurations/${courseId}`, | ||
title: intl.formatMessage(messages['header.links.groupConfigurations']), | ||
}, | ||
...(canAccessAdvancedSettings === true | ||
? [{ | ||
href: `${studioBaseUrl}/settings/advanced/${courseId}`, | ||
title: intl.formatMessage(messages['header.links.advancedSettings']), | ||
}] : [] | ||
), | ||
{ | ||
href: `${studioBaseUrl}/certificates/${courseId}`, | ||
title: intl.formatMessage(messages['header.links.certificates']), | ||
}, | ||
]; | ||
return items; | ||
}; | ||
|
||
export const useToolsMenuItems = courseId => { | ||
const intl = useIntl(); | ||
const studioBaseUrl = getConfig().STUDIO_BASE_URL; | ||
|
||
const items = [ | ||
{ | ||
href: `${studioBaseUrl}/import/${courseId}`, | ||
title: intl.formatMessage(messages['header.links.import']), | ||
}, | ||
{ | ||
href: `${studioBaseUrl}/export/${courseId}`, | ||
title: intl.formatMessage(messages['header.links.exportCourse']), | ||
}, | ||
...(getConfig().ENABLE_TAGGING_TAXONOMY_PAGES === 'true' | ||
? [{ | ||
href: '#export-tags', | ||
title: intl.formatMessage(messages['header.links.exportTags']), | ||
}] : [] | ||
), | ||
{ | ||
href: `${studioBaseUrl}/checklists/${courseId}`, | ||
title: intl.formatMessage(messages['header.links.checklists']), | ||
}, | ||
]; | ||
return items; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { useSelector } from 'react-redux'; | ||
import { getConfig, setConfig } from '@edx/frontend-platform'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { useContentMenuItems, useToolsMenuItems, useSettingMenuItems } from './hooks'; | ||
|
||
jest.mock('@edx/frontend-platform/i18n', () => ({ | ||
...jest.requireActual('@edx/frontend-platform/i18n'), | ||
useIntl: () => ({ | ||
formatMessage: jest.fn(message => message.defaultMessage), | ||
}), | ||
})); | ||
|
||
jest.mock('react-redux', () => ({ | ||
...jest.requireActual('react-redux'), | ||
useSelector: jest.fn(), | ||
})); | ||
|
||
describe('header utils', () => { | ||
describe('getContentMenuItems', () => { | ||
it('should include Video Uploads option', () => { | ||
setConfig({ | ||
...getConfig(), | ||
ENABLE_VIDEO_UPLOAD_PAGE_LINK_IN_CONTENT_DROPDOWN: 'true', | ||
}); | ||
const actualItems = renderHook(() => useContentMenuItems('course-123')).result.current; | ||
expect(actualItems).toHaveLength(5); | ||
}); | ||
it('should not include Video Uploads option', () => { | ||
setConfig({ | ||
...getConfig(), | ||
ENABLE_VIDEO_UPLOAD_PAGE_LINK_IN_CONTENT_DROPDOWN: 'false', | ||
}); | ||
const actualItems = renderHook(() => useContentMenuItems('course-123')).result.current; | ||
expect(actualItems).toHaveLength(4); | ||
}); | ||
}); | ||
|
||
describe('getSettingsMenuitems', () => { | ||
useSelector.mockReturnValue({ canAccessAdvancedSettings: true }); | ||
|
||
it('should include advanced settings option', () => { | ||
const actualItemsTitle = renderHook(() => useSettingMenuItems('course-123')).result.current.map((item) => item.title); | ||
expect(actualItemsTitle).toContain('Advanced Settings'); | ||
}); | ||
it('should not include advanced settings option', () => { | ||
useSelector.mockReturnValue({ canAccessAdvancedSettings: false }); | ||
const actualItemsTitle = renderHook(() => useSettingMenuItems('course-123')).result.current.map((item) => item.title); | ||
expect(actualItemsTitle).not.toContain('Advanced Settings'); | ||
}); | ||
}); | ||
|
||
describe('getToolsMenuItems', () => { | ||
it('should include export tags option', () => { | ||
setConfig({ | ||
...getConfig(), | ||
ENABLE_TAGGING_TAXONOMY_PAGES: 'true', | ||
}); | ||
const actualItemsTitle = renderHook(() => useToolsMenuItems('course-123')).result.current.map((item) => item.title); | ||
expect(actualItemsTitle).toEqual([ | ||
'Import', | ||
'Export Course', | ||
'Export Tags', | ||
'Checklists', | ||
]); | ||
}); | ||
it('should not include export tags option', () => { | ||
setConfig({ | ||
...getConfig(), | ||
ENABLE_TAGGING_TAXONOMY_PAGES: 'false', | ||
}); | ||
const actualItemsTitle = renderHook(() => useToolsMenuItems('course-123')).result.current.map((item) => item.title); | ||
expect(actualItemsTitle).toEqual([ | ||
'Import', | ||
'Export Course', | ||
'Checklists', | ||
]); | ||
}); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.